GUIScript: Rename SetTimedEvent to SetTimedEventByName.
[gemrb.git] / gemrb / GUIScripts / bg1 / GUIREC.py
bloba65ba2a1c5f680e2ffc4590ea23b058bc92c2fef
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 GUICommonWindows
25 from GUIDefines import *
26 from ie_stats import *
27 from ie_restype import *
28 from GUICommon import *
29 from LUCommon import CanLevelUp, GetNextLevelExp
30 from GUICommonWindows import *
31 from GUIWORLD import OpenReformPartyWindow
32 from GUICG19 import NextSound
34 ###################################################
35 RecordsWindow = None
36 InformationWindow = None
37 BiographyWindow = None
38 OptionsWindow = None
39 CustomizeWindow = None
40 OldOptionsWindow = None
41 ExportDoneButton = None
42 ExportFileName = ""
43 PortraitsTable = None
44 ScriptsTable = None
45 ColorTable = None
46 ColorIndex = None
47 ScriptTextArea = None
48 SelectedTextArea = None
50 # the available sounds
51 SoundSequence = [ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', \
52 'm', 's', 't', 'u', 'v', '_', 'x', 'y', 'z', '0', '1', '2', \
53 '3', '4', '5', '6', '7', '8', '9']
54 SoundIndex = 0
56 ###################################################
57 def OpenRecordsWindow ():
58 global RecordsWindow, OptionsWindow
59 global OldOptionsWindow
61 if CloseOtherWindow (OpenRecordsWindow):
62 if InformationWindow: OpenInformationWindow ()
64 if RecordsWindow:
65 RecordsWindow.Unload ()
66 if OptionsWindow:
67 OptionsWindow.Unload ()
68 RecordsWindow = None
69 GemRB.SetVar ("OtherWindow", -1)
70 GameWindow.SetVisible(WINDOW_VISIBLE)
71 GemRB.UnhideGUI ()
72 GUICommonWindows.OptionsWindow = OldOptionsWindow
73 OldOptionsWindow = None
74 SetSelectionChangeHandler (None)
75 return
77 GemRB.HideGUI ()
78 GameWindow.SetVisible(WINDOW_INVISIBLE)
80 GemRB.LoadWindowPack ("GUIREC")
81 RecordsWindow = Window = GemRB.LoadWindow (2)
82 GemRB.SetVar ("OtherWindow", RecordsWindow.ID)
83 # saving the original portrait window
84 OldOptionsWindow = GUICommonWindows.OptionsWindow
85 OptionsWindow = GemRB.LoadWindow (0)
86 SetupMenuWindowControls (OptionsWindow, 0, "OpenRecordsWindow")
87 OptionsWindow.SetFrame ()
89 # dual class
90 Button = Window.GetControl (0)
91 Button.SetText (7174)
92 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "DualClassWindow")
94 # levelup
95 Button = Window.GetControl (37)
96 Button.SetText (7175)
97 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "OpenLevelUpWindow")
99 # information
100 Button = Window.GetControl (1)
101 Button.SetText (11946)
102 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "OpenInformationWindow")
104 # reform party
105 Button = Window.GetControl (51)
106 Button.SetText (16559)
107 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "OpenRecReformPartyWindow")
109 # customize
110 Button = Window.GetControl (50)
111 Button.SetText (10645)
112 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "OpenCustomizeWindow")
114 # export
115 Button = Window.GetControl (36)
116 Button.SetText (13956)
117 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "OpenExportWindow")
119 ## # kit info
120 ## Button = Window.GetControl (52)
121 ## Button.SetText (61265)
122 ## Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "KitInfoWindow")
124 SetSelectionChangeHandler (UpdateRecordsWindow)
125 UpdateRecordsWindow ()
127 OptionsWindow.SetVisible (WINDOW_VISIBLE)
128 Window.SetVisible (WINDOW_VISIBLE)
129 GUICommonWindows.PortraitWindow.SetVisible (WINDOW_VISIBLE)
130 return
132 #original returns to game before continuing...
133 def OpenRecReformPartyWindow ():
134 OpenRecordsWindow ()
135 GemRB.SetTimedEventByName ("OpenReformPartyWindow", 1)
136 return
138 def UpdateRecordsWindow ():
139 global stats_overview, alignment_help
141 Window = RecordsWindow
142 if not RecordsWindow:
143 print "SelectionChange handler points to non existing window\n"
144 return
146 pc = GemRB.GameGetSelectedPCSingle ()
148 # exportable
149 Button = Window.GetControl (36)
150 if GemRB.GetPlayerStat (pc, IE_MC_FLAGS)&MC_EXPORTABLE:
151 Button.SetState (IE_GUI_BUTTON_ENABLED)
152 else:
153 Button.SetState (IE_GUI_BUTTON_DISABLED)
155 # dual-classable
156 Button = Window.GetControl (0)
157 if CanDualClass (pc):
158 Button.SetState (IE_GUI_BUTTON_DISABLED)
159 else:
160 Button.SetState (IE_GUI_BUTTON_ENABLED)
162 # levelup
163 Button = Window.GetControl (37)
164 if CanLevelUp (pc):
165 Button.SetState (IE_GUI_BUTTON_ENABLED)
166 else:
167 Button.SetState (IE_GUI_BUTTON_DISABLED)
169 # name
170 Label = Window.GetControl (0x1000000e)
171 Label.SetText (GemRB.GetPlayerName (pc, 0))
173 # portrait
174 Button = Window.GetControl (2)
175 Button.SetFlags (IE_GUI_BUTTON_NO_IMAGE | IE_GUI_BUTTON_PICTURE, OP_SET)
176 Button.SetState (IE_GUI_BUTTON_LOCKED)
177 Button.SetPicture (GemRB.GetPlayerPortrait (pc,0), "NOPORTLG")
179 # armorclass
180 Label = Window.GetControl (0x10000028)
181 ac = GemRB.GetPlayerStat (pc, IE_ARMORCLASS)
182 ac += GemRB.GetAbilityBonus (IE_DEX, 2, GemRB.GetPlayerStat (pc, IE_DEX) )
183 Label.SetText (str (ac))
184 Label.SetTooltip (17183)
186 # hp now
187 Label = Window.GetControl (0x10000029)
188 Label.SetText (str (GemRB.GetPlayerStat (pc, IE_HITPOINTS)))
189 Label.SetTooltip (17184)
191 # hp max
192 Label = Window.GetControl (0x1000002a)
193 Label.SetText (str (GemRB.GetPlayerStat (pc, IE_MAXHITPOINTS)))
194 Label.SetTooltip (17378)
196 # stats
198 sstr = GemRB.GetPlayerStat (pc, IE_STR)
199 sstrx = GemRB.GetPlayerStat (pc, IE_STREXTRA)
200 cstr = GetStatColor (pc, IE_STR)
201 if sstrx > 0 and sstr==18:
202 sstr = "%d/%02d" %(sstr, sstrx % 100)
203 else:
204 sstr = str (sstr)
206 sint = str (GemRB.GetPlayerStat (pc, IE_INT))
207 cint = GetStatColor (pc, IE_INT)
208 swis = str (GemRB.GetPlayerStat (pc, IE_WIS))
209 cwis = GetStatColor (pc, IE_WIS)
210 sdex = str (GemRB.GetPlayerStat (pc, IE_DEX))
211 cdex = GetStatColor (pc, IE_DEX)
212 scon = str (GemRB.GetPlayerStat (pc, IE_CON))
213 ccon = GetStatColor (pc, IE_CON)
214 schr = str (GemRB.GetPlayerStat (pc, IE_CHR))
215 cchr = GetStatColor (pc, IE_CHR)
217 Label = Window.GetControl (0x1000002f)
218 Label.SetText (sstr)
219 Label.SetTextColor (cstr[0], cstr[1], cstr[2])
221 Label = Window.GetControl (0x10000009)
222 Label.SetText (sdex)
223 Label.SetTextColor (cdex[0], cdex[1], cdex[2])
225 Label = Window.GetControl (0x1000000a)
226 Label.SetText (scon)
227 Label.SetTextColor (ccon[0], ccon[1], ccon[2])
229 Label = Window.GetControl (0x1000000b)
230 Label.SetText (sint)
231 Label.SetTextColor (cint[0], cint[1], cint[2])
233 Label = Window.GetControl (0x1000000c)
234 Label.SetText (swis)
235 Label.SetTextColor (cwis[0], cwis[1], cwis[2])
237 Label = Window.GetControl (0x1000000d)
238 Label.SetText (schr)
239 Label.SetTextColor (cchr[0], cchr[1], cchr[2])
241 # class
242 ClassTitle = GetActorClassTitle (pc)
243 Label = Window.GetControl (0x10000030)
244 Label.SetText (ClassTitle)
246 # race
247 text = RaceTable.GetValue (RaceTable.FindValue (3, GemRB.GetPlayerStat (pc, IE_RACE)) ,
250 Label = Window.GetControl (0x1000000f)
251 Label.SetText (text)
253 Table = GemRB.LoadTable ("aligns")
255 text = Table.GetValue (Table.FindValue ( 3, GemRB.GetPlayerStat (pc, IE_ALIGNMENT) ), 0)
256 Label = Window.GetControl (0x10000010)
257 Label.SetText (text)
259 Label = Window.GetControl (0x10000011)
260 if GemRB.GetPlayerStat (pc, IE_SEX) == 1:
261 Label.SetText (7198)
262 else:
263 Label.SetText (7199)
265 # help, info textarea
266 stats_overview = GetStatOverview (pc)
267 Text = Window.GetControl (45)
268 Text.SetText (stats_overview)
269 #TODO: making window visible/shaded depending on the pc's state
270 Window.SetVisible (WINDOW_VISIBLE)
271 return
273 def GetStatColor (pc, stat):
274 a = GemRB.GetPlayerStat (pc, stat)
275 b = GemRB.GetPlayerStat (pc, stat, 1)
276 if a==b:
277 return (255,255,255)
278 if a<b:
279 return (255,255,0)
280 return (0,255,0)
282 # GemRB.GetPlayerStat wrapper that only returns nonnegative values
283 def GSNN (pc, stat):
284 val = GemRB.GetPlayerStat (pc, stat)
285 if val >= 0:
286 return val
287 else:
288 return 0
290 # LevelDiff is used only from the level up code and holds the level
291 # difference for each class
292 def GetStatOverview (pc, LevelDiff=[0,0,0]):
293 StateTable = GemRB.LoadTable ("statdesc")
295 GS = lambda s, pc=pc: GemRB.GetPlayerStat (pc, s)
296 GA = lambda s, col, pc=pc: GemRB.GetAbilityBonus (s, col, GS (s) )
298 stats = []
299 # class levels
300 # 16480 <CLASS>: Level <LEVEL>
301 # Experience: <EXPERIENCE>
302 # Next Level: <NEXTLEVEL>
304 # collecting tokens for stat overview
305 ClassTitle = GetActorClassTitle (pc)
306 GemRB.SetToken ("CLASS", ClassTitle)
307 Class = GemRB.GetPlayerStat (pc, IE_CLASS)
308 Class = ClassTable.FindValue (5, Class)
309 Class = ClassTable.GetRowName (Class)
310 Dual = IsDualClassed (pc, 1)
311 Multi = IsMultiClassed (pc, 1)
312 XP = GemRB.GetPlayerStat (pc, IE_XP)
313 LevelDrain = GS (IE_LEVELDRAIN)
315 if Multi[0] > 1: # we're multiclassed
316 print "\tMulticlassed"
317 Levels = [GemRB.GetPlayerStat (pc, IE_LEVEL), GemRB.GetPlayerStat (pc, IE_LEVEL2), GemRB.GetPlayerStat (pc, IE_LEVEL3)]
319 stats.append ( (19721,1,'c') )
320 stats.append (None)
321 for i in range (Multi[0]):
322 ClassIndex = ClassTable.FindValue (5, Multi[i+1])
323 ClassTitle = GemRB.GetString (ClassTable.GetValue (ClassIndex, 2))
324 GemRB.SetToken ("CLASS", ClassTitle)
325 Class = ClassTable.GetRowName (ClassIndex)
326 GemRB.SetToken ("LEVEL", str (Levels[i]+LevelDiff[i]-int(LevelDrain/Multi[0])) )
327 GemRB.SetToken ("EXPERIENCE", str (XP/Multi[0]) )
328 if LevelDrain:
329 stats.append ( (GemRB.GetString (19720),1,'d') )
330 stats.append ( (GemRB.GetString (57435),1,'d') ) # LEVEL DRAINED
331 else:
332 GemRB.SetToken ("NEXTLEVEL", GetNextLevelExp (Levels[i]+LevelDiff[i], Class) )
333 stats.append ( (GemRB.GetString (16480),"",'d') )
334 stats.append (None)
335 print "\t\tClass (Level):",Class,"(",Levels[i],")"
337 elif Dual[0] > 0: # dual classed; first show the new class
338 print "\tDual classed"
339 stats.append ( (19722,1,'c') )
340 stats.append (None)
342 Levels = [GemRB.GetPlayerStat (pc, IE_LEVEL), GemRB.GetPlayerStat (pc, IE_LEVEL2), GemRB.GetPlayerStat (pc, IE_LEVEL3)]
344 # the levels are stored in the class order (eg. FIGHTER_MAGE)
345 # the current active class does not matter!
346 if IsDualSwap (pc):
347 Levels = [Levels[1], Levels[0], Levels[2]]
349 Levels[0] += LevelDiff[0]
351 ClassTitle = GemRB.GetString (ClassTable.GetValue (Dual[2], 2))
352 GemRB.SetToken ("CLASS", ClassTitle)
353 GemRB.SetToken ("LEVEL", str (Levels[0]-LevelDrain))
354 Class = ClassTable.GetRowName (Dual[2])
355 XP2 = GemRB.GetPlayerStat (pc, IE_XP)
356 GemRB.SetToken ("EXPERIENCE", str (XP2) )
357 if LevelDrain:
358 stats.append ( (GemRB.GetString (19720),1,'d') )
359 stats.append ( (GemRB.GetString (57435),1,'d') ) # LEVEL DRAINED
360 else:
361 GemRB.SetToken ("NEXTLEVEL", GetNextLevelExp (Levels[0], Class) )
362 stats.append ( (GemRB.GetString (16480),"",'d') )
363 stats.append (None)
364 # the first class (shown second)
365 if Dual[0] == 1:
366 ClassTitle = GemRB.GetString (KitListTable.GetValue (Dual[1], 2))
367 elif Dual[0] == 2:
368 ClassTitle = GemRB.GetString (ClassTable.GetValue (Dual[1], 2))
369 GemRB.SetToken ("CLASS", ClassTitle)
370 GemRB.SetToken ("LEVEL", str (Levels[1]) )
372 # the xp table contains only classes, so we have to determine the base class for kits
373 if Dual[0] == 2:
374 BaseClass = ClassTable.GetRowName (Dual[1])
375 else:
376 BaseClass = GetKitIndex (pc)
377 BaseClass = KitListTable.GetValue (BaseClass, 7)
378 BaseClass = ClassTable.FindValue (5, BaseClass)
379 BaseClass = ClassTable.GetRowName (BaseClass)
380 # the first class' XP is discarded and set to the minimum level
381 # requirement, so if you don't dual class right after a levelup,
382 # the game would eat some of your XP
383 XP1 = NextLevelTable.GetValue (BaseClass, str (Levels[1]))
384 GemRB.SetToken ("EXPERIENCE", str (XP1) )
386 # inactive until the new class SURPASSES the former
387 if Levels[0] <= Levels[1]:
388 # inactive
389 stats.append ( (19719,1,'c') )
390 else:
391 stats.append ( (19720,1,'c') )
392 stats.append (None)
393 else: # single classed
394 print "\tSingle classed"
395 Level = GemRB.GetPlayerStat (pc, IE_LEVEL) + LevelDiff[0]
396 GemRB.SetToken ("LEVEL", str (Level-LevelDrain))
397 GemRB.SetToken ("EXPERIENCE", str (XP) )
398 if LevelDrain:
399 stats.append ( (19720,1,'c') )
400 stats.append ( (57435,1,'c') ) # LEVEL DRAINED
401 else:
402 GemRB.SetToken ("NEXTLEVEL", GetNextLevelExp (Level, Class) )
403 stats.append ( (16480,1,'c') )
404 stats.append (None)
405 print "\t\tClass (Level):",Class,"(",Level,")"
407 # check to see if we have a level diff anywhere
408 if sum (LevelDiff) == 0:
409 effects = GemRB.GetPlayerStates (pc)
410 if len (effects):
411 for c in effects:
412 tmp = StateTable.GetValue (ord(c)-66, 0)
413 stats.append ( (tmp,c,'a') )
414 stats.append (None)
416 stats.append (None)
418 #proficiencies
419 stats.append ( (8442,1,'c') )
421 stats.append ( (9457, str(GS (IE_TOHIT))+" ("+str(GemRB.GetCombatDetails(pc, 0)["ToHit"])+")", '0') )
422 tmp = GS (IE_NUMBEROFATTACKS)
423 if (tmp&1):
424 tmp2 = str (tmp/2) + chr (188)
425 else:
426 tmp2 = str (tmp/2)
427 stats.append ( (9458, tmp2, '') )
428 stats.append ( (9459, GSNN (pc, IE_LORE), '0') )
429 stats.append ( (19224, GS (IE_RESISTMAGIC), '') )
431 # party's reputation
432 reptxt = GetReputation (GemRB.GameGetReputation ()/10)
433 stats.append ( (9465, reptxt, '') )
434 stats.append ( (9460, GSNN (pc, IE_LOCKPICKING), '') )
435 stats.append ( (9462, GSNN (pc, IE_TRAPS), '') )
436 stats.append ( (9463, GSNN (pc, IE_PICKPOCKET), '') )
437 stats.append ( (9461, GSNN (pc, IE_STEALTH), '') )
438 HatedRace = GS (IE_HATEDRACE)
439 if HatedRace:
440 HateTable = GemRB.LoadTable ("haterace")
441 Racist = HateTable.FindValue (1, HatedRace)
442 if Racist != -1:
443 HatedRace = HateTable.GetValue (Racist, 0)
444 stats.append ( (15982, GemRB.GetString (HatedRace), '') )
446 #stats.append ( (34120, GSNN (pc, IE_HIDEINSHADOWS), '') )
447 #stats.append ( (34121, GSNN (pc, IE_DETECTILLUSIONS), '') )
448 #stats.append ( (34122, GSNN (pc, IE_SETTRAPS), '') )
449 stats.append ( (12128, GS (IE_BACKSTABDAMAGEMULTIPLIER), 'x') )
450 stats.append ( (12126, GS (IE_TURNUNDEADLEVEL), '') )
452 #this hack only displays LOH if we know the spell
453 #TODO: the core should just not set LOH if the paladin can't learn it
454 if (HasSpell (pc, IE_SPELL_TYPE_INNATE, 0, "SPCL211") >= 0):
455 stats.append ( (12127, GS (IE_LAYONHANDSAMOUNT), '') )
457 #script
458 aiscript = GemRB.GetPlayerScript (pc )
459 stats.append ( (2078, aiscript, '') )
460 stats.append (None)
462 # 17379 Saving throws
463 stats.append (17379)
464 # 17380 Paralyze/Poison/Death
465 stats.append ( (17380, GS (IE_SAVEVSDEATH), '0') )
466 # 17381 Rod/Staff/Wand
467 stats.append ( (17381, GS (IE_SAVEVSWANDS), '0') )
468 # 17382 Petrify/Polymorph
469 stats.append ( (17382, GS (IE_SAVEVSPOLY), '0') )
470 # 17383 Breath weapon
471 stats.append ( (17383, GS (IE_SAVEVSBREATH), '0') )
472 # 17384 Spells
473 stats.append ( (17384, GS (IE_SAVEVSSPELL), '0') )
474 stats.append (None)
476 # 9466 Weapon proficiencies
477 stats.append (9466)
478 table = GemRB.LoadTable ("weapprof")
479 RowCount = table.GetRowCount ()
480 for i in range (RowCount):
481 text = table.GetValue (i, 1)
482 stat = table.GetValue (i, 0) + IE_PROFICIENCYBASTARDSWORD
483 stats.append ( (text, GS (stat)&0x07, '+') )
484 stats.append (None)
486 # 11766 AC Bonuses
487 stats.append (11766)
488 # 11770 AC vs. Crushing
489 stats.append ((11770, GS (IE_ACCRUSHINGMOD), ''))
490 # 11767 AC vs. Missile
491 stats.append ((11767, GS (IE_ACMISSILEMOD), ''))
492 # 11769 AC vs. Piercing
493 stats.append ((11769, GS (IE_ACPIERCINGMOD), ''))
494 # 11768 AC vs. Slashing
495 stats.append ((11768, GS (IE_ACSLASHINGMOD), ''))
496 stats.append (None)
498 # 10315 Ability bonuses
499 stats.append (10315)
500 value = GemRB.GetPlayerStat (pc, IE_STR)
501 ex = GemRB.GetPlayerStat (pc, IE_STREXTRA)
502 # 10332 to hit
503 stats.append ( (10332, GemRB.GetAbilityBonus (IE_STR,0,value,ex), '0') )
504 # 10336 damage
505 stats.append ( (10336, GemRB.GetAbilityBonus (IE_STR,1,value,ex), '0') )
506 # 10337 open doors (bend bars lift gates)
507 stats.append ( (10337, GemRB.GetAbilityBonus (IE_STR,2,value,ex), '0') )
508 # 10338 weight allowance
509 stats.append ( (10338, GemRB.GetAbilityBonus (IE_STR,3,value,ex), '0') )
510 # 10339 AC
511 stats.append ( (10339, GA (IE_DEX,2), '0') )
512 # 10340 Missile adjustment
513 stats.append ( (10340, GA (IE_DEX,1), '0') )
514 # 10341 Reaction adjustment
515 stats.append ( (10341, GA (IE_DEX,0), '0') )
516 # 10342 CON HP Bonus/Level
517 stats.append ( (10342, GA (IE_CON,0), '0') )
518 # 10343 Chance To Learn spell
519 if GemRB.GetMemorizableSpellsCount (pc, IE_SPELL_TYPE_WIZARD, 0, 0)>0:
520 stats.append ( (10343, GA (IE_INT,0), '%' ) )
521 # 10347 Reaction
522 stats.append ( (10347, GA (IE_REPUTATION,0), '0') )
523 stats.append (None)
525 # 10344 Bonus Priest spells
526 if GemRB.GetMemorizableSpellsCount (pc, IE_SPELL_TYPE_PRIEST, 0, 0)>0:
527 stats.append (10344)
528 for level in range (7):
529 GemRB.SetToken ("SPELLLEVEL", str (level+1) )
530 #get the bonus spell count
531 base = GemRB.GetMemorizableSpellsCount (pc, IE_SPELL_TYPE_PRIEST, level, 0)
532 if base:
533 count = GemRB.GetMemorizableSpellsCount (pc, IE_SPELL_TYPE_PRIEST, level)
534 stats.append ( (GemRB.GetString (10345), count-base, 'b') )
535 stats.append (None)
537 res = []
538 lines = 0
539 for s in stats:
540 try:
541 strref, val, type = s
542 if val == 0 and type != '0':
543 continue
544 if type == '+': #pluses
545 res.append ("[capital=0]"+GemRB.GetString (strref) + ' '+ '+' * val)
546 elif type == 'x': #x character before value
547 res.append ("[capital=0]"+GemRB.GetString (strref) +': x' + str (val) )
548 elif type == 'a': #value (portrait icon) + string
549 res.append ("[capital=2]"+val+" "+GemRB.GetString (strref))
550 elif type == 'b': #strref is an already resolved string
551 res.append ("[capital=0]"+strref+": "+str (val))
552 elif type == 'c': #normal string
553 res.append ("[capital=0]"+GemRB.GetString (strref))
554 elif type == 'd': #strref is an already resolved string
555 res.append ("[capital=0]"+strref)
556 elif type == '0': #normal value
557 res.append (GemRB.GetString (strref) + ': ' + str (val))
558 else: #normal value + type character, for example percent sign
559 res.append ("[capital=0]"+GemRB.GetString (strref) + ': ' + str (val) + type)
560 lines = 1
561 except:
562 if s != None:
563 res.append ( GemRB.GetString (s) )
564 lines = 0
565 else:
566 if lines:
567 res.append ("")
568 lines = 0
570 return "\n".join (res)
572 def GetReputation (repvalue):
573 table = GemRB.LoadTable ("reptxt")
574 if repvalue>20:
575 repvalue=20
576 txt = GemRB.GetString (table.GetValue (repvalue, 0) )
577 return txt+"("+str (repvalue)+")"
579 def OpenInformationWindow ():
580 global InformationWindow
582 if InformationWindow != None:
583 if BiographyWindow: OpenBiographyWindow ()
585 return
587 InformationWindow = Window = GemRB.LoadWindow (4)
589 # Biography
590 Button = Window.GetControl (26)
591 Button.SetText (18003)
592 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "OpenBiographyWindow")
594 # Done
595 Button = Window.GetControl (24)
596 Button.SetText (11973)
597 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "CloseInformationWindow")
599 TotalPartyExp = 0
600 ChapterPartyExp = 0
601 TotalCount = 0
602 ChapterCount = 0
603 for i in range (1, GemRB.GetPartySize () + 1):
604 stat = GemRB.GetPCStats(i)
605 TotalPartyExp = TotalPartyExp + stat['KillsTotalXP']
606 ChapterPartyExp = ChapterPartyExp + stat['KillsChapterXP']
607 TotalCount = TotalCount + stat['KillsTotalCount']
608 ChapterCount = ChapterCount + stat['KillsChapterCount']
610 # These are used to get the stats
611 pc = GemRB.GameGetSelectedPCSingle ()
612 stat = GemRB.GetPCStats (pc)
614 Label = Window.GetControl (0x10000000)
615 Label.SetText (GemRB.GetPlayerName (pc, 1))
616 # class
617 ClassTitle = GetActorClassTitle (pc)
618 Label = Window.GetControl (0x10000018)
619 Label.SetText (ClassTitle)
621 #most powerful vanquished
622 Label = Window.GetControl (0x10000005)
623 #we need getstring, so -1 will translate to empty string
624 Label.SetText (GemRB.GetString (stat['BestKilledName']))
626 # NOTE: currentTime is in seconds, joinTime is in seconds * 15
627 # (script updates???). In each case, there are 60 seconds
628 # in a minute, 24 hours in a day, but ONLY 5 minutes in an hour!!
629 # Hence currentTime (and joinTime after div by 15) has
630 # 7200 secs a day (60 * 5 * 24)
631 currentTime = GemRB.GetGameTime ()
632 joinTime = stat['JoinDate'] - stat['AwayTime']
634 party_time = currentTime - (joinTime / 15)
635 days = party_time / 7200
636 hours = (party_time % 7200) / 300
638 GemRB.SetToken ('GAMEDAYS', str (days))
639 GemRB.SetToken ('HOUR', str (hours))
640 Label = Window.GetControl (0x10000006)
641 #actually it is 16043 <DURATION>, but duration is translated to
642 #16041, hopefully this won't cause problem with international version
643 Label.SetText (16041)
645 #favourite spell
646 Label = Window.GetControl (0x10000007)
647 Label.SetText (stat['FavouriteSpell'])
649 #favourite weapon
650 Label = Window.GetControl (0x10000008)
651 #actually it is 10479 <WEAPONNAME>, but weaponname is translated to
652 #the real weapon name (which we should set using SetToken)
653 #there are other strings like bow+wname/xbow+wname/sling+wname
654 #are they used?
655 Label.SetText (stat['FavouriteWeapon'])
657 #total xp
658 Label = Window.GetControl (0x1000000f)
659 if TotalPartyExp != 0:
660 PartyExp = int ((stat['KillsTotalXP'] * 100) / TotalPartyExp)
661 Label.SetText (str (PartyExp) + '%')
662 else:
663 Label.SetText ("0%")
665 Label = Window.GetControl (0x10000013)
666 if ChapterPartyExp != 0:
667 PartyExp = int ((stat['KillsChapterXP'] * 100) / ChapterPartyExp)
668 Label.SetText (str (PartyExp) + '%')
669 else:
670 Label.SetText ("0%")
672 #total xp
673 Label = Window.GetControl (0x10000010)
674 if TotalCount != 0:
675 PartyExp = int ((stat['KillsTotalCount'] * 100) / TotalCount)
676 Label.SetText (str (PartyExp) + '%')
677 else:
678 Label.SetText ("0%")
680 Label = Window.GetControl (0x10000014)
681 if ChapterCount != 0:
682 PartyExp = int ((stat['KillsChapterCount'] * 100) / ChapterCount)
683 Label.SetText (str (PartyExp) + '%')
684 else:
685 Label.SetText ("0%")
687 Label = Window.GetControl (0x10000011)
688 Label.SetText (str (stat['KillsChapterXP']))
689 Label = Window.GetControl (0x10000015)
690 Label.SetText (str (stat['KillsTotalXP']))
692 #count of kills in chapter/game
693 Label = Window.GetControl (0x10000012)
694 Label.SetText (str (stat['KillsChapterCount']))
695 Label = Window.GetControl (0x10000016)
696 Label.SetText (str (stat['KillsTotalCount']))
698 Window.ShowModal (MODAL_SHADOW_GRAY)
699 return
701 def CloseInformationWindow ():
702 global InformationWindow
704 if InformationWindow:
705 InformationWindow.Unload ()
706 InformationWindow = None
707 OptionsWindow.SetVisible (WINDOW_VISIBLE)
708 RecordsWindow.SetVisible (WINDOW_VISIBLE)
709 GUICommonWindows.PortraitWindow.SetVisible (WINDOW_VISIBLE)
710 return
712 def OpenBiographyWindow ():
713 global BiographyWindow
715 if BiographyWindow != None:
716 return
718 BiographyWindow = Window = GemRB.LoadWindow (12)
719 GemRB.SetVar ("FloatWindow", BiographyWindow.ID)
721 TextArea = Window.GetControl (0)
722 pc = GemRB.GameGetSelectedPCSingle ()
723 TextArea.SetText (GemRB.GetPlayerString (pc, 74) )
725 # Done
726 Button = Window.GetControl (2)
727 Button.SetText (11973)
728 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "CloseBiographyWindow")
730 Window.ShowModal (MODAL_SHADOW_GRAY)
731 return
733 def CloseBiographyWindow ():
734 global BiographyWindow
736 if BiographyWindow:
737 BiographyWindow.Unload ()
738 BiographyWindow = None
739 InformationWindow.SetVisible (WINDOW_VISIBLE)
740 return
742 def OpenExportWindow ():
743 global ExportWindow, NameField, ExportDoneButton
745 ExportWindow = GemRB.LoadWindow (13)
747 TextArea = ExportWindow.GetControl (2)
748 TextArea.SetText (10962)
750 TextArea = ExportWindow.GetControl (0)
751 TextArea.GetCharacters ()
753 ExportDoneButton = ExportWindow.GetControl (4)
754 ExportDoneButton.SetText (11973)
755 ExportDoneButton.SetState (IE_GUI_BUTTON_DISABLED)
757 CancelButton = ExportWindow.GetControl (5)
758 CancelButton.SetText (13727)
759 CancelButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
761 NameField = ExportWindow.GetControl (6)
763 ExportDoneButton.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "ExportDonePress")
764 CancelButton.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "ExportCancelPress")
765 NameField.SetEventByName (IE_GUI_EDIT_ON_CHANGE, "ExportEditChanged")
766 ExportWindow.ShowModal (MODAL_SHADOW_GRAY)
767 NameField.SetStatus (IE_GUI_CONTROL_FOCUSED)
768 return
770 def ExportDonePress():
771 if ExportWindow:
772 ExportWindow.Unload()
773 #save file under name from EditControl
774 return
776 def ExportCancelPress():
777 if ExportWindow:
778 ExportWindow.Unload()
779 return
781 def ExportEditChanged():
782 ExportFileName = NameField.QueryText ()
783 if ExportFileName == "":
784 ExportDoneButton.SetState (IE_GUI_BUTTON_DISABLED)
785 else:
786 ExportDoneButton.SetState (IE_GUI_BUTTON_ENABLED)
787 return
789 def OpenCustomizeWindow ():
790 global CustomizeWindow
791 global PortraitsTable, ScriptsTable, ColorTable
793 pc = GemRB.GameGetSelectedPCSingle ()
794 if GemRB.GetPlayerStat (pc, IE_MC_FLAGS)&MC_EXPORTABLE:
795 Exportable = 1
796 else:
797 Exportable = 0
799 PortraitsTable = GemRB.LoadTable ("PICTURES")
800 ScriptsTable = GemRB.LoadTable ("SCRPDESC")
801 ColorTable = GemRB.LoadTable ("CLOWNCOL")
802 CustomizeWindow = GemRB.LoadWindow (17)
804 PortraitSelectButton = CustomizeWindow.GetControl (0)
805 PortraitSelectButton.SetText (11961)
806 if not Exportable:
807 PortraitSelectButton.SetState (IE_GUI_BUTTON_DISABLED)
809 SoundButton = CustomizeWindow.GetControl (1)
810 SoundButton.SetText (10647)
811 if not Exportable:
812 SoundButton.SetState (IE_GUI_BUTTON_DISABLED)
814 ColorButton = CustomizeWindow.GetControl (2)
815 ColorButton.SetText (10646)
816 if not Exportable:
817 ColorButton.SetState (IE_GUI_BUTTON_DISABLED)
819 ScriptButton = CustomizeWindow.GetControl (3)
820 ScriptButton.SetText (17111)
822 #This button exists only in bg2/iwd, theoretically we could create it here
823 #BiographyButton = CustomizeWindow.GetControl (9)
824 #BiographyButton.SetText (18003)
825 #if not Exportable:
826 # BiographyButton.SetState (IE_GUI_BUTTON_DISABLED)
828 TextArea = CustomizeWindow.GetControl (5)
829 TextArea.SetText (11327)
831 CustomizeDoneButton = CustomizeWindow.GetControl (7)
832 CustomizeDoneButton.SetText (11973)
833 CustomizeDoneButton.SetState (IE_GUI_BUTTON_ENABLED)
835 CancelButton = CustomizeWindow.GetControl (8);
836 CancelButton.SetText (13727)
837 CancelButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
839 PortraitSelectButton.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "OpenPortraitSelectWindow")
840 SoundButton.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "OpenSoundWindow")
841 ColorButton.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "OpenColorWindow")
842 ScriptButton.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "OpenScriptWindow")
843 #BiographyButton.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "OpenBiographyEditWindow")
844 CustomizeDoneButton.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "CustomizeDonePress")
845 CancelButton.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "CustomizeCancelPress")
847 CustomizeWindow.ShowModal (MODAL_SHADOW_GRAY)
848 return
850 def CustomizeDonePress ():
851 CloseCustomizeWindow ()
852 UpdateRecordsWindow ()
853 return
855 def CustomizeCancelPress ():
856 CloseCustomizeWindow ()
857 UpdateRecordsWindow ()
858 return
860 def CloseCustomizeWindow ():
861 global CustomizeWindow
863 if CustomizeWindow:
864 CustomizeWindow.Unload ()
865 CustomizeWindow = None
866 return
868 def OpenPortraitSelectWindow ():
869 global SubCustomizeWindow
870 global PortraitButton
871 global Gender, LastPortrait
873 SubCustomizeWindow = GemRB.LoadWindow (18)
874 pc = GemRB.GameGetSelectedPCSingle ()
875 Gender = GemRB.GetPlayerStat (pc, IE_SEX, 1)
876 PortraitName = GemRB.GetPlayerPortrait (pc, 0)
877 LastPortrait = PortraitsTable.GetRowIndex (PortraitName[0:len(PortraitName)-1])
879 PortraitButton = SubCustomizeWindow.GetControl (0)
880 PortraitButton.SetFlags (IE_GUI_BUTTON_PICTURE|IE_GUI_BUTTON_NO_IMAGE,OP_SET)
881 PortraitButton.SetState (IE_GUI_BUTTON_LOCKED)
883 LeftButton = SubCustomizeWindow.GetControl (1)
884 RightButton = SubCustomizeWindow.GetControl (2)
886 DoneButton = SubCustomizeWindow.GetControl (3)
887 DoneButton.SetText (11973)
888 DoneButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
890 CancelButton = SubCustomizeWindow.GetControl (4)
891 CancelButton.SetText (13727)
892 CancelButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
894 CustomPortraitButton = SubCustomizeWindow.GetControl (5)
895 CustomPortraitButton.SetText (17545)
897 LeftButton.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "PortraitLeftPress")
898 RightButton.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "PortraitRightPress")
899 DoneButton.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "PortraitDonePress")
900 CancelButton.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "CloseSubCustomizeWindow")
901 CustomPortraitButton.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "OpenCustomPortraitWindow")
902 SubCustomizeWindow.ShowModal (MODAL_SHADOW_GRAY)
904 while True:
905 if PortraitsTable.GetValue (LastPortrait, 0) == Gender:
906 UpdatePortrait ()
907 break
908 LastPortrait = LastPortrait + 1
910 return
912 def PortraitDonePress ():
913 pc = GemRB.GameGetSelectedPCSingle ()
914 Name = PortraitsTable.GetRowName (LastPortrait)
915 GemRB.FillPlayerInfo (pc, Name + "L", Name + "S")
916 CloseSubCustomizeWindow ()
917 return
919 def PortraitRightPress():
920 global LastPortrait
922 while True:
923 LastPortrait = LastPortrait + 1
924 if LastPortrait >= PortraitsTable.GetRowCount ():
925 LastPortrait = 0
926 if PortraitsTable.GetValue (LastPortrait, 0) == Gender:
927 UpdatePortrait ()
928 return
930 return
932 def PortraitLeftPress():
933 global LastPortrait
935 while True:
936 LastPortrait = LastPortrait - 1
937 if LastPortrait < 0:
938 LastPortrait = PortraitsTable.GetRowCount ()-1
939 if PortraitsTable.GetValue (LastPortrait, 0) == Gender:
940 UpdatePortrait ()
941 return
943 return
945 def UpdatePortrait ():
946 PortraitName = PortraitsTable.GetRowName (LastPortrait)+"G"
947 PortraitButton.SetPicture (PortraitName, "NOPORTLG")
948 return
950 def OpenCustomPortraitWindow ():
951 global SubSubCustomizeWindow
952 global PortraitList1, PortraitList2
953 global RowCount1, RowCount2
955 SubSubCustomizeWindow = GemRB.LoadWindow (19)
957 SmallPortraitButton = SubSubCustomizeWindow.GetControl (1)
958 SmallPortraitButton.SetFlags (IE_GUI_BUTTON_PICTURE|IE_GUI_BUTTON_NO_IMAGE,OP_SET)
960 LargePortraitButton = SubSubCustomizeWindow.GetControl (0)
961 LargePortraitButton.SetFlags (IE_GUI_BUTTON_PICTURE|IE_GUI_BUTTON_NO_IMAGE,OP_SET)
963 DoneButton = SubSubCustomizeWindow.GetControl (10)
964 DoneButton.SetText (11973)
965 DoneButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
966 DoneButton.SetState (IE_GUI_BUTTON_DISABLED)
968 CancelButton = SubSubCustomizeWindow.GetControl (11)
969 CancelButton.SetText (13727)
970 CancelButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
972 # Portrait List Large
973 PortraitList1 = SubSubCustomizeWindow.GetControl (2)
974 RowCount1 = PortraitList1.GetPortraits (0)
975 PortraitList1.SetEventByName (IE_GUI_TEXTAREA_ON_CHANGE, "LargeCustomPortrait")
976 GemRB.SetVar ("Row1", RowCount1)
977 PortraitList1.SetVarAssoc ("Row1",RowCount1)
979 # Portrait List Small
980 PortraitList2 = SubSubCustomizeWindow.GetControl (3)
981 RowCount2 = PortraitList2.GetPortraits (1)
982 PortraitList2.SetEventByName (IE_GUI_TEXTAREA_ON_CHANGE, "SmallCustomPortrait")
983 GemRB.SetVar ("Row2", RowCount2)
984 PortraitList2.SetVarAssoc ("Row2",RowCount2)
986 DoneButton.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "CustomPortraitDonePress")
987 CancelButton.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "CloseSubSubCustomizeWindow")
989 SubSubCustomizeWindow.ShowModal (MODAL_SHADOW_GRAY)
990 return
992 def CustomPortraitDonePress ():
993 pc = GemRB.GameGetSelectedPCSingle ()
994 GemRB.FillPlayerInfo (pc, PortraitList1.QueryText () , PortraitList2.QueryText ())
996 CloseSubSubCustomizeWindow ()
997 #closing the generic portraits, because we just set a custom one
998 CloseSubCustomizeWindow ()
999 return
1001 def LargeCustomPortrait ():
1002 Window = SubSubCustomizeWindow
1004 Portrait = PortraitList1.QueryText ()
1005 #small hack
1006 if GemRB.GetVar ("Row1") == RowCount1:
1007 return
1009 Label = Window.GetControl (0x10000007)
1010 Label.SetText (Portrait)
1012 Button = Window.GetControl (10)
1013 if Portrait=="":
1014 Portrait = "NOPORTMD"
1015 Button.SetState (IE_GUI_BUTTON_DISABLED)
1016 else:
1017 if PortraitList2.QueryText ()!="":
1018 Button.SetState (IE_GUI_BUTTON_ENABLED)
1020 Button = Window.GetControl (0)
1021 Button.SetPicture (Portrait, "NOPORTMD")
1022 return
1024 def SmallCustomPortrait ():
1025 Window = SubSubCustomizeWindow
1027 Portrait = PortraitList2.QueryText ()
1028 #small hack
1029 if GemRB.GetVar ("Row2") == RowCount2:
1030 return
1032 Label = Window.GetControl (0x10000008)
1033 Label.SetText (Portrait)
1035 Button = Window.GetControl (10)
1036 if Portrait=="":
1037 Portrait = "NOPORTSM"
1038 Button.SetState (IE_GUI_BUTTON_DISABLED)
1039 else:
1040 if PortraitList1.QueryText ()!="":
1041 Button.SetState (IE_GUI_BUTTON_ENABLED)
1043 Button = Window.GetControl (1)
1044 Button.SetPicture (Portrait, "NOPORTSM")
1045 return
1047 def OpenSoundWindow ():
1048 global SubCustomizeWindow
1049 global VoiceList
1050 global Gender
1052 SubCustomizeWindow = GemRB.LoadWindow (20)
1054 VoiceList = SubCustomizeWindow.GetControl (5)
1055 VoiceList.SetFlags (IE_GUI_TEXTAREA_SELECTABLE)
1056 pc = GemRB.GameGetSelectedPCSingle ()
1057 Gender = GemRB.GetPlayerStat (pc, IE_SEX, 1)
1059 VoiceList.SetVarAssoc ("Selected", 0)
1060 RowCount=VoiceList.GetCharSounds()
1062 PlayButton = SubCustomizeWindow.GetControl (7)
1063 PlayButton.SetText (17318)
1065 TextArea = SubCustomizeWindow.GetControl (8)
1066 TextArea.SetText (11315)
1068 DoneButton = SubCustomizeWindow.GetControl (10)
1069 DoneButton.SetText (11973)
1070 DoneButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
1072 CancelButton = SubCustomizeWindow.GetControl (11)
1073 CancelButton.SetText (13727)
1074 CancelButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
1076 PlayButton.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "PlaySoundPressed")
1077 DoneButton.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "DoneSoundWindow")
1078 CancelButton.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "CloseSubCustomizeWindow")
1080 SubCustomizeWindow.ShowModal (MODAL_SHADOW_GRAY)
1081 return
1083 def DoneSoundWindow ():
1084 pc = GemRB.GameGetSelectedPCSingle ()
1085 CharSound = VoiceList.QueryText ()
1086 GemRB.SetPlayerSound (pc, CharSound)
1088 CloseSubCustomizeWindow ()
1089 return
1091 def PlaySoundPressed():
1092 global CharSoundWindow, SoundIndex, SoundSequence
1094 CharSound = VoiceList.QueryText ()
1095 while (not GemRB.HasResource (CharSound + SoundSequence[SoundIndex], RES_WAV)):
1096 NextSound()
1097 GemRB.PlaySound (CharSound + SoundSequence[SoundIndex], 0, 0, 4)
1098 return
1100 def OpenColorWindow ():
1101 global SubCustomizeWindow
1102 global PortraitWindow
1103 global PortraitButton
1104 global HairButton, SkinButton, MajorButton, MinorButton
1105 global HairColor, SkinColor, MajorColor, MinorColor
1107 pc = GemRB.GameGetSelectedPCSingle ()
1108 MinorColor = GemRB.GetPlayerStat (pc, IE_MINOR_COLOR)
1109 MajorColor = GemRB.GetPlayerStat (pc, IE_MAJOR_COLOR)
1110 SkinColor = GemRB.GetPlayerStat (pc, IE_SKIN_COLOR)
1111 HairColor = GemRB.GetPlayerStat (pc, IE_HAIR_COLOR)
1112 SubCustomizeWindow = GemRB.LoadWindow (21)
1114 PortraitButton = SubCustomizeWindow.GetControl (0)
1115 PortraitButton.SetFlags (IE_GUI_BUTTON_PICTURE|IE_GUI_BUTTON_NO_IMAGE,OP_SET)
1116 PortraitButton.SetState (IE_GUI_BUTTON_LOCKED)
1118 HairButton = SubCustomizeWindow.GetControl (3)
1119 SkinButton = SubCustomizeWindow.GetControl (4)
1120 MajorButton = SubCustomizeWindow.GetControl (5)
1121 MinorButton = SubCustomizeWindow.GetControl (6)
1123 DoneButton = SubCustomizeWindow.GetControl (12)
1124 DoneButton.SetText (11973)
1125 DoneButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
1127 CancelButton = SubCustomizeWindow.GetControl (13)
1128 CancelButton.SetText (13727)
1129 CancelButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
1131 HairButton.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "SetHairColor")
1132 SkinButton.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "SetSkinColor")
1133 MajorButton.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "SetMajorColor")
1134 MinorButton.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "SetMinorColor")
1135 DoneButton.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "DoneColorWindow")
1136 CancelButton.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "CloseSubCustomizeWindow")
1137 UpdatePaperDoll ()
1139 SubCustomizeWindow.ShowModal (MODAL_SHADOW_GRAY)
1140 return
1142 def DoneColorWindow ():
1143 pc = GemRB.GameGetSelectedPCSingle ()
1144 GemRB.SetPlayerStat (pc, IE_MINOR_COLOR, MinorColor)
1145 GemRB.SetPlayerStat (pc, IE_MAJOR_COLOR, MajorColor)
1146 GemRB.SetPlayerStat (pc, IE_SKIN_COLOR, SkinColor)
1147 GemRB.SetPlayerStat (pc, IE_HAIR_COLOR, HairColor)
1148 CloseSubCustomizeWindow ()
1149 return
1151 def UpdatePaperDoll ():
1152 pc = GemRB.GameGetSelectedPCSingle ()
1153 Color1 = GemRB.GetPlayerStat (pc, IE_METAL_COLOR)
1154 MinorButton.SetBAM ("COLGRAD", 0, 0, MinorColor&0xff)
1155 MajorButton.SetBAM ("COLGRAD", 0, 0, MajorColor&0xff)
1156 SkinButton.SetBAM ("COLGRAD", 0, 0, SkinColor&0xff)
1157 Color5 = GemRB.GetPlayerStat (pc, IE_LEATHER_COLOR)
1158 Color6 = GemRB.GetPlayerStat (pc, IE_ARMOR_COLOR)
1159 HairButton.SetBAM ("COLGRAD", 0, 0, HairColor&0xff)
1160 PortraitButton.SetPLT (GetActorPaperDoll (pc),
1161 Color1, MinorColor, MajorColor, SkinColor, Color5, Color6, HairColor, 0, 0)
1162 return
1164 def SetHairColor ():
1165 global ColorIndex, PickedColor
1167 ColorIndex = 0
1168 PickedColor = HairColor
1169 OpenColorPicker ()
1170 return
1172 def SetSkinColor ():
1173 global ColorIndex, PickedColor
1175 ColorIndex = 1
1176 PickedColor = SkinColor
1177 OpenColorPicker ()
1178 return
1180 def SetMinorColor ():
1181 global ColorIndex, PickedColor
1183 ColorIndex = 2
1184 PickedColor = MinorColor
1185 OpenColorPicker ()
1186 return
1188 def SetMajorColor ():
1189 global ColorIndex, PickedColor
1191 ColorIndex = 3
1192 PickedColor = MajorColor
1193 OpenColorPicker ()
1194 return
1196 def OpenColorPicker ():
1197 global SubSubCustomizeWindow
1198 #global Selected
1200 SubSubCustomizeWindow = GemRB.LoadWindow (22)
1202 GemRB.SetVar ("Selected",-1)
1203 for i in range (1,35):
1204 Button = SubSubCustomizeWindow.GetControl (i)
1205 Button.SetState (IE_GUI_BUTTON_DISABLED)
1206 Button.SetFlags (IE_GUI_BUTTON_PICTURE|IE_GUI_BUTTON_RADIOBUTTON,OP_OR)
1208 #Selected = -1
1209 for i in range (34):
1210 MyColor = ColorTable.GetValue (ColorIndex, i)
1211 if MyColor == "*":
1212 break
1213 Button = SubSubCustomizeWindow.GetControl (i+1)
1214 Button.SetBAM("COLGRAD", 2, 0, MyColor)
1215 if PickedColor == MyColor:
1216 GemRB.SetVar ("Selected",i)
1217 #Selected = i
1218 Button.SetState (IE_GUI_BUTTON_ENABLED)
1219 Button.SetVarAssoc("Selected",i)
1220 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "DonePress")
1222 SubSubCustomizeWindow.ShowModal (MODAL_SHADOW_GRAY)
1223 return
1225 def DonePress():
1226 global HairColor, SkinColor, MajorColor, MinorColor
1227 global PickedColor
1229 CloseSubSubCustomizeWindow ()
1230 PickedColor=ColorTable.GetValue (ColorIndex, GemRB.GetVar ("Selected"))
1231 if ColorIndex==0:
1232 HairColor=PickedColor
1233 UpdatePaperDoll ()
1234 return
1235 if ColorIndex==1:
1236 SkinColor=PickedColor
1237 UpdatePaperDoll ()
1238 return
1239 if ColorIndex==2:
1240 MinorColor=PickedColor
1241 UpdatePaperDoll ()
1242 return
1244 MajorColor=PickedColor
1245 UpdatePaperDoll ()
1246 return
1248 def OpenScriptWindow ():
1249 global SubCustomizeWindow
1250 global ScriptTextArea, SelectedTextArea
1252 SubCustomizeWindow = GemRB.LoadWindow (11)
1254 ScriptTextArea = SubCustomizeWindow.GetControl (2)
1255 ScriptTextArea.SetFlags (IE_GUI_TEXTAREA_SELECTABLE)
1256 FillScriptList ()
1257 pc = GemRB.GameGetSelectedPCSingle ()
1258 script = GemRB.GetPlayerScript (pc)
1259 scriptindex = ScriptsTable.GetRowIndex (script)
1260 GemRB.SetVar ("Selected", scriptindex)
1261 ScriptTextArea.SetVarAssoc ("Selected", scriptindex)
1263 SelectedTextArea = SubCustomizeWindow.GetControl (4)
1264 UpdateScriptSelection ()
1266 DoneButton = SubCustomizeWindow.GetControl (5)
1267 DoneButton.SetText (11973)
1268 DoneButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
1270 CancelButton = SubCustomizeWindow.GetControl (6)
1271 CancelButton.SetText (13727)
1272 CancelButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
1274 DoneButton.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "DoneScriptWindow")
1275 CancelButton.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "CloseSubCustomizeWindow")
1276 ScriptTextArea.SetEventByName (IE_GUI_TEXTAREA_ON_CHANGE, "UpdateScriptSelection")
1278 SubCustomizeWindow.ShowModal (MODAL_SHADOW_GRAY)
1279 return
1281 def FillScriptList ():
1282 ScriptTextArea.Clear ()
1283 row = ScriptsTable.GetRowCount ()
1284 for i in range (row):
1285 GemRB.SetToken ("script", ScriptsTable.GetRowName (i) )
1286 title = ScriptsTable.GetValue (i,0)
1287 if title!=-1:
1288 desc = ScriptsTable.GetValue (i,1)
1289 txt = GemRB.GetString (title)
1291 if (desc!=-1):
1292 txt += GemRB.GetString (desc)
1294 ScriptTextArea.Append (txt+"\n", -1)
1296 else:
1297 ScriptTextArea.Append (ScriptsTable.GetRowName (i)+"\n" ,-1)
1299 return
1301 def DoneScriptWindow ():
1302 pc = GemRB.GameGetSelectedPCSingle ()
1303 script = ScriptsTable.GetRowName (GemRB.GetVar ("Selected") )
1304 GemRB.SetPlayerScript (pc, script)
1305 CloseSubCustomizeWindow ()
1306 return
1308 def UpdateScriptSelection():
1309 text = ScriptTextArea.QueryText ()
1310 SelectedTextArea.SetText (text)
1311 return
1313 def OpenBiographyEditWindow ():
1314 global SubCustomizeWindow
1315 global BioStrRef
1316 global TextArea
1318 Changed = 0
1319 pc = GemRB.GameGetSelectedPCSingle ()
1320 BioStrRef = GemRB.GetPlayerString (pc, 74)
1321 if BioStrRef != 33347:
1322 Changed = 1
1324 SubCustomizeWindow = GemRB.LoadWindow (23)
1326 ClearButton = SubCustomizeWindow.GetControl (5)
1327 ClearButton.SetText (34881)
1329 DoneButton = SubCustomizeWindow.GetControl (1)
1330 DoneButton.SetText (11973)
1331 DoneButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
1333 RevertButton = SubCustomizeWindow.GetControl (3)
1334 RevertButton.SetText (2240)
1335 if not Changed:
1336 RevertButton.SetState (IE_GUI_BUTTON_DISABLED)
1338 CancelButton = SubCustomizeWindow.GetControl (2)
1339 CancelButton.SetText (13727)
1340 CancelButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
1342 TextArea = SubCustomizeWindow.GetControl (4)
1343 TextArea.SetBufferLength (65535)
1344 TextArea.SetText (BioStrRef)
1346 ClearButton.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "ClearBiography")
1347 DoneButton.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "DoneBiographyWindow")
1348 RevertButton.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "RevertBiography")
1349 CancelButton.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "CloseSubCustomizeWindow")
1351 SubCustomizeWindow.ShowModal (MODAL_SHADOW_GRAY)
1352 return
1354 def ClearBiography():
1355 pc = GemRB.GameGetSelectedPCSingle ()
1356 BioStrRef = 62015+pc
1357 #GemRB.CreateString (BioStrRef, "")
1358 TextArea.SetText ("")
1359 return
1361 def DoneBiographyWindow ():
1362 global BioStrRef
1364 #TODO set bio
1365 pc = GemRB.GameGetSelectedPCSingle ()
1366 #pc is 1 based
1367 BioStrRef = 62015+pc
1368 GemRB.CreateString (BioStrRef, TextArea.QueryText())
1369 GemRB.SetPlayerString (pc, 74, BioStrRef)
1370 CloseSubCustomizeWindow ()
1371 return
1373 def RevertBiography():
1374 global BioStrRef
1376 BioStrRef = 33347
1377 TextArea.SetText (33347)
1378 return
1380 def CloseSubCustomizeWindow ():
1381 global SubCustomizeWindow
1383 if SubCustomizeWindow:
1384 SubCustomizeWindow.Unload ()
1385 SubCustomizeWindow = None
1386 return
1388 def CloseSubSubCustomizeWindow ():
1389 global SubSubCustomizeWindow
1391 if SubSubCustomizeWindow:
1392 SubSubCustomizeWindow.Unload ()
1393 SubSubCustomizeWindow = None
1394 return
1396 ###################################################
1397 # End of file GUIREC.py