GUIScript: Rename SetTimedEvent to SetTimedEventByName.
[gemrb.git] / gemrb / GUIScripts / bg2 / GUIREC.py
blob173074d56181412d904f8b7b918a115e534f675a
1 # -*-python-*-
2 # GemRB - Infinity Engine Emulator
3 # Copyright (C) 2003-2009 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 # GUIREC.py - scripts to control stats/records windows from the GUIREC winpack
23 ###################################################
24 import GemRB
25 import GUICommonWindows
26 from GUIDefines import *
27 from ie_stats import *
28 from ie_restype import *
29 from GUICommon import *
30 from LUCommon import CanLevelUp, GetNextLevelExp
31 from GUICommonWindows import *
32 from GUIWORLD import OpenReformPartyWindow
34 ###################################################
35 RecordsWindow = None
36 InformationWindow = None
37 BiographyWindow = None
38 PortraitWindow = None
39 OptionsWindow = None
40 CustomizeWindow = None
41 SubCustomizeWindow = None
42 SubSubCustomizeWindow = None
43 OldPortraitWindow = None
44 OldOptionsWindow = None
45 ExportWindow = None
46 KitInfoWindow = None
47 ExportDoneButton = None
48 ExportFileName = ""
49 PortraitsTable = None
50 ScriptsTable = None
51 ColorTable = None
52 ColorIndex = None
53 ScriptTextArea = None
55 # the available sounds
56 SoundSequence = [ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', \
57 'm', 's', 't', 'u', 'v', '_', 'x', 'y', 'z', '0', '1', '2', \
58 '3', '4', '5', '6', '7', '8', '9']
59 SoundIndex = 0
61 ###################################################
62 def OpenRecordsWindow ():
63 global RecordsWindow, OptionsWindow, PortraitWindow
64 global OldPortraitWindow, OldOptionsWindow
66 if CloseOtherWindow (OpenRecordsWindow):
67 if InformationWindow: OpenInformationWindow ()
69 if RecordsWindow:
70 RecordsWindow.Unload ()
71 if OptionsWindow:
72 OptionsWindow.Unload ()
73 if PortraitWindow:
74 PortraitWindow.Unload ()
76 RecordsWindow = None
77 GemRB.SetVar ("OtherWindow", -1)
78 GameWindow.SetVisible(WINDOW_VISIBLE)
79 GemRB.UnhideGUI ()
80 GUICommonWindows.PortraitWindow = OldPortraitWindow
81 OldPortraitWindow = None
82 GUICommonWindows.OptionsWindow = OldOptionsWindow
83 OldOptionsWindow = None
84 SetSelectionChangeHandler (None)
85 return
87 GemRB.HideGUI ()
88 GameWindow.SetVisible(WINDOW_INVISIBLE)
90 GemRB.LoadWindowPack ("GUIREC", 640, 480)
91 RecordsWindow = Window = GemRB.LoadWindow (2)
92 GemRB.SetVar ("OtherWindow", RecordsWindow.ID)
93 #saving the original portrait window
94 OldOptionsWindow = GUICommonWindows.OptionsWindow
95 OptionsWindow = GemRB.LoadWindow (0)
96 MarkMenuButton (OptionsWindow)
97 SetupMenuWindowControls (OptionsWindow, 0, "OpenRecordsWindow")
98 OptionsWindow.SetFrame ()
99 OldPortraitWindow = GUICommonWindows.PortraitWindow
100 PortraitWindow = OpenPortraitWindow (0)
102 # dual class
103 Button = Window.GetControl (0)
104 Button.SetText (7174)
105 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "DualClassWindow")
107 # levelup
108 Button = Window.GetControl (37)
109 Button.SetText (7175)
110 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "OpenLevelUpWindow")
112 # information
113 Button = Window.GetControl (1)
114 Button.SetText (11946)
115 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "OpenInformationWindow")
117 # reform party
118 Button = Window.GetControl (51)
119 Button.SetText (16559)
120 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "OpenRecReformPartyWindow")
122 # customize
123 Button = Window.GetControl (50)
124 Button.SetText (10645)
125 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "OpenCustomizeWindow")
127 # export
128 Button = Window.GetControl (36)
129 Button.SetText (13956)
130 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "OpenExportWindow")
132 # kit info
133 Button = Window.GetControl (52)
134 Button.SetText (61265)
135 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "KitInfoWindow")
137 SetSelectionChangeHandler (UpdateRecordsWindow)
138 UpdateRecordsWindow ()
139 OptionsWindow.SetVisible (WINDOW_VISIBLE)
140 Window.SetVisible (WINDOW_FRONT)
141 PortraitWindow.SetVisible (WINDOW_VISIBLE)
142 return
144 #original returns to game before continuing...
145 def OpenRecReformPartyWindow ():
146 OpenRecordsWindow ()
147 GemRB.SetTimedEventByName ("OpenReformPartyWindow", 1)
148 return
150 def UpdateRecordsWindow ():
151 global stats_overview, alignment_help
153 Window = RecordsWindow
154 if not RecordsWindow:
155 print "SelectionChange handler points to non existing window\n"
156 return
158 pc = GemRB.GameGetSelectedPCSingle ()
160 #update mage school
161 GemRB.SetVar ("MAGESCHOOL", 0)
162 Kit = GetKitIndex (pc)
163 if Kit and KitListTable.GetValue (Kit, 7) == 1:
164 MageTable = GemRB.LoadTable ("magesch")
165 GemRB.SetVar ("MAGESCHOOL", MageTable.FindValue (3, KitListTable.GetValue (Kit, 6) ) )
167 # exportable
168 Button = Window.GetControl (36)
169 if GemRB.GetPlayerStat (pc, IE_MC_FLAGS)&MC_EXPORTABLE:
170 Button.SetState (IE_GUI_BUTTON_ENABLED)
171 else:
172 Button.SetState (IE_GUI_BUTTON_DISABLED)
174 # dual-classable
175 Button = Window.GetControl (0)
176 if CanDualClass (pc):
177 Button.SetState (IE_GUI_BUTTON_DISABLED)
178 else:
179 Button.SetState (IE_GUI_BUTTON_ENABLED)
181 # levelup
182 Button = Window.GetControl (37)
183 if CanLevelUp (pc):
184 Button.SetState (IE_GUI_BUTTON_ENABLED)
185 else:
186 Button.SetState (IE_GUI_BUTTON_DISABLED)
188 # name
189 Label = Window.GetControl (0x1000000e)
190 Label.SetText (GemRB.GetPlayerName (pc, 0))
192 # portrait
193 Button = Window.GetControl (2)
194 Button.SetFlags (IE_GUI_BUTTON_NO_IMAGE | IE_GUI_BUTTON_PICTURE, OP_SET)
195 Button.SetState (IE_GUI_BUTTON_LOCKED)
196 Button.SetPicture (GemRB.GetPlayerPortrait (pc,0), "NOPORTMD")
198 # armorclass
199 Label = Window.GetControl (0x10000028)
200 ac = GemRB.GetPlayerStat (pc, IE_ARMORCLASS)
201 #This is a temporary solution, the core engine should set the stat correctly!
202 ac += GemRB.GetAbilityBonus (IE_DEX, 2, GemRB.GetPlayerStat (pc, IE_DEX) )
203 Label.SetText (str (ac))
204 Label.SetTooltip (17183)
206 # hp now
207 Label = Window.GetControl (0x10000029)
208 Label.SetText (str (GemRB.GetPlayerStat (pc, IE_HITPOINTS)))
209 Label.SetTooltip (17184)
211 # hp max
212 Label = Window.GetControl (0x1000002a)
213 Label.SetText (str (GemRB.GetPlayerStat (pc, IE_MAXHITPOINTS)))
214 Label.SetTooltip (17378)
216 # stats
218 sstr = GemRB.GetPlayerStat (pc, IE_STR)
219 cstr = GetStatColor (pc, IE_STR)
220 sstrx = GemRB.GetPlayerStat (pc, IE_STREXTRA)
222 if sstrx > 0 and sstr==18:
223 sstr = "%d/%02d" %(sstr, sstrx % 100)
224 else:
225 sstr = str (sstr)
226 sint = str (GemRB.GetPlayerStat (pc, IE_INT))
227 cint = GetStatColor (pc, IE_INT)
228 swis = str (GemRB.GetPlayerStat (pc, IE_WIS))
229 cwis = GetStatColor (pc, IE_WIS)
230 sdex = str (GemRB.GetPlayerStat (pc, IE_DEX))
231 cdex = GetStatColor (pc, IE_DEX)
232 scon = str (GemRB.GetPlayerStat (pc, IE_CON))
233 ccon = GetStatColor (pc, IE_CON)
234 schr = str (GemRB.GetPlayerStat (pc, IE_CHR))
235 cchr = GetStatColor (pc, IE_CHR)
237 Label = Window.GetControl (0x1000002f)
238 Label.SetText (sstr)
239 Label.SetTextColor (cstr[0], cstr[1], cstr[2])
241 Label = Window.GetControl (0x10000009)
242 Label.SetText (sdex)
243 Label.SetTextColor (cdex[0], cdex[1], cdex[2])
245 Label = Window.GetControl (0x1000000a)
246 Label.SetText (scon)
247 Label.SetTextColor (ccon[0], ccon[1], ccon[2])
249 Label = Window.GetControl (0x1000000b)
250 Label.SetText (sint)
251 Label.SetTextColor (cint[0], cint[1], cint[2])
253 Label = Window.GetControl (0x1000000c)
254 Label.SetText (swis)
255 Label.SetTextColor (cwis[0], cwis[1], cwis[2])
257 Label = Window.GetControl (0x1000000d)
258 Label.SetText (schr)
259 Label.SetTextColor (cchr[0], cchr[1], cchr[2])
261 # class
262 ClassTitle = GetActorClassTitle (pc)
263 Label = Window.GetControl (0x10000030)
264 Label.SetText (ClassTitle)
266 # race
267 text = RaceTable.GetValue (RaceTable.FindValue (3, GemRB.GetPlayerStat (pc, IE_RACE)) , 0)
269 Label = Window.GetControl (0x1000000f)
270 Label.SetText (text)
272 Table = GemRB.LoadTable ("aligns")
274 text = Table.GetValue (Table.FindValue ( 3, GemRB.GetPlayerStat (pc, IE_ALIGNMENT) ), 0)
275 Label = Window.GetControl (0x10000010)
276 Label.SetText (text)
278 Label = Window.GetControl (0x10000011)
279 if GemRB.GetPlayerStat (pc, IE_SEX) == 1:
280 Label.SetText (7198)
281 else:
282 Label.SetText (7199)
284 # help, info textarea
285 stats_overview = GetStatOverview (pc)
286 Text = Window.GetControl (45)
287 Text.SetText (stats_overview)
288 #making window visible/shaded depending on the pc's state
289 Window.SetVisible (WINDOW_VISIBLE)
290 return
292 def GetStatColor (pc, stat):
293 a = GemRB.GetPlayerStat (pc, stat)
294 b = GemRB.GetPlayerStat (pc, stat, 1)
295 if a==b:
296 return (255,255,255)
297 if a<b:
298 return (255,255,0)
299 return (0,255,0)
301 # GemRB.GetPlayerStat wrapper that only returns nonnegative values
302 def GSNN (pc, stat):
303 val = GemRB.GetPlayerStat (pc, stat)
304 if val >= 0:
305 return val
306 else:
307 return 0
309 # LevelDiff is used only from the level up code and holds the level
310 # difference for each class
311 def GetStatOverview (pc, LevelDiff=[0,0,0]):
312 StateTable = GemRB.LoadTable ("statdesc")
313 str_None = GemRB.GetString (61560)
315 GS = lambda s, pc=pc: GemRB.GetPlayerStat (pc, s)
316 GA = lambda s, col, pc=pc: GemRB.GetAbilityBonus (s, col, GS (s) )
318 stats = []
319 # class levels
320 # 16480 <CLASS>: Level <LEVEL>
321 # Experience: <EXPERIENCE>
322 # Next Level: <NEXTLEVEL>
324 # collecting tokens for stat overview
325 ClassTitle = GetActorClassTitle (pc)
326 GemRB.SetToken ("CLASS", ClassTitle)
327 Class = GemRB.GetPlayerStat (pc, IE_CLASS)
328 Class = ClassTable.FindValue (5, Class)
329 Class = ClassTable.GetRowName (Class)
330 Dual = IsDualClassed (pc, 1)
331 Multi = IsMultiClassed (pc, 1)
332 XP = GemRB.GetPlayerStat (pc, IE_XP)
333 LevelDrain = GS (IE_LEVELDRAIN)
335 if Multi[0] > 1: # we're multiclassed
336 print "\tMulticlassed"
337 Levels = [GemRB.GetPlayerStat (pc, IE_LEVEL), GemRB.GetPlayerStat (pc, IE_LEVEL2), GemRB.GetPlayerStat (pc, IE_LEVEL3)]
339 stats.append ( (19721,1,'c') )
340 stats.append (None)
341 for i in range (Multi[0]):
342 ClassIndex = ClassTable.FindValue (5, Multi[i+1])
343 ClassTitle = GemRB.GetString (ClassTable.GetValue (ClassIndex, 2))
344 GemRB.SetToken ("CLASS", ClassTitle)
345 Class = ClassTable.GetRowName (ClassIndex)
346 GemRB.SetToken ("LEVEL", str (Levels[i]+LevelDiff[i]-int(LevelDrain/Multi[0])) )
347 GemRB.SetToken ("EXPERIENCE", str (XP/Multi[0]) )
348 if LevelDrain:
349 stats.append ( (GemRB.GetString (19720),1,'d') )
350 stats.append ( (GemRB.GetString (57435),1,'d') ) # LEVEL DRAINED
351 else:
352 GemRB.SetToken ("NEXTLEVEL", GetNextLevelExp (Levels[i]+LevelDiff[i], Class) )
353 stats.append ( (GemRB.GetString (16480),"",'d') )
354 stats.append (None)
355 print "\t\tClass (Level):",Class,"(",Levels[i],")"
357 elif Dual[0] > 0: # dual classed; first show the new class
358 print "\tDual classed"
359 stats.append ( (19722,1,'c') )
360 stats.append (None)
362 Levels = [GemRB.GetPlayerStat (pc, IE_LEVEL), GemRB.GetPlayerStat (pc, IE_LEVEL2), GemRB.GetPlayerStat (pc, IE_LEVEL3)]
364 # the levels are stored in the class order (eg. FIGHTER_MAGE)
365 # the current active class does not matter!
366 if IsDualSwap (pc):
367 Levels = [Levels[1], Levels[0], Levels[2]]
369 Levels[0] += LevelDiff[0]
371 ClassTitle = GemRB.GetString (ClassTable.GetValue (Dual[2], 2))
372 GemRB.SetToken ("CLASS", ClassTitle)
373 GemRB.SetToken ("LEVEL", str (Levels[0]-LevelDrain))
374 Class = ClassTable.GetRowName (Dual[2])
375 XP2 = GemRB.GetPlayerStat (pc, IE_XP)
376 GemRB.SetToken ("EXPERIENCE", str (XP2) )
377 if LevelDrain:
378 stats.append ( (GemRB.GetString (19720),1,'d') )
379 stats.append ( (GemRB.GetString (57435),1,'d') ) # LEVEL DRAINED
380 else:
381 GemRB.SetToken ("NEXTLEVEL", GetNextLevelExp (Levels[0], Class) )
382 stats.append ( (GemRB.GetString (16480),"",'d') )
383 stats.append (None)
385 # the first class (shown second)
386 if Dual[0] == 1:
387 ClassTitle = GemRB.GetString (KitListTable.GetValue (Dual[1], 2))
388 elif Dual[0] == 2:
389 ClassTitle = GemRB.GetString (ClassTable.GetValue (Dual[1], 2))
390 GemRB.SetToken ("CLASS", ClassTitle)
391 GemRB.SetToken ("LEVEL", str (Levels[1]) )
393 # the xp table contains only classes, so we have to determine the base class for kits
394 if Dual[0] == 2:
395 BaseClass = ClassTable.GetRowName (Dual[1])
396 else:
397 BaseClass = GetKitIndex (pc)
398 BaseClass = KitListTable.GetValue (BaseClass, 7)
399 BaseClass = ClassTable.FindValue (5, BaseClass)
400 BaseClass = ClassTable.GetRowName (BaseClass)
401 # the first class' XP is discarded and set to the minimum level
402 # requirement, so if you don't dual class right after a levelup,
403 # the game would eat some of your XP
404 XP1 = NextLevelTable.GetValue (BaseClass, str (Levels[1]))
405 GemRB.SetToken ("EXPERIENCE", str (XP1) )
407 # inactive until the new class SURPASSES the former
408 if Levels[0] <= Levels[1]:
409 # inactive
410 stats.append ( (19719,1,'c') )
411 else:
412 stats.append ( (19720,1,'c') )
413 stats.append (None)
414 else: # single classed
415 print "\tSingle classed"
416 Level = GemRB.GetPlayerStat (pc, IE_LEVEL) + LevelDiff[0]
417 GemRB.SetToken ("LEVEL", str (Level-LevelDrain))
418 GemRB.SetToken ("EXPERIENCE", str (XP) )
419 if LevelDrain:
420 stats.append ( (19720,1,'c') )
421 stats.append ( (57435,1,'c') ) # LEVEL DRAINED
422 else:
423 GemRB.SetToken ("NEXTLEVEL", GetNextLevelExp (Level, Class) )
424 stats.append ( (16480,1,'c') )
425 stats.append (None)
426 print "\t\tClass (Level):",Class,"(",Level,")"
428 # check to see if we have a level diff anywhere
429 if sum (LevelDiff) == 0:
430 effects = GemRB.GetPlayerStates (pc)
431 if len (effects):
432 for c in effects:
433 tmp = StateTable.GetValue (ord(c)-66, 0)
434 stats.append ( (tmp,c,'a') )
435 stats.append (None)
437 #proficiencies
438 stats.append ( (8442,1,'c') )
440 stats.append ( (61932, GS (IE_TOHIT), '0') )
441 if (GemRB.IsDualWielding(pc)):
442 stats.append ( (56911, GemRB.GetCombatDetails(pc, 0)["ToHit"], '0') )
443 stats.append ( (56910, GemRB.GetCombatDetails(pc, 1)["ToHit"], '0') )
444 else:
445 stats.append ( (9457, GemRB.GetCombatDetails(pc, 0)["ToHit"], '0') )
446 tmp = GS (IE_NUMBEROFATTACKS)
447 if (tmp&1):
448 tmp2 = str (tmp/2) + chr (188)
449 else:
450 tmp2 = str (tmp/2)
451 stats.append ( (9458, tmp2, '') )
452 stats.append ( (9459, GSNN (pc, IE_LORE), '0') )
454 #reputation
455 reptxt = GetReputation (GemRB.GameGetReputation ()/10)
456 stats.append ( (9465, reptxt, '') )
457 stats.append ( (9460, GSNN (pc, IE_LOCKPICKING), '') )
458 stats.append ( (9462, GSNN (pc, IE_TRAPS), '') )
459 stats.append ( (9463, GSNN (pc, IE_PICKPOCKET), '') )
460 stats.append ( (9461, GSNN (pc, IE_STEALTH), '') )
461 HatedRace = GS (IE_HATEDRACE)
462 if HatedRace:
463 HateTable = GemRB.LoadTable ("haterace")
464 Racist = HateTable.FindValue (1, HatedRace)
465 if Racist != -1:
466 HatedRace = HateTable.GetValue (Racist, 0)
467 stats.append ( (15982, GemRB.GetString (HatedRace), '') )
469 stats.append ( (34120, GSNN (pc, IE_HIDEINSHADOWS), '') )
470 stats.append ( (34121, GSNN (pc, IE_DETECTILLUSIONS), '') )
471 stats.append ( (34122, GSNN (pc, IE_SETTRAPS), '') )
472 stats.append ( (12128, GS (IE_BACKSTABDAMAGEMULTIPLIER), 'x') )
473 stats.append ( (12126, GS (IE_TURNUNDEADLEVEL), '') )
475 #this hack only displays LOH if we know the spell
476 #TODO: the core should just not set LOH if the paladin can't learn it
477 if (HasSpell (pc, IE_SPELL_TYPE_INNATE, 0, "SPCL211") >= 0):
478 stats.append ( (12127, GS (IE_LAYONHANDSAMOUNT), '') )
479 #script
480 aiscript = GemRB.GetPlayerScript (pc )
481 stats.append ( (2078, aiscript, '') )
482 stats.append (None)
484 # 17379 Saving throws
485 stats.append (17379)
486 # 17380 Paralyze/Poison/Death
487 stats.append ( (17380, GS (IE_SAVEVSDEATH), '0') )
488 # 17381 Rod/Staff/Wand
489 stats.append ( (17381, GS (IE_SAVEVSWANDS), '0') )
490 # 17382 Petrify/Polymorph
491 stats.append ( (17382, GS (IE_SAVEVSPOLY), '0') )
492 # 17383 Breath weapon
493 stats.append ( (17383, GS (IE_SAVEVSBREATH), '0') )
494 # 17384 Spells
495 stats.append ( (17384, GS (IE_SAVEVSSPELL), '0') )
496 stats.append (None)
498 # 9466 Weapon proficiencies
499 stats.append (9466)
500 table = GemRB.LoadTable ("weapprof")
501 RowCount = table.GetRowCount ()
502 # the first 7 profs are foobared
503 for i in range (8,RowCount):
504 text = table.GetValue (i, 1)
505 stat = table.GetValue (i, 0)
506 stats.append ( (text, GS (stat)&0x07, '+') )
507 stats.append (None)
509 # 11766 AC bonuses
510 stats.append (11766)
511 # 11770 AC vs. Crushing
512 stats.append ((11770, GS (IE_ACCRUSHINGMOD), ''))
513 # 11767 AC vs. Missile
514 stats.append ((11767, GS (IE_ACMISSILEMOD), ''))
515 # 11769 AC vs. Piercing
516 stats.append ((11769, GS (IE_ACPIERCINGMOD), ''))
517 # 11768 AC vs. Slashing
518 stats.append ((11768, GS (IE_ACSLASHINGMOD), ''))
519 stats.append (None)
521 # 10315 Ability bonuses
522 stats.append (10315)
523 value = GemRB.GetPlayerStat (pc, IE_STR)
524 ex = GemRB.GetPlayerStat (pc, IE_STREXTRA)
525 # 10332 to hit
526 stats.append ( (10332, GemRB.GetAbilityBonus (IE_STR,0,value,ex), '0') )
527 # 10336 damage
528 stats.append ( (10336, GemRB.GetAbilityBonus (IE_STR,1,value,ex), '0') )
529 # 10337 open doors (bend bars lift gates)
530 stats.append ( (10337, GemRB.GetAbilityBonus (IE_STR,2,value,ex), '0') )
531 # 10338 weight allowance
532 stats.append ( (10338, GemRB.GetAbilityBonus (IE_STR,3,value,ex), '0') )
533 # 10339 AC
534 stats.append ( (10339, GA (IE_DEX,2), '0') )
535 # 10340 Missile adjustment
536 stats.append ( (10340, GA (IE_DEX,1), '0') )
537 # 10341 Reaction adjustment
538 stats.append ( (10341, GA (IE_DEX,0), '0') )
539 # 10342 CON HP Bonus/Level
540 stats.append ( (10342, GA (IE_CON,0), '0') )
541 # 10343 Chance To Learn spell
542 if GemRB.GetMemorizableSpellsCount (pc, IE_SPELL_TYPE_WIZARD, 0, 0)>0:
543 stats.append ( (10343, GA (IE_INT,0), '%' ) )
544 # 10347 Reaction
545 stats.append ( (10347, GA (IE_REPUTATION,0), '0') )
546 stats.append (None)
548 #Bonus spells
549 if GemRB.GetMemorizableSpellsCount (pc, IE_SPELL_TYPE_PRIEST, 0, 0)>0:
550 stats.append (10344)
551 for level in range (7):
552 GemRB.SetToken ("SPELLLEVEL", str (level+1) )
553 #get the bonus spell count
554 base = GemRB.GetMemorizableSpellsCount (pc, IE_SPELL_TYPE_PRIEST, level, 0)
555 if base:
556 count = GemRB.GetMemorizableSpellsCount (pc, IE_SPELL_TYPE_PRIEST, level)
557 stats.append ( (GemRB.GetString (10345), count-base, 'b') )
558 stats.append (None)
560 # 32204 Resistances
561 stats.append (32204)
562 # 32213 Normal Fire
563 stats.append ((32213, GS (IE_RESISTFIRE), '%'))
564 # 32222 Magic Fire
565 stats.append ((32222, GS (IE_RESISTMAGICFIRE), '%'))
566 # 32214 Normal Cold
567 stats.append ((32214, GS (IE_RESISTCOLD), '%'))
568 # 32223 Magic Cold
569 stats.append ((32223, GS (IE_RESISTMAGICCOLD), '%'))
570 # 32220 Electricity
571 stats.append ((32220, GS (IE_RESISTELECTRICITY), '%'))
572 # 32221 Acid
573 stats.append ((32221, GS (IE_RESISTACID), '%'))
574 # Magic
575 stats.append ((62146, GS (IE_RESISTMAGIC), '%'))
576 # Magic Damage
577 stats.append ((32233, GS (IE_MAGICDAMAGERESISTANCE), '%'))
578 # Missile
579 stats.append ((11767, GS (IE_RESISTMISSILE), '%'))
580 # Slashing
581 stats.append ((11768, GS (IE_RESISTSLASHING), '%'))
582 # Piercing
583 stats.append ((11769, GS (IE_RESISTPIERCING), '%'))
584 # Crushing
585 stats.append ((11770, GS (IE_RESISTCRUSHING), '%'))
586 # Poison
587 stats.append ((14017, GS (IE_RESISTPOISON), '%'))
588 stats.append (None)
590 #Weapon Style bonuses
591 stats.append (32131)
592 wstyle = GemRB.GetCombatDetails (pc, 0)["Style"] # equipped weapon style + 1000 * proficiency level
593 profcount = wstyle / 1000
594 if profcount:
595 wstyletables = { IE_PROFICIENCY2WEAPON:"wstwowpn", IE_PROFICIENCY2HANDED:"wstwohnd", IE_PROFICIENCYSINGLEWEAPON:"wssingle", IE_PROFICIENCYSWORDANDSHIELD:"wsshield" }
596 bonusrefs = { "THAC0BONUSRIGHT":56911, "THAC0BONUSLEFT":56910, "DAMAGEBONUS":10336, "CRITICALHITBONUS":32140, "PHYSICALSPEED":32141, "AC":10339, "ACVSMISSLE":10340 }
597 WStyleTable = GemRB.LoadTable (wstyletables[wstyle%1000])
598 for col in range(WStyleTable.GetColumnCount()):
599 value = WStyleTable.GetValue (profcount, col)
600 stats.append ((bonusrefs[WStyleTable.GetColumnName(col)], value, ''))
601 stats.append (None)
603 res = []
604 lines = 0
605 for s in stats:
606 try:
607 strref, val, type = s
608 if val == 0 and type != '0':
609 continue
610 if type == '+': #pluses
611 res.append ("[capital=0]"+GemRB.GetString (strref) + ' '+ '+' * val)
612 elif type == 'x': #x character before value
613 res.append ("[capital=0]"+GemRB.GetString (strref)+': x' + str (val) )
614 elif type == 'a': #value (portrait icon) + string
615 res.append ("[capital=2]"+val+" "+GemRB.GetString (strref) )
616 elif type == 'b': #strref is an already resolved string
617 res.append ("[capital=0]"+strref+": "+str (val) )
618 elif type == 'c': #normal string
619 res.append ("[capital=0]"+GemRB.GetString (strref) )
620 elif type == 'd': #strref is an already resolved string
621 res.append ("[capital=0]"+strref)
622 elif type == '0': #normal value
623 res.append (GemRB.GetString (strref) + ': ' + str (val) )
624 else: #normal value + type character, for example percent sign
625 res.append (GemRB.GetString (strref) + ': ' + str (val) + type)
626 lines = 1
627 except:
628 if s != None:
629 res.append ("[capital=0]"+ GemRB.GetString (s) )
630 lines = 0
631 else:
632 if not lines:
633 res.append (str_None)
634 res.append ("")
635 lines = 0
637 return "\n".join (res)
640 def GetReputation (repvalue):
641 table = GemRB.LoadTable ("reptxt")
642 if repvalue>20:
643 repvalue=20
644 txt = GemRB.GetString (table.GetValue (repvalue, 0) )
645 return txt+" ("+str (repvalue)+")"
648 def OpenInformationWindow ():
649 global InformationWindow
651 if InformationWindow != None:
652 if BiographyWindow:
653 OpenBiographyWindow ()
655 if InformationWindow:
656 InformationWindow.Unload ()
657 OptionsWindow.SetVisible (WINDOW_FRONT)
658 RecordsWindow.SetVisible (WINDOW_FRONT)
659 PortraitWindow.SetVisible (WINDOW_FRONT)
660 InformationWindow = None
662 return
664 InformationWindow = Window = GemRB.LoadWindow (4)
666 # Biography
667 Button = Window.GetControl (26)
668 Button.SetText (18003)
669 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "OpenBiographyWindow")
671 # Done
672 Button = Window.GetControl (24)
673 Button.SetText (11973)
674 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "OpenInformationWindow")
676 TotalPartyExp = 0
677 ChapterPartyExp = 0
678 TotalCount = 0
679 ChapterCount = 0
680 for i in range (1, GemRB.GetPartySize () + 1):
681 stat = GemRB.GetPCStats(i)
682 TotalPartyExp = TotalPartyExp + stat['KillsTotalXP']
683 ChapterPartyExp = ChapterPartyExp + stat['KillsChapterXP']
684 TotalCount = TotalCount + stat['KillsTotalCount']
685 ChapterCount = ChapterCount + stat['KillsChapterCount']
687 # These are used to get the stats
688 pc = GemRB.GameGetSelectedPCSingle ()
689 stat = GemRB.GetPCStats (pc)
691 Label = Window.GetControl (0x10000000)
692 Label.SetText (GemRB.GetPlayerName (pc, 1))
693 # class
694 ClassTitle = GetActorClassTitle (pc)
695 Label = Window.GetControl (0x10000018)
696 Label.SetText (ClassTitle)
698 #most powerful vanquished
699 Label = Window.GetControl (0x10000005)
700 #we need getstring, so -1 will translate to empty string
701 Label.SetText (GemRB.GetString (stat['BestKilledName']))
703 # NOTE: currentTime is in seconds, joinTime is in seconds * 15
704 # (script updates???). In each case, there are 60 seconds
705 # in a minute, 24 hours in a day, but ONLY 5 minutes in an hour!!
706 # Hence currentTime (and joinTime after div by 15) has
707 # 7200 secs a day (60 * 5 * 24)
708 currentTime = GemRB.GetGameTime ()
709 joinTime = stat['JoinDate'] - stat['AwayTime']
711 party_time = currentTime - (joinTime / 15)
712 print "CurrentTime",currentTime
713 days = party_time / 7200
714 hours = (party_time % 7200) / 300
716 GemRB.SetToken ('GAMEDAY', str (days))
717 GemRB.SetToken ('HOUR', str (hours))
718 Label = Window.GetControl (0x10000006)
719 #actually it is 16043 <DURATION>, but duration is translated to
720 #16041, hopefully this won't cause problem with international version
721 Label.SetText (16041)
723 #favourite spell
724 Label = Window.GetControl (0x10000007)
725 Label.SetText (stat['FavouriteSpell'])
727 #favourite weapon
728 Label = Window.GetControl (0x10000008)
729 #actually it is 10479 <WEAPONNAME>, but weaponname is translated to
730 #the real weapon name (which we should set using SetToken)
731 #there are other strings like bow+wname/xbow+wname/sling+wname
732 #are they used?
733 Label.SetText (stat['FavouriteWeapon'])
735 #total xp
736 Label = Window.GetControl (0x1000000f)
737 if TotalPartyExp != 0:
738 PartyExp = int ((stat['KillsTotalXP'] * 100) / TotalPartyExp)
739 Label.SetText (str (PartyExp) + '%')
740 else:
741 Label.SetText ("0%")
743 Label = Window.GetControl (0x10000013)
744 if ChapterPartyExp != 0:
745 PartyExp = int ((stat['KillsChapterXP'] * 100) / ChapterPartyExp)
746 Label.SetText (str (PartyExp) + '%')
747 else:
748 Label.SetText ("0%")
750 #total xp
751 Label = Window.GetControl (0x10000010)
752 if TotalCount != 0:
753 PartyExp = int ((stat['KillsTotalCount'] * 100) / TotalCount)
754 Label.SetText (str (PartyExp) + '%')
755 else:
756 Label.SetText ("0%")
758 Label = Window.GetControl (0x10000014)
759 if ChapterCount != 0:
760 PartyExp = int ((stat['KillsChapterCount'] * 100) / ChapterCount)
761 Label.SetText (str (PartyExp) + '%')
762 else:
763 Label.SetText ("0%")
765 Label = Window.GetControl (0x10000011)
766 Label.SetText (str (stat['KillsChapterXP']))
767 Label = Window.GetControl (0x10000015)
768 Label.SetText (str (stat['KillsTotalXP']))
770 #count of kills in chapter/game
771 Label = Window.GetControl (0x10000012)
772 Label.SetText (str (stat['KillsChapterCount']))
773 Label = Window.GetControl (0x10000016)
774 Label.SetText (str (stat['KillsTotalCount']))
776 Window.ShowModal (MODAL_SHADOW_GRAY)
777 return
779 def OpenBiographyWindow ():
780 global BiographyWindow
782 if BiographyWindow != None:
783 if BiographyWindow:
784 BiographyWindow.Unload ()
785 BiographyWindow = None
786 InformationWindow.ShowModal (MODAL_SHADOW_GRAY)
787 return
789 BiographyWindow = Window = GemRB.LoadWindow (12)
791 TextArea = Window.GetControl (0)
792 pc = GemRB.GameGetSelectedPCSingle ()
793 TextArea.SetText (GemRB.GetPlayerString (pc, 74) )
795 # Done
796 Button = Window.GetControl (2)
797 Button.SetText (11973)
798 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "OpenBiographyWindow")
800 return
802 def OpenExportWindow ():
803 global ExportWindow, NameField, ExportDoneButton
805 ExportWindow = GemRB.LoadWindow (13)
807 TextArea = ExportWindow.GetControl (2)
808 TextArea.SetText (10962)
810 TextArea = ExportWindow.GetControl (0)
811 TextArea.GetCharacters ()
813 ExportDoneButton = ExportWindow.GetControl (4)
814 ExportDoneButton.SetText (11973)
815 ExportDoneButton.SetState (IE_GUI_BUTTON_DISABLED)
817 CancelButton = ExportWindow.GetControl (5)
818 CancelButton.SetText (13727)
819 CancelButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
821 NameField = ExportWindow.GetControl (6)
823 ExportDoneButton.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "ExportDonePress")
824 CancelButton.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "ExportCancelPress")
825 NameField.SetEventByName (IE_GUI_EDIT_ON_CHANGE, "ExportEditChanged")
826 ExportWindow.ShowModal (MODAL_SHADOW_GRAY)
827 NameField.SetStatus (IE_GUI_CONTROL_FOCUSED)
828 return
830 def ExportDonePress():
831 if ExportWindow:
832 ExportWindow.Unload()
833 #save file under name from EditControl
834 pc = GemRB.GameGetSelectedPCSingle ()
835 GemRB.SaveCharacter (pc, ExportFileName)
836 return
838 def ExportCancelPress():
839 if ExportWindow:
840 ExportWindow.Unload()
841 return
843 def ExportEditChanged():
844 global ExportFileName
846 ExportFileName = NameField.QueryText ()
847 if ExportFileName == "":
848 ExportDoneButton.SetState (IE_GUI_BUTTON_DISABLED)
849 else:
850 ExportDoneButton.SetState (IE_GUI_BUTTON_ENABLED)
851 return
853 def KitInfoWindow ():
854 global KitInfoWindow
856 KitInfoWindow = GemRB.LoadWindow (24)
858 #back button (setting first, to be less error prone)
859 DoneButton = KitInfoWindow.GetControl (2)
860 DoneButton.SetText (11973)
861 DoneButton.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "KitDonePress")
863 #kit or class description
864 TextArea = KitInfoWindow.GetControl (0)
866 pc = GemRB.GameGetSelectedPCSingle ()
867 Class = GemRB.GetPlayerStat (pc, IE_CLASS)
868 ClassIndex = ClassTable.FindValue (5, Class)
869 Multi = ClassTable.GetValue (ClassIndex, 4)
870 Dual = IsDualClassed (pc, 1)
872 if Multi and Dual[0] == 0: # true multi class
873 text = ClassTable.GetValue (ClassIndex, 1)
874 TextArea.SetText (text)
875 KitInfoWindow.ShowModal (MODAL_SHADOW_GRAY)
876 return
878 KitIndex = GetKitIndex (pc)
880 if Dual[0]: # dual class
881 # first (previous) kit or class of the dual class
882 if Dual[0] == 1:
883 text = KitListTable.GetValue (Dual[1], 3)
884 elif Dual[0] == 2:
885 text = ClassTable.GetValue (Dual[1], 1)
887 TextArea.SetText (text)
888 TextArea.Append ("\n\n")
889 text = ClassTable.GetValue (Dual[2], 1)
891 else: # ordinary class or kit
892 if KitIndex:
893 text = KitListTable.GetValue (KitIndex, 3)
894 else:
895 text = ClassTable.GetValue (ClassIndex, 1)
897 TextArea.Append (text)
899 KitInfoWindow.ShowModal (MODAL_SHADOW_GRAY)
900 return
902 def KitDonePress():
903 if KitInfoWindow:
904 KitInfoWindow.Unload()
905 return
907 def OpenCustomizeWindow ():
908 global CustomizeWindow
909 global PortraitsTable, ScriptsTable, ColorTable
911 pc = GemRB.GameGetSelectedPCSingle ()
912 if GemRB.GetPlayerStat (pc, IE_MC_FLAGS)&MC_EXPORTABLE:
913 Exportable = 1
914 else:
915 Exportable = 0
917 PortraitsTable = GemRB.LoadTable ("PICTURES")
918 ScriptsTable = GemRB.LoadTable ("SCRPDESC")
919 ColorTable = GemRB.LoadTable ("CLOWNCOL")
920 CustomizeWindow = GemRB.LoadWindow (17)
922 AppearanceButton = CustomizeWindow.GetControl (0)
923 AppearanceButton.SetText (11961)
924 if not Exportable:
925 AppearanceButton.SetState (IE_GUI_BUTTON_DISABLED)
927 SoundButton = CustomizeWindow.GetControl (1)
928 SoundButton.SetText (10647)
929 if not Exportable:
930 SoundButton.SetState (IE_GUI_BUTTON_DISABLED)
932 ColorButton = CustomizeWindow.GetControl (2)
933 ColorButton.SetText (10646)
934 if not Exportable:
935 ColorButton.SetState (IE_GUI_BUTTON_DISABLED)
937 ScriptButton = CustomizeWindow.GetControl (3)
938 ScriptButton.SetText (17111)
940 BiographyButton = CustomizeWindow.GetControl (9)
941 BiographyButton.SetText (18003)
942 if not Exportable:
943 BiographyButton.SetState (IE_GUI_BUTTON_DISABLED)
945 TextArea = CustomizeWindow.GetControl (5)
946 TextArea.SetText (11327)
948 DoneButton = CustomizeWindow.GetControl (7)
949 DoneButton.SetText (11973)
950 DoneButton.SetState (IE_GUI_BUTTON_ENABLED)
952 CancelButton = CustomizeWindow.GetControl (8);
953 CancelButton.SetText (13727)
954 CancelButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
956 AppearanceButton.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "OpenAppearanceWindow")
957 SoundButton.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "OpenSoundWindow")
958 ColorButton.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "OpenColorWindow")
959 ScriptButton.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "OpenScriptWindow")
960 BiographyButton.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "OpenBiographyEditWindow")
961 DoneButton.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "CustomizeDonePress")
962 CancelButton.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "CustomizeCancelPress")
964 CustomizeWindow.ShowModal (MODAL_SHADOW_GRAY)
965 return
967 def CustomizeDonePress ():
968 global CustomizeWindow
970 if CustomizeWindow:
971 CustomizeWindow.Unload ()
972 CustomizeWindow = None
974 UpdateRecordsWindow ()
975 return
977 def CustomizeCancelPress ():
978 global CustomizeWindow
980 if CustomizeWindow:
981 CustomizeWindow.Unload ()
982 CustomizeWindow = None
984 UpdateRecordsWindow ()
985 return
987 def OpenAppearanceWindow ():
988 global SubCustomizeWindow
989 global PortraitButton
990 global Gender, LastPortrait
992 SubCustomizeWindow = GemRB.LoadWindow (18)
993 pc = GemRB.GameGetSelectedPCSingle ()
994 Gender = GemRB.GetPlayerStat (pc, IE_SEX, 1)
995 PortraitName = GemRB.GetPlayerPortrait (pc, 0)
996 LastPortrait = PortraitsTable.GetRowIndex (PortraitName[0:len(PortraitName)-1])
998 PortraitButton = SubCustomizeWindow.GetControl (0)
999 PortraitButton.SetFlags (IE_GUI_BUTTON_PICTURE|IE_GUI_BUTTON_NO_IMAGE,OP_SET)
1000 PortraitButton.SetState (IE_GUI_BUTTON_LOCKED)
1002 LeftButton = SubCustomizeWindow.GetControl (1)
1003 RightButton = SubCustomizeWindow.GetControl (2)
1005 DoneButton = SubCustomizeWindow.GetControl (3)
1006 DoneButton.SetText (11973)
1007 DoneButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
1009 CancelButton = SubCustomizeWindow.GetControl (4)
1010 CancelButton.SetText (13727)
1011 CancelButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
1013 CustomPortraitButton = SubCustomizeWindow.GetControl (5)
1014 CustomPortraitButton.SetText (17545)
1016 LeftButton.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "PortraitLeftPress")
1017 RightButton.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "PortraitRightPress")
1018 DoneButton.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "DonePortraitWindow")
1019 CancelButton.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "CloseSubCustomizeWindow")
1020 CustomPortraitButton.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "OpenCustomPortraitWindow")
1021 SubCustomizeWindow.ShowModal (MODAL_SHADOW_GRAY)
1023 while True:
1024 if PortraitsTable.GetValue (LastPortrait, 0) == Gender:
1025 UpdatePortrait ()
1026 break
1027 LastPortrait = LastPortrait + 1
1029 return
1031 def DonePortraitWindow ():
1032 pc = GemRB.GameGetSelectedPCSingle ()
1033 Name = PortraitsTable.GetRowName (LastPortrait)
1034 GemRB.FillPlayerInfo (pc, Name + "M", Name + "S")
1035 CloseSubCustomizeWindow ()
1036 return
1038 def PortraitRightPress():
1039 global LastPortrait
1041 while True:
1042 LastPortrait = LastPortrait + 1
1043 if LastPortrait >= PortraitsTable.GetRowCount ():
1044 LastPortrait = 0
1045 if PortraitsTable.GetValue (LastPortrait, 0) == Gender:
1046 UpdatePortrait ()
1047 return
1049 return
1051 def PortraitLeftPress():
1052 global LastPortrait
1054 while True:
1055 LastPortrait = LastPortrait - 1
1056 if LastPortrait < 0:
1057 LastPortrait = PortraitsTable.GetRowCount ()-1
1058 if PortraitsTable.GetValue (LastPortrait, 0) == Gender:
1059 UpdatePortrait ()
1060 return
1062 return
1064 def UpdatePortrait ():
1065 PortraitName = PortraitsTable.GetRowName (LastPortrait)+"L"
1066 PortraitButton.SetPicture (PortraitName, "NOPORTLG")
1067 return
1069 def OpenCustomPortraitWindow ():
1070 global SubSubCustomizeWindow
1071 global PortraitList1, PortraitList2
1072 global RowCount1, RowCount2
1074 SubSubCustomizeWindow = GemRB.LoadWindow (19)
1076 SmallPortraitButton = SubSubCustomizeWindow.GetControl (1)
1077 SmallPortraitButton.SetFlags (IE_GUI_BUTTON_PICTURE|IE_GUI_BUTTON_NO_IMAGE,OP_SET)
1079 LargePortraitButton = SubSubCustomizeWindow.GetControl (0)
1080 LargePortraitButton.SetFlags (IE_GUI_BUTTON_PICTURE|IE_GUI_BUTTON_NO_IMAGE,OP_SET)
1082 DoneButton = SubSubCustomizeWindow.GetControl (10)
1083 DoneButton.SetText (11973)
1084 DoneButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
1085 DoneButton.SetState (IE_GUI_BUTTON_DISABLED)
1087 CancelButton = SubSubCustomizeWindow.GetControl (11)
1088 CancelButton.SetText (13727)
1089 CancelButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
1091 # Portrait List Large
1092 PortraitList1 = SubSubCustomizeWindow.GetControl (2)
1093 RowCount1 = PortraitList1.GetPortraits (0)
1094 PortraitList1.SetEventByName (IE_GUI_TEXTAREA_ON_CHANGE, "LargeCustomPortrait")
1095 GemRB.SetVar ("Row1", RowCount1)
1096 PortraitList1.SetVarAssoc ("Row1",RowCount1)
1098 # Portrait List Small
1099 PortraitList2 = SubSubCustomizeWindow.GetControl (3)
1100 RowCount2 = PortraitList2.GetPortraits (1)
1101 PortraitList2.SetEventByName (IE_GUI_TEXTAREA_ON_CHANGE, "SmallCustomPortrait")
1102 GemRB.SetVar ("Row2", RowCount2)
1103 PortraitList2.SetVarAssoc ("Row2",RowCount2)
1105 DoneButton.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "DonePortraitCustomizeWindow")
1106 CancelButton.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "CloseSubSubCustomizeWindow")
1108 SubSubCustomizeWindow.ShowModal (MODAL_SHADOW_GRAY)
1109 return
1111 def DonePortraitCustomizeWindow ():
1112 pc = GemRB.GameGetSelectedPCSingle ()
1113 GemRB.FillPlayerInfo (pc, PortraitList1.QueryText () , PortraitList2.QueryText ())
1114 CloseSubSubCustomizeWindow ()
1115 #closing the generic portraits, because we just set a custom one
1116 CloseSubCustomizeWindow ()
1117 return
1119 def LargeCustomPortrait ():
1120 Window = SubSubCustomizeWindow
1122 Portrait = PortraitList1.QueryText ()
1123 #small hack
1124 if GemRB.GetVar ("Row1") == RowCount1:
1125 return
1127 Label = Window.GetControl (0x10000007)
1128 Label.SetText (Portrait)
1130 Button = Window.GetControl (10)
1131 if Portrait=="":
1132 Portrait = "NOPORTMD"
1133 Button.SetState (IE_GUI_BUTTON_DISABLED)
1134 else:
1135 if PortraitList2.QueryText ()!="":
1136 Button.SetState (IE_GUI_BUTTON_ENABLED)
1138 Button = Window.GetControl (0)
1139 Button.SetPicture (Portrait, "NOPORTMD")
1140 return
1142 def SmallCustomPortrait ():
1143 Window = SubSubCustomizeWindow
1145 Portrait = PortraitList2.QueryText ()
1146 #small hack
1147 if GemRB.GetVar ("Row2") == RowCount2:
1148 return
1150 Label = Window.GetControl (0x10000008)
1151 Label.SetText (Portrait)
1153 Button = Window.GetControl (10)
1154 if Portrait=="":
1155 Portrait = "NOPORTSM"
1156 Button.SetState (IE_GUI_BUTTON_DISABLED)
1157 else:
1158 if PortraitList1.QueryText ()!="":
1159 Button.SetState (IE_GUI_BUTTON_ENABLED)
1161 Button = Window.GetControl (1)
1162 Button.SetPicture (Portrait, "NOPORTSM")
1163 return
1165 def OpenSoundWindow ():
1166 global SubCustomizeWindow
1167 global VoiceList
1168 global Gender
1170 SubCustomizeWindow = GemRB.LoadWindow (20)
1172 VoiceList = SubCustomizeWindow.GetControl (5)
1173 VoiceList.SetFlags (IE_GUI_TEXTAREA_SELECTABLE)
1174 pc = GemRB.GameGetSelectedPCSingle ()
1175 Gender = GemRB.GetPlayerStat (pc, IE_SEX, 1)
1177 VoiceList.SetVarAssoc ("Selected", 0)
1178 RowCount=VoiceList.GetCharSounds()
1180 PlayButton = SubCustomizeWindow.GetControl (7)
1181 PlayButton.SetText (17318)
1183 TextArea = SubCustomizeWindow.GetControl (8)
1184 TextArea.SetText (11315)
1186 DoneButton = SubCustomizeWindow.GetControl (10)
1187 DoneButton.SetText (11973)
1188 DoneButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
1190 CancelButton = SubCustomizeWindow.GetControl (11)
1191 CancelButton.SetText (13727)
1192 CancelButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
1194 PlayButton.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "PlaySoundPressed")
1195 DoneButton.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "DoneSoundWindow")
1196 CancelButton.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "CloseSubCustomizeWindow")
1198 SubCustomizeWindow.ShowModal (MODAL_SHADOW_GRAY)
1199 return
1201 def DoneSoundWindow ():
1202 pc = GemRB.GameGetSelectedPCSingle ()
1203 CharSound = VoiceList.QueryText ()
1204 GemRB.SetPlayerSound (pc, CharSound)
1206 CloseSubCustomizeWindow ()
1207 return
1209 def PlaySoundPressed():
1210 global CharSoundWindow, SoundIndex, SoundSequence
1212 CharSound = VoiceList.QueryText ()
1213 while (not GemRB.HasResource (CharSound + SoundSequence[SoundIndex], RES_WAV)):
1214 NextSound()
1215 GemRB.PlaySound (CharSound + SoundSequence[SoundIndex], 0, 0, 4)
1216 return
1218 def OpenColorWindow ():
1219 global SubCustomizeWindow
1220 global PortraitWindow
1221 global PortraitButton
1222 global HairButton, SkinButton, MajorButton, MinorButton
1223 global HairColor, SkinColor, MajorColor, MinorColor
1225 pc = GemRB.GameGetSelectedPCSingle ()
1226 MinorColor = GemRB.GetPlayerStat (pc, IE_MINOR_COLOR)
1227 MajorColor = GemRB.GetPlayerStat (pc, IE_MAJOR_COLOR)
1228 SkinColor = GemRB.GetPlayerStat (pc, IE_SKIN_COLOR)
1229 HairColor = GemRB.GetPlayerStat (pc, IE_HAIR_COLOR)
1230 SubCustomizeWindow = GemRB.LoadWindow (21)
1232 PortraitButton = SubCustomizeWindow.GetControl (0)
1233 PortraitButton.SetFlags (IE_GUI_BUTTON_PICTURE|IE_GUI_BUTTON_NO_IMAGE,OP_SET)
1234 PortraitButton.SetState (IE_GUI_BUTTON_LOCKED)
1236 HairButton = SubCustomizeWindow.GetControl (3)
1237 SkinButton = SubCustomizeWindow.GetControl (4)
1238 MajorButton = SubCustomizeWindow.GetControl (5)
1239 MinorButton = SubCustomizeWindow.GetControl (6)
1241 DoneButton = SubCustomizeWindow.GetControl (12)
1242 DoneButton.SetText (11973)
1243 DoneButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
1245 CancelButton = SubCustomizeWindow.GetControl (13)
1246 CancelButton.SetText (13727)
1247 CancelButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
1249 HairButton.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "SetHairColor")
1250 SkinButton.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "SetSkinColor")
1251 MajorButton.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "SetMajorColor")
1252 MinorButton.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "SetMinorColor")
1253 DoneButton.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "DoneColorWindow")
1254 CancelButton.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "CloseSubCustomizeWindow")
1255 UpdatePaperDoll ()
1257 SubCustomizeWindow.ShowModal (MODAL_SHADOW_GRAY)
1258 return
1260 def DoneColorWindow ():
1261 pc = GemRB.GameGetSelectedPCSingle ()
1262 GemRB.SetPlayerStat (pc, IE_MINOR_COLOR, MinorColor)
1263 GemRB.SetPlayerStat (pc, IE_MAJOR_COLOR, MajorColor)
1264 GemRB.SetPlayerStat (pc, IE_SKIN_COLOR, SkinColor)
1265 GemRB.SetPlayerStat (pc, IE_HAIR_COLOR, HairColor)
1266 CloseSubCustomizeWindow ()
1267 return
1269 def UpdatePaperDoll ():
1270 pc = GemRB.GameGetSelectedPCSingle ()
1271 Color1 = GemRB.GetPlayerStat (pc, IE_METAL_COLOR)
1272 MinorButton.SetBAM ("COLGRAD", 0, 0, MinorColor&0xff)
1273 MajorButton.SetBAM ("COLGRAD", 0, 0, MajorColor&0xff)
1274 SkinButton.SetBAM ("COLGRAD", 0, 0, SkinColor&0xff)
1275 Color5 = GemRB.GetPlayerStat (pc, IE_LEATHER_COLOR)
1276 Color6 = GemRB.GetPlayerStat (pc, IE_ARMOR_COLOR)
1277 HairButton.SetBAM ("COLGRAD", 0, 0, HairColor&0xff)
1278 PortraitButton.SetPLT (GetActorPaperDoll (pc),
1279 Color1, MinorColor, MajorColor, SkinColor, Color5, Color6, HairColor, 0, 0)
1280 return
1282 def SetHairColor ():
1283 global ColorIndex, PickedColor
1285 ColorIndex = 0
1286 PickedColor = HairColor
1287 OpenColorPicker ()
1288 return
1290 def SetSkinColor ():
1291 global ColorIndex, PickedColor
1293 ColorIndex = 1
1294 PickedColor = SkinColor
1295 OpenColorPicker ()
1296 return
1298 def SetMinorColor ():
1299 global ColorIndex, PickedColor
1301 ColorIndex = 2
1302 PickedColor = MinorColor
1303 OpenColorPicker ()
1304 return
1306 def SetMajorColor ():
1307 global ColorIndex, PickedColor
1309 ColorIndex = 3
1310 PickedColor = MajorColor
1311 OpenColorPicker ()
1312 return
1314 def OpenColorPicker ():
1315 global SubSubCustomizeWindow
1316 #global Selected
1318 SubSubCustomizeWindow = GemRB.LoadWindow (22)
1320 GemRB.SetVar ("Selected",-1)
1321 for i in range (1,35):
1322 Button = SubSubCustomizeWindow.GetControl (i)
1323 Button.SetState (IE_GUI_BUTTON_DISABLED)
1324 Button.SetFlags (IE_GUI_BUTTON_PICTURE|IE_GUI_BUTTON_RADIOBUTTON,OP_OR)
1326 #Selected = -1
1327 for i in range (34):
1328 MyColor = ColorTable.GetValue (ColorIndex, i)
1329 if MyColor == "*":
1330 break
1331 Button = SubSubCustomizeWindow.GetControl (i+1)
1332 Button.SetBAM("COLGRAD", 2, 0, MyColor)
1333 if PickedColor == MyColor:
1334 GemRB.SetVar ("Selected",i)
1335 #Selected = i
1336 Button.SetState (IE_GUI_BUTTON_ENABLED)
1337 Button.SetVarAssoc("Selected",i)
1338 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "DonePress")
1340 SubSubCustomizeWindow.ShowModal (MODAL_SHADOW_GRAY)
1341 return
1343 def DonePress():
1344 global HairColor, SkinColor, MajorColor, MinorColor
1345 global PickedColor
1347 CloseSubSubCustomizeWindow ()
1348 PickedColor=ColorTable.GetValue (ColorIndex, GemRB.GetVar ("Selected"))
1349 if ColorIndex==0:
1350 HairColor=PickedColor
1351 UpdatePaperDoll ()
1352 return
1353 if ColorIndex==1:
1354 SkinColor=PickedColor
1355 UpdatePaperDoll ()
1356 return
1357 if ColorIndex==2:
1358 MinorColor=PickedColor
1359 UpdatePaperDoll ()
1360 return
1362 MajorColor=PickedColor
1363 UpdatePaperDoll ()
1364 return
1366 def OpenScriptWindow ():
1367 global SubCustomizeWindow
1368 global ScriptTextArea, SelectedTextArea
1370 SubCustomizeWindow = GemRB.LoadWindow (11)
1372 ScriptTextArea = SubCustomizeWindow.GetControl (2)
1373 ScriptTextArea.SetFlags (IE_GUI_TEXTAREA_SELECTABLE)
1374 FillScriptList ()
1375 pc = GemRB.GameGetSelectedPCSingle ()
1376 script = GemRB.GetPlayerScript (pc)
1377 scriptindex = ScriptsTable.GetRowIndex (script)
1378 GemRB.SetVar ("Selected", scriptindex)
1379 ScriptTextArea.SetVarAssoc ("Selected", scriptindex)
1381 SelectedTextArea = SubCustomizeWindow.GetControl (4)
1382 UpdateScriptSelection ()
1384 DoneButton = SubCustomizeWindow.GetControl (5)
1385 DoneButton.SetText (11973)
1386 DoneButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
1388 CancelButton = SubCustomizeWindow.GetControl (6)
1389 CancelButton.SetText (13727)
1390 CancelButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
1392 DoneButton.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "DoneScriptWindow")
1393 CancelButton.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "CloseSubCustomizeWindow")
1394 ScriptTextArea.SetEventByName (IE_GUI_TEXTAREA_ON_CHANGE, "UpdateScriptSelection")
1396 SubCustomizeWindow.ShowModal (MODAL_SHADOW_GRAY)
1397 return
1399 def FillScriptList ():
1400 ScriptTextArea.Clear ()
1401 row = ScriptsTable.GetRowCount ()
1402 for i in range (row):
1403 GemRB.SetToken ("script", ScriptsTable.GetRowName (i) )
1404 title = ScriptsTable.GetValue (i,0)
1405 if title!=-1:
1406 desc = ScriptsTable.GetValue (i,1)
1407 txt = GemRB.GetString (title)
1409 if (desc!=-1):
1410 txt += GemRB.GetString (desc)
1412 ScriptTextArea.Append (txt+"\n", -1)
1414 else:
1415 ScriptTextArea.Append (ScriptsTable.GetRowName (i)+"\n" ,-1)
1417 return
1419 def DoneScriptWindow ():
1420 pc = GemRB.GameGetSelectedPCSingle ()
1421 script = ScriptsTable.GetRowName (GemRB.GetVar ("Selected") )
1422 GemRB.SetPlayerScript (pc, script)
1423 CloseSubCustomizeWindow ()
1424 return
1426 def UpdateScriptSelection():
1427 text = ScriptTextArea.QueryText ()
1428 SelectedTextArea.SetText (text)
1429 return
1431 def OpenBiographyEditWindow ():
1432 global SubCustomizeWindow
1433 global BioStrRef
1434 global TextArea
1436 Changed = 0
1437 pc = GemRB.GameGetSelectedPCSingle ()
1438 BioStrRef = GemRB.GetPlayerString (pc, 74)
1439 if BioStrRef != 33347:
1440 Changed = 1
1442 SubCustomizeWindow = GemRB.LoadWindow (23)
1444 ClearButton = SubCustomizeWindow.GetControl (5)
1445 ClearButton.SetText (34881)
1447 DoneButton = SubCustomizeWindow.GetControl (1)
1448 DoneButton.SetText (11973)
1449 DoneButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
1451 RevertButton = SubCustomizeWindow.GetControl (3)
1452 RevertButton.SetText (2240)
1453 if not Changed:
1454 RevertButton.SetState (IE_GUI_BUTTON_DISABLED)
1456 CancelButton = SubCustomizeWindow.GetControl (2)
1457 CancelButton.SetText (13727)
1458 CancelButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
1460 TextArea = SubCustomizeWindow.GetControl (4)
1461 TextArea.SetBufferLength (65535)
1462 TextArea.SetText (BioStrRef)
1464 ClearButton.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "ClearBiography")
1465 DoneButton.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "DoneBiographyWindow")
1466 RevertButton.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "RevertBiography")
1467 CancelButton.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "CloseSubCustomizeWindow")
1469 SubCustomizeWindow.ShowModal (MODAL_SHADOW_GRAY)
1470 return
1472 def ClearBiography():
1473 pc = GemRB.GameGetSelectedPCSingle ()
1474 BioStrRef = 62015+pc
1475 #GemRB.CreateString (BioStrRef, "")
1476 TextArea.SetText ("")
1477 return
1479 def DoneBiographyWindow ():
1480 global BioStrRef
1482 #TODO set bio
1483 pc = GemRB.GameGetSelectedPCSingle ()
1484 #pc is 1 based
1485 BioStrRef = 62015+pc
1486 GemRB.CreateString (BioStrRef, TextArea.QueryText())
1487 GemRB.SetPlayerString (pc, 74, BioStrRef)
1488 CloseSubCustomizeWindow ()
1489 return
1491 def RevertBiography():
1492 global BioStrRef
1494 BioStrRef = 33347
1495 TextArea.SetText (33347)
1496 return
1498 def CloseSubCustomizeWindow ():
1499 global SubCustomizeWindow
1501 if SubCustomizeWindow:
1502 SubCustomizeWindow.Unload ()
1503 SubCustomizeWindow = None
1504 return
1506 def CloseSubSubCustomizeWindow ():
1507 global SubSubCustomizeWindow
1509 if SubSubCustomizeWindow:
1510 SubSubCustomizeWindow.Unload ()
1511 SubSubCustomizeWindow = None
1512 return
1514 ###################################################
1515 # End of file GUIREC.py