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 ###################################################
28 import GUICommonWindows
29 from GUIDefines
import *
30 from ie_stats
import *
33 MageSpellInfoWindow
= None
35 MageSpellUnmemorizeWindow
= None
38 OldPortraitWindow
= None
39 OldOptionsWindow
= None
41 def OpenMageWindow ():
42 global MageWindow
, OptionsWindow
, PortraitWindow
43 global OldPortraitWindow
, OldOptionsWindow
45 if GUICommon
.CloseOtherWindow (OpenMageWindow
):
49 OptionsWindow
.Unload ()
51 PortraitWindow
.Unload ()
54 GemRB
.SetVar ("OtherWindow", -1)
55 GUICommon
.GameWindow
.SetVisible(WINDOW_VISIBLE
)
57 GUICommonWindows
.PortraitWindow
= OldPortraitWindow
58 OldPortraitWindow
= None
59 GUICommonWindows
.OptionsWindow
= OldOptionsWindow
60 OldOptionsWindow
= None
61 GUICommonWindows
.SetSelectionChangeHandler (None)
65 GUICommon
.GameWindow
.SetVisible(WINDOW_INVISIBLE
)
67 GemRB
.LoadWindowPack ("GUIMG", 640, 480)
68 MageWindow
= Window
= GemRB
.LoadWindow (2)
69 GemRB
.SetVar ("OtherWindow", MageWindow
.ID
)
70 #saving the original portrait window
71 OldOptionsWindow
= GUICommonWindows
.OptionsWindow
72 OptionsWindow
= GemRB
.LoadWindow (0)
73 GUICommonWindows
.SetupMenuWindowControls (OptionsWindow
, 0, OpenMageWindow
)
74 OptionsWindow
.SetFrame ()
75 OldPortraitWindow
= GUICommonWindows
.PortraitWindow
76 PortraitWindow
= GUICommonWindows
.OpenPortraitWindow (0)
78 Button
= Window
.GetControl (1)
79 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, MagePrevLevelPress
)
81 Button
= Window
.GetControl (2)
82 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, MageNextLevelPress
)
85 ## Button = Window.GetControl (55)
86 ## Button.SetState (IE_GUI_BUTTON_LOCKED)
87 ## #Button.SetText (123)
88 ## #Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, xxPress)
90 ## #setup level buttons
91 ## for i in range (9):
92 ## Button = Window.GetControl (56 + i)
93 ## Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, RefreshMageLevel)
94 ## Button.SetFlags (IE_GUI_BUTTON_RADIOBUTTON, OP_OR)
96 ## for i in range (9):
97 ## Button = Window.GetControl (56 + i)
98 ## Button.SetVarAssoc ("MageSpellLevel", i)
101 # Setup memorized spells buttons
103 Button
= Window
.GetControl (3 + i
)
104 Button
.SetBorder (0,0,0,0,0,0,0,0,64,0,1)
105 Button
.SetSprites ("SPELFRAM",0,0,0,0,0)
106 Button
.SetFlags (IE_GUI_BUTTON_PICTURE
, OP_OR
)
107 Button
.SetState (IE_GUI_BUTTON_LOCKED
)
109 # Setup book spells buttons
110 for i
in range (GUICommon
.GetIWDSpellButtonCount()):
111 Button
= Window
.GetControl (27 + i
)
112 Button
.SetFlags (IE_GUI_BUTTON_NO_IMAGE
, OP_OR
)
113 Button
.SetState (IE_GUI_BUTTON_LOCKED
)
115 GUICommonWindows
.SetSelectionChangeHandler (UpdateMageWindow
)
117 OptionsWindow
.SetVisible (WINDOW_VISIBLE
)
118 #bringing the window front
119 Window
.SetVisible (WINDOW_FRONT
)
120 PortraitWindow
.SetVisible (WINDOW_VISIBLE
)
123 def UpdateMageWindow ():
124 global MageMemorizedSpellList
, MageKnownSpellList
126 MageMemorizedSpellList
= []
127 MageKnownSpellList
= []
130 pc
= GemRB
.GameGetSelectedPCSingle ()
131 type = IE_SPELL_TYPE_WIZARD
132 level
= MageSpellLevel
133 max_mem_cnt
= GemRB
.GetMemorizableSpellsCount (pc
, type, level
)
135 Label
= Window
.GetControl (0x10000032)
136 GemRB
.SetToken ('LEVEL', str (level
+ 1))
137 Label
.SetText (12137 )
139 Name
= GemRB
.GetPlayerName (pc
, 0)
140 Label
= Window
.GetControl (0x10000035)
142 mem_cnt
= GemRB
.GetMemorizedSpellsCount (pc
, type, level
)
144 Button
= Window
.GetControl (3 + i
)
146 ms
= GemRB
.GetMemorizedSpell (pc
, type, level
, i
)
147 Button
.SetSpellIcon (ms
['SpellResRef'], 0)
148 Button
.SetFlags (IE_GUI_BUTTON_NO_IMAGE
, OP_NAND
)
149 Button
.SetFlags (IE_GUI_BUTTON_PICTURE
, OP_OR
)
151 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, OpenMageSpellUnmemorizeWindow
)
153 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, OnMageUnmemorizeSpell
)
154 Button
.SetEvent (IE_GUI_BUTTON_ON_RIGHT_PRESS
, OpenMageSpellInfoWindow
)
155 spell
= GemRB
.GetSpell (ms
['SpellResRef'])
156 Button
.SetTooltip (spell
['SpellName'])
157 MageMemorizedSpellList
.append (ms
['SpellResRef'])
158 Button
.SetVarAssoc ("SpellButton", i
)
159 Button
.EnableBorder (0, ms
['Flags'] == 0)
162 Button
.SetFlags (IE_GUI_BUTTON_NORMAL
, OP_SET
)
164 Button
.SetFlags (IE_GUI_BUTTON_NO_IMAGE
, OP_SET
)
165 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, None)
166 Button
.SetEvent (IE_GUI_BUTTON_ON_RIGHT_PRESS
, None)
167 Button
.SetTooltip ('')
168 Button
.EnableBorder (0, 0)
171 known_cnt
= GemRB
.GetKnownSpellsCount (pc
, type, level
)
172 for i
in range (GUICommon
.GetIWDSpellButtonCount()):
173 Button
= Window
.GetControl (27 + i
)
175 ks
= GemRB
.GetKnownSpell (pc
, type, level
, i
)
176 Button
.SetSpellIcon (ks
['SpellResRef'], 0)
177 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, OnMageMemorizeSpell
)
178 Button
.SetEvent (IE_GUI_BUTTON_ON_RIGHT_PRESS
, OpenMageSpellInfoWindow
)
179 spell
= GemRB
.GetSpell (ks
['SpellResRef'])
180 Button
.SetTooltip (spell
['SpellName'])
181 MageKnownSpellList
.append (ks
['SpellResRef'])
182 Button
.SetVarAssoc ("SpellButton", 100 + i
)
185 Button
.SetFlags (IE_GUI_BUTTON_PICTURE
, OP_NAND
)
186 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, None)
187 Button
.SetEvent (IE_GUI_BUTTON_ON_RIGHT_PRESS
, None)
188 Button
.SetTooltip ('')
189 Button
.EnableBorder (0, 0)
191 if (CommonTables
.ClassSkills
.GetValue (GemRB
.GetPlayerStat (pc
, IE_CLASS
), 2)=="*") or \
192 GemRB
.GetPlayerStat (pc
, IE_STATE_ID
) & STATE_DEAD
:
193 Window
.SetVisible (WINDOW_GRAYED
)
195 Window
.SetVisible (WINDOW_VISIBLE
)
198 def MagePrevLevelPress ():
199 global MageSpellLevel
201 if MageSpellLevel
> 0:
202 MageSpellLevel
= MageSpellLevel
- 1
206 def MageNextLevelPress ():
207 global MageSpellLevel
209 if MageSpellLevel
< 8:
210 MageSpellLevel
= MageSpellLevel
+ 1
214 def RefreshMageLevel ():
215 global MageSpellLevel
217 MageSpellLevel
= GemRB
.GetVar ("MageSpellLevel")
221 def OnMageMemorizeSpell ():
222 pc
= GemRB
.GameGetSelectedPCSingle ()
223 level
= MageSpellLevel
224 type = IE_SPELL_TYPE_WIZARD
226 index
= GemRB
.GetVar ("SpellButton") - 100
228 if GemRB
.MemorizeSpell (pc
, type, level
, index
):
232 def OpenMageSpellInfoWindow ():
233 global MageSpellInfoWindow
235 if MageSpellInfoWindow
!= None:
236 if MageSpellInfoWindow
:
237 MageSpellInfoWindow
.Unload ()
238 MageSpellInfoWindow
= None
241 MageSpellInfoWindow
= Window
= GemRB
.LoadWindow (3)
244 Button
= Window
.GetControl (5)
245 Button
.SetText (15416)
246 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, OpenMageSpellInfoWindow
)
249 #Button = Window.GetControl (6)
250 index
= GemRB
.GetVar ("SpellButton")
252 ResRef
= MageMemorizedSpellList
[index
]
253 #Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, None)
254 #Button.SetFlags (IE_GUI_BUTTON_NO_IMAGE, OP_SET)
256 ResRef
= MageKnownSpellList
[index
- 100]
257 #Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, OpenMageSpellRemoveWindow)
258 #Button.SetText (63668)
260 spell
= GemRB
.GetSpell (ResRef
)
262 Label
= Window
.GetControl (0x0fffffff)
263 Label
.SetText (spell
['SpellName'])
265 Button
= Window
.GetControl (2)
266 Button
.SetSpellIcon (ResRef
, 1)
268 Text
= Window
.GetControl (3)
269 Text
.SetText (spell
['SpellDesc'])
271 Window
.ShowModal (MODAL_SHADOW_GRAY
)
274 def CloseMageSpellUnmemorizeWindow ():
275 global MageSpellUnmemorizeWindow
277 if MageSpellUnmemorizeWindow
:
278 MageSpellUnmemorizeWindow
.Unload ()
279 MageSpellUnmemorizeWindow
= None
282 def OpenMageSpellRemoveWindow ():
283 global MageSpellUnmemorizeWindow
285 MageSpellUnmemorizeWindow
= Window
= GemRB
.LoadWindow (5)
287 # "Are you sure you want to ....?"
288 TextArea
= Window
.GetControl (3)
289 TextArea
.SetText (63745)
292 Button
= Window
.GetControl (0)
293 Button
.SetText (17507)
294 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, OnMageRemoveSpell
)
297 Button
= Window
.GetControl (1)
298 Button
.SetText (13727)
299 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, CloseMageSpellUnmemorizeWindow
)
301 Window
.ShowModal (MODAL_SHADOW_GRAY
)
304 def OpenMageSpellUnmemorizeWindow ():
305 global MageSpellUnmemorizeWindow
307 MageSpellUnmemorizeWindow
= Window
= GemRB
.LoadWindow (5)
309 # "Are you sure you want to ....?"
310 TextArea
= Window
.GetControl (3)
311 TextArea
.SetText (11824)
314 Button
= Window
.GetControl (0)
315 Button
.SetText (17507)
316 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, OnMageUnmemorizeSpell
)
319 Button
= Window
.GetControl (1)
320 Button
.SetText (13727)
321 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, CloseMageSpellUnmemorizeWindow
)
323 Window
.ShowModal (MODAL_SHADOW_GRAY
)
326 def OnMageUnmemorizeSpell ():
327 if MageSpellUnmemorizeWindow
:
328 CloseMageSpellUnmemorizeWindow()
330 pc
= GemRB
.GameGetSelectedPCSingle ()
331 level
= MageSpellLevel
332 type = IE_SPELL_TYPE_WIZARD
334 index
= GemRB
.GetVar ("SpellButton")
336 if GemRB
.UnmemorizeSpell (pc
, type, level
, index
):
340 def OnMageRemoveSpell ():
341 CloseMageSpellUnmemorizeWindow()
342 OpenMageSpellInfoWindow()
344 pc
= GemRB
.GameGetSelectedPCSingle ()
345 level
= MageSpellLevel
346 type = IE_SPELL_TYPE_WIZARD
348 index
= GemRB
.GetVar ("SpellButton")-100
350 #remove spell from book
351 GemRB
.RemoveSpell (pc
, type, level
, index
)
355 ###################################################
356 # End of file GUIMG.py