55# =============================================================================
66# >> IMPORTS
77# =============================================================================
8- # Python Imports
9- # Collections
8+ # Python
109from collections import OrderedDict
1110
12- # Source.Python Imports
13- # Core
11+ # Source.Python
1412from core import AutoUnload
15- # Menus
16- from menus import PagedMenu
17- from menus import PagedOption
18- # Settings
13+ from menus import PagedMenu , PagedOption
1914from settings .menu import _player_settings
20- from settings .types import _SettingsType
21- from settings .types import _FloatSetting
22- from settings .types import _IntegerSetting
23- from settings .types import _StringSetting
15+ from settings .types import (
16+ BoolSetting , IntegerSetting , SettingsType , StringSetting
17+ )
2418
2519
2620# =============================================================================
@@ -46,11 +40,11 @@ def __init__(self, name, text=None):
4640 'Given name "{0}" is not valid' .format (name ))
4741
4842 # Set the base attributes
49- self ._name = name
50- self ._text = text
43+ self .name = name
44+ self .text = text
5145
5246 # Create the instance's menu
53- self ._menu = PagedMenu (
47+ self .menu = PagedMenu (
5448 select_callback = self ._chosen_item ,
5549 title = name if text is None else text )
5650
@@ -60,7 +54,7 @@ def __init__(self, name, text=None):
6054 def __setitem__ (self , item , value ):
6155 """Validate the given value and its type before setting the item."""
6256 # Is the given value a proper type?
63- if not isinstance (value , (_SettingsDictionary , _SettingsType )):
57+ if not isinstance (value , (_SettingsDictionary , SettingsType )):
6458
6559 # Raise an error
6660 raise ValueError (
@@ -80,70 +74,39 @@ def __setitem__(self, item, value):
8074 value = self [item ]
8175
8276 # Set the item's prefix
83- value ._prefix = self .prefix + '_'
77+ value .prefix = self .prefix
78+ if not value .prefix .endswith ('_' ):
79+ value .prefix += '_'
8480
8581 # Does the section's name need added to the prefix?
8682 if not isinstance (self , PlayerSettings ):
8783
8884 # Add the section's name to the prefix
89- value ._prefix += self .name .lower ().replace (' ' , '_' ) + '_'
85+ value .prefix += self .name .lower ().replace (' ' , '_' ) + '_'
9086
9187 # Add the option to the menu
9288 self .menu .append (PagedOption (
9389 value .name if value .text is None else value .text , value ))
9490
95- @property
96- def name (self ):
97- """Return the name of the _SettingsDictionary instance."""
98- return self ._name
99-
100- @property
101- def text (self ):
102- """Return the text of the _SettingsDictionary instance."""
103- return self ._text
104-
105- @property
106- def prefix (self ):
107- """Return the prefix of the _SettingsDictionary instance."""
108- return self ._prefix
109-
110- @property
111- def menu (self ):
112- """Return the instance's menu object."""
113- return self ._menu
114-
115- def add_float_setting (
116- self , name , default , text = None , min_value = None , max_value = None ):
117- """Add a new float setting to the dictionary."""
118- # Add the new float setting to the dictionary
119- self [name ] = _FloatSetting (name , default , text , min_value , max_value )
120-
121- # Return the setting
122- return self [name ]
123-
12491 def add_int_setting (
12592 self , name , default , text = None , min_value = None , max_value = None ):
12693 """Add a new integer setting to the dictionary."""
127- # Add the new integer setting to the dictionary
128- self [name ] = _IntegerSetting ( name , default , text , min_value , max_value )
94+ self [ name ] = IntegerSetting ( name , default , text , min_value , max_value )
95+ return self [name ]
12996
130- # Return the setting
97+ def add_bool_setting (self , name , default , text = None ):
98+ """Add a new boolean setting to the dictionary."""
99+ self [name ] = BoolSetting (name , default , text )
131100 return self [name ]
132101
133102 def add_string_setting (self , name , default , text = None ):
134103 """Add a new string setting to the dictionary."""
135- # Add the new string setting to the dictionary
136- self [name ] = _StringSetting (name , default , text )
137-
138- # Return the setting
104+ self [name ] = StringSetting (name , default , text )
139105 return self [name ]
140106
141107 def add_section (self , name , text = None ):
142108 """Add a new section to the dictionary."""
143- # Add the new section to the dictionary
144109 self [name ] = _SettingsDictionary (name , text )
145-
146- # Return the section
147110 return self [name ]
148111
149112 @staticmethod
@@ -186,17 +149,18 @@ def __init__(self, name, prefix, text=None):
186149 super ().__init__ (name , text )
187150
188151 # Set the prefix for the settings
189- self ._prefix = prefix .lower ()
152+ self .prefix = prefix .lower ()
190153
191154 # Add the instance to the main dictionary
192155 _player_settings [name ] = self
193156
194157 # Add the settings instance to the main settings menu
195- _player_settings . menu . append (
196- PagedOption ( name if text is None else text , self ) )
158+ self . option = PagedOption ( name if text is None else text , self )
159+ _player_settings . menu . append ( self . option )
197160
198161 def unregister_settings (self ):
199162 """Unregister the given settings from the dictionary."""
163+ _player_settings .menu .remove (self .option )
200164 del _player_settings [self .name ]
201165
202166 def _unload_instance (self ):
0 commit comments