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 # GUISTORE.py - script to open store/inn/temple windows from GUISTORE winpack
23 ###################################################
27 import GUICommonWindows
28 from GUIDefines
import *
32 StoreShoppingWindow
= None
33 StoreIdentifyWindow
= None
34 StoreStealWindow
= None
35 StoreDonateWindow
= None
36 StoreHealWindow
= None
37 StoreRumourWindow
= None
38 StoreRentWindow
= None
47 store_update_functions
= {}
49 def CloseStoreWindow ():
52 CloseStoreShoppingWindow ()
53 CloseStoreIdentifyWindow ()
54 CloseStoreStealWindow ()
55 CloseStoreDonateWindow ()
56 CloseStoreHealWindow ()
57 CloseStoreRumourWindow ()
58 CloseStoreRentWindow ()
60 GemRB
.SetVar ("OtherWindow", -1)
65 GUICommon
.GameWindow
.SetVisible(WINDOW_VISIBLE
) #enabling the game control screen
66 GemRB
.UnhideGUI () #enabling the other windows
67 GUICommonWindows
.SetSelectionChangeHandler (None)
70 def OpenStoreWindow ():
71 global StoreWindow
, party_gold
, store_name
, Store
74 GUICommon
.GameWindow
.SetVisible(WINDOW_INVISIBLE
) #removing the game control screen
76 GemRB
.LoadWindowPack ("GUISTORE")
77 StoreWindow
= Window
= GemRB
.LoadWindow (3)
78 Window
.SetVisible (WINDOW_VISIBLE
)
80 Store
= GemRB
.GetStore ()
81 # font used for store name has only uppercase chars
82 store_name
= GemRB
.GetString (Store
['StoreName']).upper ()
85 Button
= Window
.GetControl (0)
87 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, CloseStoreWindow
)
88 Button
.SetFlags (IE_GUI_BUTTON_CANCEL
, OP_OR
)
91 Button
= Window
.GetControl (1)
92 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, OpenStoreShoppingWindow
)
93 store_buttons
['shopping'] = Button
94 store_update_functions
['shopping'] = UpdateStoreShoppingWindow
97 Button
= Window
.GetControl (2)
98 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, OpenStoreIdentifyWindow
)
99 store_buttons
['identify'] = Button
100 store_update_functions
['identify'] = UpdateStoreIdentifyWindow
103 Button
= Window
.GetControl (3)
104 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, OpenStoreStealWindow
)
105 store_buttons
['steal'] = Button
106 store_update_functions
['steal'] = UpdateStoreStealWindow
109 Button
= Window
.GetControl (4)
110 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, OpenStoreDonateWindow
)
111 store_buttons
['donate'] = Button
112 store_update_functions
['donate'] = UpdateStoreDonateWindow
115 Button
= Window
.GetControl (5)
116 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, OpenStoreHealWindow
)
117 store_buttons
['heal'] = Button
118 store_update_functions
['heal'] = UpdateStoreHealWindow
121 Button
= Window
.GetControl (6)
122 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, OpenStoreRumourWindow
)
123 store_buttons
['rumour'] = Button
124 store_update_functions
['rumour'] = UpdateStoreRumourWindow
127 Button
= Window
.GetControl (7)
128 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, OpenStoreRentWindow
)
129 store_buttons
['rent'] = Button
130 store_update_functions
['rent'] = UpdateStoreRentWindow
132 OpenStoreShoppingWindow ()
136 last_store_action
= None
137 def SelectStoreAction (action
):
138 global last_store_action
142 if last_store_action
!= None and action
!= last_store_action
:
143 Button
= store_buttons
[last_store_action
]
144 Button
.SetState (IE_GUI_BUTTON_UNPRESSED
)
146 Button
= store_buttons
[action
]
147 Button
.SetState (IE_GUI_BUTTON_SELECTED
)
149 GUICommonWindows
.SetSelectionChangeHandler (store_update_functions
[action
])
151 last_store_action
= action
155 def OpenStoreShoppingWindow ():
156 global StoreShoppingWindow
159 SelectStoreAction ('shopping')
161 if StoreShoppingWindow
!= None:
162 Window
= StoreShoppingWindow
163 GemRB
.SetVar ("OtherWindow", Window
.ID
)
164 UpdateStoreShoppingWindow ()
168 StoreShoppingWindow
= Window
= GemRB
.LoadWindow (4)
169 GemRB
.SetVar ("OtherWindow", Window
.ID
)
172 Label
= Window
.GetControl (0x10000001)
173 Label
.SetText (store_name
)
176 Label
= Window
.GetControl (0x10000003)
177 Label
.SetText (str (666))
180 Label
= Window
.GetControl (0x10000004)
181 Label
.SetText (str (999))
185 Button
= Window
.GetControl (0)
186 Button
.SetText (45303)
189 Button
= Window
.GetControl (1)
190 Button
.SetText (45304)
195 # 8-11, @11 -@14 - slots and their labels
197 # 17-20, @20-@23 - slots and labels
198 # 25 encumbrance button
200 UpdateStoreShoppingWindow ()
204 def OpenStoreIdentifyWindow ():
205 global StoreIdentifyWindow
208 SelectStoreAction ('identify')
210 if StoreIdentifyWindow
!= None:
211 Window
= StoreIdentifyWindow
212 GemRB
.SetVar ("OtherWindow", Window
.ID
)
213 UpdateStoreIdentifyWindow ()
217 StoreIdentifyWindow
= Window
= GemRB
.LoadWindow (5)
218 GemRB
.SetVar ("OtherWindow", Window
.ID
)
221 Label
= Window
.GetControl (0x0fffffff)
222 Label
.SetText (store_name
)
225 Button
= Window
.GetControl (4)
226 Button
.SetText (44971)
231 Label
= Window
.GetControl (0x10000001)
232 Label
.SetText (str (666))
234 # 6-9 item slots, 0x10000009-c labels
236 UpdateStoreIdentifyWindow ()
240 def OpenStoreStealWindow ():
241 global StoreStealWindow
244 SelectStoreAction ('steal')
246 if StoreStealWindow
!= None:
247 Window
= StoreStealWindow
248 GemRB
.SetVar ("OtherWindow", Window
.ID
)
249 UpdateStoreStealWindow ()
253 StoreStealWindow
= Window
= GemRB
.LoadWindow (7)
254 GemRB
.SetVar ("OtherWindow", Window
.ID
)
257 Label
= Window
.GetControl (0x10000000)
258 Label
.SetText (store_name
)
261 Button
= Window
.GetControl (0)
262 Button
.SetText (45305)
264 UpdateStoreStealWindow ()
268 def OpenStoreDonateWindow ():
269 global StoreDonateWindow
272 SelectStoreAction ('donate')
274 if StoreDonateWindow
!= None:
275 Window
= StoreDonateWindow
276 GemRB
.SetVar ("OtherWindow", Window
.ID
)
277 UpdateStoreDonateWindow ()
281 StoreDonateWindow
= Window
= GemRB
.LoadWindow (10)
282 GemRB
.SetVar ("OtherWindow", Window
.ID
)
285 Label
= Window
.GetControl (0x10000005)
286 Label
.SetText (store_name
)
289 Button
= Window
.GetControl (2)
290 Button
.SetText (45307)
296 UpdateStoreDonateWindow ()
300 def OpenStoreHealWindow ():
301 global StoreHealWindow
304 SelectStoreAction ('heal')
306 if StoreHealWindow
!= None:
307 Window
= StoreHealWindow
308 GemRB
.SetVar ("OtherWindow", Window
.ID
)
309 UpdateStoreHealWindow ()
313 StoreHealWindow
= Window
= GemRB
.LoadWindow (6)
314 GemRB
.SetVar ("OtherWindow", Window
.ID
)
317 Label
= Window
.GetControl (0x0fffffff)
318 Label
.SetText (store_name
)
321 Label
= Window
.GetControl (0x10000001)
322 Label
.SetText (str (666))
325 Label
= Window
.GetControl (0x1000000e)
326 Label
.SetText (character_name
)
329 Button
= Window
.GetControl (3)
330 Button
.SetText (8836) # FIXME: better strref
335 UpdateStoreHealWindow ()
339 def OpenStoreRumourWindow ():
340 global StoreRumourWindow
343 SelectStoreAction ('rumour')
345 if StoreRumourWindow
!= None:
346 Window
= StoreRumourWindow
347 GemRB
.SetVar ("OtherWindow", Window
.ID
)
348 UpdateStoreRumourWindow ()
352 StoreRumourWindow
= Window
= GemRB
.LoadWindow (9)
353 GemRB
.SetVar ("OtherWindow", Window
.ID
)
356 Label
= Window
.GetControl (0x1000000a)
357 Label
.SetText (store_name
)
361 UpdateStoreRumourWindow ()
365 def OpenStoreRentWindow ():
366 global StoreRentWindow
, HelpStoreRent
369 SelectStoreAction ('rent')
371 if StoreRentWindow
!= None:
372 Window
= StoreRentWindow
373 GemRB
.SetVar ("OtherWindow", Window
.ID
)
374 UpdateStoreRentWindow ()
378 StoreRentWindow
= Window
= GemRB
.LoadWindow (8)
379 GemRB
.SetVar ("OtherWindow", Window
.ID
)
382 Label
= Window
.GetControl (0x1000000a)
383 Label
.SetText (store_name
)
386 Button
= Window
.GetControl (0)
387 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, SelectStoreRentPeasant
)
388 Button
= Window
.GetControl (4)
389 Button
.SetText (45308)
390 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, SelectStoreRentPeasant
)
393 Button
= Window
.GetControl (1)
394 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, SelectStoreRentMerchant
)
395 Button
= Window
.GetControl (5)
396 Button
.SetText (45310)
397 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, SelectStoreRentMerchant
)
400 Button
= Window
.GetControl (2)
401 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, SelectStoreRentNoble
)
402 Button
= Window
.GetControl (6)
403 Button
.SetText (45313)
404 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, SelectStoreRentNoble
)
407 Button
= Window
.GetControl (3)
408 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, SelectStoreRentRoyal
)
409 Button
= Window
.GetControl (7)
410 Button
.SetText (45316)
411 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, SelectStoreRentRoyal
)
415 Button
= Window
.GetControl (8)
416 Button
.SetText (45306)
417 Button
.SetState (IE_GUI_BUTTON_DISABLED
)
421 Label
= Window
.GetControl (0x1000000c)
424 HelpStoreRent
= Text
= Window
.GetControl (9)
431 def SelectStoreRent (room
):
434 Window
= StoreRentWindow
436 HelpStoreRent
.SetText (66865 + room
)
438 if last_room
!= None and room
!= last_room
:
439 Picture
= Window
.GetControl (0 + last_room
)
440 Picture
.SetState (IE_GUI_BUTTON_UNPRESSED
)
441 Button
= Window
.GetControl (4 + last_room
)
442 Button
.SetState (IE_GUI_BUTTON_UNPRESSED
)
444 Picture
= Window
.GetControl (0 + room
)
445 Picture
.SetState (IE_GUI_BUTTON_SELECTED
)
446 Button
= Window
.GetControl (4 + room
)
447 Button
.SetState (IE_GUI_BUTTON_PRESSED
)
449 Label
= Window
.GetControl (0x1000000c)
450 Label
.SetText (str (Store
['StoreRoomPrices'][room
]))
454 def SelectStoreRentPeasant ():
457 def SelectStoreRentMerchant ():
460 def SelectStoreRentNoble ():
463 def SelectStoreRentRoyal ():
467 def UpdateStoreCommon ():
468 global party_gold
, character_name
, pc
470 print "UpdateStoreWindow"
471 pc
= GemRB
.GameGetSelectedPCSingle ()
472 character_name
= GemRB
.GetPlayerName (pc
, 1)
474 party_gold
= GemRB
.GameGetPartyGold ()
477 def UpdateStoreShoppingWindow ():
478 Window
= StoreShoppingWindow
484 Label
= Window
.GetControl (0x10000005)
485 Label
.SetText (character_name
)
488 Label
= Window
.GetControl (0x10000002)
489 Label
.SetText (str (party_gold
))
492 def UpdateStoreIdentifyWindow ():
493 Window
= StoreIdentifyWindow
499 Label
= Window
.GetControl (0x10000000)
500 Label
.SetText (str (party_gold
))
503 Label
= Window
.GetControl (0x10000002)
504 Label
.SetText (character_name
)
508 def UpdateStoreStealWindow ():
509 Window
= StoreStealWindow
515 Label
= Window
.GetControl (0x10000001)
516 Label
.SetText (str (party_gold
))
519 Label
= Window
.GetControl (0x10000002)
520 Label
.SetText (character_name
)
524 def UpdateStoreDonateWindow ():
525 Window
= StoreDonateWindow
531 Label
= Window
.GetControl (0x10000006)
532 Label
.SetText (str (party_gold
))
536 def UpdateStoreHealWindow ():
537 Window
= StoreHealWindow
543 Label
= Window
.GetControl (0x10000000)
544 Label
.SetText (str (party_gold
))
548 def UpdateStoreRumourWindow ():
549 Window
= StoreRumourWindow
555 Label
= Window
.GetControl (0x1000000b)
556 Label
.SetText (str (party_gold
))
560 def UpdateStoreRentWindow ():
561 Window
= StoreRentWindow
567 Label
= Window
.GetControl (0x1000000b)
568 Label
.SetText (str (party_gold
))
573 def CloseStoreShoppingWindow ():
574 global StoreShoppingWindow
576 if StoreShoppingWindow
!= None:
577 if StoreShoppingWindow
:
578 StoreShoppingWindow
.Unload ()
579 StoreShoppingWindow
= None
582 def CloseStoreIdentifyWindow ():
583 global StoreIdentifyWindow
585 if StoreIdentifyWindow
!= None:
586 if StoreIdentifyWindow
:
587 StoreIdentifyWindow
.Unload ()
588 StoreIdentifyWindow
= None
591 def CloseStoreStealWindow ():
592 global StoreStealWindow
594 if StoreStealWindow
!= None:
596 StoreStealWindow
.Unload ()
597 StoreStealWindow
= None
600 def CloseStoreDonateWindow ():
601 global StoreDonateWindow
603 if StoreDonateWindow
!= None:
604 if StoreDonateWindow
:
605 StoreDonateWindow
.Unload ()
606 StoreDonateWindow
= None
609 def CloseStoreHealWindow ():
610 global StoreHealWindow
612 if StoreHealWindow
!= None:
614 StoreHealWindow
.Unload ()
615 StoreHealWindow
= None
618 def CloseStoreRumourWindow ():
619 global StoreRumourWindow
621 if StoreRumourWindow
!= None:
622 if StoreRumourWindow
:
623 StoreRumourWindow
.Unload ()
624 StoreRumourWindow
= None
627 def CloseStoreRentWindow ():
628 global StoreRentWindow
630 if StoreRentWindow
!= None:
632 StoreRentWindow
.Unload ()
633 StoreRentWindow
= None
636 ###################################################
637 # End of file GUISTORE.py