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 ###################################################
26 import GUICommonWindows
27 from GUIDefines
import *
28 from ie_stats
import *
29 from ie_slots
import *
30 from ie_spells
import *
31 from GUICommon
import CloseOtherWindow
, SetColorStat
, SetEncumbranceLabels
, CannotLearnSlotSpell
32 from GUICommon
import GameWindow
33 from GUICommonWindows
import *
35 InventoryWindow
= None
37 ItemAmountWindow
= None
39 ItemIdentifyWindow
= None
43 OldPortraitWindow
= None
44 OldOptionsWindow
= None
47 def OpenInventoryWindowClick ():
48 tmp
= GemRB
.GetVar ("PressedPortrait")+1
49 GemRB
.GameSelectPC (tmp
, True, SELECT_REPLACE
)
50 OpenInventoryWindow ()
53 def OpenInventoryWindow ():
54 global InventoryWindow
, OptionsWindow
, PortraitWindow
55 global OldPortraitWindow
, OldOptionsWindow
57 if CloseOtherWindow (OpenInventoryWindow
):
58 if GemRB
.IsDraggingItem ()==1:
59 pc
= GemRB
.GameGetSelectedPCSingle ()
60 #store the item in the inventory before window is closed
61 GemRB
.DropDraggedItem (pc
, -3)
62 #dropping on ground if cannot store in inventory
63 if GemRB
.IsDraggingItem ()==1:
64 GemRB
.DropDraggedItem (pc
, -2)
67 InventoryWindow
.Unload ()
69 OptionsWindow
.Unload ()
71 PortraitWindow
.Unload ()
73 InventoryWindow
= None
74 GemRB
.SetVar ("OtherWindow", -1)
75 GameWindow
.SetVisible(WINDOW_VISIBLE
)
77 GUICommonWindows
.PortraitWindow
= OldPortraitWindow
78 OldPortraitWindow
= None
79 GUICommonWindows
.OptionsWindow
= OldOptionsWindow
80 OldOptionsWindow
= None
81 SetSelectionChangeHandler (None)
85 GameWindow
.SetVisible(WINDOW_INVISIBLE
)
87 GemRB
.LoadWindowPack ("GUIINV", 640, 480)
88 InventoryWindow
= Window
= GemRB
.LoadWindow (2)
89 GemRB
.SetVar ("OtherWindow", InventoryWindow
.ID
)
90 GemRB
.SetVar ("MessageLabel", Window
.GetControl (0x1000003f).ID
)
91 OldOptionsWindow
= GUICommonWindows
.OptionsWindow
92 OptionsWindow
= GemRB
.LoadWindow (0)
93 SetupMenuWindowControls (OptionsWindow
, 0, "OpenInventoryWindow")
94 OptionsWindow
.SetFrame ()
95 #saving the original portrait window
96 OldPortraitWindow
= GUICommonWindows
.PortraitWindow
97 PortraitWindow
= OpenPortraitWindow (0)
99 #ground items scrollbar
100 ScrollBar
= Window
.GetControl (66)
101 ScrollBar
.SetEventByName (IE_GUI_SCROLLBAR_ON_CHANGE
, "RefreshInventoryWindow")
105 Button
= Window
.GetControl (i
+68)
106 Button
.SetEventByName (IE_GUI_MOUSE_ENTER_BUTTON
, "MouseEnterGround")
107 Button
.SetEventByName (IE_GUI_MOUSE_LEAVE_BUTTON
, "MouseLeaveGround")
108 Button
.SetVarAssoc ("GroundItemButton", i
)
109 Button
.SetSprites ("STONSLOT",0,0,1,2,3)
111 #major & minor clothing color
112 Button
= Window
.GetControl (62)
113 Button
.SetFlags (IE_GUI_BUTTON_PICTURE
,OP_OR
)
114 Button
.SetEventByName (IE_GUI_BUTTON_ON_PRESS
,"MajorPress")
115 Button
.SetTooltip (12007)
117 Button
= Window
.GetControl (63)
118 Button
.SetFlags (IE_GUI_BUTTON_PICTURE
,OP_OR
)
119 Button
.SetEventByName (IE_GUI_BUTTON_ON_PRESS
,"MinorPress")
120 Button
.SetTooltip (12008)
123 Button
= Window
.GetControl (50)
124 Button
.SetState (IE_GUI_BUTTON_LOCKED
)
125 Button
.SetFlags (IE_GUI_BUTTON_NO_IMAGE | IE_GUI_BUTTON_PICTURE
, OP_SET
)
126 Button
.SetEventByName (IE_GUI_BUTTON_ON_DRAG_DROP
, "OnAutoEquip")
129 Label
= Window
.CreateLabel (0x10000043, 5,385,60,15,"NUMBER","0:",IE_FONT_ALIGN_LEFT|IE_FONT_ALIGN_TOP
)
130 Label
= Window
.CreateLabel (0x10000044, 5,455,80,15,"NUMBER","0:",IE_FONT_ALIGN_RIGHT|IE_FONT_ALIGN_TOP
)
133 Label
= Window
.GetControl (0x10000038)
134 Label
.SetTooltip (17183)
137 Label
= Window
.GetControl (0x10000039)
138 Label
.SetTooltip (17184)
141 Label
= Window
.GetControl (0x1000003a)
142 Label
.SetTooltip (17378)
144 #info label, game paused, etc
145 Label
= Window
.GetControl (0x1000003f)
148 SlotCount
= GemRB
.GetSlotType (-1)["Count"]
149 for slot
in range (SlotCount
):
150 SlotType
= GemRB
.GetSlotType (slot
+1)
152 Button
= Window
.GetControl (SlotType
["ID"])
153 Button
.SetEventByName (IE_GUI_MOUSE_ENTER_BUTTON
, "MouseEnterSlot")
154 Button
.SetEventByName (IE_GUI_MOUSE_LEAVE_BUTTON
, "MouseLeaveSlot")
155 Button
.SetVarAssoc ("ItemButton", slot
+1)
156 Button
.SetSprites ("STONSLOT",0,0,1,2,3)
158 GemRB
.SetVar ("TopIndex", 0)
159 SetSelectionChangeHandler (UpdateInventoryWindow
)
160 UpdateInventoryWindow ()
161 OptionsWindow
.SetVisible (WINDOW_VISIBLE
)
162 Window
.SetVisible (WINDOW_FRONT
)
163 PortraitWindow
.SetVisible (WINDOW_VISIBLE
)
166 def ColorDonePress ():
167 pc
= GemRB
.GameGetSelectedPCSingle ()
170 ColorPicker
.Unload ()
171 InventoryWindow
.SetVisible (WINDOW_VISIBLE
)
172 ColorTable
= GemRB
.LoadTable ("clowncol")
173 PickedColor
=ColorTable
.GetValue (ColorIndex
, GemRB
.GetVar ("Selected"))
175 SetColorStat (pc
, IE_MAJOR_COLOR
, PickedColor
)
177 SetColorStat (pc
, IE_MINOR_COLOR
, PickedColor
)
178 UpdateInventoryWindow ()
182 global ColorIndex
, PickedColor
184 pc
= GemRB
.GameGetSelectedPCSingle ()
186 PickedColor
= GemRB
.GetPlayerStat (pc
, IE_MAJOR_COLOR
, 1) & 0xFF
191 global ColorIndex
, PickedColor
193 pc
= GemRB
.GameGetSelectedPCSingle ()
195 PickedColor
= GemRB
.GetPlayerStat (pc
, IE_MINOR_COLOR
, 1) & 0xFF
202 ColorTable
= GemRB
.LoadTable ("clowncol")
203 InventoryWindow
.SetVisible (WINDOW_GRAYED
) #darken it
204 ColorPicker
=GemRB
.LoadWindow (3)
205 GemRB
.SetVar ("Selected",-1)
207 Button
= ColorPicker
.GetControl (i
)
208 Button
.SetState (IE_GUI_BUTTON_DISABLED
)
209 Button
.SetFlags (IE_GUI_BUTTON_PICTURE|IE_GUI_BUTTON_RADIOBUTTON
,OP_OR
)
213 MyColor
= ColorTable
.GetValue (ColorIndex
, i
)
216 Button
= ColorPicker
.GetControl (i
)
217 Button
.SetBAM ("COLGRAD", 2, 0, MyColor
)
218 if PickedColor
== MyColor
:
219 GemRB
.SetVar ("Selected",i
)
221 Button
.SetState (IE_GUI_BUTTON_ENABLED
)
222 Button
.SetVarAssoc ("Selected",i
)
223 Button
.SetEventByName (IE_GUI_BUTTON_ON_PRESS
, "ColorDonePress")
224 ColorPicker
.SetVisible (WINDOW_VISIBLE
)
228 def UpdateInventoryWindow ():
229 Window
= InventoryWindow
231 pc
= GemRB
.GameGetSelectedPCSingle ()
232 Container
= GemRB
.GetContainer (pc
, 1)
233 ScrollBar
= Window
.GetControl (66)
234 Count
= Container
['ItemCount']
237 ScrollBar
.SetVarAssoc ("TopIndex", Count
)
238 RefreshInventoryWindow ()
239 #populate inventory slot controls
240 SlotCount
= GemRB
.GetSlotType (-1)["Count"]
241 for i
in range (SlotCount
):
245 #partial update without altering TopIndex
246 def RefreshInventoryWindow ():
247 Window
= InventoryWindow
249 pc
= GemRB
.GameGetSelectedPCSingle ()
252 Label
= Window
.GetControl (0x10000032)
253 Label
.SetText (GemRB
.GetPlayerName (pc
, 0))
256 Button
= Window
.GetControl (50)
257 Color1
= GemRB
.GetPlayerStat (pc
, IE_METAL_COLOR
)
258 Color2
= GemRB
.GetPlayerStat (pc
, IE_MINOR_COLOR
)
259 Color3
= GemRB
.GetPlayerStat (pc
, IE_MAJOR_COLOR
)
260 Color4
= GemRB
.GetPlayerStat (pc
, IE_SKIN_COLOR
)
261 Color5
= GemRB
.GetPlayerStat (pc
, IE_LEATHER_COLOR
)
262 Color6
= GemRB
.GetPlayerStat (pc
, IE_ARMOR_COLOR
)
263 Color7
= GemRB
.GetPlayerStat (pc
, IE_HAIR_COLOR
)
264 Button
.SetPLT (GetActorPaperDoll (pc
),
265 Color1
, Color2
, Color3
, Color4
, Color5
, Color6
, Color7
, 0, 0)
267 anim_id
= GemRB
.GetPlayerStat (pc
, IE_ANIMATION_ID
)
268 row
= "0x%04X" %anim_id
269 size
= AppearanceAvatarTable
.GetValue (row
, "SIZE")
272 slot_item
= GemRB
.GetSlotItem (pc
, GemRB
.GetEquippedQuickSlot (pc
) )
274 item
= GemRB
.GetItem (slot_item
["ItemResRef"])
275 if (item
['AnimationType'] != ''):
276 Button
.SetPLT("WP" + size
+ item
['AnimationType'] + "INV", Color1
, Color2
, Color3
, Color4
, Color5
, Color6
, Color7
, 0, 1)
279 slot_item
= GemRB
.GetSlotItem (pc
, 3)
281 itemname
= slot_item
["ItemResRef"]
282 item
= GemRB
.GetItem (itemname
)
283 if (item
['AnimationType'] != ''):
284 if (GemRB
.CanUseItemType (SLOT_WEAPON
, itemname
)):
286 Button
.SetPLT("WP" + size
+ item
['AnimationType'] + "OIN", Color1
, Color2
, Color3
, Color4
, Color5
, Color6
, Color7
, 0, 2)
289 Button
.SetPLT("WP" + size
+ item
['AnimationType'] + "INV", Color1
, Color2
, Color3
, Color4
, Color5
, Color6
, Color7
, 0, 2)
292 slot_item
= GemRB
.GetSlotItem (pc
, 1)
294 item
= GemRB
.GetItem (slot_item
["ItemResRef"])
295 if (item
['AnimationType'] != ''):
296 Button
.SetPLT("WP" + size
+ item
['AnimationType'] + "INV", Color1
, Color2
, Color3
, Color4
, Color5
, Color6
, Color7
, 0, 3)
299 SetEncumbranceLabels ( Window
, 0x10000043, 0x10000044, pc
)
302 Label
= Window
.GetControl (0x10000038)
303 ac
= GemRB
.GetPlayerStat (pc
, IE_ARMORCLASS
)
304 ac
+= GemRB
.GetAbilityBonus (IE_DEX
, 2, GemRB
.GetPlayerStat (pc
, IE_DEX
) )
305 Label
.SetText (str (ac
))
306 Label
.SetTooltip (10339)
309 hp
= GemRB
.GetPlayerStat (pc
, IE_HITPOINTS
)
310 Label
= Window
.GetControl (0x10000039)
311 Label
.SetText (str (hp
))
312 Label
.SetTooltip (17184)
315 hpmax
= GemRB
.GetPlayerStat (pc
, IE_MAXHITPOINTS
)
316 Label
= Window
.GetControl (0x1000003a)
317 Label
.SetText (str (hpmax
))
318 Label
.SetTooltip (17378)
321 Label
= Window
.GetControl (0x10000040)
322 Label
.SetText (str (GemRB
.GameGetPartyGold ()))
325 ClassTitle
= GetActorClassTitle (pc
)
326 Label
= Window
.GetControl (0x10000042)
327 Label
.SetText (ClassTitle
)
329 Button
= Window
.GetControl (62)
330 Color
= GemRB
.GetPlayerStat (pc
, IE_MAJOR_COLOR
, 1) & 0xFF
331 Button
.SetBAM ("COLGRAD", 1, 0, Color
)
333 Button
= Window
.GetControl (63)
334 Color
= GemRB
.GetPlayerStat (pc
, IE_MINOR_COLOR
, 1) & 0xFF
335 Button
.SetBAM ("COLGRAD", 1, 0, Color
)
337 #update ground inventory slots
338 Container
= GemRB
.GetContainer (pc
, 1)
339 TopIndex
= GemRB
.GetVar ("TopIndex")
341 Button
= Window
.GetControl (i
+68)
342 if GemRB
.IsDraggingItem ()==1:
343 Button
.SetState (IE_GUI_BUTTON_SECOND
)
345 Button
.SetState (IE_GUI_BUTTON_ENABLED
)
346 Button
.SetEventByName (IE_GUI_BUTTON_ON_DRAG_DROP
, "OnDragItemGround")
347 Slot
= GemRB
.GetContainerItem (pc
, i
+TopIndex
)
350 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, None)
351 Button
.SetEvent (IE_GUI_BUTTON_ON_RIGHT_PRESS
, None)
352 Button
.SetEvent (IE_GUI_BUTTON_ON_SHIFT_PRESS
, None)
354 Button
.SetEventByName (IE_GUI_BUTTON_ON_PRESS
, "OnDragItemGround")
355 Button
.SetEventByName (IE_GUI_BUTTON_ON_RIGHT_PRESS
, "OpenGroundItemInfoWindow")
356 Button
.SetEventByName (IE_GUI_BUTTON_ON_SHIFT_PRESS
, "OpenGroundItemAmountWindow")
358 UpdateInventorySlot (pc
, Button
, Slot
, "ground")
360 #making window visible/shaded depending on the pc's state
361 Window
.SetVisible (WINDOW_VISIBLE
)
364 def UpdateSlot (pc
, slot
):
365 """Updates a specific slot."""
367 Window
= InventoryWindow
368 SlotType
= GemRB
.GetSlotType (slot
+1, pc
)
369 ControlID
= SlotType
["ID"]
374 if GemRB
.IsDraggingItem ()==1:
376 drag_item
= GemRB
.GetSlotItem (0,0)
377 itemname
= drag_item
["ItemResRef"]
378 drag_item
= GemRB
.GetItem (itemname
)
382 Button
= Window
.GetControl (ControlID
)
383 slot_item
= GemRB
.GetSlotItem (pc
, slot
+1)
385 Button
.SetEventByName (IE_GUI_BUTTON_ON_DRAG_DROP
, "OnDragItem")
386 Button
.SetFlags (IE_GUI_BUTTON_NO_IMAGE
, OP_NAND
)
387 UpdateInventorySlot (pc
, Button
, slot_item
, "inventory")
390 Button
.SetEventByName (IE_GUI_BUTTON_ON_PRESS
, "OnDragItem")
391 Button
.SetEventByName (IE_GUI_BUTTON_ON_RIGHT_PRESS
, "OpenItemInfoWindow")
392 Button
.SetEventByName (IE_GUI_BUTTON_ON_SHIFT_PRESS
, "OpenItemAmountWindow")
393 Button
.SetEventByName (IE_GUI_BUTTON_ON_DOUBLE_PRESS
, "OpenItemAmountWindow")
395 if SlotType
["ResRef"]=="*":
396 Button
.SetBAM ("",0,0)
397 Button
.SetTooltip (SlotType
["Tip"])
399 elif SlotType
["ResRef"]=="":
400 Button
.SetBAM ("",0,0)
401 Button
.SetFlags (IE_GUI_BUTTON_NO_IMAGE
, OP_OR
)
402 Button
.SetTooltip ("")
405 Button
.SetBAM (SlotType
["ResRef"],0,0)
406 Button
.SetTooltip (SlotType
["Tip"])
408 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, None)
409 Button
.SetEvent (IE_GUI_BUTTON_ON_RIGHT_PRESS
, None)
410 Button
.SetEvent (IE_GUI_BUTTON_ON_SHIFT_PRESS
, None)
411 Button
.SetEvent (IE_GUI_BUTTON_ON_DOUBLE_PRESS
, None)
413 if OverSlot
== slot
+1:
414 if GemRB
.CanUseItemType (SlotType
["Type"], itemname
):
415 Button
.SetState (IE_GUI_BUTTON_SELECTED
)
417 Button
.SetState (IE_GUI_BUTTON_ENABLED
)
419 if (SlotType
["Type"]&SLOT_INVENTORY
) or not GemRB
.CanUseItemType (SlotType
["Type"], itemname
):
420 Button
.SetState (IE_GUI_BUTTON_ENABLED
)
422 Button
.SetState (IE_GUI_BUTTON_SECOND
)
424 if slot_item
and (GemRB
.GetEquippedQuickSlot (pc
)==slot
+1 or GemRB
.GetEquippedAmmunition (pc
)==slot
+1):
425 Button
.SetState (IE_GUI_BUTTON_THIRD
)
429 def OnDragItemGround ():
430 pc
= GemRB
.GameGetSelectedPCSingle ()
431 slot
= GemRB
.GetVar ("GroundItemButton") + GemRB
.GetVar ("TopIndex")
433 if GemRB
.IsDraggingItem ()==0:
434 slot_item
= GemRB
.GetContainerItem (pc
, slot
)
435 item
= GemRB
.GetItem (slot_item
["ItemResRef"])
436 GemRB
.DragItem (pc
, slot
, item
["ItemIcon"], 0, 1) #container
438 GemRB
.DropDraggedItem (pc
, -2) #dropping on ground
440 UpdateInventoryWindow ()
444 if not GemRB
.IsDraggingItem ()!=1:
447 pc
= GemRB
.GameGetSelectedPCSingle ()
449 #-1 : drop stuff in equipable slots (but not inventory)
450 GemRB
.DropDraggedItem (pc
, -1)
452 if GemRB
.IsDraggingItem ()==1:
453 GemRB
.PlaySound ("GAM_47") #failed equip
455 UpdateInventoryWindow ()
459 """Updates dragging."""
461 if GemRB
.IsDraggingItem()==2:
464 pc
= GemRB
.GameGetSelectedPCSingle ()
465 slot
= GemRB
.GetVar ("ItemButton")
467 if not GemRB
.IsDraggingItem ():
468 slot_item
= GemRB
.GetSlotItem (pc
, slot
)
469 item
= GemRB
.GetItem (slot_item
["ItemResRef"])
470 GemRB
.DragItem (pc
, slot
, item
["ItemIcon"], 0, 0)
472 SlotType
= GemRB
.GetSlotType (slot
, pc
)
473 if SlotType
["ResRef"]!="":
474 GemRB
.DropDraggedItem (pc
, slot
)
476 UpdateInventoryWindow ()
479 def OnDropItemToPC ():
480 pc
= GemRB
.GetVar ("PressedPortrait") + 1
482 #-3 : drop stuff in inventory (but not equippable slots)
483 GemRB
.DropDraggedItem (pc
, -3)
484 if GemRB
.IsDraggingItem ()==1:
485 GemRB
.DisplayString (17999,0xffffff)
486 UpdateInventoryWindow ()
489 def DecreaseStackAmount ():
490 Text
= ItemAmountWindow
.GetControl (6)
491 Amount
= Text
.QueryText ()
492 number
= int ("0"+Amount
)-1
495 Text
.SetText (str (number
))
498 def IncreaseStackAmount ():
499 Text
= ItemAmountWindow
.GetControl (6)
500 Amount
= Text
.QueryText ()
501 number
= int ("0"+Amount
)+1
502 if number
>StackAmount
:
504 Text
.SetText (str (number
))
507 def DragItemAmount ():
508 pc
= GemRB
.GameGetSelectedPCSingle ()
509 slot
= GemRB
.GetVar ("ItemButton")
510 slot_item
= GemRB
.GetSlotItem (pc
, slot
)
511 Text
= ItemAmountWindow
.GetControl (6)
512 Amount
= Text
.QueryText ()
513 item
= GemRB
.GetItem (slot_item
["ItemResRef"])
514 GemRB
.DragItem (pc
, slot
, item
["ItemIcon"], int ("0"+Amount
), 0)
515 OpenItemAmountWindow ()
518 def OpenItemAmountWindow ():
519 """Open the split window."""
521 global ItemAmountWindow
, StackAmount
523 if ItemAmountWindow
!= None:
525 ItemAmountWindow
.Unload ()
526 ItemAmountWindow
= None
528 GemRB
.SetRepeatClickFlags (GEM_RK_DISABLE
, OP_OR
)
531 pc
= GemRB
.GameGetSelectedPCSingle ()
532 slot
= GemRB
.GetVar ("ItemButton")
534 if GemRB
.IsDraggingItem ()==1:
535 GemRB
.DropDraggedItem(pc
, slot
)
536 # disallow splitting while holding split items (double splitting)
537 if GemRB
.IsDraggingItem () == 1:
538 UpdateSlot (pc
, slot
-1)
543 GemRB
.SetRepeatClickFlags (GEM_RK_DISABLE
, OP_NAND
)
545 slot_item
= GemRB
.GetSlotItem (pc
, slot
)
546 ResRef
= slot_item
['ItemResRef']
547 item
= GemRB
.GetItem (ResRef
)
550 StackAmount
= slot_item
["Usages0"]
554 #OpenItemAmountWindow ()
555 UpdateSlot (pc
, slot
-1)
558 ItemAmountWindow
= Window
= GemRB
.LoadWindow (4)
560 Icon
= Window
.GetControl (0)
561 Icon
.SetFlags (IE_GUI_BUTTON_PICTURE | IE_GUI_BUTTON_NO_IMAGE
, OP_SET
)
562 Icon
.SetItemIcon (ResRef
)
565 Text
= Window
.GetControl (6)
566 Text
.SetText (str (StackAmount
//2) )
567 Text
.SetStatus (IE_GUI_EDIT_NUMBER|IE_GUI_CONTROL_FOCUSED
)
570 Button
= Window
.GetControl (4)
571 Button
.SetEventByName (IE_GUI_BUTTON_ON_PRESS
,"DecreaseStackAmount")
574 Button
= Window
.GetControl (3)
575 Button
.SetEventByName (IE_GUI_BUTTON_ON_PRESS
,"IncreaseStackAmount")
578 Button
= Window
.GetControl (2)
579 Button
.SetText (11973)
580 Button
.SetEventByName (IE_GUI_BUTTON_ON_PRESS
, "DragItemAmount")
581 Button
.SetFlags (IE_GUI_BUTTON_DEFAULT
, OP_OR
)
584 Button
= Window
.GetControl (1)
585 Button
.SetText (13727)
586 Button
.SetEventByName (IE_GUI_BUTTON_ON_PRESS
, "OpenItemAmountWindow")
587 Button
.SetFlags (IE_GUI_BUTTON_CANCEL
, OP_OR
)
595 Window
.ShowModal (MODAL_SHADOW_GRAY
)
598 def DrinkItemWindow ():
599 pc
= GemRB
.GameGetSelectedPCSingle ()
600 slot
= GemRB
.GetVar ("ItemButton")
601 # the drink item header is always the first
602 GemRB
.UseItem (pc
, slot
, 0)
603 CloseItemInfoWindow ()
606 def OpenErrorWindow (strref
):
607 """Opens the error window and displays the string."""
610 pc
= GemRB
.GameGetSelectedPCSingle ()
612 ErrorWindow
= Window
= GemRB
.LoadWindow (7)
613 Button
= Window
.GetControl (0)
614 Button
.SetText (11973)
615 Button
.SetEventByName (IE_GUI_BUTTON_ON_PRESS
, "CloseErrorWindow")
616 Button
.SetFlags (IE_GUI_BUTTON_DEFAULT
, OP_OR
)
618 TextArea
= Window
.GetControl (3)
619 TextArea
.SetText (strref
)
620 Window
.ShowModal (MODAL_SHADOW_GRAY
)
623 def CloseErrorWindow ():
625 ErrorWindow
.Unload ()
626 UpdateInventoryWindow ()
629 def ReadItemWindow ():
630 """Tries to learn the mage scroll."""
632 pc
= GemRB
.GameGetSelectedPCSingle ()
633 slot
= GemRB
.GetVar ("ItemButton")
636 slot_item
= GemRB
.GetSlotItem (pc
, slot
)
637 spell_ref
= GemRB
.GetItem (slot_item
['ItemResRef'], pc
)['Spell']
638 spell
= GemRB
.GetSpell (spell_ref
)
640 # can we learn more spells of this level?
641 spell_count
= GemRB
.GetKnownSpellsCount (pc
, IE_SPELL_TYPE_WIZARD
, spell
['SpellLevel']-1)
642 if spell_count
> GemRB
.GetAbilityBonus (IE_INT
, 2, GemRB
.GetPlayerStat (pc
, IE_INT
)):
646 if GemRB
.LearnSpell (pc
, spell_ref
, LS_STATS|LS_ADDXP
):
648 strref
= 10831 # failure
650 strref
= 10830 # success
651 GemRB
.RemoveItem (pc
, slot
)
653 print "WARNING: invalid spell header in item", slot_item
['ItemResRef']
654 CloseItemInfoWindow ()
657 CloseItemInfoWindow ()
658 OpenErrorWindow (strref
)
662 def OpenItemWindow ():
664 GemRB
.SetVar ("Inventory", 1)
666 ItemInfoWindow
.Unload ()
667 OpenInventoryWindow ()
668 pc
= GemRB
.GameGetSelectedPCSingle ()
669 slot
= GemRB
.GetVar ("ItemButton")
670 slot_item
= GemRB
.GetSlotItem (pc
, slot
)
671 ResRef
= slot_item
['ItemResRef']
672 #the store will have to reopen the inventory
673 GemRB
.EnterStore (ResRef
)
676 def DialogItemWindow ():
678 ItemInfoWindow
.Unload ()
679 OpenInventoryWindow ()
680 pc
= GemRB
.GameGetSelectedPCSingle ()
681 slot
= GemRB
.GetVar ("ItemButton")
682 slot_item
= GemRB
.GetSlotItem (pc
, slot
)
683 ResRef
= slot_item
['ItemResRef']
684 item
= GemRB
.GetItem (ResRef
)
685 dialog
=item
["Dialog"]
686 GemRB
.ExecuteString ("StartDialog(\""+dialog
+"\",Myself)", pc
)
689 def IdentifyUseSpell ():
690 global ItemIdentifyWindow
692 pc
= GemRB
.GameGetSelectedPCSingle ()
693 slot
= GemRB
.GetVar ("ItemButton")
694 if ItemIdentifyWindow
:
695 ItemIdentifyWindow
.Unload ()
696 GemRB
.HasSpecialSpell (pc
, 1, 1)
698 ItemInfoWindow
.Unload ()
699 GemRB
.ChangeItemFlag (pc
, slot
, IE_INV_ITEM_IDENTIFIED
, OP_OR
)
700 OpenItemInfoWindow ()
703 def IdentifyUseScroll ():
704 global ItemIdentifyWindow
706 pc
= GemRB
.GameGetSelectedPCSingle ()
707 slot
= GemRB
.GetVar ("ItemButton")
708 if ItemIdentifyWindow
:
709 ItemIdentifyWindow
.Unload ()
711 ItemInfoWindow
.Unload ()
712 if GemRB
.HasSpecialItem (pc
, 1, 1):
713 GemRB
.ChangeItemFlag (pc
, slot
, IE_INV_ITEM_IDENTIFIED
, OP_OR
)
714 OpenItemInfoWindow ()
717 def CloseIdentifyItemWindow ():
718 if ItemIdentifyWindow
:
719 ItemIdentifyWindow
.Unload ()
722 def IdentifyItemWindow ():
723 global ItemIdentifyWindow
725 pc
= GemRB
.GameGetSelectedPCSingle ()
727 ItemIdentifyWindow
= Window
= GemRB
.LoadWindow (9)
728 Button
= Window
.GetControl (0)
729 Button
.SetText (17105)
730 Button
.SetEventByName (IE_GUI_BUTTON_ON_PRESS
, "IdentifyUseSpell")
731 if not GemRB
.HasSpecialSpell (pc
, 1, 0):
732 Button
.SetState (IE_GUI_BUTTON_DISABLED
)
734 Button
= Window
.GetControl (1)
735 Button
.SetText (17106)
736 Button
.SetEventByName (IE_GUI_BUTTON_ON_PRESS
, "IdentifyUseScroll")
737 if not GemRB
.HasSpecialItem (pc
, 1, 0):
738 Button
.SetState (IE_GUI_BUTTON_DISABLED
)
740 Button
= Window
.GetControl (2)
741 Button
.SetText (13727)
742 Button
.SetEventByName (IE_GUI_BUTTON_ON_PRESS
, "CloseIdentifyItemWindow")
743 Button
.SetFlags (IE_GUI_BUTTON_CANCEL
, OP_OR
)
745 TextArea
= Window
.GetControl (3)
746 TextArea
.SetText (19394)
747 Window
.ShowModal (MODAL_SHADOW_GRAY
)
750 def CloseItemInfoWindow ():
752 ItemInfoWindow
.Unload ()
753 UpdateInventoryWindow ()
756 def DisplayItem (itemresref
, type):
757 global ItemInfoWindow
759 item
= GemRB
.GetItem (itemresref
)
760 ItemInfoWindow
= Window
= GemRB
.LoadWindow (5)
763 Label
= Window
.GetControl (0x10000000)
767 Button
= Window
.GetControl (2)
768 Button
.SetFlags (IE_GUI_BUTTON_PICTURE
, OP_OR
)
769 Button
.SetItemIcon (itemresref
,0)
770 Button
.SetState (IE_GUI_BUTTON_LOCKED
)
773 Button
= Window
.GetControl (4)
774 Button
.SetText (11973)
775 Button
.SetEventByName (IE_GUI_BUTTON_ON_PRESS
, "CloseItemInfoWindow")
776 Button
.SetFlags (IE_GUI_BUTTON_CANCEL
, OP_OR
)
779 Text
= Window
.GetControl (5)
781 text
= item
["ItemDesc"]
783 text
= item
["ItemDescIdentified"]
787 Button
= Window
.GetControl (8)
790 Button
.SetText (14133)
791 Button
.SetEventByName (IE_GUI_BUTTON_ON_PRESS
, "IdentifyItemWindow")
793 Button
.SetState (IE_GUI_BUTTON_LOCKED
)
794 Button
.SetFlags (IE_GUI_BUTTON_NO_IMAGE
, OP_SET
)
797 #Button = Window.GetControl (7)
798 #Button.SetFlags (IE_GUI_BUTTON_PICTURE, OP_OR)
799 #Button.SetItemIcon (itemresref,2)
802 Button
= Window
.GetControl (9)
803 drink
= (type&1) and (item
["Function"]&1)
804 read
= (type&1) and (item
["Function"]&2)
805 container
= (type&1) and (item
["Function"]&4)
806 dialog
= (type&1) and (item
["Dialog"]!="")
808 Button
.SetText (19392)
809 Button
.SetEventByName (IE_GUI_BUTTON_ON_PRESS
, "DrinkItemWindow")
810 elif read
and not CannotLearnSlotSpell ():
811 Button
.SetText (17104)
812 Button
.SetEventByName (IE_GUI_BUTTON_ON_PRESS
, "ReadItemWindow")
814 Button
.SetText (24891)
815 Button
.SetEventByName (IE_GUI_BUTTON_ON_PRESS
, "OpenItemWindow")
817 Button
.SetText (item
["DialogName"])
818 Button
.SetEventByName (IE_GUI_BUTTON_ON_PRESS
, "DialogItemWindow")
820 Button
.SetState (IE_GUI_BUTTON_LOCKED
)
821 Button
.SetFlags (IE_GUI_BUTTON_NO_IMAGE
, OP_SET
)
823 Text
= Window
.GetControl (0x1000000b)
825 text
= item
["ItemName"]
827 text
= item
["ItemNameIdentified"]
830 ItemInfoWindow
.ShowModal (MODAL_SHADOW_GRAY
)
833 def OpenItemInfoWindow ():
834 pc
= GemRB
.GameGetSelectedPCSingle ()
835 slot
= GemRB
.GetVar ("ItemButton")
836 slot_item
= GemRB
.GetSlotItem (pc
, slot
)
837 item
= GemRB
.GetItem (slot_item
["ItemResRef"])
839 #auto identify when lore is high enough
840 if item
["LoreToID"]<=GemRB
.GetPlayerStat (pc
, IE_LORE
):
841 GemRB
.ChangeItemFlag (pc
, slot
, IE_INV_ITEM_IDENTIFIED
, OP_OR
)
842 slot_item
["Flags"] |
= IE_INV_ITEM_IDENTIFIED
843 UpdateInventoryWindow ()
845 if slot_item
["Flags"] & IE_INV_ITEM_IDENTIFIED
:
849 DisplayItem (slot_item
["ItemResRef"], value
)
852 def OpenGroundItemInfoWindow ():
853 global ItemInfoWindow
855 pc
= GemRB
.GameGetSelectedPCSingle ()
856 slot
= GemRB
.GetVar ("TopIndex") + GemRB
.GetVar ("GroundItemButton")
857 slot_item
= GemRB
.GetContainerItem (pc
, slot
)
859 #the ground items are only displayable
860 if slot_item
["Flags"] & IE_INV_ITEM_IDENTIFIED
:
864 DisplayItem (slot_item
["ItemResRef"], value
)
867 def MouseEnterSlot ():
870 pc
= GemRB
.GameGetSelectedPCSingle ()
871 OverSlot
= GemRB
.GetVar ("ItemButton")
872 if GemRB
.IsDraggingItem ()==1:
873 UpdateSlot (pc
, OverSlot
-1)
876 def MouseLeaveSlot ():
879 pc
= GemRB
.GameGetSelectedPCSingle ()
880 slot
= GemRB
.GetVar ("ItemButton")
881 if slot
== OverSlot
or not GemRB
.IsDraggingItem ():
883 UpdateSlot (pc
, slot
-1)
886 def MouseEnterGround ():
887 Window
= InventoryWindow
888 i
= GemRB
.GetVar ("GroundItemButton")
889 Button
= Window
.GetControl (i
+68)
890 if GemRB
.IsDraggingItem ()==1:
891 Button
.SetState (IE_GUI_BUTTON_SELECTED
)
894 def MouseLeaveGround ():
895 Window
= InventoryWindow
896 i
= GemRB
.GetVar ("GroundItemButton")
897 Button
= Window
.GetControl (i
+68)
898 if GemRB
.IsDraggingItem ()==1:
899 Button
.SetState (IE_GUI_BUTTON_SECOND
)
902 ###################################################
903 #End of file GUIINV.py