iwd: more gcw syncing with bg2 - actonpc and dragging
[gemrb.git] / gemrb / GUIScripts / pst / GUISTORE.py
blob709b6d39611190d3ea188c67cd528377a2a7a165
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 # GUISTORE.py - script to open store/inn/temple windows from GUISTORE winpack
23 ###################################################
25 import GemRB
26 import GUICommon
27 import GUICommonWindows
28 from GUIDefines import *
30 StoreWindow = None
32 StoreShoppingWindow = None
33 StoreIdentifyWindow = None
34 StoreStealWindow = None
35 StoreDonateWindow = None
36 StoreHealWindow = None
37 StoreRumourWindow = None
38 StoreRentWindow = None
40 HelpStoreRent = None
42 store_name = ""
43 pc = 0
44 character_name = ""
45 party_gold = 0
46 store_buttons = {}
47 store_update_functions = {}
49 def CloseStoreWindow ():
50 global StoreWindow
52 CloseStoreShoppingWindow ()
53 CloseStoreIdentifyWindow ()
54 CloseStoreStealWindow ()
55 CloseStoreDonateWindow ()
56 CloseStoreHealWindow ()
57 CloseStoreRumourWindow ()
58 CloseStoreRentWindow ()
60 GemRB.SetVar ("OtherWindow", -1)
61 if StoreWindow:
62 StoreWindow.Unload ()
63 StoreWindow = None
64 GemRB.LeaveStore ()
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
73 GemRB.HideGUI ()
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 ()
84 # Done
85 Button = Window.GetControl (0)
86 Button.SetText (1403)
87 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, CloseStoreWindow)
88 Button.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
90 # buy / sell
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
96 # identify
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
102 # steal
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
108 # donate
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
114 # heal / cure
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
120 # rumour
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
126 # rent room
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 ()
134 GemRB.UnhideGUI()
136 last_store_action = None
137 def SelectStoreAction (action):
138 global last_store_action
140 Window = StoreWindow
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
158 GemRB.HideGUI ()
159 SelectStoreAction ('shopping')
161 if StoreShoppingWindow != None:
162 Window = StoreShoppingWindow
163 GemRB.SetVar ("OtherWindow", Window.ID)
164 UpdateStoreShoppingWindow ()
165 GemRB.UnhideGUI ()
166 return
168 StoreShoppingWindow = Window = GemRB.LoadWindow (4)
169 GemRB.SetVar ("OtherWindow", Window.ID)
171 # title ...
172 Label = Window.GetControl (0x10000001)
173 Label.SetText (store_name)
175 # buy price ...
176 Label = Window.GetControl (0x10000003)
177 Label.SetText (str (666))
179 # sell price ...
180 Label = Window.GetControl (0x10000004)
181 Label.SetText (str (999))
184 # Buy
185 Button = Window.GetControl (0)
186 Button.SetText (45303)
188 # Sell
189 Button = Window.GetControl (1)
190 Button.SetText (45304)
192 # 45374
194 # 7 scrollbar
195 # 8-11, @11 -@14 - slots and their labels
196 # 16 scrollbar
197 # 17-20, @20-@23 - slots and labels
198 # 25 encumbrance button
200 UpdateStoreShoppingWindow ()
201 GemRB.UnhideGUI ()
204 def OpenStoreIdentifyWindow ():
205 global StoreIdentifyWindow
207 GemRB.HideGUI ()
208 SelectStoreAction ('identify')
210 if StoreIdentifyWindow != None:
211 Window = StoreIdentifyWindow
212 GemRB.SetVar ("OtherWindow", Window.ID)
213 UpdateStoreIdentifyWindow ()
214 GemRB.UnhideGUI ()
215 return
217 StoreIdentifyWindow = Window = GemRB.LoadWindow (5)
218 GemRB.SetVar ("OtherWindow", Window.ID)
220 # title ...
221 Label = Window.GetControl (0x0fffffff)
222 Label.SetText (store_name)
224 # Identify
225 Button = Window.GetControl (4)
226 Button.SetText (44971)
228 # 14 ta
230 # price ...
231 Label = Window.GetControl (0x10000001)
232 Label.SetText (str (666))
234 # 6-9 item slots, 0x10000009-c labels
236 UpdateStoreIdentifyWindow ()
237 GemRB.UnhideGUI ()
240 def OpenStoreStealWindow ():
241 global StoreStealWindow
243 GemRB.HideGUI ()
244 SelectStoreAction ('steal')
246 if StoreStealWindow != None:
247 Window = StoreStealWindow
248 GemRB.SetVar ("OtherWindow", Window.ID)
249 UpdateStoreStealWindow ()
250 GemRB.UnhideGUI ()
251 return
253 StoreStealWindow = Window = GemRB.LoadWindow (7)
254 GemRB.SetVar ("OtherWindow", Window.ID)
256 # title ...
257 Label = Window.GetControl (0x10000000)
258 Label.SetText (store_name)
260 # Steal
261 Button = Window.GetControl (0)
262 Button.SetText (45305)
264 UpdateStoreStealWindow ()
265 GemRB.UnhideGUI ()
268 def OpenStoreDonateWindow ():
269 global StoreDonateWindow
271 GemRB.HideGUI ()
272 SelectStoreAction ('donate')
274 if StoreDonateWindow != None:
275 Window = StoreDonateWindow
276 GemRB.SetVar ("OtherWindow", Window.ID)
277 UpdateStoreDonateWindow ()
278 GemRB.UnhideGUI ()
279 return
281 StoreDonateWindow = Window = GemRB.LoadWindow (10)
282 GemRB.SetVar ("OtherWindow", Window.ID)
284 # title ...
285 Label = Window.GetControl (0x10000005)
286 Label.SetText (store_name)
288 # Donate
289 Button = Window.GetControl (2)
290 Button.SetText (45307)
292 # 0 ta
293 # 3 donation entry
294 # 4 5 +-
296 UpdateStoreDonateWindow ()
297 GemRB.UnhideGUI ()
300 def OpenStoreHealWindow ():
301 global StoreHealWindow
303 GemRB.HideGUI ()
304 SelectStoreAction ('heal')
306 if StoreHealWindow != None:
307 Window = StoreHealWindow
308 GemRB.SetVar ("OtherWindow", Window.ID)
309 UpdateStoreHealWindow ()
310 GemRB.UnhideGUI ()
311 return
313 StoreHealWindow = Window = GemRB.LoadWindow (6)
314 GemRB.SetVar ("OtherWindow", Window.ID)
316 # title ...
317 Label = Window.GetControl (0x0fffffff)
318 Label.SetText (store_name)
320 # price ...
321 Label = Window.GetControl (0x10000001)
322 Label.SetText (str (666))
324 # price ...
325 Label = Window.GetControl (0x1000000e)
326 Label.SetText (character_name)
328 # Heal
329 Button = Window.GetControl (3)
330 Button.SetText (8836) # FIXME: better strref
333 # 13 ta
335 UpdateStoreHealWindow ()
336 GemRB.UnhideGUI ()
339 def OpenStoreRumourWindow ():
340 global StoreRumourWindow
342 GemRB.HideGUI ()
343 SelectStoreAction ('rumour')
345 if StoreRumourWindow != None:
346 Window = StoreRumourWindow
347 GemRB.SetVar ("OtherWindow", Window.ID)
348 UpdateStoreRumourWindow ()
349 GemRB.UnhideGUI ()
350 return
352 StoreRumourWindow = Window = GemRB.LoadWindow (9)
353 GemRB.SetVar ("OtherWindow", Window.ID)
355 # title ...
356 Label = Window.GetControl (0x1000000a)
357 Label.SetText (store_name)
359 # 13 ta, 15 ta
361 UpdateStoreRumourWindow ()
362 GemRB.UnhideGUI ()
365 def OpenStoreRentWindow ():
366 global StoreRentWindow, HelpStoreRent
368 GemRB.HideGUI ()
369 SelectStoreAction ('rent')
371 if StoreRentWindow != None:
372 Window = StoreRentWindow
373 GemRB.SetVar ("OtherWindow", Window.ID)
374 UpdateStoreRentWindow ()
375 GemRB.UnhideGUI ()
376 return
378 StoreRentWindow = Window = GemRB.LoadWindow (8)
379 GemRB.SetVar ("OtherWindow", Window.ID)
381 # title ...
382 Label = Window.GetControl (0x1000000a)
383 Label.SetText (store_name)
385 # Peasant
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)
392 # Merchant
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)
399 # Noble
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)
406 # Royal
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)
414 # Rent
415 Button = Window.GetControl (8)
416 Button.SetText (45306)
417 Button.SetState (IE_GUI_BUTTON_DISABLED)
420 # price ...
421 Label = Window.GetControl (0x1000000c)
422 Label.SetText ("0")
424 HelpStoreRent = Text = Window.GetControl (9)
427 GemRB.UnhideGUI ()
430 last_room = None
431 def SelectStoreRent (room):
432 global last_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]))
452 last_room = room
454 def SelectStoreRentPeasant ():
455 SelectStoreRent (0)
457 def SelectStoreRentMerchant ():
458 SelectStoreRent (1)
460 def SelectStoreRentNoble ():
461 SelectStoreRent (2)
463 def SelectStoreRentRoyal ():
464 SelectStoreRent (3)
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
480 GemRB.HideGUI ()
481 UpdateStoreCommon ()
483 # character name ...
484 Label = Window.GetControl (0x10000005)
485 Label.SetText (character_name)
487 # party gold ...
488 Label = Window.GetControl (0x10000002)
489 Label.SetText (str (party_gold))
490 GemRB.UnhideGUI ()
492 def UpdateStoreIdentifyWindow ():
493 Window = StoreIdentifyWindow
495 GemRB.HideGUI ()
496 UpdateStoreCommon ()
498 # party gold ...
499 Label = Window.GetControl (0x10000000)
500 Label.SetText (str (party_gold))
502 # character name ...
503 Label = Window.GetControl (0x10000002)
504 Label.SetText (character_name)
506 GemRB.UnhideGUI ()
508 def UpdateStoreStealWindow ():
509 Window = StoreStealWindow
511 GemRB.HideGUI ()
512 UpdateStoreCommon ()
514 # party gold ...
515 Label = Window.GetControl (0x10000001)
516 Label.SetText (str (party_gold))
518 # character name ...
519 Label = Window.GetControl (0x10000002)
520 Label.SetText (character_name)
522 GemRB.UnhideGUI ()
524 def UpdateStoreDonateWindow ():
525 Window = StoreDonateWindow
527 GemRB.HideGUI ()
528 UpdateStoreCommon ()
530 # party gold ...
531 Label = Window.GetControl (0x10000006)
532 Label.SetText (str (party_gold))
534 GemRB.UnhideGUI ()
536 def UpdateStoreHealWindow ():
537 Window = StoreHealWindow
539 GemRB.HideGUI ()
540 UpdateStoreCommon ()
542 # party gold ...
543 Label = Window.GetControl (0x10000000)
544 Label.SetText (str (party_gold))
546 GemRB.UnhideGUI ()
548 def UpdateStoreRumourWindow ():
549 Window = StoreRumourWindow
551 GemRB.HideGUI ()
552 UpdateStoreCommon ()
554 # party gold ...
555 Label = Window.GetControl (0x1000000b)
556 Label.SetText (str (party_gold))
558 GemRB.UnhideGUI ()
560 def UpdateStoreRentWindow ():
561 Window = StoreRentWindow
563 GemRB.HideGUI ()
564 UpdateStoreCommon ()
566 # party gold ...
567 Label = Window.GetControl (0x1000000b)
568 Label.SetText (str (party_gold))
570 GemRB.UnhideGUI ()
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:
595 if StoreStealWindow:
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:
613 if StoreHealWindow:
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:
631 if StoreRentWindow:
632 StoreRentWindow.Unload ()
633 StoreRentWindow = None
636 ###################################################
637 # End of file GUISTORE.py