GUIScript: Use None instead if "", for null event handler.
[gemrb.git] / gemrb / GUIScripts / pst / GUIOPT.py
blobae87410873c3de4242e368c08063e29afc78ef81
1 # -*-python-*-
2 # GemRB - Infinity Engine Emulator
3 # Copyright (C) 2003 The GemRB Project
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 # GUIOPT.py - scripts to control options windows mostly from GUIOPT winpack
23 # GUIOPT:
24 # 0 - Main options window (peacock tail)
25 # 1 - Video options window
26 # 2 - msg win with 1 button
27 # 3 - msg win with 2 buttons
28 # 4 - msg win with 3 buttons
29 # 5 - Audio options window
30 # 6 - Gameplay options window
31 # 8 - Feedback options window
32 # 9 - Autopause options window
35 ###################################################
36 import GemRB
37 from GUIDefines import *
38 from GUICommon import CloseOtherWindow
39 from GUICommonWindows import EnableAnimatedWindows, DisableAnimatedWindows
41 from GUISAVE import OpenSaveWindow
42 import MessageWindow
44 ###################################################
45 OptionsWindow = None
46 VideoOptionsWindow = None
47 AudioOptionsWindow = None
48 GameplayOptionsWindow = None
49 FeedbackOptionsWindow = None
50 AutopauseOptionsWindow = None
51 LoadMsgWindow = None
52 QuitMsgWindow = None
53 MoviesWindow = None
54 KeysWindow = None
56 ###################################################
57 def OpenOptionsWindow ():
58 """Open main options window (peacock tail)"""
59 global OptionsWindow
61 if CloseOtherWindow (OpenOptionsWindow):
62 if VideoOptionsWindow: OpenVideoOptionsWindow ()
63 if AudioOptionsWindow: OpenAudioOptionsWindow ()
64 if GameplayOptionsWindow: OpenGameplayOptionsWindow ()
65 if FeedbackOptionsWindow: OpenFeedbackOptionsWindow ()
66 if AutopauseOptionsWindow: OpenAutopauseOptionsWindow ()
67 if LoadMsgWindow: OpenLoadMsgWindow ()
68 if QuitMsgWindow: OpenQuitMsgWindow ()
69 if KeysWindow: OpenKeysWindow ()
70 if MoviesWindow: OpenMoviesWindow ()
72 GemRB.HideGUI ()
73 if OptionsWindow:
74 OptionsWindow.Unload ()
75 GemRB.SetVar ("OtherWindow", -1)
76 EnableAnimatedWindows ()
77 OptionsWindow = None
79 GemRB.UnhideGUI ()
80 return
82 GemRB.HideGUI ()
83 GemRB.LoadWindowPack ("GUIOPT")
84 OptionsWindow = Window = GemRB.LoadWindow (0)
85 GemRB.SetVar ("OtherWindow", OptionsWindow.ID)
86 DisableAnimatedWindows ()
88 # Return to Game
89 Button = Window.GetControl (0)
90 Button.SetText (28638)
91 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "OpenOptionsWindow")
93 # Quit Game
94 Button = Window.GetControl (1)
95 Button.SetText (2595)
96 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "OpenQuitMsgWindow")
98 # Load Game
99 Button = Window.GetControl (2)
100 Button.SetText (2592)
101 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "OpenLoadMsgWindow")
103 # Save Game
104 Button = Window.GetControl (3)
105 Button.SetText (20639)
106 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "OpenSaveWindow")
108 # Video Options
109 Button = Window.GetControl (4)
110 Button.SetText (28781)
111 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "OpenVideoOptionsWindow")
113 # Audio Options
114 Button = Window.GetControl (5)
115 Button.SetText (29720)
116 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "OpenAudioOptionsWindow")
118 # Gameplay Options
119 Button = Window.GetControl (6)
120 Button.SetText (29722)
121 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "OpenGameplayOptionsWindow")
123 # Keyboard Mappings
124 Button = Window.GetControl (7)
125 Button.SetText (29723)
126 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "OpenKeyboardMappingsWindow")
128 # Movies
129 Button = Window.GetControl (9)
130 Button.SetText (38156) # or 2594
131 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "OpenMoviesWindow")
133 # game version, e.g. v1.1.0000
134 Label = Window.GetControl (0x10000007)
135 Label.SetText (GEMRB_VERSION)
137 #Window.SetVisible (WINDOW_VISIBLE)
138 GemRB.UnhideGUI ()
142 ###################################################
144 def OpenVideoOptionsWindow ():
145 """Open video options window"""
146 global VideoOptionsWindow, VideoHelpText
148 GemRB.HideGUI ()
150 if VideoOptionsWindow:
151 if VideoOptionsWindow:
152 VideoOptionsWindow.Unload ()
153 VideoOptionsWindow = None
154 GemRB.SetVar ("FloatWindow", -1)
156 GemRB.UnhideGUI ()
157 return
160 VideoOptionsWindow = Window = GemRB.LoadWindow (1)
161 GemRB.SetVar ("FloatWindow", VideoOptionsWindow.ID)
164 VideoHelpText = OptHelpText ('VideoOptions', Window, 9, 31052)
166 OptDone ('VideoOptions', Window, 7)
167 OptCancel ('VideoOptions', Window, 8)
169 OptSlider ('VideoOptions', 'Brightness', Window, 1, 10, 31234, "Brightness Correction", "GammaFeedback", 1)
170 OptSlider ('VideoOptions', 'Contrast', Window, 2, 11, 31429, "Gamma Correction", "GammaFeedback", 1)
172 OptCheckbox ('VideoOptions', 'SoftwareBlitting', Window, 6, 15, 30898, "SoftBlt")
173 OptCheckbox ('VideoOptions', 'SoftwareMirroring', Window, 4, 13, 30896, "SoftMirrorBlt")
174 OptCheckbox ('VideoOptions', 'SoftwareTransparency', Window, 5, 14, 30897, "SoftSrcKeyBlt")
176 GemRB.UnhideGUI ()
177 Window.ShowModal (MODAL_SHADOW_GRAY)
178 return
180 def GammaFeedback ():
181 GemRB.SetGamma (GemRB.GetVar("Brightness Correction")/5,GemRB.GetVar("Gamma Correction")/5)
182 return
184 def DisplayHelpVideoOptions ():
185 VideoHelpText.SetText (31052)
187 def DisplayHelpBrightness ():
188 VideoHelpText.SetText (31431)
190 def DisplayHelpContrast ():
191 VideoHelpText.SetText (31459)
193 def DisplayHelpSoftwareBlitting ():
194 VideoHelpText.SetText (31221)
196 def DisplayHelpSoftwareMirroring ():
197 VideoHelpText.SetText (31216)
199 def DisplayHelpSoftwareTransparency ():
200 VideoHelpText.SetText (31220)
204 ###################################################
206 saved_audio_options = {}
208 def OpenAudioOptionsWindow ():
209 """Open audio options window"""
210 global AudioOptionsWindow, AudioHelpText
212 GemRB.HideGUI ()
214 if AudioOptionsWindow:
215 if AudioOptionsWindow:
216 AudioOptionsWindow.Unload ()
217 AudioOptionsWindow = None
218 GemRB.SetVar ("FloatWindow", -1)
220 # Restore values in case of cancel
221 if GemRB.GetVar ("Cancel") == 1:
222 for k, v in saved_audio_options.items ():
223 GemRB.SetVar (k, v)
224 UpdateVolume ()
226 GemRB.UnhideGUI ()
227 return
230 AudioOptionsWindow = Window = GemRB.LoadWindow (5)
231 GemRB.SetVar ("FloatWindow", AudioOptionsWindow.ID)
234 # save values, so we can restore them on cancel
235 for v in "Volume Ambients", "Volume SFX", "Volume Voices", "Volume Music", "Volume Movie", "Sound Processing", "Music Processing":
236 saved_audio_options[v] = GemRB.GetVar (v)
239 AudioHelpText = OptHelpText ('AudioOptions', Window, 9, 31210)
241 OptDone ('AudioOptions', Window, 7)
242 OptCancel ('AudioOptions', Window, 8)
245 OptSlider ('AudioOptions', 'AmbientVolume', Window, 1, 10, 31460, "Volume Ambients", "UpdateVolume")
246 OptSlider ('AudioOptions', 'SoundFXVolume', Window, 2, 11, 31466, "Volume SFX", "UpdateVolume")
247 OptSlider ('AudioOptions', 'VoiceVolume', Window, 3, 12, 31467, "Volume Voices", "UpdateVolume")
248 OptSlider ('AudioOptions', 'MusicVolume', Window, 4, 13, 31468, "Volume Music", "UpdateVolume")
249 OptSlider ('AudioOptions', 'MovieVolume', Window, 5, 14, 31469, "Volume Movie", "UpdateVolume")
251 OptCheckbox ('AudioOptions', 'CreativeEAX', Window, 6, 15, 30900, "Environmental Audio")
252 OptCheckbox ('AudioOptions', 'SoundProcessing', Window, 16, 17, 63242, "Sound Processing")
253 OptCheckbox ('AudioOptions', 'MusicProcessing', Window, 18, 19, 63243, "Music Processing")
256 #AudioOptionsWindow.SetVisible (WINDOW_VISIBLE)
257 GemRB.UnhideGUI ()
258 Window.ShowModal (MODAL_SHADOW_GRAY)
260 def UpdateVolume ():
261 GemRB.UpdateAmbientsVolume ()
262 GemRB.UpdateMusicVolume ()
264 def DisplayHelpAudioOptions ():
265 AudioHelpText.SetText (31210)
267 def DisplayHelpAmbientVolume ():
268 AudioHelpText.SetText (31227)
270 def DisplayHelpSoundFXVolume ():
271 AudioHelpText.SetText (31228)
273 def DisplayHelpVoiceVolume ():
274 AudioHelpText.SetText (31226)
276 def DisplayHelpMusicVolume ():
277 AudioHelpText.SetText (31225)
279 def DisplayHelpMovieVolume ():
280 AudioHelpText.SetText (31229)
282 def DisplayHelpCreativeEAX ():
283 AudioHelpText.SetText (31224)
285 def DisplayHelpSoundProcessing ():
286 AudioHelpText.SetText (63244)
288 def DisplayHelpMusicProcessing ():
289 AudioHelpText.SetText (63247)
293 ###################################################
295 def OpenGameplayOptionsWindow ():
296 """Open gameplay options window"""
297 global GameplayOptionsWindow, GameplayHelpText
299 GemRB.HideGUI ()
301 if GameplayOptionsWindow:
302 if FeedbackOptionsWindow: OpenFeedbackOptionsWindow()
303 if AutopauseOptionsWindow: OpenAutopauseOptionsWindow()
305 if GameplayOptionsWindow:
306 GameplayOptionsWindow.Unload ()
307 GameplayOptionsWindow = None
308 GemRB.SetVar ("FloatWindow", -1)
310 GemRB.UnhideGUI ()
311 return
314 GameplayOptionsWindow = Window = GemRB.LoadWindow (6)
315 GemRB.SetVar ("FloatWindow", GameplayOptionsWindow.ID)
318 GameplayHelpText = OptHelpText ('GameplayOptions', Window, 12, 31212)
320 OptDone ('GameplayOptions', Window, 10)
321 OptCancel ('GameplayOptions', Window, 11)
323 OptSlider ('GameplayOptions', 'TooltipDelay', Window, 1, 13, 31481, "Tooltips", "UpdateTooltips", TOOLTIP_DELAY_FACTOR)
324 OptSlider ('GameplayOptions', 'MouseScrollingSpeed', Window, 2, 14, 31482, "Mouse Scroll Speed", "UpdateMouseSpeed")
325 OptSlider ('GameplayOptions', 'KeyboardScrollingSpeed', Window, 3, 15, 31480, "Keyboard Scroll Speed", "UpdateKeyboardSpeed")
326 OptSlider ('GameplayOptions', 'Difficulty', Window, 4, 16, 31479, "Difficulty Level")
328 OptCheckbox ('GameplayOptions', 'DitherAlways', Window, 5, 17, 31217, "Always Dither")
329 OptCheckbox ('GameplayOptions', 'Gore', Window, 6, 18, 31218, "Gore???")
330 OptCheckbox ('GameplayOptions', 'AlwaysRun', Window, 22, 23, 62418, "Always Run")
332 OptButton ('GameplayOptions', 'FeedbackOptions', Window, 8, 20, 31478)
333 OptButton ('GameplayOptions', 'AutopauseOptions', Window, 9, 21, 31470)
335 GemRB.UnhideGUI ()
336 Window.ShowModal (MODAL_SHADOW_GRAY)
337 return
339 def DisplayHelpGameplayOptions ():
340 GameplayHelpText.SetText (31212)
342 def UpdateTooltips ():
343 GemRB.SetTooltipDelay (GemRB.GetVar ("Tooltips") )
345 def DisplayHelpTooltipDelay ():
346 GameplayHelpText.SetText (31232)
348 def UpdateMouseSpeed ():
349 GemRB.SetMouseScrollSpeed (GemRB.GetVar ("Mouse Scroll Speed") )
351 def DisplayHelpMouseScrollingSpeed ():
352 GameplayHelpText.SetText (31230)
354 def UpdateKeyboardSpeed ():
355 #GemRB.SetKeyboardScrollSpeed (GemRB.GetVar ("Keyboard Scroll Speed") )
356 return
358 def DisplayHelpKeyboardScrollingSpeed ():
359 GameplayHelpText.SetText (31231)
361 def DisplayHelpDifficulty ():
362 GameplayHelpText.SetText (31233)
364 def DisplayHelpDitherAlways ():
365 GameplayHelpText.SetText (31222)
367 def DisplayHelpGore ():
368 GameplayHelpText.SetText (31223)
370 def DisplayHelpAlwaysRun ():
371 GameplayHelpText.SetText (62419)
373 def DisplayHelpFeedbackOptions ():
374 GameplayHelpText.SetText (31213)
376 def DisplayHelpAutopauseOptions ():
377 GameplayHelpText.SetText (31214)
381 ###################################################
383 def OpenFeedbackOptionsWindow ():
384 """Open feedback options window"""
385 global FeedbackOptionsWindow, FeedbackHelpText
387 GemRB.HideGUI ()
389 if FeedbackOptionsWindow:
390 if FeedbackOptionsWindow:
391 FeedbackOptionsWindow.Unload ()
392 FeedbackOptionsWindow = None
393 GemRB.SetVar ("FloatWindow", GameplayOptionsWindow.ID)
395 GemRB.UnhideGUI ()
396 GameplayOptionsWindow.ShowModal (MODAL_SHADOW_GRAY)
397 return
400 FeedbackOptionsWindow = Window = GemRB.LoadWindow (8)
401 GemRB.SetVar ("FloatWindow", FeedbackOptionsWindow.ID)
404 FeedbackHelpText = OptHelpText ('FeedbackOptions', Window, 9, 37410)
406 OptDone ('FeedbackOptions', Window, 7)
407 OptCancel ('FeedbackOptions', Window, 8)
409 OptSlider ('FeedbackOptions', 'MarkerFeedback', Window, 1, 10, 37463, "GUI Feedback Level")
410 OptSlider ('FeedbackOptions', 'LocatorFeedback', Window, 2, 11, 37586, "Locator Feedback Level")
411 OptSlider ('FeedbackOptions', 'SelectionFeedbackLevel', Window, 20, 21, 54879, "Selection Sounds Frequency")
412 OptSlider ('FeedbackOptions', 'CommandFeedbackLevel', Window, 22, 23, 55012, "Command Sounds Frequency")
414 OptCheckbox ('FeedbackOptions', 'CharacterStates', Window, 6, 15, 37594, "")
415 OptCheckbox ('FeedbackOptions', 'MiscellaneousMessages', Window, 17, 19, 37596, "")
416 OptCheckbox ('FeedbackOptions', 'ToHitRolls', Window, 3, 12, 37588, "")
417 OptCheckbox ('FeedbackOptions', 'CombatInfo', Window, 4, 13, 37590, "")
418 OptCheckbox ('FeedbackOptions', 'SpellCasting', Window, 5, 14, 37592, "")
421 GemRB.UnhideGUI ()
422 Window.ShowModal (MODAL_SHADOW_GRAY)
424 def DisplayHelpMarkerFeedback ():
425 FeedbackHelpText.SetText (37411)
427 def DisplayHelpLocatorFeedback ():
428 FeedbackHelpText.SetText (37447)
430 def DisplayHelpSelectionFeedbackLevel ():
431 FeedbackHelpText.SetText (54878)
433 def DisplayHelpCommandFeedbackLevel ():
434 FeedbackHelpText.SetText (54880)
436 def DisplayHelpCharacterStates ():
437 FeedbackHelpText.SetText (37460)
439 def DisplayHelpMiscellaneousMessages ():
440 FeedbackHelpText.SetText (37462)
442 def DisplayHelpToHitRolls ():
443 FeedbackHelpText.SetText (37453)
445 def DisplayHelpCombatInfo ():
446 FeedbackHelpText.SetText (37457)
448 def DisplayHelpSpellCasting ():
449 FeedbackHelpText.SetText (37458)
452 ###################################################
454 def OpenAutopauseOptionsWindow ():
455 """Open autopause options window"""
456 global AutopauseOptionsWindow, AutopauseHelpText
458 GemRB.HideGUI ()
460 if AutopauseOptionsWindow:
461 if AutopauseOptionsWindow:
462 AutopauseOptionsWindow.Unload ()
463 AutopauseOptionsWindow = None
464 GemRB.SetVar ("FloatWindow", GameplayOptionsWindow.ID)
466 GemRB.UnhideGUI ()
467 GameplayOptionsWindow.ShowModal (MODAL_SHADOW_GRAY)
468 return
471 AutopauseOptionsWindow = Window = GemRB.LoadWindow (9)
472 GemRB.SetVar ("FloatWindow", AutopauseOptionsWindow.ID)
475 AutopauseHelpText = OptHelpText ('AutopauseOptions', Window, 1, 31214)
477 OptDone ('AutopauseOptions', Window, 16)
478 OptCancel ('AutopauseOptions', Window, 17)
480 # Set variable for each checkbox according to a particular bit of
481 # AutoPauseState
482 state = GemRB.GetVar ("Auto Pause State")
483 GemRB.SetVar("AutoPauseState_Unusable", (state & 0x01) != 0 )
484 GemRB.SetVar("AutoPauseState_Attacked", (state & 0x02) != 0 )
485 GemRB.SetVar("AutoPauseState_Hit", (state & 0x04) != 0 )
486 GemRB.SetVar("AutoPauseState_Wounded", (state & 0x08) != 0 )
487 GemRB.SetVar("AutoPauseState_Dead", (state & 0x10) != 0 )
488 GemRB.SetVar("AutoPauseState_NoTarget", (state & 0x20) != 0 )
489 GemRB.SetVar("AutoPauseState_EndRound", (state & 0x40) != 0 )
492 OptCheckbox ('AutopauseOptions', 'CharacterHit', Window, 2, 9, 37598, "AutoPauseState_Hit", "OnAutoPauseClicked")
493 OptCheckbox ('AutopauseOptions', 'CharacterInjured', Window, 3, 10, 37681, "AutoPauseState_Wounded", "OnAutoPauseClicked")
494 OptCheckbox ('AutopauseOptions', 'CharacterDead', Window, 4, 11, 37682, "AutoPauseState_Dead", "OnAutoPauseClicked")
495 OptCheckbox ('AutopauseOptions', 'CharacterAttacked', Window, 5, 12, 37683, "AutoPauseState_Attacked", "OnAutoPauseClicked")
496 OptCheckbox ('AutopauseOptions', 'WeaponUnusable', Window, 6, 13, 37684, "AutoPauseState_Unusable", "OnAutoPauseClicked")
497 OptCheckbox ('AutopauseOptions', 'TargetGone', Window, 7, 14, 37685, "AutoPauseState_NoTarget", "OnAutoPauseClicked")
498 OptCheckbox ('AutopauseOptions', 'EndOfRound', Window, 8, 15, 37686, "AutoPauseState_EndRound", "OnAutoPauseClicked")
500 GemRB.UnhideGUI ()
501 Window.ShowModal (MODAL_SHADOW_GRAY)
505 def OnAutoPauseClicked ():
506 state = (0x01 * GemRB.GetVar("AutoPauseState_Unusable") +
507 0x02 * GemRB.GetVar("AutoPauseState_Attacked") +
508 0x04 * GemRB.GetVar("AutoPauseState_Hit") +
509 0x08 * GemRB.GetVar("AutoPauseState_Wounded") +
510 0x10 * GemRB.GetVar("AutoPauseState_Dead") +
511 0x20 * GemRB.GetVar("AutoPauseState_NoTarget") +
512 0x40 * GemRB.GetVar("AutoPauseState_EndRound"))
514 GemRB.SetVar("Auto Pause State", state)
516 def DisplayHelpCharacterHit ():
517 AutopauseHelpText.SetText (37688)
519 def DisplayHelpCharacterInjured ():
520 AutopauseHelpText.SetText (37689)
522 def DisplayHelpCharacterDead ():
523 AutopauseHelpText.SetText (37690)
525 def DisplayHelpCharacterAttacked ():
526 AutopauseHelpText.SetText (37691)
528 def DisplayHelpWeaponUnusable ():
529 AutopauseHelpText.SetText (37692)
531 def DisplayHelpTargetGone ():
532 AutopauseHelpText.SetText (37693)
534 def DisplayHelpEndOfRound ():
535 AutopauseHelpText.SetText (37694)
538 ###################################################
539 ###################################################
541 def OpenLoadMsgWindow ():
542 global LoadMsgWindow
544 GemRB.HideGUI()
546 if LoadMsgWindow:
547 if LoadMsgWindow:
548 LoadMsgWindow.Unload ()
549 LoadMsgWindow = None
550 GemRB.SetVar ("FloatWindow", -1)
552 GemRB.UnhideGUI ()
553 return
555 LoadMsgWindow = Window = GemRB.LoadWindow (3)
556 GemRB.SetVar ("FloatWindow", LoadMsgWindow.ID)
558 # Load
559 Button = Window.GetControl (0)
560 Button.SetText (28648)
561 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "LoadGame")
563 # Cancel
564 Button = Window.GetControl (1)
565 Button.SetText (4196)
566 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "OpenLoadMsgWindow")
568 # Loading a game will destroy ...
569 Text = Window.GetControl (3)
570 Text.SetText (39432)
572 GemRB.UnhideGUI ()
573 Window.ShowModal (MODAL_SHADOW_GRAY)
576 def LoadGame ():
577 OpenOptionsWindow ()
578 GemRB.QuitGame ()
579 GemRB.SetNextScript ('GUILOAD')
583 ###################################################
585 def OpenQuitMsgWindow ():
586 global QuitMsgWindow
588 #GemRB.HideGUI()
590 if QuitMsgWindow:
591 if QuitMsgWindow:
592 QuitMsgWindow.Unload ()
593 QuitMsgWindow = None
594 GemRB.SetVar ("FloatWindow", -1)
596 #GemRB.UnhideGUI ()
597 return
599 QuitMsgWindow = Window = GemRB.LoadWindow (4)
600 GemRB.SetVar ("FloatWindow", QuitMsgWindow.ID)
602 # Save
603 Button = Window.GetControl (0)
604 Button.SetText (28645)
605 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "SaveGame")
607 # Quit Game
608 Button = Window.GetControl (1)
609 Button.SetText (2595)
610 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "QuitGame")
612 # Cancel
613 Button = Window.GetControl (2)
614 Button.SetText (4196)
615 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "OpenQuitMsgWindow")
616 Button.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
618 # The game has not been saved ....
619 Text = Window.GetControl (3)
620 Text.SetText (39430) # or 39431 - cannot be saved atm
622 #GemRB.UnhideGUI ()
623 Window.ShowModal (MODAL_SHADOW_GRAY)
624 return
626 def QuitGame ():
627 OpenOptionsWindow ()
628 GemRB.QuitGame ()
629 GemRB.SetNextScript ('Start')
631 def SaveGame ():
632 OpenOptionsWindow ()
633 GemRB.QuitGame ()
634 GemRB.SetNextScript ('GUISAVE')
637 ###################################################
639 key_list = [
640 ('GemRB', None),
641 ('Grab pointer', '^G'),
642 ('Toggle fullscreen', '^F'),
643 ('Enable cheats', '^T'),
644 ('', None),
646 ('IE', None),
647 ('Open Inventory', 'I'),
648 ('Open Priest Spells', 'P'),
649 ('Open Mage Spells', 'S'),
650 ('Pause Game', 'SPC'),
651 ('Select Weapon', ''),
652 ('', None),
656 KEYS_PAGE_SIZE = 60
657 KEYS_PAGE_COUNT = ((len (key_list) - 1) / KEYS_PAGE_SIZE)+ 1
659 def OpenKeyboardMappingsWindow ():
660 global KeysWindow
661 global last_key_action
663 last_key_action = None
665 GemRB.HideGUI()
667 if KeysWindow:
668 if KeysWindow:
669 KeysWindow.Unload ()
670 KeysWindow = None
671 GemRB.SetVar ("OtherWindow", OptionsWindow.ID)
673 GemRB.LoadWindowPack ("GUIOPT")
674 GemRB.UnhideGUI ()
675 return
677 GemRB.LoadWindowPack ("GUIKEYS")
678 KeysWindow = Window = GemRB.LoadWindow (0)
679 GemRB.SetVar ("OtherWindow", KeysWindow.ID)
682 # Default
683 Button = Window.GetControl (3)
684 Button.SetText (49051)
685 #Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, None)
687 # Done
688 Button = Window.GetControl (4)
689 Button.SetText (1403)
690 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "OpenKeyboardMappingsWindow")
691 Button.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
693 # Cancel
694 Button = Window.GetControl (5)
695 Button.SetText (4196)
696 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "OpenKeyboardMappingsWindow")
697 Button.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
699 keys_setup_page (0)
702 #KeysWindow.SetVisible (WINDOW_VISIBLE)
703 GemRB.UnhideGUI ()
706 def keys_setup_page (pageno):
707 Window = KeysWindow
710 # Page n of n
711 Label = Window.GetControl (0x10000001)
712 #txt = GemRB.ReplaceVarsInText (49053, {'PAGE': str (pageno + 1), 'NUMPAGES': str (KEYS_PAGE_COUNT)})
713 GemRB.SetToken ('PAGE', str (pageno + 1))
714 GemRB.SetToken ('NUMPAGES', str (KEYS_PAGE_COUNT))
715 Label.SetText (49053)
718 for i in range (KEYS_PAGE_SIZE):
719 try:
720 label, key = key_list[pageno * KEYS_PAGE_SIZE + i]
721 except:
722 label = ''
723 key = None
726 if key == None:
727 # Section header
728 Label = Window.GetControl (0x10000005 + i)
729 Label.SetText ('')
731 Label = Window.GetControl (0x10000041 + i)
732 Label.SetText (label)
733 Label.SetTextColor (0, 255, 255)
735 else:
736 Label = Window.GetControl (0x10000005 + i)
737 Label.SetText (key)
738 Label.SetEventByName (IE_GUI_LABEL_ON_PRESS, "OnActionLabelPress")
739 Label.SetVarAssoc ("KeyAction", i)
741 Label = Window.GetControl (0x10000041 + i)
742 Label.SetText (label)
743 Label.SetEventByName (IE_GUI_LABEL_ON_PRESS, "OnActionLabelPress")
744 Label.SetVarAssoc ("KeyAction", i)
748 last_key_action = None
749 def OnActionLabelPress ():
750 global last_key_action
752 Window = KeysWindow
753 i = GemRB.GetVar ("KeyAction")
755 if last_key_action != None:
756 Label = Window.GetControl (0x10000005 + last_key_action)
757 Label.SetTextColor (255, 255, 255)
758 Label = Window.GetControl (0x10000041 + last_key_action)
759 Label.SetTextColor (255, 255, 255)
761 Label = Window.GetControl (0x10000005 + i)
762 Label.SetTextColor (255, 255, 0)
763 Label = Window.GetControl (0x10000041 + i)
764 Label.SetTextColor (255, 255, 0)
766 last_key_action = i
768 # 49155
770 ###################################################
772 def OpenMoviesWindow ():
773 global MoviesWindow
775 GemRB.HideGUI()
777 if MoviesWindow:
778 if MoviesWindow:
779 MoviesWindow.Unload ()
780 MoviesWindow = None
781 GemRB.SetVar ("FloatWindow", -1)
783 GemRB.LoadWindowPack ("GUIOPT")
784 GemRB.UnhideGUI ()
785 return
787 GemRB.LoadWindowPack ("GUIMOVIE")
788 # FIXME: clean the window to black
789 MoviesWindow = Window = GemRB.LoadWindow (0)
790 GemRB.SetVar ("FloatWindow", MoviesWindow.ID)
793 # Play Movie
794 Button = Window.GetControl (2)
795 Button.SetText (33034)
796 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "OnPlayMoviePress")
798 # Credits
799 Button = Window.GetControl (3)
800 Button.SetText (33078)
801 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "OnCreditsPress")
803 # Done
804 Button = Window.GetControl (4)
805 Button.SetText (1403)
806 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "OpenMoviesWindow")
808 # movie list
809 List = Window.GetControl (0)
810 List.SetFlags (IE_GUI_TEXTAREA_SELECTABLE)
811 List.SetVarAssoc ('SelectedMovie', -1)
813 #Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "OpenMoviesWindow")
816 MovieTable = GemRB.LoadTable ("MOVIDESC")
818 for i in range (MovieTable.GetRowCount ()):
819 #key = MovieTable.GetRowName (i)
820 desc = MovieTable.GetValue (i, 0)
821 List.Append (desc, i)
825 GemRB.UnhideGUI ()
826 Window.ShowModal (MODAL_SHADOW_BLACK)
829 ###################################################
830 def OnPlayMoviePress ():
831 selected = GemRB.GetVar ('SelectedMovie')
833 # FIXME: This should not happen, when the PlayMovie button gets
834 # properly disabled/enabled, but it does not now
835 if selected == -1:
836 return
838 MovieTable = GemRB.LoadTable ("MOVIDESC")
839 key = MovieTable.GetRowName (selected)
841 GemRB.PlayMovie (key, 1)
843 ###################################################
844 def OnCreditsPress ():
845 GemRB.PlayMovie ("CREDITS")
847 ###################################################
848 ###################################################
850 # These functions help to setup controls found
851 # in Video, Audio, Gameplay, Feedback and Autopause
852 # options windows
854 # These controls are usually made from an active
855 # control (button, slider ...) and a label
858 def OptSlider (winname, ctlname, window, slider_id, label_id, label_strref, assoc_var, fn = None, scale = 1):
859 """Standard slider for option windows"""
860 slider = window.GetControl (slider_id)
861 #slider.SetEventByName (IE_GUI_MOUSE_ENTER_BUTTON, "DisplayHelp" + ctlname)
862 #slider.SetEventByName (IE_GUI_MOUSE_LEAVE_BUTTON, "DisplayHelp" + winname)
863 if fn: slider.SetEventByName (IE_GUI_SLIDER_ON_CHANGE, fn)
865 slider.SetVarAssoc (assoc_var, scale)
867 label = window.GetControl (label_id)
868 label.SetText (label_strref)
869 label.SetFlags (IE_GUI_BUTTON_NO_IMAGE, OP_SET)
870 label.SetState (IE_GUI_BUTTON_LOCKED)
871 #label.SetEventByName (IE_GUI_MOUSE_OVER_BUTTON, "DisplayHelp" + ctlname)
872 label.SetEventByName (IE_GUI_MOUSE_ENTER_BUTTON, "DisplayHelp" + ctlname)
873 label.SetEventByName (IE_GUI_MOUSE_LEAVE_BUTTON, "DisplayHelp" + winname)
875 return slider
878 def OptCheckbox (winname, ctlname, window, button_id, label_id, label_strref, assoc_var = None, handler = None):
879 """Standard checkbox for option windows"""
881 button = window.GetControl (button_id)
882 button.SetFlags (IE_GUI_BUTTON_CHECKBOX, OP_OR)
883 button.SetEventByName (IE_GUI_MOUSE_ENTER_BUTTON, "DisplayHelp" + ctlname)
884 button.SetEventByName (IE_GUI_MOUSE_LEAVE_BUTTON, "DisplayHelp" + winname)
885 if assoc_var:
886 button.SetVarAssoc (assoc_var, 1)
887 if GemRB.GetVar (assoc_var):
888 button.SetState (IE_GUI_BUTTON_PRESSED)
889 else:
890 button.SetState (IE_GUI_BUTTON_UNPRESSED)
891 else:
892 button.SetState (IE_GUI_BUTTON_UNPRESSED)
894 if handler:
895 button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, handler)
897 label = window.GetControl (label_id)
898 label.SetText (label_strref)
899 label.SetFlags (IE_GUI_BUTTON_NO_IMAGE, OP_SET)
900 label.SetState (IE_GUI_BUTTON_LOCKED)
901 label.SetEventByName (IE_GUI_MOUSE_ENTER_BUTTON, "DisplayHelp" + ctlname)
902 label.SetEventByName (IE_GUI_MOUSE_LEAVE_BUTTON, "DisplayHelp" + winname)
904 return button
906 def OptButton (winname, ctlname, window, button_id, label_id, label_strref):
907 """Standard subwindow button for option windows"""
908 button = window.GetControl (button_id)
909 button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "Open%sWindow" %ctlname)
910 button.SetEventByName (IE_GUI_MOUSE_ENTER_BUTTON, "DisplayHelp" + ctlname)
911 button.SetEventByName (IE_GUI_MOUSE_LEAVE_BUTTON, "DisplayHelp" + winname)
913 label = window.GetControl (label_id)
914 label.SetText (label_strref)
915 label.SetFlags (IE_GUI_BUTTON_NO_IMAGE, OP_SET)
916 label.SetState (IE_GUI_BUTTON_LOCKED)
917 label.SetEventByName (IE_GUI_MOUSE_ENTER_BUTTON, "DisplayHelp" + ctlname)
918 label.SetEventByName (IE_GUI_MOUSE_LEAVE_BUTTON, "DisplayHelp" + winname)
920 def OptDone (winname, window, button_id):
921 """Standard `Done' button for option windows"""
922 button = window.GetControl (button_id)
923 button.SetText (1403) # Done
924 button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "Open%sWindow" %winname)
925 button.SetVarAssoc ("Cancel", 0)
927 def OptCancel (winname, window, button_id):
928 """Standard `Cancel' button for option windows"""
929 button = window.GetControl (button_id)
930 button.SetText (4196) # Cancel
931 button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "Open%sWindow" %winname)
932 button.SetVarAssoc ("Cancel", 1)
934 def OptHelpText (winname, window, text_id, text_strref):
935 """Standard textarea with context help for option windows"""
936 text = window.GetControl (text_id)
937 text.SetText (text_strref)
938 return text
941 ###################################################
942 # End of file GUIOPT.py