TickHook: Fix crash when TickHook isn't set.
[gemrb.git] / gemrb / GUIScripts / bg2 / GUICG13.py
blob5d3af107cc7ab863495e856034c54cd15d765a08
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, color (GUICG13)
20 import GemRB
21 import CommonTables
22 from GUIDefines import *
23 from ie_stats import *
25 global IE_ANIM_ID
26 ColorTable = 0
27 ColorWindow = 0
28 ColorPicker = 0
29 DoneButton = 0
30 ColorIndex = 0
31 PickedColor = 0
32 HairButton = 0
33 SkinButton = 0
34 MajorButton = 0
35 MinorButton = 0
36 HairColor = 0
37 SkinColor = 0
38 MajorColor = 0
39 MinorColor = 0
40 PDollButton = 0
41 MyChar = 0
42 IE_ANIM_ID = 206
44 def RefreshPDoll():
45 AnimID = 0x6000
46 table = GemRB.LoadTable("avprefr")
47 Race = GemRB.GetPlayerStat (MyChar, IE_RACE)
48 AnimID = AnimID+table.GetValue(Race, 0)
49 table = GemRB.LoadTable("avprefc")
50 Class = GemRB.GetPlayerStat (MyChar, IE_CLASS)
51 AnimID = AnimID+table.GetValue(Class, 0)
52 table = GemRB.LoadTable("avprefg")
53 Gender = GemRB.GetPlayerStat (MyChar, IE_SEX)
54 AnimID = AnimID+table.GetValue(Gender,0)
55 ResRef = CommonTables.Pdolls.GetValue(hex(AnimID), "LEVEL1")
57 PDollButton.SetPLT(ResRef, 0, MinorColor, MajorColor, SkinColor, 0, 0, HairColor, 0)
58 return
60 def OnLoad():
61 global ColorWindow, DoneButton, PDollButton, ColorTable
62 global HairButton, SkinButton, MajorButton, MinorButton
63 global HairColor, SkinColor, MajorColor, MinorColor
64 global MyChar
66 GemRB.LoadWindowPack("GUICG", 640, 480)
67 ColorWindow=GemRB.LoadWindow(13)
69 MyChar = GemRB.GetVar ("Slot")
70 ColorTable = GemRB.LoadTable("clowncol")
71 #set these colors to some default
72 PortraitTable = GemRB.LoadTable("pictures")
73 PortraitName = GemRB.GetToken("LargePortrait")
74 PortraitName = PortraitName[0:len(PortraitName)-1]
75 PortraitIndex = PortraitTable.GetRowIndex(PortraitName)
76 if PortraitIndex<0:
77 HairColor=PortraitTable.GetValue(0,1)
78 SkinColor=PortraitTable.GetValue(0,2)
79 MinorColor=PortraitTable.GetValue(0,3)
80 MajorColor=PortraitTable.GetValue(0,4)
81 else:
82 HairColor=PortraitTable.GetValue(PortraitIndex,1)
83 SkinColor=PortraitTable.GetValue(PortraitIndex,2)
84 MinorColor=PortraitTable.GetValue(PortraitIndex,3)
85 MajorColor=PortraitTable.GetValue(PortraitIndex,4)
87 PDollButton = ColorWindow.GetControl(1)
88 PDollButton.SetState (IE_GUI_BUTTON_LOCKED)
89 PDollButton.SetFlags(IE_GUI_BUTTON_PICTURE,OP_OR)
91 HairButton = ColorWindow.GetControl(2)
92 HairButton.SetFlags(IE_GUI_BUTTON_PICTURE,OP_OR)
93 HairButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, HairPress)
94 HairButton.SetBAM("COLGRAD", 1, 0, HairColor)
96 SkinButton = ColorWindow.GetControl(3)
97 SkinButton.SetFlags(IE_GUI_BUTTON_PICTURE,OP_OR)
98 SkinButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, SkinPress)
99 SkinButton.SetBAM("COLGRAD", 1, 0, SkinColor)
101 MajorButton = ColorWindow.GetControl(5)
102 MajorButton.SetFlags(IE_GUI_BUTTON_PICTURE,OP_OR)
103 MajorButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, MajorPress)
104 MajorButton.SetBAM("COLGRAD", 1, 0, MinorColor)
106 MinorButton = ColorWindow.GetControl(4)
107 MinorButton.SetFlags(IE_GUI_BUTTON_PICTURE,OP_OR)
108 MinorButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, MinorPress)
109 MinorButton.SetBAM("COLGRAD", 1, 0, MajorColor)
111 BackButton = ColorWindow.GetControl(13)
112 BackButton.SetText(15416)
113 BackButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
114 DoneButton = ColorWindow.GetControl(0)
115 DoneButton.SetText(11973)
116 DoneButton.SetFlags(IE_GUI_BUTTON_DEFAULT,OP_OR)
118 DoneButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, NextPress)
119 BackButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, BackPress)
120 RefreshPDoll()
121 ColorWindow.SetVisible(WINDOW_VISIBLE)
122 return
124 def DonePress():
125 global HairColor, SkinColor, MajorColor, MinorColor
127 if ColorPicker:
128 ColorPicker.Unload()
129 ColorWindow.SetVisible(WINDOW_VISIBLE)
130 PickedColor=ColorTable.GetValue(ColorIndex, GemRB.GetVar("Selected"))
131 if ColorIndex==0:
132 HairColor=PickedColor
133 HairButton.SetBAM("COLGRAD", 1, 0, HairColor)
134 RefreshPDoll()
135 return
136 if ColorIndex==1:
137 SkinColor=PickedColor
138 SkinButton.SetBAM("COLGRAD", 1, 0, SkinColor)
139 RefreshPDoll()
140 return
141 if ColorIndex==2:
142 MinorColor=PickedColor
143 MajorButton.SetBAM("COLGRAD", 1, 0, MinorColor)
144 RefreshPDoll()
145 return
147 MajorColor=PickedColor
148 MinorButton.SetBAM("COLGRAD", 1, 0, MajorColor)
149 RefreshPDoll()
150 return
152 def GetColor():
153 global ColorPicker
155 ColorPicker=GemRB.LoadWindow(14)
156 GemRB.SetVar("Selected",-1)
157 for i in range(34):
158 Button = ColorPicker.GetControl(i)
159 Button.SetState(IE_GUI_BUTTON_DISABLED)
160 Button.SetFlags(IE_GUI_BUTTON_PICTURE|IE_GUI_BUTTON_RADIOBUTTON,OP_OR)
162 Selected = -1
163 for i in range(34):
164 MyColor = ColorTable.GetValue(ColorIndex, i)
165 if MyColor == "*":
166 break
167 Button = ColorPicker.GetControl(i)
168 Button.SetBAM("COLGRAD", 2, 0, MyColor)
169 if PickedColor == MyColor:
170 GemRB.SetVar("Selected",i)
171 Selected = i
172 Button.SetState(IE_GUI_BUTTON_ENABLED)
173 Button.SetVarAssoc("Selected",i)
174 Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, DonePress)
176 ColorPicker.SetVisible(WINDOW_VISIBLE)
177 return
179 def HairPress():
180 global ColorIndex, PickedColor
182 ColorWindow.SetVisible(WINDOW_INVISIBLE)
183 ColorIndex = 0
184 PickedColor = HairColor
185 GetColor()
186 return
188 def SkinPress():
189 global ColorIndex, PickedColor
191 ColorWindow.SetVisible(WINDOW_INVISIBLE)
192 ColorIndex = 1
193 PickedColor = SkinColor
194 GetColor()
195 return
197 def MajorPress():
198 global ColorIndex, PickedColor
200 ColorWindow.SetVisible(WINDOW_INVISIBLE)
201 ColorIndex = 2
202 PickedColor = MinorColor
203 GetColor()
204 return
206 def MinorPress():
207 global ColorIndex, PickedColor
209 ColorWindow.SetVisible(WINDOW_INVISIBLE)
210 ColorIndex = 3
211 PickedColor = MajorColor
212 GetColor()
213 return
215 def BackPress():
216 if ColorWindow:
217 ColorWindow.Unload()
218 GemRB.SetNextScript("CharGen7")
219 return
221 def NextPress():
222 if ColorWindow:
223 ColorWindow.Unload()
224 GemRB.SetVar("HairColor",HairColor)
225 GemRB.SetVar("SkinColor",SkinColor)
226 GemRB.SetVar("MinorColor",MinorColor)
227 GemRB.SetVar("MajorColor",MajorColor)
228 GemRB.SetNextScript("GUICG19") #sounds
229 return