iwd: more gcw syncing with bg2 - actonpc and dragging
[gemrb.git] / gemrb / GUIScripts / pst / GUIINV.py
blobeb44e089f0e382bd6bc527016ef00f104c1ac726
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 # GUIINV.py - scripts to control inventory windows from GUIINV winpack
23 ###################################################
25 from GUIDefines import *
26 from ie_stats import *
27 from ie_slots import *
28 import GemRB
29 import GUICommon
30 import GUICommonWindows
33 InventoryWindow = None
34 ItemInfoWindow = None
35 ItemAmountWindow = None
36 ItemIdentifyWindow = None
37 OverSlot = None
39 ItemHash = {}
41 # Control ID's:
42 # 0 - 9 eye, rings, earrings, tattoos, etc
43 # 10-13 Quick Weapon
44 # 14-18 Quick Item
45 # 19-23 Quiver
46 # 24-43 Personal Item
47 # 47-56 Ground Item
49 # 44 - portrait
50 # 45 - ground scrollbar?
51 # 46 - encumbrance
52 # 0x10000000 + 57 - name
53 # 0x10000000 + 58 - AC
54 # 0x10000000 + 59 - hp
55 # 0x10000000 + 60 - hp max
56 # 0x10000000 + 61 - msg
57 # 0x10000000 + 62 - party gold
58 # 0x10000000 + 63 - class
61 def OpenInventoryWindow ():
62 global AvSlotsTable
63 global InventoryWindow
65 AvSlotsTable = GemRB.LoadTable ('avslots')
67 if GUICommon.CloseOtherWindow (OpenInventoryWindow):
68 GemRB.HideGUI ()
69 if InventoryWindow:
70 InventoryWindow.Unload ()
71 InventoryWindow = None
72 GemRB.SetVar ("OtherWindow", -1)
73 GemRB.SetVar ("MessageLabel", -1)
74 GUICommonWindows.SetSelectionChangeHandler (None)
75 GemRB.UnhideGUI ()
76 return
78 GemRB.HideGUI ()
79 GemRB.LoadWindowPack ("GUIINV")
80 InventoryWindow = Window = GemRB.LoadWindow (3)
81 GemRB.SetVar ("OtherWindow", InventoryWindow.ID)
82 GemRB.SetVar ("MessageLabel", Window.GetControl(0x1000003d).ID)
84 # inventory slots
85 for i in range (44):
86 Button = Window.GetControl (i)
87 Button.SetFlags (IE_GUI_BUTTON_ALIGN_RIGHT , OP_OR)
88 Button.SetFont ("NUMBER2")
89 Button.SetVarAssoc ("ItemButton", i)
90 Button.SetBorder (0,0,0,0,0,128,128,255,64,0,1)
91 Button.SetBorder (1,0,0,0,0,255,128,128,64,0,1)
92 Button.SetEvent (IE_GUI_MOUSE_ENTER_BUTTON, MouseEnterSlot)
93 Button.SetEvent (IE_GUI_MOUSE_LEAVE_BUTTON, MouseLeaveSlot)
95 # Ground Item
96 for i in range (10):
97 Button = Window.GetControl (i+47)
98 Button.SetVarAssoc ("GroundItemButton", i)
99 Button.SetFlags (IE_GUI_BUTTON_ALIGN_RIGHT , OP_OR)
100 Button.SetFont ("NUMBER2")
101 Button.SetBorder (0,0,0,0,0,128,128,255,64,0,1)
102 Button.SetBorder (1,0,0,0,0,255,128,128,64,0,1)
103 Button.SetEvent (IE_GUI_MOUSE_ENTER_BUTTON, MouseEnterGround)
104 Button.SetEvent (IE_GUI_MOUSE_LEAVE_BUTTON, MouseLeaveGround)
106 ScrollBar = Window.GetControl (45)
107 ScrollBar.SetEvent (IE_GUI_SCROLLBAR_ON_CHANGE, RefreshInventoryWindow)
109 for i in range (57, 64):
110 Label = Window.GetControl (0x10000000 + i)
111 Label.SetText (str (i))
113 # portrait
114 Button = Window.GetControl (44)
115 Button.SetState (IE_GUI_BUTTON_LOCKED)
116 Button.SetFlags(IE_GUI_BUTTON_NO_IMAGE | IE_GUI_BUTTON_PICTURE, OP_SET)
117 Button.SetEvent (IE_GUI_BUTTON_ON_DRAG_DROP, OnAutoEquip)
119 # encumbrance
120 Button = Window.GetControl (46)
121 Button.SetFont ("NUMBER")
122 Button.SetState (IE_GUI_BUTTON_LOCKED)
123 Button.SetFlags (IE_GUI_BUTTON_NO_IMAGE, OP_SET)
125 # armor class
126 Label = Window.GetControl (0x1000003a)
127 Label.SetTooltip (4197)
129 # hp current
130 Label = Window.GetControl (0x1000003b)
131 Label.SetTooltip (4198)
133 # hp max
134 Label = Window.GetControl (0x1000003c)
135 Label.SetTooltip (4199)
137 # info label, game paused, etc
138 Label = Window.GetControl (0x1000003d)
139 Label.SetTextColor(255, 255, 255)
140 Label.SetText ("")
141 GemRB.SetVar ("TopIndex", 0)
142 GUICommonWindows.SetSelectionChangeHandler (UpdateInventoryWindow)
143 UpdateInventoryWindow ()
145 GemRB.UnhideGUI()
148 def UpdateInventoryWindow ():
149 global ItemHash
150 global slot_list
152 Window = InventoryWindow
154 GUICommonWindows.UpdateAnimation ()
156 pc = GemRB.GameGetSelectedPCSingle ()
158 Container = GemRB.GetContainer (pc, 1)
159 ScrollBar = Window.GetControl (45)
160 Count = Container['ItemCount']
161 if Count<1:
162 Count=1
163 ScrollBar.SetVarAssoc ("TopIndex", Count)
164 RefreshInventoryWindow ()
165 # And now for the items ....
167 ItemHash = {}
169 # get a list which maps slot number to slot type/icon/tooltip
170 row = GemRB.GetPlayerStat (pc, IE_SPECIFIC)
171 slot_list = map (int, AvSlotsTable.GetValue (row, 1, 0).split( ','))
173 # populate inventory slot controls
174 for i in range (46):
175 UpdateSlot (pc, i)
177 def RefreshInventoryWindow ():
178 Window = InventoryWindow
179 pc = GemRB.GameGetSelectedPCSingle ()
181 # name
182 Label = Window.GetControl (0x10000039)
183 Label.SetText (GemRB.GetPlayerName (pc, 1))
186 # portrait
187 Button = Window.GetControl (44)
188 Button.SetPicture (GUICommonWindows.GetActorPortrait (pc, 'INVENTORY'))
190 GUICommon.SetEncumbranceLabels (Window, 46, None, pc)
192 # armor class
193 ac = GemRB.GetPlayerStat (pc, IE_ARMORCLASS)
194 ac += GemRB.GetAbilityBonus (IE_DEX, 2, GemRB.GetPlayerStat (pc, IE_DEX) )
195 Label = Window.GetControl (0x1000003a)
196 Label.SetText (str (ac))
198 # hp current
199 hp = GemRB.GetPlayerStat (pc, IE_HITPOINTS)
200 Label = Window.GetControl (0x1000003b)
201 Label.SetText (str (hp))
203 # hp max
204 hpmax = GemRB.GetPlayerStat (pc, IE_MAXHITPOINTS)
205 Label = Window.GetControl (0x1000003c)
206 Label.SetText (str (hpmax))
208 # party gold
209 Label = Window.GetControl (0x1000003e)
210 Label.SetText (str (GemRB.GameGetPartyGold ()))
212 # class
213 text = GUICommon.ClassTable.GetValue (GemRB.GetPlayerStat (pc, IE_CLASS) - 1, 0)
215 Label = Window.GetControl (0x1000003f)
216 Label.SetText (text)
218 # update ground inventory slots
219 Container = GemRB.GetContainer(pc, 1)
220 TopIndex = GemRB.GetVar ("TopIndex")
221 for i in range (10):
222 Button = Window.GetControl (i+47)
223 if GemRB.IsDraggingItem ():
224 Button.SetState (IE_GUI_BUTTON_SECOND)
225 else:
226 Button.SetState (IE_GUI_BUTTON_ENABLED)
227 Button.SetEvent (IE_GUI_BUTTON_ON_DRAG_DROP, OnDragItemGround)
228 Slot = GemRB.GetContainerItem (pc, i+TopIndex)
229 if Slot != None:
230 item = GemRB.GetItem (Slot['ItemResRef'])
231 identified = Slot["Flags"] & IE_INV_ITEM_IDENTIFIED
233 Button.SetItemIcon (Slot['ItemResRef'])
234 Button.SetFlags (IE_GUI_BUTTON_PICTURE, OP_OR)
235 if not identified or item["ItemNameIdentified"] == -1:
236 Button.SetTooltip (item["ItemName"])
237 Button.EnableBorder (0, 1)
238 else:
239 Button.SetTooltip (item["ItemNameIdentified"])
240 Button.EnableBorder (0, 0)
241 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, OnDragItemGround)
242 Button.SetEvent (IE_GUI_BUTTON_ON_RIGHT_PRESS, OpenGroundItemInfoWindow)
243 Button.SetEvent (IE_GUI_BUTTON_ON_SHIFT_PRESS, None) #TODO: implement OpenGroundItemAmountWindow
245 else:
246 Button.SetFlags (IE_GUI_BUTTON_PICTURE, OP_NAND)
247 Button.SetTooltip (4273)
248 Button.EnableBorder (0, 0)
249 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, None)
250 Button.SetEvent (IE_GUI_BUTTON_ON_RIGHT_PRESS, None)
251 Button.SetEvent (IE_GUI_BUTTON_ON_SHIFT_PRESS, None)
252 return
254 def UpdateSlot (pc, i):
255 Window = InventoryWindow
257 # NOTE: there are invisible items (e.g. MORTEP) in inaccessible slots
258 # used to assign powers and protections
260 if slot_list[i]<0:
261 slot = i+1
262 SlotType = GemRB.GetSlotType (slot)
263 slot_item = 0
264 else:
265 slot = slot_list[i]+1
266 SlotType = GemRB.GetSlotType (slot)
267 slot_item = GemRB.GetSlotItem (pc, slot)
269 ControlID = SlotType["ID"]
270 if ControlID<0:
271 return
273 if GemRB.IsDraggingItem ():
274 #get dragged item
275 drag_item = GemRB.GetSlotItem (0,0)
276 itemname = drag_item["ItemResRef"]
277 drag_item = GemRB.GetItem (itemname)
278 else:
279 itemname = ""
281 Button = Window.GetControl (ControlID)
282 ItemHash[ControlID] = [slot, slot_item]
283 Button.SetSprites ('IVSLOT', 0, 0, 1, 2, 3)
284 if slot_item:
285 item = GemRB.GetItem (slot_item['ItemResRef'])
286 identified = slot_item['Flags'] & IE_INV_ITEM_IDENTIFIED
288 Button.SetItemIcon (slot_item['ItemResRef'])
289 if item['StackAmount'] > 1:
290 Button.SetText (str (slot_item['Usages0']))
291 else:
292 Button.SetText ('')
294 if not identified or item['ItemNameIdentified'] == -1:
295 Button.SetTooltip (item['ItemName'])
296 Button.EnableBorder (0, 1)
297 else:
298 Button.SetTooltip (item['ItemNameIdentified'])
299 Button.EnableBorder (0, 0)
301 if GemRB.CanUseItemType (SLOT_ANY, slot_item['ItemResRef'], pc):
302 Button.EnableBorder (1, 0)
303 else:
304 Button.EnableBorder (1, 1)
306 Button.SetFlags (IE_GUI_BUTTON_NO_IMAGE, OP_NAND)
307 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, OnDragItem)
308 Button.SetEvent (IE_GUI_BUTTON_ON_RIGHT_PRESS, OpenItemInfoWindow)
309 Button.SetEvent (IE_GUI_BUTTON_ON_SHIFT_PRESS, OpenItemAmountWindow)
310 Button.SetEvent (IE_GUI_BUTTON_ON_DRAG_DROP, OnDragItem)
311 else:
312 Button.SetItemIcon ('')
313 Button.SetText ('')
315 if slot_list[i]>=0:
316 Button.SetSprites (SlotType["ResRef"], 0, 0, 1, 2, 3)
317 Button.SetFlags (IE_GUI_BUTTON_NO_IMAGE, OP_NAND)
318 Button.SetEvent (IE_GUI_BUTTON_ON_DRAG_DROP, OnDragItem)
319 Button.SetTooltip (SlotType["Tip"])
320 else:
321 Button.SetFlags (IE_GUI_BUTTON_NO_IMAGE, OP_OR)
322 Button.SetEvent (IE_GUI_BUTTON_ON_DRAG_DROP, None)
323 Button.SetTooltip ('')
324 itemname = ""
326 Button.EnableBorder (0, 0)
327 Button.EnableBorder (1, 0)
328 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, None)
329 Button.SetEvent (IE_GUI_BUTTON_ON_RIGHT_PRESS, None)
330 Button.SetEvent (IE_GUI_BUTTON_ON_SHIFT_PRESS, None)
332 if OverSlot == slot-1:
333 if GemRB.CanUseItemType (SlotType["Type"], itemname):
334 Button.SetState (IE_GUI_BUTTON_SELECTED)
335 else:
336 Button.SetState (IE_GUI_BUTTON_ENABLED)
337 else:
338 if (SlotType["Type"]&SLOT_INVENTORY) or not GemRB.CanUseItemType (SlotType["Type"], itemname):
339 Button.SetState (IE_GUI_BUTTON_ENABLED)
340 else:
341 Button.SetState (IE_GUI_BUTTON_SECOND)
343 if slot_item and (GemRB.GetEquippedQuickSlot (pc)==slot or GemRB.GetEquippedAmmunition (pc)==slot):
344 Button.SetState (IE_GUI_BUTTON_THIRD)
345 return
347 def OnDragItemGround ():
348 pc = GemRB.GameGetSelectedPCSingle ()
350 slot = GemRB.GetVar ("GroundItemButton") + GemRB.GetVar ("TopIndex")
351 if not GemRB.IsDraggingItem ():
352 slot_item = GemRB.GetContainerItem (pc, slot)
353 item = GemRB.GetItem (slot_item["ItemResRef"])
354 GemRB.DragItem (pc, slot, item["ItemIcon"], 0, 1) #container
355 GemRB.PlaySound (item["DescIcon"])
356 else:
357 GemRB.DropDraggedItem (pc, -2) #dropping on ground
359 UpdateInventoryWindow ()
360 return
362 def OnAutoEquip ():
363 if not GemRB.IsDraggingItem ():
364 return
366 pc = GemRB.GameGetSelectedPCSingle ()
368 item = GemRB.GetSlotItem (0,0)
369 ret = GemRB.DropDraggedItem (pc, -1)
370 #this is exactly the same hack as the blackisle guys did it
371 #quite lame, but we should copy their efforts the best
372 if ret == 2 and item and (item['ItemResRef'] == "dustrobe"):
373 GemRB.SetGlobal("APPEARANCE","GLOBAL",2)
375 UpdateInventoryWindow ()
376 return
378 def OnDragItem ():
379 pc = GemRB.GameGetSelectedPCSingle ()
381 slot, slot_item = ItemHash[GemRB.GetVar ('ItemButton')]
383 if not GemRB.IsDraggingItem ():
384 ResRef = slot_item['ItemResRef']
385 item = GemRB.GetItem (ResRef)
386 GemRB.DragItem (pc, slot, item["ItemIcon"], 0, 0)
387 if slot == 2:
388 GemRB.SetGlobal("APPEARANCE","GLOBAL",0)
389 else:
390 item = GemRB.GetSlotItem (0,0)
391 itemdata = GemRB.GetItem(item['ItemResRef'])
392 GemRB.DropDraggedItem (pc, slot)
393 if slot == 2 and item['ItemResRef'] == 'dustrobe':
394 GemRB.SetGlobal("APPEARANCE","GLOBAL",2)
395 elif slot < 21 and itemdata['AnimationType'] != '':
396 GemRB.SetGlobal("APPEARANCE","GLOBAL",0)
398 UpdateInventoryWindow ()
401 def OnDropItemToPC ():
402 pc = GemRB.GetVar ("PressedPortrait") + 1
403 GemRB.DropDraggedItem (pc, -3)
404 UpdateInventoryWindow ()
405 return
407 def DragItemAmount ():
408 """Drag a split item."""
410 pc = GemRB.GameGetSelectedPCSingle ()
411 slot, slot_item = ItemHash[GemRB.GetVar ('ItemButton')]
412 Text = ItemAmountWindow.GetControl (6)
413 Amount = Text.QueryText ()
414 item = GemRB.GetItem (slot_item["ItemResRef"])
415 GemRB.DragItem (pc, slot, item["ItemIcon"], int ("0"+Amount), 0)
416 OpenItemAmountWindow ()
417 return
419 def OpenItemAmountWindow ():
420 global ItemAmountWindow
422 GemRB.HideGUI ()
424 if ItemAmountWindow != None:
425 if ItemAmountWindow:
426 ItemAmountWindow.Unload ()
427 ItemAmountWindow = None
428 GemRB.SetVar ("FloatWindow", -1)
430 GemRB.UnhideGUI ()
431 return
433 ItemAmountWindow = Window = GemRB.LoadWindow (4)
434 GemRB.SetVar ("FloatWindow", ItemAmountWindow.ID)
436 pc = GemRB.GameGetSelectedPCSingle ()
437 slot, slot_item = ItemHash[GemRB.GetVar ('ItemButton')]
438 ResRef = slot_item['ItemResRef']
439 item = GemRB.GetItem (ResRef)
441 # item icon
442 Icon = Window.GetControl (0)
443 Icon.SetFlags (IE_GUI_BUTTON_PICTURE | IE_GUI_BUTTON_NO_IMAGE, OP_SET)
444 Icon.SetItemIcon (ResRef)
446 # item amount
447 Text = Window.GetControl (6)
448 Text.SetSize (40, 40)
449 Text.SetText ("1")
450 Text.SetStatus (IE_GUI_EDIT_NUMBER|IE_GUI_CONTROL_FOCUSED)
452 # Done
453 Button = Window.GetControl (2)
454 Button.SetText (1403)
455 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, DragItemAmount)
456 Button.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
458 # Cancel
459 Button = Window.GetControl (1)
460 Button.SetText (4196)
461 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, OpenItemAmountWindow)
462 Button.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
464 # 0 bmp
465 # 1,2 done/cancel?
466 # 3 +
467 # 4 -
468 # 6 text
470 GemRB.UnhideGUI ()
471 Window.ShowModal (MODAL_SHADOW_GRAY)
473 def LeftItemScroll ():
474 tmp = GemRB.GetVar ('ItemButton') - 1
475 if tmp < 0:
476 tmp = 43
478 while tmp not in ItemHash or not ItemHash[tmp][1]:
479 tmp = tmp - 1
480 if tmp < 0:
481 tmp = 43
483 GemRB.SetVar ('ItemButton', tmp)
484 #one for close, one for reopen
485 CloseItemInfoWindow ()
486 OpenItemInfoWindow ()
487 return
489 def RightItemScroll ():
490 tmp = GemRB.GetVar ('ItemButton') + 1
491 if tmp > 43:
492 tmp = 0
494 while tmp not in ItemHash or not ItemHash[tmp][1]:
495 tmp = tmp + 1
496 if tmp > 43:
497 tmp = 0
499 GemRB.SetVar ('ItemButton', tmp)
500 #one for close, one for reopen
501 CloseItemInfoWindow ()
502 OpenItemInfoWindow ()
503 return
505 def DrinkItemWindow ():
506 pc = GemRB.GameGetSelectedPCSingle ()
507 slot = GemRB.GetVar ("ItemButton")
508 # the drink item header is always the first
509 GemRB.UseItem (pc, slot, 0)
510 if ItemInfoWindow:
511 ItemInfoWindow.Unload ()
512 return
514 def ReadItemWindow ():
515 pc = GemRB.GameGetSelectedPCSingle ()
516 slot = GemRB.GetVar ("ItemButton")
517 # the learn scroll header is always the second
518 GemRB.UseItem (pc, slot, 1)
519 if ItemInfoWindow:
520 ItemInfoWindow.Unload ()
521 return
523 def OpenItemWindow ():
524 #close inventory
525 GemRB.SetVar ("Inventory", 1)
526 if ItemInfoWindow:
527 ItemInfoWindow.Unload ()
528 OpenInventoryWindow ()
529 pc = GemRB.GameGetSelectedPCSingle ()
530 slot = GemRB.GetVar ("ItemButton")
531 slot_item = GemRB.GetSlotItem (pc, slot)
532 ResRef = slot_item['ItemResRef']
533 #the store will have to reopen the inventory
534 GemRB.EnterStore (ResRef)
535 return
537 def DialogItemWindow ():
539 CloseItemInfoWindow ()
540 OpenInventoryWindow ()
541 pc = GemRB.GameGetSelectedPCSingle ()
542 slot, slot_item = ItemHash[GemRB.GetVar ('ItemButton')]
543 ResRef = slot_item['ItemResRef']
544 item = GemRB.GetItem (ResRef)
545 dialog=item['Dialog']
546 GemRB.ExecuteString ("StartDialog(\""+dialog+"\",Myself)", pc)
547 return
549 def IdentifyUseSpell ():
550 global ItemIdentifyWindow
552 pc = GemRB.GameGetSelectedPCSingle ()
553 slot = GemRB.GetVar ("ItemButton")
554 if ItemIdentifyWindow:
555 ItemIdentifyWindow.Unload ()
556 GemRB.HasSpecialSpell (pc, 1, 1)
557 GemRB.ChangeItemFlag (pc, slot, IE_INV_ITEM_IDENTIFIED, OP_OR)
558 CloseIdentifyItemWindow()
559 return
561 def IdentifyUseScroll ():
562 global ItemIdentifyWindow
564 pc = GemRB.GameGetSelectedPCSingle ()
565 slot = GemRB.GetVar ("ItemButton")
566 if ItemIdentifyWindow:
567 ItemIdentifyWindow.Unload ()
568 if GemRB.HasSpecialItem (pc, 1, 1):
569 GemRB.ChangeItemFlag (pc, slot, IE_INV_ITEM_IDENTIFIED, OP_OR)
570 CloseIdentifyItemWindow()
571 return
573 def CloseIdentifyItemWindow ():
574 global ItemIdentifyWindow
576 if ItemIdentifyWindow:
577 ItemIdentifyWindow.Unload ()
578 ItemIdentifyWindow = None
579 return
581 def IdentifyItemWindow ():
582 global ItemIdentifyWindow
584 pc = GemRB.GameGetSelectedPCSingle ()
586 ItemIdentifyWindow = Window = GemRB.LoadWindow (9)
588 # how would you like to identify ....
589 Text = Window.GetControl (3)
590 Text.SetText (4258)
592 # Spell
593 Button = Window.GetControl (0)
594 Button.SetText (4259)
595 if not GemRB.HasSpecialSpell (pc, 1, 0):
596 Button.SetState (IE_GUI_BUTTON_DISABLED)
597 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, IdentifyUseSpell)
599 # Scroll
600 Button = Window.GetControl (1)
601 Button.SetText (4260)
602 if not GemRB.HasSpecialItem (pc, 1, 0):
603 Button.SetState (IE_GUI_BUTTON_DISABLED)
604 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, IdentifyUseScroll)
606 # Cancel
607 Button = Window.GetControl (2)
608 Button.SetText (4196)
609 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, CloseIdentifyItemWindow)
610 Button.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
612 Window.ShowModal (MODAL_SHADOW_GRAY)
613 return
615 def CloseItemInfoWindow ():
616 if ItemInfoWindow:
617 ItemInfoWindow.Unload ()
618 UpdateInventoryWindow()
619 return
621 def DisplayItem (itemresref, type):
622 global ItemInfoWindow
624 item = GemRB.GetItem (itemresref)
625 ItemInfoWindow = Window = GemRB.LoadWindow (5)
627 # Done
628 Button = Window.GetControl (4)
629 Button.SetText (1403)
630 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, CloseItemInfoWindow)
632 # Identify
633 Button = Window.GetControl (8)
634 if type&2:
635 Button.SetText (4256)
636 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, IdentifyItemWindow)
637 else:
638 Button.SetState (IE_GUI_BUTTON_LOCKED)
639 Button.SetFlags (IE_GUI_BUTTON_NO_IMAGE, OP_SET)
641 # Talk to Item/Use
642 Button = Window.GetControl (9)
643 drink = (type&1) and (item["Function"]&1)
644 read = (type&1) and (item["Function"]&2)
645 container = (type&1) and (item["Function"]&4)
646 dialog = (type&1) and (item["Dialog"]!="")
648 Button.SetState (IE_GUI_BUTTON_ENABLED)
649 Button.SetFlags (IE_GUI_BUTTON_NORMAL, OP_SET)
650 if drink:
651 #no drink/food in PST, this is the closest strref in stock pst
652 Button.SetText (4251)
653 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, DrinkItemWindow)
654 elif read:
655 Button.SetText (4252)
656 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, ReadItemWindow)
657 elif container:
658 #no containers in PST, this is the closest strref in stock pst
659 Button.SetText (52399)
660 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, OpenItemWindow)
661 elif dialog:
662 Button.SetText (4254)
663 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, DialogItemWindow)
664 else:
665 Button.SetText ('')
666 Button.SetState (IE_GUI_BUTTON_LOCKED)
667 Button.SetFlags (IE_GUI_BUTTON_NO_IMAGE, OP_SET)
669 Label = Window.GetControl (0x10000000)
670 if type&2:
671 Label.SetText (GemRB.GetString (item['ItemName']).upper())
672 else:
673 Label.SetText (GemRB.GetString (item['ItemNameIdentified']).upper())
675 Icon = Window.GetControl (2)
676 Icon.SetFlags (IE_GUI_BUTTON_PICTURE | IE_GUI_BUTTON_NO_IMAGE, OP_SET)
677 Icon.SetItemIcon (itemresref)
679 Text = Window.GetControl (5)
680 if type&2:
681 Text.SetText (item['ItemDesc'])
682 else:
683 Text.SetText (item['ItemDescIdentified'])
685 IdText = Window.GetControl (0x1000000b)
686 if type&2:
687 # 4279 - This item has not been identified
688 IdText.SetText (4279)
689 else:
690 IdText.SetText ('')
692 Icon = Window.GetControl (7)
693 Icon.SetFlags (IE_GUI_BUTTON_PICTURE | IE_GUI_BUTTON_NO_IMAGE, OP_SET)
694 Icon.SetItemIcon (itemresref, 1)
696 #left scroll
697 Button = Window.GetControl (13)
698 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, LeftItemScroll)
700 #right scroll
701 Button = Window.GetControl (14)
702 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, RightItemScroll)
704 Window.ShowModal (MODAL_SHADOW_GRAY)
705 return
707 def OpenItemInfoWindow ():
708 pc = GemRB.GameGetSelectedPCSingle ()
709 slot, slot_item = ItemHash[GemRB.GetVar ('ItemButton')]
710 ResRef = slot_item['ItemResRef']
711 item = GemRB.GetItem (slot_item["ItemResRef"])
713 #auto identify when lore is high enough
714 if item["LoreToID"]<=GemRB.GetPlayerStat (pc, IE_LORE):
715 GemRB.ChangeItemFlag (pc, slot, IE_INV_ITEM_IDENTIFIED, OP_OR)
716 slot_item["Flags"] |= IE_INV_ITEM_IDENTIFIED
717 UpdateInventoryWindow ()
719 if slot_item["Flags"] & IE_INV_ITEM_IDENTIFIED:
720 value = 1
721 else:
722 value = 3
723 DisplayItem (slot_item["ItemResRef"], value)
724 return
726 def OpenGroundItemInfoWindow ():
727 global ItemInfoWindow
729 pc = GemRB.GameGetSelectedPCSingle ()
730 slot = GemRB.GetVar ("TopIndex") + GemRB.GetVar ("GroundItemButton")
731 slot_item = GemRB.GetContainerItem (pc, slot)
733 #the ground items are only displayable
734 if slot_item["Flags"] & IE_INV_ITEM_IDENTIFIED:
735 value = 0
736 else:
737 value = 2
738 DisplayItem (slot_item["ItemResRef"], value)
739 return
741 def MouseEnterSlot ():
742 global OverSlot
744 pc = GemRB.GameGetSelectedPCSingle ()
745 slot = GemRB.GetVar ('ItemButton')
746 if slot not in ItemHash:
747 return
748 OverSlot = ItemHash[slot][0]-1
749 if GemRB.IsDraggingItem ():
750 for i in range(len(slot_list)):
751 if slot_list[i]==OverSlot:
752 UpdateSlot (pc, i)
753 return
755 def MouseLeaveSlot ():
756 global OverSlot
758 pc = GemRB.GameGetSelectedPCSingle ()
759 slot = GemRB.GetVar ('ItemButton')
760 if slot not in ItemHash:
761 return
762 slot = ItemHash[slot][0]-1
763 if slot == OverSlot or not GemRB.IsDraggingItem ():
764 OverSlot = None
766 for i in range(len(slot_list)):
767 if slot_list[i]==slot:
768 UpdateSlot (pc, i)
769 return
771 def MouseEnterGround ():
772 Window = InventoryWindow
773 i = GemRB.GetVar ("GroundItemButton")
774 Button = Window.GetControl (i+47)
775 if GemRB.IsDraggingItem ():
776 Button.SetState (IE_GUI_BUTTON_SELECTED)
777 return
779 def MouseLeaveGround ():
780 Window = InventoryWindow
781 i = GemRB.GetVar ("GroundItemButton")
782 Button = Window.GetControl (i+47)
783 if GemRB.IsDraggingItem ():
784 Button.SetState (IE_GUI_BUTTON_SECOND)
785 return
787 ###################################################
788 # End of file GUIINV.py