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 # GUIPR.py - scripts to control the priest spells windows from the GUIPR winpack
23 ###################################################
28 from GUIDefines
import *
29 from ie_stats
import *
30 from ie_action
import ACT_CAST
33 PriestSpellInfoWindow
= None
35 PriestSpellUnmemorizeWindow
= None
38 OldPortraitWindow
= None
39 OldOptionsWindow
= None
41 def OpenPriestWindow ():
42 import GUICommonWindows
43 global PriestWindow
, OptionsWindow
, PortraitWindow
44 global OldPortraitWindow
, OldOptionsWindow
46 if GUICommon
.CloseOtherWindow (OpenPriestWindow
):
48 PriestWindow
.Unload ()
50 OptionsWindow
.Unload ()
52 PortraitWindow
.Unload ()
55 GemRB
.SetVar ("OtherWindow", -1)
56 GUICommon
.GameWindow
.SetVisible(WINDOW_VISIBLE
)
58 GUICommonWindows
.PortraitWindow
= OldPortraitWindow
59 OldPortraitWindow
= None
60 GUICommonWindows
.OptionsWindow
= OldOptionsWindow
61 OldOptionsWindow
= None
62 GUICommonWindows
.SetSelectionChangeHandler (None)
66 GUICommon
.GameWindow
.SetVisible(WINDOW_INVISIBLE
)
68 GemRB
.LoadWindowPack ("GUIPR", 640, 480)
69 PriestWindow
= Window
= GemRB
.LoadWindow (2)
70 GemRB
.SetVar ("OtherWindow", PriestWindow
.ID
)
71 #saving the original portrait window
72 OldOptionsWindow
= GUICommonWindows
.OptionsWindow
73 OptionsWindow
= GemRB
.LoadWindow (0)
74 GUICommonWindows
.MarkMenuButton (OptionsWindow
)
75 GUICommonWindows
.SetupMenuWindowControls (OptionsWindow
, 0, OpenPriestWindow
)
76 OptionsWindow
.SetFrame ()
77 OldPortraitWindow
= GUICommonWindows
.PortraitWindow
78 PortraitWindow
= GUICommonWindows
.OpenPortraitWindow (0)
80 Button
= Window
.GetControl (1)
81 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, PriestPrevLevelPress
)
83 Button
= Window
.GetControl (2)
84 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, PriestNextLevelPress
)
88 Button
= Window
.GetControl (55 + i
)
89 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, RefreshPriestLevel
)
90 Button
.SetFlags (IE_GUI_BUTTON_RADIOBUTTON
, OP_OR
)
93 Button
= Window
.GetControl (55 + i
)
94 Button
.SetVarAssoc ("PriestSpellLevel", i
)
96 # Setup memorized spells buttons
98 Button
= Window
.GetControl (3 + i
)
99 Button
.SetBorder (0,0,0,0,0,0,0,0,64,0,1)
100 Button
.SetSprites ("SPELFRAM",0,0,0,0,0)
101 Button
.SetFlags (IE_GUI_BUTTON_PICTURE
, OP_OR
)
102 Button
.SetState (IE_GUI_BUTTON_LOCKED
)
104 # Setup book spells buttons
106 Button
= Window
.GetControl (27 + i
)
107 Button
.SetFlags (IE_GUI_BUTTON_NO_IMAGE
, OP_OR
)
108 Button
.SetState (IE_GUI_BUTTON_LOCKED
)
110 GUICommonWindows
.SetSelectionChangeHandler (UpdatePriestWindow
)
111 UpdatePriestWindow ()
112 OptionsWindow
.SetVisible (WINDOW_VISIBLE
)
113 #bringing window front
114 Window
.SetVisible (WINDOW_FRONT
)
115 PortraitWindow
.SetVisible (WINDOW_VISIBLE
)
118 def UpdatePriestWindow ():
119 global PriestMemorizedSpellList
, PriestKnownSpellList
121 PriestMemorizedSpellList
= []
122 PriestKnownSpellList
= []
124 Window
= PriestWindow
125 pc
= GemRB
.GameGetSelectedPCSingle ()
126 type = IE_SPELL_TYPE_PRIEST
127 level
= PriestSpellLevel
128 max_mem_cnt
= GemRB
.GetMemorizableSpellsCount (pc
, type, level
)
130 Label
= Window
.GetControl (0x10000032)
131 GemRB
.SetToken("SPELLLEVEL", str(level
+1) )
132 Label
.SetText (10345)
134 Name
= GemRB
.GetPlayerName (pc
, 0)
135 Label
= Window
.GetControl (0x10000035)
138 mem_cnt
= GemRB
.GetMemorizedSpellsCount (pc
, type, level
)
140 Button
= Window
.GetControl (3 + i
)
142 ms
= GemRB
.GetMemorizedSpell (pc
, type, level
, i
)
143 Button
.SetSpellIcon (ms
['SpellResRef'], 0)
144 Button
.SetFlags (IE_GUI_BUTTON_NO_IMAGE
, OP_NAND
)
145 Button
.SetFlags (IE_GUI_BUTTON_PICTURE
, OP_OR
)
147 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, OpenPriestSpellUnmemorizeWindow
)
149 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, OnPriestUnmemorizeSpell
)
150 Button
.SetEvent (IE_GUI_BUTTON_ON_RIGHT_PRESS
, OpenPriestSpellInfoWindow
)
151 spell
= GemRB
.GetSpell (ms
['SpellResRef'])
152 Button
.SetTooltip (spell
['SpellName'])
153 PriestMemorizedSpellList
.append (ms
['SpellResRef'])
154 Button
.SetVarAssoc ("SpellButton", i
)
155 Button
.EnableBorder (0, ms
['Flags'] == 0)
158 Button
.SetFlags (IE_GUI_BUTTON_NORMAL
, OP_SET
)
160 Button
.SetFlags (IE_GUI_BUTTON_NO_IMAGE
, OP_SET
)
161 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, None)
162 Button
.SetEvent (IE_GUI_BUTTON_ON_RIGHT_PRESS
, None)
163 Button
.SetTooltip ('')
164 Button
.EnableBorder (0, 0)
167 known_cnt
= GemRB
.GetKnownSpellsCount (pc
, type, level
)
169 Button
= Window
.GetControl (27 + i
)
171 ks
= GemRB
.GetKnownSpell (pc
, type, level
, i
)
172 Button
.SetSpellIcon (ks
['SpellResRef'], 0)
173 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, OnPriestMemorizeSpell
)
174 Button
.SetEvent (IE_GUI_BUTTON_ON_RIGHT_PRESS
, OpenPriestSpellInfoWindow
)
175 spell
= GemRB
.GetSpell (ks
['SpellResRef'])
176 Button
.SetTooltip (spell
['SpellName'])
177 PriestKnownSpellList
.append (ks
['SpellResRef'])
178 Button
.SetVarAssoc ("SpellButton", 100 + i
)
181 Button
.SetFlags (IE_GUI_BUTTON_NO_IMAGE
, OP_OR
)
182 Button
.SetFlags (IE_GUI_BUTTON_PICTURE
, OP_NAND
)
183 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, None)
184 Button
.SetEvent (IE_GUI_BUTTON_ON_RIGHT_PRESS
, None)
185 Button
.SetTooltip ('')
186 Button
.EnableBorder (0, 0)
188 Class
= GemRB
.GetPlayerStat (pc
, IE_CLASS
)
189 DivineCaster
= CommonTables
.ClassSkills
.GetValue (Class
, 1)
190 if DivineCaster
== "*":
191 # also check the DRUIDSPELL column
192 DivineCaster
= CommonTables
.ClassSkills
.GetValue (Class
, 0)
193 CantCast
= DivineCaster
== "*" or GemRB
.GetPlayerStat(pc
, IE_DISABLEDBUTTON
)&(1<<ACT_CAST
)
194 if CantCast
or GemRB
.GetPlayerStat (pc
, IE_STATE_ID
) & STATE_DEAD
:
195 Window
.SetVisible (WINDOW_GRAYED
)
197 Window
.SetVisible (WINDOW_VISIBLE
)
200 def PriestPrevLevelPress ():
201 global PriestSpellLevel
203 if PriestSpellLevel
> 0:
204 PriestSpellLevel
= PriestSpellLevel
- 1
205 UpdatePriestWindow ()
208 def PriestNextLevelPress ():
209 global PriestSpellLevel
211 if PriestSpellLevel
< 6:
212 PriestSpellLevel
= PriestSpellLevel
+ 1
213 UpdatePriestWindow ()
216 def RefreshPriestLevel ():
217 global PriestSpellLevel
219 PriestSpellLevel
= GemRB
.GetVar ("PriestSpellLevel")
220 UpdatePriestWindow ()
223 def OpenPriestSpellInfoWindow ():
224 global PriestSpellInfoWindow
226 if PriestSpellInfoWindow
!= None:
227 if PriestSpellInfoWindow
:
228 PriestSpellInfoWindow
.Unload ()
229 PriestSpellInfoWindow
= None
232 PriestSpellInfoWindow
= Window
= GemRB
.LoadWindow (3)
235 Button
= Window
.GetControl (5)
236 Button
.SetText (15416)
237 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, OpenPriestSpellInfoWindow
)
239 index
= GemRB
.GetVar ("SpellButton")
241 ResRef
= PriestMemorizedSpellList
[index
]
243 ResRef
= PriestKnownSpellList
[index
- 100]
245 spell
= GemRB
.GetSpell (ResRef
)
247 Label
= Window
.GetControl (0x0fffffff)
248 Label
.SetText (spell
['SpellName'])
250 Button
= Window
.GetControl (2)
251 Button
.SetSpellIcon (ResRef
, 1)
253 Text
= Window
.GetControl (3)
254 Text
.SetText (spell
['SpellDesc'])
256 Window
.ShowModal (MODAL_SHADOW_GRAY
)
259 def OnPriestMemorizeSpell ():
260 pc
= GemRB
.GameGetSelectedPCSingle ()
261 level
= PriestSpellLevel
262 type = IE_SPELL_TYPE_PRIEST
264 index
= GemRB
.GetVar ("SpellButton") - 100
266 if GemRB
.MemorizeSpell (pc
, type, level
, index
):
267 UpdatePriestWindow ()
270 def OpenPriestSpellRemoveWindow ():
271 global PriestSpellUnmemorizeWindow
273 PriestSpellUnmemorizeWindow
= Window
= GemRB
.LoadWindow (5)
275 # "Are you sure you want to ....?"
276 TextArea
= Window
.GetControl (3)
277 TextArea
.SetText (11824)
280 Button
= Window
.GetControl (0)
281 Button
.SetText (17507)
282 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, OnPriestRemoveSpell
)
283 Button
.SetFlags (IE_GUI_BUTTON_DEFAULT
, OP_OR
)
286 Button
= Window
.GetControl (1)
287 Button
.SetText (13727)
288 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, ClosePriestSpellUnmemorizeWindow
)
289 Button
.SetFlags (IE_GUI_BUTTON_CANCEL
, OP_OR
)
291 Window
.ShowModal (MODAL_SHADOW_GRAY
)
294 def ClosePriestSpellUnmemorizeWindow ():
295 global PriestSpellUnmemorizeWindow
297 if PriestSpellUnmemorizeWindow
:
298 PriestSpellUnmemorizeWindow
.Unload ()
299 PriestSpellUnmemorizeWindow
= None
302 def OpenPriestSpellUnmemorizeWindow ():
303 global PriestSpellUnmemorizeWindow
305 PriestSpellUnmemorizeWindow
= Window
= GemRB
.LoadWindow (5)
307 # "Are you sure you want to ....?"
308 TextArea
= Window
.GetControl (3)
309 TextArea
.SetText (11824)
312 Button
= Window
.GetControl (0)
313 Button
.SetText (17507)
314 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, OnPriestUnmemorizeSpell
)
315 Button
.SetFlags (IE_GUI_BUTTON_DEFAULT
, OP_OR
)
318 Button
= Window
.GetControl (1)
319 Button
.SetText (13727)
320 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, ClosePriestSpellUnmemorizeWindow
)
321 Button
.SetFlags (IE_GUI_BUTTON_CANCEL
, OP_OR
)
323 Window
.ShowModal (MODAL_SHADOW_GRAY
)
326 def OnPriestUnmemorizeSpell ():
327 if PriestSpellUnmemorizeWindow
:
328 ClosePriestSpellUnmemorizeWindow ()
330 pc
= GemRB
.GameGetSelectedPCSingle ()
331 level
= PriestSpellLevel
332 type = IE_SPELL_TYPE_PRIEST
334 index
= GemRB
.GetVar ("SpellButton")
336 if GemRB
.UnmemorizeSpell (pc
, type, level
, index
):
337 UpdatePriestWindow ()
340 def OnPriestRemoveSpell ():
341 ClosePriestSpellUnmemorizeWindow()
342 OpenPriestSpellInfoWindow()
344 pc
= GemRB
.GameGetSelectedPCSingle ()
345 level
= PriestSpellLevel
346 type = IE_SPELL_TYPE_PRIEST
348 index
= GemRB
.GetVar ("SpellButton") - 100
350 #remove spell from book
351 GemRB
.RemoveSpell (pc
, type, level
, index
)
352 UpdatePriestWindow ()
355 ###################################################
356 # End of file GUIPR.py