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 ###################################################
26 import GUICommonWindows
27 from GUIDefines
import *
28 from ie_stats
import *
29 from GUICommon
import CloseOtherWindow
30 from GUICommon
import GameWindow
31 from GUICommonWindows
import *
34 PriestSpellInfoWindow
= None
36 PriestSpellUnmemorizeWindow
= None
39 OldPortraitWindow
= None
40 OldOptionsWindow
= None
42 def OpenPriestWindow ():
43 global PriestWindow
, OptionsWindow
, PortraitWindow
44 global OldPortraitWindow
, OldOptionsWindow
46 if CloseOtherWindow (OpenPriestWindow
):
48 PriestWindow
.Unload ()
50 OptionsWindow
.Unload ()
52 PortraitWindow
.Unload ()
55 GemRB
.SetVar ("OtherWindow", -1)
56 GameWindow
.SetVisible(WINDOW_VISIBLE
)
58 GUICommonWindows
.PortraitWindow
= OldPortraitWindow
59 OldPortraitWindow
= None
60 GUICommonWindows
.OptionsWindow
= OldOptionsWindow
61 OldOptionsWindow
= None
62 SetSelectionChangeHandler (None)
66 GameWindow
.SetVisible(WINDOW_INVISIBLE
)
68 GemRB
.LoadWindowPack ("GUIPR", 640, 480)
69 PriestWindow
= Window
= GemRB
.LoadWindowObject (2)
70 GemRB
.SetVar ("OtherWindow", PriestWindow
.ID
)
71 #saving the original portrait window
72 OldOptionsWindow
= GUICommonWindows
.OptionsWindow
73 OptionsWindow
= GemRB
.LoadWindowObject (0)
74 MarkMenuButton (OptionsWindow
)
75 SetupMenuWindowControls (OptionsWindow
, 0, "OpenPriestWindow")
76 OptionsWindow
.SetFrame ()
77 OldPortraitWindow
= GUICommonWindows
.PortraitWindow
78 PortraitWindow
= 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 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
, "")
162 Button
.SetEvent (IE_GUI_BUTTON_ON_RIGHT_PRESS
, "")
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
, "")
184 Button
.SetEvent (IE_GUI_BUTTON_ON_RIGHT_PRESS
, "")
185 Button
.SetTooltip ('')
186 Button
.EnableBorder (0, 0)
188 Class
= GemRB
.GetPlayerStat (GemRB
.GameGetSelectedPCSingle(), IE_CLASS
)
189 DivineCaster
= ClassSkillsTable
.GetValue (Class
, 1)
190 if DivineCaster
== "*":
191 # also check the DRUIDSPELL column
192 DivineCaster
= ClassSkillsTable
.GetValue (Class
, 0)
193 if DivineCaster
== "*":
194 Window
.SetVisible (WINDOW_GRAYED
)
196 Window
.SetVisible (WINDOW_VISIBLE
)
199 def PriestPrevLevelPress ():
200 global PriestSpellLevel
202 if PriestSpellLevel
> 0:
203 PriestSpellLevel
= PriestSpellLevel
- 1
204 UpdatePriestWindow ()
207 def PriestNextLevelPress ():
208 global PriestSpellLevel
210 if PriestSpellLevel
< 6:
211 PriestSpellLevel
= PriestSpellLevel
+ 1
212 UpdatePriestWindow ()
215 def RefreshPriestLevel ():
216 global PriestSpellLevel
218 PriestSpellLevel
= GemRB
.GetVar ("PriestSpellLevel")
219 UpdatePriestWindow ()
222 def OpenPriestSpellInfoWindow ():
223 global PriestSpellInfoWindow
225 if PriestSpellInfoWindow
!= None:
226 if PriestSpellInfoWindow
:
227 PriestSpellInfoWindow
.Unload ()
228 PriestSpellInfoWindow
= None
231 PriestSpellInfoWindow
= Window
= GemRB
.LoadWindowObject (3)
234 Button
= Window
.GetControl (5)
235 Button
.SetText (15416)
236 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, "OpenPriestSpellInfoWindow")
238 index
= GemRB
.GetVar ("SpellButton")
240 ResRef
= PriestMemorizedSpellList
[index
]
242 ResRef
= PriestKnownSpellList
[index
- 100]
244 spell
= GemRB
.GetSpell (ResRef
)
246 Label
= Window
.GetControl (0x0fffffff)
247 Label
.SetText (spell
['SpellName'])
249 Button
= Window
.GetControl (2)
250 Button
.SetSpellIcon (ResRef
, 1)
252 Text
= Window
.GetControl (3)
253 Text
.SetText (spell
['SpellDesc'])
255 Window
.ShowModal (MODAL_SHADOW_GRAY
)
258 def OnPriestMemorizeSpell ():
259 pc
= GemRB
.GameGetSelectedPCSingle ()
260 level
= PriestSpellLevel
261 type = IE_SPELL_TYPE_PRIEST
263 index
= GemRB
.GetVar ("SpellButton") - 100
265 if GemRB
.MemorizeSpell (pc
, type, level
, index
):
266 UpdatePriestWindow ()
269 def OpenPriestSpellRemoveWindow ():
270 global PriestSpellUnmemorizeWindow
272 PriestSpellUnmemorizeWindow
= Window
= GemRB
.LoadWindowObject (5)
274 # "Are you sure you want to ....?"
275 TextArea
= Window
.GetControl (3)
276 TextArea
.SetText (11824)
279 Button
= Window
.GetControl (0)
280 Button
.SetText (17507)
281 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, "OnPriestRemoveSpell")
282 Button
.SetFlags (IE_GUI_BUTTON_DEFAULT
, OP_OR
)
285 Button
= Window
.GetControl (1)
286 Button
.SetText (13727)
287 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, "ClosePriestSpellUnmemorizeWindow")
288 Button
.SetFlags (IE_GUI_BUTTON_CANCEL
, OP_OR
)
290 Window
.ShowModal (MODAL_SHADOW_GRAY
)
293 def ClosePriestSpellUnmemorizeWindow ():
294 global PriestSpellUnmemorizeWindow
296 if PriestSpellUnmemorizeWindow
:
297 PriestSpellUnmemorizeWindow
.Unload ()
298 PriestSpellUnmemorizeWindow
= None
301 def OpenPriestSpellUnmemorizeWindow ():
302 global PriestSpellUnmemorizeWindow
304 PriestSpellUnmemorizeWindow
= Window
= GemRB
.LoadWindowObject (5)
306 # "Are you sure you want to ....?"
307 TextArea
= Window
.GetControl (3)
308 TextArea
.SetText (11824)
311 Button
= Window
.GetControl (0)
312 Button
.SetText (17507)
313 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, "OnPriestUnmemorizeSpell")
314 Button
.SetFlags (IE_GUI_BUTTON_DEFAULT
, OP_OR
)
317 Button
= Window
.GetControl (1)
318 Button
.SetText (13727)
319 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, "ClosePriestSpellUnmemorizeWindow")
320 Button
.SetFlags (IE_GUI_BUTTON_CANCEL
, OP_OR
)
322 Window
.ShowModal (MODAL_SHADOW_GRAY
)
325 def OnPriestUnmemorizeSpell ():
326 if PriestSpellUnmemorizeWindow
:
327 ClosePriestSpellUnmemorizeWindow ()
329 pc
= GemRB
.GameGetSelectedPCSingle ()
330 level
= PriestSpellLevel
331 type = IE_SPELL_TYPE_PRIEST
333 index
= GemRB
.GetVar ("SpellButton")
335 if GemRB
.UnmemorizeSpell (pc
, type, level
, index
):
336 UpdatePriestWindow ()
339 def OnPriestRemoveSpell ():
340 ClosePriestSpellUnmemorizeWindow()
341 OpenPriestSpellInfoWindow()
343 pc
= GemRB
.GameGetSelectedPCSingle ()
344 level
= PriestSpellLevel
345 type = IE_SPELL_TYPE_PRIEST
347 index
= GemRB
.GetVar ("SpellButton") - 100
349 #remove spell from book
350 GemRB
.RemoveSpell (pc
, type, level
, index
)
351 UpdatePriestWindow ()
354 ###################################################
355 # End of file GUIPR.py