TickHook: Fix crash when TickHook isn't set.
[gemrb.git] / gemrb / GUIScripts / bg2 / GUICG19.py
blobcb425f5820d24009cb013b21877145169efdb839
1 # GemRB - Infinity Engine Emulator
2 # Copyright (C) 2003 The GemRB Project
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 #character generation, sounds (GUICG19)
20 from ie_restype import *
21 import GemRB
23 VoiceList = 0
24 CharSoundWindow = 0
26 # the available sounds
27 SoundSequence = [ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', \
28 'm', 's', 't', 'u', 'v', '_', 'x', 'y', 'z', '0', '1', '2', \
29 '3', '4', '5', '6', '7', '8', '9']
30 SoundIndex = 0
32 def OnLoad():
33 global CharSoundWindow, VoiceList
35 GemRB.LoadWindowPack("GUICG", 640, 480)
36 CharSoundWindow=GemRB.LoadWindow(19)
38 VoiceList = CharSoundWindow.GetControl (45)
39 VoiceList.SetFlags (IE_GUI_TEXTAREA_SELECTABLE)
40 if GemRB.GetVar ("Gender")==1:
41 GemRB.SetVar ("Selected", 4)
42 else:
43 GemRB.SetVar ("Selected", 0)
45 VoiceList.SetVarAssoc ("Selected", 0)
46 RowCount=VoiceList.GetCharSounds()
48 PlayButton = CharSoundWindow.GetControl (47)
49 PlayButton.SetState (IE_GUI_BUTTON_ENABLED)
50 PlayButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, PlayPress)
51 PlayButton.SetText (17318)
53 TextArea = CharSoundWindow.GetControl (50)
54 TextArea.SetText (11315)
56 BackButton = CharSoundWindow.GetControl(10)
57 BackButton.SetText(15416)
58 BackButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
59 DoneButton = CharSoundWindow.GetControl(0)
60 DoneButton.SetText(11973)
61 DoneButton.SetFlags(IE_GUI_BUTTON_DEFAULT,OP_OR)
63 VoiceList.SetEvent(IE_GUI_TEXTAREA_ON_CHANGE, ChangeVoice)
64 DoneButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, NextPress)
65 BackButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, BackPress)
66 CharSoundWindow.SetVisible(WINDOW_VISIBLE)
67 return
69 def PlayPress():
70 global CharSoundWindow, SoundIndex, SoundSequence
72 CharSound = VoiceList.QueryText()
73 # SClassID.h -> IE_WAV_CLASS_ID = 0x00000004
74 while (not GemRB.HasResource (CharSound + SoundSequence[SoundIndex], RES_WAV)):
75 NextSound()
76 # play the sound like it was a speech, so any previous yells are quieted
77 GemRB.PlaySound (CharSound + SoundSequence[SoundIndex], 0, 0, 4)
78 NextSound()
79 return
81 def NextSound():
82 global SoundIndex, SoundSequence
83 SoundIndex += 1
84 if SoundIndex >= len(SoundSequence):
85 SoundIndex = 0
86 return
88 # When a new voice is selected, play the sounds again from the beginning of the sequence
89 def ChangeVoice():
90 global SoundIndex
91 SoundIndex = 0
92 return
94 def BackPress():
95 global CharSoundWindow
97 if CharSoundWindow:
98 CharSoundWindow.Unload()
99 GemRB.SetNextScript("GUICG13")
100 return
102 def NextPress():
103 global CharSoundWindow
105 CharSound = VoiceList.QueryText ()
106 MyChar = GemRB.GetVar ("Slot")
107 GemRB.SetPlayerSound (MyChar, CharSound)
109 if CharSoundWindow:
110 CharSoundWindow.Unload()
111 GemRB.SetNextScript("CharGen8") #name
112 return