5
5
# =============================================================================
6
6
# >> IMPORTS
7
7
# =============================================================================
8
- # Python Imports
9
- # Collections
8
+ # Python
10
9
from collections import OrderedDict
11
10
12
- # Source.Python Imports
13
- # Core
11
+ # Source.Python
14
12
from core import AutoUnload
15
- # Menus
16
- from menus import PagedMenu
17
- from menus import PagedOption
18
- # Settings
13
+ from menus import PagedMenu , PagedOption
19
14
from 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
+ )
24
18
25
19
26
20
# =============================================================================
@@ -46,11 +40,11 @@ def __init__(self, name, text=None):
46
40
'Given name "{0}" is not valid' .format (name ))
47
41
48
42
# Set the base attributes
49
- self ._name = name
50
- self ._text = text
43
+ self .name = name
44
+ self .text = text
51
45
52
46
# Create the instance's menu
53
- self ._menu = PagedMenu (
47
+ self .menu = PagedMenu (
54
48
select_callback = self ._chosen_item ,
55
49
title = name if text is None else text )
56
50
@@ -60,7 +54,7 @@ def __init__(self, name, text=None):
60
54
def __setitem__ (self , item , value ):
61
55
"""Validate the given value and its type before setting the item."""
62
56
# Is the given value a proper type?
63
- if not isinstance (value , (_SettingsDictionary , _SettingsType )):
57
+ if not isinstance (value , (_SettingsDictionary , SettingsType )):
64
58
65
59
# Raise an error
66
60
raise ValueError (
@@ -80,70 +74,39 @@ def __setitem__(self, item, value):
80
74
value = self [item ]
81
75
82
76
# Set the item's prefix
83
- value ._prefix = self .prefix + '_'
77
+ value .prefix = self .prefix
78
+ if not value .prefix .endswith ('_' ):
79
+ value .prefix += '_'
84
80
85
81
# Does the section's name need added to the prefix?
86
82
if not isinstance (self , PlayerSettings ):
87
83
88
84
# Add the section's name to the prefix
89
- value ._prefix += self .name .lower ().replace (' ' , '_' ) + '_'
85
+ value .prefix += self .name .lower ().replace (' ' , '_' ) + '_'
90
86
91
87
# Add the option to the menu
92
88
self .menu .append (PagedOption (
93
89
value .name if value .text is None else value .text , value ))
94
90
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
-
124
91
def add_int_setting (
125
92
self , name , default , text = None , min_value = None , max_value = None ):
126
93
"""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 ]
129
96
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 )
131
100
return self [name ]
132
101
133
102
def add_string_setting (self , name , default , text = None ):
134
103
"""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 )
139
105
return self [name ]
140
106
141
107
def add_section (self , name , text = None ):
142
108
"""Add a new section to the dictionary."""
143
- # Add the new section to the dictionary
144
109
self [name ] = _SettingsDictionary (name , text )
145
-
146
- # Return the section
147
110
return self [name ]
148
111
149
112
@staticmethod
@@ -186,17 +149,18 @@ def __init__(self, name, prefix, text=None):
186
149
super ().__init__ (name , text )
187
150
188
151
# Set the prefix for the settings
189
- self ._prefix = prefix .lower ()
152
+ self .prefix = prefix .lower ()
190
153
191
154
# Add the instance to the main dictionary
192
155
_player_settings [name ] = self
193
156
194
157
# 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 )
197
160
198
161
def unregister_settings (self ):
199
162
"""Unregister the given settings from the dictionary."""
163
+ _player_settings .menu .remove (self .option )
200
164
del _player_settings [self .name ]
201
165
202
166
def _unload_instance (self ):
0 commit comments