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 # GUIWORLD.py - scripts to control some windows from GUIWORLD winpack
22 # except of Actions, Portrait, Options and Dialog windows
24 ###################################################
27 from GUIDefines
import *
28 from GUICommon
import CloseOtherWindow
, SetEncumbranceLabels
, GetWindowPack
29 from GUICommonWindows
import EnableAnimatedWindows
, DisableAnimatedWindows
, \
30 SetItemButton
, OpenWaitForDiscWindow
31 from GUIClasses
import GWindow
33 ContainerWindow
= None
34 FormationWindow
= None
35 ReformPartyWindow
= None
39 def CloseContinueWindow ():
40 GemRB
.SetVar ("DialogChoose", GemRB
.GetVar ("DialogOption"))
41 Window
= GWindow(GemRB
.GetVar ("MessageWindow"))
42 Button
= Window
.GetControl (0)
44 Button
.SetEventByName (IE_GUI_BUTTON_ON_PRESS
, "OnDecreaseSize")
46 def NextDialogState ():
49 def OpenEndMessageWindow ():
50 Window
= GWindow(GemRB
.GetVar ("MessageWindow"))
51 Button
= Window
.GetControl (0)
52 Button
.SetText (34602)
53 Button
.SetEventByName (IE_GUI_BUTTON_ON_PRESS
, "CloseContinueWindow")
56 def OpenContinueMessageWindow ():
57 Window
= GWindow(GemRB
.GetVar ("MessageWindow"))
58 Button
= Window
.GetControl (0)
59 Button
.SetText (34603)
60 Button
.SetEventByName (IE_GUI_BUTTON_ON_PRESS
, "CloseContinueWindow")
63 def OpenContainerWindow ():
64 global ContainerWindow
, Container
69 hideflag
= GemRB
.HideGUI ()
71 GemRB
.LoadWindowPack (GetWindowPack())
72 ContainerWindow
= Window
= GemRB
.LoadWindow (8)
73 DisableAnimatedWindows ()
74 GemRB
.SetVar ("ActionsWindow", Window
.ID
)
76 Container
= GemRB
.GetContainer(0)
79 # 10 - 13 - Personal Item
81 # 52, 53 scroller ground, scroller personal
83 # 0x10000036 - label gold
86 Button
= Window
.GetControl (i
)
87 Button
.SetFlags (IE_GUI_BUTTON_ALIGN_RIGHT | IE_GUI_BUTTON_ALIGN_BOTTOM
, OP_OR
)
88 #Button.SetFont ('NUMBER')
91 Button
= Window
.GetControl (10 + i
)
92 Button
.SetFlags (IE_GUI_BUTTON_ALIGN_RIGHT | IE_GUI_BUTTON_ALIGN_BOTTOM
, OP_OR
)
93 #Button.SetFont ('NUMBER')
96 Button
= Window
.GetControl (50)
97 Button
.SetFlags (IE_GUI_BUTTON_NO_IMAGE
, OP_SET
)
99 Button
= Window
.GetControl (54)
100 Button
.SetFont ("NUMBER")
101 Button
.SetFlags (IE_GUI_BUTTON_NO_IMAGE
, OP_SET
)
103 party_gold
= GemRB
.GameGetPartyGold ()
104 Text
= Window
.GetControl (0x10000036)
105 Text
.SetText (str (party_gold
))
110 # Ground items scrollbar
111 ScrollBar
= Window
.GetControl (52)
112 ScrollBar
.SetEventByName(IE_GUI_SCROLLBAR_ON_CHANGE
, "RedrawContainerWindow")
113 GemRB
.SetVar ("LeftTopIndex", 0)
114 ScrollBar
.SetVarAssoc ("LeftTopIndex", Count
)
116 # Personal items scrollbar
117 ScrollBar
= Window
.GetControl (53)
118 ScrollBar
.SetEventByName(IE_GUI_SCROLLBAR_ON_CHANGE
, "RedrawContainerWindow")
119 GemRB
.SetVar ("RightTopIndex", 0)
120 ScrollBar
.SetVarAssoc ("RightTopIndex", Count
)
124 Button
= Window
.GetControl (51)
125 Button
.SetText (1403)
126 Button
.SetEventByName (IE_GUI_BUTTON_ON_PRESS
, "LeaveContainer")
128 UpdateContainerWindow ()
134 def UpdateContainerWindow ():
137 Window
= ContainerWindow
139 pc
= GemRB
.GameGetFirstSelectedPC ()
140 SetEncumbranceLabels (Window
, 54, None, pc
)
142 party_gold
= GemRB
.GameGetPartyGold ()
143 Text
= Window
.GetControl (0x10000036)
144 Text
.SetText (str (party_gold
))
146 Container
= GemRB
.GetContainer (0) #will use first selected pc anyway
147 LeftCount
= Container
['ItemCount']
148 ScrollBar
= Window
.GetControl (52)
149 Count
= LeftCount
/ 3
152 ScrollBar
.SetVarAssoc ("LeftTopIndex", Count
)
154 inventory_slots
= GemRB
.GetSlots (pc
, 0x8000)
155 RightCount
= len (inventory_slots
)
156 ScrollBar
= Window
.GetControl (53)
157 Count
= RightCount
/ 2
160 ScrollBar
.SetVarAssoc ("RightTopIndex", Count
)
162 RedrawContainerWindow ()
165 def RedrawContainerWindow ():
166 Window
= ContainerWindow
168 LeftTopIndex
= GemRB
.GetVar ("LeftTopIndex") * 3
169 LeftIndex
= GemRB
.GetVar ("LeftIndex")
170 RightTopIndex
= GemRB
.GetVar ("RightTopIndex") * 2
171 RightIndex
= GemRB
.GetVar ("RightIndex")
172 LeftCount
= Container
['ItemCount']
173 pc
= GemRB
.GameGetFirstSelectedPC ()
174 inventory_slots
= GemRB
.GetSlots (pc
, 0x8000)
175 RightCount
= len (inventory_slots
)
178 #this is an autoselected container, but we could use PC too
179 Slot
= GemRB
.GetContainerItem (0, i
+ LeftTopIndex
)
180 Button
= Window
.GetControl (i
)
184 SetItemButton (Window
, Button
, Slot
, 'TakeItemContainer', '')
185 Button
.SetVarAssoc ("LeftIndex", LeftTopIndex
+i
)
187 SetItemButton (Window
, Button
, Slot
, '', '')
188 Button
.SetVarAssoc ("LeftIndex", -1)
192 if i
+ RightTopIndex
< RightCount
:
193 Slot
= GemRB
.GetSlotItem (pc
, inventory_slots
[i
+RightTopIndex
])
196 Button
= Window
.GetControl (i
+ 10)
198 SetItemButton (Window
, Button
, Slot
, '', '')
201 SetItemButton (Window
, Button
, Slot
, 'DropItemContainer', '')
202 Button
.SetVarAssoc ("RightIndex", RightTopIndex
+i
)
204 SetItemButton (Window
, Button
, Slot
, '', '')
205 Button
.SetVarAssoc ("RightIndex", -1)
209 def CloseContainerWindow ():
210 global ContainerWindow
212 if ContainerWindow
== None:
215 hideflag
= GemRB
.HideGUI ()
218 ContainerWindow
.Unload ()
219 ContainerWindow
= None
220 EnableAnimatedWindows ()
226 #doing this way it will inform the core system too, which in turn will call
227 #CloseContainerWindow ()
228 def LeaveContainer ():
229 GemRB
.LeaveContainer()
231 def DropItemContainer ():
232 RightIndex
= GemRB
.GetVar ("RightIndex")
236 #we need to get the right slot number
237 pc
= GemRB
.GameGetFirstSelectedPC ()
238 inventory_slots
= GemRB
.GetSlots (pc
, 0x8000)
239 if RightIndex
>= len (inventory_slots
):
242 GemRB
.ChangeContainerItem (0, inventory_slots
[RightIndex
], 0)
243 UpdateContainerWindow ()
246 def TakeItemContainer ():
247 LeftIndex
= GemRB
.GetVar ("LeftIndex")
251 if LeftIndex
>= Container
['ItemCount']:
254 GemRB
.ChangeContainerItem (0, LeftIndex
, 1)
255 UpdateContainerWindow ()
258 def OpenReformPartyWindow ():
259 global ReformPartyWindow
261 if CloseOtherWindow(OpenReformPartyWindow
):
263 if ReformPartyWindow
:
264 ReformPartyWindow
.Unload ()
265 ReformPartyWindow
= None
267 GemRB
.SetVar ("OtherWindow", -1)
268 EnableAnimatedWindows ()
269 GemRB
.LoadWindowPack ("GUIREC")
274 GemRB
.LoadWindowPack (GetWindowPack())
275 ReformPartyWindow
= Window
= GemRB
.LoadWindow (24)
276 GemRB
.SetVar ("OtherWindow", Window
.ID
)
277 DisableAnimatedWindows ()
280 Button
= Window
.GetControl (15)
281 Button
.SetText (42514)
282 Button
.SetState (IE_GUI_BUTTON_DISABLED
)
285 Button
= Window
.GetControl (8)
286 Button
.SetText (1403)
287 Button
.SetEventByName (IE_GUI_BUTTON_ON_PRESS
, "OpenReformPartyWindow")
292 last_formation
= None
294 def OpenFormationWindow ():
295 global FormationWindow
297 if CloseOtherWindow(OpenFormationWindow
):
300 FormationWindow
.Unload ()
301 FormationWindow
= None
303 GemRB
.GameSetFormation (last_formation
, 0)
304 EnableAnimatedWindows ()
305 GemRB
.SetVar ("OtherWindow", -1)
310 GemRB
.LoadWindowPack (GetWindowPack())
311 FormationWindow
= Window
= GemRB
.LoadWindow (27)
312 GemRB
.SetVar ("OtherWindow", Window
.ID
)
313 DisableAnimatedWindows ()
316 Button
= Window
.GetControl (13)
317 Button
.SetText (1403)
318 Button
.SetEventByName (IE_GUI_BUTTON_ON_PRESS
, "OpenFormationWindow")
337 Button
= Window
.GetControl (i
)
338 Button
.SetVarAssoc ("SelectedFormation", i
)
339 Button
.SetTooltip (tooltips
[i
])
340 Button
.SetEventByName (IE_GUI_BUTTON_ON_PRESS
, "SelectFormation")
342 GemRB
.SetVar ("SelectedFormation", GemRB
.GameGetFormation (0))
347 def SelectFormation ():
348 global last_formation
349 Window
= FormationWindow
351 formation
= GemRB
.GetVar ("SelectedFormation")
352 print "FORMATION:", formation
353 if last_formation
!= None and last_formation
!= formation
:
354 Button
= Window
.GetControl (last_formation
)
355 Button
.SetState (IE_GUI_BUTTON_UNPRESSED
)
357 Button
= Window
.GetControl (formation
)
358 Button
.SetState (IE_GUI_BUTTON_SELECTED
)
360 last_formation
= formation