44from ursina .prefabs .button_group import ButtonGroup
55
66import pypresence , json , copy
7- from utils .utils import FakePyPresence , Dropdown , FileManager , is_float
7+
8+ from utils .utils import FakePyPresence , Dropdown , FileManager , FocusView , is_float
89from utils .constants import discord_presence_id , settings , settings_start_category
910from utils .preload import music_sound
1011
11- class Settings :
12+ class Settings ( FocusView ) :
1213 def __init__ (self , rpc ):
14+ super ().__init__ (model = 'cube' , color = color .dark_gray , scale = (1.8 , 1.2 ), z = 1 )
15+
1316 self .rpc = rpc
1417 rpc .update (state = 'In Settings' , details = 'Modifying Settings' , start = rpc .start_time )
1518
1619 self .data = json .load (open ('settings.json' ))
1720 self .edits = {}
1821 self .category = settings_start_category
19-
20- self .main = Entity (parent = camera .ui , model = 'cube' , color = color .dark_gray , scale = (1.8 , 1.2 ), z = 1 )
2122
22- self .back_button = Button ( 'Back' , parent = camera . ui , color = color . gray , scale = ( .1 , .05 ), position = ( - .8 , .45 ), on_click = self .exit )
23+ self .ui = [ self .main ]
2324
2425 self .category_group = ButtonGroup (tuple (settings .keys ()), default = self .category , spacing = (.25 , 0 , 0 ))
2526 self .category_group .on_value_changed = lambda : self .show (self .category_group .value )
2627 self .category_group .position = (- .6 , .4 )
27-
28- self .ui = [self .main , self .back_button , self .category_group ]
28+ self .ui .append (self .category_group )
2929
3030 self .weapon_dmg_inputs = {}
3131 self .weapon_atk_speed_inputs = {}
@@ -39,8 +39,14 @@ def __init__(self, rpc):
3939 self .enemy_img_path_buttons = {}
4040 self .enemy_remove_buttons = {}
4141
42+ self .back_button = Button ('Back' , parent = camera .ui , color = color .gray , scale = (.1 , .05 ), position = (- .8 , .45 ), on_click = self .exit )
43+
4244 self .show (self .category )
4345
46+ self .ui .append (self .back_button )
47+
48+ self .detect_focusable_widgets ()
49+
4450 def show (self , category ):
4551 self .clear ()
4652 self .category = category
@@ -66,13 +72,13 @@ def show(self, category):
6672 if type == 'bool' :
6773 bool_button_group = ButtonGroup (('OFF' , 'ON' ), default = 'ON' if val else 'OFF' , spacing = (.1 , 0 , 0 ))
6874 bool_button_group .position = (.2 , y )
69- bool_button_group .on_value_changed = lambda bool_button_group = bool_button_group , n = name : self .update (n , bool_button_group .value == 'ON' )
75+ bool_button_group .on_value_changed = lambda bool_button_group = bool_button_group , n = name : self .update_settings (n , bool_button_group .value == 'ON' )
7076 self .ui .append (bool_button_group )
7177
7278 elif type == 'slider' :
73- slider = ThinSlider (text = name , min = info ['min' ], max = info ['max' ], default = val , dynamic = True )
79+ slider = ThinSlider (min = info ['min' ], max = info ['max' ], default = val , dynamic = True )
7480 slider .position = (.2 , y )
75- slider .on_value_changed = lambda slider = slider , n = name : self .update (n , int (slider .value ))
81+ slider .on_value_changed = lambda slider = slider , n = name : self .update_settings (n , int (slider .value ))
7682 self .ui .append (slider )
7783
7884 elif type == "option" :
@@ -100,10 +106,12 @@ def show(self, category):
100106 self .apply_button = Button ('Apply' , parent = camera .ui , color = color .green , scale = (.15 , .08 ), position = (.6 , - .4 ), on_click = self .apply_changes )
101107 self .ui .append (self .apply_button )
102108
109+ self .detect_focusable_widgets ()
110+
103111 def directory_selected (self , btn , name , value ):
104112 btn .text = f"Select Directory ({ value } )"
105113
106- self .update (name , value )
114+ self .update_settings (name , value )
107115
108116 def select_directory (self , btn , name ):
109117 self .dir_file_manager = FileManager (return_folders = True , z = - 1 )
@@ -123,9 +131,9 @@ def select_image_file(self, btn, name, item_type):
123131 def dropdown_update (self , n , dropdown_menu , btn ):
124132 dropdown_menu .text = btn .text
125133
126- self .update (n , btn .text )
134+ self .update_settings (n , btn .text )
127135
128- def update (self , name , value ):
136+ def update_settings (self , name , value ):
129137 self .edits [settings [self .category ][name ]['config_key' ]] = value
130138
131139 def apply_changes (self ):
@@ -255,6 +263,8 @@ def enemies(self):
255263 self .apply_button = Button ('Apply' , parent = camera .ui , color = color .green , scale = (.15 , .08 ), position = (.6 , - .4 ), on_click = self .apply_changes )
256264 self .ui .append (self .apply_button )
257265
266+ self .detect_focusable_widgets ()
267+
258268 def weapons (self ):
259269 y = .3
260270
@@ -295,16 +305,15 @@ def weapons(self):
295305 self .apply_button = Button ('Apply' , parent = camera .ui , color = color .green , scale = (.15 , .08 ), position = (.6 , - .4 ), on_click = self .apply_changes )
296306 self .ui .append (self .apply_button )
297307
308+ self .detect_focusable_widgets ()
309+
298310 def clear (self ):
299311 for e in list (self .ui ):
300312 if e not in (self .main , self .back_button , self .category_group ):
301313 destroy (e )
302314 self .ui .remove (e )
303315
304- def hide (self ):
305- for e in self .ui :
306- destroy (e )
307- self .ui .clear ()
316+ self .detect_focusable_widgets ()
308317
309318 def exit (self ):
310319 self .hide ()
@@ -339,4 +348,6 @@ def credits(self):
339348
340349 self .credits_label = Text (text = text , parent = camera .ui , position = (0 , 0 ), origin = (0 , 0 ), scale = font_size , color = color .white )
341350 self .credits_label .type = 'credits_text'
342- self .ui .append (self .credits_label )
351+ self .ui .append (self .credits_label )
352+
353+ self .detect_focusable_widgets ()
0 commit comments