TickHook: Fix crash when TickHook isn't set.
[gemrb.git] / gemrb / GUIScripts / bg2 / GUICG12.py
blob22d4a53a97a4f0476309ae866fe569931a3435de
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, appearance (GUICG12)
20 import GemRB
22 AppearanceWindow = 0
23 CustomWindow = 0
24 PortraitButton = 0
25 PortraitsTable = 0
26 LastPortrait = 0
27 Gender = 0
29 def SetPicture ():
30 global PortraitsTable, LastPortrait
32 PortraitName = PortraitsTable.GetRowName (LastPortrait)+"L"
33 PortraitButton.SetPicture (PortraitName, "NOPORTLG")
34 return
36 def OnLoad():
37 global AppearanceWindow, PortraitButton, PortraitsTable, LastPortrait
38 global Gender
40 Gender=GemRB.GetVar ("Gender")
42 GemRB.LoadWindowPack ("GUICG", 640, 480)
43 AppearanceWindow = GemRB.LoadWindow (11)
45 #Load the Portraits Table
46 PortraitsTable = GemRB.LoadTable ("PICTURES")
47 PortraitsStart = PortraitsTable.FindValue (0, 2)
48 FemaleCount = PortraitsTable.GetRowCount () - PortraitsStart + 1
49 if Gender == 2:
50 LastPortrait = GemRB.Roll (1, FemaleCount, PortraitsStart-1)
51 else:
52 LastPortrait = GemRB.Roll (1, PortraitsTable.GetRowCount()-FemaleCount, 0)
54 TextAreaControl = AppearanceWindow.GetControl (7)
55 TextAreaControl.SetText ("") # why is this here?
57 PortraitButton = AppearanceWindow.GetControl (1)
58 PortraitButton.SetFlags (IE_GUI_BUTTON_PICTURE|IE_GUI_BUTTON_NO_IMAGE,OP_SET)
59 PortraitButton.SetState (IE_GUI_BUTTON_LOCKED)
61 LeftButton = AppearanceWindow.GetControl (2)
62 RightButton = AppearanceWindow.GetControl (3)
64 BackButton = AppearanceWindow.GetControl (5)
65 BackButton.SetText (15416)
66 BackButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
68 CustomButton = AppearanceWindow.GetControl (6)
69 CustomButton.SetText (17545)
71 DoneButton = AppearanceWindow.GetControl (0)
72 DoneButton.SetText (11973)
73 DoneButton.SetFlags (IE_GUI_BUTTON_DEFAULT,OP_OR)
75 RightButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, RightPress)
76 LeftButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, LeftPress)
77 BackButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, BackPress)
78 CustomButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, CustomPress)
79 DoneButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, NextPress)
81 Flag = False
82 while True:
83 if PortraitsTable.GetValue (LastPortrait, 0) == Gender:
84 SetPicture ()
85 break
86 LastPortrait = LastPortrait + 1
87 if LastPortrait >= PortraitsTable.GetRowCount ():
88 LastPortrait = 0
89 if Flag:
90 SetPicture ()
91 break
92 Flag = True
94 AppearanceWindow.SetVisible (WINDOW_VISIBLE)
95 return
97 def RightPress():
98 global LastPortrait
99 while True:
100 LastPortrait = LastPortrait + 1
101 if LastPortrait >= PortraitsTable.GetRowCount ():
102 LastPortrait = 0
103 if PortraitsTable.GetValue (LastPortrait, 0) == Gender:
104 SetPicture ()
105 return
107 def LeftPress():
108 global LastPortrait
109 while True:
110 LastPortrait = LastPortrait - 1
111 if LastPortrait < 0:
112 LastPortrait = PortraitsTable.GetRowCount ()-1
113 if PortraitsTable.GetValue (LastPortrait, 0) == Gender:
114 SetPicture ()
115 return
117 def BackPress():
118 if AppearanceWindow:
119 AppearanceWindow.Unload ()
120 GemRB.SetNextScript ("GUICG1")
121 GemRB.SetVar ("Gender",0) #scrapping the gender value
122 return
124 def CustomDone():
125 Window = CustomWindow
127 Portrait = PortraitList1.QueryText ()
128 GemRB.SetToken ("LargePortrait", Portrait)
129 Portrait = PortraitList2.QueryText ()
130 GemRB.SetToken ("SmallPortrait", Portrait)
131 if Window:
132 Window.Unload ()
133 if AppearanceWindow:
134 AppearanceWindow.Unload ()
135 GemRB.SetNextScript ("CharGen2")
136 return
138 def CustomAbort():
139 if CustomWindow:
140 CustomWindow.Unload ()
141 return
143 def LargeCustomPortrait():
144 Window = CustomWindow
146 Portrait = PortraitList1.QueryText ()
147 #small hack
148 if GemRB.GetVar ("Row1") == RowCount1:
149 return
151 Label = Window.GetControl (0x10000007)
152 Label.SetText (Portrait)
154 Button = Window.GetControl (6)
155 if Portrait=="":
156 Portrait = "NOPORTMD"
157 Button.SetState (IE_GUI_BUTTON_DISABLED)
158 else:
159 if PortraitList2.QueryText ()!="":
160 Button.SetState (IE_GUI_BUTTON_ENABLED)
162 Button = Window.GetControl (0)
163 Button.SetPicture (Portrait, "NOPORTMD")
164 return
166 def SmallCustomPortrait():
167 Window = CustomWindow
169 Portrait = PortraitList2.QueryText ()
170 #small hack
171 if GemRB.GetVar ("Row2") == RowCount2:
172 return
174 Label = Window.GetControl (0x10000008)
175 Label.SetText (Portrait)
177 Button = Window.GetControl (6)
178 if Portrait=="":
179 Portrait = "NOPORTSM"
180 Button.SetState (IE_GUI_BUTTON_DISABLED)
181 else:
182 if PortraitList1.QueryText ()!="":
183 Button.SetState (IE_GUI_BUTTON_ENABLED)
185 Button = Window.GetControl (1)
186 Button.SetPicture (Portrait, "NOPORTSM")
187 return
189 def CustomPress():
190 global PortraitList1, PortraitList2
191 global RowCount1, RowCount2
192 global CustomWindow
194 CustomWindow = Window = GemRB.LoadWindow (18)
195 PortraitList1 = Window.GetControl (2)
196 RowCount1 = PortraitList1.GetPortraits (0)
197 PortraitList1.SetEvent (IE_GUI_TEXTAREA_ON_CHANGE, LargeCustomPortrait)
198 GemRB.SetVar ("Row1", RowCount1)
199 PortraitList1.SetVarAssoc ("Row1",RowCount1)
201 PortraitList2 = Window.GetControl (4)
202 RowCount2 = PortraitList2.GetPortraits (1)
203 PortraitList2.SetEvent (IE_GUI_TEXTAREA_ON_CHANGE, SmallCustomPortrait)
204 GemRB.SetVar ("Row2", RowCount2)
205 PortraitList2.SetVarAssoc ("Row2",RowCount2)
207 Button = Window.GetControl (6)
208 Button.SetText (11973)
209 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, CustomDone)
210 Button.SetState (IE_GUI_BUTTON_DISABLED)
212 Button = Window.GetControl (7)
213 Button.SetText (15416)
214 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, CustomAbort)
216 Button = Window.GetControl (0)
217 PortraitName = PortraitsTable.GetRowName (LastPortrait)+"M"
218 Button.SetPicture (PortraitName, "NOPORTMD")
219 Button.SetState (IE_GUI_BUTTON_LOCKED)
221 Button = Window.GetControl (1)
222 PortraitName = PortraitsTable.GetRowName (LastPortrait)+"S"
223 Button.SetPicture (PortraitName, "NOPORTSM")
224 Button.SetState (IE_GUI_BUTTON_LOCKED)
226 Window.ShowModal (MODAL_SHADOW_NONE)
227 return
229 def NextPress():
230 if AppearanceWindow:
231 AppearanceWindow.Unload ()
232 PortraitTable = GemRB.LoadTable ("pictures")
233 PortraitName = PortraitTable.GetRowName (LastPortrait )
234 GemRB.SetToken ("SmallPortrait", PortraitName+"S")
235 GemRB.SetToken ("LargePortrait", PortraitName+"M")
236 GemRB.SetNextScript ("CharGen2") #Before race
237 return