TickHook: Fix crash when TickHook isn't set.
[gemrb.git] / gemrb / GUIScripts / iwd / GUIWORLD.py
blob2379322afce8b82f41866ed3bdac9e8da908447f
1 # -*-python-*-
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 # GUIW.py - scripts to control some windows from GUIWORLD winpack
22 # except of Actions, Portrait, Options and Dialog windows
23 #################################################################
25 import GemRB
26 from GUIDefines import *
27 from ie_restype import *
28 import GUICommon
29 import GUICommonWindows
30 import GUIClasses
32 FRAME_PC_SELECTED = 0
33 FRAME_PC_TARGET = 1
35 ContinueWindow = None
36 ReformPartyWindow = None
37 OldActionsWindow = None
38 OldMessageWindow = None
40 def CloseContinueWindow ():
41 if ContinueWindow:
42 # don't close the actual window now to avoid flickering: we might still want it open
43 GemRB.SetVar ("DialogChoose", GemRB.GetVar ("DialogOption"))
45 def NextDialogState ():
46 global ContinueWindow, OldActionsWindow
48 if ContinueWindow == None:
49 return
51 hideflag = GemRB.HideGUI ()
53 if ContinueWindow:
54 ContinueWindow.Unload ()
55 GemRB.SetVar ("ActionsWindow", OldActionsWindow.ID)
56 ContinueWindow = None
57 OldActionsWindow = None
58 if hideflag:
59 GemRB.UnhideGUI ()
62 def OpenEndMessageWindow ():
63 global ContinueWindow, OldActionsWindow
65 hideflag = GemRB.HideGUI ()
67 if not ContinueWindow:
68 GemRB.LoadWindowPack (GUICommon.GetWindowPack())
69 ContinueWindow = Window = GemRB.LoadWindow (9)
70 OldActionsWindow = GUIClasses.GWindow( GemRB.GetVar ("ActionsWindow") )
71 GemRB.SetVar ("ActionsWindow", Window.ID)
73 #end dialog
74 Button = ContinueWindow.GetControl (0)
75 Button.SetText (9371)
76 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, CloseContinueWindow)
77 if GUICommonWindows.PortraitWindow:
78 GUICommonWindows.UpdatePortraitWindow ()
79 if hideflag:
80 GemRB.UnhideGUI ()
83 def OpenContinueMessageWindow ():
84 global ContinueWindow, OldActionsWindow
86 hideflag = GemRB.HideGUI ()
88 if not ContinueWindow:
89 GemRB.LoadWindowPack (GUICommon.GetWindowPack())
90 ContinueWindow = Window = GemRB.LoadWindow (9)
91 OldActionsWindow = GUIClasses.GWindow( GemRB.GetVar ("ActionsWindow") )
92 GemRB.SetVar ("ActionsWindow", Window.ID)
94 #continue
95 Button = ContinueWindow.GetControl (0)
96 Button.SetText (9372)
97 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, CloseContinueWindow)
98 if hideflag:
99 GemRB.UnhideGUI ()
101 def UpdateReformWindow ():
102 Window = ReformPartyWindow
104 select = GemRB.GetVar ("Selected")
106 need_to_drop = GemRB.GetPartySize ()-PARTY_SIZE
107 if need_to_drop<0:
108 need_to_drop = 0
110 #excess player number
111 Label = Window.GetControl (0x1000000f)
112 Label.SetText (str(need_to_drop) )
114 #done
115 Button = Window.GetControl (8)
116 if need_to_drop:
117 Button.SetState (IE_GUI_BUTTON_DISABLED)
118 else:
119 Button.SetState (IE_GUI_BUTTON_ENABLED)
121 #remove
122 Button = Window.GetControl (15)
123 if select:
124 Button.SetState (IE_GUI_BUTTON_ENABLED)
125 else:
126 Button.SetState (IE_GUI_BUTTON_DISABLED)
128 for i in range (PARTY_SIZE+1):
129 Button = Window.GetControl (i)
130 Button.EnableBorder (FRAME_PC_SELECTED, select == i+2 )
131 #+2 because protagonist is skipped
132 pic = GemRB.GetPlayerPortrait (i+2,1)
133 if not pic:
134 Button.SetFlags (IE_GUI_BUTTON_NO_IMAGE, OP_SET)
135 Button.SetState (IE_GUI_BUTTON_LOCKED)
136 continue
138 Button.SetState (IE_GUI_BUTTON_ENABLED)
139 Button.SetFlags (IE_GUI_BUTTON_PICTURE|IE_GUI_BUTTON_ALIGN_BOTTOM|IE_GUI_BUTTON_ALIGN_LEFT, OP_SET)
140 Button.SetPicture (pic, "NOPORTSM")
141 GUICommonWindows.UpdatePortraitWindow ()
142 return
144 def RemovePlayer ():
145 global ReformPartyWindow
147 hideflag = GemRB.HideGUI ()
149 GemRB.LoadWindowPack (GUICommon.GetWindowPack())
150 if ReformPartyWindow:
151 ReformPartyWindow.Unload ()
152 ReformPartyWindow = Window = GemRB.LoadWindow (25)
153 GemRB.SetVar ("OtherWindow", Window.ID)
155 #are you sure
156 Label = Window.GetControl (0x0fffffff)
157 Label.SetText (17518)
159 #confirm
160 Button = Window.GetControl (1)
161 Button.SetText (17507)
162 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, RemovePlayerConfirm)
163 Button.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
165 #cancel
166 Button = Window.GetControl (2)
167 Button.SetText (13727)
168 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, RemovePlayerCancel)
169 Button.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
171 def RemovePlayerConfirm ():
172 global ReformPartyWindow
174 hideflag = GemRB.HideGUI ()
175 if ReformPartyWindow:
176 ReformPartyWindow.Unload ()
177 GemRB.SetVar ("OtherWindow", -1)
178 #removing selected player
179 ReformPartyWindow = None
180 if hideflag:
181 GemRB.UnhideGUI ()
182 GemRB.LeaveParty (GemRB.GetVar("Selected") )
183 OpenReformPartyWindow ()
184 return
186 def RemovePlayerCancel ():
187 global ReformPartyWindow
189 hideflag = GemRB.HideGUI ()
190 if ReformPartyWindow:
191 ReformPartyWindow.Unload ()
192 GemRB.SetVar ("OtherWindow", -1)
193 ReformPartyWindow = None
194 if hideflag:
195 GemRB.UnhideGUI ()
196 OpenReformPartyWindow ()
197 return
199 def OpenReformPartyWindow ():
200 global ReformPartyWindow
202 GemRB.SetVar ("Selected", 0)
203 hideflag = GemRB.HideGUI ()
205 if ReformPartyWindow:
206 if ReformPartyWindow:
207 ReformPartyWindow.Unload ()
208 ReformPartyWindow = None
210 GemRB.SetVar ("OtherWindow", -1)
211 #GemRB.LoadWindowPack ("GUIREC")
212 if hideflag:
213 GemRB.UnhideGUI ()
214 #re-enabling party size control
215 GemRB.GameSetPartySize (PARTY_SIZE)
216 return
218 GemRB.LoadWindowPack (GUICommon.GetWindowPack())
219 ReformPartyWindow = Window = GemRB.LoadWindow (24)
220 GemRB.SetVar ("OtherWindow", Window.ID)
222 #PC portraits
223 for j in range (PARTY_SIZE+1):
224 Button = Window.GetControl (j)
225 Button.SetState (IE_GUI_BUTTON_LOCKED)
226 Button.SetFlags (IE_GUI_BUTTON_RADIOBUTTON|IE_GUI_BUTTON_NO_IMAGE|IE_GUI_BUTTON_PICTURE,OP_SET)
227 Button.SetBorder (FRAME_PC_SELECTED, 1, 1, 2, 2, 0, 255, 0, 255)
228 #protagonist is skipped
229 index = j + 2
230 Button.SetVarAssoc ("Selected", index)
231 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, UpdateReformWindow)
233 # Remove
234 Button = Window.GetControl (15)
235 Button.SetText (17507)
236 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, RemovePlayer)
238 # Done
239 Button = Window.GetControl (8)
240 Button.SetText (11973)
241 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, OpenReformPartyWindow)
242 GemRB.SetVar ("ActionsWindow", -1)
243 UpdateReformWindow ()
244 if hideflag:
245 GemRB.UnhideGUI ()
246 Window.ShowModal (MODAL_SHADOW_GRAY)
247 return
249 def DeathWindow ():
250 #no death movie, but music is changed
251 GemRB.LoadMusicPL ("Theme.mus",1)
252 GemRB.HideGUI ()
253 GemRB.SetTimedEvent (DeathWindowEnd, 10)
254 return
256 def DeathWindowEnd ():
257 GemRB.GamePause (1,1)
259 GemRB.LoadWindowPack (GUICommon.GetWindowPack())
260 Window = GemRB.LoadWindow (17)
262 #reason for death
263 Label = Window.GetControl (0x0fffffff)
264 Label.SetText (16498)
266 #load
267 Button = Window.GetControl (1)
268 Button.SetText (15590)
269 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, LoadPress)
271 #quit
272 Button = Window.GetControl (2)
273 Button.SetText (15417)
274 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, QuitPress)
276 GemRB.HideGUI ()
277 GemRB.SetVar ("MessageWindow", -1)
278 GemRB.UnhideGUI ()
279 Window.ShowModal (MODAL_SHADOW_GRAY)
280 return
282 def QuitPress():
283 GemRB.QuitGame ()
284 GemRB.SetNextScript ("Start")
285 return
287 def LoadPress():
288 GemRB.QuitGame ()
289 GemRB.SetNextScript ("GUILOAD")
290 return