iwd: more gcw syncing with bg2 - actonpc and dragging
[gemrb.git] / gemrb / GUIScripts / bg2 / GUICG4.py
blob850c254ec375132d333821a442205ebd2c0b7d14
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, ability (GUICG4)
20 import GemRB
21 import GUICommon
22 from ie_stats import *
23 from GUIDefines import *
25 AbilityWindow = 0
26 TextAreaControl = 0
27 DoneButton = 0
28 AbilityTable = 0
29 Abclasrq = 0
30 Abclsmod = 0
31 Abclasrq = 0
32 Abracerq = 0
33 PointsLeft = 0
34 Minimum = 0
35 Maximum = 0
36 Add = 0
37 KitIndex = 0
38 HasStrExtra = 0
39 MyChar = 0
41 def CalcLimits(Abidx):
42 global Minimum, Maximum, Add
44 Race = GUICommon.RaceTable.FindValue (3, GemRB.GetPlayerStat (MyChar, IE_RACE) )
45 RaceName = GUICommon.RaceTable.GetRowName(Race)
47 Minimum = 3
48 Maximum = 18
50 tmp = Abclasrq.GetValue(KitIndex, Abidx)
51 if tmp!=0 and tmp>Minimum:
52 Minimum = tmp
54 Race = Abracerq.GetRowIndex(RaceName)
55 tmp = Abracerq.GetValue(Race, Abidx*2)
56 if tmp!=0 and tmp>Minimum:
57 Minimum = tmp
59 tmp = Abracerq.GetValue(Race, Abidx*2+1)
60 if tmp!=0 and tmp>Maximum:
61 Maximum = tmp
63 Race = Abracead.GetRowIndex(RaceName)
64 Add = Abracead.GetValue(Race, Abidx) + Abclsmod.GetValue(KitIndex, Abidx)
65 Maximum = Maximum + Add
66 Minimum = Minimum + Add
67 if Minimum<1:
68 Minimum=1
69 if Maximum>25:
70 Maximum=25
72 return
74 def RollPress():
75 global Minimum, Maximum, Add, HasStrExtra, PointsLeft
77 GemRB.SetVar("Ability",0)
78 GemRB.SetVar("Ability -1",0)
79 PointsLeft = 0
80 SumLabel = AbilityWindow.GetControl(0x10000002)
81 SumLabel.SetText("0")
82 SumLabel.SetUseRGB(1)
84 if HasStrExtra:
85 e = GemRB.Roll(1,100,0)
86 else:
87 e = 0
88 GemRB.SetVar("StrExtra", e)
89 for i in range(6):
90 dice = 3
91 size = 5
92 CalcLimits(i)
93 v = GemRB.Roll(dice, size, Add+3)
94 if v<Minimum:
95 v = Minimum
96 if v>Maximum:
97 v = Maximum
98 GemRB.SetVar("Ability "+str(i), v )
99 Label = AbilityWindow.GetControl(0x10000003+i)
100 if i==0 and v==18 and HasStrExtra:
101 Label.SetText("18/"+str(e) )
102 else:
103 Label.SetText(str(v) )
104 Label.SetUseRGB(1)
105 return
107 def OnLoad():
108 global AbilityWindow, TextAreaControl, DoneButton
109 global PointsLeft, HasStrExtra
110 global AbilityTable, Abclasrq, Abclsmod, Abracerq, Abracead
111 global KitIndex, Minimum, Maximum, MyChar
113 Abracead = GemRB.LoadTable("ABRACEAD")
114 Abclsmod = GemRB.LoadTable("ABCLSMOD")
115 Abclasrq = GemRB.LoadTable("ABCLASRQ")
116 Abracerq = GemRB.LoadTable("ABRACERQ")
118 MyChar = GemRB.GetVar ("Slot")
119 Kit = GUICommon.GetKitIndex (MyChar)
120 Class = GemRB.GetPlayerStat (MyChar, IE_CLASS)
121 Class = GUICommon.ClassTable.FindValue (5, Class)
122 if Kit == 0:
123 KitName = GUICommon.ClassTable.GetRowName(Class)
124 else:
125 #rowname is just a number, first value row what we need here
126 KitName = GUICommon.KitListTable.GetValue(Kit, 0)
128 #if the class uses the warrior table for saves, then it may have the extra strength
129 if GUICommon.ClassTable.GetValue(Class, 3)=="SAVEWAR":
130 HasStrExtra=1
131 else:
132 HasStrExtra=0
134 KitIndex = Abclasrq.GetRowIndex(KitName)
136 GemRB.LoadWindowPack("GUICG", 640, 480)
137 AbilityTable = GemRB.LoadTable("ability")
138 AbilityWindow = GemRB.LoadWindow(4)
140 RerollButton = AbilityWindow.GetControl(2)
141 RerollButton.SetText(11982)
142 StoreButton = AbilityWindow.GetControl(37)
143 StoreButton.SetText(17373)
144 RecallButton = AbilityWindow.GetControl(38)
145 RecallButton.SetText(17374)
147 BackButton = AbilityWindow.GetControl(36)
148 BackButton.SetText(15416)
149 BackButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
150 DoneButton = AbilityWindow.GetControl(0)
151 DoneButton.SetText(11973)
152 DoneButton.SetFlags(IE_GUI_BUTTON_DEFAULT,OP_OR)
153 DoneButton.SetState(IE_GUI_BUTTON_ENABLED)
155 RollPress()
156 StorePress()
157 for i in range(6):
158 Label = AbilityWindow.GetControl(i+0x10000009)
159 Label.SetEvent(IE_GUI_LABEL_ON_PRESS, eval("OverPress"+str(i)))
160 Button = AbilityWindow.GetControl(i+30)
161 Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, JustPress)
162 Button.SetEvent(IE_GUI_MOUSE_LEAVE_BUTTON, EmptyPress)
163 Button.SetVarAssoc("Ability", i)
165 Button = AbilityWindow.GetControl(i*2+16)
166 Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, LeftPress)
167 Button.SetVarAssoc("Ability", i )
169 Button = AbilityWindow.GetControl(i*2+17)
170 Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, RightPress)
171 Button.SetVarAssoc("Ability", i )
173 TextAreaControl = AbilityWindow.GetControl(29)
174 TextAreaControl.SetText(17247)
176 StoreButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, StorePress)
177 RecallButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, RecallPress)
178 RerollButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, RollPress)
179 DoneButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, NextPress)
180 BackButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, BackPress)
181 AbilityWindow.SetVisible(WINDOW_VISIBLE)
182 GemRB.SetRepeatClickFlags(GEM_RK_DISABLE, OP_NAND)
183 return
185 def RightPress():
186 global PointsLeft
188 Abidx = GemRB.GetVar("Ability")
189 Ability = GemRB.GetVar("Ability "+str(Abidx) )
190 CalcLimits(Abidx)
191 GemRB.SetToken("MINIMUM",str(Minimum) )
192 GemRB.SetToken("MAXIMUM",str(Maximum) )
193 TextAreaControl.SetText(AbilityTable.GetValue(Abidx, 1) )
194 if Ability<=Minimum:
195 return
196 GemRB.SetVar("Ability "+str(Abidx), Ability-1)
197 PointsLeft = PointsLeft + 1
198 GemRB.SetVar("Ability -1",PointsLeft)
199 SumLabel = AbilityWindow.GetControl(0x10000002)
200 SumLabel.SetText(str(PointsLeft) )
201 Label = AbilityWindow.GetControl(0x10000003+Abidx)
202 StrExtra = GemRB.GetVar("StrExtra")
203 if Abidx==0 and Ability==19 and StrExtra:
204 Label.SetText("18/"+str(StrExtra) )
205 else:
206 Label.SetText(str(Ability-1) )
207 return
209 def JustPress():
210 Abidx = GemRB.GetVar("Ability")
211 Ability = GemRB.GetVar("Ability "+str(Abidx) )
212 CalcLimits(Abidx)
213 GemRB.SetToken("MINIMUM",str(Minimum) )
214 GemRB.SetToken("MAXIMUM",str(Maximum) )
215 TextAreaControl.SetText(AbilityTable.GetValue(Abidx, 1) )
216 return
218 def LeftPress():
219 global PointsLeft
221 Abidx = GemRB.GetVar("Ability")
222 Ability = GemRB.GetVar("Ability "+str(Abidx) )
223 CalcLimits(Abidx)
224 GemRB.SetToken("MINIMUM",str(Minimum) )
225 GemRB.SetToken("MAXIMUM",str(Maximum) )
226 TextAreaControl.SetText(AbilityTable.GetValue(Abidx, 1) )
227 if PointsLeft == 0:
228 return
229 if Ability>=Maximum: #should be more elaborate
230 return
231 GemRB.SetVar("Ability "+str(Abidx), Ability+1)
232 PointsLeft = PointsLeft - 1
233 GemRB.SetVar("Ability -1",PointsLeft)
234 SumLabel = AbilityWindow.GetControl(0x10000002)
235 SumLabel.SetText(str(PointsLeft) )
236 Label = AbilityWindow.GetControl(0x10000003+Abidx)
237 StrExtra = GemRB.GetVar("StrExtra")
238 if Abidx==0 and Ability==17 and HasStrExtra==1:
239 Label.SetText("18/%02d"%(StrExtra) )
240 else:
241 Label.SetText(str(Ability+1) )
242 return
244 def EmptyPress():
245 TextAreaControl = AbilityWindow.GetControl(29)
246 TextAreaControl.SetText(17247)
247 return
249 def StorePress():
250 GemRB.SetVar("StoredStrExtra",GemRB.GetVar("StrExtra") )
251 for i in range(-1,6):
252 GemRB.SetVar("Stored "+str(i),GemRB.GetVar("Ability "+str(i) ) )
253 return
255 def RecallPress():
256 global PointsLeft
258 e=GemRB.GetVar("StoredStrExtra")
259 GemRB.SetVar("StrExtra",e)
260 for i in range(-1,6):
261 v = GemRB.GetVar("Stored "+str(i) )
262 GemRB.SetVar("Ability "+str(i), v)
263 Label = AbilityWindow.GetControl(0x10000003+i)
264 if i==0 and v==18 and HasStrExtra==1:
265 Label.SetText("18/"+str(e) )
266 else:
267 Label.SetText(str(v) )
269 PointsLeft = GemRB.GetVar("Ability -1")
270 return
272 def BackPress():
273 if AbilityWindow:
274 AbilityWindow.Unload()
275 GemRB.SetNextScript("CharGen5")
276 GemRB.SetVar("StrExtra",0)
277 for i in range(-1,6):
278 GemRB.SetVar("Ability "+str(i),0) #scrapping the abilities
279 GemRB.SetRepeatClickFlags(GEM_RK_DISABLE, OP_OR)
280 return
282 def NextPress():
283 if AbilityWindow:
284 AbilityWindow.Unload()
285 AbilityTable = GemRB.LoadTable ("ability")
286 AbilityCount = AbilityTable.GetRowCount ()
288 # print our diagnostic as we loop (so as not to duplicate)
289 for i in range (AbilityCount):
290 StatID = AbilityTable.GetValue (i, 3)
291 StatName = AbilityTable.GetRowName (i)
292 StatValue = GemRB.GetVar ("Ability "+str(i))
293 GemRB.SetPlayerStat (MyChar, StatID, StatValue)
294 print "\t",StatName,":\t", StatValue
296 GemRB.SetPlayerStat (MyChar, IE_STREXTRA, GemRB.GetVar ("StrExtra"))
297 print "\tSTREXTRA:\t",GemRB.GetVar ("StrExtra")
299 GemRB.SetRepeatClickFlags(GEM_RK_DISABLE, OP_OR)
300 GemRB.SetNextScript("CharGen6")
301 return
303 def OverPress0():
304 Ability = GemRB.GetVar("Ability 0")
305 CalcLimits(0)
306 GemRB.SetToken("MINIMUM",str(Minimum) )
307 GemRB.SetToken("MAXIMUM",str(Maximum) )
308 TextAreaControl.SetText(AbilityTable.GetValue(0, 1) )
309 return
311 def OverPress1():
312 Ability = GemRB.GetVar("Ability 1")
313 CalcLimits(1)
314 GemRB.SetToken("MINIMUM",str(Minimum) )
315 GemRB.SetToken("MAXIMUM",str(Maximum) )
316 TextAreaControl.SetText(AbilityTable.GetValue(1, 1) )
317 return
319 def OverPress2():
320 Ability = GemRB.GetVar("Ability 2")
321 CalcLimits(2)
322 GemRB.SetToken("MINIMUM",str(Minimum) )
323 GemRB.SetToken("MAXIMUM",str(Maximum) )
324 TextAreaControl.SetText(AbilityTable.GetValue(2, 1) )
325 return
327 def OverPress3():
328 Ability = GemRB.GetVar("Ability 3")
329 CalcLimits(3)
330 GemRB.SetToken("MINIMUM",str(Minimum) )
331 GemRB.SetToken("MAXIMUM",str(Maximum) )
332 TextAreaControl.SetText(AbilityTable.GetValue(3, 1) )
333 return
335 def OverPress4():
336 Ability = GemRB.GetVar("Ability 4")
337 CalcLimits(4)
338 GemRB.SetToken("MINIMUM",str(Minimum) )
339 GemRB.SetToken("MAXIMUM",str(Maximum) )
340 TextAreaControl.SetText(AbilityTable.GetValue(4, 1) )
341 return
343 def OverPress5():
344 Ability = GemRB.GetVar("Ability 5")
345 CalcLimits(5)
346 GemRB.SetToken("MINIMUM",str(Minimum) )
347 GemRB.SetToken("MAXIMUM",str(Maximum) )
348 TextAreaControl.SetText(AbilityTable.GetValue(5, 1) )
349 return