TickHook: Fix crash when TickHook isn't set.
[gemrb.git] / gemrb / GUIScripts / iwd / CharGen.py
blob16c56909524d7edb546b535e580d78df456e81bb
1 # -*-python-*-
2 # GemRB - Infinity Engine Emulator
3 # Copyright (C) 2003-2005 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 #Character Generation
23 ###################################################
25 import GemRB
26 from GUIDefines import *
27 from ie_stats import *
28 from ie_spells import LS_MEMO
29 import GUICommon
30 import CommonTables
31 import LUSkillsSelection
33 CharGenWindow = 0
34 CharGenState = 0
35 TextArea = 0
36 PortraitButton = 0
37 AcceptButton = 0
39 GenderButton = 0
40 GenderWindow = 0
41 GenderTextArea = 0
42 GenderDoneButton = 0
44 Portrait = 0
45 PortraitsTable = 0
46 PortraitPortraitButton = 0
48 RaceButton = 0
49 RaceWindow = 0
50 RaceTextArea = 0
51 RaceDoneButton = 0
53 ClassButton = 0
54 ClassWindow = 0
55 ClassTextArea = 0
56 ClassDoneButton = 0
58 ClassMultiWindow = 0
59 ClassMultiTextArea = 0
60 ClassMultiDoneButton = 0
62 KitTable = 0
63 KitWindow = 0
64 KitTextArea = 0
65 KitDoneButton = 0
67 AlignmentButton = 0
68 AlignmentWindow = 0
69 AlignmentTable = 0
70 AlignmentTextArea = 0
71 AlignmentDoneButton = 0
73 AbilitiesButton = 0
74 AbilitiesWindow = 0
75 AbilitiesTable = 0
76 AbilitiesRaceAddTable = 0
77 AbilitiesRaceReqTable = 0
78 AbilitiesClassReqTable = 0
79 AbilitiesMinimum = 0
80 AbilitiesMaximum = 0
81 AbilitiesModifier = 0
82 AbilitiesTextArea = 0
83 AbilitiesRecallButton = 0
84 AbilitiesDoneButton = 0
86 SkillsButton = 0
87 SkillsWindow = 0
88 SkillsTable = 0
89 SkillsTextArea = 0
90 SkillsDoneButton = 0
91 SkillsPointsLeft = 0
92 SkillsState = 0
94 RacialEnemyButton = 0
95 RacialEnemyWindow = 0
96 RacialEnemyTable = 0
97 RacialEnemyTextArea = 0
98 RacialEnemyDoneButton = 0
100 ProficienciesWindow = 0
101 ProficienciesTable = 0
102 ProfsMaxTable = 0
103 ProficienciesTextArea = 0
104 ProficienciesDoneButton = 0
105 ProficienciesPointsLeft = 0
107 MageSpellsWindow = 0
108 MageSpellsTextArea = 0
109 MageSpellsDoneButton = 0
110 MageSpellsSelectPointsLeft = 0
112 MageMemorizeWindow = 0
113 MageMemorizeTextArea = 0
114 MageMemorizeDoneButton = 0
115 MageMemorizePointsLeft = 0
117 PriestMemorizeWindow = 0
118 PriestMemorizeTextArea = 0
119 PriestMemorizeDoneButton = 0
120 PriestMemorizePointsLeft = 0
122 AppearanceButton = 0
123 AppearanceWindow = 0
124 AppearanceTable = 0
125 AppearanceAvatarButton = 0
126 AppearanceHairButton = 0
127 AppearanceSkinButton = 0
128 AppearanceMajorButton = 0
129 AppearanceMinorButton = 0
130 HairColor = 0
131 SkinColor = 0
132 MajorColor = 0
133 MinorColor = 0
135 CharSoundWindow = 0
136 CharSoundTable = 0
137 CharSoundStrings = 0
139 BiographyButton = 0
140 BiographyWindow = 0
141 BiographyField = 0
143 NameButton = 0
144 NameWindow = 0
145 NameField = 0
146 NameDoneButton = 0
148 SoundIndex = 0
149 VerbalConstants = None
150 HasStrExtra = 0
151 MyChar = 0
153 def OnLoad():
154 global CharGenWindow, CharGenState, TextArea, PortraitButton, AcceptButton
155 global GenderButton, RaceButton, ClassButton, AlignmentButton
156 global AbilitiesButton, SkillsButton, AppearanceButton, BiographyButton, NameButton
157 global KitTable, ProficienciesTable, AlignmentTable, RacialEnemyTable
158 global AbilitiesTable, SkillsTable, PortraitsTable
159 global MyChar
161 KitTable = GemRB.LoadTable ("magesch")
162 ProficienciesTable = GemRB.LoadTable ("weapprof")
163 AlignmentTable = GemRB.LoadTable ("aligns")
164 RacialEnemyTable = GemRB.LoadTable ("haterace")
165 AbilitiesTable = GemRB.LoadTable ("ability")
166 SkillsTable = GemRB.LoadTable ("skills")
167 PortraitsTable = GemRB.LoadTable ("pictures")
168 GemRB.LoadWindowPack ("GUICG", 640, 480)
169 CharGenWindow = GemRB.LoadWindow (0)
170 CharGenWindow.SetFrame ()
171 CharGenState = 0
172 MyChar = GemRB.GetVar ("Slot")
174 GenderButton = CharGenWindow.GetControl (0)
175 GenderButton.SetState (IE_GUI_BUTTON_ENABLED)
176 GenderButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
177 GenderButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, GenderPress)
178 GenderButton.SetText (11956)
180 RaceButton = CharGenWindow.GetControl (1)
181 RaceButton.SetState (IE_GUI_BUTTON_DISABLED)
182 RaceButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, RacePress)
183 RaceButton.SetText (11957)
185 ClassButton = CharGenWindow.GetControl (2)
186 ClassButton.SetState (IE_GUI_BUTTON_DISABLED)
187 ClassButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, ClassPress)
188 ClassButton.SetText (11959)
190 AlignmentButton = CharGenWindow.GetControl (3)
191 AlignmentButton.SetState (IE_GUI_BUTTON_DISABLED)
192 AlignmentButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, AlignmentPress)
193 AlignmentButton.SetText (11958)
195 AbilitiesButton = CharGenWindow.GetControl (4)
196 AbilitiesButton.SetState (IE_GUI_BUTTON_DISABLED)
197 AbilitiesButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, AbilitiesPress)
198 AbilitiesButton.SetText (11960)
200 SkillsButton = CharGenWindow.GetControl (5)
201 SkillsButton.SetState (IE_GUI_BUTTON_DISABLED)
202 SkillsButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, SkillsPress)
203 SkillsButton.SetText (11983)
205 AppearanceButton = CharGenWindow.GetControl (6)
206 AppearanceButton.SetState (IE_GUI_BUTTON_DISABLED)
207 AppearanceButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, AppearancePress)
208 AppearanceButton.SetText (11961)
210 BiographyButton = CharGenWindow.GetControl (16)
211 BiographyButton.SetState (IE_GUI_BUTTON_DISABLED)
212 BiographyButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, BiographyPress)
213 BiographyButton.SetText (18003)
215 NameButton = CharGenWindow.GetControl (7)
216 NameButton.SetState (IE_GUI_BUTTON_DISABLED)
217 NameButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, NamePress)
218 NameButton.SetText (11963)
220 BackButton = CharGenWindow.GetControl (11)
221 BackButton.SetState (IE_GUI_BUTTON_ENABLED)
222 BackButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, BackPress)
223 BackButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
225 PortraitButton = CharGenWindow.GetControl (12)
226 PortraitButton.SetFlags (IE_GUI_BUTTON_PICTURE|IE_GUI_BUTTON_NO_IMAGE, OP_SET)
227 PortraitButton.SetState (IE_GUI_BUTTON_LOCKED)
229 ImportButton = CharGenWindow.GetControl (13)
230 ImportButton.SetState (IE_GUI_BUTTON_ENABLED)
231 ImportButton.SetText (13955)
232 ImportButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, ImportPress)
234 CancelButton = CharGenWindow.GetControl (15)
235 CancelButton.SetState (IE_GUI_BUTTON_ENABLED)
236 CancelButton.SetText (13727)
237 CancelButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, CancelPress)
239 AcceptButton = CharGenWindow.GetControl (8)
240 AcceptButton.SetState (IE_GUI_BUTTON_DISABLED)
241 AcceptButton.SetText (11962)
242 AcceptButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, AcceptPress)
244 TextArea = CharGenWindow.GetControl (9)
245 TextArea.SetText (16575)
247 CharGenWindow.SetVisible (WINDOW_VISIBLE)
248 return
250 def BackPress():
251 global CharGenWindow, CharGenState, SkillsState
252 global GenderButton, RaceButton, ClassButton, AlignmentButton, AbilitiesButton, SkillsButton, AppearanceButton, BiographyButton, NameButton
254 if CharGenState > 0:
255 CharGenState = CharGenState - 1
256 else:
257 CancelPress()
258 return
260 if CharGenState > 6:
261 CharGenState = 6
262 GemRB.SetToken ("CHARNAME","")
264 if CharGenState == 0:
265 RaceButton.SetState (IE_GUI_BUTTON_DISABLED)
266 RaceButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_NAND)
267 GenderButton.SetState (IE_GUI_BUTTON_ENABLED)
268 GenderButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
269 elif CharGenState == 1:
270 ClassButton.SetState (IE_GUI_BUTTON_DISABLED)
271 ClassButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_NAND)
272 RaceButton.SetState (IE_GUI_BUTTON_ENABLED)
273 RaceButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
274 elif CharGenState == 2:
275 AlignmentButton.SetState (IE_GUI_BUTTON_DISABLED)
276 AlignmentButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_NAND)
277 ClassButton.SetState (IE_GUI_BUTTON_ENABLED)
278 ClassButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
279 elif CharGenState == 3:
280 AbilitiesButton.SetState (IE_GUI_BUTTON_DISABLED)
281 AbilitiesButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_NAND)
282 AlignmentButton.SetState (IE_GUI_BUTTON_ENABLED)
283 AlignmentButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
284 elif CharGenState == 4:
285 SkillsButton.SetState (IE_GUI_BUTTON_DISABLED)
286 SkillsButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_NAND)
287 AbilitiesButton.SetState (IE_GUI_BUTTON_ENABLED)
288 AbilitiesButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
289 elif CharGenState == 5:
290 AppearanceButton.SetState (IE_GUI_BUTTON_DISABLED)
291 SkillsButton.SetState (IE_GUI_BUTTON_ENABLED)
292 SkillsButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
293 SkillsState = 0
294 elif CharGenState == 6:
295 NameButton.SetState (IE_GUI_BUTTON_DISABLED)
296 BiographyButton.SetState (IE_GUI_BUTTON_DISABLED)
297 AppearanceButton.SetState (IE_GUI_BUTTON_ENABLED)
299 AcceptButton.SetState (IE_GUI_BUTTON_DISABLED)
300 SetCharacterDescription()
301 return
303 def CancelPress():
304 global CharGenWindow
306 if CharGenWindow:
307 CharGenWindow.Unload ()
308 GemRB.CreatePlayer ("", MyChar | 0x8000 )
309 GemRB.SetNextScript ("PartyFormation")
310 return
312 def AcceptPress():
313 #mage spells
314 Kit = GemRB.GetPlayerStat (MyChar, IE_KIT)
315 KitIndex = KitTable.FindValue (3, Kit)
316 Class = GemRB.GetPlayerStat (MyChar, IE_CLASS)
317 t = GemRB.GetPlayerStat (MyChar, IE_ALIGNMENT)
318 TableName = CommonTables.ClassSkills.GetValue (Class, 2, 0)
319 if TableName != "*":
320 #todo: set up ALL spell levels not just level 1
321 GUICommon.SetupSpellLevels (MyChar, TableName, IE_SPELL_TYPE_WIZARD, 1)
322 Learnable = GUICommon.GetLearnableMageSpells (KitIndex, t, 1)
323 SpellBook = GemRB.GetVar ("MageSpellBook")
324 MemoBook = GemRB.GetVar ("MageMemorized")
326 for i in range (len(Learnable) ):
327 if SpellBook & j:
328 if MemoBook & j:
329 memorize = 8
330 else:
331 memorize = 0
332 GemRB.LearnSpell (MyChar, Learnable[i], memorize)
333 j=j<<1
335 #priest spells
336 TableName = CommonTables.ClassSkills.GetValue (Class, 1, 0)
337 if TableName != "*":
338 if TableName == "MXSPLPRS" or TableName == "MXSPLPAL":
339 ClassFlag = 0x8000
340 elif TableName == "MXSPLDRU":
341 #there is no separate druid table, falling back to priest
342 TableName = "MXSPLPRS"
343 ClassFlag = 0x4000
344 elif TableName == "MXSPLRAN":
345 ClassFlag = 0x4000
346 else:
347 ClassFlag = 0
348 #todo: set up ALL spell levels not just level 1
349 GUICommon.SetupSpellLevels (MyChar, TableName, IE_SPELL_TYPE_PRIEST, 1)
350 Learnable = GUICommon.GetLearnablePriestSpells (ClassFlag, t, 1)
351 for i in range (len(Learnable) ):
352 GemRB.LearnSpell (MyChar, Learnable[i], 0)
354 # ranger tracking is a hardcoded innate
355 if GUICommon.HasHOW():
356 if CommonTables.ClassSkills.GetValue (GemRB.GetPlayerStat (MyChar, IE_CLASS), 0) != "*":
357 GemRB.LearnSpell (MyChar, "spin139", LS_MEMO)
359 # save all the skills
360 LUSkillsSelection.SkillsSave (MyChar)
362 TmpTable = GemRB.LoadTable ("repstart")
363 t = AlignmentTable.FindValue (3, t)
364 t = TmpTable.GetValue (t, 0) * 10
365 GemRB.SetPlayerStat (MyChar, IE_REPUTATION, t)
366 # set the party rep if this in the main char
367 if MyChar == 1:
368 GemRB.GameSetReputation (t)
370 print "Reputation", t
371 TmpTable = GemRB.LoadTable ("strtgold")
372 a = TmpTable.GetValue (Class, 1) #number of dice
373 b = TmpTable.GetValue (Class, 0) #size
374 c = TmpTable.GetValue (Class, 2) #adjustment
375 d = TmpTable.GetValue (Class, 3) #external multiplier
376 e = TmpTable.GetValue (Class, 4) #level bonus rate
377 t = GemRB.GetPlayerStat (MyChar, IE_LEVEL) #FIXME: calculate multiclass average
378 if t>1:
379 e=e*(t-1)
380 else:
382 t = GemRB.Roll (a,b,c)*d+e
383 GemRB.SetPlayerStat (MyChar, IE_GOLD, t)
384 GemRB.SetPlayerStat (MyChar, IE_EA, 2 )
385 #GemRB.SetPlayerStat (MyChar, IE_HATEDRACE, GemRB.GetVar ("HatedRace") )
386 #Str = GemRB.GetVar ("Ability1")
387 #GemRB.SetPlayerStat (MyChar, IE_STR, Str)
388 #if Str == 18:
389 # GemRB.SetPlayerStat (MyChar, IE_STREXTRA, GemRB.GetVar ("StrExtra"))
390 #else:
391 # GemRB.SetPlayerStat (MyChar, IE_STREXTRA, 0)
393 #GemRB.SetPlayerStat (MyChar, IE_DEX, GemRB.GetVar ("Ability2"))
394 #GemRB.SetPlayerStat (MyChar, IE_CON, GemRB.GetVar ("Ability3"))
395 #GemRB.SetPlayerStat (MyChar, IE_INT, GemRB.GetVar ("Ability4"))
396 #GemRB.SetPlayerStat (MyChar, IE_WIS, GemRB.GetVar ("Ability5"))
397 #GemRB.SetPlayerStat (MyChar, IE_CHR, GemRB.GetVar ("Ability6"))
399 GemRB.SetPlayerName (MyChar, GemRB.GetToken ("CHARNAME"), 0)
400 GemRB.SetToken ("CHARNAME","")
401 GemRB.SetPlayerStat (MyChar, IE_XP, CommonTables.ClassSkills.GetValue (Class, 3) )
403 GUICommon.SetColorStat (MyChar, IE_SKIN_COLOR, GemRB.GetVar ("SkinColor") )
404 GUICommon.SetColorStat (MyChar, IE_HAIR_COLOR, GemRB.GetVar ("HairColor") )
405 GUICommon.SetColorStat (MyChar, IE_MAJOR_COLOR, GemRB.GetVar ("MajorColor") )
406 GUICommon.SetColorStat (MyChar, IE_MINOR_COLOR, GemRB.GetVar ("MinorColor") )
407 GUICommon.SetColorStat (MyChar, IE_METAL_COLOR, 0x1B )
408 GUICommon.SetColorStat (MyChar, IE_LEATHER_COLOR, 0x16 )
409 GUICommon.SetColorStat (MyChar, IE_ARMOR_COLOR, 0x17 )
411 #does all the rest
412 LargePortrait = GemRB.GetToken ("LargePortrait")
413 SmallPortrait = GemRB.GetToken ("SmallPortrait")
414 GemRB.FillPlayerInfo (MyChar, LargePortrait, SmallPortrait)
416 #10 is a weapon slot (see slottype.2da row 10)
417 GemRB.CreateItem (MyChar, "staf01", 10, 1, 0, 0)
418 GemRB.SetEquippedQuickSlot (MyChar, 0)
420 if CharGenWindow:
421 CharGenWindow.Unload ()
422 GemRB.SetNextScript ("PartyFormation")
423 return
425 def SetCharacterDescription():
426 global CharGenWindow, TextArea, CharGenState, ClassFlag
427 global MyChar
429 TextArea.Clear()
430 if CharGenState > 7:
431 TextArea.Append (1047)
432 TextArea.Append (": ")
433 TextArea.Append (GemRB.GetToken ("CHARNAME"))
434 TextArea.Append ("", -1)
435 if CharGenState > 0:
436 TextArea.Append (12135)
437 TextArea.Append (": ")
438 if GemRB.GetPlayerStat (MyChar, IE_SEX) == 1:
439 TextArea.Append (1050)
440 else:
441 TextArea.Append (1051)
442 if CharGenState > 2:
443 Class = CommonTables.Classes.FindValue (5, GemRB.GetPlayerStat (MyChar, IE_CLASS) )
444 TextArea.Append (12136, -1)
445 TextArea.Append (": ")
446 #this is only mage school in iwd
447 Kit = GemRB.GetPlayerStat (MyChar, IE_KIT)
448 KitIndex = KitTable.FindValue (3, Kit)
449 if KitIndex <= 0:
450 ClassTitle = CommonTables.Classes.GetValue (Class, 2)
451 else:
452 ClassTitle = KitTable.GetValue (KitIndex, 2)
453 TextArea.Append (ClassTitle)
455 if CharGenState > 1:
456 TextArea.Append (1048, -1)
457 TextArea.Append (": ")
458 Race = GemRB.GetPlayerStat (MyChar, IE_RACE)
459 Race = CommonTables.Races.FindValue (3, GemRB.GetPlayerStat (MyChar, IE_RACE) )
460 TextArea.Append (CommonTables.Races.GetValue (Race, 2) )
461 if CharGenState > 3:
462 TextArea.Append (1049, -1)
463 TextArea.Append (": ")
464 Alignment = AlignmentTable.FindValue (3, GemRB.GetPlayerStat(MyChar, IE_ALIGNMENT) )
465 TextArea.Append (AlignmentTable.GetValue (Alignment, 2) )
466 if CharGenState > 4:
467 strextra = GemRB.GetPlayerStat (MyChar, IE_STREXTRA)
468 TextArea.Append ("", -1)
469 for i in range (6):
470 TextArea.Append (AbilitiesTable.GetValue (i, 2), -1)
471 TextArea.Append (": " )
472 StatID = AbilitiesTable.GetValue (i, 3)
473 stat = GemRB.GetPlayerStat (MyChar, StatID)
474 if (i == 0) and HasStrExtra and (stat==18):
475 TextArea.Append (str(stat) + "/" + str(strextra) )
476 else:
477 TextArea.Append (str(stat) )
478 if CharGenState > 5:
479 ClassName = CommonTables.Classes.GetRowName (Class)
480 Row = CommonTables.Classes.GetValue (Class, 5)
481 IsRanger = CommonTables.ClassSkills.GetValue (Row, 0)
482 IsArcane = CommonTables.ClassSkills.GetValue (Row, 1)
483 IsMage = CommonTables.ClassSkills.GetValue (Row, 2)
484 IsBard = CommonTables.ClassSkills.GetValue (Row, 4)
485 IsThief = CommonTables.ClassSkills.GetValue (Row, 5)
487 if IsThief!="*":
488 TextArea.Append ("", -1)
489 TextArea.Append (8442, -1)
490 for i in range (4):
491 TextArea.Append (SkillsTable.GetValue (i+2, 2), -1)
492 StatID = SkillsTable.GetValue (i+2, 3)
493 TextArea.Append (": " )
494 TextArea.Append (str(GemRB.GetPlayerStat (MyChar, StatID)) )
495 TextArea.Append ("%" )
496 elif IsRanger!="*":
497 TextArea.Append ("", -1)
498 TextArea.Append (8442, -1)
499 for i in range (4):
500 StatID = SkillsTable.GetValue (i+2, 3)
501 Stat = GemRB.GetPlayerStat (MyChar, StatID)
502 if Stat>0:
503 TextArea.Append (SkillsTable.GetValue (i+2, 2), -1)
504 TextArea.Append (": " )
505 TextArea.Append (str(Stat) )
506 TextArea.Append ("%" )
507 TextArea.Append ("", -1)
508 TextArea.Append (15982, -1)
509 TextArea.Append (": " )
510 RacialEnemy = GemRB.GetVar ("RacialEnemyIndex") + GemRB.GetVar ("RacialEnemy") - 1
511 TextArea.Append (RacialEnemyTable.GetValue (RacialEnemy, 3) )
512 elif IsBard!="*":
513 TextArea.Append ("", -1)
514 TextArea.Append (8442, -1)
515 for i in range (4):
516 StatID = SkillsTable.GetValue (i+2, 3)
517 Stat = GemRB.GetPlayerStat (MyChar, StatID)
518 if Stat>0:
519 TextArea.Append (SkillsTable.GetValue (i+2, 2), -1)
520 TextArea.Append (": " )
521 TextArea.Append (str(Stat) )
522 TextArea.Append ("%" )
524 TextArea.Append ("", -1)
525 TextArea.Append (9466, -1)
526 for i in range (15):
527 StatID = ProficienciesTable.GetValue (i, 0)
528 ProficiencyValue = GemRB.GetPlayerStat (MyChar, StatID )
529 if ProficiencyValue > 0:
530 TextArea.Append (ProficienciesTable.GetValue (i, 3), -1)
531 TextArea.Append (" ")
532 j = 0
533 while j < ProficiencyValue:
534 TextArea.Append ("+")
535 j = j + 1
537 if IsMage !="*":
538 TextArea.Append ("", -1)
539 TextArea.Append (11027, -1)
540 TextArea.Append (": " )
541 t = GemRB.GetPlayerStat (MyChar, IE_ALIGNMENT)
542 Learnable = GUICommon.GetLearnableMageSpells (GemRB.GetPlayerStat (MyChar, IE_KIT), t,1)
543 MageSpellBook = GemRB.GetVar ("MageSpellBook")
544 MageMemorized = GemRB.GetVar ("MageMemorized")
545 for i in range (len(Learnable)):
546 if (1 << i) & MageSpellBook:
547 Spell = GemRB.GetSpell (Learnable[i])
548 TextArea.Append (Spell["SpellName"], -1)
549 if (1 << i) & MageMemorized:
550 TextArea.Append (" +")
551 TextArea.Append (" ")
553 if IsArcane!="*":
554 TextArea.Append ("", -1)
555 TextArea.Append (11028, -1)
556 TextArea.Append (": " )
557 t = GemRB.GetPlayerStat (MyChar, IE_ALIGNMENT)
558 if IsArcane == "MXSPLPRS" or IsArcane == "MXSPLPAL":
559 ClassFlag = 0x4000
560 elif IsArcane == "MXSPLDRU" or IsArcane == "MXSPLRAN":
561 ClassFlag = 0x8000
562 else:
563 ClassFlag = 0
565 Learnable = GUICommon.GetLearnablePriestSpells( ClassFlag, t, 1)
566 PriestMemorized = GemRB.GetVar ("PriestMemorized")
567 for i in range (len(Learnable)):
568 if (1 << i) & PriestMemorized:
569 Spell = GemRB.GetSpell (Learnable[i])
570 TextArea.Append (Spell["SpellName"], -1)
571 TextArea.Append (" +")
572 return
575 # Gender Selection
577 def GenderPress():
578 global CharGenWindow, GenderWindow, GenderDoneButton, GenderTextArea
579 global MyChar
581 CharGenWindow.SetVisible (WINDOW_INVISIBLE)
582 GenderWindow = GemRB.LoadWindow (1)
583 GemRB.SetVar ("Gender", 0)
584 GemRB.CreatePlayer ("charbase", MyChar | 0x8000 )
586 MaleButton = GenderWindow.GetControl (2)
587 MaleButton.SetState (IE_GUI_BUTTON_ENABLED)
588 MaleButton.SetFlags (IE_GUI_BUTTON_RADIOBUTTON,OP_OR)
589 MaleButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, MalePress)
591 FemaleButton = GenderWindow.GetControl (3)
592 FemaleButton.SetState (IE_GUI_BUTTON_ENABLED)
593 FemaleButton.SetFlags (IE_GUI_BUTTON_RADIOBUTTON,OP_OR)
594 FemaleButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, FemalePress)
596 MaleButton.SetVarAssoc ("Gender", 1)
597 FemaleButton.SetVarAssoc ("Gender", 2)
599 GenderTextArea = GenderWindow.GetControl (5)
600 GenderTextArea.SetText (17236)
602 GenderDoneButton = GenderWindow.GetControl (0)
603 GenderDoneButton.SetState (IE_GUI_BUTTON_DISABLED)
604 GenderDoneButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, GenderDonePress)
605 GenderDoneButton.SetText (11973)
606 GenderDoneButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
608 GenderCancelButton = GenderWindow.GetControl (6)
609 GenderCancelButton.SetState (IE_GUI_BUTTON_ENABLED)
610 GenderCancelButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, GenderCancelPress)
611 GenderCancelButton.SetText (13727)
612 GenderCancelButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
614 GenderWindow.SetVisible (WINDOW_VISIBLE)
615 return
617 def MalePress():
618 global GenderWindow, GenderDoneButton, GenderTextArea
620 GenderTextArea.SetText (13083)
621 GenderDoneButton.SetState (IE_GUI_BUTTON_ENABLED)
622 return
624 def FemalePress():
625 global GenderWindow, GenderDoneButton, GenderTextArea
627 GenderTextArea.SetText (13084)
628 GenderDoneButton.SetState (IE_GUI_BUTTON_ENABLED)
629 return
631 def GenderDonePress():
632 global CharGenWindow, GenderWindow
633 global MyChar
635 if GenderWindow:
636 GenderWindow.Unload ()
637 Gender = GemRB.GetVar ("Gender")
638 GemRB.SetPlayerStat (MyChar, IE_SEX, Gender)
640 CharGenWindow.SetVisible (WINDOW_VISIBLE)
641 PortraitSelect()
642 return
644 def GenderCancelPress():
645 global CharGenWindow, GenderWindow
646 global MyChar
648 GemRB.SetVar ("Gender", 0)
649 GemRB.SetPlayerStat (MyChar, IE_SEX, 0)
650 if GenderWindow:
651 GenderWindow.Unload ()
652 CharGenWindow.SetVisible (WINDOW_VISIBLE)
653 return
655 def PortraitSelect():
656 global CharGenWindow, PortraitWindow, Portrait, PortraitPortraitButton
657 global MyChar
659 CharGenWindow.SetVisible (WINDOW_INVISIBLE)
660 PortraitWindow = GemRB.LoadWindow (11)
662 # this is not the correct one, but I don't know which is
663 Portrait = 0
665 PortraitPortraitButton = PortraitWindow.GetControl (1)
666 PortraitPortraitButton.SetFlags (IE_GUI_BUTTON_PICTURE|IE_GUI_BUTTON_NO_IMAGE, OP_SET)
668 PortraitLeftButton = PortraitWindow.GetControl (2)
669 PortraitLeftButton.SetState (IE_GUI_BUTTON_ENABLED)
670 PortraitLeftButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, CGPortraitLeftPress)
671 PortraitLeftButton.SetFlags (IE_GUI_BUTTON_RADIOBUTTON, OP_OR)
673 PortraitRightButton = PortraitWindow.GetControl (3)
674 PortraitRightButton.SetState (IE_GUI_BUTTON_ENABLED)
675 PortraitRightButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, CGPortraitRightPress)
676 PortraitRightButton.SetFlags (IE_GUI_BUTTON_RADIOBUTTON, OP_OR)
678 PortraitCustomButton = PortraitWindow.GetControl (6)
679 PortraitCustomButton.SetState (IE_GUI_BUTTON_ENABLED)
680 PortraitCustomButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, PortraitCustomPress)
681 PortraitCustomButton.SetText (17545)
683 PortraitDoneButton = PortraitWindow.GetControl (0)
684 PortraitDoneButton.SetState (IE_GUI_BUTTON_ENABLED)
685 PortraitDoneButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, CGPortraitDonePress)
686 PortraitDoneButton.SetText (11973)
687 PortraitDoneButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
689 PortraitCancelButton = PortraitWindow.GetControl (5)
690 PortraitCancelButton.SetState (IE_GUI_BUTTON_ENABLED)
691 PortraitCancelButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, CGPortraitCancelPress)
692 PortraitCancelButton.SetText (13727)
693 PortraitCancelButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
695 while PortraitsTable.GetValue (Portrait, 0) != GemRB.GetPlayerStat (MyChar, IE_SEX):
696 Portrait = Portrait + 1
697 PortraitPortraitButton.SetPicture (PortraitsTable.GetRowName (Portrait) + "G")
699 PortraitWindow.SetVisible (WINDOW_VISIBLE)
700 return
702 def CGPortraitLeftPress():
703 global PortraitWindow, Portrait, PortraitPortraitButton
704 global MyChar
706 while True:
707 Portrait = Portrait - 1
708 if Portrait < 0:
709 Portrait = PortraitsTable.GetRowCount () - 1
710 if PortraitsTable.GetValue (Portrait, 0) == GemRB.GetPlayerStat(MyChar, IE_SEX):
711 PortraitPortraitButton.SetPicture (PortraitsTable.GetRowName (Portrait) + "G")
712 return
714 def CGPortraitRightPress():
715 global PortraitWindow, Portrait, PortraitPortraitButton
716 global MyChar
718 while True:
719 Portrait = Portrait + 1
720 if Portrait == PortraitsTable.GetRowCount():
721 Portrait = 0
722 if PortraitsTable.GetValue (Portrait, 0) == GemRB.GetPlayerStat(MyChar, IE_SEX):
723 PortraitPortraitButton.SetPicture (PortraitsTable.GetRowName (Portrait) + "G")
724 return
726 def CustomDone():
727 global CharGenWindow, PortraitWindow
728 global PortraitButton, GenderButton, RaceButton
729 global CharGenState, Portrait
731 Window = CustomWindow
733 PortraitName = PortraitList2.QueryText ()
734 GemRB.SetToken ("SmallPortrait", PortraitName)
735 PortraitName = PortraitList1.QueryText ()
736 GemRB.SetToken ("LargePortrait", PortraitName)
737 if Window:
738 Window.Unload ()
740 if PortraitWindow:
741 PortraitWindow.Unload ()
742 PortraitButton.SetPicture(PortraitName)
743 GenderButton.SetState (IE_GUI_BUTTON_DISABLED)
744 GenderButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_NAND)
745 RaceButton.SetState (IE_GUI_BUTTON_ENABLED)
746 RaceButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
747 CharGenState = 1
748 Portrait = -1
749 SetCharacterDescription()
750 CharGenWindow.SetVisible (WINDOW_VISIBLE)
751 return
753 def CustomAbort():
754 if CustomWindow:
755 CustomWindow.Unload ()
756 return
758 def CGLargeCustomPortrait():
759 Window = CustomWindow
761 Portrait = PortraitList1.QueryText ()
762 #small hack
763 if GemRB.GetVar ("Row1") == RowCount1:
764 return
766 Label = Window.GetControl (0x10000007)
767 Label.SetText (Portrait)
769 Button = Window.GetControl (6)
770 if Portrait=="":
771 Portrait = "NOPORTMD"
772 Button.SetState (IE_GUI_BUTTON_DISABLED)
773 else:
774 if PortraitList2.QueryText ()!="":
775 Button.SetState (IE_GUI_BUTTON_ENABLED)
777 Button = Window.GetControl (0)
778 Button.SetPicture (Portrait, "NOPORTMD")
779 return
781 def CGSmallCustomPortrait():
782 Window = CustomWindow
784 Portrait = PortraitList2.QueryText ()
785 #small hack
786 if GemRB.GetVar ("Row2") == RowCount2:
787 return
789 Label = Window.GetControl (0x10000008)
790 Label.SetText (Portrait)
792 Button = Window.GetControl (6)
793 if Portrait=="":
794 Portrait = "NOPORTSM"
795 Button.SetState (IE_GUI_BUTTON_DISABLED)
796 else:
797 if PortraitList1.QueryText ()!="":
798 Button.SetState (IE_GUI_BUTTON_ENABLED)
800 Button = Window.GetControl (1)
801 Button.SetPicture (Portrait, "NOPORTSM")
802 return
804 def PortraitCustomPress():
805 global PortraitList1, PortraitList2
806 global RowCount1, RowCount2
807 global CustomWindow
809 CustomWindow = Window = GemRB.LoadWindow (18)
810 PortraitList1 = Window.GetControl (2)
811 RowCount1 = PortraitList1.GetPortraits (0)
812 PortraitList1.SetEvent (IE_GUI_TEXTAREA_ON_CHANGE, CGLargeCustomPortrait)
813 GemRB.SetVar ("Row1", RowCount1)
814 PortraitList1.SetVarAssoc ("Row1",RowCount1)
816 PortraitList2 = Window.GetControl (4)
817 RowCount2 = PortraitList2.GetPortraits (1)
818 PortraitList2.SetEvent (IE_GUI_TEXTAREA_ON_CHANGE, CGSmallCustomPortrait)
819 GemRB.SetVar ("Row2", RowCount2)
820 PortraitList2.SetVarAssoc ("Row2",RowCount2)
822 Button = Window.GetControl (6)
823 Button.SetText (11973)
824 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, CustomDone)
825 Button.SetState (IE_GUI_BUTTON_DISABLED)
827 Button = Window.GetControl (7)
828 Button.SetText (13727)
829 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, CustomAbort)
831 Button = Window.GetControl (0)
832 PortraitName = PortraitsTable.GetRowName (Portrait)+"L"
833 Button.SetPicture (PortraitName, "NOPORTMD")
834 Button.SetState (IE_GUI_BUTTON_LOCKED)
836 Button = Window.GetControl (1)
837 PortraitName = PortraitsTable.GetRowName (Portrait)+"S"
838 Button.SetPicture (PortraitName, "NOPORTSM")
839 Button.SetState (IE_GUI_BUTTON_LOCKED)
841 Window.ShowModal (MODAL_SHADOW_NONE)
842 return
844 def CGPortraitDonePress():
845 global CharGenWindow, PortraitWindow, PortraitButton, GenderButton, RaceButton
846 global CharGenState, Portrait
848 PortraitName = PortraitsTable.GetRowName (Portrait )
849 GemRB.SetToken ("SmallPortrait", PortraitName+"S")
850 GemRB.SetToken ("LargePortrait", PortraitName+"L")
851 PortraitButton.SetPicture(PortraitsTable.GetRowName (Portrait) + "L")
852 GenderButton.SetState (IE_GUI_BUTTON_DISABLED)
853 GenderButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_NAND)
854 RaceButton.SetState (IE_GUI_BUTTON_ENABLED)
855 RaceButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
856 CharGenState = 1
857 SetCharacterDescription()
858 CharGenWindow.SetVisible (WINDOW_VISIBLE)
859 if PortraitWindow:
860 PortraitWindow.Unload ()
861 return
863 def CGPortraitCancelPress():
864 global CharGenWindow, PortraitWindow
866 if PortraitWindow:
867 PortraitWindow.Unload ()
868 CharGenWindow.SetVisible (WINDOW_VISIBLE)
869 return
871 # Race Selection
873 def RacePress():
874 global CharGenWindow, RaceWindow, RaceDoneButton, RaceTextArea
876 CharGenWindow.SetVisible (WINDOW_INVISIBLE)
877 RaceWindow = GemRB.LoadWindow (8)
878 GemRB.SetVar ("Race", 0)
880 for i in range (2, 8):
881 RaceSelectButton = RaceWindow.GetControl (i)
882 RaceSelectButton.SetFlags (IE_GUI_BUTTON_RADIOBUTTON, OP_OR)
884 for i in range (2, 8):
885 RaceSelectButton = RaceWindow.GetControl (i)
886 RaceSelectButton.SetState (IE_GUI_BUTTON_ENABLED)
887 RaceSelectButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, RaceSelectPress)
888 RaceSelectButton.SetText (CommonTables.Races.GetValue (i - 2, 0))
889 RaceSelectButton.SetVarAssoc ("Race", i - 1)
891 RaceTextArea = RaceWindow.GetControl (8)
892 RaceTextArea.SetText (17237)
894 RaceDoneButton = RaceWindow.GetControl (0)
895 RaceDoneButton.SetState (IE_GUI_BUTTON_DISABLED)
896 RaceDoneButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, RaceDonePress)
897 RaceDoneButton.SetText (11973)
898 RaceDoneButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
900 RaceCancelButton = RaceWindow.GetControl (10)
901 RaceCancelButton.SetState (IE_GUI_BUTTON_ENABLED)
902 RaceCancelButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, RaceCancelPress)
903 RaceCancelButton.SetText (13727)
904 RaceCancelButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
906 RaceWindow.SetVisible (WINDOW_VISIBLE)
907 return
909 def RaceSelectPress():
910 global RaceWindow, RaceDoneButton, RaceTextArea
912 Race = GemRB.GetVar ("Race") - 1
913 RaceTextArea.SetText (CommonTables.Races.GetValue (Race, 1) )
914 RaceDoneButton.SetState (IE_GUI_BUTTON_ENABLED)
915 return
917 def RaceDonePress():
918 global CharGenWindow, CharGenState, RaceWindow, RaceButton, ClassButton
920 if RaceWindow:
921 RaceWindow.Unload ()
922 RaceButton.SetState (IE_GUI_BUTTON_DISABLED)
923 RaceButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_NAND)
924 ClassButton.SetState (IE_GUI_BUTTON_ENABLED)
925 ClassButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
926 CharGenState = 2
928 Race = GemRB.GetVar ("Race")-1
929 Race = CommonTables.Races.GetValue (Race, 3)
930 GemRB.SetPlayerStat (MyChar, IE_RACE, Race)
931 SetCharacterDescription()
932 CharGenWindow.SetVisible (WINDOW_VISIBLE)
933 return
935 def RaceCancelPress():
936 global CharGenWindow, RaceWindow
938 if RaceWindow:
939 RaceWindow.Unload ()
940 CharGenWindow.SetVisible (WINDOW_VISIBLE)
941 return
943 # Class Selection
945 def ClassPress():
946 global CharGenWindow, ClassWindow, ClassTextArea, ClassDoneButton
948 CharGenWindow.SetVisible (WINDOW_INVISIBLE)
949 ClassWindow = GemRB.LoadWindow (2)
950 ClassCount = CommonTables.Classes.GetRowCount ()
951 RaceRow = CommonTables.Races.FindValue (3, GemRB.GetPlayerStat (MyChar, IE_RACE) )
952 RaceName = CommonTables.Races.GetRowName (RaceRow)
953 GemRB.SetVar ("Class", 0)
954 GemRB.SetVar ("Class Kit", 0)
955 GemRB.SetVar ("MAGESCHOOL", 0)
957 for i in range (2, 10):
958 ClassSelectButton = ClassWindow.GetControl (i)
959 ClassSelectButton.SetFlags (IE_GUI_BUTTON_RADIOBUTTON, OP_SET)
961 HasMulti = 0
962 j = 2
963 for i in range (ClassCount):
964 Allowed = CommonTables.Classes.GetValue (CommonTables.Classes.GetRowName (i), RaceName)
965 if CommonTables.Classes.GetValue (i, 4):
966 if Allowed != 0:
967 HasMulti = 1
968 else:
969 ClassSelectButton = ClassWindow.GetControl (j)
970 j = j + 1
971 if Allowed > 0:
972 ClassSelectButton.SetState (IE_GUI_BUTTON_ENABLED)
973 else:
974 ClassSelectButton.SetState (IE_GUI_BUTTON_DISABLED)
975 ClassSelectButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, ClassSelectPress)
976 ClassSelectButton.SetText (CommonTables.Classes.GetValue (i, 0) )
977 ClassSelectButton.SetVarAssoc ("Class", i + 1)
979 ClassMultiButton = ClassWindow.GetControl (10)
980 if HasMulti == 0:
981 ClassMultiButton.SetState (IE_GUI_BUTTON_DISABLED)
982 else:
983 ClassMultiButton.SetState (IE_GUI_BUTTON_ENABLED)
984 ClassMultiButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, ClassMultiPress)
985 ClassMultiButton.SetText (11993)
987 KitButton = ClassWindow.GetControl (11)
988 #only the mage class has schools
989 Allowed = CommonTables.Classes.GetValue ("MAGE", RaceName)
990 if Allowed:
991 KitButton.SetState (IE_GUI_BUTTON_ENABLED)
992 else:
993 KitButton.SetState (IE_GUI_BUTTON_DISABLED)
994 KitButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, KitPress)
995 KitButton.SetText (11994)
997 ClassTextArea = ClassWindow.GetControl (13)
998 ClassTextArea.SetText (17242)
1000 ClassDoneButton = ClassWindow.GetControl (0)
1001 ClassDoneButton.SetState (IE_GUI_BUTTON_DISABLED)
1002 ClassDoneButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, ClassDonePress)
1003 ClassDoneButton.SetText (11973)
1004 ClassDoneButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
1006 ClassCancelButton = ClassWindow.GetControl (14)
1007 ClassCancelButton.SetState (IE_GUI_BUTTON_ENABLED)
1008 ClassCancelButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, ClassCancelPress)
1009 ClassCancelButton.SetText (13727)
1010 ClassCancelButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
1012 ClassWindow.SetVisible (WINDOW_VISIBLE)
1013 return
1015 def ClassSelectPress():
1016 global ClassWindow, ClassTextArea, ClassDoneButton
1018 Class = GemRB.GetVar ("Class") - 1
1019 ClassTextArea.SetText (CommonTables.Classes.GetValue (Class, 1) )
1020 ClassDoneButton.SetState (IE_GUI_BUTTON_ENABLED)
1021 return
1023 def ClassMultiPress():
1024 global ClassWindow, ClassMultiWindow, ClassMultiTextArea, ClassMultiDoneButton
1026 ClassWindow.SetVisible (WINDOW_INVISIBLE)
1027 ClassMultiWindow = GemRB.LoadWindow (10)
1028 ClassCount = CommonTables.Classes.GetRowCount ()
1029 RaceRow = CommonTables.Races.FindValue (3, GemRB.GetPlayerStat (MyChar, IE_RACE) )
1030 RaceName = CommonTables.Races.GetRowName (RaceRow)
1032 print "Multi racename:", RaceName
1033 for i in range (2, 10):
1034 ClassMultiSelectButton = ClassMultiWindow.GetControl (i)
1035 ClassMultiSelectButton.SetFlags (IE_GUI_BUTTON_RADIOBUTTON, OP_SET)
1037 j = 2
1038 for i in range (ClassCount):
1039 ClassName = CommonTables.Classes.GetRowName (i)
1040 if (CommonTables.Classes.GetValue (ClassName, "MULTI") > 0):
1041 ClassMultiSelectButton = ClassMultiWindow.GetControl (j)
1042 j = j + 1
1043 if (CommonTables.Classes.GetValue (ClassName, RaceName) > 0):
1044 ClassMultiSelectButton.SetState (IE_GUI_BUTTON_ENABLED)
1045 else:
1046 ClassMultiSelectButton.SetState (IE_GUI_BUTTON_DISABLED)
1047 ClassMultiSelectButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, ClassMultiSelectPress)
1048 ClassMultiSelectButton.SetText (CommonTables.Classes.GetValue (i, 0) )
1049 ClassMultiSelectButton.SetVarAssoc ("Class", i + 1)
1051 ClassMultiTextArea = ClassMultiWindow.GetControl (12)
1052 ClassMultiTextArea.SetText (17244)
1054 ClassMultiDoneButton = ClassMultiWindow.GetControl (0)
1055 ClassMultiDoneButton.SetState (IE_GUI_BUTTON_DISABLED)
1056 ClassMultiDoneButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, ClassMultiDonePress)
1057 ClassMultiDoneButton.SetText (11973)
1058 ClassMultiDoneButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
1060 ClassMultiCancelButton = ClassMultiWindow.GetControl (14)
1061 ClassMultiCancelButton.SetState (IE_GUI_BUTTON_ENABLED)
1062 ClassMultiCancelButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, ClassMultiCancelPress)
1063 ClassMultiCancelButton.SetText (13727)
1064 ClassMultiCancelButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
1066 ClassMultiWindow.SetVisible (WINDOW_VISIBLE)
1067 return
1069 def ClassMultiSelectPress():
1070 global ClassMultiWindow, ClassMultiTextArea, ClassMultiDoneButton
1072 Class = GemRB.GetVar ("Class") - 1
1073 ClassMultiTextArea.SetText (CommonTables.Classes.GetValue (Class, 1) )
1074 ClassMultiDoneButton.SetState (IE_GUI_BUTTON_ENABLED)
1075 return
1077 def ClassMultiDonePress():
1078 global ClassMultiWindow
1080 if ClassMultiWindow:
1081 ClassMultiWindow.Unload ()
1082 ClassDonePress()
1083 return
1085 def ClassMultiCancelPress():
1086 global ClassWindow, ClassMultiWindow
1088 if ClassMultiWindow:
1089 ClassMultiWindow.Unload ()
1090 ClassWindow.SetVisible (WINDOW_VISIBLE)
1091 return
1093 def KitPress():
1094 global ClassWindow, KitWindow, KitTextArea, KitDoneButton
1096 ClassWindow.SetVisible (WINDOW_INVISIBLE)
1097 KitWindow = GemRB.LoadWindow (12)
1099 #only mage class (1) has schools. It is the sixth button
1100 GemRB.SetVar ("Class", 6)
1101 GemRB.SetVar ("Class Kit",0)
1102 GemRB.SetVar ("MAGESCHOOL",0)
1104 for i in range (8):
1105 Button = KitWindow.GetControl (i+2)
1106 Button.SetFlags (IE_GUI_BUTTON_RADIOBUTTON, OP_OR)
1107 Button.SetText (KitTable.GetValue (i+1, 0) )
1108 Button.SetVarAssoc ("MAGESCHOOL", i+1)
1109 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, KitSelectPress)
1111 KitTextArea = KitWindow.GetControl (11)
1112 KitTextArea.SetText (17245)
1114 KitDoneButton = KitWindow.GetControl (0)
1115 KitDoneButton.SetState (IE_GUI_BUTTON_DISABLED)
1116 KitDoneButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, KitDonePress)
1117 KitDoneButton.SetText (11973)
1118 KitDoneButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
1120 KitCancelButton = KitWindow.GetControl (12)
1121 KitCancelButton.SetState (IE_GUI_BUTTON_ENABLED)
1122 KitCancelButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, KitCancelPress)
1123 KitCancelButton.SetText (13727)
1124 KitCancelButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
1126 KitWindow.SetVisible (WINDOW_VISIBLE)
1127 return
1129 def KitSelectPress():
1130 global KitWindow, KitTextArea
1132 Kit = GemRB.GetVar ("MAGESCHOOL")
1133 KitTextArea.SetText (KitTable.GetValue (Kit, 1))
1134 KitDoneButton.SetState (IE_GUI_BUTTON_ENABLED)
1135 return
1137 def KitDonePress():
1138 global KitWindow
1140 if KitWindow:
1141 KitWindow.Unload ()
1142 ClassDonePress()
1143 return
1145 def KitCancelPress():
1146 global ClassWindow, KitWindow
1148 if KitWindow:
1149 KitWindow.Unload ()
1150 ClassWindow.SetVisible (WINDOW_VISIBLE)
1151 return
1153 def ClassDonePress():
1154 global CharGenWindow, CharGenState, ClassWindow, ClassButton, AlignmentButton
1155 global MyChar
1157 if ClassWindow:
1158 ClassWindow.Unload ()
1159 ClassButton.SetState (IE_GUI_BUTTON_DISABLED)
1160 ClassButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_NAND)
1161 AlignmentButton.SetState (IE_GUI_BUTTON_ENABLED)
1162 AlignmentButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
1164 ClassIndex = GemRB.GetVar ("Class")-1
1165 Class = CommonTables.Classes.GetValue (ClassIndex, 5)
1166 GemRB.SetPlayerStat (MyChar, IE_CLASS, Class)
1168 Kit = KitTable.GetValue (GemRB.GetVar ("MAGESCHOOL"), 3 )
1169 if (Kit == -1 ):
1170 Kit = 0x4000
1172 GemRB.SetPlayerStat (MyChar, IE_KIT, Kit)
1174 CharGenState = 3
1175 SetCharacterDescription()
1176 CharGenWindow.SetVisible (WINDOW_VISIBLE)
1177 return
1179 def ClassCancelPress():
1180 global CharGenWindow, ClassWindow
1182 if ClassWindow:
1183 ClassWindow.Unload ()
1184 CharGenWindow.SetVisible (WINDOW_VISIBLE)
1185 return
1187 # Alignment Selection
1189 def AlignmentPress():
1190 global CharGenWindow, AlignmentWindow, AlignmentTextArea, AlignmentDoneButton
1192 CharGenWindow.SetVisible (WINDOW_INVISIBLE)
1193 AlignmentWindow = GemRB.LoadWindow (3)
1194 ClassAlignmentTable = GemRB.LoadTable ("alignmnt")
1195 Class = GemRB.GetPlayerStat (MyChar, IE_CLASS)
1196 ClassIndex = CommonTables.Classes.FindValue (5, Class)
1197 ClassName = CommonTables.Classes.GetRowName (ClassIndex)
1198 GemRB.SetVar ("Alignment", 0)
1200 for i in range (2, 11):
1201 AlignmentSelectButton = AlignmentWindow.GetControl (i)
1202 AlignmentSelectButton.SetFlags (IE_GUI_BUTTON_RADIOBUTTON, OP_OR)
1204 for i in range (9):
1205 AlignmentSelectButton = AlignmentWindow.GetControl (i + 2)
1206 if ClassAlignmentTable.GetValue (ClassName, AlignmentTable.GetValue(i, 4)) == 0:
1207 AlignmentSelectButton.SetState (IE_GUI_BUTTON_DISABLED)
1208 else:
1209 AlignmentSelectButton.SetState (IE_GUI_BUTTON_ENABLED)
1210 AlignmentSelectButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, AlignmentSelectPress)
1211 AlignmentSelectButton.SetText (AlignmentTable.GetValue (i, 0) )
1212 AlignmentSelectButton.SetVarAssoc ("Alignment", i + 1)
1214 AlignmentTextArea = AlignmentWindow.GetControl (11)
1215 AlignmentTextArea.SetText (9602)
1217 AlignmentDoneButton = AlignmentWindow.GetControl (0)
1218 AlignmentDoneButton.SetState (IE_GUI_BUTTON_DISABLED)
1219 AlignmentDoneButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, AlignmentDonePress)
1220 AlignmentDoneButton.SetText (11973)
1221 AlignmentDoneButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
1223 AlignmentCancelButton = AlignmentWindow.GetControl (13)
1224 AlignmentCancelButton.SetState (IE_GUI_BUTTON_ENABLED)
1225 AlignmentCancelButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, AlignmentCancelPress)
1226 AlignmentCancelButton.SetText (13727)
1227 AlignmentCancelButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
1229 AlignmentWindow.SetVisible (WINDOW_VISIBLE)
1230 return
1232 def AlignmentSelectPress():
1233 global AlignmentWindow, AlignmentTextArea, AlignmentDoneButton
1235 Alignment = GemRB.GetVar ("Alignment") - 1
1236 AlignmentTextArea.SetText (AlignmentTable.GetValue (Alignment, 1))
1237 AlignmentDoneButton.SetState (IE_GUI_BUTTON_ENABLED)
1238 return
1240 def AlignmentDonePress():
1241 global CharGenWindow, CharGenState, AlignmentWindow, AlignmentButton, AbilitiesButton
1242 global MyChar
1244 if AlignmentWindow:
1245 AlignmentWindow.Unload ()
1246 AlignmentButton.SetState (IE_GUI_BUTTON_DISABLED)
1247 AlignmentButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_NAND)
1248 AbilitiesButton.SetState (IE_GUI_BUTTON_ENABLED)
1249 AbilitiesButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
1251 Alignment = AlignmentTable.GetValue (GemRB.GetVar ("Alignment")-1, 3)
1252 GemRB.SetPlayerStat (MyChar, IE_ALIGNMENT, Alignment )
1254 CharGenState = 4
1255 SetCharacterDescription()
1256 CharGenWindow.SetVisible (WINDOW_VISIBLE)
1257 return
1259 def AlignmentCancelPress():
1260 global CharGenWindow, AlignmentWindow
1262 if AlignmentWindow:
1263 AlignmentWindow.Unload ()
1264 CharGenWindow.SetVisible (WINDOW_VISIBLE)
1265 return
1267 # Abilities Selection
1269 def AbilitiesPress():
1270 global CharGenWindow, AbilitiesWindow
1271 global AbilitiesTextArea, AbilitiesRecallButton, AbilitiesDoneButton
1272 global AbilitiesRaceAddTable, AbilitiesRaceReqTable, AbilitiesClassReqTable
1273 global HasStrExtra
1275 GemRB.SetRepeatClickFlags(GEM_RK_DISABLE, OP_NAND)
1276 CharGenWindow.SetVisible (WINDOW_INVISIBLE)
1277 AbilitiesWindow = GemRB.LoadWindow (4)
1278 AbilitiesRaceAddTable = GemRB.LoadTable ("ABRACEAD")
1279 AbilitiesRaceReqTable = GemRB.LoadTable ("ABRACERQ")
1280 AbilitiesClassReqTable = GemRB.LoadTable ("ABCLASRQ")
1282 PointsLeftLabel = AbilitiesWindow.GetControl (0x10000002)
1283 PointsLeftLabel.SetUseRGB (1)
1285 Class = GemRB.GetPlayerStat (MyChar, IE_CLASS)
1286 Class = CommonTables.Classes.FindValue (5, Class)
1287 HasStrExtra = CommonTables.Classes.GetValue (Class, 3)=="SAVEWAR"
1289 for i in range (6):
1290 AbilitiesLabelButton = AbilitiesWindow.GetControl (30 + i)
1291 AbilitiesLabelButton.SetState (IE_GUI_BUTTON_ENABLED)
1292 AbilitiesLabelButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, AbilitiesLabelPress)
1293 AbilitiesLabelButton.SetVarAssoc ("AbilityIndex", i + 1)
1295 AbilitiesPlusButton = AbilitiesWindow.GetControl (16 + i * 2)
1296 AbilitiesPlusButton.SetState (IE_GUI_BUTTON_ENABLED)
1297 AbilitiesPlusButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, AbilitiesPlusPress)
1298 AbilitiesPlusButton.SetVarAssoc ("AbilityIndex", i + 1)
1300 AbilitiesMinusButton = AbilitiesWindow.GetControl (17 + i * 2)
1301 AbilitiesMinusButton.SetState (IE_GUI_BUTTON_ENABLED)
1302 AbilitiesMinusButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, AbilitiesMinusPress)
1303 AbilitiesMinusButton.SetVarAssoc ("AbilityIndex", i + 1)
1305 AbilityLabel = AbilitiesWindow.GetControl (0x10000003 + i)
1306 AbilityLabel.SetUseRGB (1)
1308 AbilitiesStoreButton = AbilitiesWindow.GetControl (37)
1309 AbilitiesStoreButton.SetState (IE_GUI_BUTTON_ENABLED)
1310 AbilitiesStoreButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, AbilitiesStorePress)
1311 AbilitiesStoreButton.SetText (17373)
1313 AbilitiesRecallButton = AbilitiesWindow.GetControl (38)
1314 AbilitiesRecallButton.SetState (IE_GUI_BUTTON_DISABLED)
1315 AbilitiesRecallButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, AbilitiesRecallPress)
1316 AbilitiesRecallButton.SetText (17374)
1318 AbilitiesRerollButton = AbilitiesWindow.GetControl (2)
1319 AbilitiesRerollButton.SetState (IE_GUI_BUTTON_ENABLED)
1320 AbilitiesRerollButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, AbilitiesRerollPress)
1321 AbilitiesRerollButton.SetText (11982)
1323 AbilitiesTextArea = AbilitiesWindow.GetControl (29)
1324 AbilitiesTextArea.SetText (17247)
1326 AbilitiesDoneButton = AbilitiesWindow.GetControl (0)
1327 AbilitiesDoneButton.SetState (IE_GUI_BUTTON_ENABLED)
1328 AbilitiesDoneButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, AbilitiesDonePress)
1329 AbilitiesDoneButton.SetText (11973)
1330 AbilitiesDoneButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
1332 AbilitiesCancelButton = AbilitiesWindow.GetControl (36)
1333 AbilitiesCancelButton.SetState (IE_GUI_BUTTON_ENABLED)
1334 AbilitiesCancelButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, AbilitiesCancelPress)
1335 AbilitiesCancelButton.SetText (13727)
1336 AbilitiesCancelButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
1338 AbilitiesRerollPress()
1340 AbilitiesWindow.SetVisible (WINDOW_VISIBLE)
1341 return
1343 def AbilitiesCalcLimits(Index):
1344 global AbilitiesRaceReqTable, AbilitiesRaceAddTable, AbilitiesClassReqTable
1345 global AbilitiesMinimum, AbilitiesMaximum, AbilitiesModifier
1347 RaceName = CommonTables.Races.GetRowName (GemRB.GetPlayerStat (MyChar, IE_RACE) - 1)
1348 Race = AbilitiesRaceReqTable.GetRowIndex (RaceName)
1349 AbilitiesMinimum = AbilitiesRaceReqTable.GetValue (Race, Index * 2)
1350 AbilitiesMaximum = AbilitiesRaceReqTable.GetValue (Race, Index * 2 + 1)
1351 AbilitiesModifier = AbilitiesRaceAddTable.GetValue (Race, Index)
1353 Class = CommonTables.Classes.FindValue (5, GemRB.GetPlayerStat (MyChar, IE_CLASS) )
1354 ClassName = CommonTables.Classes.GetRowName (Class)
1355 ClassIndex = AbilitiesClassReqTable.GetRowIndex (ClassName)
1356 Min = AbilitiesClassReqTable.GetValue (ClassIndex, Index)
1357 if Min > 0 and AbilitiesMinimum < Min:
1358 AbilitiesMinimum = Min
1360 AbilitiesMinimum = AbilitiesMinimum + AbilitiesModifier
1361 AbilitiesMaximum = AbilitiesMaximum + AbilitiesModifier
1362 return
1364 def AbilitiesLabelPress():
1365 global AbilitiesWindow, AbilitiesTextArea
1367 AbilityIndex = GemRB.GetVar ("AbilityIndex") - 1
1368 AbilitiesCalcLimits(AbilityIndex)
1369 GemRB.SetToken ("MINIMUM", str(AbilitiesMinimum) )
1370 GemRB.SetToken ("MAXIMUM", str(AbilitiesMaximum) )
1371 AbilitiesTextArea.SetText (AbilitiesTable.GetValue (AbilityIndex, 1) )
1372 return
1374 def AbilitiesPlusPress():
1375 global AbilitiesWindow, AbilitiesTextArea
1376 global AbilitiesMinimum, AbilitiesMaximum
1378 Abidx = GemRB.GetVar ("AbilityIndex") - 1
1379 AbilitiesCalcLimits(Abidx)
1380 GemRB.SetToken ("MINIMUM", str(AbilitiesMinimum) )
1381 GemRB.SetToken ("MAXIMUM", str(AbilitiesMaximum) )
1382 AbilitiesTextArea.SetText (AbilitiesTable.GetValue (Abidx, 1) )
1383 PointsLeft = GemRB.GetVar ("Ability0")
1384 Ability = GemRB.GetVar ("Ability" + str(Abidx + 1) )
1385 if PointsLeft > 0 and Ability < AbilitiesMaximum:
1386 PointsLeft = PointsLeft - 1
1387 GemRB.SetVar ("Ability0", PointsLeft)
1388 PointsLeftLabel = AbilitiesWindow.GetControl (0x10000002)
1389 PointsLeftLabel.SetText (str(PointsLeft) )
1390 Ability = Ability + 1
1391 GemRB.SetVar ("Ability" + str(Abidx + 1), Ability)
1392 Label = AbilitiesWindow.GetControl (0x10000003 + Abidx)
1393 StrExtra = GemRB.GetVar("StrExtra")
1394 if Abidx==0 and Ability==18 and HasStrExtra:
1395 Label.SetText("18/"+str(StrExtra) )
1396 else:
1397 Label.SetText(str(Ability) )
1399 if PointsLeft == 0:
1400 AbilitiesDoneButton.SetState (IE_GUI_BUTTON_ENABLED)
1401 return
1403 def AbilitiesMinusPress():
1404 global AbilitiesWindow, AbilitiesTextArea
1405 global AbilitiesMinimum, AbilitiesMaximum
1407 Abidx = GemRB.GetVar ("AbilityIndex") - 1
1408 AbilitiesCalcLimits(Abidx)
1409 GemRB.SetToken ("MINIMUM", str(AbilitiesMinimum) )
1410 GemRB.SetToken ("MAXIMUM", str(AbilitiesMaximum) )
1411 AbilitiesTextArea.SetText (AbilitiesTable.GetValue (Abidx, 1) )
1412 PointsLeft = GemRB.GetVar ("Ability0")
1413 Ability = GemRB.GetVar ("Ability" + str(Abidx + 1) )
1414 if Ability > AbilitiesMinimum:
1415 Ability = Ability - 1
1416 GemRB.SetVar ("Ability" + str(Abidx + 1), Ability)
1417 Label = AbilitiesWindow.GetControl (0x10000003 + Abidx)
1418 StrExtra = GemRB.GetVar("StrExtra")
1419 if Abidx==0 and Ability==18 and HasStrExtra:
1420 Label.SetText("18/"+str(StrExtra) )
1421 else:
1422 Label.SetText(str(Ability) )
1424 PointsLeft = PointsLeft + 1
1425 GemRB.SetVar ("Ability0", PointsLeft)
1426 PointsLeftLabel = AbilitiesWindow.GetControl (0x10000002)
1427 PointsLeftLabel.SetText (str(PointsLeft) )
1428 AbilitiesDoneButton.SetState (IE_GUI_BUTTON_DISABLED)
1429 return
1431 def AbilitiesStorePress():
1432 global AbilitiesWindow, AbilitiesRecallButton
1434 GemRB.SetVar("StoredStrExtra", GemRB.GetVar ("StrExtra") )
1435 for i in range (7):
1436 GemRB.SetVar ("Stored" + str(i), GemRB.GetVar ("Ability" + str(i)))
1437 AbilitiesRecallButton.SetState (IE_GUI_BUTTON_ENABLED)
1438 return
1440 def AbilitiesRecallPress():
1441 global AbilitiesWindow
1443 AbilitiesWindow.Invalidate ()
1444 e=GemRB.GetVar("StoredStrExtra")
1445 GemRB.SetVar("StrExtra",e)
1446 for i in range (7):
1447 v = GemRB.GetVar ("Stored" + str(i))
1448 GemRB.SetVar ("Ability" + str(i), v)
1449 Label = AbilitiesWindow.GetControl (0x10000002 + i)
1450 if i==0 and v==18 and HasStrExtra==1:
1451 Label.SetText("18/"+str(e) )
1452 else:
1453 Label.SetText(str(v) )
1455 PointsLeft = GemRB.GetVar("Ability0")
1456 if PointsLeft == 0:
1457 AbilitiesDoneButton.SetState(IE_GUI_BUTTON_ENABLED)
1458 else:
1459 AbilitiesDoneButton.SetState(IE_GUI_BUTTON_DISABLED)
1460 return
1462 def AbilitiesRerollPress():
1463 global AbilitiesWindow, AbilitiesMinimum, AbilitiesMaximum, AbilitiesModifier
1465 AbilitiesWindow.Invalidate ()
1466 GemRB.SetVar ("Ability0", 0)
1467 PointsLeftLabel = AbilitiesWindow.GetControl (0x10000002)
1468 PointsLeftLabel.SetText ("0")
1469 Dices = 3
1470 Sides = 5
1472 #roll strextra even when the current stat is not 18
1473 if HasStrExtra:
1474 e = GemRB.Roll (1,100,0)
1475 else:
1476 e = 0
1477 GemRB.SetVar("StrExtra", e)
1478 for i in range (6):
1479 AbilitiesCalcLimits(i)
1480 Value = GemRB.Roll (Dices, Sides, AbilitiesModifier+3)
1481 if Value < AbilitiesMinimum:
1482 Value = AbilitiesMinimum
1483 if Value > AbilitiesMaximum:
1484 Value = AbilitiesMaximum
1485 GemRB.SetVar ("Ability" + str(i + 1), Value)
1486 Label = AbilitiesWindow.GetControl (0x10000003 + i)
1488 if i==0 and HasStrExtra and Value==18:
1489 Label.SetText("18/"+str(e) )
1490 else:
1491 Label.SetText(str(Value) )
1493 AbilitiesDoneButton.SetState(IE_GUI_BUTTON_ENABLED)
1494 return
1496 def AbilitiesDonePress():
1497 global CharGenWindow, CharGenState, AbilitiesWindow, AbilitiesButton, SkillsButton, SkillsState
1499 if AbilitiesWindow:
1500 AbilitiesWindow.Unload ()
1501 AbilitiesButton.SetState (IE_GUI_BUTTON_DISABLED)
1502 AbilitiesButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_NAND)
1503 SkillsButton.SetState (IE_GUI_BUTTON_ENABLED)
1504 SkillsButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
1506 Str = GemRB.GetVar ("Ability1")
1507 GemRB.SetPlayerStat (MyChar, IE_STR, Str)
1508 if Str == 18:
1509 GemRB.SetPlayerStat (MyChar, IE_STREXTRA, GemRB.GetVar ("StrExtra"))
1510 else:
1511 GemRB.SetPlayerStat (MyChar, IE_STREXTRA, 0)
1513 GemRB.SetPlayerStat (MyChar, IE_DEX, GemRB.GetVar ("Ability2"))
1514 GemRB.SetPlayerStat (MyChar, IE_CON, GemRB.GetVar ("Ability3"))
1515 GemRB.SetPlayerStat (MyChar, IE_INT, GemRB.GetVar ("Ability4"))
1516 GemRB.SetPlayerStat (MyChar, IE_WIS, GemRB.GetVar ("Ability5"))
1517 GemRB.SetPlayerStat (MyChar, IE_CHR, GemRB.GetVar ("Ability6"))
1519 CharGenState = 5
1520 SkillsState = 0
1521 SetCharacterDescription()
1522 GemRB.SetRepeatClickFlags(GEM_RK_DISABLE, OP_OR)
1523 CharGenWindow.SetVisible (WINDOW_VISIBLE)
1524 return
1526 def AbilitiesCancelPress():
1527 global CharGenWindow, AbilitiesWindow
1529 if AbilitiesWindow:
1530 AbilitiesWindow.Unload ()
1531 GemRB.SetRepeatClickFlags(GEM_RK_DISABLE, OP_OR)
1532 CharGenWindow.SetVisible (WINDOW_VISIBLE)
1533 return
1535 # Skills Selection
1537 def SkillsPress():
1538 global CharGenWindow, AppearanceButton
1539 global SkillsState, SkillsButton, CharGenState, ClassFlag
1541 Level = 1
1542 SpellLevel = 1
1543 Class = GemRB.GetPlayerStat (MyChar, IE_CLASS)
1544 IsRanger = CommonTables.ClassSkills.GetValue (Class, 0)
1545 IsArcane = CommonTables.ClassSkills.GetValue (Class, 1)
1546 IsMage = CommonTables.ClassSkills.GetValue (Class, 2)
1547 IsBard = CommonTables.ClassSkills.GetValue (Class, 4)
1548 IsThief = CommonTables.ClassSkills.GetValue (Class, 5)
1550 if SkillsState == 0:
1551 GemRB.SetVar ("HatedRace", 0)
1552 RaceName = CommonTables.Races.GetRowName (GemRB.GetPlayerStat (MyChar, IE_RACE) - 1)
1553 if IsThief!="*":
1554 SkillsSelect()
1555 elif IsRanger!="*":
1556 SkillRaceTable = GemRB.LoadTable ("SKILLRAC")
1557 SkillDexterityTable = GemRB.LoadTable ("SKILLDEX")
1558 Dexterity = str(GemRB.GetPlayerStat (MyChar, IE_DEX) )
1559 Skill = SkillRaceTable.GetValue (RaceName, "STEALTH")
1560 Skill = Skill + SkillDexterityTable.GetValue(Dexterity, "STEALTH")
1561 Skill = Skill + GemRB.LoadTable("SKILLRNG").GetValue(str(Level), "STEALTH")
1562 GemRB.SetPlayerStat (MyChar, IE_STEALTH, Skill)
1563 RacialEnemySelect()
1564 elif IsBard!="*":
1565 SkillRaceTable = GemRB.LoadTable ("SKILLRAC")
1566 SkillDexterityTable = GemRB.LoadTable ("SKILLDEX")
1567 Dexterity = str(GemRB.GetPlayerStat (MyChar, IE_DEX) )
1568 Skill = SkillRaceTable.GetValue (RaceName, "PICK_POCKETS")
1569 Skill = Skill + SkillDexterityTable.GetValue(Dexterity, "PICK_POCKETS")
1570 Skill = Skill + GemRB.LoadTable(IsBard).GetValue(str(Level), "PICK_POCKETS")
1571 GemRB.SetPlayerStat (MyChar, IE_PICKPOCKET, Skill)
1572 SkillsState = 1
1573 else:
1574 SkillsState = 1
1576 if SkillsState == 1:
1577 ProficienciesSelect()
1579 if SkillsState == 2:
1580 if IsMage!="*":
1581 MageSpellsSelect(IsMage, Level, SpellLevel)
1582 else:
1583 SkillsState = 3
1585 if SkillsState == 3:
1586 if IsMage!="*":
1587 MageSpellsMemorize(IsMage, Level, SpellLevel)
1588 else:
1589 SkillsState = 4
1591 if SkillsState == 4:
1592 if IsArcane=="MXSPLPRS" or IsArcane =="MXSPLPAL":
1593 ClassFlag = 0x4000
1594 PriestSpellsMemorize(IsArcane, Level, SpellLevel)
1595 elif IsArcane=="MXSPLDRU" or IsArcane =="MXSPLRAN":
1596 #no separate spell progression
1597 if IsArcane == "MXSPLDRU":
1598 IsArcane = "MXSPLPRS"
1599 ClassFlag = 0x8000
1600 PriestSpellsMemorize(IsArcane, Level, SpellLevel)
1601 else:
1602 SkillsState = 5
1604 if SkillsState == 5:
1605 SkillsButton.SetState (IE_GUI_BUTTON_DISABLED)
1606 SkillsButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_NAND)
1607 AppearanceButton.SetState (IE_GUI_BUTTON_ENABLED)
1608 AppearanceButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
1610 Race = GemRB.GetVar ("HatedRace")
1611 GemRB.SetPlayerStat (MyChar, IE_HATEDRACE, Race)
1613 ProfCount = ProficienciesTable.GetRowCount ()
1614 for i in range(ProfCount):
1615 StatID = ProficienciesTable.GetValue (i, 0)
1616 Value = GemRB.GetVar ("Proficiency"+str(i) )
1617 GemRB.SetPlayerStat (MyChar, StatID, Value )
1619 CharGenState = 6
1620 SetCharacterDescription()
1621 return
1623 def SkillsSelect():
1624 global CharGenWindow, SkillsWindow, SkillsTextArea, SkillsDoneButton, SkillsPointsLeft
1626 CharGenWindow.SetVisible (WINDOW_INVISIBLE)
1627 SkillsWindow = GemRB.LoadWindow (6)
1628 RaceName = CommonTables.Races.GetRowName (GemRB.GetPlayerStat (MyChar, IE_RACE) - 1)
1629 Dexterity = str(GetPlayerStat (MyChar, IE_DEX) )
1630 SkillRaceTable = GemRB.LoadTable ("SKILLRAC")
1631 SkillDexterityTable = GemRB.LoadTable ("SKILLDEX")
1633 Levels = [GemRB.GetPlayerStat (MyChar, IE_LEVEL), \
1634 GemRB.GetPlayerStat (MyChar, IE_LEVEL2), \
1635 GemRB.GetPlayerStat (MyChar, IE_LEVEL3)]
1637 LUSkillsSelection.SetupSkillsWindow (MyChar, \
1638 LUSkillsSelection.LUSKILLS_TYPE_CHARGEN, SkillsWindow, RedrawSkills, [0,0,0], Levels, 0, False)
1640 SkillsPointsLeft = GemRB.GetVar ("SkillPointsLeft")
1641 if SkillsPointsLeft<=0:
1642 SkillsDonePress()
1643 return
1645 SkillsDoneButton = SkillsWindow.GetControl (0)
1646 SkillsDoneButton.SetState (IE_GUI_BUTTON_DISABLED)
1647 SkillsDoneButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, SkillsDonePress)
1648 SkillsDoneButton.SetText (11973)
1649 SkillsDoneButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
1651 SkillsCancelButton = SkillsWindow.GetControl (25)
1652 SkillsCancelButton.SetState (IE_GUI_BUTTON_ENABLED)
1653 SkillsCancelButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, SkillsCancelPress)
1654 SkillsCancelButton.SetText (13727)
1655 SkillsCancelButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
1656 GemRB.SetRepeatClickFlags(GEM_RK_DISABLE, OP_NAND)
1658 RedrawSkills()
1659 SkillsWindow.SetVisible (WINDOW_VISIBLE)
1660 return
1662 def RedrawSkills():
1663 PointsLeft = GemRB.GetVar ("SkillPointsLeft")
1664 if PointsLeft == 0:
1665 SkillsDoneButton.SetState(IE_GUI_BUTTON_ENABLED)
1666 else:
1667 SkillsDoneButton.SetState(IE_GUI_BUTTON_DISABLED)
1668 return
1670 def SkillsDonePress():
1671 global CharGenWindow, SkillsWindow, SkillsState
1673 if SkillsWindow:
1674 SkillsWindow.Unload ()
1675 SkillsState = 1
1676 CharGenWindow.SetVisible (WINDOW_VISIBLE)
1677 SkillsPress()
1678 return
1680 def SkillsCancelPress():
1681 global CharGenWindow, SkillsWindow, SkillsState
1683 if SkillsWindow:
1684 SkillsWindow.Unload ()
1685 SkillsState = 0
1686 CharGenWindow.SetVisible (WINDOW_VISIBLE)
1687 return
1689 # Racial Enemy Selection
1691 def RacialEnemySelect():
1692 global CharGenWindow, RacialEnemyWindow, RacialEnemyTextArea, RacialEnemyDoneButton
1694 CharGenWindow.SetVisible (WINDOW_INVISIBLE)
1695 RacialEnemyWindow = GemRB.LoadWindow (15)
1696 RacialEnemyCount = RacialEnemyTable.GetRowCount ()
1698 for i in range (2, 8):
1699 RacialEnemySelectButton = RacialEnemyWindow.GetControl (i)
1700 RacialEnemySelectButton.SetFlags (IE_GUI_BUTTON_RADIOBUTTON, OP_OR)
1702 for i in range (2, 8):
1703 RacialEnemySelectButton = RacialEnemyWindow.GetControl (i)
1704 RacialEnemySelectButton.SetState (IE_GUI_BUTTON_ENABLED)
1705 RacialEnemySelectButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, RacialEnemySelectPress)
1706 RacialEnemySelectButton.SetVarAssoc ("RacialEnemy", i - 1)
1708 GemRB.SetVar ("RacialEnemyIndex", 0)
1709 GemRB.SetVar ("HatedRace", 0)
1710 RacialEnemyScrollBar = RacialEnemyWindow.GetControl (1)
1711 RacialEnemyScrollBar.SetVarAssoc ("RacialEnemyIndex", RacialEnemyCount - 5)
1712 RacialEnemyScrollBar.SetEvent (IE_GUI_SCROLLBAR_ON_CHANGE, DisplayRacialEnemies)
1714 RacialEnemyTextArea = RacialEnemyWindow.GetControl (8)
1715 RacialEnemyTextArea.SetText (17256)
1717 RacialEnemyDoneButton = RacialEnemyWindow.GetControl (11)
1718 RacialEnemyDoneButton.SetState (IE_GUI_BUTTON_DISABLED)
1719 RacialEnemyDoneButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, RacialEnemyDonePress)
1720 RacialEnemyDoneButton.SetText (11973)
1721 RacialEnemyDoneButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
1723 RacialEnemyCancelButton = RacialEnemyWindow.GetControl (10)
1724 RacialEnemyCancelButton.SetState (IE_GUI_BUTTON_ENABLED)
1725 RacialEnemyCancelButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, RacialEnemyCancelPress)
1726 RacialEnemyCancelButton.SetText (13727)
1727 RacialEnemyCancelButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
1729 DisplayRacialEnemies()
1730 RacialEnemyWindow.SetVisible (WINDOW_VISIBLE)
1731 return
1733 def DisplayRacialEnemies():
1734 global RacialEnemyWindow
1736 RacialEnemyIndex = GemRB.GetVar ("RacialEnemyIndex")
1737 for i in range (2, 8):
1738 RacialEnemySelectButton = RacialEnemyWindow.GetControl (i)
1739 RacialEnemySelectButton.SetText (RacialEnemyTable.GetValue (RacialEnemyIndex + i - 2, 0))
1740 return
1742 def RacialEnemySelectPress():
1743 global RacialEnemyWindow, RacialEnemyDoneButton, RacialEnemyTextArea
1745 RacialEnemy = GemRB.GetVar ("RacialEnemyIndex") + GemRB.GetVar ("RacialEnemy") - 1
1746 RacialEnemyTextArea.SetText (RacialEnemyTable.GetValue (RacialEnemy, 2) )
1747 GemRB.SetVar ("HatedRace", RacialEnemyTable.GetValue (RacialEnemy, 1) )
1748 RacialEnemyDoneButton.SetState (IE_GUI_BUTTON_ENABLED)
1749 return
1751 def RacialEnemyDonePress():
1752 global CharGenWindow, RacialEnemyWindow, SkillsState
1754 if RacialEnemyWindow:
1755 RacialEnemyWindow.Unload ()
1757 SkillsState = 1
1758 CharGenWindow.SetVisible (WINDOW_VISIBLE)
1759 SkillsPress()
1760 return
1762 def RacialEnemyCancelPress():
1763 global CharGenWindow, RacialEnemyWindow, SkillsState
1765 if RacialEnemyWindow:
1766 RacialEnemyWindow.Unload ()
1767 SkillsState = 0
1768 CharGenWindow.SetVisible (WINDOW_VISIBLE)
1769 return
1772 # Weapon Proficiencies Selection
1774 def ProficienciesSelect():
1775 global CharGenWindow, ProficienciesWindow, ProficienciesTextArea
1776 global ProficienciesPointsLeft, ProficienciesDoneButton, ProfsMaxTable
1778 CharGenWindow.SetVisible (WINDOW_INVISIBLE)
1779 ProficienciesWindow = GemRB.LoadWindow (9)
1780 ProfsTable = GemRB.LoadTable ("profs")
1781 ProfsMaxTable = GemRB.LoadTable ("profsmax")
1782 ClassWeaponsTable = GemRB.LoadTable ("clasweap")
1784 Class = GemRB.GetPlayerStat (MyChar, IE_CLASS)
1785 ClassIndex = CommonTables.Classes.FindValue (5, Class)
1786 ClassName = CommonTables.Classes.GetRowName (ClassIndex)
1787 Class = ProfsTable.GetRowIndex (ClassName)
1788 ProficienciesPointsLeft = ProfsTable.GetValue (Class, 0)
1789 PointsLeftLabel = ProficienciesWindow.GetControl (0x10000009)
1790 PointsLeftLabel.SetUseRGB (1)
1791 PointsLeftLabel.SetText (str(ProficienciesPointsLeft))
1793 for i in range (8):
1794 ProficienciesLabel = ProficienciesWindow.GetControl (69 + i)
1795 ProficienciesLabel.SetState (IE_GUI_BUTTON_ENABLED)
1796 ProficienciesLabel.SetEvent (IE_GUI_BUTTON_ON_PRESS, ProficienciesLabelPress)
1797 ProficienciesLabel.SetVarAssoc ("ProficienciesIndex", i + 1)
1799 for j in range (5):
1800 ProficienciesMark = ProficienciesWindow.GetControl (27 + i * 5 + j)
1801 ProficienciesMark.SetSprites("GUIPFC", 0, 0, 0, 0, 0)
1802 ProficienciesMark.SetState (IE_GUI_BUTTON_DISABLED)
1803 ProficienciesMark.SetFlags (IE_GUI_BUTTON_NO_IMAGE, OP_OR)
1805 Allowed = ClassWeaponsTable.GetValue (ClassName, ProficienciesTable.GetRowName (i))
1807 ProficienciesPlusButton = ProficienciesWindow.GetControl (11 + i * 2)
1808 if Allowed == 0:
1809 ProficienciesPlusButton.SetState (IE_GUI_BUTTON_DISABLED)
1810 ProficienciesPlusButton.SetFlags (IE_GUI_BUTTON_NO_IMAGE, OP_OR)
1811 else:
1812 ProficienciesPlusButton.SetState (IE_GUI_BUTTON_ENABLED)
1813 ProficienciesPlusButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, ProficienciesPlusPress)
1814 ProficienciesPlusButton.SetVarAssoc ("ProficienciesIndex", i + 1)
1816 ProficienciesMinusButton = ProficienciesWindow.GetControl (12 + i * 2)
1817 if Allowed == 0:
1818 ProficienciesMinusButton.SetState (IE_GUI_BUTTON_DISABLED)
1819 ProficienciesMinusButton.SetFlags (IE_GUI_BUTTON_NO_IMAGE, OP_OR)
1820 else:
1821 ProficienciesMinusButton.SetState (IE_GUI_BUTTON_ENABLED)
1822 ProficienciesMinusButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, ProficienciesMinusPress)
1823 ProficienciesMinusButton.SetVarAssoc ("ProficienciesIndex", i + 1)
1825 for i in range (7):
1826 ProficienciesLabel = ProficienciesWindow.GetControl (85 + i)
1827 ProficienciesLabel.SetState (IE_GUI_BUTTON_ENABLED)
1828 ProficienciesLabel.SetEvent (IE_GUI_BUTTON_ON_PRESS, ProficienciesLabelPress)
1829 ProficienciesLabel.SetVarAssoc ("ProficienciesIndex", i + 9)
1831 for j in range (5):
1832 ProficienciesMark = ProficienciesWindow.GetControl (92 + i * 5 + j)
1833 ProficienciesMark.SetSprites("GUIPFC", 0, 0, 0, 0, 0)
1834 ProficienciesMark.SetState (IE_GUI_BUTTON_DISABLED)
1835 ProficienciesMark.SetFlags (IE_GUI_BUTTON_NO_IMAGE, OP_OR)
1837 Allowed = ClassWeaponsTable.GetValue (ClassName, ProficienciesTable.GetRowName (i + 8))
1839 ProficienciesPlusButton = ProficienciesWindow.GetControl (127 + i * 2)
1840 if Allowed == 0:
1841 ProficienciesPlusButton.SetState (IE_GUI_BUTTON_DISABLED)
1842 ProficienciesPlusButton.SetFlags (IE_GUI_BUTTON_NO_IMAGE, OP_OR)
1843 else:
1844 ProficienciesPlusButton.SetState (IE_GUI_BUTTON_ENABLED)
1845 ProficienciesPlusButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, ProficienciesPlusPress)
1846 ProficienciesPlusButton.SetVarAssoc ("ProficienciesIndex", i + 9)
1848 ProficienciesMinusButton = ProficienciesWindow.GetControl (128 + i * 2)
1849 if Allowed == 0:
1850 ProficienciesMinusButton.SetState (IE_GUI_BUTTON_DISABLED)
1851 ProficienciesMinusButton.SetFlags (IE_GUI_BUTTON_NO_IMAGE, OP_OR)
1852 else:
1853 ProficienciesMinusButton.SetState (IE_GUI_BUTTON_ENABLED)
1854 ProficienciesMinusButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, ProficienciesMinusPress)
1855 ProficienciesMinusButton.SetVarAssoc ("ProficienciesIndex", i + 9)
1857 for i in range (15):
1858 GemRB.SetVar ("Proficiency" + str(i), 0)
1860 GemRB.SetToken ("number", str(ProficienciesPointsLeft) )
1861 ProficienciesTextArea = ProficienciesWindow.GetControl (68)
1862 ProficienciesTextArea.SetText (9588)
1864 ProficienciesDoneButton = ProficienciesWindow.GetControl (0)
1865 ProficienciesDoneButton.SetState (IE_GUI_BUTTON_DISABLED)
1866 ProficienciesDoneButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, ProficienciesDonePress)
1867 ProficienciesDoneButton.SetText (11973)
1868 ProficienciesDoneButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
1870 ProficienciesCancelButton = ProficienciesWindow.GetControl (77)
1871 ProficienciesCancelButton.SetState (IE_GUI_BUTTON_ENABLED)
1872 ProficienciesCancelButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, ProficienciesCancelPress)
1873 ProficienciesCancelButton.SetText (13727)
1874 ProficienciesCancelButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
1876 ProficienciesWindow.SetVisible (WINDOW_VISIBLE)
1877 return
1879 def ProficienciesLabelPress():
1880 global ProficienciesWindow, ProficienciesTextArea
1882 ProficienciesIndex = GemRB.GetVar ("ProficienciesIndex") - 1
1883 ProficienciesTextArea.SetText (ProficienciesTable.GetValue (ProficienciesIndex, 2) )
1884 return
1886 def ProficienciesPlusPress():
1887 global ProficienciesWindow, ProficienciesTextArea
1888 global ProficienciesPointsLeft, ProfsMaxTable
1890 ProficienciesIndex = GemRB.GetVar ("ProficienciesIndex") - 1
1891 ProficienciesValue = GemRB.GetVar ("Proficiency" + str(ProficienciesIndex) )
1892 Class = GemRB.GetPlayerStat (MyChar, IE_CLASS)
1893 ClassIndex = CommonTables.Classes.FindValue (5, Class)
1894 ClassName = CommonTables.Classes.GetRowName (ClassIndex)
1895 Class = ProfsMaxTable.GetRowIndex (ClassName)
1896 if ProficienciesPointsLeft > 0 and ProficienciesValue < ProfsMaxTable.GetValue (Class, 0):
1897 ProficienciesPointsLeft = ProficienciesPointsLeft - 1
1898 PointsLeftLabel = ProficienciesWindow.GetControl (0x10000009)
1899 PointsLeftLabel.SetText (str(ProficienciesPointsLeft))
1900 if ProficienciesPointsLeft == 0:
1901 ProficienciesDoneButton.SetState (IE_GUI_BUTTON_ENABLED)
1903 ProficienciesValue = ProficienciesValue + 1
1904 GemRB.SetVar ("Proficiency" + str(ProficienciesIndex), ProficienciesValue)
1905 if ProficienciesIndex < 8:
1906 ControlID = 26 + ProficienciesIndex * 5 + ProficienciesValue
1907 else:
1908 ControlID = 51 + ProficienciesIndex * 5 + ProficienciesValue
1909 ProficienciesMark = ProficienciesWindow.GetControl (ControlID)
1910 ProficienciesMark.SetFlags (IE_GUI_BUTTON_NO_IMAGE, OP_NAND)
1912 ProficienciesTextArea.SetText (ProficienciesTable.GetValue (ProficienciesIndex, 2) )
1913 return
1915 def ProficienciesMinusPress():
1916 global ProficienciesWindow, ProficienciesTextArea, ProficienciesPointsLeft
1918 ProficienciesIndex = GemRB.GetVar ("ProficienciesIndex") - 1
1919 ProficienciesValue = GemRB.GetVar ("Proficiency" + str(ProficienciesIndex) )
1920 if ProficienciesValue > 0:
1921 ProficienciesValue = ProficienciesValue - 1
1922 GemRB.SetVar ("Proficiency" + str(ProficienciesIndex), ProficienciesValue)
1923 if ProficienciesIndex < 8:
1924 ControlID = 27 + ProficienciesIndex * 5 + ProficienciesValue
1925 else:
1926 ControlID = 52 + ProficienciesIndex * 5 + ProficienciesValue
1927 ProficienciesMark = ProficienciesWindow.GetControl (ControlID)
1928 ProficienciesMark.SetFlags (IE_GUI_BUTTON_NO_IMAGE, OP_OR)
1930 ProficienciesPointsLeft = ProficienciesPointsLeft + 1
1931 PointsLeftLabel = ProficienciesWindow.GetControl (0x10000009)
1932 PointsLeftLabel.SetText (str(ProficienciesPointsLeft))
1933 ProficienciesDoneButton.SetState (IE_GUI_BUTTON_DISABLED)
1935 ProficienciesTextArea.SetText (ProficienciesTable.GetValue (ProficienciesIndex, 2) )
1936 return
1938 def ProficienciesDonePress():
1939 global CharGenWindow, ProficienciesWindow, SkillsState
1941 if ProficienciesWindow:
1942 ProficienciesWindow.Unload ()
1943 SkillsState = 2
1944 CharGenWindow.SetVisible (WINDOW_VISIBLE)
1945 SkillsPress()
1946 return
1948 def ProficienciesCancelPress():
1949 global CharGenWindow, ProficienciesWindow, SkillsState
1951 if ProficienciesWindow:
1952 ProficienciesWindow.Unload ()
1953 SkillsState = 0
1954 CharGenWindow.SetVisible (WINDOW_VISIBLE)
1955 return
1957 # Spells Selection
1959 def MageSpellsSelect(SpellTable, Level, SpellLevel):
1960 global CharGenWindow, MageSpellsWindow, MageSpellsTextArea, MageSpellsDoneButton, MageSpellsSelectPointsLeft, Learnable
1962 CharGenWindow.SetVisible (WINDOW_INVISIBLE)
1963 MageSpellsWindow = GemRB.LoadWindow (7)
1964 #kit (school), alignment, level
1965 k = GemRB.GetPlayerStat (MyChar, IE_KIT)
1966 t = GemRB.GetPlayerStat (MyChar, IE_ALIGNMENT)
1967 Learnable = GUICommon.GetLearnableMageSpells(k, t, SpellLevel)
1968 GemRB.SetVar ("MageSpellBook", 0)
1969 GemRB.SetVar ("SpellMask", 0)
1971 if len(Learnable)<1:
1972 MageSpellsDonePress()
1973 return
1975 if k>0:
1976 MageSpellsSelectPointsLeft = 3
1977 else:
1978 MageSpellsSelectPointsLeft = 2
1979 PointsLeftLabel = MageSpellsWindow.GetControl (0x1000001b)
1980 PointsLeftLabel.SetUseRGB (1)
1981 PointsLeftLabel.SetText (str(MageSpellsSelectPointsLeft))
1983 for i in range (24):
1984 SpellButton = MageSpellsWindow.GetControl (i + 2)
1985 SpellButton.SetFlags (IE_GUI_BUTTON_PICTURE|IE_GUI_BUTTON_CHECKBOX, OP_OR)
1986 if i < len(Learnable):
1987 Spell = GemRB.GetSpell (Learnable[i])
1988 SpellButton.SetSpellIcon(Learnable[i], 1)
1989 SpellButton.SetState (IE_GUI_BUTTON_ENABLED)
1990 SpellButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, MageSpellsSelectPress)
1991 SpellButton.SetVarAssoc ("SpellMask", 1 << i)
1992 SpellButton.SetTooltip(Spell["SpellName"])
1993 else:
1994 SpellButton.SetState (IE_GUI_BUTTON_DISABLED)
1996 GemRB.SetToken ("number", str(MageSpellsSelectPointsLeft))
1997 MageSpellsTextArea = MageSpellsWindow.GetControl (27)
1998 MageSpellsTextArea.SetText (17250)
2000 MageSpellsDoneButton = MageSpellsWindow.GetControl (0)
2001 MageSpellsDoneButton.SetState (IE_GUI_BUTTON_DISABLED)
2002 MageSpellsDoneButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, MageSpellsDonePress)
2003 MageSpellsDoneButton.SetText (11973)
2004 MageSpellsDoneButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
2006 MageSpellsCancelButton = MageSpellsWindow.GetControl (29)
2007 MageSpellsCancelButton.SetState (IE_GUI_BUTTON_ENABLED)
2008 MageSpellsCancelButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, MageSpellsCancelPress)
2009 MageSpellsCancelButton.SetText (13727)
2010 MageSpellsCancelButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
2012 MageSpellsWindow.SetVisible (WINDOW_VISIBLE)
2013 return
2015 def MageSpellsSelectPress():
2016 global MageSpellsWindow, MageSpellsTextArea, MageSpellsDoneButton, MageSpellsSelectPointsLeft, Learnable
2018 MageSpellBook = GemRB.GetVar ("MageSpellBook")
2019 SpellMask = GemRB.GetVar ("SpellMask")
2021 #getting the bit index
2022 Spell = abs(MageSpellBook - SpellMask)
2023 i = -1
2024 while (Spell > 0):
2025 i = i + 1
2026 Spell = Spell >> 1
2028 Spell = GemRB.GetSpell (Learnable[i])
2029 MageSpellsTextArea.SetText (Spell["SpellDesc"])
2031 if SpellMask < MageSpellBook:
2032 MageSpellsSelectPointsLeft = MageSpellsSelectPointsLeft + 1
2033 else:
2034 if MageSpellsSelectPointsLeft==0:
2035 SpellMask = MageSpellBook
2036 GemRB.SetVar ("SpellMask", SpellMask)
2037 else:
2038 MageSpellsSelectPointsLeft = MageSpellsSelectPointsLeft - 1
2040 if MageSpellsSelectPointsLeft == 0:
2041 MageSpellsDoneButton.SetState (IE_GUI_BUTTON_ENABLED)
2042 else:
2043 MageSpellsDoneButton.SetState (IE_GUI_BUTTON_DISABLED)
2045 for i in range (len(Learnable)):
2046 SpellButton = MageSpellsWindow.GetControl (i + 2)
2047 if ((1 << i) & SpellMask) == 0:
2048 SpellButton.SetState (IE_GUI_BUTTON_LOCKED)
2050 PointsLeftLabel = MageSpellsWindow.GetControl (0x1000001b)
2051 PointsLeftLabel.SetText (str(MageSpellsSelectPointsLeft))
2052 GemRB.SetVar ("MageSpellBook", SpellMask)
2053 return
2055 def MageSpellsDonePress():
2056 global CharGenWindow, MageSpellsWindow, SkillsState
2058 if MageSpellsWindow:
2059 MageSpellsWindow.Unload ()
2060 SkillsState = 3
2061 CharGenWindow.SetVisible (WINDOW_VISIBLE)
2062 SkillsPress()
2063 return
2065 def MageSpellsCancelPress():
2066 global CharGenWindow, MageSpellsWindow, SkillsState
2068 if MageSpellsWindow:
2069 MageSpellsWindow.Unload ()
2070 SkillsState = 0
2071 CharGenWindow.SetVisible (WINDOW_VISIBLE)
2072 return
2075 # Mage Spells Memorize
2077 def MageSpellsMemorize(SpellTable, Level, SpellLevel):
2078 global CharGenWindow, MageMemorizeWindow, MageMemorizeTextArea, MageMemorizeDoneButton, MageMemorizePointsLeft
2080 CharGenWindow.SetVisible (WINDOW_INVISIBLE)
2081 MageMemorizeWindow = GemRB.LoadWindow (16)
2082 MaxSpellsMageTable = GemRB.LoadTable (SpellTable)
2083 MageSpellBook = GemRB.GetVar ("MageSpellBook")
2084 GemRB.SetVar ("MageMemorized", 0)
2085 GemRB.SetVar ("SpellMask", 0)
2087 MageMemorizePointsLeft = MaxSpellsMageTable.GetValue (str(Level), str(SpellLevel) )
2088 if MageMemorizePointsLeft<1 or len(Learnable)<1:
2089 MageMemorizeDonePress()
2090 return
2092 PointsLeftLabel = MageMemorizeWindow.GetControl (0x1000001b)
2093 PointsLeftLabel.SetUseRGB (1)
2094 PointsLeftLabel.SetText (str(MageMemorizePointsLeft))
2096 j = 0
2097 for i in range (12):
2098 SpellButton = MageMemorizeWindow.GetControl (i + 2)
2099 SpellButton.SetFlags (IE_GUI_BUTTON_PICTURE|IE_GUI_BUTTON_CHECKBOX, OP_OR)
2100 while (j < len(Learnable)) and (((1 << j) & MageSpellBook) == 0):
2101 j = j + 1
2102 if j < len(Learnable):
2103 Spell = GemRB.GetSpell (Learnable[j])
2104 SpellButton.SetTooltip(Spell["SpellName"])
2105 SpellButton.SetSpellIcon(Learnable[j], 1)
2106 SpellButton.SetState (IE_GUI_BUTTON_ENABLED)
2107 SpellButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, MageMemorizeSelectPress)
2108 SpellButton.SetVarAssoc ("SpellMask", 1 << j)
2109 j = j + 1
2110 else:
2111 SpellButton.SetState (IE_GUI_BUTTON_DISABLED)
2113 GemRB.SetToken ("number", str(MageMemorizePointsLeft))
2114 MageMemorizeTextArea = MageMemorizeWindow.GetControl (27)
2115 MageMemorizeTextArea.SetText (17253)
2117 MageMemorizeDoneButton = MageMemorizeWindow.GetControl (0)
2118 MageMemorizeDoneButton.SetState (IE_GUI_BUTTON_DISABLED)
2119 MageMemorizeDoneButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, MageMemorizeDonePress)
2120 MageMemorizeDoneButton.SetText (11973)
2121 MageMemorizeDoneButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
2123 MageMemorizeCancelButton = MageMemorizeWindow.GetControl (29)
2124 MageMemorizeCancelButton.SetState (IE_GUI_BUTTON_ENABLED)
2125 MageMemorizeCancelButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, MageMemorizeCancelPress)
2126 MageMemorizeCancelButton.SetText (13727)
2127 MageMemorizeCancelButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
2129 MageMemorizeWindow.SetVisible (WINDOW_VISIBLE)
2130 return
2132 def MageMemorizeSelectPress():
2133 global MageMemorizeWindow, MageMemorizeTextArea, MageMemorizeDoneButton, MageMemorizePointsLeft, Learnable
2135 MageSpellBook = GemRB.GetVar ("MageSpellBook")
2136 MageMemorized = GemRB.GetVar ("MageMemorized")
2137 SpellMask = GemRB.GetVar ("SpellMask")
2139 Spell = abs(MageMemorized - SpellMask)
2140 i = -1
2141 while (Spell > 0):
2142 i = i + 1
2143 Spell = Spell >> 1
2145 Spell = GemRB.GetSpell (Learnable[i])
2146 MageMemorizeTextArea.SetText (Spell["SpellDesc"])
2148 if SpellMask < MageMemorized:
2149 MageMemorizePointsLeft = MageMemorizePointsLeft + 1
2150 j = 0
2151 for i in range (12):
2152 SpellButton = MageMemorizeWindow.GetControl (i + 2)
2153 while (j < len(Learnable) ) and (((1 << j) & MageSpellBook) == 0):
2154 j = j + 1
2155 if j < len(Learnable):
2156 SpellButton.SetState (IE_GUI_BUTTON_ENABLED)
2157 j = j + 1
2158 MageMemorizeDoneButton.SetState (IE_GUI_BUTTON_DISABLED)
2159 else:
2160 MageMemorizePointsLeft = MageMemorizePointsLeft - 1
2161 if MageMemorizePointsLeft == 0:
2162 j = 0
2163 for i in range (12):
2164 SpellButton = MageMemorizeWindow.GetControl (i + 2)
2165 while (j < len(Learnable) ) and (((1 << j) & MageSpellBook) == 0):
2166 j = j + 1
2167 if j < len(Learnable):
2168 if ((1 << j) & SpellMask) == 0:
2169 SpellButton.SetState (IE_GUI_BUTTON_DISABLED)
2170 j = j + 1
2171 MageMemorizeDoneButton.SetState (IE_GUI_BUTTON_ENABLED)
2173 PointsLeftLabel = MageMemorizeWindow.GetControl (0x1000001b)
2174 PointsLeftLabel.SetText (str(MageMemorizePointsLeft))
2175 GemRB.SetVar ("MageMemorized", SpellMask)
2176 return
2178 def MageMemorizeDonePress():
2179 global CharGenWindow, MageMemorizeWindow, SkillsState
2181 if MageMemorizeWindow:
2182 MageMemorizeWindow.Unload ()
2183 SkillsState = 4
2184 CharGenWindow.SetVisible (WINDOW_VISIBLE)
2185 SkillsPress()
2186 return
2188 def MageMemorizeCancelPress():
2189 global CharGenWindow, MageMemorizeWindow, SkillsState
2191 if MageMemorizeWindow:
2192 MageMemorizeWindow.Unload ()
2193 SkillsState = 0
2194 CharGenWindow.SetVisible (WINDOW_VISIBLE)
2195 return
2197 # Priest Spells Memorize
2199 def PriestSpellsMemorize(SpellTable, Level, SpellLevel):
2200 global CharGenWindow, PriestMemorizeWindow, Learnable, ClassFlag
2201 global PriestMemorizeTextArea, PriestMemorizeDoneButton, PriestMemorizePointsLeft
2203 CharGenWindow.SetVisible (WINDOW_INVISIBLE)
2204 PriestMemorizeWindow = GemRB.LoadWindow (17)
2205 t = AlignmentTable.GetValue ( GemRB.GetVar ("Alignment")-1, 3)
2206 Learnable = GUICommon.GetLearnablePriestSpells( ClassFlag, t, SpellLevel)
2208 MaxSpellsPriestTable = GemRB.LoadTable (SpellTable)
2209 GemRB.SetVar ("PriestMemorized", 0)
2210 GemRB.SetVar ("SpellMask", 0)
2212 PriestMemorizePointsLeft = MaxSpellsPriestTable.GetValue (str(Level), str(SpellLevel) )
2213 if PriestMemorizePointsLeft<1 or len(Learnable)<1:
2214 PriestMemorizeDonePress()
2215 return
2217 PointsLeftLabel = PriestMemorizeWindow.GetControl (0x1000001b)
2218 PointsLeftLabel.SetUseRGB (1)
2219 PointsLeftLabel.SetText (str(PriestMemorizePointsLeft))
2221 for i in range (12):
2222 SpellButton = PriestMemorizeWindow.GetControl (i + 2)
2223 SpellButton.SetFlags (IE_GUI_BUTTON_PICTURE|IE_GUI_BUTTON_CHECKBOX, OP_OR)
2224 if i < len(Learnable):
2225 Spell = GemRB.GetSpell (Learnable[i])
2226 SpellButton.SetTooltip(Spell["SpellName"])
2227 SpellButton.SetSpellIcon(Learnable[i], 1)
2228 SpellButton.SetState (IE_GUI_BUTTON_ENABLED)
2229 SpellButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, PriestMemorizeSelectPress)
2230 SpellButton.SetVarAssoc ("SpellMask", 1 << i)
2231 else:
2232 SpellButton.SetState (IE_GUI_BUTTON_DISABLED)
2234 GemRB.SetToken ("number", str(PriestMemorizePointsLeft))
2235 PriestMemorizeTextArea = PriestMemorizeWindow.GetControl (27)
2236 PriestMemorizeTextArea.SetText (17253)
2238 PriestMemorizeDoneButton = PriestMemorizeWindow.GetControl (0)
2239 PriestMemorizeDoneButton.SetState (IE_GUI_BUTTON_DISABLED)
2240 PriestMemorizeDoneButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, PriestMemorizeDonePress)
2241 PriestMemorizeDoneButton.SetText (11973)
2242 PriestMemorizeDoneButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
2244 PriestMemorizeCancelButton = PriestMemorizeWindow.GetControl (29)
2245 PriestMemorizeCancelButton.SetState (IE_GUI_BUTTON_ENABLED)
2246 PriestMemorizeCancelButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, PriestMemorizeCancelPress)
2247 PriestMemorizeCancelButton.SetText (13727)
2248 PriestMemorizeCancelButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
2250 PriestMemorizeWindow.SetVisible (WINDOW_VISIBLE)
2251 return
2253 def PriestMemorizeSelectPress():
2254 global PriestMemorizeWindow, Learnable, PriestMemorizeTextArea, PriestMemorizeDoneButton, PriestMemorizePointsLeft
2256 PriestMemorized = GemRB.GetVar ("PriestMemorized")
2257 SpellMask = GemRB.GetVar ("SpellMask")
2258 Spell = abs(PriestMemorized - SpellMask)
2260 i = -1
2261 while (Spell > 0):
2262 i = i + 1
2263 Spell = Spell >> 1
2265 Spell=GemRB.GetSpell (Learnable[i])
2266 PriestMemorizeTextArea.SetText (Spell["SpellDesc"])
2268 if SpellMask < PriestMemorized:
2269 PriestMemorizePointsLeft = PriestMemorizePointsLeft + 1
2270 for i in range (len(Learnable)):
2271 SpellButton = PriestMemorizeWindow.GetControl (i + 2)
2272 if (((1 << i) & SpellMask) == 0):
2273 SpellButton.SetState (IE_GUI_BUTTON_ENABLED)
2274 PriestMemorizeDoneButton.SetState (IE_GUI_BUTTON_DISABLED)
2275 else:
2276 PriestMemorizePointsLeft = PriestMemorizePointsLeft - 1
2277 if PriestMemorizePointsLeft == 0:
2278 for i in range (len(Learnable)):
2279 SpellButton = PriestMemorizeWindow.GetControl (i + 2)
2280 if ((1 << i) & SpellMask) == 0:
2281 SpellButton.SetState (IE_GUI_BUTTON_DISABLED)
2282 PriestMemorizeDoneButton.SetState (IE_GUI_BUTTON_ENABLED)
2284 PointsLeftLabel = PriestMemorizeWindow.GetControl (0x1000001b)
2285 PointsLeftLabel.SetText (str(PriestMemorizePointsLeft))
2286 GemRB.SetVar ("PriestMemorized", SpellMask)
2287 return
2289 def PriestMemorizeDonePress():
2290 global CharGenWindow, PriestMemorizeWindow, SkillsState
2292 if PriestMemorizeWindow:
2293 PriestMemorizeWindow.Unload ()
2294 SkillsState = 5
2295 CharGenWindow.SetVisible (WINDOW_VISIBLE)
2296 SkillsPress()
2297 return
2299 def PriestMemorizeCancelPress():
2300 global CharGenWindow, PriestMemorizeWindow, SkillsState
2302 if PriestMemorizeWindow:
2303 PriestMemorizeWindow.Unload ()
2304 SkillsState = 0
2305 CharGenWindow.SetVisible (WINDOW_VISIBLE)
2306 return
2308 # Appearance Selection
2310 def AppearancePress():
2311 global CharGenWindow, AppearanceWindow, AppearanceTable
2312 global Portrait, AppearanceAvatarButton, PortraitName
2313 global AppearanceHairButton, AppearanceSkinButton
2314 global AppearanceMajorButton, AppearanceMinorButton
2315 global HairColor, SkinColor, MajorColor, MinorColor
2317 CharGenWindow.SetVisible (WINDOW_INVISIBLE)
2318 AppearanceWindow = GemRB.LoadWindow (13)
2319 AppearanceTable = GemRB.LoadTable ("PORTCOLR")
2321 if Portrait<0:
2322 PortraitIndex = 0
2323 else:
2324 PortraitName = PortraitsTable.GetRowName (Portrait)
2325 PortraitIndex = AppearanceTable.GetRowIndex (PortraitName + "L")
2327 HairColor = AppearanceTable.GetValue (PortraitIndex, 1)
2328 GemRB.SetVar ("HairColor", HairColor)
2329 SkinColor = AppearanceTable.GetValue (PortraitIndex, 0)
2330 GemRB.SetVar ("SkinColor", SkinColor)
2331 MajorColor = AppearanceTable.GetValue (PortraitIndex, 2)
2332 GemRB.SetVar ("MajorColor", MajorColor)
2333 MinorColor = AppearanceTable.GetValue (PortraitIndex, 3)
2334 GemRB.SetVar ("MinorColor", MinorColor)
2336 AppearanceAvatarButton = AppearanceWindow.GetControl (1)
2337 AppearanceAvatarButton.SetState (IE_GUI_BUTTON_LOCKED)
2338 AppearanceAvatarButton.SetFlags (IE_GUI_BUTTON_PICTURE|IE_GUI_BUTTON_ANIMATED, OP_OR)
2339 DrawAvatar()
2341 AppearanceHairButton = AppearanceWindow.GetControl (2)
2342 AppearanceHairButton.SetFlags (IE_GUI_BUTTON_PICTURE, OP_OR)
2343 AppearanceHairButton.SetState (IE_GUI_BUTTON_ENABLED)
2344 AppearanceHairButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, AppearanceHairPress)
2345 AppearanceHairButton.SetBAM ("COLGRAD", 0, 0, HairColor)
2347 AppearanceSkinButton = AppearanceWindow.GetControl (3)
2348 AppearanceSkinButton.SetFlags (IE_GUI_BUTTON_PICTURE, OP_OR)
2349 AppearanceSkinButton.SetState (IE_GUI_BUTTON_ENABLED)
2350 AppearanceSkinButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, AppearanceSkinPress)
2351 AppearanceSkinButton.SetBAM ("COLGRAD", 0, 0, SkinColor)
2353 AppearanceMajorButton = AppearanceWindow.GetControl (4)
2354 AppearanceMajorButton.SetFlags (IE_GUI_BUTTON_PICTURE, OP_OR)
2355 AppearanceMajorButton.SetState (IE_GUI_BUTTON_ENABLED)
2356 AppearanceMajorButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, AppearanceMajorPress)
2357 AppearanceMajorButton.SetBAM ("COLGRAD", 0, 0, MajorColor)
2359 AppearanceMinorButton = AppearanceWindow.GetControl (5)
2360 AppearanceMinorButton.SetFlags (IE_GUI_BUTTON_PICTURE, OP_OR)
2361 AppearanceMinorButton.SetState (IE_GUI_BUTTON_ENABLED)
2362 AppearanceMinorButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, AppearanceMinorPress)
2363 AppearanceMinorButton.SetBAM ("COLGRAD", 0, 0, MinorColor)
2365 AppearanceDoneButton = AppearanceWindow.GetControl (0)
2366 AppearanceDoneButton.SetState (IE_GUI_BUTTON_ENABLED)
2367 AppearanceDoneButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, AppearanceDonePress)
2368 AppearanceDoneButton.SetText (11973)
2369 AppearanceDoneButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
2371 AppearanceCancelButton = AppearanceWindow.GetControl (13)
2372 AppearanceCancelButton.SetState (IE_GUI_BUTTON_ENABLED)
2373 AppearanceCancelButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, AppearanceCancelPress)
2374 AppearanceCancelButton.SetText (13727)
2375 AppearanceCancelButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
2377 AppearanceWindow.SetVisible (WINDOW_VISIBLE)
2378 return
2380 def DrawAvatar():
2381 global AppearanceAvatarButton
2382 global MyChar
2384 AvatarID = 0x6000
2385 table = GemRB.LoadTable ("avprefr")
2386 lookup = CommonTables.Races.FindValue (3, GemRB.GetPlayerStat(MyChar, IE_RACE))
2387 lookup = CommonTables.Races.GetRowName (lookup)
2388 AvatarID = AvatarID+table.GetValue (lookup, "RACE")
2389 table = GemRB.LoadTable ("avprefc")
2390 lookup = CommonTables.Classes.FindValue (5, GemRB.GetPlayerStat(MyChar, IE_CLASS))
2391 lookup = CommonTables.Classes.GetRowName (lookup)
2392 AvatarID = AvatarID+table.GetValue (lookup, "PREFIX")
2393 table = GemRB.LoadTable ("avprefg")
2394 AvatarID = AvatarID+table.GetValue (GemRB.GetPlayerStat(MyChar,IE_SEX),0)
2396 AvatarRef = CommonTables.Pdolls.GetValue (hex(AvatarID), "LEVEL1")
2397 AppearanceAvatarButton.SetPLT(AvatarRef, 0, MinorColor, MajorColor, SkinColor, 0, 0, HairColor, 0)
2399 return
2401 def AppearanceHairPress():
2402 GemRB.SetVar ("ColorType", 0)
2403 AppearanceColorChoice (GemRB.GetVar ("HairColor"))
2404 return
2406 def AppearanceSkinPress():
2407 GemRB.SetVar ("ColorType", 1)
2408 AppearanceColorChoice (GemRB.GetVar ("SkinColor"))
2409 return
2411 def AppearanceMajorPress():
2412 GemRB.SetVar ("ColorType", 2)
2413 AppearanceColorChoice (GemRB.GetVar ("MajorColor"))
2414 return
2416 def AppearanceMinorPress():
2417 GemRB.SetVar ("ColorType", 3)
2418 AppearanceColorChoice (GemRB.GetVar ("MinorColor"))
2419 return
2421 def AppearanceColorChoice (CurrentColor):
2422 global AppearanceWindow, AppearanceColorWindow
2424 AppearanceWindow.SetVisible (WINDOW_INVISIBLE)
2425 AppearanceColorWindow = GemRB.LoadWindow (14)
2426 AppearanceColorTable = GemRB.LoadTable ("clowncol")
2427 ColorType = GemRB.GetVar ("ColorType")
2428 GemRB.SetVar ("SelectedColor", CurrentColor)
2430 for i in range (34):
2431 ColorButton = AppearanceColorWindow.GetControl (i)
2432 ColorButton.SetState (IE_GUI_BUTTON_ENABLED)
2433 ColorButton.SetFlags (IE_GUI_BUTTON_PICTURE, OP_OR)
2435 for i in range (34):
2436 Color = AppearanceColorTable.GetValue (ColorType, i)
2437 if Color != "*":
2438 ColorButton = AppearanceColorWindow.GetControl (i)
2439 ColorButton.SetBAM ("COLGRAD", 0, 0, Color)
2440 ColorButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, AppearanceColorSelected)
2441 ColorButton.SetVarAssoc ("SelectedColor", Color)
2443 AppearanceColorWindow.SetVisible (WINDOW_VISIBLE)
2444 return
2446 def AppearanceColorSelected():
2447 global HairColor, SkinColor, MajorColor, MinorColor
2448 global AppearanceWindow, AppearanceColorWindow
2449 global AppearanceHairButton, AppearanceSkinButton
2450 global AppearanceMajorButton, AppearanceMinorButton
2452 if AppearanceColorWindow:
2453 AppearanceColorWindow.Unload ()
2454 ColorType = GemRB.GetVar ("ColorType")
2455 if ColorType == 0:
2456 HairColor = GemRB.GetVar ("SelectedColor")
2457 GemRB.SetVar ("HairColor", HairColor)
2458 AppearanceHairButton.SetBAM ("COLGRAD", 0, 0, HairColor)
2459 elif ColorType == 1:
2460 SkinColor = GemRB.GetVar ("SelectedColor")
2461 GemRB.SetVar ("SkinColor", SkinColor)
2462 AppearanceSkinButton.SetBAM ("COLGRAD", 0, 0, SkinColor)
2463 elif ColorType == 2:
2464 MajorColor = GemRB.GetVar ("SelectedColor")
2465 GemRB.SetVar ("MajorColor", MajorColor)
2466 AppearanceMajorButton.SetBAM ("COLGRAD", 0, 0, MajorColor)
2467 elif ColorType == 3:
2468 MinorColor = GemRB.GetVar ("SelectedColor")
2469 GemRB.SetVar ("MinorColor", MinorColor)
2470 AppearanceMinorButton.SetBAM ("COLGRAD", 0, 0, MinorColor)
2471 DrawAvatar()
2472 AppearanceWindow.SetVisible (WINDOW_VISIBLE)
2473 return
2475 def AppearanceDonePress():
2476 global CharGenWindow, AppearanceWindow
2478 if AppearanceWindow:
2479 AppearanceWindow.Unload ()
2480 CharGenWindow.SetVisible (WINDOW_VISIBLE)
2481 CharSoundSelect()
2482 return
2484 def AppearanceCancelPress():
2485 global CharGenWindow, AppearanceWindow
2487 if AppearanceWindow:
2488 AppearanceWindow.Unload ()
2489 CharGenWindow.SetVisible (WINDOW_VISIBLE)
2490 return
2492 def CharSoundSelect():
2493 global CharGenWindow, CharSoundWindow, CharSoundTable, CharSoundStrings
2494 global CharSoundVoiceList, VerbalConstants
2496 CharGenWindow.SetVisible (WINDOW_INVISIBLE)
2497 CharSoundWindow = GemRB.LoadWindow (19)
2498 CharSoundTable = GemRB.LoadTable ("CHARSND")
2499 CharSoundStrings = GemRB.LoadTable ("CHARSTR")
2501 VerbalConstants = [CharSoundTable.GetRowName(i) for i in range(CharSoundTable.GetRowCount())]
2502 CharSoundVoiceList = CharSoundWindow.GetControl (45)
2503 CharSoundVoiceList.SetFlags (IE_GUI_TEXTAREA_SELECTABLE)
2504 RowCount=CharSoundVoiceList.GetCharSounds()
2506 CharSoundPlayButton = CharSoundWindow.GetControl (47)
2507 CharSoundPlayButton.SetState (IE_GUI_BUTTON_ENABLED)
2508 CharSoundPlayButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, CharSoundPlayPress)
2509 CharSoundPlayButton.SetText (17318)
2511 CharSoundTextArea = CharSoundWindow.GetControl (50)
2512 CharSoundTextArea.SetText (11315)
2514 CharSoundDoneButton = CharSoundWindow.GetControl (0)
2515 CharSoundDoneButton.SetState (IE_GUI_BUTTON_ENABLED)
2516 CharSoundDoneButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, CharSoundDonePress)
2517 CharSoundDoneButton.SetText (11973)
2518 CharSoundDoneButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
2520 CharSoundCancelButton = CharSoundWindow.GetControl (10)
2521 CharSoundCancelButton.SetState (IE_GUI_BUTTON_ENABLED)
2522 CharSoundCancelButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, CharSoundCancelPress)
2523 CharSoundCancelButton.SetText (13727)
2524 CharSoundCancelButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
2526 CharSoundWindow.SetVisible (WINDOW_VISIBLE)
2527 return
2529 def CharSoundPlayPress():
2530 global CharGenWindow, CharSoundWindow, CharSoundTable, CharSoundStrings
2531 global CharSoundVoiceList, SoundIndex, VerbalConstants
2533 row = CharSoundVoiceList.QueryText ()
2535 GemRB.SetPlayerSound (MyChar, row)
2537 #play sound as sound slot
2538 GemRB.VerbalConstant (MyChar, int(VerbalConstants[SoundIndex]))
2540 SoundIndex += 1
2541 if SoundIndex >= len(VerbalConstants):
2542 SoundIndex = 0
2543 return
2545 def CharSoundDonePress():
2546 global CharGenWindow, CharSoundWindow, AppearanceButton, BiographyButton, NameButton, CharGenState
2548 if CharSoundWindow:
2549 CharSoundWindow.Unload ()
2550 AppearanceButton.SetState (IE_GUI_BUTTON_DISABLED)
2551 AppearanceButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_NAND)
2552 BiographyButton.SetState (IE_GUI_BUTTON_ENABLED)
2553 NameButton.SetState (IE_GUI_BUTTON_ENABLED)
2554 NameButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
2555 CharGenState = 7
2556 SetCharacterDescription()
2557 CharGenWindow.SetVisible (WINDOW_VISIBLE)
2558 return
2560 def CharSoundCancelPress():
2561 global CharGenWindow, CharSoundWindow
2563 if CharSoundWindow:
2564 CharSoundWindow.Unload ()
2565 CharGenWindow.SetVisible (WINDOW_VISIBLE)
2566 return
2568 # Biography Selection
2570 def BiographyPress():
2571 global CharGenWindow, BiographyWindow, BiographyField
2573 CharGenWindow.SetVisible (WINDOW_INVISIBLE)
2574 BiographyWindow = GemRB.LoadWindow (51)
2576 BiographyField = BiographyWindow.GetControl (4)
2577 BiographyField.SetText (19423)
2579 BiographyClearButton = BiographyWindow.GetControl (5)
2580 BiographyClearButton.SetState (IE_GUI_BUTTON_ENABLED)
2581 BiographyClearButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, BiographyClearPress)
2582 BiographyClearButton.SetText (18622)
2584 BiographyCancelButton = BiographyWindow.GetControl (2)
2585 BiographyCancelButton.SetState (IE_GUI_BUTTON_ENABLED)
2586 BiographyCancelButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, BiographyCancelPress)
2587 BiographyCancelButton.SetText (13727)
2588 BiographyCancelButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
2590 BiographyDoneButton = BiographyWindow.GetControl (1)
2591 BiographyDoneButton.SetState (IE_GUI_BUTTON_ENABLED)
2592 BiographyDoneButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, BiographyDonePress)
2593 BiographyDoneButton.SetText (11973)
2594 BiographyDoneButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
2596 BiographyWindow.SetVisible (WINDOW_VISIBLE)
2597 return
2599 def BiographyClearPress():
2600 global BiographyWindow, BiographyField
2602 BiographyField.SetText ("")
2603 return
2605 def BiographyCancelPress():
2606 global CharGenWindow, BiographyWindow
2608 if BiographyWindow:
2609 BiographyWindow.Unload ()
2610 CharGenWindow.SetVisible (WINDOW_VISIBLE)
2611 return
2613 def BiographyDonePress():
2614 global CharGenWindow, BiographyWindow, BiographyField
2616 GemRB.SetToken ("Biography", BiographyField.QueryText () )
2617 if BiographyWindow:
2618 BiographyWindow.Unload ()
2619 CharGenWindow.SetVisible (WINDOW_VISIBLE)
2620 return
2622 # Name Selection
2624 def NamePress():
2625 global CharGenWindow, NameWindow, NameDoneButton, NameField
2627 CharGenWindow.SetVisible (WINDOW_INVISIBLE)
2628 NameWindow = GemRB.LoadWindow (5)
2630 NameDoneButton = NameWindow.GetControl (0)
2631 NameDoneButton.SetState (IE_GUI_BUTTON_DISABLED)
2632 NameDoneButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, NameDonePress)
2633 NameDoneButton.SetText (11973)
2634 NameDoneButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
2636 NameCancelButton = NameWindow.GetControl (3)
2637 NameCancelButton.SetState (IE_GUI_BUTTON_ENABLED)
2638 NameCancelButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, NameCancelPress)
2639 NameCancelButton.SetText (13727)
2640 NameCancelButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
2642 NameField = NameWindow.GetControl (2)
2643 NameField.SetEvent (IE_GUI_EDIT_ON_CHANGE, NameEditChange)
2644 NameField.SetText (GemRB.GetToken ("CHARNAME") )
2645 NameField.SetStatus (IE_GUI_CONTROL_FOCUSED)
2647 NameWindow.SetVisible (WINDOW_VISIBLE)
2648 NameEditChange()
2649 return
2651 def NameEditChange():
2652 global NameField
2654 if NameField.QueryText () == "":
2655 NameDoneButton.SetState (IE_GUI_BUTTON_DISABLED)
2656 else:
2657 NameDoneButton.SetState (IE_GUI_BUTTON_ENABLED)
2658 return
2660 def NameDonePress():
2661 global CharGenWindow, CharGenState, NameWindow, NameField, AcceptButton
2663 GemRB.SetToken ("CHARNAME", NameField.QueryText () )
2664 if NameWindow:
2665 NameWindow.Unload ()
2666 CharGenState = 8
2667 AcceptButton.SetState (IE_GUI_BUTTON_ENABLED)
2668 AcceptButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
2669 SetCharacterDescription()
2670 CharGenWindow.SetVisible (WINDOW_VISIBLE)
2671 return
2673 def NameCancelPress():
2674 global CharGenWindow, NameWindow
2676 GemRB.SetToken ("CHARNAME", "")
2677 if NameWindow:
2678 NameWindow.Unload ()
2679 CharGenWindow.SetVisible (WINDOW_VISIBLE)
2680 return
2682 # Import Character
2684 def ImportPress():
2685 global CharGenWindow, ImportWindow
2686 global CharImportList
2688 CharGenWindow.SetVisible (WINDOW_INVISIBLE)
2689 ImportWindow = GemRB.LoadWindow (20)
2691 TextAreaControl = ImportWindow.GetControl(4)
2692 TextAreaControl.SetText(10963)
2694 GemRB.SetVar ("Selected", 0)
2695 CharImportList = ImportWindow.GetControl(2)
2696 CharImportList.SetFlags (IE_GUI_TEXTAREA_SELECTABLE)
2697 CharImportList.SetVarAssoc ("Selected",0)
2698 CharImportList.GetCharacters()
2700 ImportDoneButton = ImportWindow.GetControl (0)
2701 ImportDoneButton.SetState (IE_GUI_BUTTON_ENABLED)
2702 ImportDoneButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, ImportDonePress)
2703 ImportDoneButton.SetText (11973)
2704 ImportDoneButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
2706 ImportCancelButton = ImportWindow.GetControl (1)
2707 ImportCancelButton.SetState (IE_GUI_BUTTON_ENABLED)
2708 ImportCancelButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, ImportCancelPress)
2709 ImportCancelButton.SetText (13727)
2710 ImportCancelButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
2712 ImportWindow.SetVisible (WINDOW_VISIBLE)
2713 return
2715 def ImportDonePress():
2716 global CharGenWindow, ImportWindow, CharImportList
2717 global CharGenState, SkillsState, Portrait
2719 # Import the character from the chosen name
2720 GemRB.CreatePlayer (CharImportList.QueryText(), MyChar|0x8000, 1)
2722 GemRB.SetToken ("CHARNAME", GemRB.GetPlayerName (MyChar) )
2723 GemRB.SetToken ("SmallPortrait", GemRB.GetPlayerPortrait (MyChar, 1) )
2724 PortraitName = GemRB.GetPlayerPortrait (MyChar, 0)
2725 GemRB.SetToken ("LargePortrait", PortraitName )
2726 PortraitButton.SetPicture (PortraitName)
2727 Portrait = -1
2729 CharGenState = 7
2730 SkillsState = 5
2731 SetCharacterDescription ()
2732 GenderButton.SetState (IE_GUI_BUTTON_DISABLED)
2733 GenderButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_NAND)
2734 RaceButton.SetState (IE_GUI_BUTTON_DISABLED)
2735 RaceButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_NAND)
2736 ClassButton.SetState (IE_GUI_BUTTON_DISABLED)
2737 ClassButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_NAND)
2738 AlignmentButton.SetState (IE_GUI_BUTTON_DISABLED)
2739 AlignmentButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_NAND)
2740 AbilitiesButton.SetState (IE_GUI_BUTTON_DISABLED)
2741 AbilitiesButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_NAND)
2742 SkillsButton.SetState (IE_GUI_BUTTON_DISABLED)
2743 SkillsButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_NAND)
2744 AppearanceButton.SetState (IE_GUI_BUTTON_ENABLED)
2745 AppearanceButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
2746 BiographyButton.SetState (IE_GUI_BUTTON_ENABLED)
2747 BiographyButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
2748 NameButton.SetState (IE_GUI_BUTTON_ENABLED)
2749 NameButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
2750 CharGenWindow.SetVisible (WINDOW_VISIBLE)
2751 if ImportWindow:
2752 ImportWindow.Unload ()
2753 return
2755 def ImportCancelPress():
2756 global CharGenWindow, ImportWindow
2758 if ImportWindow:
2759 ImportWindow.Unload ()
2760 CharGenWindow.SetVisible (WINDOW_VISIBLE)
2761 return