factored out the EFFv2 saving into EFFImporter
[gemrb.git] / gemrb / GUIScripts / iwd / GUIREC.py
blobe3f21d023f61741bce60599070c7a9153afed742
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
22 ###################################################
23 import GemRB
24 import GUICommon
25 import CommonTables
26 import GUICommonWindows
27 from GUIDefines import *
28 from ie_stats import *
29 from ie_restype import *
30 import LUCommon
31 import LevelUp
32 import GUIWORLD
33 import DualClass
34 import Portrait
36 ###################################################
37 RecordsWindow = None
38 InformationWindow = None
39 BiographyWindow = None
40 PortraitWindow = None
41 CustomPortraitWindow = None
42 OptionsWindow = None
43 CustomizeWindow = None
44 OldPortraitWindow = None
45 OldOptionsWindow = None
46 ExportDoneButton = None
47 ExportFileName = ""
49 ScriptsTable = None
50 ColorTable = None
51 ColorIndex = None
52 ScriptTextArea = None
53 SelectedTextArea = 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, PortraitWindow, OptionsWindow
64 global OldPortraitWindow, OldOptionsWindow
66 if GUICommon.CloseOtherWindow (OpenRecordsWindow):
67 if InformationWindow: OpenInformationWindow ()
69 if RecordsWindow:
70 RecordsWindow.Unload ()
71 if OptionsWindow:
72 OptionsWindow.Unload ()
73 if PortraitWindow:
74 PortraitWindow.Unload ()
75 if CustomPortraitWindow:
76 CustomPortraitWindow.Unload()
77 RecordsWindow = None
78 GemRB.SetVar ("OtherWindow", -1)
79 GUICommon.GameWindow.SetVisible(WINDOW_VISIBLE)
80 GemRB.UnhideGUI ()
81 GUICommonWindows.PortraitWindow = OldPortraitWindow
82 OldPortraitWindow = None
83 GUICommonWindows.OptionsWindow = OldOptionsWindow
84 OldOptionsWindow = None
85 GUICommonWindows.SetSelectionChangeHandler (None)
86 return
88 GemRB.HideGUI ()
89 GUICommon.GameWindow.SetVisible(WINDOW_INVISIBLE)
91 GemRB.LoadWindowPack ("GUIREC", 640, 480) #TODO: remove?
92 RecordsWindow = Window = GemRB.LoadWindow (2)
93 GemRB.SetVar ("OtherWindow", RecordsWindow.ID)
94 # saving the original portrait window
95 OldOptionsWindow = GUICommonWindows.OptionsWindow
96 OptionsWindow = GemRB.LoadWindow (0)
97 GUICommonWindows.SetupMenuWindowControls (OptionsWindow, 0, OpenRecordsWindow)
98 OptionsWindow.SetFrame ()
99 OldPortraitWindow = GUICommonWindows.PortraitWindow
100 PortraitWindow = GUICommonWindows.OpenPortraitWindow (0)
102 # dual class
103 Button = Window.GetControl (0)
104 Button.SetText (7174)
105 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, DualClass.DualClassWindow)
107 # levelup
108 Button = Window.GetControl (37)
109 Button.SetText (7175)
110 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, LevelUp.OpenLevelUpWindow)
112 # information
113 Button = Window.GetControl (1)
114 Button.SetText (11946)
115 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, OpenInformationWindow)
117 # reform party
118 Button = Window.GetControl (51)
119 Button.SetText (16559)
120 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, GUIWORLD.OpenReformPartyWindow)
122 # customize
123 Button = Window.GetControl (50)
124 Button.SetText (10645)
125 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, OpenCustomizeWindow)
127 # export
128 Button = Window.GetControl (36)
129 Button.SetText (13956)
130 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, OpenExportWindow)
132 ## # kit info
133 ## Button = Window.GetControl (52)
134 ## Button.SetText (61265)
135 ## Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, KitInfoWindow)
137 GUICommonWindows.SetSelectionChangeHandler (UpdateRecordsWindow)
138 UpdateRecordsWindow ()
140 OptionsWindow.SetVisible (WINDOW_VISIBLE)
141 Window.SetVisible (WINDOW_FRONT)
142 PortraitWindow.SetVisible (WINDOW_VISIBLE)
143 return
145 def UpdateRecordsWindow ():
146 global stats_overview, alignment_help
148 Window = RecordsWindow
149 if not RecordsWindow:
150 print "SelectionChange handler points to non existing window\n"
151 return
153 pc = GemRB.GameGetSelectedPCSingle ()
155 # exportable
156 Button = Window.GetControl (36)
157 if GemRB.GetPlayerStat (pc, IE_MC_FLAGS)&MC_EXPORTABLE:
158 Button.SetState (IE_GUI_BUTTON_ENABLED)
159 else:
160 Button.SetState (IE_GUI_BUTTON_DISABLED)
162 # dual-classable
163 Button = Window.GetControl (0)
164 if GUICommon.CanDualClass (pc):
165 Button.SetState (IE_GUI_BUTTON_DISABLED)
166 else:
167 Button.SetState (IE_GUI_BUTTON_ENABLED)
169 # levelup
170 Button = Window.GetControl (37)
171 if LUCommon.CanLevelUp (pc):
172 Button.SetState (IE_GUI_BUTTON_ENABLED)
173 else:
174 Button.SetState (IE_GUI_BUTTON_DISABLED)
176 # name
177 Label = Window.GetControl (0x1000000e)
178 Label.SetText (GemRB.GetPlayerName (pc, 0))
180 # portrait
181 Button = Window.GetControl (2)
182 Button.SetFlags (IE_GUI_BUTTON_NO_IMAGE | IE_GUI_BUTTON_PICTURE, OP_SET)
183 Button.SetState (IE_GUI_BUTTON_LOCKED)
184 Button.SetPicture (GemRB.GetPlayerPortrait (pc,0), "NOPORTMD")
186 # armorclass
187 Label = Window.GetControl (0x10000028)
188 ac = GemRB.GetPlayerStat (pc, IE_ARMORCLASS)
189 ac += GemRB.GetAbilityBonus (IE_DEX, 2, GemRB.GetPlayerStat (pc, IE_DEX) )
190 Label.SetText (str (ac))
191 Label.SetTooltip (17183)
193 # hp now
194 Label = Window.GetControl (0x10000029)
195 Label.SetText (str (GemRB.GetPlayerStat (pc, IE_HITPOINTS)))
196 Label.SetTooltip (17184)
198 # hp max
199 Label = Window.GetControl (0x1000002a)
200 Label.SetText (str (GemRB.GetPlayerStat (pc, IE_MAXHITPOINTS)))
201 Label.SetTooltip (17378)
203 # stats
205 sstr = GemRB.GetPlayerStat (pc, IE_STR)
206 sstrx = GemRB.GetPlayerStat (pc, IE_STREXTRA)
207 cstr = GetStatColor (pc, IE_STR)
208 if sstrx > 0 and sstr==18:
209 sstr = "%d/%02d" %(sstr, sstrx % 100)
210 else:
211 sstr = str (sstr)
213 sint = str (GemRB.GetPlayerStat (pc, IE_INT))
214 cint = GetStatColor (pc, IE_INT)
215 swis = str (GemRB.GetPlayerStat (pc, IE_WIS))
216 cwis = GetStatColor (pc, IE_WIS)
217 sdex = str (GemRB.GetPlayerStat (pc, IE_DEX))
218 cdex = GetStatColor (pc, IE_DEX)
219 scon = str (GemRB.GetPlayerStat (pc, IE_CON))
220 ccon = GetStatColor (pc, IE_CON)
221 schr = str (GemRB.GetPlayerStat (pc, IE_CHR))
222 cchr = GetStatColor (pc, IE_CHR)
224 Label = Window.GetControl (0x1000002f)
225 Label.SetText (sstr)
226 Label.SetTextColor (cstr[0], cstr[1], cstr[2])
228 Label = Window.GetControl (0x10000009)
229 Label.SetText (sdex)
230 Label.SetTextColor (cdex[0], cdex[1], cdex[2])
232 Label = Window.GetControl (0x1000000a)
233 Label.SetText (scon)
234 Label.SetTextColor (ccon[0], ccon[1], ccon[2])
236 Label = Window.GetControl (0x1000000b)
237 Label.SetText (sint)
238 Label.SetTextColor (cint[0], cint[1], cint[2])
240 Label = Window.GetControl (0x1000000c)
241 Label.SetText (swis)
242 Label.SetTextColor (cwis[0], cwis[1], cwis[2])
244 Label = Window.GetControl (0x1000000d)
245 Label.SetText (schr)
246 Label.SetTextColor (cchr[0], cchr[1], cchr[2])
248 # class
249 ClassTitle = GUICommon.GetActorClassTitle (pc)
250 Label = Window.GetControl (0x10000030)
251 Label.SetText (ClassTitle)
253 # race
254 text = CommonTables.Races.GetValue (CommonTables.Races.FindValue (3, GemRB.GetPlayerStat (pc, IE_RACE)) ,
257 Label = Window.GetControl (0x1000000f)
258 Label.SetText (text)
260 Table = GemRB.LoadTable ("aligns")
262 text = Table.GetValue (Table.FindValue ( 3, GemRB.GetPlayerStat (pc, IE_ALIGNMENT) ), 0)
263 Label = Window.GetControl (0x10000010)
264 Label.SetText (text)
266 Label = Window.GetControl (0x10000011)
267 if GemRB.GetPlayerStat (pc, IE_SEX) == 1:
268 Label.SetText (7198)
269 else:
270 Label.SetText (7199)
272 # help, info textarea
273 stats_overview = GetStatOverview (pc)
274 Text = Window.GetControl (45)
275 Text.SetText (stats_overview)
276 #TODO: making window visible/shaded depending on the pc's state
277 Window.SetVisible (WINDOW_VISIBLE)
278 return
280 def GetStatColor (pc, stat):
281 a = GemRB.GetPlayerStat (pc, stat)
282 b = GemRB.GetPlayerStat (pc, stat, 1)
283 if a==b:
284 return (255,255,255)
285 if a<b:
286 return (255,255,0)
287 return (0,255,0)
289 # GemRB.GetPlayerStat wrapper that only returns nonnegative values
290 def GSNN (pc, stat):
291 val = GemRB.GetPlayerStat (pc, stat)
292 if val >= 0:
293 return val
294 else:
295 return 0
297 # LevelDiff is used only from the level up code and holds the level
298 # difference for each class
299 def GetStatOverview (pc, LevelDiff=[0,0,0]):
300 StateTable = GemRB.LoadTable ("statdesc")
302 GS = lambda s, pc=pc: GemRB.GetPlayerStat (pc, s)
303 GB = lambda s, pc=pc: GemRB.GetPlayerStat (pc, s, 1)
304 GA = lambda s, col, pc=pc: GemRB.GetAbilityBonus (s, col, GS (s) )
306 stats = []
307 # class levels
308 # 16480 <CLASS>: Level <LEVEL>
309 # Experience: <EXPERIENCE>
310 # Next Level: <NEXTLEVEL>
312 # collecting tokens for stat overview
313 ClassTitle = GUICommon.GetActorClassTitle (pc)
314 GemRB.SetToken ("CLASS", ClassTitle)
315 Class = GemRB.GetPlayerStat (pc, IE_CLASS)
316 Class = CommonTables.Classes.FindValue (5, Class)
317 Class = CommonTables.Classes.GetRowName (Class)
318 Dual = GUICommon.IsDualClassed (pc, 1)
319 Multi = GUICommon.IsMultiClassed (pc, 1)
320 XP = GemRB.GetPlayerStat (pc, IE_XP)
321 LevelDrain = GS (IE_LEVELDRAIN)
323 if GS (IE_STATE_ID) & STATE_DEAD:
324 stats.append ( (11829,1,'c') ) # DEAD
325 stats.append (None)
327 if Multi[0] > 1: # we're multiclassed
328 print "\tMulticlassed"
329 Levels = [GemRB.GetPlayerStat (pc, IE_LEVEL), GemRB.GetPlayerStat (pc, IE_LEVEL2), GemRB.GetPlayerStat (pc, IE_LEVEL3)]
331 stats.append ( (19721,1,'c') )
332 stats.append (None)
333 for i in range (Multi[0]):
334 ClassIndex = CommonTables.Classes.FindValue (5, Multi[i+1])
335 ClassTitle = GemRB.GetString (CommonTables.Classes.GetValue (ClassIndex, 2))
336 GemRB.SetToken ("CLASS", ClassTitle)
337 Class = CommonTables.Classes.GetRowName (ClassIndex)
338 GemRB.SetToken ("LEVEL", str (Levels[i]+LevelDiff[i]-int(LevelDrain/Multi[0])) )
339 GemRB.SetToken ("EXPERIENCE", str (XP/Multi[0]) )
340 if LevelDrain:
341 stats.append ( (GemRB.GetString (19720),1,'d') )
342 stats.append ( (GemRB.GetString (57435),1,'d') ) # LEVEL DRAINED
343 else:
344 GemRB.SetToken ("NEXTLEVEL", LUCommon.GetNextLevelExp (Levels[i]+LevelDiff[i], Class) )
345 stats.append ( (GemRB.GetString (16480),"",'d') )
346 stats.append (None)
347 print "\t\tClass (Level):",Class,"(",Levels[i],")"
349 elif Dual[0] > 0: # dual classed; first show the new class
350 print "\tDual classed"
351 stats.append ( (19722,1,'c') )
352 stats.append (None)
354 Levels = [GemRB.GetPlayerStat (pc, IE_LEVEL), GemRB.GetPlayerStat (pc, IE_LEVEL2), GemRB.GetPlayerStat (pc, IE_LEVEL3)]
356 # the levels are stored in the class order (eg. FIGHTER_MAGE)
357 # the current active class does not matter!
358 if GUICommon.IsDualSwap (pc):
359 Levels = [Levels[1], Levels[0], Levels[2]]
361 Levels[0] += LevelDiff[0]
363 ClassTitle = GemRB.GetString (CommonTables.Classes.GetValue (Dual[2], 2))
364 GemRB.SetToken ("CLASS", ClassTitle)
365 GemRB.SetToken ("LEVEL", str (Levels[0]-LevelDrain))
366 Class = CommonTables.Classes.GetRowName (Dual[2])
367 XP2 = GemRB.GetPlayerStat (pc, IE_XP)
368 GemRB.SetToken ("EXPERIENCE", str (XP2) )
369 if LevelDrain:
370 stats.append ( (GemRB.GetString (19720),1,'d') )
371 stats.append ( (GemRB.GetString (57435),1,'d') ) # LEVEL DRAINED
372 else:
373 GemRB.SetToken ("NEXTLEVEL", LUCommon.GetNextLevelExp (Levels[0], Class) )
374 stats.append ( (GemRB.GetString (16480),"",'d') )
375 stats.append (None)
376 # the first class (shown second)
377 if Dual[0] == 1:
378 ClassTitle = GemRB.GetString (CommonTables.KitList.GetValue (Dual[1], 2))
379 elif Dual[0] == 2:
380 ClassTitle = GemRB.GetString (CommonTables.Classes.GetValue (Dual[1], 2))
381 GemRB.SetToken ("CLASS", ClassTitle)
382 GemRB.SetToken ("LEVEL", str (Levels[1]) )
384 # the xp table contains only classes, so we have to determine the base class for kits
385 if Dual[0] == 2:
386 BaseClass = CommonTables.Classes.GetRowName (Dual[1])
387 else:
388 BaseClass = GUICommon.GetKitIndex (pc)
389 BaseClass = CommonTables.KitList.GetValue (BaseClass, 7)
390 BaseClass = CommonTables.Classes.FindValue (5, BaseClass)
391 BaseClass = CommonTables.Classes.GetRowName (BaseClass)
392 # the first class' XP is discarded and set to the minimum level
393 # requirement, so if you don't dual class right after a levelup,
394 # the game would eat some of your XP
395 XP1 = CommonTables.NextLevel.GetValue (BaseClass, str (Levels[1]))
396 GemRB.SetToken ("EXPERIENCE", str (XP1) )
398 # inactive until the new class SURPASSES the former
399 if Levels[0] <= Levels[1]:
400 # inactive
401 stats.append ( (19719,1,'c') )
402 else:
403 stats.append ( (19720,1,'c') )
404 stats.append (None)
405 else: # single classed
406 print "\tSingle classed"
407 Level = GemRB.GetPlayerStat (pc, IE_LEVEL) + LevelDiff[0]
408 GemRB.SetToken ("LEVEL", str (Level-LevelDrain))
409 GemRB.SetToken ("EXPERIENCE", str (XP) )
410 if LevelDrain:
411 stats.append ( (19720,1,'c') )
412 stats.append ( (57435,1,'c') ) # LEVEL DRAINED
413 else:
414 GemRB.SetToken ("NEXTLEVEL", LUCommon.GetNextLevelExp (Level, Class) )
415 stats.append ( (16480,1,'c') )
416 stats.append (None)
417 print "\t\tClass (Level):",Class,"(",Level,")"
419 # check to see if we have a level diff anywhere
420 if sum (LevelDiff) == 0:
421 effects = GemRB.GetPlayerStates (pc)
422 if len (effects):
423 for c in effects:
424 tmp = StateTable.GetValue (ord(c)-66, 0)
425 stats.append ( (tmp,c,'a') )
426 stats.append (None)
428 stats.append (None)
430 #proficiencies
431 stats.append ( (8442,1,'c') )
433 stats.append ( (9457, str(GS (IE_TOHIT))+" ("+str(GemRB.GetCombatDetails(pc, 0)["ToHit"])+")", '0') )
434 tmp = GS (IE_NUMBEROFATTACKS)
435 if (tmp&1):
436 tmp2 = str (tmp/2) + chr (188)
437 else:
438 tmp2 = str (tmp/2)
439 stats.append ( (9458, tmp2, '') )
440 stats.append ( (9459, GSNN (pc, IE_LORE), '0') )
441 stats.append ( (19224, GS (IE_RESISTMAGIC), '') )
443 # party's reputation
444 reptxt = GetReputation (GemRB.GameGetReputation ()/10)
445 stats.append ( (9465, reptxt, '') )
446 stats.append ( (9460, GSNN (pc, IE_LOCKPICKING), '') )
447 stats.append ( (9462, GSNN (pc, IE_TRAPS), '') )
448 stats.append ( (9463, GSNN (pc, IE_PICKPOCKET), '') )
449 stats.append ( (9461, GSNN (pc, IE_STEALTH), '') )
450 stats.append ( (34120, GSNN (pc, IE_HIDEINSHADOWS), '') )
451 stats.append ( (34121, GSNN (pc, IE_DETECTILLUSIONS), '') )
452 stats.append ( (34122, GSNN (pc, IE_SETTRAPS), '') )
454 HatedRace = GS (IE_HATEDRACE)
455 if HatedRace:
456 HateTable = GemRB.LoadTable ("haterace")
457 Racist = HateTable.FindValue (1, HatedRace)
458 if Racist != -1:
459 HatedRace = HateTable.GetValue (Racist, 3)
460 stats.append ( (15982, GemRB.GetString (HatedRace), '') )
462 stats.append ( (12128, GS (IE_BACKSTABDAMAGEMULTIPLIER), 'x') )
463 stats.append ( (12126, GS (IE_TURNUNDEADLEVEL), '') )
465 #this hack only displays LOH if we know the spell
466 #TODO: the core should just not set LOH if the paladin can't learn it
467 if (GUICommon.HasSpell (pc, IE_SPELL_TYPE_INNATE, 0, "SPCL211") >= 0):
468 stats.append ( (12127, GS (IE_LAYONHANDSAMOUNT), '') )
470 #script
471 aiscript = GemRB.GetPlayerScript (pc )
472 stats.append ( (2078, aiscript, '') )
473 stats.append (None)
475 # 17379 Saving throws
476 stats.append (17379)
477 # 17380 Paralyze/Poison/Death
478 stats.append ( (17380, IE_SAVEVSDEATH, 's') )
479 # 17381 Rod/Staff/Wand
480 stats.append ( (17381, IE_SAVEVSWANDS, 's') )
481 # 17382 Petrify/Polymorph
482 stats.append ( (17382, IE_SAVEVSPOLY, 's') )
483 # 17383 Breath weapon
484 stats.append ( (17383, IE_SAVEVSBREATH, 's') )
485 # 17384 Spells
486 stats.append ( (17384, IE_SAVEVSSPELL, 's') )
487 stats.append (None)
489 # 9466 Weapon proficiencies
490 stats.append (9466)
491 table = GemRB.LoadTable ("weapprof")
492 RowCount = table.GetRowCount ()
493 for i in range (RowCount):
494 text = table.GetValue (i, 3)
495 stat = table.GetValue (i, 0)
496 stats.append ( (text, GS (stat)&0x07, '+') )
497 stats.append (None)
499 # 11766 AC Bonuses
500 stats.append (11766)
501 # 11770 AC vs. Crushing
502 stats.append ((11770, GS (IE_ACCRUSHINGMOD), ''))
503 # 11767 AC vs. Missile
504 stats.append ((11767, GS (IE_ACMISSILEMOD), ''))
505 # 11769 AC vs. Piercing
506 stats.append ((11769, GS (IE_ACPIERCINGMOD), ''))
507 # 11768 AC vs. Slashing
508 stats.append ((11768, GS (IE_ACSLASHINGMOD), ''))
509 stats.append (None)
511 # 10315 Ability bonuses
512 stats.append (10315)
513 value = GemRB.GetPlayerStat (pc, IE_STR)
514 ex = GemRB.GetPlayerStat (pc, IE_STREXTRA)
515 # 10332 to hit
516 stats.append ( (10332, GemRB.GetAbilityBonus (IE_STR,0,value,ex), '0') )
517 # 10336 damage
518 stats.append ( (10336, GemRB.GetAbilityBonus (IE_STR,1,value,ex), '0') )
519 # 10337 open doors (bend bars lift gates)
520 stats.append ( (10337, GemRB.GetAbilityBonus (IE_STR,2,value,ex), '0') )
521 # 10338 weight allowance
522 stats.append ( (10338, GemRB.GetAbilityBonus (IE_STR,3,value,ex), '0') )
523 # 10339 AC
524 stats.append ( (10339, GA (IE_DEX,2), '0') )
525 # 10340 Missile adjustment
526 stats.append ( (10340, GA (IE_DEX,1), '0') )
527 # 10341 Reaction adjustment
528 stats.append ( (10341, GA (IE_DEX,0), '0') )
529 # 10342 CON HP Bonus/Level
530 stats.append ( (10342, GA (IE_CON,0), 'p') )
531 # 10343 Chance To Learn spell
532 if GemRB.GetMemorizableSpellsCount (pc, IE_SPELL_TYPE_WIZARD, 0, 0)>0:
533 stats.append ( (10343, GA (IE_INT,0), '%' ) )
534 # 10347 Reaction
535 stats.append ( (10347, GA (IE_REPUTATION,0), '0') )
536 stats.append (None)
538 # 10344 Bonus Priest spells
539 if GemRB.GetMemorizableSpellsCount (pc, IE_SPELL_TYPE_PRIEST, 0, 0)>0:
540 stats.append (10344)
541 for level in range (7):
542 GemRB.SetToken ("SPELLLEVEL", str (level+1) )
543 #get the bonus spell count
544 base = GemRB.GetMemorizableSpellsCount (pc, IE_SPELL_TYPE_PRIEST, level, 0)
545 if base:
546 count = GemRB.GetMemorizableSpellsCount (pc, IE_SPELL_TYPE_PRIEST, level)
547 stats.append ( (GemRB.GetString (10345), count-base, 'b') )
548 stats.append (None)
550 # 32204 Resistances
551 stats.append (15544)
552 # 67216 Slashing Attacks
553 stats.append ((11768, GS (IE_RESISTSLASHING), '%'))
554 # 67217 Piercing Attacks
555 stats.append ((11769, GS (IE_RESISTPIERCING), '%'))
556 # 67218 Crushing Attacks
557 stats.append ((11770, GS (IE_RESISTCRUSHING), '%'))
558 # 67219 Missile Attacks
559 stats.append ((11767, GS (IE_RESISTMISSILE), '%'))
560 # Poison
561 stats.append ((14017, GS (IE_RESISTPOISON), '%'))
562 stats.append (None)
564 res = []
565 lines = 0
566 for s in stats:
567 try:
568 strref, val, type = s
569 if val == 0 and type != '0':
570 continue
571 if type == '+': #pluses
572 res.append ("[capital=0]"+GemRB.GetString (strref) + ' '+ '+' * val)
573 elif type == 'p': #a plus prefix if positive
574 if val > 0:
575 res.append ("[capital=0]" + GemRB.GetString (strref) + ' +' + str (val) )
576 else:
577 res.append ("[capital=0]" + GemRB.GetString (strref) + ' ' + str (val) )
578 elif type == 's': #both base and (modified) stat, but only if they differ
579 base = str (GB (val))
580 stat = str (GS (val))
581 if base == stat:
582 res.append ("[capital=0]" + GemRB.GetString (strref) + ': ' + base)
583 else:
584 res.append ("[capital=0]" + GemRB.GetString (strref) + ': ' + base + " (" + stat + ")")
585 elif type == 'x': #x character before value
586 res.append ("[capital=0]"+GemRB.GetString (strref) +': x' + str (val) )
587 elif type == 'a': #value (portrait icon) + string
588 res.append ("[capital=2]"+val+" "+GemRB.GetString (strref))
589 elif type == 'b': #strref is an already resolved string
590 res.append ("[capital=0]"+strref+": "+str (val))
591 elif type == 'c': #normal string
592 res.append ("[capital=0]"+GemRB.GetString (strref))
593 elif type == 'd': #strref is an already resolved string
594 res.append ("[capital=0]"+strref)
595 elif type == '0': #normal value
596 res.append (GemRB.GetString (strref) + ': ' + str (val))
597 else: #normal value + type character, for example percent sign
598 res.append ("[capital=0]"+GemRB.GetString (strref) + ': ' + str (val) + type)
599 lines = 1
600 except:
601 if s != None:
602 res.append ( GemRB.GetString (s) )
603 lines = 0
604 else:
605 if lines:
606 res.append ("")
607 lines = 0
609 return "\n".join (res)
611 def GetReputation (repvalue):
612 table = GemRB.LoadTable ("reptxt")
613 if repvalue>20:
614 repvalue=20
615 txt = GemRB.GetString (table.GetValue (repvalue, 0) )
616 return txt+"("+str (repvalue)+")"
618 def OpenInformationWindow ():
619 global InformationWindow
621 if InformationWindow != None:
622 if BiographyWindow: OpenBiographyWindow ()
624 if InformationWindow:
625 InformationWindow.Unload ()
626 InformationWindow = None
627 GemRB.SetVar ("FloatWindow", -1)
628 return
630 InformationWindow = Window = GemRB.LoadWindow (4)
631 GemRB.SetVar ("FloatWindow", InformationWindow.ID)
633 # Biography
634 Button = Window.GetControl (26)
635 Button.SetText (18003)
636 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, OpenBiographyWindow)
638 # Done
639 Button = Window.GetControl (24)
640 Button.SetText (11973)
641 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, OpenInformationWindow)
643 TotalPartyExp = 0
644 ChapterPartyExp = 0
645 TotalCount = 0
646 ChapterCount = 0
647 for i in range (1, GemRB.GetPartySize () + 1):
648 stat = GemRB.GetPCStats(i)
649 TotalPartyExp = TotalPartyExp + stat['KillsTotalXP']
650 ChapterPartyExp = ChapterPartyExp + stat['KillsChapterXP']
651 TotalCount = TotalCount + stat['KillsTotalCount']
652 ChapterCount = ChapterCount + stat['KillsChapterCount']
654 # These are used to get the stats
655 pc = GemRB.GameGetSelectedPCSingle ()
656 stat = GemRB.GetPCStats (pc)
658 Label = Window.GetControl (0x10000000)
659 Label.SetText (GemRB.GetPlayerName (pc, 1))
660 # class
661 ClassTitle = GUICommon.GetActorClassTitle (pc)
662 Label = Window.GetControl (0x10000018)
663 Label.SetText (ClassTitle)
665 #most powerful vanquished
666 Label = Window.GetControl (0x10000005)
667 #we need getstring, so -1 will translate to empty string
668 Label.SetText (GemRB.GetString (stat['BestKilledName']))
670 # NOTE: currentTime is in seconds, joinTime is in seconds * 15
671 # (script updates???). In each case, there are 60 seconds
672 # in a minute, 24 hours in a day, but ONLY 5 minutes in an hour!!
673 # Hence currentTime (and joinTime after div by 15) has
674 # 7200 secs a day (60 * 5 * 24)
675 currentTime = GemRB.GetGameTime ()
676 joinTime = stat['JoinDate'] - stat['AwayTime']
678 party_time = currentTime - (joinTime / 15)
679 days = party_time / 7200
680 hours = (party_time % 7200) / 300
682 GemRB.SetToken ('GAMEDAYS', str (days))
683 GemRB.SetToken ('HOUR', str (hours))
684 Label = Window.GetControl (0x10000006)
685 #actually it is 16043 <DURATION>, but duration is translated to
686 #16041, hopefully this won't cause problem with international version
687 Label.SetText (16041)
689 #favourite spell
690 Label = Window.GetControl (0x10000007)
691 Label.SetText (stat['FavouriteSpell'])
693 #favourite weapon
694 Label = Window.GetControl (0x10000008)
695 #actually it is 10479 <WEAPONNAME>, but weaponname is translated to
696 #the real weapon name (which we should set using SetToken)
697 #there are other strings like bow+wname/xbow+wname/sling+wname
698 #are they used?
699 Label.SetText (stat['FavouriteWeapon'])
701 #total xp
702 Label = Window.GetControl (0x1000000f)
703 if TotalPartyExp != 0:
704 PartyExp = int ((stat['KillsTotalXP'] * 100) / TotalPartyExp)
705 Label.SetText (str (PartyExp) + '%')
706 else:
707 Label.SetText ("0%")
709 Label = Window.GetControl (0x10000013)
710 if ChapterPartyExp != 0:
711 PartyExp = int ((stat['KillsChapterXP'] * 100) / ChapterPartyExp)
712 Label.SetText (str (PartyExp) + '%')
713 else:
714 Label.SetText ("0%")
716 #total xp
717 Label = Window.GetControl (0x10000010)
718 if TotalCount != 0:
719 PartyExp = int ((stat['KillsTotalCount'] * 100) / TotalCount)
720 Label.SetText (str (PartyExp) + '%')
721 else:
722 Label.SetText ("0%")
724 Label = Window.GetControl (0x10000014)
725 if ChapterCount != 0:
726 PartyExp = int ((stat['KillsChapterCount'] * 100) / ChapterCount)
727 Label.SetText (str (PartyExp) + '%')
728 else:
729 Label.SetText ("0%")
731 Label = Window.GetControl (0x10000011)
732 Label.SetText (str (stat['KillsChapterXP']))
733 Label = Window.GetControl (0x10000015)
734 Label.SetText (str (stat['KillsTotalXP']))
736 #count of kills in chapter/game
737 Label = Window.GetControl (0x10000012)
738 Label.SetText (str (stat['KillsChapterCount']))
739 Label = Window.GetControl (0x10000016)
740 Label.SetText (str (stat['KillsTotalCount']))
742 Window.ShowModal (MODAL_SHADOW_GRAY)
743 return
745 def OpenBiographyWindow ():
746 global BiographyWindow
748 if BiographyWindow != None:
749 if BiographyWindow:
750 BiographyWindow.Unload ()
751 BiographyWindow = None
752 GemRB.SetVar ("FloatWindow", InformationWindow.ID)
754 InformationWindow.ShowModal (MODAL_SHADOW_GRAY)
755 return
757 BiographyWindow = Window = GemRB.LoadWindow (12)
758 GemRB.SetVar ("FloatWindow", BiographyWindow.ID)
760 TextArea = Window.GetControl (0)
761 pc = GemRB.GameGetSelectedPCSingle ()
762 TextArea.SetText (GemRB.GetPlayerString (pc, 63) )
764 # Done
765 Button = Window.GetControl (2)
766 Button.SetText (11973)
767 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, OpenBiographyWindow)
769 Window.ShowModal (MODAL_SHADOW_GRAY)
770 return
772 def OpenExportWindow ():
773 global ExportWindow, NameField, ExportDoneButton
775 ExportWindow = GemRB.LoadWindow (13)
777 TextArea = ExportWindow.GetControl (2)
778 TextArea.SetText (10962)
780 TextArea = ExportWindow.GetControl (0)
781 TextArea.GetCharacters ()
783 ExportDoneButton = ExportWindow.GetControl (4)
784 ExportDoneButton.SetText (11973)
785 ExportDoneButton.SetState (IE_GUI_BUTTON_DISABLED)
787 CancelButton = ExportWindow.GetControl (5)
788 CancelButton.SetText (13727)
789 CancelButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
791 NameField = ExportWindow.GetControl (6)
793 ExportDoneButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, ExportDonePress)
794 CancelButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, ExportCancelPress)
795 NameField.SetEvent (IE_GUI_EDIT_ON_CHANGE, ExportEditChanged)
796 ExportWindow.ShowModal (MODAL_SHADOW_GRAY)
797 NameField.SetStatus (IE_GUI_CONTROL_FOCUSED)
798 return
800 def ExportDonePress():
801 if ExportWindow:
802 ExportWindow.Unload()
803 #save file under name from EditControl
804 return
806 def ExportCancelPress():
807 if ExportWindow:
808 ExportWindow.Unload()
809 return
811 def ExportEditChanged():
812 ExportFileName = NameField.QueryText ()
813 if ExportFileName == "":
814 ExportDoneButton.SetState (IE_GUI_BUTTON_DISABLED)
815 else:
816 ExportDoneButton.SetState (IE_GUI_BUTTON_ENABLED)
817 return
819 def OpenCustomizeWindow ():
820 global CustomizeWindow
821 global PortraitsTable, ScriptsTable, ColorTable
823 pc = GemRB.GameGetSelectedPCSingle ()
824 if GemRB.GetPlayerStat (pc, IE_MC_FLAGS)&MC_EXPORTABLE:
825 Exportable = 1
826 else:
827 Exportable = 0
829 PortraitsTable = GemRB.LoadTable ("PICTURES")
830 ScriptsTable = GemRB.LoadTable ("SCRPDESC")
831 ColorTable = GemRB.LoadTable ("CLOWNCOL")
832 CustomizeWindow = GemRB.LoadWindow (17)
834 PortraitSelectButton = CustomizeWindow.GetControl (0)
835 PortraitSelectButton.SetText (11961)
836 if not Exportable:
837 PortraitSelectButton.SetState (IE_GUI_BUTTON_DISABLED)
839 SoundButton = CustomizeWindow.GetControl (1)
840 SoundButton.SetText (10647)
841 if not Exportable:
842 SoundButton.SetState (IE_GUI_BUTTON_DISABLED)
844 ColorButton = CustomizeWindow.GetControl (2)
845 ColorButton.SetText (10646)
846 if not Exportable:
847 ColorButton.SetState (IE_GUI_BUTTON_DISABLED)
849 ScriptButton = CustomizeWindow.GetControl (3)
850 ScriptButton.SetText (17111)
852 BiographyButton = CustomizeWindow.GetControl (9)
853 BiographyButton.SetText (18003)
854 if not Exportable:
855 BiographyButton.SetState (IE_GUI_BUTTON_DISABLED)
857 TextArea = CustomizeWindow.GetControl (5)
858 TextArea.SetText (11327)
860 CustomizeDoneButton = CustomizeWindow.GetControl (7)
861 CustomizeDoneButton.SetText (11973)
862 CustomizeDoneButton.SetState (IE_GUI_BUTTON_ENABLED)
864 CancelButton = CustomizeWindow.GetControl (8);
865 CancelButton.SetText (13727)
866 CancelButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
868 PortraitSelectButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, OpenPortraitSelectWindow)
869 SoundButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, OpenSoundWindow)
870 ColorButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, OpenColorWindow)
871 ScriptButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, OpenScriptWindow)
872 BiographyButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, OpenBiographyEditWindow)
873 CustomizeDoneButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, CustomizeDonePress)
874 CancelButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, CustomizeCancelPress)
876 CustomizeWindow.ShowModal (MODAL_SHADOW_GRAY)
877 return
879 def CustomizeDonePress ():
880 CloseCustomizeWindow ()
881 UpdateRecordsWindow ()
882 return
884 def CustomizeCancelPress ():
885 CloseCustomizeWindow ()
886 UpdateRecordsWindow ()
887 return
889 def CloseCustomizeWindow ():
890 global CustomizeWindow
892 if CustomizeWindow:
893 CustomizeWindow.Unload ()
894 CustomizeWindow = None
895 return
897 def OpenSoundWindow ():
898 global SubCustomizeWindow
899 global VoiceList
900 global Gender
902 SubCustomizeWindow = GemRB.LoadWindow (20)
904 VoiceList = SubCustomizeWindow.GetControl (5)
905 VoiceList.SetFlags (IE_GUI_TEXTAREA_SELECTABLE)
906 pc = GemRB.GameGetSelectedPCSingle ()
907 Gender = GemRB.GetPlayerStat (pc, IE_SEX, 1)
909 VoiceList.SetVarAssoc ("Selected", 0)
910 RowCount=VoiceList.GetCharSounds()
912 PlayButton = SubCustomizeWindow.GetControl (7)
913 PlayButton.SetText (17318)
915 TextArea = SubCustomizeWindow.GetControl (8)
916 TextArea.SetText (11315)
918 DoneButton = SubCustomizeWindow.GetControl (10)
919 DoneButton.SetText (11973)
920 DoneButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
922 CancelButton = SubCustomizeWindow.GetControl (11)
923 CancelButton.SetText (13727)
924 CancelButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
926 PlayButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, PlaySoundPressed)
927 DoneButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, DoneSoundWindow)
928 CancelButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, CloseSubCustomizeWindow)
930 SubCustomizeWindow.ShowModal (MODAL_SHADOW_GRAY)
931 return
933 def DoneSoundWindow ():
934 pc = GemRB.GameGetSelectedPCSingle ()
935 CharSound = VoiceList.QueryText ()
936 GemRB.SetPlayerSound (pc, CharSound)
938 CloseSubCustomizeWindow ()
939 return
941 #TODO: iwd has a different naming scheme
942 #def PlaySoundPressed():
943 #global CharSoundWindow, SoundIndex, SoundSequence
945 #CharSound = VoiceList.QueryText ()
946 #while (not GemRB.HasResource (CharSound + SoundSequence[SoundIndex], RES_WAV)):
947 #SoundIndex += 1
948 #if SoundIndex >= len(SoundSequence):
949 #SoundIndex = 0
950 #GemRB.PlaySound (CharSound + SoundSequence[SoundIndex], 0, 0, 4)
951 #return
953 def OpenColorWindow ():
954 global SubCustomizeWindow
955 global PortraitWindow
956 global PortraitButton
957 global HairButton, SkinButton, MajorButton, MinorButton
958 global HairColor, SkinColor, MajorColor, MinorColor
960 pc = GemRB.GameGetSelectedPCSingle ()
961 MinorColor = GemRB.GetPlayerStat (pc, IE_MINOR_COLOR)
962 MajorColor = GemRB.GetPlayerStat (pc, IE_MAJOR_COLOR)
963 SkinColor = GemRB.GetPlayerStat (pc, IE_SKIN_COLOR)
964 HairColor = GemRB.GetPlayerStat (pc, IE_HAIR_COLOR)
965 SubCustomizeWindow = GemRB.LoadWindow (21)
967 PortraitButton = SubCustomizeWindow.GetControl (0)
968 PortraitButton.SetFlags (IE_GUI_BUTTON_PICTURE|IE_GUI_BUTTON_NO_IMAGE,OP_SET)
969 PortraitButton.SetState (IE_GUI_BUTTON_LOCKED)
971 HairButton = SubCustomizeWindow.GetControl (3)
972 SkinButton = SubCustomizeWindow.GetControl (4)
973 MajorButton = SubCustomizeWindow.GetControl (5)
974 MinorButton = SubCustomizeWindow.GetControl (6)
976 DoneButton = SubCustomizeWindow.GetControl (12)
977 DoneButton.SetText (11973)
978 DoneButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
980 CancelButton = SubCustomizeWindow.GetControl (13)
981 CancelButton.SetText (13727)
982 CancelButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
984 HairButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, SetHairColor)
985 SkinButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, SetSkinColor)
986 MajorButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, SetMajorColor)
987 MinorButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, SetMinorColor)
988 DoneButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, DoneColorWindow)
989 CancelButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, CloseSubCustomizeWindow)
990 UpdatePaperDoll ()
992 SubCustomizeWindow.ShowModal (MODAL_SHADOW_GRAY)
993 return
995 def DoneColorWindow ():
996 pc = GemRB.GameGetSelectedPCSingle ()
997 GemRB.SetPlayerStat (pc, IE_MINOR_COLOR, MinorColor)
998 GemRB.SetPlayerStat (pc, IE_MAJOR_COLOR, MajorColor)
999 GemRB.SetPlayerStat (pc, IE_SKIN_COLOR, SkinColor)
1000 GemRB.SetPlayerStat (pc, IE_HAIR_COLOR, HairColor)
1001 CloseSubCustomizeWindow ()
1002 return
1004 def UpdatePaperDoll ():
1005 pc = GemRB.GameGetSelectedPCSingle ()
1006 Color1 = GemRB.GetPlayerStat (pc, IE_METAL_COLOR)
1007 MinorButton.SetBAM ("COLGRAD", 0, 0, MinorColor&0xff)
1008 MajorButton.SetBAM ("COLGRAD", 0, 0, MajorColor&0xff)
1009 SkinButton.SetBAM ("COLGRAD", 0, 0, SkinColor&0xff)
1010 Color5 = GemRB.GetPlayerStat (pc, IE_LEATHER_COLOR)
1011 Color6 = GemRB.GetPlayerStat (pc, IE_ARMOR_COLOR)
1012 HairButton.SetBAM ("COLGRAD", 0, 0, HairColor&0xff)
1013 PortraitButton.SetPLT (GUICommon.GetActorPaperDoll (pc),
1014 Color1, MinorColor, MajorColor, SkinColor, Color5, Color6, HairColor, 0, 0)
1015 return
1017 def SetHairColor ():
1018 global ColorIndex, PickedColor
1020 ColorIndex = 0
1021 PickedColor = HairColor
1022 OpenColorPicker ()
1023 return
1025 def SetSkinColor ():
1026 global ColorIndex, PickedColor
1028 ColorIndex = 1
1029 PickedColor = SkinColor
1030 OpenColorPicker ()
1031 return
1033 def SetMinorColor ():
1034 global ColorIndex, PickedColor
1036 ColorIndex = 2
1037 PickedColor = MinorColor
1038 OpenColorPicker ()
1039 return
1041 def SetMajorColor ():
1042 global ColorIndex, PickedColor
1044 ColorIndex = 3
1045 PickedColor = MajorColor
1046 OpenColorPicker ()
1047 return
1049 def OpenColorPicker ():
1050 global SubSubCustomizeWindow
1051 #global Selected
1053 SubSubCustomizeWindow = GemRB.LoadWindow (22)
1055 GemRB.SetVar ("Selected",-1)
1056 for i in range (1,35):
1057 Button = SubSubCustomizeWindow.GetControl (i)
1058 Button.SetState (IE_GUI_BUTTON_DISABLED)
1059 Button.SetFlags (IE_GUI_BUTTON_PICTURE|IE_GUI_BUTTON_RADIOBUTTON,OP_OR)
1061 #Selected = -1
1062 for i in range (34):
1063 MyColor = ColorTable.GetValue (ColorIndex, i)
1064 if MyColor == "*":
1065 break
1066 Button = SubSubCustomizeWindow.GetControl (i+1)
1067 Button.SetBAM("COLGRAD", 2, 0, MyColor)
1068 if PickedColor == MyColor:
1069 GemRB.SetVar ("Selected",i)
1070 #Selected = i
1071 Button.SetState (IE_GUI_BUTTON_ENABLED)
1072 Button.SetVarAssoc("Selected",i)
1073 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, DonePress)
1075 SubSubCustomizeWindow.ShowModal (MODAL_SHADOW_GRAY)
1076 return
1078 def DonePress():
1079 global HairColor, SkinColor, MajorColor, MinorColor
1080 global PickedColor
1082 CloseSubSubCustomizeWindow ()
1083 PickedColor=ColorTable.GetValue (ColorIndex, GemRB.GetVar ("Selected"))
1084 if ColorIndex==0:
1085 HairColor=PickedColor
1086 UpdatePaperDoll ()
1087 return
1088 if ColorIndex==1:
1089 SkinColor=PickedColor
1090 UpdatePaperDoll ()
1091 return
1092 if ColorIndex==2:
1093 MinorColor=PickedColor
1094 UpdatePaperDoll ()
1095 return
1097 MajorColor=PickedColor
1098 UpdatePaperDoll ()
1099 return
1101 def OpenScriptWindow ():
1102 global SubCustomizeWindow
1103 global ScriptTextArea, SelectedTextArea
1105 SubCustomizeWindow = GemRB.LoadWindow (11)
1107 ScriptTextArea = SubCustomizeWindow.GetControl (2)
1108 ScriptTextArea.SetFlags (IE_GUI_TEXTAREA_SELECTABLE)
1109 FillScriptList ()
1110 pc = GemRB.GameGetSelectedPCSingle ()
1111 script = GemRB.GetPlayerScript (pc)
1112 scriptindex = ScriptsTable.GetRowIndex (script)
1113 GemRB.SetVar ("Selected", scriptindex)
1114 ScriptTextArea.SetVarAssoc ("Selected", scriptindex)
1116 SelectedTextArea = SubCustomizeWindow.GetControl (4)
1117 UpdateScriptSelection ()
1119 DoneButton = SubCustomizeWindow.GetControl (5)
1120 DoneButton.SetText (11973)
1121 DoneButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
1123 CancelButton = SubCustomizeWindow.GetControl (6)
1124 CancelButton.SetText (13727)
1125 CancelButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
1127 DoneButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, DoneScriptWindow)
1128 CancelButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, CloseSubCustomizeWindow)
1129 ScriptTextArea.SetEvent (IE_GUI_TEXTAREA_ON_CHANGE, UpdateScriptSelection)
1131 SubCustomizeWindow.ShowModal (MODAL_SHADOW_GRAY)
1132 return
1134 def FillScriptList ():
1135 ScriptTextArea.Clear ()
1136 row = ScriptsTable.GetRowCount ()
1137 for i in range (row):
1138 GemRB.SetToken ("script", ScriptsTable.GetRowName (i) )
1139 title = ScriptsTable.GetValue (i,0)
1140 if title!=-1:
1141 desc = ScriptsTable.GetValue (i,1)
1142 txt = GemRB.GetString (title)
1144 if (desc!=-1):
1145 txt += GemRB.GetString (desc)
1147 ScriptTextArea.Append (txt+"\n", -1)
1149 else:
1150 ScriptTextArea.Append (ScriptsTable.GetRowName (i)+"\n" ,-1)
1152 return
1154 def DoneScriptWindow ():
1155 pc = GemRB.GameGetSelectedPCSingle ()
1156 script = ScriptsTable.GetRowName (GemRB.GetVar ("Selected") )
1157 GemRB.SetPlayerScript (pc, script)
1158 CloseSubCustomizeWindow ()
1159 return
1161 def UpdateScriptSelection():
1162 text = ScriptTextArea.QueryText ()
1163 SelectedTextArea.SetText (text)
1164 return
1166 def OpenBiographyEditWindow ():
1167 global SubCustomizeWindow
1168 global BioStrRef
1169 global TextArea
1171 Changed = 0
1172 pc = GemRB.GameGetSelectedPCSingle ()
1173 BioStrRef = GemRB.GetPlayerString (pc, 74)
1174 if BioStrRef != 33347:
1175 Changed = 1
1177 SubCustomizeWindow = GemRB.LoadWindow (51)
1179 ClearButton = SubCustomizeWindow.GetControl (5)
1180 ClearButton.SetText (34881)
1182 DoneButton = SubCustomizeWindow.GetControl (1)
1183 DoneButton.SetText (11973)
1184 DoneButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
1186 RevertButton = SubCustomizeWindow.GetControl (3)
1187 RevertButton.SetText (2240)
1188 if not Changed:
1189 RevertButton.SetState (IE_GUI_BUTTON_DISABLED)
1191 CancelButton = SubCustomizeWindow.GetControl (2)
1192 CancelButton.SetText (13727)
1193 CancelButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
1195 TextArea = SubCustomizeWindow.GetControl (4)
1196 TextArea.SetBufferLength (65535)
1197 TextArea.SetText (BioStrRef)
1199 ClearButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, ClearBiography)
1200 DoneButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, DoneBiographyWindow)
1201 RevertButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, RevertBiography)
1202 CancelButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, CloseSubCustomizeWindow)
1204 SubCustomizeWindow.ShowModal (MODAL_SHADOW_GRAY)
1205 return
1207 def ClearBiography():
1208 pc = GemRB.GameGetSelectedPCSingle ()
1209 BioStrRef = 62015+pc
1210 #GemRB.CreateString (BioStrRef, "")
1211 TextArea.SetText ("")
1212 return
1214 def DoneBiographyWindow ():
1215 global BioStrRef
1217 #TODO set bio
1218 pc = GemRB.GameGetSelectedPCSingle ()
1219 #pc is 1 based
1220 BioStrRef = 62015+pc
1221 GemRB.CreateString (BioStrRef, TextArea.QueryText())
1222 GemRB.SetPlayerString (pc, 74, BioStrRef)
1223 CloseSubCustomizeWindow ()
1224 return
1226 def RevertBiography():
1227 global BioStrRef
1229 BioStrRef = 33347
1230 TextArea.SetText (33347)
1231 return
1233 def CloseSubCustomizeWindow ():
1234 global SubCustomizeWindow
1236 if SubCustomizeWindow:
1237 SubCustomizeWindow.Unload ()
1238 SubCustomizeWindow = None
1239 return
1241 def CloseSubSubCustomizeWindow ():
1242 global SubSubCustomizeWindow
1244 if SubSubCustomizeWindow:
1245 SubSubCustomizeWindow.Unload ()
1246 SubSubCustomizeWindow = None
1247 return
1249 def OpenPortraitSelectWindow ():
1250 global CharGenWindow, PortraitWindow, PortraitPictureButton
1252 PortraitWindow = GemRB.LoadWindow (18)
1254 PortraitPictureButton = PortraitWindow.GetControl (0)
1255 PortraitPictureButton.SetFlags (IE_GUI_BUTTON_PICTURE|IE_GUI_BUTTON_NO_IMAGE, OP_SET)
1257 PortraitLeftButton = PortraitWindow.GetControl (1)
1258 PortraitLeftButton.SetState (IE_GUI_BUTTON_ENABLED)
1259 PortraitLeftButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, PortraitLeftPress)
1260 PortraitLeftButton.SetFlags (IE_GUI_BUTTON_RADIOBUTTON, OP_OR)
1262 PortraitRightButton = PortraitWindow.GetControl (2)
1263 PortraitRightButton.SetState (IE_GUI_BUTTON_ENABLED)
1264 PortraitRightButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, PortraitRightPress)
1265 PortraitRightButton.SetFlags (IE_GUI_BUTTON_RADIOBUTTON, OP_OR)
1267 PortraitCustomButton = PortraitWindow.GetControl (5)
1268 PortraitCustomButton.SetState (IE_GUI_BUTTON_ENABLED)
1269 PortraitCustomButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, OpenCustomPortraitWindow)
1270 PortraitCustomButton.SetText (17545)
1272 PortraitDoneButton = PortraitWindow.GetControl (3)
1273 PortraitDoneButton.SetState (IE_GUI_BUTTON_ENABLED)
1274 PortraitDoneButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, PortraitDonePress)
1275 PortraitDoneButton.SetText (11973)
1276 PortraitDoneButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
1278 PortraitCancelButton = PortraitWindow.GetControl (4)
1279 PortraitCancelButton.SetState (IE_GUI_BUTTON_ENABLED)
1280 PortraitCancelButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, PortraitCancelPress)
1281 PortraitCancelButton.SetText (13727)
1282 PortraitCancelButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
1284 # get players gender and portrait
1285 Pc = GemRB.GameGetSelectedPCSingle ()
1286 PcGender = GemRB.GetPlayerStat (Pc, IE_SEX)
1287 PcPortrait = GemRB.GetPlayerPortrait(Pc,0)
1289 # initialize and set portrait
1290 Portrait.Init (PcGender)
1291 Portrait.Set (PcPortrait)
1292 PortraitPictureButton.SetPicture (Portrait.Name () + "G")
1294 PortraitWindow.ShowModal (MODAL_SHADOW_GRAY)
1295 return
1297 def PortraitLeftPress ():
1298 global PortraitPictureButton
1300 PortraitPictureButton.SetPicture (Portrait.Previous () + "G")
1302 def PortraitRightPress ():
1303 global PortraitPictureButton
1305 PortraitPictureButton.SetPicture (Portrait.Next () + "G" )
1307 def ClosePortraitSelectWindow ():
1308 global PortraitWindow
1310 if PortraitWindow:
1311 PortraitWindow.Unload ()
1312 PortraitWindow = None
1314 #UpdateRecordsWindow ()
1315 CustomizeWindow.ShowModal (MODAL_SHADOW_GRAY)
1316 return
1318 def PortraitCancelPress ():
1319 ClosePortraitSelectWindow ()
1320 return
1322 def PortraitDonePress ():
1323 pc = GemRB.GameGetSelectedPCSingle ()
1324 GemRB.FillPlayerInfo (pc, Portrait.Name () + "L", Portrait.Name () + "S")
1325 ClosePortraitWindow ()
1326 return
1328 def ClosePortraitWindow ():
1329 global PortraitWindow
1331 if PortraitWindow:
1332 PortraitWindow.Unload ()
1333 PortraitWindow = None
1335 CustomizeWindow.ShowModal (MODAL_SHADOW_GRAY)
1336 return
1338 def OpenCustomPortraitWindow ():
1339 global CustomPortraitWindow
1340 global PortraitList1, PortraitList2
1341 global RowCount1, RowCount2
1343 CustomPortraitWindow = GemRB.LoadWindow (19)
1345 CustomPortraitDoneButton = CustomPortraitWindow.GetControl (10)
1346 CustomPortraitDoneButton.SetState (IE_GUI_BUTTON_DISABLED)
1347 CustomPortraitDoneButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, CustomPortraitDonePress)
1348 CustomPortraitDoneButton.SetText (11973)
1349 CustomPortraitDoneButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
1351 CustomPortraitCancelButton = CustomPortraitWindow.GetControl (11)
1352 CustomPortraitCancelButton.SetState (IE_GUI_BUTTON_ENABLED)
1353 CustomPortraitCancelButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, CloseCustomPortraitWindow)
1354 CustomPortraitCancelButton.SetText (13727)
1355 CustomPortraitCancelButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
1357 # Portrait List Large
1358 PortraitList1 = CustomPortraitWindow.GetControl (2)
1359 RowCount1 = PortraitList1.GetPortraits (0)
1360 PortraitList1.SetEvent (IE_GUI_TEXTAREA_ON_CHANGE, LargeCustomPortrait)
1361 GemRB.SetVar ("Row1", RowCount1)
1362 PortraitList1.SetVarAssoc ("Row1",RowCount1)
1364 # Portrait List Small
1365 PortraitList2 = CustomPortraitWindow.GetControl (3)
1366 RowCount2 = PortraitList2.GetPortraits (1)
1367 PortraitList2.SetEvent (IE_GUI_TEXTAREA_ON_CHANGE, SmallCustomPortrait)
1368 GemRB.SetVar ("Row2", RowCount2)
1369 PortraitList2.SetVarAssoc ("Row2",RowCount2)
1371 CustomPortraitWindow.ShowModal (MODAL_SHADOW_GRAY)
1373 return
1375 def CustomPortraitDonePress ():
1376 pc = GemRB.GameGetSelectedPCSingle ()
1377 GemRB.FillPlayerInfo (pc, PortraitList1.QueryText () , PortraitList2.QueryText ())
1379 CloseCustomPortraitWindow ()
1380 ClosePortraitWindow ()
1381 return
1383 def CloseCustomPortraitWindow ():
1384 global CustomPortraitWindow
1386 if CustomPortraitWindow:
1387 CustomPortraitWindow.ShowModal (MODAL_SHADOW_BLACK)
1388 CustomPortraitWindow.Unload ()
1389 CustomPortraitWindow = None
1391 return
1393 def LargeCustomPortrait():
1394 global PortraitList1
1396 Window = CustomPortraitWindow
1398 Portrait = PortraitList1.QueryText ()
1399 #small hack
1400 if GemRB.GetVar ("Row1") == RowCount1:
1401 return
1403 Label = Window.GetControl (0x10000007)
1404 Label.SetText (Portrait)
1406 Button = Window.GetControl (10)
1407 if Portrait=="":
1408 Portrait = "NOPORTMD"
1409 Button.SetState (IE_GUI_BUTTON_DISABLED)
1410 else:
1411 if PortraitList2.QueryText ()!="":
1412 Button.SetState (IE_GUI_BUTTON_ENABLED)
1414 Button = Window.GetControl (0)
1415 Button.SetPicture (Portrait, "NOPORTMD")
1416 return
1418 def SmallCustomPortrait():
1419 global PortraitList2
1421 Window = CustomPortraitWindow
1423 Portrait = PortraitList2.QueryText ()
1424 #small hack
1425 if GemRB.GetVar ("Row2") == RowCount2:
1426 return
1428 Label = Window.GetControl (0x10000008)
1429 Label.SetText (Portrait)
1431 Button = Window.GetControl (10)
1432 if Portrait=="":
1433 Portrait = "NOPORTSM"
1434 Button.SetState (IE_GUI_BUTTON_DISABLED)
1435 else:
1436 if PortraitList1.QueryText ()!="":
1437 Button.SetState (IE_GUI_BUTTON_ENABLED)
1439 Button = Window.GetControl (1)
1440 Button.SetPicture (Portrait, "NOPORTSM")
1441 return
1444 ###################################################
1445 # End of file GUIREC.py