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
36 OldOptionsWindow
= None
39 def OpenMageWindow ():
40 global MageWindow
, OptionsWindow
41 global OldOptionsWindow
43 if GUICommon
.CloseOtherWindow (OpenMageWindow
):
47 OptionsWindow
.Unload ()
49 GemRB
.SetVar ("OtherWindow", -1)
50 GUICommon
.GameWindow
.SetVisible(WINDOW_VISIBLE
)
52 OptionsWindow
= OldOptionsWindow
53 OldOptionsWindow
= None
54 GUICommonWindows
.SetSelectionChangeHandler(None)
58 GUICommon
.GameWindow
.SetVisible(WINDOW_INVISIBLE
)
59 GemRB
.LoadWindowPack ("GUIMG")
60 MageWindow
= Window
= GemRB
.LoadWindow (2)
61 GemRB
.SetVar ("OtherWindow", MageWindow
.ID
)
62 OldOptionsWindow
= GUICommonWindows
.OptionsWindow
63 OptionsWindow
= GemRB
.LoadWindow (0)
64 GUICommonWindows
.SetupMenuWindowControls (OptionsWindow
, 0, OpenMageWindow
)
65 OptionsWindow
.SetFrame ()
67 Button
= Window
.GetControl (1)
68 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, MagePrevLevelPress
)
70 Button
= Window
.GetControl (2)
71 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, MageNextLevelPress
)
74 ## Button = Window.GetControl (55)
75 ## Button.SetState (IE_GUI_BUTTON_LOCKED)
76 ## #Button.SetText (123)
77 ## #Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, xxPress)
79 ## #setup level buttons
80 ## for i in range (9):
81 ## Button = Window.GetControl (56 + i)
82 ## Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, RefreshMageLevel)
83 ## Button.SetFlags (IE_GUI_BUTTON_RADIOBUTTON, OP_OR)
85 ## for i in range (9):
86 ## Button = Window.GetControl (56 + i)
87 ## Button.SetVarAssoc ("MageSpellLevel", i)
89 # Setup memorized spells buttons
91 Button
= Window
.GetControl (3 + i
)
92 Button
.SetBorder (0,0,0,0,0,0,0,0,64,0,1)
93 Button
.SetSprites ("SPELFRAM",0,0,0,0,0)
94 Button
.SetFlags (IE_GUI_BUTTON_PICTURE
, OP_OR
)
95 Button
.SetState (IE_GUI_BUTTON_LOCKED
)
97 # Setup book spells buttons
99 Button
= Window
.GetControl (27 + i
)
100 Button
.SetFlags (IE_GUI_BUTTON_NO_IMAGE
, OP_OR
)
101 Button
.SetState (IE_GUI_BUTTON_LOCKED
)
103 GUICommonWindows
.SetSelectionChangeHandler (UpdateMageWindow
)
106 OptionsWindow
.SetVisible (WINDOW_VISIBLE
)
107 Window
.SetVisible (WINDOW_FRONT
)
108 GUICommonWindows
.PortraitWindow
.SetVisible (WINDOW_VISIBLE
)
112 def UpdateMageWindow ():
113 global MageMemorizedSpellList
, MageKnownSpellList
115 MageMemorizedSpellList
= []
116 MageKnownSpellList
= []
119 pc
= GemRB
.GameGetSelectedPCSingle ()
120 type = IE_SPELL_TYPE_WIZARD
121 level
= MageSpellLevel
122 max_mem_cnt
= GemRB
.GetMemorizableSpellsCount (pc
, type, level
)
124 Label
= Window
.GetControl (0x10000032)
125 GemRB
.SetToken ('LEVEL', str (level
+ 1))
126 Label
.SetText (12137 )
128 Name
= GemRB
.GetPlayerName (pc
, 0)
129 Label
= Window
.GetControl (0x10000035)
132 mem_cnt
= GemRB
.GetMemorizedSpellsCount (pc
, type, level
)
134 Button
= Window
.GetControl (3 + i
)
136 ms
= GemRB
.GetMemorizedSpell (pc
, type, level
, i
)
137 Button
.SetSpellIcon (ms
['SpellResRef'], 0)
138 Button
.SetFlags (IE_GUI_BUTTON_NO_IMAGE
, OP_NAND
)
139 Button
.SetFlags (IE_GUI_BUTTON_PICTURE
, OP_OR
)
141 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, OpenMageSpellUnmemorizeWindow
)
143 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, OnMageUnmemorizeSpell
)
144 Button
.SetEvent (IE_GUI_BUTTON_ON_RIGHT_PRESS
, OpenMageSpellInfoWindow
)
145 spell
= GemRB
.GetSpell (ms
['SpellResRef'])
146 Button
.SetTooltip (spell
['SpellName'])
147 MageMemorizedSpellList
.append (ms
['SpellResRef'])
148 Button
.SetVarAssoc ("SpellButton", i
)
149 Button
.EnableBorder (0, ms
['Flags'] == 0)
152 Button
.SetFlags (IE_GUI_BUTTON_NORMAL
, OP_SET
)
154 Button
.SetFlags (IE_GUI_BUTTON_NO_IMAGE
, OP_SET
)
155 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, None)
156 Button
.SetEvent (IE_GUI_BUTTON_ON_RIGHT_PRESS
, None)
157 Button
.SetTooltip ('')
158 Button
.EnableBorder (0, 0)
161 known_cnt
= GemRB
.GetKnownSpellsCount (pc
, type, level
)
163 Button
= Window
.GetControl (27 + i
)
165 ks
= GemRB
.GetKnownSpell (pc
, type, level
, i
)
166 Button
.SetSpellIcon (ks
['SpellResRef'], 0)
167 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, OnMageMemorizeSpell
)
168 Button
.SetEvent (IE_GUI_BUTTON_ON_RIGHT_PRESS
, OpenMageSpellInfoWindow
)
169 spell
= GemRB
.GetSpell (ks
['SpellResRef'])
170 Button
.SetTooltip (spell
['SpellName'])
171 MageKnownSpellList
.append (ks
['SpellResRef'])
172 Button
.SetVarAssoc ("SpellButton", 100 + i
)
175 Button
.SetFlags (IE_GUI_BUTTON_PICTURE
, OP_NAND
)
176 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, None)
177 Button
.SetEvent (IE_GUI_BUTTON_ON_RIGHT_PRESS
, None)
178 Button
.SetTooltip ('')
179 Button
.EnableBorder (0, 0)
181 if (CommonTables
.ClassSkills
.GetValue (GemRB
.GetPlayerStat (pc
, IE_CLASS
), 2)=="*") or \
182 GemRB
.GetPlayerStat (pc
, IE_STATE_ID
) & STATE_DEAD
:
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
.LoadWindow (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.LoadWindow (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
.LoadWindow (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