GUIScript: Use None instead if "", for null event handler.
[gemrb.git] / gemrb / GUIScripts / iwd / GUISTORE.py
blob9afdd9c8d8eb1184c57f1b97d168bcbf1559fc25
1 # -*-python-*-
2 # GemRB - Infinity Engine Emulator
3 # Copyright (C) 2003-2005 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 GUICommonWindows
27 from GUIDefines import *
28 from GUICommonWindows import *
29 from ie_stats import *
30 from ie_slots import *
31 from GUICommon import CheckStat100
32 from GUICommon import GameWindow
34 StoreWindow = None
35 MessageWindow = None
36 ActionWindow = None
37 PortraitWindow = None
38 StoreShoppingWindow = None
39 StoreIdentifyWindow = None
40 StoreStealWindow = None
41 StoreDonateWindow = None
42 StoreHealWindow = None
43 StoreRumourWindow = None
44 StoreRentWindow = None
45 OldPortraitWindow = None
46 RentConfirmWindow = None
47 LeftButton = None
48 RightButton = None
50 ITEM_PC = 0
51 ITEM_STORE = 1
53 Inventory = None
54 RentIndex = -1
55 Store = None
56 Buttons = [-1,-1,-1,-1]
57 inventory_slots = ()
58 total_price = 0
59 total_income = 0
61 # 0 - Store
62 # 1 - Tavern
63 # 2 - Inn
64 # 3 - Temple
65 # 4 - Container
66 # 5 - Container
68 # 0 - buy/sell
69 # 1 - identify
70 # 2 - steal
71 # 3 - heal
72 # 4 - donate
73 # 5 - drink
74 # 6 - rent
76 storebams = ("STORSTOR","STORTVRN","STORINN","STORTMPL","STORSTOR","STORSTOR")
77 storetips = (14288,14292,14291,12138,15013,14289,14287)
78 roomtypes = (17389,17517,17521,17519)
79 store_funcs = ( "OpenStoreShoppingWindow", "OpenStoreIdentifyWindow",
80 "OpenStoreStealWindow", "OpenStoreHealWindow", "OpenStoreDonateWindow",
81 "OpenStoreRumourWindow", "OpenStoreRentWindow" )
82 store_update_funcs = None
84 def CloseWindows ():
85 CloseStoreShoppingWindow ()
86 CloseStoreIdentifyWindow ()
87 CloseStoreStealWindow ()
88 CloseStoreHealWindow ()
89 CloseStoreDonateWindow ()
90 CloseStoreRumourWindow ()
91 CloseStoreRentWindow ()
92 return
94 def CloseStoreWindow ():
95 global StoreWindow, ActionWindow, PortraitWindow
96 global OldPortraitWindow
98 GemRB.SetVar ("Inventory", 0)
99 CloseWindows ()
100 if StoreWindow:
101 StoreWindow.Unload ()
102 if ActionWindow:
103 ActionWindow.Unload ()
104 if PortraitWindow:
105 PortraitWindow.Unload ()
106 StoreWindow = None
107 GemRB.LeaveStore ()
108 GUICommonWindows.PortraitWindow = OldPortraitWindow
109 if Inventory:
110 GemRB.RunEventHandler("OpenInventoryWindow")
111 else:
112 GameWindow.SetVisible(WINDOW_VISIBLE) #enabling the game control screen
113 GemRB.UnhideGUI () #enabling the other windows
114 SetSelectionChangeHandler( None )
115 return
117 def OpenStoreWindow ():
118 global Store
119 global StoreWindow, ActionWindow, PortraitWindow
120 global OldPortraitWindow
121 global store_update_funcs
122 global Inventory
124 #these are function pointers, not strings
125 #can't put this in global init, doh!
126 store_update_funcs = (OpenStoreShoppingWindow,
127 OpenStoreIdentifyWindow,OpenStoreStealWindow,
128 OpenStoreHealWindow, OpenStoreDonateWindow,
129 OpenStoreRumourWindow,OpenStoreRentWindow )
131 GemRB.HideGUI ()
132 GameWindow.SetVisible(WINDOW_INVISIBLE) #removing the game control screen
134 if GemRB.GetVar ("Inventory"):
135 Inventory = 1
136 else:
137 Inventory = None
139 GemRB.SetVar ("Action", 0)
140 GemRB.LoadWindowPack ("GUISTORE", 640, 480)
141 StoreWindow = Window = GemRB.LoadWindow (3)
142 #saving the original portrait window
143 OldPortraitWindow = GUICommonWindows.PortraitWindow
144 PortraitWindow = OpenPortraitWindow (0)
145 ActionWindow = GemRB.LoadWindow (0)
146 #this window is static and grey, but good to stick the frame onto
147 ActionWindow.SetFrame ()
149 Store = GemRB.GetStore ()
151 # Done
152 Button = Window.GetControl (0)
153 Button.SetText (11973)
154 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "CloseStoreWindow")
156 #Store type icon
157 Button = Window.GetControl (5)
158 Button.SetSprites (storebams[Store['StoreType']],0,0,0,0,0)
160 #based on shop type, these buttons will change
161 store_type = Store['StoreType']
162 store_buttons = Store['StoreButtons']
163 for i in range (4):
164 Buttons[i] = Button = Window.GetControl (i+1)
165 Action = store_buttons[i]
166 Button.SetVarAssoc ("Action", i)
167 if Action>=0:
168 Button.SetFlags (IE_GUI_BUTTON_RADIOBUTTON, OP_OR)
169 #this is different from BG???
170 Button.SetSprites ("GUISTBBC", Action, 1,2,0,0)
171 Button.SetTooltip (storetips[Action])
172 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, store_funcs[Action])
173 Button.SetState (IE_GUI_BUTTON_ENABLED)
174 else:
175 Button.SetFlags (IE_GUI_BUTTON_NO_IMAGE, OP_OR)
176 Button.SetTooltip ("")
177 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, None)
178 Button.SetState (IE_GUI_BUTTON_DISABLED)
180 ActionWindow.SetVisible (WINDOW_VISIBLE)
181 Window.SetVisible (WINDOW_VISIBLE)
182 store_update_funcs[store_buttons[0]] ()
183 PortraitWindow.SetVisible (WINDOW_VISIBLE)
184 return
186 def OpenStoreShoppingWindow ():
187 global StoreShoppingWindow
188 global LeftButton, RightButton
190 CloseWindows()
192 StoreShoppingWindow = Window = GemRB.LoadWindow (2)
194 if Inventory:
195 # Title
196 Label = Window.GetControl (0xfffffff)
197 Label.SetText (26291)
198 # buy price ...
199 Label = Window.GetControl (0x1000002b)
200 Label.SetText ("")
201 # sell price ...
202 Label = Window.GetControl (0x1000002c)
203 Label.SetText ("")
204 # buy price ...
205 Label = Window.GetControl (0x1000002f)
206 Label.SetText ("")
207 # sell price ...
208 Label = Window.GetControl (0x10000030)
209 Label.SetText ("")
210 else:
211 # buy price ...
212 Label = Window.GetControl (0x1000002b)
213 Label.SetText ("0")
215 # sell price ...
216 Label = Window.GetControl (0x1000002c)
217 Label.SetText ("0")
219 for i in range (4):
220 Button = Window.GetControl (i+5)
221 Button.SetBorder (0,0,0,0,0,32,32,192,128,0,1)
222 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "SelectBuy")
223 Button.SetEventByName (IE_GUI_BUTTON_ON_RIGHT_PRESS, "InfoLeftWindow")
225 Button = Window.GetControl (i+13)
226 Button.SetBorder (0,0,0,0,0,32,32,192,128,0,1)
227 if Store['StoreType'] != 3: # can't sell to temples
228 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "SelectSell")
229 Button.SetEventByName (IE_GUI_BUTTON_ON_RIGHT_PRESS, "InfoRightWindow")
231 # Buy
232 LeftButton = Button = Window.GetControl (2)
233 if Inventory:
234 Button.SetText (26287)
235 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "ToBackpackPressed")
236 else:
237 Button.SetText (13703)
238 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "BuyPressed")
240 # Sell
241 RightButton = Button = Window.GetControl (3)
242 if Inventory:
243 Button.SetText (26288)
244 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "ToBagPressed")
245 else:
246 Button.SetText (13704)
247 if Store['StoreType'] != 3: # can't sell to temples
248 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "SellPressed")
250 # inactive button
251 #Button = Window.GetControl (50)
252 #Button.SetState (IE_GUI_BUTTON_LOCKED)
253 #Button.SetFlags (IE_GUI_BUTTON_NO_IMAGE, OP_SET)
255 #backpack
256 Button = Window.GetControl (44)
257 Button.SetState (IE_GUI_BUTTON_LOCKED)
259 # encumbrance
260 Label = Window.CreateLabel (0x10000043, 15,325,60,15,"NUMBER","0:",IE_FONT_ALIGN_LEFT|IE_FONT_ALIGN_TOP)
261 Label = Window.CreateLabel (0x10000044, 15,365,80,15,"NUMBER","0:",IE_FONT_ALIGN_RIGHT|IE_FONT_ALIGN_TOP)
263 # left scrollbar
264 ScrollBar = Window.GetControl (11)
265 ScrollBar.SetEventByName (IE_GUI_SCROLLBAR_ON_CHANGE, "RedrawStoreShoppingWindow")
267 # right scrollbar
268 ScrollBar = Window.GetControl (12)
269 ScrollBar.SetEventByName (IE_GUI_SCROLLBAR_ON_CHANGE, "RedrawStoreShoppingWindow")
271 SetSelectionChangeHandler( UpdateStoreShoppingWindow )
272 UpdateStoreShoppingWindow ()
273 Window.SetVisible (WINDOW_VISIBLE)
274 return
276 def OpenStoreIdentifyWindow ():
277 global StoreIdentifyWindow
279 GemRB.SetVar ("Index", -1)
280 GemRB.SetVar ("TopIndex", 0)
281 CloseWindows()
283 StoreIdentifyWindow = Window = GemRB.LoadWindow (4)
285 # Identify
286 Button = Window.GetControl (5)
287 Button.SetText (14133)
288 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "IdentifyPressed")
289 Button.SetEventByName (IE_GUI_BUTTON_ON_RIGHT_PRESS, "InfoIdentifyWindow")
291 # price ...
292 Label = Window.GetControl (0x10000003)
293 Label.SetText ("0")
295 # 8-11 item slots, 0x1000000c-f labels
296 for i in range (4):
297 Button = Window.GetControl (i+8)
298 Button.SetFlags (IE_GUI_BUTTON_RADIOBUTTON, OP_OR)
299 Button.SetSprites ("GUISTMSC", 0, 1,2,0,3)
300 Button.SetBorder (0,0,0,0,0,32,32,192,128,0,1)
301 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "RedrawStoreIdentifyWindow")
302 Button.SetEventByName (IE_GUI_BUTTON_ON_RIGHT_PRESS, "InfoIdentifyWindow")
304 ScrollBar = Window.GetControl (7)
305 ScrollBar.SetEventByName (IE_GUI_SCROLLBAR_ON_CHANGE, "RedrawStoreIdentifyWindow")
307 SetSelectionChangeHandler( UpdateStoreIdentifyWindow )
308 UpdateStoreIdentifyWindow ()
309 Window.SetVisible (WINDOW_VISIBLE)
310 return
312 def OpenStoreStealWindow ():
313 global StoreStealWindow
314 global LeftButton
316 GemRB.SetVar ("RightIndex", 0)
317 GemRB.SetVar ("LeftIndex", 0)
318 CloseWindows()
320 StoreStealWindow = Window = GemRB.LoadWindow (6)
322 for i in range (4):
323 Button = Window.GetControl (i+4)
324 Button.SetBorder (0,0,0,0,0,32,32,192,128,0,1)
325 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "RedrawStoreStealWindow")
327 Button = Window.GetControl (i+11)
328 Button.SetBorder (0,0,0,0,0,32,32,192,128,0,1)
329 Button.SetEventByName (IE_GUI_BUTTON_ON_RIGHT_PRESS, "InfoRightWindow")
331 # Steal
332 LeftButton = Button = Window.GetControl (1)
333 Button.SetText (14179)
334 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "StealPressed")
336 Button = Window.GetControl (37)
337 Button.SetState (IE_GUI_BUTTON_LOCKED)
339 # encumbrance
340 Label = Window.CreateLabel (0x10000043, 15,325,60,15,"NUMBER","0:",IE_FONT_ALIGN_LEFT|IE_FONT_ALIGN_TOP)
341 Label = Window.CreateLabel (0x10000044, 15,365,80,15,"NUMBER","0:",IE_FONT_ALIGN_RIGHT|IE_FONT_ALIGN_TOP)
343 # left scrollbar
344 ScrollBar = Window.GetControl (9)
345 ScrollBar.SetEventByName (IE_GUI_SCROLLBAR_ON_CHANGE, "RedrawStoreStealWindow")
347 # right scrollbar
348 ScrollBar = Window.GetControl (10)
349 ScrollBar.SetEventByName (IE_GUI_SCROLLBAR_ON_CHANGE, "RedrawStoreStealWindow")
351 SetSelectionChangeHandler( UpdateStoreStealWindow )
352 UpdateStoreStealWindow ()
353 Window.SetVisible (WINDOW_VISIBLE)
354 return
356 def OpenStoreDonateWindow ():
357 global StoreDonateWindow
359 CloseWindows ()
361 StoreDonateWindow = Window = GemRB.LoadWindow (9)
363 # graphics
364 Button = Window.GetControl (10)
365 Button.SetFlags (IE_GUI_BUTTON_PICTURE|IE_GUI_BUTTON_ANIMATED|IE_GUI_BUTTON_PLAYONCE, OP_OR)
366 Button.SetState (IE_GUI_BUTTON_LOCKED)
368 # Donate
369 Button = Window.GetControl (3)
370 Button.SetText (15101)
371 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "DonateGold")
372 Button.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
374 # Entry
375 Field = Window.GetControl (5)
376 Field.SetText ("0")
377 Field.SetEventByName (IE_GUI_EDIT_ON_CHANGE, "UpdateStoreDonateWindow")
378 Field.SetStatus (IE_GUI_EDIT_NUMBER)
381 Button = Window.GetControl (6)
382 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "IncrementDonation")
384 Button = Window.GetControl (7)
385 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "DecrementDonation")
387 SetSelectionChangeHandler( UpdateStoreDonateWindow )
388 UpdateStoreDonateWindow ()
389 Window.SetVisible (WINDOW_VISIBLE)
390 return
392 def OpenStoreHealWindow ():
393 global StoreHealWindow
395 GemRB.SetVar ("Index", -1)
396 GemRB.SetVar ("TopIndex", 0)
397 CloseWindows()
399 StoreHealWindow = Window = GemRB.LoadWindow (5)
401 #spell buttons
402 for i in range (4):
403 Button = Window.GetControl (i+8)
404 Button.SetFlags (IE_GUI_BUTTON_RADIOBUTTON, OP_OR)
405 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "UpdateStoreHealWindow")
406 Button.SetEventByName (IE_GUI_BUTTON_ON_RIGHT_PRESS, "InfoHealWindow")
408 # price tag
409 Label = Window.GetControl (0x10000003)
410 Label.SetText ("0")
412 # Heal
413 Button = Window.GetControl (5)
414 Button.SetText (13703)
415 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "BuyHeal")
416 Button.SetState (IE_GUI_BUTTON_DISABLED)
418 ScrollBar = Window.GetControl (7)
419 ScrollBar.SetEventByName (IE_GUI_SCROLLBAR_ON_CHANGE, "UpdateStoreHealWindow")
420 Count = Store['StoreCureCount']
421 if Count>4:
422 Count = Count-4
423 else:
424 Count = 0
425 ScrollBar.SetVarAssoc ("TopIndex", Count+1)
427 UpdateStoreHealWindow ()
428 Window.SetVisible (WINDOW_VISIBLE)
429 return
431 def OpenStoreRumourWindow ():
432 global StoreRumourWindow
434 GemRB.SetVar ("TopIndex", 0)
435 CloseWindows()
437 StoreRumourWindow = Window = GemRB.LoadWindow (8)
439 #removing those pesky labels
440 for i in range (5):
441 Window.DeleteControl (0x10000005+i)
443 TextArea = Window.GetControl (11)
444 TextArea.SetText (14144)
446 #the quality isn't displayed in iwd
447 #BAM = "TVRNQUL%d"% ((Store['StoreFlags']>>9)&3)
448 #Button = Window.GetControl (12)
449 #Button.SetSprites (BAM, 0, 0, 0, 0, 0)
450 #Button.SetState (IE_GUI_BUTTON_LOCKED)
452 ScrollBar = Window.GetControl (5)
453 ScrollBar.SetEventByName (IE_GUI_SCROLLBAR_ON_CHANGE, "UpdateStoreRumourWindow")
454 Count = Store['StoreDrinkCount']
455 if Count>4:
456 Count = Count-4
457 else:
458 Count = 0
459 ScrollBar.SetVarAssoc ("TopIndex", Count+1)
461 UpdateStoreRumourWindow ()
462 Window.SetVisible (WINDOW_VISIBLE)
463 return
465 def OpenStoreRentWindow ():
466 global StoreRentWindow, RentIndex
468 CloseWindows()
470 StoreRentWindow = Window = GemRB.LoadWindow (7)
472 # room types
473 RentIndex = -1
474 for i in range (4):
475 ok = Store['StoreRoomPrices'][i]
476 Button = Window.GetControl (i)
477 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "UpdateStoreRentWindow")
478 if ok<0:
479 Button.SetState (IE_GUI_BUTTON_DISABLED) #disabled room icons are selected, not disabled
480 else:
481 Button.SetVarAssoc ("RentIndex", i)
482 if RentIndex==-1:
483 RentIndex = i
485 Button = Window.GetControl (i+4)
486 Button.SetText (14294+i)
487 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "UpdateStoreRentWindow")
488 Button.SetFlags (IE_GUI_BUTTON_RADIOBUTTON, OP_OR)
489 Button.SetVarAssoc ("RentIndex", i)
490 if ok<0:
491 Button.SetState (IE_GUI_BUTTON_DISABLED)
493 # Rent
494 Button = Window.GetControl (11)
495 Button.SetText (14293)
496 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "RentRoom")
498 GemRB.SetVar ("RentIndex", RentIndex)
500 UpdateStoreRentWindow ()
501 Window.SetVisible (WINDOW_VISIBLE)
502 return
504 def UpdateStoreCommon (Window, title, name, gold):
506 Label = Window.GetControl (title)
507 Label.SetText (Store['StoreName'])
509 if name:
510 pc = GemRB.GameGetSelectedPCSingle ()
511 Label = Window.GetControl (name)
512 Label.SetText (GemRB.GetPlayerName (pc, 0) )
514 Label = Window.GetControl (gold)
515 Label.SetText (str(GemRB.GameGetPartyGold ()))
516 return
518 def UpdateStoreShoppingWindow ():
519 global Store, inventory_slots
521 Window = StoreShoppingWindow
522 #reget store in case of a change
523 Store = GemRB.GetStore ()
524 LeftCount = Store['StoreItemCount']-3
525 if LeftCount<0:
526 LeftCount=0
527 ScrollBar = Window.GetControl (11)
528 ScrollBar.SetVarAssoc ("LeftTopIndex", LeftCount)
529 LeftTopIndex = GemRB.GetVar ("LeftTopIndex")
530 if LeftTopIndex>LeftCount:
531 GemRB.SetVar ("LeftTopIndex", LeftCount)
533 pc = GemRB.GameGetSelectedPCSingle ()
534 inventory_slots = GemRB.GetSlots (pc, SLOT_INVENTORY)
535 RightCount = len(inventory_slots)-3
536 if RightCount<0:
537 RightCount=0
538 ScrollBar = Window.GetControl (12)
539 ScrollBar.SetVarAssoc ("RightTopIndex", RightCount)
540 RightTopIndex = GemRB.GetVar ("RightTopIndex")
541 if RightTopIndex>RightCount:
542 GemRB.SetVar ("RightTopIndex", RightCount)
544 RedrawStoreShoppingWindow ()
545 return
547 def SelectBuy ():
548 Window = StoreShoppingWindow
550 pc = GemRB.GameGetSelectedPCSingle ()
551 LeftIndex = GemRB.GetVar ("LeftIndex")
552 GemRB.ChangeStoreItem (pc, LeftIndex, SHOP_BUY|SHOP_SELECT)
553 RedrawStoreShoppingWindow ()
554 return
556 def ToBackpackPressed ():
557 Window = StoreShoppingWindow
559 pc = GemRB.GameGetSelectedPCSingle ()
560 LeftCount = Store['StoreItemCount']
561 #going backwards because removed items shift the slots
562 for i in range (LeftCount, 0, -1):
563 Flags = GemRB.IsValidStoreItem (pc, i-1, ITEM_STORE)&SHOP_SELECT
564 if Flags:
565 GemRB.ChangeStoreItem (pc, i-1, SHOP_BUY)
567 UpdateStoreShoppingWindow ()
568 return
570 def BuyPressed ():
571 Window = StoreShoppingWindow
573 if (BuySum>GemRB.GameGetPartyGold ()):
574 ErrorWindow (11047)
575 return
577 pc = GemRB.GameGetSelectedPCSingle ()
578 LeftCount = Store['StoreItemCount']
579 #going backwards because removed items shift the slots
580 for i in range (LeftCount, 0, -1):
581 Flags = GemRB.IsValidStoreItem (pc, i-1, ITEM_STORE)&SHOP_SELECT
582 if Flags:
583 Slot = GemRB.GetStoreItem (i-1)
584 Item = GemRB.GetItem (Slot['ItemResRef'])
585 Price = Item['Price'] * Store['SellMarkup'] / 100
586 if Price <= 0:
587 Price = 1
589 if GemRB.ChangeStoreItem (pc, i-1, SHOP_BUY):
590 GemRB.GameSetPartyGold (GemRB.GameGetPartyGold ()-Price)
591 UpdateStoreShoppingWindow ()
592 return
594 def SelectSell ():
595 Window = StoreShoppingWindow
597 pc = GemRB.GameGetSelectedPCSingle ()
598 RightIndex = GemRB.GetVar ("RightIndex")
599 GemRB.ChangeStoreItem (pc, inventory_slots[RightIndex], SHOP_SELL|SHOP_SELECT)
600 RedrawStoreShoppingWindow ()
601 return
603 def ToBagPressed ():
604 Window = StoreShoppingWindow
606 pc = GemRB.GameGetSelectedPCSingle ()
607 RightCount = len (inventory_slots)
608 #no need to go reverse
609 for Slot in range (RightCount):
610 Flags = GemRB.IsValidStoreItem (pc, inventory_slots[Slot], ITEM_PC)
611 if Flags & SHOP_SELECT:
612 GemRB.ChangeStoreItem (pc, inventory_slots[Slot], SHOP_SELL)
613 UpdateStoreShoppingWindow ()
614 return
616 def SellPressed ():
617 Window = StoreShoppingWindow
619 pc = GemRB.GameGetSelectedPCSingle ()
620 RightCount = len (inventory_slots)
621 #no need to go reverse
622 for Slot in range (RightCount):
623 Flags = GemRB.IsValidStoreItem (pc, inventory_slots[Slot], ITEM_PC) & SHOP_SELECT
624 if Flags:
625 GemRB.ChangeStoreItem (pc, inventory_slots[Slot], SHOP_SELL)
627 GemRB.GameSetPartyGold (GemRB.GameGetPartyGold ()+SellSum)
628 UpdateStoreShoppingWindow ()
629 return
631 def RedrawStoreShoppingWindow ():
632 global BuySum, SellSum
634 Window = StoreShoppingWindow
636 UpdateStoreCommon (Window, 0x10000003, 0x1000002e, 0x1000002a)
637 pc = GemRB.GameGetSelectedPCSingle ()
639 LeftTopIndex = GemRB.GetVar ("LeftTopIndex")
640 LeftIndex = GemRB.GetVar ("LeftIndex")
641 RightTopIndex = GemRB.GetVar ("RightTopIndex")
642 RightIndex = GemRB.GetVar ("RightIndex")
643 LeftCount = Store['StoreItemCount']
644 BuySum = 0
645 for i in range (LeftCount):
646 if GemRB.IsValidStoreItem (pc, i, ITEM_STORE) & SHOP_SELECT:
647 Slot = GemRB.GetStoreItem (i)
648 Item = GemRB.GetItem (Slot['ItemResRef'])
649 if Inventory:
650 Price = 1
651 else:
652 Price = Item['Price'] * Store['SellMarkup'] / 100
653 if Price <= 0:
654 Price = 1
655 BuySum = BuySum + Price
657 RightCount = len(inventory_slots)
658 SellSum = 0
659 for i in range (RightCount):
660 Flags = GemRB.IsValidStoreItem (pc, inventory_slots[i], ITEM_PC)
661 if Flags & SHOP_SELECT:
662 Slot = GemRB.GetSlotItem (pc, inventory_slots[i])
663 Item = GemRB.GetItem (Slot['ItemResRef'])
664 if Inventory:
665 Price = 1
666 else:
667 Price = Item['Price'] * Store['BuyMarkup'] / 100
668 if Flags & SHOP_ID:
669 Price = 1
670 SellSum = SellSum + Price
672 Label = Window.GetControl (0x1000002b)
673 if Inventory:
674 Label.SetText ("")
675 else:
676 Label.SetText (str(BuySum) )
677 if BuySum:
678 LeftButton.SetState (IE_GUI_BUTTON_ENABLED)
679 else:
680 LeftButton.SetState (IE_GUI_BUTTON_DISABLED)
682 Label = Window.GetControl (0x1000002c)
683 if Inventory:
684 Label.SetText ("")
685 else:
686 Label.SetText (str(SellSum) )
687 if SellSum:
688 RightButton.SetState (IE_GUI_BUTTON_ENABLED)
689 else:
690 RightButton.SetState (IE_GUI_BUTTON_DISABLED)
692 for i in range (4):
693 if i+LeftTopIndex<LeftCount:
694 Slot = GemRB.GetStoreItem (i+LeftTopIndex)
695 else:
696 Slot = None
697 Button = Window.GetControl (i+5)
698 Label = Window.GetControl (0x10000012+i)
699 Button.SetVarAssoc ("LeftIndex", LeftTopIndex+i)
700 if Slot != None:
701 Flags = GemRB.IsValidStoreItem (pc, i+LeftTopIndex, ITEM_STORE)
702 Item = GemRB.GetItem (Slot['ItemResRef'])
703 Button.SetItemIcon (Slot['ItemResRef'], 0)
704 Button.SetFlags (IE_GUI_BUTTON_NO_IMAGE, OP_NAND)
705 Button.SetFlags (IE_GUI_BUTTON_PICTURE, OP_OR)
706 if Flags & SHOP_BUY:
707 if Flags & SHOP_SELECT:
708 Button.SetState (IE_GUI_BUTTON_SELECTED)
709 else:
710 Button.SetState (IE_GUI_BUTTON_ENABLED)
711 else:
712 Button.SetState (IE_GUI_BUTTON_DISABLED)
714 if Flags & SHOP_ID:
715 GemRB.SetToken ("ITEMNAME", GemRB.GetString (Item['ItemName']))
716 Button.EnableBorder (0, 1)
717 else:
718 GemRB.SetToken ("ITEMNAME", GemRB.GetString (Item['ItemNameIdentified']))
719 Button.EnableBorder (0, 0)
721 if Inventory:
722 Label.SetText (24890) #different from BG
723 else:
724 Price = Item['Price'] * Store['SellMarkup'] / 100
725 if Price <= 0:
726 Price = 1
727 GemRB.SetToken ("ITEMCOST", str(Price) )
728 Label.SetText (10162)
729 else:
730 Button.SetState (IE_GUI_BUTTON_DISABLED)
731 Button.SetFlags (IE_GUI_BUTTON_NO_IMAGE, OP_OR)
732 Button.SetFlags (IE_GUI_BUTTON_PICTURE, OP_NAND)
733 Label.SetText ("")
735 if i+RightTopIndex<RightCount:
736 Slot = GemRB.GetSlotItem (pc, inventory_slots[i+RightTopIndex])
737 else:
738 Slot = None
739 Button = Window.GetControl (i+13)
740 Label = Window.GetControl (0x1000001e+i)
741 Button.SetVarAssoc ("RightIndex", RightTopIndex+i)
742 if Slot != None:
743 Flags = GemRB.IsValidStoreItem (pc, inventory_slots[i+RightTopIndex], ITEM_PC)
744 Item = GemRB.GetItem (Slot['ItemResRef'])
745 Button.SetItemIcon (Slot['ItemResRef'], 0)
746 Button.SetFlags (IE_GUI_BUTTON_NO_IMAGE, OP_NAND)
747 Button.SetFlags (IE_GUI_BUTTON_PICTURE, OP_OR)
748 if Inventory:
749 Price = 1
750 else:
751 Price = Item['Price'] * Store['BuyMarkup'] / 100
753 if (Price>0) and (Flags & SHOP_SELL):
754 if Flags & SHOP_SELECT:
755 Button.SetState (IE_GUI_BUTTON_SELECTED)
756 else:
757 Button.SetState (IE_GUI_BUTTON_ENABLED)
758 else:
759 Button.SetState (IE_GUI_BUTTON_DISABLED)
761 if Flags & SHOP_ID:
762 GemRB.SetToken ("ITEMNAME", GemRB.GetString (Item['ItemName']))
763 Price = 1
764 Button.EnableBorder (0, 1)
765 else:
766 GemRB.SetToken ("ITEMNAME", GemRB.GetString (Item['ItemNameIdentified']))
767 Button.EnableBorder (0, 0)
769 if Inventory:
770 Label.SetText (24890) #different from BG
771 else:
772 GemRB.SetToken ("ITEMCOST", str(Price) )
773 Label.SetText (10162)
774 else:
775 Button.SetState (IE_GUI_BUTTON_DISABLED)
776 Button.SetFlags (IE_GUI_BUTTON_NO_IMAGE, OP_OR)
777 Button.SetFlags (IE_GUI_BUTTON_PICTURE, OP_NAND)
778 Label.SetText ("")
779 return
781 def UpdateStoreIdentifyWindow ():
782 global inventory_slots
784 Window = StoreIdentifyWindow
786 pc = GemRB.GameGetSelectedPCSingle ()
787 inventory_slots = GemRB.GetSlots (pc, SLOT_INVENTORY)
788 Count = len(inventory_slots)
789 ScrollBar = Window.GetControl (7)
790 ScrollBar.SetVarAssoc ("TopIndex", Count-3)
791 GemRB.SetVar ("Index", -1)
792 RedrawStoreIdentifyWindow ()
793 return
795 def RedrawStoreIdentifyWindow ():
796 Window = StoreIdentifyWindow
798 UpdateStoreCommon (Window, 0x10000000, 0x10000005, 0x10000001)
799 TopIndex = GemRB.GetVar ("TopIndex")
800 Index = GemRB.GetVar ("Index")
801 pc = GemRB.GameGetSelectedPCSingle ()
802 Count = len(inventory_slots)
803 IDPrice = Store['IDPrice']
805 TextArea = Window.GetControl (23)
806 TextArea.SetText ("")
807 Selected = 0
808 for i in range (4):
809 if TopIndex+i<Count:
810 Slot = GemRB.GetSlotItem (pc, inventory_slots[TopIndex+i])
811 else:
812 Slot = None
813 Button = Window.GetControl (i+8)
814 Label = Window.GetControl (0x1000000c+i)
815 Button.SetVarAssoc ("Index", TopIndex+i)
816 if Slot != None:
817 Flags = GemRB.IsValidStoreItem (pc, inventory_slots[TopIndex+i], ITEM_PC)
818 Item = GemRB.GetItem (Slot['ItemResRef'])
819 Button.SetItemIcon (Slot['ItemResRef'], 0)
820 Button.SetFlags (IE_GUI_BUTTON_NO_IMAGE, OP_NAND)
821 Button.SetFlags (IE_GUI_BUTTON_PICTURE, OP_OR)
822 if Flags & SHOP_ID:
823 if Index == TopIndex+i:
824 Button.SetState (IE_GUI_BUTTON_SELECTED)
825 Text = Item['ItemDesc']
826 TextArea.SetText (Text)
827 Selected = 1
828 else:
829 Button.SetState (IE_GUI_BUTTON_ENABLED)
831 GemRB.SetToken ("ITEMNAME", GemRB.GetString (Item['ItemName']))
832 GemRB.SetToken ("ITEMCOST", str(IDPrice) )
833 Button.EnableBorder (0, 1)
834 else:
835 if Index == TopIndex+i:
836 Text = Item['ItemDescIdentified']
837 TextArea.SetText (Text)
838 Button.SetState (IE_GUI_BUTTON_DISABLED)
839 GemRB.SetToken ("ITEMNAME", GemRB.GetString (Item['ItemNameIdentified']))
840 GemRB.SetToken ("ITEMCOST", str(0) )
841 Button.EnableBorder (0, 0)
843 Label.SetText (10162)
844 else:
845 Button.SetState (IE_GUI_BUTTON_DISABLED)
846 Button.SetFlags (IE_GUI_BUTTON_NO_IMAGE, OP_OR)
847 Button.SetFlags (IE_GUI_BUTTON_PICTURE, OP_NAND)
848 Label.SetText ("")
850 Button = Window.GetControl (5)
851 Label = Window.GetControl (0x10000003)
852 if Selected:
853 Button.SetState (IE_GUI_BUTTON_ENABLED)
854 Label.SetText (str(IDPrice) )
855 else:
856 Button.SetState (IE_GUI_BUTTON_DISABLED)
857 Label.SetText (str(0) )
858 return
860 def IdentifyPressed ():
861 IDPrice = Store['IDPrice']
862 if (GemRB.GameGetPartyGold ()<IDPrice):
863 return
865 Index = GemRB.GetVar ("Index")
866 if (Index<0):
867 return
869 pc = GemRB.GameGetSelectedPCSingle ()
870 Count = len(inventory_slots)
871 if Index >= Count:
872 return
874 GemRB.ChangeStoreItem (pc, inventory_slots[Index], SHOP_ID)
875 GemRB.GameSetPartyGold (GemRB.GameGetPartyGold ()-IDPrice)
876 UpdateStoreIdentifyWindow ()
877 return
879 def InfoIdentifyWindow ():
880 Index = GemRB.GetVar ("Index")
881 pc = GemRB.GameGetSelectedPCSingle ()
882 Count = len(inventory_slots)
883 if Index >= Count:
884 return
885 Slot = GemRB.GetSlotItem (pc, inventory_slots[Index])
886 Item = GemRB.GetItem (Slot['ItemResRef'])
887 InfoWindow (Slot, Item)
888 return
890 def InfoLeftWindow ():
891 Index = GemRB.GetVar ("LeftIndex")
892 Slot = GemRB.GetStoreItem (Index)
893 Item = GemRB.GetItem (Slot['ItemResRef'])
894 InfoWindow (Slot, Item)
895 return
897 def InfoRightWindow ():
898 Index = GemRB.GetVar ("RightIndex")
899 pc = GemRB.GameGetSelectedPCSingle ()
900 Count = len(inventory_slots)
901 if Index >= Count:
902 return
903 Slot = GemRB.GetSlotItem (pc, inventory_slots[Index])
904 Item = GemRB.GetItem (Slot['ItemResRef'])
905 InfoWindow (Slot, Item)
906 return
908 def InfoWindow (Slot, Item):
909 global MessageWindow
911 Identify = Slot['Flags'] & IE_INV_ITEM_IDENTIFIED
913 MessageWindow = Window = GemRB.LoadWindow (12)
915 #fake label
916 Label = Window.GetControl (0x10000000)
917 Label.SetText ("")
919 #description bam, only in bg2
920 #Button = Window.GetControl (7)
921 #Button.SetItemIcon (Slot['ItemResRef'], 2)
923 #slot bam
924 Button = Window.GetControl (2)
925 Button.SetItemIcon (Slot['ItemResRef'], 0)
927 Label = Window.GetControl (0x10000007)
928 TextArea = Window.GetControl (5)
929 if Identify:
930 Label.SetText (Item['ItemNameIdentified'])
931 TextArea.SetText (Item['ItemDescIdentified'])
932 else:
933 Label.SetText (Item['ItemName'])
934 TextArea.SetText (Item['ItemDesc'])
936 #Done
937 Button = Window.GetControl (4)
938 Button.SetText (11973)
939 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "ErrorDone")
941 Window.ShowModal (MODAL_SHADOW_GRAY)
942 return
944 def UpdateStoreStealWindow ():
945 global Store, inventory_slots
947 Window = StoreStealWindow
949 #reget store in case of a change
950 Store = GemRB.GetStore ()
951 LeftCount = Store['StoreItemCount']
952 ScrollBar = Window.GetControl (9)
953 ScrollBar.SetVarAssoc ("LeftTopIndex", LeftCount-3)
955 pc = GemRB.GameGetSelectedPCSingle ()
956 inventory_slots = GemRB.GetSlots (pc, SLOT_INVENTORY)
957 RightCount = len(inventory_slots)
958 ScrollBar = Window.GetControl (10)
959 ScrollBar.SetVarAssoc ("RightTopIndex", RightCount-3)
960 GemRB.SetVar ("LeftIndex", -1)
961 LeftButton.SetState (IE_GUI_BUTTON_DISABLED)
962 RedrawStoreStealWindow ()
963 return
965 def StealPressed ():
966 Window = StoreShoppingWindow
968 LeftIndex = GemRB.GetVar ("LeftIndex")
969 pc = GemRB.GameGetSelectedPCSingle ()
970 #percentage skill check, if fails, trigger StealFailed
971 if CheckStat100 (pc, IE_PICKPOCKET, Store['StealFailure']):
972 GemRB.ChangeStoreItem (pc, LeftIndex, SHOP_STEAL)
973 UpdateStoreStealWindow ()
974 else:
975 GemRB.StealFailed ()
976 CloseStoreWindow ()
977 return
979 def RedrawStoreStealWindow ():
980 Window = StoreStealWindow
982 UpdateStoreCommon (Window, 0x10000002, 0x10000027, 0x10000023)
983 LeftTopIndex = GemRB.GetVar ("LeftTopIndex")
984 LeftIndex = GemRB.GetVar ("LeftIndex")
985 RightTopIndex = GemRB.GetVar ("RightTopIndex")
986 RightIndex = GemRB.GetVar ("RightIndex")
987 LeftCount = Store['StoreItemCount']
988 pc = GemRB.GameGetSelectedPCSingle ()
989 RightCount = len(inventory_slots)
990 for i in range (4):
991 Slot = GemRB.GetStoreItem (i+LeftTopIndex)
992 Button = Window.GetControl (i+4)
993 Label = Window.GetControl (0x1000000f+i)
994 Button.SetVarAssoc ("LeftIndex", LeftTopIndex+i)
995 if Slot != None:
996 Flags = GemRB.IsValidStoreItem (pc, i+LeftTopIndex, ITEM_STORE)
997 Item = GemRB.GetItem (Slot['ItemResRef'])
998 Button.SetItemIcon (Slot['ItemResRef'], 0)
999 Button.SetFlags (IE_GUI_BUTTON_NO_IMAGE, OP_NAND)
1000 Button.SetFlags (IE_GUI_BUTTON_PICTURE, OP_OR)
1001 if Flags & SHOP_STEAL:
1002 if LeftIndex == LeftTopIndex + i:
1003 Button.SetState (IE_GUI_BUTTON_SELECTED)
1004 else:
1005 Button.SetState (IE_GUI_BUTTON_ENABLED)
1006 else:
1007 Button.SetState (IE_GUI_BUTTON_DISABLED)
1009 if Flags & SHOP_ID:
1010 GemRB.SetToken ("ITEMNAME", GemRB.GetString (Item['ItemName']))
1011 Button.EnableBorder (0, 1)
1012 else:
1013 GemRB.SetToken ("ITEMNAME", GemRB.GetString (Item['ItemNameIdentified']))
1014 Button.EnableBorder (0, 0)
1016 GemRB.SetToken ("ITEMCOST", str(Slot['Price']) )
1017 Label.SetText (10162)
1018 else:
1019 Button.SetState (IE_GUI_BUTTON_DISABLED)
1020 Button.SetFlags (IE_GUI_BUTTON_NO_IMAGE, OP_OR)
1021 Button.SetFlags (IE_GUI_BUTTON_PICTURE, OP_NAND)
1022 Label.SetText ("")
1024 if i+RightTopIndex<RightCount:
1025 Slot = GemRB.GetSlotItem (pc, inventory_slots[i+RightTopIndex])
1026 else:
1027 Slot = None
1028 Button = Window.GetControl (i+11)
1029 Label = Window.GetControl (0x10000019+i)
1030 Button.SetVarAssoc ("RightIndex", RightTopIndex+i)
1031 if Slot != None:
1032 Flags = GemRB.IsValidStoreItem (pc, inventory_slots[i+RightTopIndex], ITEM_PC)
1033 Item = GemRB.GetItem (Slot['ItemResRef'])
1034 Button.SetItemIcon (Slot['ItemResRef'], 0)
1035 Button.SetFlags (IE_GUI_BUTTON_NO_IMAGE, OP_NAND)
1036 Button.SetFlags (IE_GUI_BUTTON_PICTURE, OP_OR)
1037 Price = Item['Price'] * Store['BuyMarkup'] / 100
1038 Button.SetState (IE_GUI_BUTTON_ENABLED)
1039 if Flags & SHOP_ID:
1040 GemRB.SetToken ("ITEMNAME", GemRB.GetString (Item['ItemName']))
1041 Button.EnableBorder (0, 1)
1042 else:
1043 GemRB.SetToken ("ITEMNAME", GemRB.GetString (Item['ItemNameIdentified']))
1044 Button.EnableBorder (0, 0)
1046 GemRB.SetToken ("ITEMCOST", str(Price) )
1047 Label.SetText (10162)
1048 else:
1049 Button.SetState (IE_GUI_BUTTON_DISABLED)
1050 Button.SetFlags (IE_GUI_BUTTON_NO_IMAGE, OP_OR)
1051 Button.SetFlags (IE_GUI_BUTTON_PICTURE, OP_NAND)
1052 Label.SetText ("")
1053 if LeftIndex>=0:
1054 LeftButton.SetState (IE_GUI_BUTTON_ENABLED)
1055 else:
1056 LeftButton.SetState (IE_GUI_BUTTON_DISABLED)
1057 return
1059 def UpdateStoreDonateWindow ():
1060 Window = StoreDonateWindow
1062 UpdateStoreCommon (Window, 0x10000007, 0, 0x10000008)
1063 Field = Window.GetControl (5)
1064 donation = int("0"+Field.QueryText ())
1065 gold = GemRB.GameGetPartyGold ()
1066 if donation>gold:
1067 donation = gold
1068 Field.SetText (str(gold) )
1070 Button = Window.GetControl (3)
1071 if donation:
1072 Button.SetState (IE_GUI_BUTTON_ENABLED)
1073 else:
1074 Button.SetState (IE_GUI_BUTTON_DISABLED)
1075 return
1077 def IncrementDonation ():
1078 Window = StoreDonateWindow
1080 Field = Window.GetControl (5)
1081 donation = int("0"+Field.QueryText ())
1082 if donation<GemRB.GameGetPartyGold ():
1083 Field.SetText (str(donation+1) )
1084 else:
1085 Field.SetText (str(GemRB.GameGetPartyGold ()) )
1086 UpdateStoreDonateWindow ()
1087 return
1089 def DecrementDonation ():
1090 Window = StoreDonateWindow
1092 Field = Window.GetControl (5)
1093 donation = int("0"+Field.QueryText ())
1094 if donation>0:
1095 Field.SetText (str(donation-1) )
1096 else:
1097 Field.SetText (str(0) )
1098 UpdateStoreDonateWindow ()
1099 return
1101 def DonateGold ():
1102 Window = StoreDonateWindow
1104 TextArea = Window.GetControl (0)
1105 TextArea.SetFlags (IE_GUI_TEXTAREA_AUTOSCROLL)
1107 Button = Window.GetControl (10)
1108 Button.SetAnimation ("DONATE")
1110 Field = Window.GetControl (5)
1111 donation = int("0"+Field.QueryText ())
1112 GemRB.GameSetPartyGold (GemRB.GameGetPartyGold ()-donation)
1113 if GemRB.IncreaseReputation (donation):
1114 TextArea.Append (10468, -1)
1115 GemRB.PlaySound ("act_03")
1116 UpdateStoreDonateWindow ()
1117 return
1119 TextArea.Append (10469, -1)
1120 GemRB.PlaySound ("act_03e")
1121 UpdateStoreDonateWindow ()
1122 return
1124 def UpdateStoreHealWindow ():
1125 Window = StoreHealWindow
1127 UpdateStoreCommon (Window, 0x10000000, 0, 0x10000001)
1128 TopIndex = GemRB.GetVar ("TopIndex")
1129 Index = GemRB.GetVar ("Index")
1130 for i in range (4):
1131 Cure = GemRB.GetStoreCure (TopIndex+i)
1133 Button = Window.GetControl (i+8)
1134 Label = Window.GetControl (0x1000000c+i)
1135 Button.SetVarAssoc ("Index", TopIndex+i)
1136 if Cure != None:
1137 Spell = GemRB.GetSpell (Cure['CureResRef'])
1138 Button.SetSpellIcon (Cure['CureResRef'], 1)
1139 Button.SetFlags (IE_GUI_BUTTON_NO_IMAGE, OP_NAND)
1140 Button.SetFlags (IE_GUI_BUTTON_PICTURE, OP_OR)
1142 GemRB.SetToken ("ITEMNAME", GemRB.GetString (Spell['SpellName']))
1143 GemRB.SetToken ("ITEMCOST", str(Cure['Price']) )
1144 Label.SetText (10162)
1146 else:
1147 Button.SetState (IE_GUI_BUTTON_DISABLED)
1148 Button.SetFlags (IE_GUI_BUTTON_NO_IMAGE, OP_OR)
1149 Button.SetFlags (IE_GUI_BUTTON_PICTURE, OP_NAND)
1150 Label.SetText ("")
1151 if TopIndex+i==Index:
1152 TextArea = Window.GetControl (23)
1153 TextArea.SetText (Cure['Description'])
1154 Label = Window.GetControl (0x10000003)
1155 Label.SetText (str(Cure['Price']) )
1156 Button = Window.GetControl (5)
1157 Button.SetState (IE_GUI_BUTTON_ENABLED)
1158 return
1160 def InfoHealWindow ():
1161 global MessageWindow
1163 UpdateStoreHealWindow ()
1164 Index = GemRB.GetVar ("Index")
1165 Cure = GemRB.GetStoreCure (Index)
1166 Spell = GemRB.GetSpell (Cure['CureResRef'])
1168 MessageWindow = Window = GemRB.LoadWindow (14)
1170 Label = Window.GetControl (0x10000000)
1171 Label.SetText (Spell['SpellName'])
1173 Button = Window.GetControl (2)
1174 Button.SetSpellIcon (Cure['CureResRef'], 1)
1176 TextArea = Window.GetControl (3)
1177 TextArea.SetText (Spell['SpellDesc'])
1179 #Done
1180 Button = Window.GetControl (5)
1181 Button.SetText (11973)
1182 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "ErrorDone")
1184 Window.ShowModal (MODAL_SHADOW_GRAY)
1185 return
1187 def BuyHeal ():
1188 Index = GemRB.GetVar ("Index")
1189 Cure = GemRB.GetStoreCure (Index)
1190 gold = GemRB.GameGetPartyGold ()
1191 if gold < Cure['Price']:
1192 ErrorWindow (11048)
1193 return
1195 GemRB.GameSetPartyGold (gold-Cure['Price'])
1196 pc = GemRB.GameGetSelectedPCSingle ()
1197 GemRB.ApplySpell (pc, Cure['CureResRef'])
1198 UpdateStoreHealWindow ()
1199 return
1201 def UpdateStoreRumourWindow ():
1202 Window = StoreRumourWindow
1204 UpdateStoreCommon (Window, 0x10000011, 0, 0x10000012)
1205 TopIndex = GemRB.GetVar ("TopIndex")
1206 for i in range (5):
1207 Drink = GemRB.GetStoreDrink (TopIndex+i)
1208 Button = Window.GetControl (i)
1209 Button.SetVarAssoc ("Index", i)
1210 if Drink != None:
1211 GemRB.SetToken ("ITEMNAME", GemRB.GetString (Drink['DrinkName']))
1212 GemRB.SetToken ("ITEMCOST", str(Drink['Price']) )
1213 Button.SetText (10162)
1214 Button.SetState (IE_GUI_BUTTON_ENABLED)
1215 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "GulpDrink")
1216 else:
1217 Button.SetText ("")
1218 Button.SetState (IE_GUI_BUTTON_DISABLED)
1219 return
1221 def GulpDrink ():
1222 Window = StoreRumourWindow
1224 TextArea = Window.GetControl (13)
1225 TextArea.SetFlags (IE_GUI_TEXTAREA_AUTOSCROLL)
1226 pc = GemRB.GameGetSelectedPCSingle ()
1227 intox = GemRB.GetPlayerStat (pc, IE_INTOXICATION)
1228 intox = 0
1229 if intox > 80:
1230 TextArea.Append (10832, -1)
1231 return
1233 gold = GemRB.GameGetPartyGold ()
1234 Index = GemRB.GetVar ("TopIndex")+GemRB.GetVar ("Index")
1235 Drink = GemRB.GetStoreDrink (Index)
1236 if gold < Drink['Price']:
1237 ErrorWindow (11049)
1238 return
1240 GemRB.GameSetPartyGold (gold-Drink['Price'])
1241 GemRB.SetPlayerStat (pc, IE_INTOXICATION, intox+Drink['Strength'])
1242 text = GemRB.GetRumour (Drink['Strength'], Store['TavernRumour'])
1243 TextArea.Append (text, -1)
1244 GemRB.PlaySound ("gam_07")
1245 UpdateStoreRumourWindow ()
1246 return
1248 def UpdateStoreRentWindow ():
1249 global RentIndex
1251 Window = StoreRentWindow
1252 UpdateStoreCommon (Window, 0x10000008, 0, 0x10000009)
1253 RentIndex = GemRB.GetVar ("RentIndex")
1254 Button = Window.GetControl (11)
1255 Label = Window.GetControl (0x1000000d)
1256 if RentIndex>=0:
1257 TextArea = Window.GetControl (12)
1258 TextArea.SetText (roomtypes[RentIndex] )
1259 price = Store['StoreRoomPrices'][RentIndex]
1260 Label.SetText (str(price) )
1261 Button.SetState (IE_GUI_BUTTON_ENABLED)
1262 else:
1263 Label.SetText ("0" )
1264 Button.SetState (IE_GUI_BUTTON_DISABLED)
1265 return
1267 def RentConfirm ():
1268 RentIndex = GemRB.GetVar ("RentIndex")
1269 price = Store['StoreRoomPrices'][RentIndex]
1270 Gold = GemRB.GameGetPartyGold ()
1271 GemRB.GameSetPartyGold (Gold-price)
1272 GemRB.RestParty (13, 1, RentIndex+1)
1273 if RentConfirmWindow:
1274 RentConfirmWindow.Unload ()
1275 Window = StoreRentWindow
1276 TextArea = Window.GetControl (12)
1277 #is there any way to change this???
1278 GemRB.SetToken ("HOUR", "8")
1279 GemRB.SetToken ("HP", "%d"%(RentIndex+1))
1280 TextArea.SetText (16476)
1281 GemRB.SetVar ("RentIndex", -1)
1282 Button = Window.GetControl (RentIndex+4)
1283 Button.SetState (IE_GUI_BUTTON_ENABLED)
1284 UpdateStoreRentWindow ()
1285 return
1287 def RentDeny () :
1288 if RentConfirmWindow:
1289 RentConfirmWindow.Unload ()
1290 UpdateStoreRentWindow ()
1291 return
1293 def RentRoom ():
1294 global RentIndex, RentConfirmWindow
1296 RentIndex = GemRB.GetVar ("RentIndex")
1297 price = Store['StoreRoomPrices'][RentIndex]
1298 Gold = GemRB.GameGetPartyGold ()
1299 if Gold<price:
1300 ErrorWindow (11051)
1301 return
1303 RentConfirmWindow = Window = GemRB.LoadWindow (11)
1304 #confirm
1305 Button = Window.GetControl (0)
1306 Button.SetText (17199)
1307 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "RentConfirm")
1308 Button.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
1310 #deny
1311 Button = Window.GetControl (1)
1312 Button.SetText (13727)
1313 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "RentDeny")
1314 Button.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
1316 #textarea
1317 TextArea = Window.GetControl (3)
1318 TextArea.SetText (15358)
1320 Window.ShowModal (MODAL_SHADOW_GRAY)
1321 return
1323 def CloseStoreShoppingWindow ():
1324 global StoreShoppingWindow
1326 if StoreShoppingWindow != None:
1327 if StoreShoppingWindow:
1328 StoreShoppingWindow.Unload ()
1329 StoreShoppingWindow = None
1330 return
1332 def CloseStoreIdentifyWindow ():
1333 global StoreIdentifyWindow
1335 if StoreIdentifyWindow != None:
1336 if StoreIdentifyWindow:
1337 StoreIdentifyWindow.Unload ()
1338 StoreIdentifyWindow = None
1339 return
1341 def CloseStoreStealWindow ():
1342 global StoreStealWindow
1344 if StoreStealWindow != None:
1345 if StoreStealWindow:
1346 StoreStealWindow.Unload ()
1347 StoreStealWindow = None
1348 return
1350 def CloseStoreDonateWindow ():
1351 global StoreDonateWindow
1353 if StoreDonateWindow != None:
1354 if StoreDonateWindow:
1355 StoreDonateWindow.Unload ()
1356 StoreDonateWindow = None
1357 return
1359 def CloseStoreHealWindow ():
1360 global StoreHealWindow
1362 if StoreHealWindow != None:
1363 if StoreHealWindow:
1364 StoreHealWindow.Unload ()
1365 StoreHealWindow = None
1366 return
1368 def CloseStoreRumourWindow ():
1369 global StoreRumourWindow
1371 if StoreRumourWindow != None:
1372 if StoreRumourWindow:
1373 StoreRumourWindow.Unload ()
1374 StoreRumourWindow = None
1375 return
1377 def CloseStoreRentWindow ():
1378 global StoreRentWindow
1380 if StoreRentWindow != None:
1381 if StoreRentWindow:
1382 StoreRentWindow.Unload ()
1383 StoreRentWindow = None
1384 return
1386 def ErrorWindow (strref):
1387 global MessageWindow
1389 MessageWindow = Window = GemRB.LoadWindow (10)
1391 TextArea = Window.GetControl (3)
1392 TextArea.SetText (strref)
1394 #done
1395 Button = Window.GetControl (0)
1396 Button.SetText (11973)
1397 Button.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "ErrorDone")
1399 Window.ShowModal (MODAL_SHADOW_GRAY)
1400 return
1402 def ErrorDone ():
1403 if MessageWindow:
1404 MessageWindow.Unload ()
1405 return
1407 ###################################################
1408 # End of file GUISTORE.py