Button: Add separate event handler for dropping portraits.
[gemrb.git] / gemrb / GUIScripts / bg2 / GUIMG.py
blob72a9d4c90614d7a97bc1cd20fc6697f86901ce28
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 import GUICommonWindows
27 from GUIDefines import *
28 from ie_stats import *
29 from GUICommon import CloseOtherWindow, HasTOB
30 from GUICommon import GameWindow
31 from GUICommonWindows import *
33 MageWindow = None
34 MageSpellInfoWindow = None
35 MageSpellLevel = 0
36 MageSpellUnmemorizeWindow = None
37 PortraitWindow = None
38 OptionsWindow = None
39 OldPortraitWindow = None
40 OldOptionsWindow = None
41 BookType = None
42 OtherWindow = None
43 Exclusions = None
44 ContCond = None
45 ContTarg = None
46 SpellType = None
47 Level = 1
49 def OpenMageWindow ():
50 global MageWindow, OptionsWindow, PortraitWindow
51 global OldPortraitWindow, OldOptionsWindow
53 if 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 GameWindow.SetVisible(WINDOW_VISIBLE)
64 GemRB.UnhideGUI ()
65 GUICommonWindows.PortraitWindow = OldPortraitWindow
66 OldPortraitWindow = None
67 GUICommonWindows.OptionsWindow = OldOptionsWindow
68 OldOptionsWindow = None
69 SetSelectionChangeHandler (None)
70 return
72 GemRB.HideGUI ()
73 GameWindow.SetVisible(WINDOW_INVISIBLE)
75 GemRB.LoadWindowPack ("GUIMG", 640, 480)
77 #saving the original portrait window
78 OldOptionsWindow = GUICommonWindows.OptionsWindow
79 OptionsWindow = GemRB.LoadWindowObject (0)
80 MarkMenuButton (OptionsWindow)
81 SetupMenuWindowControls (OptionsWindow, 0, "OpenMageWindow")
82 OptionsWindow.SetFrame ()
83 OldPortraitWindow = GUICommonWindows.PortraitWindow
85 PortraitWindow = OpenPortraitWindow (0)
86 SetupMageWindow()
87 SetSelectionChangeHandler (SetupMageWindow)
88 return
90 def SetupMageWindow ():
91 global MageWindow
92 global BookType
94 pc = GemRB.GameGetSelectedPCSingle ()
95 BookType = 0
96 if (ClassSkillsTable.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.LoadWindowObject (8)
105 else:
106 MageWindow = Window = GemRB.LoadWindowObject (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 if not BookType:
172 mem_cnt = GemRB.GetMemorizedSpellsCount (pc, type, level)
173 for i in range (12):
174 Button = Window.GetControl (3 + i)
175 if i < mem_cnt:
176 ms = GemRB.GetMemorizedSpell (pc, type, level, i)
177 Button.SetSpellIcon (ms['SpellResRef'], 0)
178 Button.SetFlags (IE_GUI_BUTTON_NO_IMAGE, OP_NAND)
179 Button.SetFlags (IE_GUI_BUTTON_PICTURE, OP_OR)
180 if ms['Flags']:
181 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, "OpenMageSpellUnmemorizeWindow")
182 else:
183 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, "OnMageUnmemorizeSpell")
184 Button.SetEvent (IE_GUI_BUTTON_ON_RIGHT_PRESS, "OpenMageSpellInfoWindow")
185 spell = GemRB.GetSpell (ms['SpellResRef'])
186 Button.SetTooltip (spell['SpellName'])
187 MageMemorizedSpellList.append (ms['SpellResRef'])
188 Button.SetVarAssoc ("SpellButton", i)
189 Button.EnableBorder (0, ms['Flags'] == 0)
190 else:
191 if i < max_mem_cnt:
192 Button.SetFlags (IE_GUI_BUTTON_NORMAL, OP_SET)
193 else:
194 Button.SetFlags (IE_GUI_BUTTON_NO_IMAGE, OP_SET)
195 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, "")
196 Button.SetEvent (IE_GUI_BUTTON_ON_RIGHT_PRESS, "")
197 Button.SetTooltip ('')
198 Button.EnableBorder (0, 0)
199 else:
200 label = Window.GetControl (0x10000040)
201 label.SetText (GemRB.GetString(61256) + " " + str(max_mem_cnt)) #spells can cast
203 known_cnt = GemRB.GetKnownSpellsCount (pc, type, level)
204 for i in range (24):
205 Button = Window.GetControl (27 + i)
206 if i < known_cnt:
207 ks = GemRB.GetKnownSpell (pc, type, level, i)
208 Button.SetSpellIcon (ks['SpellResRef'], 0)
209 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, "OnMageMemorizeSpell")
210 Button.SetEvent (IE_GUI_BUTTON_ON_RIGHT_PRESS, "OpenMageSpellInfoWindow")
211 spell = GemRB.GetSpell (ks['SpellResRef'])
212 Button.SetTooltip (spell['SpellName'])
213 MageKnownSpellList.append (ks['SpellResRef'])
214 Button.SetVarAssoc ("SpellButton", 100 + i)
216 else:
217 Button.SetFlags (IE_GUI_BUTTON_PICTURE, OP_NAND)
218 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, "")
219 Button.SetEvent (IE_GUI_BUTTON_ON_RIGHT_PRESS, "")
220 Button.SetTooltip ('')
221 Button.EnableBorder (0, 0)
223 if (ClassSkillsTable.GetValue (GemRB.GetPlayerStat (pc, IE_CLASS), 2)=="*"):
224 Window.SetVisible (WINDOW_GRAYED)
225 else:
226 Window.SetVisible (WINDOW_VISIBLE)
227 return
229 def MagePrevLevelPress ():
230 global MageSpellLevel
232 if MageSpellLevel > 0:
233 MageSpellLevel = MageSpellLevel - 1
234 UpdateMageWindow ()
235 return
237 def MageNextLevelPress ():
238 global MageSpellLevel
240 if MageSpellLevel < 8:
241 MageSpellLevel = MageSpellLevel + 1
242 UpdateMageWindow ()
243 return
245 def RefreshMageLevel ():
246 global MageSpellLevel
248 MageSpellLevel = GemRB.GetVar ("MageSpellLevel")
249 UpdateMageWindow ()
250 return
252 def OpenMageSpellInfoWindow ():
253 global MageSpellInfoWindow
255 if MageSpellInfoWindow != None:
256 if MageSpellInfoWindow:
257 MageSpellInfoWindow.Unload ()
258 MageSpellInfoWindow = None
259 return
261 MageSpellInfoWindow = Window = GemRB.LoadWindowObject (3)
263 #back
264 Button = Window.GetControl (5)
265 Button.SetText (15416)
266 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, "OpenMageSpellInfoWindow")
268 #erase
269 index = GemRB.GetVar ("SpellButton")
270 if HasTOB():
271 Button = Window.GetControl (6)
272 if index < 100:
273 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, "")
274 Button.SetFlags (IE_GUI_BUTTON_NO_IMAGE, OP_SET)
275 else:
276 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, "OpenMageSpellRemoveWindow")
277 Button.SetText (63668)
278 if index < 100:
279 ResRef = MageMemorizedSpellList[index]
280 else:
281 ResRef = MageKnownSpellList[index - 100]
283 spell = GemRB.GetSpell (ResRef)
285 Label = Window.GetControl (0x0fffffff)
286 Label.SetText (spell['SpellName'])
288 Button = Window.GetControl (2)
289 Button.SetSpellIcon (ResRef, 1)
291 Text = Window.GetControl (3)
292 Text.SetText (spell['SpellDesc'])
294 Window.ShowModal (MODAL_SHADOW_GRAY)
295 return
297 def OnMageMemorizeSpell ():
298 pc = GemRB.GameGetSelectedPCSingle ()
299 level = MageSpellLevel
300 type = IE_SPELL_TYPE_WIZARD
302 index = GemRB.GetVar ("SpellButton") - 100
304 if GemRB.MemorizeSpell (pc, type, level, index):
305 UpdateMageWindow ()
306 return
308 def CloseMageSpellUnmemorizeWindow ():
309 global MageSpellUnmemorizeWindow
311 if MageSpellUnmemorizeWindow:
312 MageSpellUnmemorizeWindow.Unload ()
313 MageSpellUnmemorizeWindow = None
314 return
316 def OpenMageSpellRemoveWindow ():
317 global MageSpellUnmemorizeWindow
319 MageSpellUnmemorizeWindow = Window = GemRB.LoadWindowObject (101)
321 # "Are you sure you want to ....?"
322 TextArea = Window.GetControl (3)
323 TextArea.SetText (63745)
325 # Remove
326 Button = Window.GetControl (0)
327 Button.SetText (17507)
328 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, "OnMageRemoveSpell")
329 Button.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
331 # Cancel
332 Button = Window.GetControl (1)
333 Button.SetText (13727)
334 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, "CloseMageSpellUnmemorizeWindow")
335 Button.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
337 Window.ShowModal (MODAL_SHADOW_GRAY)
338 return
340 def OpenMageSpellUnmemorizeWindow ():
341 global MageSpellUnmemorizeWindow
343 MageSpellUnmemorizeWindow = Window = GemRB.LoadWindowObject (101)
345 # "Are you sure you want to ....?"
346 TextArea = Window.GetControl (3)
347 TextArea.SetText (11824)
349 # Remove
350 Button = Window.GetControl (0)
351 Button.SetText (17507)
352 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, "OnMageUnmemorizeSpell")
353 Button.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
355 # Cancel
356 Button = Window.GetControl (1)
357 Button.SetText (13727)
358 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, "CloseMageSpellUnmemorizeWindow")
359 Button.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
361 Window.ShowModal (MODAL_SHADOW_GRAY)
362 return
364 def OnMageUnmemorizeSpell ():
365 if MageSpellUnmemorizeWindow:
366 CloseMageSpellUnmemorizeWindow()
368 pc = GemRB.GameGetSelectedPCSingle ()
369 level = MageSpellLevel
370 type = IE_SPELL_TYPE_WIZARD
372 index = GemRB.GetVar ("SpellButton")
374 if GemRB.UnmemorizeSpell (pc, type, level, index):
375 UpdateMageWindow ()
376 return
378 def OnMageRemoveSpell ():
379 CloseMageSpellUnmemorizeWindow()
380 OpenMageSpellInfoWindow()
382 pc = GemRB.GameGetSelectedPCSingle ()
383 level = MageSpellLevel
384 type = IE_SPELL_TYPE_WIZARD
386 index = GemRB.GetVar ("SpellButton")-100
388 #remove spell from book
389 GemRB.RemoveSpell (pc, type, level, index)
390 UpdateMageWindow ()
391 return
393 def LoadCondition ():
394 global ContCond, ContTarg
396 Table = GemRB.LoadTableObject ("contcond")
397 CondCount = Table.GetRowCount ()
398 ContCond = [0] * CondCount
400 for i in range (CondCount):
401 #get the condition's name and description
402 tuple = (Table.GetValue (i, 0),Table.GetValue (i, 1) )
403 ContCond[i] = tuple
405 Table = GemRB.LoadTableObject ("conttarg")
406 TargCount = Table.GetRowCount ()
407 ContTarg = [0] * TargCount
409 for i in range (TargCount):
410 #get the condition's name and description
411 tuple = (Table.GetValue (i, 0),Table.GetValue (i, 1) )
412 ContTarg[i] = tuple
413 return
415 def OpenSequencerWindow ():
416 global OtherWindow
417 global ContingencyTextArea, TypeButton, OkButton
418 global Level, MaxLevel, Target, Count
419 global pc
420 global ContCond, ContTarg
421 global Spell1, Spell2, Spell3, Source
423 if ContCond == None:
424 LoadCondition()
426 Level = 1
427 Spell1 = ""
428 Spell2 = ""
429 Spell3 = ""
430 #the target player (who receives the contingency or sequencer)
431 pc = GemRB.GetVar("P0")
432 #maximum spell level
433 MaxLevel = GemRB.GetVar("P1")
434 #target 0 - any, 1 - caster only, 2 - sequencer
435 #spell count 1-3
436 p2 = GemRB.GetVar("P2")
437 Source = GemRB.GetSpellCastOn(pc)
439 print "Source: ", Source
440 Target = p2>>16
441 Count = p2&255
442 if Count > 3:
443 Count = 3
445 GemRB.LoadWindowPack ("GUIMG", 640, 480)
447 #saving the original portrait window
448 OtherWindow = Window = GemRB.LoadWindowObject (6)
450 Title = Window.GetControl (0x0fffffff)
452 ContingencyTextArea = Window.GetControl (25)
454 if Target == 2:
455 if Count < 3:
456 Title.SetText (55374)
457 ContingencyTextArea.SetText (60420)
458 else:
459 Title.SetText (55375)
460 ContingencyTextArea.SetText (55372)
461 else:
462 if Count < 3:
463 Title.SetText (11941)
464 else:
465 Title.SetText (55376)
466 ContingencyTextArea.SetText (55373)
468 CondSelect = Window.GetControl (4)
469 CondLabel = Window.GetControl (0x10000000)
470 TargSelect = Window.GetControl (6)
471 TargLabel = Window.GetControl (0x10000001)
472 TypeButton = Window.GetControl (8)
474 #no cleric spells available
475 if (ClassSkillsTable.GetValue (GemRB.GetPlayerStat (pc, IE_CLASS), 0)=="*" and
476 ClassSkillsTable.GetValue (GemRB.GetPlayerStat (pc, IE_CLASS), 1)=="*"):
477 TypeButton.SetState (IE_GUI_BUTTON_DISABLED)
479 if Target == 2:
480 CondSelect.SetPos (-1,-1)
481 CondLabel.SetPos (-1,-1)
482 TargSelect.SetPos (-1,-1)
483 TargLabel.SetPos (-1,-1)
484 sb = Window.GetControl (5)
485 sb.SetPos (-1,-1)
486 sb = Window.GetControl (7)
487 sb.SetPos (-1,-1)
488 else:
489 CondSelect.SetFlags (IE_GUI_TEXTAREA_SELECTABLE, OP_SET)
490 CondSelect.SetEvent (IE_GUI_TEXTAREA_ON_CHANGE, "ContingencyHelpCondition")
491 CondSelect.SetVarAssoc ("ContCond", 0)
492 for elem in ContCond:
493 CondSelect.Append (elem[0], -1)
495 TargSelect.SetFlags (IE_GUI_TEXTAREA_SELECTABLE, OP_SET)
496 TargSelect.SetEvent (IE_GUI_TEXTAREA_ON_CHANGE, "ContingencyHelpTarget")
497 TargSelect.SetVarAssoc ("ContTarg", 0)
498 for elem in ContTarg:
499 TargSelect.Append (elem[0], -1)
500 #check if target is only self
501 if Target:
502 TargSelect.SetVarAssoc ("ContTarg", 1)
503 break
505 GemRB.SetVar ("SpellType", 0)
506 TypeButton.SetVarAssoc ("SpellType", 1)
507 TypeButton.SetFlags (IE_GUI_BUTTON_CHECKBOX, OP_OR)
508 TypeButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, "ContTypePressed")
510 Button = Window.GetControl (9)
511 Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, "LevelIncrease")
512 Button = Window.GetControl (10)
513 Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, "LevelDecrease")
515 OkButton = Window.GetControl (27)
516 OkButton.SetText (11973)
517 OkButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
518 OkButton.SetState (IE_GUI_BUTTON_DISABLED)
520 CancelButton = Window.GetControl (29)
521 CancelButton.SetText (13727)
522 CancelButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
524 OkButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, "ContingencyOk")
525 CancelButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, "ContingencyCancel")
526 ContTypePressed ()
527 Window.ShowModal (MODAL_SHADOW_GRAY)
528 return
530 def UpdateSpellList ():
531 Window = OtherWindow
533 if SpellType:
534 Type = IE_SPELL_TYPE_PRIEST
535 else:
536 Type = IE_SPELL_TYPE_WIZARD
538 Label = Window.GetControl (0x1000001d)
539 Label.SetText (GemRB.GetString(12137)+str(Level) )
541 BuildSpellList(pc, Type, Level-1)
543 names = SpellList.keys()
544 names.sort()
546 cnt = len(names)
547 j = 0
548 for i in range(11,20):
549 Button = Window.GetControl (i)
550 Button.SetFont ("NUMBER")
551 Button.SetFlags (IE_FONT_ALIGN_RIGHT|IE_FONT_ALIGN_BOTTOM,OP_OR)
552 if j<cnt:
553 Button.SetSpellIcon (names[j], 1)
554 Button.SetText( str(SpellList[names[j]]) )
555 Button.SetVarAssoc("Index", j)
556 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, "ContingencyHelpSpell")
557 Button.SetState (IE_GUI_BUTTON_ENABLED)
558 else:
559 Button.SetSpellIcon("")
560 Button.SetText("")
561 Button.SetState (IE_GUI_BUTTON_DISABLED)
562 j = j+1
564 Button = Window.GetControl (22)
565 Button.SetSpellIcon(Spell1, 1)
566 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, "DeleteSpell1")
567 Button = Window.GetControl (23)
568 Button.SetSpellIcon(Spell2, 1)
569 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, "DeleteSpell2")
570 Button = Window.GetControl (24)
571 Button.SetSpellIcon(Spell3, 1)
572 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, "DeleteSpell3")
574 if not Spell1:
575 OkButton.SetState (IE_GUI_BUTTON_DISABLED)
576 else:
577 OkButton.SetState (IE_GUI_BUTTON_ENABLED)
578 return
580 def ContTypePressed ():
581 global SpellType
583 Label = OtherWindow.GetControl (0x10000002)
584 SpellType = GemRB.GetVar ("SpellType")
586 if SpellType:
587 Label.SetText (54352)
588 TypeButton.SetText (18039)
589 else:
590 Label.SetText (21836)
591 TypeButton.SetText (7204)
592 UpdateSpellList()
593 return
595 def ContingencyOk ():
596 global OtherWindow
598 #set the storage
599 if Target == 2:
600 GemRB.ApplyEffect (pc, "Sequencer:Store", 0, 0, Spell1, Spell2, Spell3, Source)
601 else:
602 GemRB.ApplyEffect (pc, "CastSpellOnCondition", Target, Condition, Spell1, Spell2, Spell3, Source)
603 #set the innate
604 GemRB.LearnSpell (pc, Source+"d", LS_MEMO)
605 OtherWindow.Unload()
606 return
608 def ContingencyCancel ():
609 global OtherWindow
611 GemRB.SetPlayerStat (pc, IE_IDENTIFYMODE, 0)
612 OtherWindow.Unload()
613 return
615 def ContingencyHelpSpell ():
616 global Spell1, Spell2, Spell3
618 names = SpellList.keys()
619 names.sort()
620 i = GemRB.GetVar("Index")
621 spell = names[i]
623 if Spell1=="" and Count>0:
624 Spell1 = spell
625 elif Spell2=="" and Count>1:
626 Spell2 = spell
627 elif Spell3=="" and Count>2:
628 Spell3 = spell
630 spl = GemRB.GetSpell(spell)
631 ContingencyTextArea.SetText (spl["SpellDesc"])
632 UpdateSpellList ()
633 return
635 def DeleteSpell1 ():
636 global Spell1, Spell2, Spell3
638 Spell1 = Spell2
639 Spell2 = Spell3
640 Spell3 = ""
641 ContingencyTextArea.SetText("")
642 UpdateSpellList ()
643 return
645 def DeleteSpell2 ():
646 global Spell2, Spell3
648 Spell2 = Spell3
649 Spell3 = ""
650 ContingencyTextArea.SetText("")
651 UpdateSpellList ()
652 return
654 def DeleteSpell3 ():
655 global Spell3
657 Spell3 = ""
658 ContingencyTextArea.SetText("")
659 UpdateSpellList ()
660 return
662 def ContingencyHelpCondition ():
663 i = GemRB.GetVar ("ContCond")
664 ContingencyTextArea.SetText (ContCond[i][1])
665 return
667 def ContingencyHelpTarget ():
668 i = GemRB.GetVar ("ContTarg")
669 ContingencyTextArea.SetText (ContTarg[i][1])
670 return
672 def LoadExclusions():
673 global Exclusions
675 ExclusionTable = GemRB.LoadTableObject ("contingx")
676 Columns = ExclusionTable.GetColumnCount ()
677 Rows = ExclusionTable.GetRowCount ()
678 Exclusions = []
679 for i in range (Columns):
680 Exclusions.append ([])
681 for j in range (Rows):
682 spell = ExclusionTable.GetValue (j,i,0)
683 if spell[0]=="*":
684 break
685 Exclusions[i].append (spell.lower())
687 return
689 #TODO: build a correct list for sorcerers too!
690 def BuildSpellList (pc, type, level):
691 global SpellList
693 if not Exclusions:
694 LoadExclusions()
696 SpellList = {}
697 dummy = [Spell1,Spell2,Spell3]
698 mem_cnt = GemRB.GetMemorizedSpellsCount (pc, type, level)
700 for i in range(mem_cnt):
701 ms = GemRB.GetMemorizedSpell (pc, type, level, i)
702 if ms["Flags"]:
703 spell = ms["SpellResRef"]
704 if spell in Exclusions[level]:
705 continue
706 if spell in dummy:
707 dummy.remove(spell)
708 continue
709 if not (spell in SpellList):
710 SpellList[spell] = 1
711 else:
712 SpellList[spell] = SpellList[spell]+1
713 return
715 def LevelIncrease():
716 global Level
718 if Level<MaxLevel:
719 Level = Level+1
720 UpdateSpellList()
721 return
723 def LevelDecrease():
724 global Level
726 if Level>1:
727 Level = Level-1
728 UpdateSpellList()
729 return
731 ###################################################
732 # End of file GUIMG.py