2 # GemRB - Infinity Engine Emulator
3 # Copyright (C) 2010 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.
22 from GUIDefines
import *
23 from ie_stats
import *
24 from ie_slots
import *
25 from ie_spells
import *
30 ItemAmountWindow
= None
31 ItemIdentifyWindow
= None
32 ItemAbilitiesWindow
= None
36 def OnDragItemGround ():
37 """Drops and item to the ground."""
39 pc
= GemRB
.GameGetSelectedPCSingle ()
40 slot
= GemRB
.GetVar ("GroundItemButton") + GemRB
.GetVar ("TopIndex")
42 if GemRB
.IsDraggingItem ()==0:
43 slot_item
= GemRB
.GetContainerItem (pc
, slot
)
44 item
= GemRB
.GetItem (slot_item
["ItemResRef"])
45 GemRB
.DragItem (pc
, slot
, item
["ItemIcon"], 0, 1) #container
46 if GUICommon
.GameIsPST():
47 GemRB
.PlaySound (item
["DescIcon"])
49 GemRB
.DropDraggedItem (pc
, -2) #dropping on ground
51 GUIINV
.UpdateInventoryWindow ()
55 """Auto-equips equipment if possible."""
57 if GemRB
.IsDraggingItem ()!=1:
60 pc
= GemRB
.GameGetSelectedPCSingle ()
62 #-1 : drop stuff in equipable slots (but not inventory)
63 GemRB
.DropDraggedItem (pc
, -1)
65 if GemRB
.IsDraggingItem ()==1:
66 GemRB
.PlaySound("GAM_47") #failed equip
68 GUIINV
.UpdateInventoryWindow ()
72 """Updates dragging."""
74 if GemRB
.IsDraggingItem()==2:
77 #don't call when splitting items
78 if ItemAmountWindow
!= None:
81 pc
= GemRB
.GameGetSelectedPCSingle ()
82 slot
= GemRB
.GetVar ("ItemButton")
83 slot_item
= GemRB
.GetSlotItem (pc
, slot
)
85 if not GemRB
.IsDraggingItem ():
86 item
= GemRB
.GetItem (slot_item
["ItemResRef"])
87 GemRB
.DragItem (pc
, slot
, item
["ItemIcon"], 0, 0)
89 SlotType
= GemRB
.GetSlotType (slot
, pc
)
91 if GemRB
.GetPlayerStat (pc
, IE_CLASS
)==0x14:
93 if SlotType
["Effects"]==TYPE_OFFHAND
:
95 GemRB
.DisplayString (61355, 0xffffff)
97 if SlotType
["ResRef"]!="":
99 item
= GemRB
.GetItem (slot_item
["ItemResRef"])
100 #drag items into a bag
101 if item
["Function"]&4:
103 GemRB
.DropDraggedItem (pc
, slot
)
105 GemRB
.EnterStore (slot_item
["ItemResRef"])
106 #if it is possible to add, then do it
107 if GemRB
.IsValidStoreItem (pc
, slot
, 0)&SHOP_SELL
:
108 GemRB
.ChangeStoreItem (pc
, slot
, SHOP_SELL
)
110 GemRB
.DisplayString( 9375, 0xfffffff)
114 GemRB
.DropDraggedItem (pc
, slot
)
116 GUIINV
.UpdateInventoryWindow ()
119 def OnDropItemToPC ():
120 """Gives an item to another character."""
122 pc
= GemRB
.GetVar ("PressedPortrait")
124 #-3 : drop stuff in inventory (but not equippable slots)
125 GemRB
.DropDraggedItem (pc
, -3)
126 if GemRB
.IsDraggingItem ()==1:
127 if GUICommon
.HasTOB ():
128 GemRB
.DisplayString (61794, 0xfffffff)
129 elif GUICommon
.GameIsPST ():
130 GemRB
.DisplayString (19257, 0xfffffff)
132 GemRB
.DisplayString (17999, 0xfffffff)
134 GUIINV
.UpdateInventoryWindow ()
137 def DecreaseStackAmount ():
138 """Decreases the split size."""
140 Text
= ItemAmountWindow
.GetControl (6)
141 Amount
= Text
.QueryText ()
142 number
= int ("0"+Amount
)-1
145 Text
.SetText (str (number
))
148 def IncreaseStackAmount ():
149 """Increases the split size."""
151 Text
= ItemAmountWindow
.GetControl (6)
152 Amount
= Text
.QueryText ()
153 number
= int ("0"+Amount
)+1
154 if number
>StackAmount
:
156 Text
.SetText (str (number
))
159 def DragItemAmount ():
160 """Drag a split item."""
162 pc
= GemRB
.GameGetSelectedPCSingle ()
165 if GemRB
.IsDraggingItem()==1:
166 GemRB
.DropDraggedItem (pc
, UsedSlot
)
167 UpdateSlot (pc
, UsedSlot
-1)
169 slot_item
= GemRB
.GetSlotItem (pc
, UsedSlot
)
171 #if dropping didn't help, don't die if slot_item isn't here
173 Text
= ItemAmountWindow
.GetControl (6)
174 Amount
= Text
.QueryText ()
175 item
= GemRB
.GetItem (slot_item
["ItemResRef"])
176 GemRB
.DragItem (pc
, UsedSlot
, item
["ItemIcon"], int ("0"+Amount
), 0)
177 OpenItemAmountWindow ()
180 def MouseEnterSlot ():
183 pc
= GemRB
.GameGetSelectedPCSingle ()
184 OverSlot
= GemRB
.GetVar ("ItemButton")
185 if GemRB
.IsDraggingItem ()==1:
186 UpdateSlot (pc
, OverSlot
-1)
189 def MouseLeaveSlot ():
192 pc
= GemRB
.GameGetSelectedPCSingle ()
193 slot
= GemRB
.GetVar ("ItemButton")
194 if slot
== OverSlot
or not GemRB
.IsDraggingItem ():
196 UpdateSlot (pc
, slot
-1)
199 def MouseEnterGround ():
200 Window
= GUIINV
.InventoryWindow
202 if GUICommon
.GameIsPST():
206 i
= GemRB
.GetVar ("GroundItemButton")
207 Button
= Window
.GetControl (i
+offset
)
209 if GemRB
.IsDraggingItem ()==1:
210 Button
.SetState (IE_GUI_BUTTON_SELECTED
)
213 def MouseLeaveGround ():
214 Window
= GUIINV
.InventoryWindow
216 if GUICommon
.GameIsPST():
220 i
= GemRB
.GetVar ("GroundItemButton")
221 Button
= Window
.GetControl (i
+offset
)
223 if GemRB
.IsDraggingItem ()==1:
224 Button
.SetState (IE_GUI_BUTTON_SECOND
)
227 def CloseItemInfoWindow ():
229 ItemInfoWindow
.Unload ()
230 GUIINV
.UpdateInventoryWindow ()
233 def DisplayItem (itemresref
, type):
234 global ItemInfoWindow
236 item
= GemRB
.GetItem (itemresref
)
237 ItemInfoWindow
= Window
= GemRB
.LoadWindow (5)
239 if GUICommon
.GameIsPST():
240 strrefs
= [ 1403, 4256, 4255, 4251, 4252, 4254, 4279 ]
242 strrefs
= [ 11973, 14133, 11960, 19392, 17104, item
["DialogName"], 17108 ]
245 Label
= Window
.GetControl (0x10000000)
247 text
= item
["ItemName"]
249 text
= item
["ItemNameIdentified"]
253 Button
= Window
.GetControl (2)
254 if GUICommon
.GameIsPST():
255 Button
.SetFlags (IE_GUI_BUTTON_PICTURE | IE_GUI_BUTTON_NO_IMAGE
, OP_SET
)
256 Button
.SetItemIcon (itemresref
)
258 Button
.SetFlags (IE_GUI_BUTTON_PICTURE
, OP_OR
)
259 Button
.SetItemIcon (itemresref
,0)
260 Button
.SetState (IE_GUI_BUTTON_LOCKED
)
263 Button
= Window
.GetControl (4)
264 Button
.SetText (strrefs
[0])
265 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, CloseItemInfoWindow
)
266 Button
.SetFlags (IE_GUI_BUTTON_CANCEL
, OP_OR
)
269 Text
= Window
.GetControl (5)
271 text
= item
["ItemDesc"]
273 text
= item
["ItemDescIdentified"]
277 Button
= Window
.GetControl(8)
278 select
= (type&1) and (item
["Function"]&8)
281 Button
.SetText (strrefs
[1])
282 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, IdentifyItemWindow
)
283 elif select
and not GUICommon
.GameIsPST():
284 Button
.SetText (strrefs
[2])
285 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, AbilitiesItemWindow
)
287 Button
.SetState (IE_GUI_BUTTON_LOCKED
)
288 Button
.SetFlags (IE_GUI_BUTTON_NO_IMAGE
, OP_SET
)
291 if GUICommon
.GameIsBG2() or GUICommon
.GameIsPST():
292 Button
= Window
.GetControl (7)
293 Button
.SetFlags (IE_GUI_BUTTON_PICTURE | IE_GUI_BUTTON_CENTER_PICTURES | IE_GUI_BUTTON_NO_IMAGE
, OP_OR
)
294 if GUICommon
.GameIsPST():
295 Button
.SetItemIcon (itemresref
, 1) # no DescIcon
297 Button
.SetItemIcon (itemresref
, 2)
298 Button
.SetState (IE_GUI_BUTTON_LOCKED
)
301 Button
= Window
.GetControl(9)
302 drink
= (type&1) and (item
["Function"]&1)
303 read
= (type&1) and (item
["Function"]&2)
304 #sorcerors cannot learn spells
306 pc
= GemRB
.GameGetSelectedPCSingle ()
307 if GemRB
.GetPlayerStat (pc
, IE_CLASS
) == 19:
309 container
= (type&1) and (item
["Function"]&4)
310 dialog
= (type&1) and (item
["Dialog"]!="")
311 familiar
= (type&1) and (item
["Type"] == 38)
313 Button
.SetText (strrefs
[3])
314 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, DrinkItemWindow
)
316 Button
.SetText (strrefs
[4])
317 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, ReadItemWindow
)
319 if GUICommon
.GameIsIWD2() or GUICommon
.GameIsHOW():
320 Button
.SetText (24891) # Open Container
321 elif GUICommon
.GameIsBG2():
322 Button
.SetText (44002) # open container
324 # a fallback, since the originals have nothing appropriate
325 # FIXME: where do mods add the new string? This is untranslatable
326 Button
.SetText ("Open container")
327 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, OpenItemWindow
)
329 Button
.SetText (strrefs
[5])
330 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, DialogItemWindow
)
332 Button
.SetText (4373)
333 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, ReleaseFamiliar
)
335 Button
.SetState (IE_GUI_BUTTON_LOCKED
)
336 Button
.SetFlags (IE_GUI_BUTTON_NO_IMAGE
, OP_SET
)
338 Label
= Window
.HasControl(0x1000000b)
340 Label
= Window
.GetControl (0x1000000b)
343 Label
.SetText (strrefs
[6])
347 # in pst one can cycle through all the items from the description window
348 if Window
.HasControl (14):
350 Button
= Window
.GetControl (13)
351 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, GUIINV
.LeftItemScroll
)
354 Button
= Window
.GetControl (14)
355 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, GUIINV
.RightItemScroll
)
357 ItemInfoWindow
.ShowModal(MODAL_SHADOW_GRAY
)
360 def OpenItemInfoWindow ():
361 pc
= GemRB
.GameGetSelectedPCSingle ()
362 if GUICommon
.GameIsPST():
363 slot
, slot_item
= GUIINV
.ItemHash
[GemRB
.GetVar ('ItemButton')]
365 slot
= GemRB
.GetVar ("ItemButton")
366 slot_item
= GemRB
.GetSlotItem (pc
, slot
)
367 item
= GemRB
.GetItem (slot_item
["ItemResRef"])
369 #auto identify when lore is high enough
370 if item
["LoreToID"]<=GemRB
.GetPlayerStat (pc
, IE_LORE
):
371 GemRB
.ChangeItemFlag (pc
, slot
, IE_INV_ITEM_IDENTIFIED
, OP_OR
)
372 slot_item
["Flags"] |
= IE_INV_ITEM_IDENTIFIED
373 GUIINV
.UpdateInventoryWindow ()
375 if slot_item
["Flags"] & IE_INV_ITEM_IDENTIFIED
:
379 DisplayItem (slot_item
["ItemResRef"], value
)
382 def OpenGroundItemInfoWindow ():
383 global ItemInfoWindow
385 pc
= GemRB
.GameGetSelectedPCSingle ()
386 slot
= GemRB
.GetVar("TopIndex")+GemRB
.GetVar("GroundItemButton")
387 slot_item
= GemRB
.GetContainerItem (pc
, slot
)
389 #the ground items are only displayable
390 if slot_item
["Flags"] & IE_INV_ITEM_IDENTIFIED
:
394 DisplayItem(slot_item
["ItemResRef"], value
)
397 def OpenItemAmountWindow ():
398 """Open the split window."""
400 global UsedSlot
, OverSlot
401 global ItemAmountWindow
, StackAmount
403 pc
= GemRB
.GameGetSelectedPCSingle ()
405 if ItemAmountWindow
!= None:
407 ItemAmountWindow
.Unload ()
408 ItemAmountWindow
= None
409 GemRB
.SetRepeatClickFlags (GEM_RK_DISABLE
, OP_OR
)
412 GUIINV
.UpdateInventoryWindow()
415 UsedSlot
= GemRB
.GetVar ("ItemButton")
416 if GemRB
.IsDraggingItem ()==1:
417 GemRB
.DropDraggedItem (pc
, UsedSlot
)
419 UpdateSlot (pc
, UsedSlot
-1)
420 # disallow splitting while holding split items (double splitting)
421 if GemRB
.IsDraggingItem () == 1:
424 slot_item
= GemRB
.GetSlotItem (pc
, UsedSlot
)
427 StackAmount
= slot_item
["Usages0"]
431 UpdateSlot (pc
, UsedSlot
-1)
434 ResRef
= slot_item
['ItemResRef']
435 item
= GemRB
.GetItem (ResRef
)
437 ItemAmountWindow
= Window
= GemRB
.LoadWindow (4)
440 Icon
= Window
.GetControl (0)
441 Icon
.SetFlags (IE_GUI_BUTTON_PICTURE | IE_GUI_BUTTON_NO_IMAGE
, OP_SET
)
442 Icon
.SetItemIcon (ResRef
)
445 Text
= Window
.GetControl (6)
446 # FIXME: use a proper size
447 # FIXME: fix it for all the games
448 if GUICommon
.GameIsIWD2():
449 Text
.SetSize (40, 40)
450 Text
.SetText (str (StackAmount
//2))
451 Text
.SetStatus (IE_GUI_EDIT_NUMBER|IE_GUI_CONTROL_FOCUSED
)
454 Button
= Window
.GetControl (4)
455 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, DecreaseStackAmount
)
458 Button
= Window
.GetControl (3)
459 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, IncreaseStackAmount
)
462 Button
= Window
.GetControl (2)
463 Button
.SetText (11973)
464 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, DragItemAmount
)
465 Button
.SetFlags (IE_GUI_BUTTON_DEFAULT
, OP_OR
)
468 Button
= Window
.GetControl (1)
469 Button
.SetText (13727)
470 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, OpenItemAmountWindow
)
471 Button
.SetFlags (IE_GUI_BUTTON_CANCEL
, OP_OR
)
474 GemRB
.SetRepeatClickFlags (GEM_RK_DISABLE
, OP_NAND
)
475 Window
.ShowModal (MODAL_SHADOW_GRAY
)
478 def UpdateSlot (pc
, slot
):
479 """Updates a specific slot."""
481 Window
= GUIINV
.InventoryWindow
482 SlotType
= GemRB
.GetSlotType (slot
+1, pc
)
483 ControlID
= SlotType
["ID"]
488 if GemRB
.IsDraggingItem ()==1:
490 drag_item
= GemRB
.GetSlotItem (0,0)
491 itemname
= drag_item
["ItemResRef"]
492 drag_item
= GemRB
.GetItem (itemname
)
496 Button
= Window
.GetControl (ControlID
)
497 slot_item
= GemRB
.GetSlotItem (pc
, slot
+1)
499 Button
.SetEvent (IE_GUI_BUTTON_ON_DRAG_DROP
, OnDragItem
)
500 Button
.SetFlags (IE_GUI_BUTTON_NO_IMAGE
, OP_NAND
)
501 GUICommon
.UpdateInventorySlot (pc
, Button
, slot_item
, "inventory", SlotType
["Type"]&SLOT_INVENTORY
== 0)
504 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, OnDragItem
)
505 Button
.SetEvent (IE_GUI_BUTTON_ON_RIGHT_PRESS
, OpenItemInfoWindow
)
506 Button
.SetEvent (IE_GUI_BUTTON_ON_SHIFT_PRESS
, OpenItemAmountWindow
)
508 if SlotType
["ResRef"]=="*":
509 Button
.SetBAM ("",0,0)
510 Button
.SetTooltip (SlotType
["Tip"])
512 elif SlotType
["ResRef"]=="":
513 Button
.SetBAM ("",0,0)
514 Button
.SetFlags (IE_GUI_BUTTON_NO_IMAGE
, OP_OR
)
515 Button
.SetTooltip ("")
518 Button
.SetBAM (SlotType
["ResRef"],0,0)
519 Button
.SetTooltip (SlotType
["Tip"])
521 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, None)
522 Button
.SetEvent (IE_GUI_BUTTON_ON_RIGHT_PRESS
, None)
523 Button
.SetEvent (IE_GUI_BUTTON_ON_SHIFT_PRESS
, None)
524 Button
.SetEvent (IE_GUI_BUTTON_ON_DOUBLE_PRESS
, OpenItemAmountWindow
)
526 if OverSlot
== slot
+1:
527 if GemRB
.CanUseItemType (SlotType
["Type"], itemname
):
528 Button
.SetState (IE_GUI_BUTTON_SELECTED
)
530 Button
.SetState (IE_GUI_BUTTON_ENABLED
)
532 if (SlotType
["Type"]&SLOT_INVENTORY
) or not GemRB
.CanUseItemType (SlotType
["Type"], itemname
):
533 Button
.SetState (IE_GUI_BUTTON_ENABLED
)
535 Button
.SetState (IE_GUI_BUTTON_SECOND
)
537 if slot_item
and (GemRB
.GetEquippedQuickSlot (pc
)==slot
+1 or GemRB
.GetEquippedAmmunition (pc
)==slot
+1):
538 Button
.SetState (IE_GUI_BUTTON_THIRD
)
544 ColorPicker
.Unload ()
545 GUIINV
.InventoryWindow
.SetVisible (WINDOW_VISIBLE
)
548 def ColorDonePress():
549 """Saves the selected colors."""
551 pc
= GemRB
.GameGetSelectedPCSingle ()
554 ColorPicker
.Unload ()
556 ColorTable
= GemRB
.LoadTable ("clowncol")
557 PickedColor
=ColorTable
.GetValue (ColorIndex
, GemRB
.GetVar ("Selected"))
559 GUICommon
.SetColorStat (pc
, IE_HAIR_COLOR
, PickedColor
)
561 GUICommon
.SetColorStat (pc
, IE_SKIN_COLOR
, PickedColor
)
563 GUICommon
.SetColorStat (pc
, IE_MAJOR_COLOR
, PickedColor
)
565 GUICommon
.SetColorStat (pc
, IE_MINOR_COLOR
, PickedColor
)
566 GUIINV
.UpdateInventoryWindow ()
570 global ColorIndex
, PickedColor
572 pc
= GemRB
.GameGetSelectedPCSingle ()
574 PickedColor
= GemRB
.GetPlayerStat (pc
, IE_HAIR_COLOR
, 1) & 0xFF
579 global ColorIndex
, PickedColor
581 pc
= GemRB
.GameGetSelectedPCSingle ()
583 PickedColor
= GemRB
.GetPlayerStat (pc
, IE_SKIN_COLOR
, 1) & 0xFF
588 """Selects the major color."""
589 global ColorIndex
, PickedColor
591 pc
= GemRB
.GameGetSelectedPCSingle ()
593 PickedColor
= GemRB
.GetPlayerStat (pc
, IE_MAJOR_COLOR
, 1) & 0xFF
598 """Selects the minor color."""
599 global ColorIndex
, PickedColor
601 pc
= GemRB
.GameGetSelectedPCSingle ()
603 PickedColor
= GemRB
.GetPlayerStat (pc
, IE_MINOR_COLOR
, 1) & 0xFF
608 """Opens the color selection window."""
612 ColorTable
= GemRB
.LoadTable ("clowncol")
613 GUIINV
.InventoryWindow
.SetVisible (WINDOW_GRAYED
) #darken it
614 ColorPicker
=GemRB
.LoadWindow (3)
615 GemRB
.SetVar ("Selected",-1)
616 if GUICommon
.GameIsIWD2():
617 Button
= ColorPicker
.GetControl (35)
618 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, CancelColor
)
619 Button
.SetText(13727)
622 Button
= ColorPicker
.GetControl (i
)
623 Button
.SetState (IE_GUI_BUTTON_DISABLED
)
624 Button
.SetFlags (IE_GUI_BUTTON_PICTURE|IE_GUI_BUTTON_RADIOBUTTON
,OP_OR
)
628 MyColor
= ColorTable
.GetValue (ColorIndex
, i
)
631 Button
= ColorPicker
.GetControl (i
)
632 Button
.SetBAM ("COLGRAD", 2, 0, MyColor
)
633 if PickedColor
== MyColor
:
634 GemRB
.SetVar ("Selected",i
)
636 Button
.SetState (IE_GUI_BUTTON_ENABLED
)
637 Button
.SetVarAssoc ("Selected",i
)
638 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, ColorDonePress
)
639 ColorPicker
.SetVisible (WINDOW_VISIBLE
)
642 def ReleaseFamiliar ():
643 """Simple Use Item"""
645 pc
= GemRB
.GameGetSelectedPCSingle ()
646 slot
= GemRB
.GetVar ("ItemButton")
647 # the header is always the first, target is always self
648 GemRB
.UseItem (pc
, slot
, 0, 5)
649 CloseItemInfoWindow ()
652 def DrinkItemWindow ():
653 """Drink the potion"""
655 pc
= GemRB
.GameGetSelectedPCSingle ()
656 slot
= GemRB
.GetVar ("ItemButton")
657 # the drink item header is always the first
658 GemRB
.UseItem (pc
, slot
, 0)
659 CloseItemInfoWindow ()
662 def OpenErrorWindow (strref
):
663 """Opens the error window and displays the string."""
666 pc
= GemRB
.GameGetSelectedPCSingle ()
668 ErrorWindow
= Window
= GemRB
.LoadWindow (7)
669 Button
= Window
.GetControl (0)
670 Button
.SetText (11973)
671 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, CloseErrorWindow
)
672 Button
.SetFlags (IE_GUI_BUTTON_DEFAULT
, OP_OR
)
674 TextArea
= Window
.GetControl (3)
675 TextArea
.SetText (strref
)
676 Window
.ShowModal (MODAL_SHADOW_GRAY
)
679 def CloseErrorWindow ():
681 ErrorWindow
.Unload ()
682 GUIINV
.UpdateInventoryWindow ()
685 def ReadItemWindow ():
686 global level
, spell_ref
687 """Tries to learn the mage scroll."""
689 pc
= GemRB
.GameGetSelectedPCSingle ()
690 slot
= GemRB
.GetVar ("ItemButton")
691 ret
= GUICommon
.CannotLearnSlotSpell()
695 CloseItemInfoWindow ()
696 if GUICommon
.HasTOB():
697 OpenErrorWindow (strref
)
700 slot_item
= GemRB
.GetSlotItem (pc
, slot
)
701 spell_ref
= GemRB
.GetItem (slot_item
['ItemResRef'], pc
)['Spell']
702 spell
= GemRB
.GetSpell (spell_ref
)
704 # can we learn more spells of this level?
705 level
= spell
['SpellLevel']-1
706 spell_count
= GemRB
.GetKnownSpellsCount (pc
, IE_SPELL_TYPE_WIZARD
, level
)
707 if spell_count
> GemRB
.GetAbilityBonus (IE_INT
, 2, GemRB
.GetPlayerStat (pc
, IE_INT
)):
709 if GUICommon
.GameIsBG2():
714 GemRB
.UseItem (pc
, slot
, 1, 5)
715 GemRB
.SetTimedEvent(DelayedReadItemWindow
, 1)
718 print "WARNING: invalid spell header in item", slot_item
['ItemResRef']
719 CloseItemInfoWindow ()
722 CloseItemInfoWindow ()
723 OpenErrorWindow (strref
)
727 def DelayedReadItemWindow ():
728 global level
, spell_ref
730 pc
= GemRB
.GameGetSelectedPCSingle ()
731 if GUICommon
.HasSpell (pc
, IE_SPELL_TYPE_WIZARD
, level
, spell_ref
):
736 CloseItemInfoWindow ()
737 if not GUICommon
.GameIsPST():
738 OpenErrorWindow (strref
)
741 def OpenItemWindow ():
742 """Displays information about the item."""
745 GemRB
.SetVar ("Inventory", 1)
747 ItemInfoWindow
.Unload ()
748 GUIINV
.OpenInventoryWindow ()
749 pc
= GemRB
.GameGetSelectedPCSingle ()
750 slot
= GemRB
.GetVar ("ItemButton")
751 slot_item
= GemRB
.GetSlotItem (pc
, slot
)
752 ResRef
= slot_item
['ItemResRef']
753 #the store will have to reopen the inventory
754 GemRB
.EnterStore (ResRef
)
757 def DialogItemWindow ():
758 """Converse with an item."""
761 ItemInfoWindow
.Unload ()
762 GUIINV
.OpenInventoryWindow ()
763 pc
= GemRB
.GameGetSelectedPCSingle ()
764 if GUICommon
.GameIsPST():
765 slot
, slot_item
= GUIINV
.ItemHash
[GemRB
.GetVar ('ItemButton')]
767 slot
= GemRB
.GetVar ("ItemButton")
768 slot_item
= GemRB
.GetSlotItem (pc
, slot
)
769 ResRef
= slot_item
['ItemResRef']
770 item
= GemRB
.GetItem (ResRef
)
771 dialog
=item
["Dialog"]
772 GemRB
.ExecuteString ("StartDialogOverride(\""+dialog
+"\",Myself,0,0,1)", pc
)
775 def IdentifyUseSpell ():
776 """Identifies the item with a memorized spell."""
778 global ItemIdentifyWindow
780 pc
= GemRB
.GameGetSelectedPCSingle ()
781 slot
= GemRB
.GetVar ("ItemButton")
782 if ItemIdentifyWindow
:
783 ItemIdentifyWindow
.Unload ()
784 GemRB
.HasSpecialSpell (pc
, 1, 1)
786 ItemInfoWindow
.Unload ()
787 GemRB
.ChangeItemFlag (pc
, slot
, IE_INV_ITEM_IDENTIFIED
, OP_OR
)
791 def IdentifyUseScroll ():
792 """Identifies the item with a scroll or other item."""
794 global ItemIdentifyWindow
796 pc
= GemRB
.GameGetSelectedPCSingle ()
797 slot
= GemRB
.GetVar ("ItemButton")
798 if ItemIdentifyWindow
:
799 ItemIdentifyWindow
.Unload ()
801 ItemInfoWindow
.Unload ()
802 if GemRB
.HasSpecialItem (pc
, 1, 1):
803 GemRB
.ChangeItemFlag (pc
, slot
, IE_INV_ITEM_IDENTIFIED
, OP_OR
)
807 def CloseIdentifyItemWindow ():
808 global ItemIdentifyWindow
810 if ItemIdentifyWindow
:
811 ItemIdentifyWindow
.Unload ()
812 ItemIdentifyWindow
= None
815 def IdentifyItemWindow ():
816 global ItemIdentifyWindow
818 pc
= GemRB
.GameGetSelectedPCSingle ()
820 ItemIdentifyWindow
= Window
= GemRB
.LoadWindow (9)
821 Button
= Window
.GetControl (0)
822 if GUICommon
.GameIsPST():
823 Button
.SetText (4259)
825 Button
.SetText (17105)
826 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, IdentifyUseSpell
)
827 if not GemRB
.HasSpecialSpell (pc
, 1, 0):
828 Button
.SetState (IE_GUI_BUTTON_DISABLED
)
830 Button
= Window
.GetControl (1)
831 if GUICommon
.GameIsPST():
832 Button
.SetText (4260)
834 Button
.SetText (17106)
835 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, IdentifyUseScroll
)
836 if not GemRB
.HasSpecialItem (pc
, 1, 0):
837 Button
.SetState (IE_GUI_BUTTON_DISABLED
)
839 Button
= Window
.GetControl (2)
840 if GUICommon
.GameIsPST():
841 Button
.SetText (4196)
843 Button
.SetText (13727)
844 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, CloseIdentifyItemWindow
)
845 Button
.SetFlags (IE_GUI_BUTTON_CANCEL
, OP_OR
)
847 TextArea
= Window
.GetControl (3)
848 if GUICommon
.GameIsPST():
849 TextArea
.SetText (4258)
851 TextArea
.SetText (19394)
852 Window
.ShowModal (MODAL_SHADOW_GRAY
)
855 def DoneAbilitiesItemWindow ():
856 pc
= GemRB
.GameGetSelectedPCSingle ()
857 slot
= GemRB
.GetVar ("ItemButton")
858 GemRB
.SetupQuickSlot (pc
, 0, slot
, GemRB
.GetVar ("Ability") )
859 CloseAbilitiesItemWindow ()
862 def CloseAbilitiesItemWindow ():
863 global ItemAbilitiesWindow
865 if ItemAbilitiesWindow
:
866 ItemAbilitiesWindow
.Unload ()
867 ItemAbilitiesWindow
= None
870 def AbilitiesItemWindow ():
871 global ItemAbilitiesWindow
873 ItemAbilitiesWindow
= Window
= GemRB
.LoadWindow (6)
875 pc
= GemRB
.GameGetSelectedPCSingle ()
876 slot
= GemRB
.GetVar ("ItemButton")
877 slot_item
= GemRB
.GetSlotItem (pc
, slot
)
878 item
= GemRB
.GetItem (slot_item
["ItemResRef"])
879 Tips
= item
["Tooltips"]
881 GemRB
.SetVar ("Ability", slot_item
["Header"])
883 Button
= Window
.GetControl (i
+1)
884 Button
.SetSprites ("GUIBTBUT",i
,0,1,2,0)
885 Button
.SetFlags (IE_GUI_BUTTON_RADIOBUTTON
, OP_OR
)
886 Button
.SetVarAssoc ("Ability",i
)
887 Text
= Window
.GetControl (i
+0x10000003)
889 Button
.SetItemIcon (slot_item
['ItemResRef'],i
+6)
890 Text
.SetText (Tips
[i
])
893 Button
.SetItemIcon ("",3)
895 Button
.SetState (IE_GUI_BUTTON_DISABLED
)
897 TextArea
= Window
.GetControl (8)
898 TextArea
.SetText (11322)
900 Button
= Window
.GetControl (7)
901 Button
.SetText (11973)
902 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, DoneAbilitiesItemWindow
)
903 Button
.SetFlags (IE_GUI_BUTTON_DEFAULT
, OP_OR
)
905 Button
= Window
.GetControl (10)
906 Button
.SetText (13727)
907 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, CloseAbilitiesItemWindow
)
908 Button
.SetFlags (IE_GUI_BUTTON_CANCEL
, OP_OR
)
909 Window
.ShowModal (MODAL_SHADOW_GRAY
)