2 # GemRB - Infinity Engine Emulator
3 # Copyright (C) 2003 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 GUIMG winpack
23 ###################################################
26 import GUICommonWindows
27 from GUIDefines
import *
28 from ie_stats
import *
29 from GUICommon
import CloseOtherWindow
, ClassSkillsTable
30 from GUICommon
import GameWindow
31 from GUICommonWindows
import *
34 MageSpellInfoWindow
= None
36 MageSpellUnmemorizeWindow
= None
37 OldOptionsWindow
= None
40 def OpenMageWindow ():
41 global MageWindow
, OptionsWindow
42 global OldOptionsWindow
44 if CloseOtherWindow (OpenMageWindow
):
48 OptionsWindow
.Unload ()
50 GemRB
.SetVar ("OtherWindow", -1)
51 GameWindow
.SetVisible(WINDOW_VISIBLE
)
53 OptionsWindow
= OldOptionsWindow
54 OldOptionsWindow
= None
55 SetSelectionChangeHandler(None)
59 GameWindow
.SetVisible(WINDOW_INVISIBLE
)
60 GemRB
.LoadWindowPack ("GUIMG")
61 MageWindow
= Window
= GemRB
.LoadWindowObject (2)
62 GemRB
.SetVar ("OtherWindow", MageWindow
.ID
)
63 OldOptionsWindow
= GUICommonWindows
.OptionsWindow
64 OptionsWindow
= GemRB
.LoadWindowObject (0)
65 SetupMenuWindowControls (OptionsWindow
, 0, "OpenMageWindow")
66 OptionsWindow
.SetFrame ()
68 Button
= Window
.GetControl (1)
69 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, "MagePrevLevelPress")
71 Button
= Window
.GetControl (2)
72 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, "MageNextLevelPress")
75 ## Button = Window.GetControl (55)
76 ## Button.SetState (IE_GUI_BUTTON_LOCKED)
77 ## #Button.SetText (123)
78 ## #Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, "xxPress")
80 ## #setup level buttons
81 ## for i in range (9):
82 ## Button = Window.GetControl (56 + i)
83 ## Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, "RefreshMageLevel")
84 ## Button.SetFlags (IE_GUI_BUTTON_RADIOBUTTON, OP_OR)
86 ## for i in range (9):
87 ## Button = Window.GetControl (56 + i)
88 ## Button.SetVarAssoc ("MageSpellLevel", i)
90 # Setup memorized spells buttons
92 Button
= Window
.GetControl (3 + i
)
93 Button
.SetBorder (0,0,0,0,0,0,0,0,64,0,1)
94 Button
.SetSprites ("SPELFRAM",0,0,0,0,0)
95 Button
.SetFlags (IE_GUI_BUTTON_PICTURE
, OP_OR
)
96 Button
.SetState (IE_GUI_BUTTON_LOCKED
)
98 # Setup book spells buttons
100 Button
= Window
.GetControl (27 + i
)
101 Button
.SetFlags (IE_GUI_BUTTON_NO_IMAGE
, OP_OR
)
102 Button
.SetState (IE_GUI_BUTTON_LOCKED
)
104 SetSelectionChangeHandler (UpdateMageWindow
)
107 OptionsWindow
.SetVisible (WINDOW_VISIBLE
)
108 Window
.SetVisible (WINDOW_FRONT
)
109 GUICommonWindows
.PortraitWindow
.SetVisible (WINDOW_VISIBLE
)
113 def UpdateMageWindow ():
114 global MageMemorizedSpellList
, MageKnownSpellList
116 MageMemorizedSpellList
= []
117 MageKnownSpellList
= []
120 pc
= GemRB
.GameGetSelectedPCSingle ()
121 type = IE_SPELL_TYPE_WIZARD
122 level
= MageSpellLevel
123 max_mem_cnt
= GemRB
.GetMemorizableSpellsCount (pc
, type, level
)
125 Label
= Window
.GetControl (0x10000032)
126 GemRB
.SetToken ('LEVEL', str (level
+ 1))
127 Label
.SetText (12137 )
129 Name
= GemRB
.GetPlayerName (pc
, 0)
130 Label
= Window
.GetControl (0x10000035)
133 mem_cnt
= GemRB
.GetMemorizedSpellsCount (pc
, type, level
)
135 Button
= Window
.GetControl (3 + i
)
137 ms
= GemRB
.GetMemorizedSpell (pc
, type, level
, i
)
138 Button
.SetSpellIcon (ms
['SpellResRef'], 0)
139 Button
.SetFlags (IE_GUI_BUTTON_NO_IMAGE
, OP_NAND
)
140 Button
.SetFlags (IE_GUI_BUTTON_PICTURE
, OP_OR
)
142 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, "OpenMageSpellUnmemorizeWindow")
144 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, "OnMageUnmemorizeSpell")
145 Button
.SetEvent (IE_GUI_BUTTON_ON_RIGHT_PRESS
, "OpenMageSpellInfoWindow")
146 spell
= GemRB
.GetSpell (ms
['SpellResRef'])
147 Button
.SetTooltip (spell
['SpellName'])
148 MageMemorizedSpellList
.append (ms
['SpellResRef'])
149 Button
.SetVarAssoc ("SpellButton", i
)
150 Button
.EnableBorder (0, ms
['Flags'] == 0)
153 Button
.SetFlags (IE_GUI_BUTTON_NORMAL
, OP_SET
)
155 Button
.SetFlags (IE_GUI_BUTTON_NO_IMAGE
, OP_SET
)
156 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, "")
157 Button
.SetEvent (IE_GUI_BUTTON_ON_RIGHT_PRESS
, "")
158 Button
.SetTooltip ('')
159 Button
.EnableBorder (0, 0)
162 known_cnt
= GemRB
.GetKnownSpellsCount (pc
, type, level
)
164 Button
= Window
.GetControl (27 + i
)
166 ks
= GemRB
.GetKnownSpell (pc
, type, level
, i
)
167 Button
.SetSpellIcon (ks
['SpellResRef'], 0)
168 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, "OnMageMemorizeSpell")
169 Button
.SetEvent (IE_GUI_BUTTON_ON_RIGHT_PRESS
, "OpenMageSpellInfoWindow")
170 spell
= GemRB
.GetSpell (ks
['SpellResRef'])
171 Button
.SetTooltip (spell
['SpellName'])
172 MageKnownSpellList
.append (ks
['SpellResRef'])
173 Button
.SetVarAssoc ("SpellButton", 100 + i
)
176 Button
.SetFlags (IE_GUI_BUTTON_PICTURE
, OP_NAND
)
177 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, "")
178 Button
.SetEvent (IE_GUI_BUTTON_ON_RIGHT_PRESS
, "")
179 Button
.SetTooltip ('')
180 Button
.EnableBorder (0, 0)
182 if (ClassSkillsTable
.GetValue (GemRB
.GetPlayerStat( GemRB
.GameGetSelectedPCSingle(), IE_CLASS
), 2)=="*"):
183 Window
.SetVisible (WINDOW_GRAYED
)
185 Window
.SetVisible (WINDOW_VISIBLE
)
188 def MagePrevLevelPress ():
189 global MageSpellLevel
191 if MageSpellLevel
> 0:
192 MageSpellLevel
= MageSpellLevel
- 1
196 def MageNextLevelPress ():
197 global MageSpellLevel
199 if MageSpellLevel
< 8:
200 MageSpellLevel
= MageSpellLevel
+ 1
204 def RefreshMageLevel ():
205 global MageSpellLevel
207 MageSpellLevel
= GemRB
.GetVar ("MageSpellLevel")
211 def OpenMageSpellInfoWindow ():
212 global MageSpellInfoWindow
214 if MageSpellInfoWindow
!= None:
215 if MageSpellInfoWindow
:
216 MageSpellInfoWindow
.Unload ()
217 MageSpellInfoWindow
= None
220 MageSpellInfoWindow
= Window
= GemRB
.LoadWindowObject (3)
223 Button
= Window
.GetControl (5)
224 Button
.SetText (15416)
225 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, "OpenMageSpellInfoWindow")
228 #Button = Window.GetControl (6)
229 index
= GemRB
.GetVar ("SpellButton")
231 ResRef
= MageMemorizedSpellList
[index
]
233 ResRef
= MageKnownSpellList
[index
- 100]
235 spell
= GemRB
.GetSpell (ResRef
)
237 Label
= Window
.GetControl (0x0fffffff)
238 Label
.SetText (spell
['SpellName'])
240 Button
= Window
.GetControl (2)
241 Button
.SetSpellIcon (ResRef
, 1)
243 Text
= Window
.GetControl (3)
244 Text
.SetText (spell
['SpellDesc'])
246 Window
.ShowModal (MODAL_SHADOW_GRAY
)
249 def OnMageMemorizeSpell ():
250 pc
= GemRB
.GameGetSelectedPCSingle ()
251 level
= MageSpellLevel
252 type = IE_SPELL_TYPE_WIZARD
254 index
= GemRB
.GetVar ("SpellButton") - 100
256 if GemRB
.MemorizeSpell (pc
, type, level
, index
):
260 def CloseMageSpellUnmemorizeWindow ():
261 global MageSpellUnmemorizeWindow
263 if MageSpellUnmemorizeWindow
:
264 MageSpellUnmemorizeWindow
.Unload ()
265 MageSpellUnmemorizeWindow
= None
268 #def OpenMageSpellRemoveWindow ():
269 # global MageSpellUnmemorizeWindow
271 # MageSpellUnmemorizeWindow = Window = GemRB.LoadWindowObject (5)
273 # # "Are you sure you want to ....?"
274 # TextArea = Window.GetControl (3)
275 # TextArea.SetText (63745)
278 # Button = Window.GetControl (0)
279 # Button.SetText (17507)
280 # Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, "OnMageRemoveSpell")
281 # Button.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
284 # Button = Window.GetControl (1)
285 # Button.SetText (13727)
286 # Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, "CloseMageSpellUnmemorizeWindow")
287 # Button.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
289 # Window.ShowModal (MODAL_SHADOW_GRAY)
292 def OpenMageSpellUnmemorizeWindow ():
293 global MageSpellUnmemorizeWindow
295 MageSpellUnmemorizeWindow
= Window
= GemRB
.LoadWindowObject (5)
297 # "Are you sure you want to ....?"
298 TextArea
= Window
.GetControl (3)
299 TextArea
.SetText (11824)
302 Button
= Window
.GetControl (0)
303 Button
.SetText (17507)
304 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, "OnMageUnmemorizeSpell")
305 Button
.SetFlags (IE_GUI_BUTTON_DEFAULT
, OP_OR
)
308 Button
= Window
.GetControl (1)
309 Button
.SetText (13727)
310 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, "CloseMageSpellUnmemorizeWindow")
311 Button
.SetFlags (IE_GUI_BUTTON_CANCEL
, OP_OR
)
313 Window
.ShowModal (MODAL_SHADOW_GRAY
)
316 def OnMageUnmemorizeSpell ():
317 if MageSpellUnmemorizeWindow
:
318 CloseMageSpellUnmemorizeWindow()
320 pc
= GemRB
.GameGetSelectedPCSingle ()
321 level
= MageSpellLevel
322 type = IE_SPELL_TYPE_WIZARD
324 index
= GemRB
.GetVar ("SpellButton")
326 if GemRB
.UnmemorizeSpell (pc
, type, level
, index
):
330 #def OnMageRemoveSpell ():
331 # CloseMageSpellUnmemorizeWindow()
332 # OpenMageSpellInfoWindow()
334 # pc = GemRB.GameGetSelectedPCSingle ()
335 # level = MageSpellLevel
336 # type = IE_SPELL_TYPE_WIZARD
338 # index = GemRB.GetVar ("SpellButton")-100
340 # #remove spell from book
341 # GemRB.RemoveSpell (pc, type, level, index)
342 # UpdateMageWindow ()
345 ###################################################
346 # End of file GUIMG.py