fixed the rest of the functions that needed globalid capabilities
[gemrb.git] / gemrb / GUIScripts / bg2 / GUIMG.py
blobf380ed86704abeb9ba9a8d960421bcbba87a36bb
1 # -*-python-*-
2 # GemRB - Infinity Engine Emulator
3 # Copyright (C) 2003-2004 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 # GUIMG.py - scripts to control mage spells windows from the GUIMG winpack
23 ###################################################
25 import GemRB
26 from GUIDefines import *
27 from ie_stats import *
28 import GUICommon
29 import CommonTables
30 from ie_spells import LS_MEMO
32 MageWindow = None
33 MageSpellInfoWindow = None
34 MageSpellLevel = 0
35 MageSpellUnmemorizeWindow = None
36 PortraitWindow = None
37 OptionsWindow = None
38 OldPortraitWindow = None
39 OldOptionsWindow = None
40 BookType = None
41 OtherWindow = None
42 Exclusions = None
43 ContCond = None
44 ContTarg = None
45 SpellType = None
46 Level = 1
48 def OpenMageWindow ():
49 import GUICommonWindows
50 global MageWindow, OptionsWindow, PortraitWindow
51 global OldPortraitWindow, OldOptionsWindow
53 if GUICommon.CloseOtherWindow (OpenMageWindow):
54 if MageWindow:
55 MageWindow.Unload ()
56 if OptionsWindow:
57 OptionsWindow.Unload ()
58 if PortraitWindow:
59 PortraitWindow.Unload ()
61 MageWindow = None
62 GemRB.SetVar ("OtherWindow", -1)
63 GUICommon.GameWindow.SetVisible(WINDOW_VISIBLE)
64 GemRB.UnhideGUI ()
65 GUICommonWindows.PortraitWindow = OldPortraitWindow
66 OldPortraitWindow = None
67 GUICommonWindows.OptionsWindow = OldOptionsWindow
68 OldOptionsWindow = None
69 GUICommonWindows.SetSelectionChangeHandler (None)
70 return
72 GemRB.HideGUI ()
73 GUICommon.GameWindow.SetVisible(WINDOW_INVISIBLE)
75 GemRB.LoadWindowPack ("GUIMG", 640, 480)
77 #saving the original portrait window
78 OldOptionsWindow = GUICommonWindows.OptionsWindow
79 OptionsWindow = GemRB.LoadWindow (0)
80 GUICommonWindows.MarkMenuButton (OptionsWindow)
81 GUICommonWindows.SetupMenuWindowControls (OptionsWindow, 0, OpenMageWindow)
82 OptionsWindow.SetFrame ()
83 OldPortraitWindow = GUICommonWindows.PortraitWindow
85 PortraitWindow = GUICommonWindows.OpenPortraitWindow (0)
86 SetupMageWindow()
87 GUICommonWindows.SetSelectionChangeHandler (SetupMageWindow)
88 return
90 def SetupMageWindow ():
91 global MageWindow
92 global BookType
94 pc = GemRB.GameGetSelectedPCSingle ()
95 BookType = 0
96 if (CommonTables.ClassSkills.GetValue (GemRB.GetPlayerStat (pc, IE_CLASS), 8)==2):
97 BookType = 1
99 if MageWindow:
100 MageWindow.Unload()
101 MageWindow = None
103 if BookType:
104 MageWindow = Window = GemRB.LoadWindow (8)
105 else:
106 MageWindow = Window = GemRB.LoadWindow (2)
107 GemRB.SetVar ("OtherWindow", MageWindow.ID)
109 Button = Window.GetControl (1)
110 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, MagePrevLevelPress)
112 Button = Window.GetControl (2)
113 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, MageNextLevelPress)
115 #unknown usage
116 Button = Window.GetControl (55)
117 Button.SetState (IE_GUI_BUTTON_LOCKED)
119 #setup level buttons
120 for i in range (9):
121 Button = Window.GetControl (56 + i)
122 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, RefreshMageLevel)
123 Button.SetFlags (IE_GUI_BUTTON_RADIOBUTTON, OP_OR)
125 for i in range (9):
126 Button = Window.GetControl (56 + i)
127 Button.SetVarAssoc ("MageSpellLevel", i)
129 # Setup memorized spells buttons
130 if not BookType:
131 for i in range (12):
132 Button = Window.GetControl (3 + i)
133 Button.SetBorder (0,0,0,0,0,0,0,0,64,0,1)
134 Button.SetSprites ("SPELFRAM",0,0,0,0,0)
135 Button.SetFlags (IE_GUI_BUTTON_PICTURE, OP_OR)
136 Button.SetState (IE_GUI_BUTTON_LOCKED)
138 # Setup book spells buttons
139 for i in range (24):
140 Button = Window.GetControl (27 + i)
141 Button.SetFlags (IE_GUI_BUTTON_NO_IMAGE, OP_OR)
142 Button.SetState (IE_GUI_BUTTON_LOCKED)
144 UpdateMageWindow ()
145 OptionsWindow.SetVisible (WINDOW_VISIBLE)
146 #bringing the window front
147 Window.SetVisible (WINDOW_FRONT)
148 PortraitWindow.SetVisible (WINDOW_VISIBLE)
149 return
151 def UpdateMageWindow ():
152 global MageMemorizedSpellList, MageKnownSpellList
154 MageMemorizedSpellList = []
155 MageKnownSpellList = []
157 Window = MageWindow
158 pc = GemRB.GameGetSelectedPCSingle ()
159 type = IE_SPELL_TYPE_WIZARD
160 level = MageSpellLevel
161 max_mem_cnt = GemRB.GetMemorizableSpellsCount (pc, type, level, 1)
163 Label = Window.GetControl (0x10000032)
164 GemRB.SetToken("SPELLLEVEL", str(level+1) )
165 Label.SetText (10345)
167 Name = GemRB.GetPlayerName (pc, 0)
168 Label = Window.GetControl (0x10000035)
169 Label.SetText (Name)
171 known_cnt = GemRB.GetKnownSpellsCount (pc, type, level)
172 mem_cnt = GemRB.GetMemorizedSpellsCount (pc, type, level)
173 if not BookType:
174 for i in range (12):
175 Button = Window.GetControl (3 + i)
176 if i < mem_cnt:
177 ms = GemRB.GetMemorizedSpell (pc, type, level, i)
178 Button.SetSpellIcon (ms['SpellResRef'], 0)
179 Button.SetFlags (IE_GUI_BUTTON_NO_IMAGE, OP_NAND)
180 Button.SetFlags (IE_GUI_BUTTON_PICTURE, OP_OR)
181 if ms['Flags']:
182 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, OpenMageSpellUnmemorizeWindow)
183 else:
184 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, OnMageUnmemorizeSpell)
185 Button.SetEvent (IE_GUI_BUTTON_ON_RIGHT_PRESS, OpenMageSpellInfoWindow)
186 spell = GemRB.GetSpell (ms['SpellResRef'])
187 Button.SetTooltip (spell['SpellName'])
188 MageMemorizedSpellList.append (ms['SpellResRef'])
189 Button.SetVarAssoc ("SpellButton", i)
190 Button.EnableBorder (0, ms['Flags'] == 0)
191 else:
192 if i < max_mem_cnt:
193 Button.SetFlags (IE_GUI_BUTTON_NORMAL, OP_SET)
194 else:
195 Button.SetFlags (IE_GUI_BUTTON_NO_IMAGE, OP_SET)
196 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, None)
197 Button.SetEvent (IE_GUI_BUTTON_ON_RIGHT_PRESS, None)
198 Button.SetTooltip ('')
199 Button.EnableBorder (0, 0)
200 else:
201 label = Window.GetControl (0x10000040)
202 if known_cnt:
203 # we give sorcerers all charges for all the spells, so some extra math is needed
204 label.SetText (GemRB.GetString(61256) + " " + str(mem_cnt/known_cnt) + "/" + str(max_mem_cnt))
205 else:
206 label.SetText ("")
208 for i in range (24):
209 Button = Window.GetControl (27 + i)
210 if i < known_cnt:
211 ks = GemRB.GetKnownSpell (pc, type, level, i)
212 Button.SetSpellIcon (ks['SpellResRef'], 0)
213 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, OnMageMemorizeSpell)
214 Button.SetEvent (IE_GUI_BUTTON_ON_RIGHT_PRESS, OpenMageSpellInfoWindow)
215 spell = GemRB.GetSpell (ks['SpellResRef'])
216 Button.SetTooltip (spell['SpellName'])
217 MageKnownSpellList.append (ks['SpellResRef'])
218 Button.SetVarAssoc ("SpellButton", 100 + i)
220 else:
221 Button.SetFlags (IE_GUI_BUTTON_PICTURE, OP_NAND)
222 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, None)
223 Button.SetEvent (IE_GUI_BUTTON_ON_RIGHT_PRESS, None)
224 Button.SetTooltip ('')
225 Button.EnableBorder (0, 0)
227 if (CommonTables.ClassSkills.GetValue (GemRB.GetPlayerStat (pc, IE_CLASS), 2)=="*") or \
228 GemRB.GetPlayerStat (pc, IE_STATE_ID) & STATE_DEAD:
229 Window.SetVisible (WINDOW_GRAYED)
230 else:
231 Window.SetVisible (WINDOW_VISIBLE)
232 return
234 def MagePrevLevelPress ():
235 global MageSpellLevel
237 if MageSpellLevel > 0:
238 MageSpellLevel = MageSpellLevel - 1
239 UpdateMageWindow ()
240 return
242 def MageNextLevelPress ():
243 global MageSpellLevel
245 if MageSpellLevel < 8:
246 MageSpellLevel = MageSpellLevel + 1
247 UpdateMageWindow ()
248 return
250 def RefreshMageLevel ():
251 global MageSpellLevel
253 MageSpellLevel = GemRB.GetVar ("MageSpellLevel")
254 UpdateMageWindow ()
255 return
257 def OpenMageSpellInfoWindow ():
258 global MageSpellInfoWindow
260 if MageSpellInfoWindow != None:
261 if MageSpellInfoWindow:
262 MageSpellInfoWindow.Unload ()
263 MageSpellInfoWindow = None
264 return
266 MageSpellInfoWindow = Window = GemRB.LoadWindow (3)
268 #back
269 Button = Window.GetControl (5)
270 Button.SetText (15416)
271 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, OpenMageSpellInfoWindow)
273 #erase
274 index = GemRB.GetVar ("SpellButton")
275 if GUICommon.HasTOB():
276 Button = Window.GetControl (6)
277 if index < 100:
278 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, None)
279 Button.SetFlags (IE_GUI_BUTTON_NO_IMAGE, OP_SET)
280 else:
281 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, OpenMageSpellRemoveWindow)
282 Button.SetText (63668)
283 if index < 100:
284 ResRef = MageMemorizedSpellList[index]
285 else:
286 ResRef = MageKnownSpellList[index - 100]
288 spell = GemRB.GetSpell (ResRef)
290 Label = Window.GetControl (0x0fffffff)
291 Label.SetText (spell['SpellName'])
293 Button = Window.GetControl (2)
294 Button.SetSpellIcon (ResRef, 1)
296 Text = Window.GetControl (3)
297 Text.SetText (spell['SpellDesc'])
299 Window.ShowModal (MODAL_SHADOW_GRAY)
300 return
302 def OnMageMemorizeSpell ():
303 pc = GemRB.GameGetSelectedPCSingle ()
304 level = MageSpellLevel
305 type = IE_SPELL_TYPE_WIZARD
307 index = GemRB.GetVar ("SpellButton") - 100
309 if GemRB.MemorizeSpell (pc, type, level, index):
310 UpdateMageWindow ()
311 return
313 def CloseMageSpellUnmemorizeWindow ():
314 global MageSpellUnmemorizeWindow
316 if MageSpellUnmemorizeWindow:
317 MageSpellUnmemorizeWindow.Unload ()
318 MageSpellUnmemorizeWindow = None
319 return
321 def OpenMageSpellRemoveWindow ():
322 global MageSpellUnmemorizeWindow
324 MageSpellUnmemorizeWindow = Window = GemRB.LoadWindow (101)
326 # "Are you sure you want to ....?"
327 TextArea = Window.GetControl (3)
328 TextArea.SetText (63745)
330 # Remove
331 Button = Window.GetControl (0)
332 Button.SetText (17507)
333 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, OnMageRemoveSpell)
334 Button.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
336 # Cancel
337 Button = Window.GetControl (1)
338 Button.SetText (13727)
339 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, CloseMageSpellUnmemorizeWindow)
340 Button.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
342 Window.ShowModal (MODAL_SHADOW_GRAY)
343 return
345 def OpenMageSpellUnmemorizeWindow ():
346 global MageSpellUnmemorizeWindow
348 MageSpellUnmemorizeWindow = Window = GemRB.LoadWindow (101)
350 # "Are you sure you want to ....?"
351 TextArea = Window.GetControl (3)
352 TextArea.SetText (11824)
354 # Remove
355 Button = Window.GetControl (0)
356 Button.SetText (17507)
357 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, OnMageUnmemorizeSpell)
358 Button.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
360 # Cancel
361 Button = Window.GetControl (1)
362 Button.SetText (13727)
363 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, CloseMageSpellUnmemorizeWindow)
364 Button.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
366 Window.ShowModal (MODAL_SHADOW_GRAY)
367 return
369 def OnMageUnmemorizeSpell ():
370 if MageSpellUnmemorizeWindow:
371 CloseMageSpellUnmemorizeWindow()
373 pc = GemRB.GameGetSelectedPCSingle ()
374 level = MageSpellLevel
375 type = IE_SPELL_TYPE_WIZARD
377 index = GemRB.GetVar ("SpellButton")
379 if GemRB.UnmemorizeSpell (pc, type, level, index):
380 UpdateMageWindow ()
381 return
383 def OnMageRemoveSpell ():
384 CloseMageSpellUnmemorizeWindow()
385 OpenMageSpellInfoWindow()
387 pc = GemRB.GameGetSelectedPCSingle ()
388 level = MageSpellLevel
389 type = IE_SPELL_TYPE_WIZARD
391 index = GemRB.GetVar ("SpellButton")-100
393 #remove spell from book
394 GemRB.RemoveSpell (pc, type, level, index)
395 UpdateMageWindow ()
396 return
398 def LoadCondition ():
399 global ContCond, ContTarg
401 Table = GemRB.LoadTable ("contcond")
402 CondCount = Table.GetRowCount ()
403 ContCond = [0] * CondCount
405 for i in range (CondCount):
406 #get the condition's name and description
407 tuple = (Table.GetValue (i, 0),Table.GetValue (i, 1) )
408 ContCond[i] = tuple
410 Table = GemRB.LoadTable ("conttarg")
411 TargCount = Table.GetRowCount ()
412 ContTarg = [0] * TargCount
414 for i in range (TargCount):
415 #get the condition's name and description
416 tuple = (Table.GetValue (i, 0),Table.GetValue (i, 1) )
417 ContTarg[i] = tuple
418 return
420 def OpenSequencerWindow ():
421 global OtherWindow
422 global ContingencyTextArea, TypeButton, OkButton
423 global Level, MaxLevel, Target, Count
424 global pc
425 global ContCond, ContTarg
426 global Spell1, Spell2, Spell3, Source
428 if ContCond == None:
429 LoadCondition()
431 Level = 1
432 Spell1 = ""
433 Spell2 = ""
434 Spell3 = ""
435 #the target player (who receives the contingency or sequencer)
436 pc = GemRB.GetVar("P0")
437 #maximum spell level
438 MaxLevel = GemRB.GetVar("P1")
439 #target 0 - any, 1 - caster only, 2 - sequencer
440 #spell count 1-3
441 p2 = GemRB.GetVar("P2")
442 Source = GemRB.GetSpellCastOn(pc)
444 print "Source: ", Source
445 Target = p2>>16
446 Count = p2&255
447 if Count > 3:
448 Count = 3
450 GemRB.LoadWindowPack ("GUIMG", 640, 480)
452 #saving the original portrait window
453 OtherWindow = Window = GemRB.LoadWindow (6)
455 Title = Window.GetControl (0x0fffffff)
457 ContingencyTextArea = Window.GetControl (25)
459 if Target == 2:
460 if Count < 3:
461 Title.SetText (55374)
462 ContingencyTextArea.SetText (60420)
463 else:
464 Title.SetText (55375)
465 ContingencyTextArea.SetText (55372)
466 else:
467 if Count < 3:
468 Title.SetText (11941)
469 else:
470 Title.SetText (55376)
471 ContingencyTextArea.SetText (55373)
473 CondSelect = Window.GetControl (4)
474 CondLabel = Window.GetControl (0x10000000)
475 TargSelect = Window.GetControl (6)
476 TargLabel = Window.GetControl (0x10000001)
477 TypeButton = Window.GetControl (8)
479 #no cleric spells available
480 if (CommonTables.ClassSkills.GetValue (GemRB.GetPlayerStat (pc, IE_CLASS), 0)=="*" and
481 CommonTables.ClassSkills.GetValue (GemRB.GetPlayerStat (pc, IE_CLASS), 1)=="*"):
482 TypeButton.SetState (IE_GUI_BUTTON_DISABLED)
484 if Target == 2:
485 CondSelect.SetPos (-1,-1)
486 CondLabel.SetPos (-1,-1)
487 TargSelect.SetPos (-1,-1)
488 TargLabel.SetPos (-1,-1)
489 sb = Window.GetControl (5)
490 sb.SetPos (-1,-1)
491 sb = Window.GetControl (7)
492 sb.SetPos (-1,-1)
493 else:
494 CondSelect.SetFlags (IE_GUI_TEXTAREA_SELECTABLE, OP_SET)
495 CondSelect.SetEvent (IE_GUI_TEXTAREA_ON_CHANGE, ContingencyHelpCondition)
496 CondSelect.SetVarAssoc ("ContCond", 0)
497 for elem in ContCond:
498 CondSelect.Append (elem[0], -1)
500 TargSelect.SetFlags (IE_GUI_TEXTAREA_SELECTABLE, OP_SET)
501 TargSelect.SetEvent (IE_GUI_TEXTAREA_ON_CHANGE, ContingencyHelpTarget)
502 TargSelect.SetVarAssoc ("ContTarg", 0)
503 for elem in ContTarg:
504 TargSelect.Append (elem[0], -1)
505 #check if target is only self
506 if Target:
507 TargSelect.SetVarAssoc ("ContTarg", 1)
508 break
510 GemRB.SetVar ("SpellType", 0)
511 TypeButton.SetVarAssoc ("SpellType", 1)
512 TypeButton.SetFlags (IE_GUI_BUTTON_CHECKBOX, OP_OR)
513 TypeButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, ContTypePressed)
515 Button = Window.GetControl (9)
516 Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, LevelIncrease)
517 Button = Window.GetControl (10)
518 Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, LevelDecrease)
520 OkButton = Window.GetControl (27)
521 OkButton.SetText (11973)
522 OkButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
523 OkButton.SetState (IE_GUI_BUTTON_DISABLED)
525 CancelButton = Window.GetControl (29)
526 CancelButton.SetText (13727)
527 CancelButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
529 OkButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, ContingencyOk)
530 CancelButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, ContingencyCancel)
531 ContTypePressed ()
532 Window.ShowModal (MODAL_SHADOW_GRAY)
533 return
535 def UpdateSpellList ():
536 Window = OtherWindow
538 if SpellType:
539 Type = IE_SPELL_TYPE_PRIEST
540 else:
541 Type = IE_SPELL_TYPE_WIZARD
543 Label = Window.GetControl (0x1000001d)
544 Label.SetText (GemRB.GetString(12137)+str(Level) )
546 BuildSpellList(pc, Type, Level-1)
548 names = SpellList.keys()
549 names.sort()
551 cnt = len(names)
552 j = 0
553 for i in range(11,20):
554 Button = Window.GetControl (i)
555 Button.SetFont ("NUMBER")
556 Button.SetFlags (IE_FONT_ALIGN_RIGHT|IE_FONT_ALIGN_BOTTOM,OP_OR)
557 if j<cnt:
558 Button.SetSpellIcon (names[j], 1)
559 Button.SetText( str(SpellList[names[j]]) )
560 Button.SetVarAssoc("Index", j)
561 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, ContingencyHelpSpell)
562 Button.SetState (IE_GUI_BUTTON_ENABLED)
563 else:
564 Button.SetSpellIcon("")
565 Button.SetText("")
566 Button.SetState (IE_GUI_BUTTON_DISABLED)
567 j = j+1
569 Button = Window.GetControl (22)
570 Button.SetSpellIcon(Spell1, 1)
571 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, DeleteSpell1)
572 Button = Window.GetControl (23)
573 Button.SetSpellIcon(Spell2, 1)
574 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, DeleteSpell2)
575 Button = Window.GetControl (24)
576 Button.SetSpellIcon(Spell3, 1)
577 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, DeleteSpell3)
579 if not Spell1:
580 OkButton.SetState (IE_GUI_BUTTON_DISABLED)
581 else:
582 OkButton.SetState (IE_GUI_BUTTON_ENABLED)
583 return
585 def ContTypePressed ():
586 global SpellType
588 Label = OtherWindow.GetControl (0x10000002)
589 SpellType = GemRB.GetVar ("SpellType")
591 if SpellType:
592 Label.SetText (54352)
593 TypeButton.SetText (18039)
594 else:
595 Label.SetText (21836)
596 TypeButton.SetText (7204)
597 UpdateSpellList()
598 return
600 def ContingencyOk ():
601 global OtherWindow
603 #set the storage
604 if Target == 2:
605 GemRB.ApplyEffect (pc, "Sequencer:Store", 0, 0, Spell1, Spell2, Spell3, Source)
606 else:
607 GemRB.ApplyEffect (pc, "CastSpellOnCondition", 0, GemRB.GetVar ("ContCond"), Spell1, Spell2, Spell3, Source)
608 #set the innate
609 GemRB.LearnSpell (pc, Source+"d", LS_MEMO)
610 OtherWindow.Unload()
611 return
613 def ContingencyCancel ():
614 global OtherWindow
616 GemRB.SetPlayerStat (pc, IE_IDENTIFYMODE, 0)
617 OtherWindow.Unload()
618 return
620 def ContingencyHelpSpell ():
621 global Spell1, Spell2, Spell3
623 names = SpellList.keys()
624 names.sort()
625 i = GemRB.GetVar("Index")
626 spell = names[i]
628 if Spell1=="" and Count>0:
629 Spell1 = spell
630 elif Spell2=="" and Count>1:
631 Spell2 = spell
632 elif Spell3=="" and Count>2:
633 Spell3 = spell
635 spl = GemRB.GetSpell(spell)
636 ContingencyTextArea.SetText (spl["SpellDesc"])
637 UpdateSpellList ()
638 return
640 def DeleteSpell1 ():
641 global Spell1, Spell2, Spell3
643 Spell1 = Spell2
644 Spell2 = Spell3
645 Spell3 = ""
646 ContingencyTextArea.SetText("")
647 UpdateSpellList ()
648 return
650 def DeleteSpell2 ():
651 global Spell2, Spell3
653 Spell2 = Spell3
654 Spell3 = ""
655 ContingencyTextArea.SetText("")
656 UpdateSpellList ()
657 return
659 def DeleteSpell3 ():
660 global Spell3
662 Spell3 = ""
663 ContingencyTextArea.SetText("")
664 UpdateSpellList ()
665 return
667 def ContingencyHelpCondition ():
668 i = GemRB.GetVar ("ContCond")
669 ContingencyTextArea.SetText (ContCond[i][1])
670 return
672 def ContingencyHelpTarget ():
673 i = GemRB.GetVar ("ContTarg")
674 ContingencyTextArea.SetText (ContTarg[i][1])
675 return
677 def LoadExclusions():
678 global Exclusions
680 ExclusionTable = GemRB.LoadTable ("contingx")
681 Columns = ExclusionTable.GetColumnCount ()
682 Rows = ExclusionTable.GetRowCount ()
683 Exclusions = []
684 for i in range (Columns):
685 Exclusions.append ([])
686 for j in range (Rows):
687 spell = ExclusionTable.GetValue (j,i,0)
688 if spell[0]=="*":
689 break
690 Exclusions[i].append (spell.lower())
692 return
694 #TODO: build a correct list for sorcerers too!
695 def BuildSpellList (pc, type, level):
696 global SpellList
698 if not Exclusions:
699 LoadExclusions()
701 SpellList = {}
702 dummy = [Spell1,Spell2,Spell3]
703 mem_cnt = GemRB.GetMemorizedSpellsCount (pc, type, level)
705 for i in range(mem_cnt):
706 ms = GemRB.GetMemorizedSpell (pc, type, level, i)
707 if ms["Flags"]:
708 spell = ms["SpellResRef"]
709 if spell in Exclusions[level]:
710 continue
711 if spell in dummy:
712 dummy.remove(spell)
713 continue
714 if not (spell in SpellList):
715 SpellList[spell] = 1
716 else:
717 SpellList[spell] = SpellList[spell]+1
718 return
720 def LevelIncrease():
721 global Level
723 if Level<MaxLevel:
724 Level = Level+1
725 UpdateSpellList()
726 return
728 def LevelDecrease():
729 global Level
731 if Level>1:
732 Level = Level-1
733 UpdateSpellList()
734 return
736 ###################################################
737 # End of file GUIMG.py