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 the GUIWORLD winpack
22 # except of Actions, Portrait, Options and Dialog windows
23 #################################################################
26 from GUIDefines
import *
27 import GUICommonWindows
29 from GUIClasses
import GWindow
34 ContainerWindow
= None
36 ReformPartyWindow
= None
37 OldActionsWindow
= None
38 OldMessageWindow
= None
41 def CloseContinueWindow ():
43 # don't close the actual window now to avoid flickering: we might still want it open
44 GemRB
.SetVar ("DialogChoose", GemRB
.GetVar ("DialogOption"))
46 def NextDialogState ():
47 global ContinueWindow
, OldActionsWindow
49 if ContinueWindow
== None:
52 hideflag
= GemRB
.HideGUI ()
55 ContinueWindow
.Unload ()
56 GemRB
.SetVar ("ActionsWindow", OldActionsWindow
.ID
)
58 OldActionsWindow
= None
63 def OpenEndMessageWindow ():
64 global ContinueWindow
, OldActionsWindow
66 hideflag
= GemRB
.HideGUI ()
68 if not ContinueWindow
:
69 GemRB
.LoadWindowPack (GUICommon
.GetWindowPack())
70 ContinueWindow
= Window
= GemRB
.LoadWindow (9)
71 OldActionsWindow
= GWindow( GemRB
.GetVar ("ActionsWindow") )
72 GemRB
.SetVar ("ActionsWindow", Window
.ID
)
75 Button
= ContinueWindow
.GetControl (0)
77 Button
.SetEventByName (IE_GUI_BUTTON_ON_PRESS
, "CloseContinueWindow")
78 if GUICommonWindows
.PortraitWindow
:
79 GUICommonWindows
.UpdatePortraitWindow ()
84 def OpenContinueMessageWindow ():
85 global ContinueWindow
, OldActionsWindow
87 hideflag
= GemRB
.HideGUI ()
89 if not ContinueWindow
:
90 GemRB
.LoadWindowPack (GUICommon
.GetWindowPack())
91 ContinueWindow
= Window
= GemRB
.LoadWindow (9)
92 OldActionsWindow
= GWindow( GemRB
.GetVar ("ActionsWindow") )
93 GemRB
.SetVar ("ActionsWindow", Window
.ID
)
96 Button
= ContinueWindow
.GetControl (0)
98 Button
.SetEventByName (IE_GUI_BUTTON_ON_PRESS
, "CloseContinueWindow")
103 def CloseContainerWindow ():
104 global OldActionsWindow
, OldMessageWindow
, ContainerWindow
106 if ContainerWindow
== None:
109 hideflag
= GemRB
.HideGUI ()
112 ContainerWindow
.Unload ()
113 ContainerWindow
= None
114 GemRB
.SetVar ("ActionsWindow", OldActionsWindow
.ID
)
115 GemRB
.SetVar ("MessageWindow", OldMessageWindow
.ID
)
116 Table
= GemRB
.LoadTable ("containr")
117 row
= Container
['Type']
118 tmp
= Table
.GetValue (row
, 2)
119 #play closing sound if applicable
121 GemRB
.PlaySound (tmp
)
123 #it is enough to close here
129 def UpdateContainerWindow ():
132 Window
= ContainerWindow
134 pc
= GemRB
.GameGetFirstSelectedPC ()
135 SetEncumbranceLabels( Window
, 0x10000043, 0x10000044, pc
)
137 party_gold
= GemRB
.GameGetPartyGold ()
138 Text
= Window
.GetControl (0x10000036)
139 Text
.SetText (str (party_gold
))
141 Container
= GemRB
.GetContainer(0) #will use first selected pc anyway
142 LeftCount
= Container
['ItemCount']
143 ScrollBar
= Window
.GetControl (52)
147 ScrollBar
.SetVarAssoc ("LeftTopIndex", Count
)
149 inventory_slots
= GemRB
.GetSlots (pc
, 0x8000)
150 RightCount
= len(inventory_slots
)
151 ScrollBar
= Window
.GetControl (53)
155 ScrollBar
.SetVarAssoc ("RightTopIndex", Count
)
157 RedrawContainerWindow ()
160 def RedrawContainerWindow ():
161 Window
= ContainerWindow
163 LeftTopIndex
= GemRB
.GetVar ("LeftTopIndex") * 3
164 LeftIndex
= GemRB
.GetVar ("LeftIndex")
165 RightTopIndex
= GemRB
.GetVar ("RightTopIndex") * 2
166 RightIndex
= GemRB
.GetVar ("RightIndex")
167 LeftCount
= Container
['ItemCount']
168 pc
= GemRB
.GameGetFirstSelectedPC ()
169 inventory_slots
= GemRB
.GetSlots (pc
, 0x8000)
170 RightCount
= len(inventory_slots
)
173 #this is an autoselected container, but we could use PC too
174 Slot
= GemRB
.GetContainerItem (0, i
+LeftTopIndex
)
175 Button
= Window
.GetControl (i
)
177 Button
.SetVarAssoc ("LeftIndex", LeftTopIndex
+i
)
179 Button
.SetVarAssoc ("LeftIndex", -1)
180 GUICommon
.UpdateInventorySlot (pc
, Button
, Slot
, "container")
183 if i
+RightTopIndex
<RightCount
:
184 Slot
= GemRB
.GetSlotItem (pc
, inventory_slots
[i
+RightTopIndex
])
187 Button
= Window
.GetControl (i
+10)
189 Button
.SetVarAssoc ("RightIndex", RightTopIndex
+i
)
191 Button
.SetVarAssoc ("RightIndex", -1)
192 GUICommon
.UpdateInventorySlot (pc
, Button
, Slot
, "inventory")
195 def OpenContainerWindow ():
196 global OldActionsWindow
, OldMessageWindow
197 global ContainerWindow
, Container
202 hideflag
= GemRB
.HideGUI ()
204 GemRB
.LoadWindowPack (GUICommon
.GetWindowPack())
205 ContainerWindow
= Window
= GemRB
.LoadWindow (8)
206 OldActionsWindow
= GWindow( GemRB
.GetVar ("ActionsWindow") )
207 OldMessageWindow
= GWindow( GemRB
.GetVar ("MessageWindow") )
208 GemRB
.SetVar ("ActionsWindow", Window
.ID
)
209 GemRB
.SetVar ("MessageWindow", -1)
211 Container
= GemRB
.GetContainer(0)
213 # Gears (time) when options pane is down
214 Button
= Window
.GetControl (62)
215 Label
= Button
.CreateLabelOnButton (0x1000003e, "NORMAL", 0)
217 Label
.SetAnimation ("CPEN")
218 Button
.SetAnimation ("CGEAR")
219 Button
.SetBAM ("CDIAL", 0, 0)
220 Button
.SetState (IE_GUI_BUTTON_ENABLED
)
221 Button
.SetFlags (IE_GUI_BUTTON_PICTURE|IE_GUI_BUTTON_ANIMATED|IE_GUI_BUTTON_NORMAL
, OP_SET
)
222 Button
.SetEventByName(IE_GUI_BUTTON_ON_PRESS
, "GearsClicked")
223 GUICommon
.SetGamedaysAndHourToken()
224 Button
.SetTooltip(16041)
226 # 0 - 5 - Ground Item
227 # 10 - 13 - Personal Item
229 # 52, 53 scroller ground, scroller personal
233 Button
= Window
.GetControl (i
)
234 Button
.SetVarAssoc ("LeftIndex", i
)
235 #Button.SetFlags (IE_GUI_BUTTON_CHECKBOX, OP_OR)
236 Button
.SetEventByName (IE_GUI_BUTTON_ON_PRESS
, "TakeItemContainer")
239 Button
= Window
.GetControl (i
+10)
240 Button
.SetVarAssoc ("RightIndex", i
)
241 #Button.SetFlags (IE_GUI_BUTTON_CHECKBOX, OP_OR)
242 Button
.SetEventByName (IE_GUI_BUTTON_ON_PRESS
, "DropItemContainer")
245 ScrollBar
= Window
.GetControl (52)
246 ScrollBar
.SetEventByName (IE_GUI_SCROLLBAR_ON_CHANGE
, "RedrawContainerWindow")
249 ScrollBar
= Window
.GetControl (53)
250 ScrollBar
.SetEventByName (IE_GUI_SCROLLBAR_ON_CHANGE
, "RedrawContainerWindow")
252 Label
= Window
.CreateLabel (0x10000043, 323,14,60,15,"NUMBER","0:",IE_FONT_ALIGN_LEFT|IE_FONT_ALIGN_TOP
)
253 Label
= Window
.CreateLabel (0x10000044, 323,20,80,15,"NUMBER","0:",IE_FONT_ALIGN_RIGHT|IE_FONT_ALIGN_TOP
)
255 Button
= Window
.GetControl (50)
256 Button
.SetState (IE_GUI_BUTTON_LOCKED
)
257 Table
= GemRB
.LoadTable ("containr")
258 row
= Container
['Type']
259 tmp
= Table
.GetValue (row
, 0)
261 GemRB
.PlaySound (tmp
)
262 tmp
= Table
.GetValue (row
, 1)
264 Button
.SetSprites (tmp
, 0, 0, 0, 0, 0 )
267 Button
= Window
.GetControl (51)
268 Button
.SetText (1403)
269 Button
.SetEventByName (IE_GUI_BUTTON_ON_PRESS
, "LeaveContainer")
271 GemRB
.SetVar ("LeftTopIndex", 0)
272 GemRB
.SetVar ("RightTopIndex", 0)
273 UpdateContainerWindow ()
278 #doing this way it will inform the core system too, which in turn will call
279 #CloseContainerWindow ()
280 def LeaveContainer ():
281 GemRB
.LeaveContainer()
283 def DropItemContainer ():
284 RightIndex
= GemRB
.GetVar ("RightIndex")
288 #we need to get the right slot number
289 pc
= GemRB
.GameGetFirstSelectedPC ()
290 inventory_slots
= GemRB
.GetSlots (pc
, 0x8000)
291 if RightIndex
>= len(inventory_slots
):
293 GemRB
.ChangeContainerItem (0, inventory_slots
[RightIndex
], 0)
294 UpdateContainerWindow ()
297 def TakeItemContainer ():
298 LeftIndex
= GemRB
.GetVar ("LeftIndex")
302 if LeftIndex
>= Container
['ItemCount']:
304 GemRB
.ChangeContainerItem (0, LeftIndex
, 1)
305 UpdateContainerWindow ()
308 def UpdateReformWindow ():
309 Window
= ReformPartyWindow
311 select
= GemRB
.GetVar ("Selected")
313 need_to_drop
= GemRB
.GetPartySize ()-PARTY_SIZE
317 #excess player number
318 Label
= Window
.GetControl (0x1000000f)
319 Label
.SetText (str(need_to_drop
) )
322 Button
= Window
.GetControl (8)
324 Button
.SetState (IE_GUI_BUTTON_DISABLED
)
326 Button
.SetState (IE_GUI_BUTTON_ENABLED
)
329 Button
= Window
.GetControl (15)
331 Button
.SetState (IE_GUI_BUTTON_ENABLED
)
333 Button
.SetState (IE_GUI_BUTTON_DISABLED
)
335 for i
in range (PARTY_SIZE
+1):
336 Button
= Window
.GetControl (i
)
337 Button
.EnableBorder (FRAME_PC_SELECTED
, select
== i
+2 )
338 #+2 because protagonist is skipped
339 pic
= GemRB
.GetPlayerPortrait (i
+2,1)
341 Button
.SetFlags (IE_GUI_BUTTON_NO_IMAGE
, OP_SET
)
342 Button
.SetState (IE_GUI_BUTTON_LOCKED
)
345 Button
.SetState (IE_GUI_BUTTON_ENABLED
)
346 Button
.SetFlags (IE_GUI_BUTTON_PICTURE|IE_GUI_BUTTON_ALIGN_BOTTOM|IE_GUI_BUTTON_ALIGN_LEFT
, OP_SET
)
347 Button
.SetPicture (pic
, "NOPORTSM")
348 GUICommonWindows
.UpdatePortraitWindow ()
352 global ReformPartyWindow
354 hideflag
= GemRB
.HideGUI ()
356 GemRB
.LoadWindowPack (GUICommon
.GetWindowPack())
357 if ReformPartyWindow
:
358 ReformPartyWindow
.Unload ()
359 ReformPartyWindow
= Window
= GemRB
.LoadWindow (25)
360 GemRB
.SetVar ("OtherWindow", Window
.ID
)
363 Label
= Window
.GetControl (0x0fffffff)
364 Label
.SetText (17518)
367 Button
= Window
.GetControl (1)
368 Button
.SetText (17507)
369 Button
.SetEventByName (IE_GUI_BUTTON_ON_PRESS
, "RemovePlayerConfirm")
370 Button
.SetFlags (IE_GUI_BUTTON_DEFAULT
, OP_OR
)
373 Button
= Window
.GetControl (2)
374 Button
.SetText (13727)
375 Button
.SetEventByName (IE_GUI_BUTTON_ON_PRESS
, "RemovePlayerCancel")
376 Button
.SetFlags (IE_GUI_BUTTON_CANCEL
, OP_OR
)
378 GemRB
.SetVar ("OtherWindow", Window
.ID
)
379 GemRB
.SetVar ("ActionsWindow", -1)
382 Window
.ShowModal (MODAL_SHADOW_GRAY
)
385 def RemovePlayerConfirm ():
386 slot
= GemRB
.GetVar ("Selected")
387 GemRB
.LeaveParty (slot
, 2)
388 OpenReformPartyWindow ()
391 def RemovePlayerCancel ():
392 #Once for getting rid of the confirmation window
393 OpenReformPartyWindow ()
394 #and once for reopening the reform party window
395 OpenReformPartyWindow ()
398 def OpenReformPartyWindow ():
399 global ReformPartyWindow
, OldActionsWindow
, OldMessageWindow
401 GemRB
.SetVar ("Selected", 0)
402 hideflag
= GemRB
.HideGUI ()
404 if ReformPartyWindow
:
405 if ReformPartyWindow
:
406 ReformPartyWindow
.Unload ()
408 GemRB
.SetVar ("ActionsWindow", OldActionsWindow
.ID
)
409 GemRB
.SetVar ("MessageWindow", OldMessageWindow
.ID
)
410 GemRB
.SetVar ("OtherWindow", -1)
412 OldActionsWindow
= None
413 OldMessageWindow
= None
414 ReformPartyWindow
= None
417 #re-enabling party size control
418 GemRB
.GameSetPartySize (PARTY_SIZE
)
419 GUICommonWindows
.UpdatePortraitWindow()
422 GemRB
.LoadWindowPack (GUICommon
.GetWindowPack())
423 ReformPartyWindow
= Window
= GemRB
.LoadWindow (24)
424 GemRB
.SetVar ("OtherWindow", Window
.ID
)
427 for j
in range (PARTY_SIZE
+1):
428 Button
= Window
.GetControl (j
)
429 Button
.SetState (IE_GUI_BUTTON_LOCKED
)
430 Button
.SetFlags (IE_GUI_BUTTON_RADIOBUTTON|IE_GUI_BUTTON_NO_IMAGE|IE_GUI_BUTTON_PICTURE
,OP_SET
)
431 Button
.SetBorder (FRAME_PC_SELECTED
, 1, 1, 2, 2, 0, 255, 0, 255)
432 #protagonist is skipped
434 Button
.SetVarAssoc ("Selected", index
)
435 Button
.SetEventByName (IE_GUI_BUTTON_ON_PRESS
, "UpdateReformWindow")
438 Button
= Window
.GetControl (15)
439 Button
.SetText (17507)
440 Button
.SetEventByName (IE_GUI_BUTTON_ON_PRESS
, "RemovePlayer")
443 Button
= Window
.GetControl (8)
444 Button
.SetText (11973)
445 Button
.SetEventByName (IE_GUI_BUTTON_ON_PRESS
, "OpenReformPartyWindow")
447 OldActionsWindow
= GWindow( GemRB
.GetVar ("ActionsWindow") )
448 OldMessageWindow
= GWindow( GemRB
.GetVar ("MessageWindow") )
449 GemRB
.SetVar ("ActionsWindow", -1)
450 GemRB
.SetVar ("MessageWindow", -1)
451 UpdateReformWindow ()
454 Window
.ShowModal (MODAL_SHADOW_GRAY
)
459 GemRB
.SetTimedEventByName ("DeathWindowEnd", 10)
462 def DeathWindowEnd ():
463 #playing death movie before continuing
464 GemRB
.PlayMovie ("deathand",1)
465 GemRB
.GamePause (1,1)
467 GemRB
.LoadWindowPack (GUICommon
.GetWindowPack())
468 Window
= GemRB
.LoadWindow (17)
471 Label
= Window
.GetControl (0x0fffffff)
472 Label
.SetText (16498)
475 Button
= Window
.GetControl (1)
476 Button
.SetText (15590)
477 Button
.SetEventByName (IE_GUI_BUTTON_ON_PRESS
, "LoadPress")
480 Button
= Window
.GetControl (2)
481 Button
.SetText (15417)
482 Button
.SetEventByName (IE_GUI_BUTTON_ON_PRESS
, "QuitPress")
485 GemRB
.SetVar ("MessageWindow", -1)
487 Window
.ShowModal (MODAL_SHADOW_GRAY
)
492 GemRB
.SetNextScript ("Start")
497 GemRB
.SetNextScript ("GUILOAD")