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 # GUIPR.py - scripts to control priest spells windows from GUIPR winpack
23 ###################################################
26 import GUICommonWindows
27 from GUIDefines
import *
28 from ie_stats
import *
29 from GUICommon
import CloseOtherWindow
, GetIWDSpellButtonCount
, ClassSkillsTable
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
.LoadWindow (2)
70 GemRB
.SetVar ("OtherWindow", PriestWindow
.ID
)
71 #saving the original portrait window
72 OldOptionsWindow
= GUICommonWindows
.OptionsWindow
73 OptionsWindow
= GemRB
.LoadWindow (0)
74 SetupMenuWindowControls (OptionsWindow
, 0, "OpenPriestWindow")
75 OptionsWindow
.SetFrame ()
76 OldPortraitWindow
= GUICommonWindows
.PortraitWindow
77 PortraitWindow
= OpenPortraitWindow (0)
79 Button
= Window
.GetControl (1)
80 Button
.SetEventByName (IE_GUI_BUTTON_ON_PRESS
, "PriestPrevLevelPress")
82 Button
= Window
.GetControl (2)
83 Button
.SetEventByName (IE_GUI_BUTTON_ON_PRESS
, "PriestNextLevelPress")
85 # Setup memorized spells buttons
87 Button
= Window
.GetControl (3 + i
)
88 Button
.SetBorder (0,0,0,0,0,0,0,0,64,0,1)
89 Button
.SetSprites ("SPELFRAM",0,0,0,0,0)
90 Button
.SetFlags (IE_GUI_BUTTON_PICTURE
, OP_OR
)
91 Button
.SetState (IE_GUI_BUTTON_LOCKED
)
93 # Setup book spells buttons
94 for i
in range (GetIWDSpellButtonCount()):
95 Button
= Window
.GetControl (27 + i
)
96 Button
.SetFlags (IE_GUI_BUTTON_NO_IMAGE
, OP_OR
)
97 Button
.SetState (IE_GUI_BUTTON_LOCKED
)
99 SetSelectionChangeHandler (UpdatePriestWindow
)
100 UpdatePriestWindow ()
101 OptionsWindow
.SetVisible (WINDOW_VISIBLE
)
102 #bringing window front
103 Window
.SetVisible (WINDOW_FRONT
)
104 PortraitWindow
.SetVisible (WINDOW_VISIBLE
)
107 def UpdatePriestWindow ():
108 global PriestMemorizedSpellList
, PriestKnownSpellList
110 PriestMemorizedSpellList
= []
111 PriestKnownSpellList
= []
113 Window
= PriestWindow
114 pc
= GemRB
.GameGetSelectedPCSingle ()
115 type = IE_SPELL_TYPE_PRIEST
116 level
= PriestSpellLevel
117 max_mem_cnt
= GemRB
.GetMemorizableSpellsCount (pc
, type, level
)
119 Label
= Window
.GetControl (0x10000032)
120 GemRB
.SetToken ('LEVEL', str (level
+ 1))
121 Label
.SetText (12137)
123 Name
= GemRB
.GetPlayerName (pc
, 0)
124 Label
= Window
.GetControl (0x10000035)
127 mem_cnt
= GemRB
.GetMemorizedSpellsCount (pc
, type, level
)
129 Button
= Window
.GetControl (3 + i
)
131 ms
= GemRB
.GetMemorizedSpell (pc
, type, level
, i
)
132 Button
.SetSpellIcon (ms
['SpellResRef'], 0)
133 Button
.SetFlags (IE_GUI_BUTTON_NO_IMAGE
, OP_NAND
)
134 Button
.SetFlags (IE_GUI_BUTTON_PICTURE
, OP_OR
)
136 Button
.SetEventByName (IE_GUI_BUTTON_ON_PRESS
, "OpenPriestSpellUnmemorizeWindow")
138 Button
.SetEventByName (IE_GUI_BUTTON_ON_PRESS
, "OnPriestUnmemorizeSpell")
139 Button
.SetEventByName (IE_GUI_BUTTON_ON_RIGHT_PRESS
, "OpenPriestSpellInfoWindow")
140 spell
= GemRB
.GetSpell (ms
['SpellResRef'])
141 Button
.SetTooltip (spell
['SpellName'])
142 PriestMemorizedSpellList
.append (ms
['SpellResRef'])
143 Button
.SetVarAssoc ("SpellButton", i
)
144 Button
.EnableBorder (0, ms
['Flags'] == 0)
147 Button
.SetFlags (IE_GUI_BUTTON_NORMAL
, OP_SET
)
149 Button
.SetFlags (IE_GUI_BUTTON_NO_IMAGE
, OP_SET
)
150 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, None)
151 Button
.SetEvent (IE_GUI_BUTTON_ON_RIGHT_PRESS
, None)
152 Button
.SetTooltip ('')
153 Button
.EnableBorder (0, 0)
156 known_cnt
= GemRB
.GetKnownSpellsCount (pc
, type, level
)
157 for i
in range (GetIWDSpellButtonCount()):
158 Button
= Window
.GetControl (27 + i
)
160 ks
= GemRB
.GetKnownSpell (pc
, type, level
, i
)
161 Button
.SetSpellIcon (ks
['SpellResRef'], 0)
162 Button
.SetFlags (IE_GUI_BUTTON_NO_IMAGE
, OP_NAND
)
163 Button
.SetEventByName (IE_GUI_BUTTON_ON_PRESS
, "OnPriestMemorizeSpell")
164 Button
.SetEventByName (IE_GUI_BUTTON_ON_RIGHT_PRESS
, "OpenPriestSpellInfoWindow")
165 spell
= GemRB
.GetSpell (ks
['SpellResRef'])
166 Button
.SetTooltip (spell
['SpellName'])
167 PriestKnownSpellList
.append (ks
['SpellResRef'])
168 Button
.SetVarAssoc ("SpellButton", 100 + i
)
171 Button
.SetFlags (IE_GUI_BUTTON_NO_IMAGE
, OP_OR
)
172 Button
.SetFlags (IE_GUI_BUTTON_PICTURE
, OP_NAND
)
173 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, None)
174 Button
.SetEvent (IE_GUI_BUTTON_ON_RIGHT_PRESS
, None)
175 Button
.SetTooltip ('')
176 Button
.EnableBorder (0, 0)
177 if (ClassSkillsTable
.GetValue (GemRB
.GetPlayerStat( GemRB
.GameGetSelectedPCSingle(), IE_CLASS
), 1)=="*"):
178 Window
.SetVisible (WINDOW_GRAYED
)
180 Window
.SetVisible (WINDOW_VISIBLE
)
183 def PriestPrevLevelPress ():
184 global PriestSpellLevel
186 if PriestSpellLevel
> 0:
187 PriestSpellLevel
= PriestSpellLevel
- 1
188 UpdatePriestWindow ()
191 def PriestNextLevelPress ():
192 global PriestSpellLevel
194 if PriestSpellLevel
< 6:
195 PriestSpellLevel
= PriestSpellLevel
+ 1
196 UpdatePriestWindow ()
199 def RefreshPriestLevel ():
200 global PriestSpellLevel
202 PriestSpellLevel
= GemRB
.GetVar ("PriestSpellLevel")
203 UpdatePriestWindow ()
206 def OpenPriestSpellInfoWindow ():
207 global PriestSpellInfoWindow
209 if PriestSpellInfoWindow
!= None:
210 if PriestSpellInfoWindow
:
211 PriestSpellInfoWindow
.Unload ()
212 PriestSpellInfoWindow
= None
215 PriestSpellInfoWindow
= Window
= GemRB
.LoadWindow (3)
218 Button
= Window
.GetControl (5)
219 Button
.SetText (15416)
220 Button
.SetEventByName (IE_GUI_BUTTON_ON_PRESS
, "OpenPriestSpellInfoWindow")
222 index
= GemRB
.GetVar ("SpellButton")
224 ResRef
= PriestMemorizedSpellList
[index
]
226 ResRef
= PriestKnownSpellList
[index
- 100]
228 spell
= GemRB
.GetSpell (ResRef
)
230 #Label = Window.GetControl (0x0fffffff)
231 #Label.SetText (spell['SpellName'])
233 Label
= Window
.GetControl (0x10000000)
234 Label
.SetText (spell
['SpellName'])
236 Button
= Window
.GetControl (2)
237 Button
.SetSpellIcon (ResRef
, 1)
239 Text
= Window
.GetControl (3)
240 Text
.SetText (spell
['SpellDesc'])
242 Window
.ShowModal (MODAL_SHADOW_GRAY
)
245 def OnPriestMemorizeSpell ():
246 pc
= GemRB
.GameGetSelectedPCSingle ()
247 level
= PriestSpellLevel
248 type = IE_SPELL_TYPE_PRIEST
250 index
= GemRB
.GetVar ("SpellButton") - 100
252 if GemRB
.MemorizeSpell (pc
, type, level
, index
):
253 UpdatePriestWindow ()
256 def OpenPriestSpellRemoveWindow ():
257 global PriestSpellUnmemorizeWindow
259 PriestSpellUnmemorizeWindow
= Window
= GemRB
.LoadWindow (5)
261 # "Are you sure you want to ....?"
262 TextArea
= Window
.GetControl (3)
263 TextArea
.SetText (63745)
266 Button
= Window
.GetControl (0)
267 Button
.SetText (17507)
268 Button
.SetEventByName (IE_GUI_BUTTON_ON_PRESS
, "OnPriestRemoveSpell")
269 Button
.SetFlags (IE_GUI_BUTTON_DEFAULT
, OP_OR
)
272 Button
= Window
.GetControl (1)
273 Button
.SetText (13727)
274 Button
.SetEventByName (IE_GUI_BUTTON_ON_PRESS
, "ClosePriestSpelliUnmemorizeWindow")
275 Button
.SetFlags (IE_GUI_BUTTON_CANCEL
, OP_OR
)
277 Window
.ShowModal (MODAL_SHADOW_GRAY
)
280 def ClosePriestSpellUnmemorizeWindow ():
281 global PriestSpellUnmemorizeWindow
283 if PriestSpellUnmemorizeWindow
:
284 PriestSpellUnmemorizeWindow
.Unload ()
285 PriestSpellUnmemorizeWindow
= None
288 def OpenPriestSpellUnmemorizeWindow ():
289 global PriestSpellUnmemorizeWindow
291 PriestSpellUnmemorizeWindow
= Window
= GemRB
.LoadWindow (5)
293 # "Are you sure you want to ....?"
294 TextArea
= Window
.GetControl (3)
295 TextArea
.SetText (11824)
298 Button
= Window
.GetControl (0)
299 Button
.SetText (17507)
300 Button
.SetEventByName (IE_GUI_BUTTON_ON_PRESS
, "OnPriestUnmemorizeSpell")
301 Button
.SetFlags (IE_GUI_BUTTON_DEFAULT
, OP_OR
)
304 Button
= Window
.GetControl (1)
305 Button
.SetText (13727)
306 Button
.SetEventByName (IE_GUI_BUTTON_ON_PRESS
, "ClosePriestSpellUnmemorizeWindow")
307 Button
.SetFlags (IE_GUI_BUTTON_CANCEL
, OP_OR
)
309 Window
.ShowModal (MODAL_SHADOW_GRAY
)
312 def OnPriestUnmemorizeSpell ():
313 if PriestSpellUnmemorizeWindow
:
314 ClosePriestSpellUnmemorizeWindow ()
316 pc
= GemRB
.GameGetSelectedPCSingle ()
317 level
= PriestSpellLevel
318 type = IE_SPELL_TYPE_PRIEST
320 index
= GemRB
.GetVar ("SpellButton")
322 if GemRB
.UnmemorizeSpell (pc
, type, level
, index
):
323 UpdatePriestWindow ()
326 def OnPriestRemoveSpell ():
327 if PriestSpellUnmemorizeWindow
:
328 ClosePriestSpellRemoveWindow ()
330 pc
= GemRB
.GameGetSelectedPCSingle ()
331 level
= PriestSpellLevel
332 type = IE_SPELL_TYPE_PRIEST
334 index
= GemRB
.GetVar ("SpellButton") - 100
336 #remove spell from book
337 GemRB
.RemoveSpell (pc
, type, level
, index
)
338 UpdatePriestWindow ()
341 ###################################################
342 # End of file GUIPR.py