1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 import Menu
24 from Language import _
25 import Dialogs
26 import Config
27 import Mod
28 import Audio
29
30 import pygame
31
33 - def __init__(self, config, section, option, autoApply = False):
34 self.config = config
35 self.section = section
36 self.option = option
37 self.changed = False
38 self.value = None
39 self.autoApply = autoApply
40 o = config.prototype[section][option]
41 v = config.get(section, option)
42 if isinstance(o.options, dict):
43 values = o.options.values()
44 values.sort()
45 try:
46 valueIndex = values.index(o.options[v])
47 except KeyError:
48 valueIndex = 0
49 elif isinstance(o.options, list):
50 values = o.options
51 try:
52 valueIndex = values.index(v)
53 except ValueError:
54 valueIndex = 0
55 else:
56 raise RuntimeError("No usable options for %s.%s." % (section, option))
57 Menu.Choice.__init__(self, text = o.text, callback = self.change, values = values, valueIndex = valueIndex)
58
60 o = self.config.prototype[self.section][self.option]
61
62 if isinstance(o.options, dict):
63 for k, v in o.options.items():
64 if v == value:
65 value = k
66 break
67
68 self.changed = True
69 self.value = value
70
71 if self.autoApply:
72 self.apply()
73
75 if self.changed:
76 self.config.set(self.section, self.option, self.value)
77
79 - def __init__(self, engine, config, section, option, autoApply = False):
82
88
90 - def __init__(self, engine, config, section, option):
91 self.engine = engine
92 self.config = config
93 self.section = section
94 self.option = option
95 self.changed = False
96 self.value = None
97 Menu.Choice.__init__(self, text = "", callback = self.change)
98
99 - def getText(self, selected):
100 def keycode(k):
101 try:
102 return int(k)
103 except:
104 return getattr(pygame, k)
105 o = self.config.prototype[self.section][self.option]
106 v = self.config.get(self.section, self.option)
107 return "%s: %s" % (o.text, pygame.key.name(keycode(v)).capitalize())
108
110 o = self.config.prototype[self.section][self.option]
111
112 if isinstance(o.options, dict):
113 for k, v in o.options.items():
114 if v == value:
115 value = k
116 break
117
118 key = Dialogs.getKey(self.engine, _("Press a key for '%s' or Escape to cancel.") % (o.text))
119
120 if key:
121 self.config.set(self.section, self.option, key)
122 self.engine.input.reloadControls()
123
126
127
130 applyItem = [(_("Apply New Settings"), self.applySettings)]
131
132 modSettings = [
133 ConfigChoice(engine.config, "mods", "mod_" + m) for m in Mod.getAvailableMods(engine)
134 ] + applyItem
135
136 gameSettings = [
137 (_("Mod settings"), modSettings),
138 ConfigChoice(engine.config, "game", "language"),
139 ConfigChoice(engine.config, "game", "leftymode", autoApply = True),
140 ConfigChoice(engine.config, "game", "tapping", autoApply = True),
141 ConfigChoice(engine.config, "game", "uploadscores", autoApply = True),
142 ]
143 gameSettingsMenu = Menu.Menu(engine, gameSettings + applyItem)
144
145 keySettings = [
146 (_("Test Keys"), lambda: Dialogs.testKeys(engine)),
147 KeyConfigChoice(engine, engine.config, "player", "key_action1"),
148 KeyConfigChoice(engine, engine.config, "player", "key_action2"),
149 KeyConfigChoice(engine, engine.config, "player", "key_1"),
150 KeyConfigChoice(engine, engine.config, "player", "key_2"),
151 KeyConfigChoice(engine, engine.config, "player", "key_3"),
152 KeyConfigChoice(engine, engine.config, "player", "key_4"),
153 KeyConfigChoice(engine, engine.config, "player", "key_5"),
154 KeyConfigChoice(engine, engine.config, "player", "key_left"),
155 KeyConfigChoice(engine, engine.config, "player", "key_right"),
156 KeyConfigChoice(engine, engine.config, "player", "key_up"),
157 KeyConfigChoice(engine, engine.config, "player", "key_down"),
158 KeyConfigChoice(engine, engine.config, "player", "key_cancel"),
159 ]
160 keySettingsMenu = Menu.Menu(engine, keySettings)
161
162 modes = engine.video.getVideoModes()
163 modes.reverse()
164 Config.define("video", "resolution", str, "640x480", text = _("Video Resolution"), options = ["%dx%d" % (m[0], m[1]) for m in modes])
165 videoSettings = [
166 ConfigChoice(engine.config, "video", "resolution"),
167 ConfigChoice(engine.config, "video", "fullscreen"),
168 ConfigChoice(engine.config, "video", "fps"),
169 ConfigChoice(engine.config, "video", "multisamples"),
170
171 ConfigChoice(engine.config, "opengl", "svgquality"),
172 ConfigChoice(engine.config, "video", "fontscale"),
173 ]
174 videoSettingsMenu = Menu.Menu(engine, videoSettings + applyItem)
175
176 volumeSettings = [
177 VolumeConfigChoice(engine, engine.config, "audio", "guitarvol"),
178 VolumeConfigChoice(engine, engine.config, "audio", "songvol"),
179 VolumeConfigChoice(engine, engine.config, "audio", "rhythmvol"),
180 VolumeConfigChoice(engine, engine.config, "audio", "screwupvol"),
181 ]
182 volumeSettingsMenu = Menu.Menu(engine, volumeSettings + applyItem)
183
184 audioSettings = [
185 (_("Volume Settings"), volumeSettingsMenu),
186 ConfigChoice(engine.config, "audio", "delay"),
187 ConfigChoice(engine.config, "audio", "frequency"),
188 ConfigChoice(engine.config, "audio", "bits"),
189 ConfigChoice(engine.config, "audio", "buffersize"),
190 ]
191 audioSettingsMenu = Menu.Menu(engine, audioSettings + applyItem)
192
193 settings = [
194 (_("Game Settings"), gameSettingsMenu),
195 (_("Key Settings"), keySettingsMenu),
196 (_("Video Settings"), videoSettingsMenu),
197 (_("Audio Settings"), audioSettingsMenu),
198 ]
199
200 self.settingsToApply = settings + \
201 videoSettings + \
202 audioSettings + \
203 volumeSettings + \
204 gameSettings + \
205 modSettings
206
207 Menu.Menu.__init__(self, engine, settings)
208
210 for option in self.settingsToApply:
211 if isinstance(option, ConfigChoice):
212 option.apply()
213 self.engine.restart()
214
217 settings = [
218 VolumeConfigChoice(engine, engine.config, "audio", "guitarvol", autoApply = True),
219 VolumeConfigChoice(engine, engine.config, "audio", "songvol", autoApply = True),
220 VolumeConfigChoice(engine, engine.config, "audio", "rhythmvol", autoApply = True),
221 VolumeConfigChoice(engine, engine.config, "audio", "screwupvol", autoApply = True),
222 ]
223 Menu.Menu.__init__(self, engine, settings)
224