def DumpUnusableItems(pc): """Dumps everything in the inventory that is now unusable.""" SlotTypes = [ SLOT_ARMOUR, SLOT_SHIELD, SLOT_HELM, SLOT_RING, SLOT_CLOAK, SLOT_BOOT, SLOT_AMULET, SLOT_GLOVE, SLOT_BELT, SLOT_ITEM, SLOT_WEAPON, SLOT_QUIVER ] for stype in SlotTypes: Slots = GemRB.GetSlots(pc, stype) if not len(Slots): # nothing there continue for slot in Slots: SlotType = GemRB.GetSlotType(slot, pc) CREItem = GemRB.GetSlotItem(pc, slot) if not GemRB.CanUseItemType(SlotType["Type"], CREItem["ItemResRef"], pc): # move it to a free inventory slot by mimicking dragging Item = GemRB.GetItem(CREItem["ItemResRef"]) GemRB.DragItem(pc, slot, Item["ItemIcon"]) if not GemRB.DropDraggedItem(pc, -3): # ASI_FAILED # inventory was probably too full, drop to ground GemRB.DropDraggedItem(pc, -2)
def UpdateInventorySlot(pc, Button, Slot, Type, Equipped=False): Button.SetFont("NUMBER") color = {'r': 128, 'g': 128, 'b': 255, 'a': 64} Button.SetBorder(0, color, 0, 1) color = {'r': 32, 'g': 32, 'b': 255, 'a': 255} Button.SetBorder(1, color, 0, 0, Button.GetInsetFrame(2)) color = {'r': 255, 'g': 128, 'b': 128, 'a': 64} Button.SetBorder(2, color, 0, 1) Button.SetText("") Button.SetFlags( IE_GUI_BUTTON_ALIGN_RIGHT | IE_GUI_BUTTON_ALIGN_BOTTOM | IE_GUI_BUTTON_PICTURE, OP_OR) if Slot == None: Button.SetFlags(IE_GUI_BUTTON_PICTURE, OP_NAND) tooltips = {"inventory": 12013, "ground": 12011, "container": ""} if GameCheck.IsGemRBDemo(): tooltips = {"inventory": 82, "ground": 83, "container": ""} Button.SetTooltip(tooltips[Type]) Button.EnableBorder(0, 0) Button.EnableBorder(1, 0) Button.EnableBorder(2, 0) else: item = GemRB.GetItem(Slot['ItemResRef']) identified = Slot["Flags"] & IE_INV_ITEM_IDENTIFIED magical = item["Enchantment"] > 0 # MaxStackAmount holds the *maximum* item count in the stack while Usages0 holds the actual if item["MaxStackAmount"] > 1: Button.SetText(str(Slot["Usages0"])) else: Button.SetText("") # auto-identify mundane items; the actual indentification will happen on transfer if not identified and item["LoreToID"] == 0: identified = True if not identified or item["ItemNameIdentified"] == -1: Button.SetTooltip(item["ItemName"]) Button.EnableBorder(0, 1) Button.EnableBorder(1, 0) else: Button.SetTooltip(item["ItemNameIdentified"]) Button.EnableBorder(0, 0) if magical and not GameCheck.IsPST(): Button.EnableBorder(1, 1) else: Button.EnableBorder(1, 0) if GemRB.CanUseItemType(SLOT_ALL, Slot['ItemResRef'], pc, Equipped): Button.EnableBorder(2, 0) else: Button.EnableBorder(2, 1) Button.SetItemIcon(Slot['ItemResRef'], 0) return
def UpdateInventorySlot(pc, Button, Slot, Type, Equipped=False): Button.SetFont("NUMBER") Button.SetBorder(0, 0, 0, 0, 0, 128, 128, 255, 64, 0, 1) Button.SetBorder(1, 2, 2, 2, 2, 32, 32, 255, 0, 0, 0) Button.SetBorder(2, 0, 0, 0, 0, 255, 128, 128, 64, 0, 1) Button.SetFlags( IE_GUI_BUTTON_ALIGN_RIGHT | IE_GUI_BUTTON_ALIGN_TOP | IE_GUI_BUTTON_PICTURE, OP_OR) Button.SetText("") if Slot == None: Button.SetFlags(IE_GUI_BUTTON_PICTURE, OP_NAND) if Type == "inventory": Button.SetTooltip(12013) # Personal Item elif Type == "ground": Button.SetTooltip(12011) # Ground Item else: Button.SetTooltip("") Button.EnableBorder(0, 0) Button.EnableBorder(1, 0) Button.EnableBorder(2, 0) else: item = GemRB.GetItem(Slot['ItemResRef']) identified = Slot["Flags"] & IE_INV_ITEM_IDENTIFIED magical = Slot["Flags"] & IE_INV_ITEM_MAGICAL # MaxStackAmount holds the *maximum* item count in the stack while Usages0 holds the actual if item["MaxStackAmount"] > 1: Button.SetText(str(Slot["Usages0"])) else: Button.SetText("") # auto-identify mundane items; the actual indentification will happen on transfer if not identified and item["LoreToID"] == 0: identified = True if not identified or item["ItemNameIdentified"] == -1: Button.SetTooltip(item["ItemName"]) Button.EnableBorder(0, 1) Button.EnableBorder(1, 0) else: Button.SetTooltip(item["ItemNameIdentified"]) Button.EnableBorder(0, 0) if magical: Button.EnableBorder(1, 1) else: Button.EnableBorder(1, 0) if GemRB.CanUseItemType(SLOT_ALL, Slot['ItemResRef'], pc, Equipped): Button.EnableBorder(2, 0) else: Button.EnableBorder(2, 1) Button.SetItemIcon(Slot['ItemResRef'], 0) return
def MouseEnterSlot(btn, slot): pc = GemRB.GameGetSelectedPCSingle() if GemRB.IsDraggingItem() == 1: drag_item = GemRB.GetSlotItem(0, 0) SlotType = UpdateSlot(pc, slot - 1) if GemRB.CanUseItemType(SlotType["Type"], drag_item["ItemResRef"]): btn.SetState(IE_GUI_BUTTON_SELECTED) else: btn.SetState(IE_GUI_BUTTON_ENABLED) return
def RefreshInventoryWindow(): """Partial redraw without resetting TopIndex.""" Window = InventoryWindow pc = GemRB.GameGetSelectedPCSingle() # name Label = Window.GetControl(0x10000032) Label.SetText(GemRB.GetPlayerName(pc, 0)) # class Label = Window.GetControl(0x10000042) Label.SetText(GUICommon.GetActorClassTitle(pc)) # portrait Button = Window.GetControl(50) Color1 = GemRB.GetPlayerStat(pc, IE_METAL_COLOR) Color2 = GemRB.GetPlayerStat(pc, IE_MINOR_COLOR) Color3 = GemRB.GetPlayerStat(pc, IE_MAJOR_COLOR) Color4 = GemRB.GetPlayerStat(pc, IE_SKIN_COLOR) Color5 = GemRB.GetPlayerStat(pc, IE_LEATHER_COLOR) Color6 = GemRB.GetPlayerStat(pc, IE_ARMOR_COLOR) Color7 = GemRB.GetPlayerStat(pc, IE_HAIR_COLOR) # disable coloring and equipment for non-humanoid dolls (shapes/morphs, mod additions) # ... which doesn't include ogres and flinds, who are also clown-colored # if one more exception needs to be added, rather externalise this to a new pdolls.2da flags column anim_id = GemRB.GetPlayerStat(pc, IE_ANIMATION_ID) if (anim_id < 0x5000 or anim_id >= 0x7000 or anim_id == 0x6404) and (anim_id != 0x8000 and anim_id != 0x9000): Color1 = -1 Button.SetPLT(GUICommon.GetActorPaperDoll(pc), Color1, Color2, Color3, Color4, Color5, Color6, Color7, 0, 0) # disable equipment for flinds and ogres and Sarevok (Recovery Mod) if anim_id == 0x8000 or anim_id == 0x9000 or anim_id == 0x6404: Color1 = -1 row = "0x%04X" % anim_id size = CommonTables.Pdolls.GetValue(row, "SIZE") # Weapon slot_item = GemRB.GetSlotItem(pc, GemRB.GetEquippedQuickSlot(pc)) if slot_item and Color1 != -1: item = GemRB.GetItem(slot_item["ItemResRef"]) if (item['AnimationType'] != ''): Button.SetPLT("WP" + size + item['AnimationType'] + "INV", Color1, Color2, Color3, Color4, Color5, Color6, Color7, 0, 1) # Shield slot_item = GemRB.GetSlotItem(pc, 3) if slot_item and Color1 != -1: itemname = slot_item["ItemResRef"] item = GemRB.GetItem(itemname) if (item['AnimationType'] != ''): if (GemRB.CanUseItemType(SLOT_WEAPON, itemname)): #off-hand weapon Button.SetPLT("WP" + size + item['AnimationType'] + "OIN", Color1, Color2, Color3, Color4, Color5, Color6, Color7, 0, 2) else: #shield Button.SetPLT("WP" + size + item['AnimationType'] + "INV", Color1, Color2, Color3, Color4, Color5, Color6, Color7, 0, 2) # Helmet slot_item = GemRB.GetSlotItem(pc, 1) if slot_item and Color1 != -1: item = GemRB.GetItem(slot_item["ItemResRef"]) if (item['AnimationType'] != ''): Button.SetPLT("WP" + size + item['AnimationType'] + "INV", Color1, Color2, Color3, Color4, Color5, Color6, Color7, 0, 3) # encumbrance GUICommon.SetEncumbranceLabels(Window, 0x10000043, 0x10000044, pc) # armor class ac = GemRB.GetPlayerStat(pc, IE_ARMORCLASS) Label = Window.GetControl(0x10000038) Label.SetText(str(ac)) Label.SetTooltip(10339) # hp current hp = GemRB.GetPlayerStat(pc, IE_HITPOINTS) Label = Window.GetControl(0x10000039) Label.SetText(str(hp)) Label.SetTooltip(17184) # hp max hpmax = GemRB.GetPlayerStat(pc, IE_MAXHITPOINTS) Label = Window.GetControl(0x1000003a) Label.SetText(str(hpmax)) Label.SetTooltip(17378) # party gold Label = Window.GetControl(0x10000040) Label.SetText(str(GemRB.GameGetPartyGold())) Button = Window.GetControl(62) Color = GemRB.GetPlayerStat(pc, IE_MAJOR_COLOR, 1) & 0xFF Button.SetBAM("COLGRAD", 0, 0, Color) Button = Window.GetControl(63) Color = GemRB.GetPlayerStat(pc, IE_MINOR_COLOR, 1) & 0xFF Button.SetBAM("COLGRAD", 0, 0, Color) # update ground inventory slots Container = GemRB.GetContainer(pc, 1) TopIndex = GemRB.GetVar("TopIndex") for i in range(5): Button = Window.GetControl(i + 68) if GemRB.IsDraggingItem() == 1: Button.SetState(IE_GUI_BUTTON_FAKEPRESSED) else: Button.SetState(IE_GUI_BUTTON_ENABLED) Button.SetEvent(IE_GUI_BUTTON_ON_DRAG_DROP, InventoryCommon.OnDragItemGround) Slot = GemRB.GetContainerItem(pc, i + TopIndex) if Slot == None: Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, None) Button.SetEvent(IE_GUI_BUTTON_ON_RIGHT_PRESS, None) Button.SetEvent(IE_GUI_BUTTON_ON_SHIFT_PRESS, None) else: Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, InventoryCommon.OnDragItemGround) Button.SetEvent(IE_GUI_BUTTON_ON_RIGHT_PRESS, InventoryCommon.OpenGroundItemInfoWindow) Button.SetEvent(IE_GUI_BUTTON_ON_SHIFT_PRESS, None) #TODO: implement OpenGroundItemAmountWindow InventoryCommon.UpdateInventorySlot(pc, Button, Slot, "ground") # making window visible/shaded depending on the pc's state GUICommon.AdjustWindowVisibility(Window, pc, False) return
def GiveEquipment(MyChar, ClassName, KitIndex): # get the kit (or use class if no kit) to load the start table if KitIndex == 0: EquipmentColName = ClassName # sorcerers are missing from the table, use the mage equipment instead if EquipmentColName == "SORCERER": EquipmentColName = "MAGE" else: EquipmentColName = CommonTables.KitList.GetValue(KitIndex, 0) EquipmentTable = GemRB.LoadTable("25stweap") # a map of slots in the table to the real slots # SLOT_BAG is invalid, so use the inventory (first occurence) # SLOT_INVENTORY: use -1 instead, that's what CreateItem expects RealSlots = [ SLOT_ARMOUR, SLOT_SHIELD, SLOT_HELM, -1, SLOT_RING, \ SLOT_RING, SLOT_CLOAK, SLOT_BOOT, SLOT_AMULET, SLOT_GLOVE, \ SLOT_BELT, SLOT_QUIVER, SLOT_QUIVER, SLOT_QUIVER, \ SLOT_ITEM, SLOT_ITEM, SLOT_ITEM, SLOT_WEAPON, SLOT_WEAPON, SLOT_WEAPON ] inventory_exclusion = 0 #loop over rows - item slots for slot in range(0, EquipmentTable.GetRowCount()): slotname = EquipmentTable.GetRowName(slot) item_resref = EquipmentTable.GetValue(slotname, EquipmentColName) # no item - go to next if item_resref == "*": continue # the table has typos for kitted bard's armor if item_resref == "LEATH14": item_resref = "LEAT14" # get empty slots of the requested type realslot = GemRB.GetSlots(MyChar, RealSlots[slot], -1) if RealSlots[slot] == SLOT_WEAPON: # exclude the shield slot, so the offhand stays empty realslot = realslot[1:] if realslot == (): # fallback to the inventory realslot = GemRB.GetSlots(MyChar, -1, -1) if realslot == (): # this shouldn't happen! print "Eeek! No free slots for", item_resref continue # if an item contains a comma, the rest of the value is the stack if "," in item_resref: item_resref = item_resref.split(",") count = int(item_resref[1]) item_resref = item_resref[0] else: count = 0 targetslot = realslot[0] SlotType = GemRB.GetSlotType(targetslot, MyChar) i = 1 item = GemRB.GetItem(item_resref) if inventory_exclusion & item['Exclusion']: # oops, too many magic items to equip, so just dump it to the inventory targetslot = GemRB.GetSlots(MyChar, -1, -1)[0] SlotType = -1 else: # if there are no free slots, CreateItem will create the item on the ground while not GemRB.CanUseItemType (SlotType["Type"], item_resref, MyChar) \ and i < len(realslot): targetslot = realslot[i] SlotType = GemRB.GetSlotType(targetslot, MyChar) i = i + 1 GemRB.CreateItem(MyChar, item_resref, targetslot, count, 0, 0) GemRB.ChangeItemFlag(MyChar, targetslot, IE_INV_ITEM_IDENTIFIED, OP_OR) inventory_exclusion |= item['Exclusion'] # grant the slayer change ability to the protagonist if MyChar == 1: GemRB.LearnSpell(MyChar, "SPIN822", LS_MEMO) return
def RefreshInventoryWindow (): """Partial redraw without resetting TopIndex.""" Window = InventoryWindow pc = GemRB.GameGetSelectedPCSingle () # name Label = Window.GetControl (0x10000032) Label.SetText (GemRB.GetPlayerName (pc, 0)) # portrait Button = Window.GetControl (50) Color1 = GemRB.GetPlayerStat (pc, IE_METAL_COLOR) Color2 = GemRB.GetPlayerStat (pc, IE_MINOR_COLOR) Color3 = GemRB.GetPlayerStat (pc, IE_MAJOR_COLOR) Color4 = GemRB.GetPlayerStat (pc, IE_SKIN_COLOR) Color5 = GemRB.GetPlayerStat (pc, IE_LEATHER_COLOR) Color6 = GemRB.GetPlayerStat (pc, IE_ARMOR_COLOR) Color7 = GemRB.GetPlayerStat (pc, IE_HAIR_COLOR) Button.SetPLT (GUICommon.GetActorPaperDoll (pc), Color1, Color2, Color3, Color4, Color5, Color6, Color7, 0, 0) anim_id = GemRB.GetPlayerStat (pc, IE_ANIMATION_ID) row = "0x%04X" %anim_id size = CommonTables.Pdolls.GetValue (row, "SIZE") # Weapon slot_item = GemRB.GetSlotItem (pc, GemRB.GetEquippedQuickSlot (pc) ) if slot_item: item = GemRB.GetItem (slot_item["ItemResRef"]) if (item['AnimationType'] != ''): Button.SetPLT ("WP" + size + item['AnimationType'] + "INV", Color1, Color2, Color3, Color4, Color5, Color6, Color7, 0, 1) # Shield slot_item = GemRB.GetSlotItem (pc, 3) if slot_item: itemname = slot_item["ItemResRef"] item = GemRB.GetItem (itemname) if (item['AnimationType'] != ''): if (GemRB.CanUseItemType (SLOT_WEAPON, itemname)): #off-hand weapon Button.SetPLT ("WP" + size + item['AnimationType'] + "OIN", Color1, Color2, Color3, Color4, Color5, Color6, Color7, 0, 2) else: #shield Button.SetPLT ("WP" + size + item['AnimationType'] + "INV", Color1, Color2, Color3, Color4, Color5, Color6, Color7, 0, 2) # Helmet slot_item = GemRB.GetSlotItem (pc, 1) if slot_item: item = GemRB.GetItem (slot_item["ItemResRef"]) if (item['AnimationType'] != ''): Button.SetPLT ("WP" + size + item['AnimationType'] + "INV", Color1, Color2, Color3, Color4, Color5, Color6, Color7, 0, 3) # encumbrance GUICommon.SetEncumbranceLabels ( Window, 0x10000043, 0x10000044, pc) # armor class ac = GemRB.GetPlayerStat (pc, IE_ARMORCLASS) Label = Window.GetControl (0x10000038) Label.SetText (str (ac)) Label.SetTooltip (10339) # hp current hp = GemRB.GetPlayerStat (pc, IE_HITPOINTS) Label = Window.GetControl (0x10000039) Label.SetText (str (hp)) Label.SetTooltip (17184) # hp max hpmax = GemRB.GetPlayerStat (pc, IE_MAXHITPOINTS) Label = Window.GetControl (0x1000003a) Label.SetText (str (hpmax)) Label.SetTooltip (17378) # party gold Label = Window.GetControl (0x10000040) Label.SetText (str (GemRB.GameGetPartyGold ())) # class ClassTitle = GUICommon.GetActorClassTitle (pc) Label = Window.GetControl (0x10000042) Label.SetText (ClassTitle) Button = Window.GetControl (62) Color = GemRB.GetPlayerStat (pc, IE_MAJOR_COLOR, 1) & 0xFF Button.SetBAM ("COLGRAD", 0, 0, Color) Button = Window.GetControl (63) Color = GemRB.GetPlayerStat (pc, IE_MINOR_COLOR, 1) & 0xFF Button.SetBAM ("COLGRAD", 0, 0, Color) # update ground inventory slots Container = GemRB.GetContainer (pc, 1) TopIndex = GemRB.GetVar ("TopIndex") for i in range (5): Button = Window.GetControl (i+68) if GemRB.IsDraggingItem ()==1: Button.SetState (IE_GUI_BUTTON_FAKEPRESSED) else: Button.SetState (IE_GUI_BUTTON_ENABLED) Button.SetEvent (IE_GUI_BUTTON_ON_DRAG_DROP, InventoryCommon.OnDragItemGround) Slot = GemRB.GetContainerItem (pc, i+TopIndex) if Slot == None: Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, None) Button.SetEvent (IE_GUI_BUTTON_ON_RIGHT_PRESS, None) Button.SetEvent (IE_GUI_BUTTON_ON_SHIFT_PRESS, None) else: Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, InventoryCommon.OnDragItemGround) Button.SetEvent (IE_GUI_BUTTON_ON_RIGHT_PRESS, InventoryCommon.OpenGroundItemInfoWindow) Button.SetEvent (IE_GUI_BUTTON_ON_SHIFT_PRESS, None) #TODO: implement OpenGroundItemAmountWindow GUICommon.UpdateInventorySlot (pc, Button, Slot, "ground") # making window visible/shaded depending on the pc's state GUICommon.AdjustWindowVisibility (Window, pc, False) return
def UpdateSlot (pc, slot): """Updates a specific slot.""" Window = GUIINV.InventoryWindow SlotType = GemRB.GetSlotType (slot+1, pc) ControlID = SlotType["ID"] if not ControlID: return if GemRB.IsDraggingItem ()==1: #get dragged item drag_item = GemRB.GetSlotItem (0,0) itemname = drag_item["ItemResRef"] drag_item = GemRB.GetItem (itemname) else: itemname = "" Button = Window.GetControl (ControlID) slot_item = GemRB.GetSlotItem (pc, slot+1) Button.SetEvent (IE_GUI_BUTTON_ON_DRAG_DROP, OnDragItem) Button.SetFlags (IE_GUI_BUTTON_NO_IMAGE, OP_NAND) # characters should auto-identify any item they recieve if slot_item: item = GemRB.GetItem (slot_item["ItemResRef"]) TryAutoIdentification(pc, item, slot+1, slot_item, GemRB.GetVar("GUIEnhancements")&GE_TRY_IDENTIFY_ON_TRANSFER) UpdateInventorySlot (pc, Button, slot_item, "inventory", SlotType["Type"]&SLOT_INVENTORY == 0) if slot_item: Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, OnDragItem) Button.SetEvent (IE_GUI_BUTTON_ON_RIGHT_PRESS, OpenItemInfoWindow) Button.SetEvent (IE_GUI_BUTTON_ON_SHIFT_PRESS, OpenItemAmountWindow) else: if SlotType["ResRef"]=="*": Button.SetBAM ("",0,0) Button.SetTooltip (SlotType["Tip"]) itemname = "" elif SlotType["ResRef"]=="": Button.SetBAM ("",0,0) Button.SetFlags (IE_GUI_BUTTON_NO_IMAGE, OP_OR) Button.SetTooltip ("") itemname = "" else: Button.SetBAM (SlotType["ResRef"],0,0) Button.SetTooltip (SlotType["Tip"]) Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, None) Button.SetEvent (IE_GUI_BUTTON_ON_RIGHT_PRESS, None) Button.SetEvent (IE_GUI_BUTTON_ON_SHIFT_PRESS, None) Button.SetEvent (IE_GUI_BUTTON_ON_DOUBLE_PRESS, OpenItemAmountWindow) if OverSlot == slot+1: if GemRB.CanUseItemType (SlotType["Type"], itemname): Button.SetState (IE_GUI_BUTTON_SELECTED) else: Button.SetState (IE_GUI_BUTTON_ENABLED) else: if (SlotType["Type"]&SLOT_INVENTORY) or not GemRB.CanUseItemType (SlotType["Type"], itemname): Button.SetState (IE_GUI_BUTTON_ENABLED) else: Button.SetState (IE_GUI_BUTTON_FAKEPRESSED) if slot_item and (GemRB.GetEquippedQuickSlot (pc)==slot+1 or GemRB.GetEquippedAmmunition (pc)==slot+1): Button.SetState (IE_GUI_BUTTON_FAKEDISABLED) return
def UpdateSlot(pc, i): Window = InventoryWindow # NOTE: there are invisible items (e.g. MORTEP) in inaccessible slots # used to assign powers and protections using_fists = 0 if slot_list[i] < 0: slot = i + 1 SlotType = GemRB.GetSlotType(slot) slot_item = 0 else: slot = slot_list[i] + 1 SlotType = GemRB.GetSlotType(slot) slot_item = GemRB.GetSlotItem(pc, slot) #PST displays the default weapon in the first slot if nothing else was equipped if slot_item is None and SlotType[ "ID"] == 10 and GemRB.GetEquippedQuickSlot(pc) == 10: slot_item = GemRB.GetSlotItem(pc, 0) using_fists = 1 ControlID = SlotType["ID"] if ControlID < 0: return if GemRB.IsDraggingItem(): #get dragged item drag_item = GemRB.GetSlotItem(0, 0) itemname = drag_item["ItemResRef"] drag_item = GemRB.GetItem(itemname) else: itemname = "" Button = Window.GetControl(ControlID) ItemHash[ControlID] = [slot, slot_item] Button.SetSprites('IVSLOT', 0, 0, 1, 2, 3) if slot_item: item = GemRB.GetItem(slot_item['ItemResRef']) identified = slot_item['Flags'] & IE_INV_ITEM_IDENTIFIED Button.SetItemIcon(slot_item['ItemResRef']) if item['MaxStackAmount'] > 1: Button.SetText(str(slot_item['Usages0'])) else: Button.SetText('') if not identified or item['ItemNameIdentified'] == -1: Button.SetTooltip(item['ItemName']) Button.EnableBorder(0, 1) else: Button.SetTooltip(item['ItemNameIdentified']) Button.EnableBorder(0, 0) if GemRB.CanUseItemType(SLOT_ANY, slot_item['ItemResRef'], pc): Button.EnableBorder(1, 0) else: Button.EnableBorder(1, 1) Button.SetFlags(IE_GUI_BUTTON_NO_IMAGE, OP_NAND) Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, OnDragItem) Button.SetEvent(IE_GUI_BUTTON_ON_RIGHT_PRESS, InventoryCommon.OpenItemInfoWindow) Button.SetEvent(IE_GUI_BUTTON_ON_SHIFT_PRESS, OpenItemAmountWindow) Button.SetEvent(IE_GUI_BUTTON_ON_DRAG_DROP, OnDragItem) #If the slot is being used to display the 'default' weapon, disable dragging. if SlotType["ID"] == 10 and using_fists: Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, None) #dropping is ok, because it will drop in the quick weapon slot and not the default weapon slot. else: Button.SetItemIcon('') Button.SetText('') if slot_list[i] >= 0: Button.SetSprites(SlotType["ResRef"], 0, 0, 1, 2, 3) Button.SetFlags(IE_GUI_BUTTON_NO_IMAGE, OP_NAND) Button.SetEvent(IE_GUI_BUTTON_ON_DRAG_DROP, OnDragItem) Button.SetTooltip(SlotType["Tip"]) else: Button.SetFlags(IE_GUI_BUTTON_NO_IMAGE, OP_OR) Button.SetEvent(IE_GUI_BUTTON_ON_DRAG_DROP, None) Button.SetTooltip('') itemname = "" Button.EnableBorder(0, 0) Button.EnableBorder(1, 0) if SlotType["Effects"] == 4: Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, DefaultWeapon) else: Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, None) Button.SetEvent(IE_GUI_BUTTON_ON_RIGHT_PRESS, None) Button.SetEvent(IE_GUI_BUTTON_ON_SHIFT_PRESS, None) if OverSlot == slot - 1: if GemRB.CanUseItemType(SlotType["Type"], itemname): Button.SetState(IE_GUI_BUTTON_SELECTED) else: Button.SetState(IE_GUI_BUTTON_ENABLED) else: if (SlotType["Type"] & SLOT_INVENTORY) or not GemRB.CanUseItemType( SlotType["Type"], itemname): Button.SetState(IE_GUI_BUTTON_ENABLED) else: Button.SetState(IE_GUI_BUTTON_FAKEPRESSED) if slot_item and (GemRB.GetEquippedQuickSlot(pc) == slot or GemRB.GetEquippedAmmunition(pc) == slot): Button.SetState(IE_GUI_BUTTON_FAKEDISABLED) return
def UpdateSlot(pc, slot): """Updates a specific slot.""" Window = GemRB.GetView("WIN_INV") using_fists = slot_item = SlotType = None if GameCheck.IsPST(): if slot >= len(SlotMap): #this prevents accidental out of range errors from the avslots list return GemRB.GetSlotType(slot + 1) elif SlotMap[slot] == -1: # This decides which icon to display in the empty slot # NOTE: there are invisible items (e.g. MORTEP) in inaccessible slots # used to assign powers and protections SlotType = GemRB.GetSlotType(slot + 1, pc) slot_item = None else: SlotType = GemRB.GetSlotType(SlotMap[slot] + 1) slot_item = GemRB.GetSlotItem(pc, SlotMap[slot] + 1) #PST displays the default weapon in the first slot if nothing else was equipped if slot_item is None and SlotType[ "ID"] == 10 and GemRB.GetEquippedQuickSlot(pc) == 10: slot_item = GemRB.GetSlotItem(pc, 0) using_fists = 1 else: SlotType = GemRB.GetSlotType(slot + 1, pc) slot_item = GemRB.GetSlotItem(pc, slot + 1) ControlID = SlotType["ID"] if ControlID == -1: return None if GemRB.IsDraggingItem() == 1: #get dragged item drag_item = GemRB.GetSlotItem(0, 0) itemname = drag_item["ItemResRef"] else: itemname = "" Button = Window.GetControl(ControlID) # It is important to check for a control - some games use CID 0 for slots with no control, others -1 if not Button: return Button.SetAction(OnDragItem, IE_ACT_DRAG_DROP_DST) Button.SetFlags(IE_GUI_BUTTON_NO_IMAGE, OP_NAND) # characters should auto-identify any item they recieve if slot_item: item = GemRB.GetItem(slot_item["ItemResRef"]) TryAutoIdentification( pc, item, slot + 1, slot_item, GemRB.GetVar("GUIEnhancements") & GE_TRY_IDENTIFY_ON_TRANSFER) UpdateInventorySlot(pc, Button, slot_item, "inventory", SlotType["Type"] & SLOT_INVENTORY == 0) if slot_item: Button.SetAction(OnDragItem, IE_ACT_DRAG_DROP_CRT) Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, OnDragItem) Button.SetEvent(IE_GUI_BUTTON_ON_RIGHT_PRESS, OpenItemInfoWindow) Button.SetEvent(IE_GUI_BUTTON_ON_SHIFT_PRESS, OpenItemAmountWindow) #If the slot is being used to display the 'default' weapon, disable dragging. if SlotType["ID"] == 10 and using_fists: Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, None) #dropping is ok, because it will drop in the quick weapon slot and not the default weapon slot. else: if SlotType["ResRef"] == "*": Button.SetBAM("", 0, 0) Button.SetTooltip(SlotType["Tip"]) itemname = "" elif SlotType["ResRef"] == "": Button.SetBAM("", 0, 0) Button.SetFlags(IE_GUI_BUTTON_NO_IMAGE, OP_OR) Button.SetTooltip("") itemname = "" else: if SlotType["Flags"] & 2: Button.SetPicture(SlotType["ResRef"]) else: Button.SetBAM(SlotType["ResRef"], 0, 0) Button.SetTooltip(SlotType["Tip"]) if SlotMap and SlotMap[slot] < 0: Button.SetBAM("", 0, 0) Button.SetFlags(IE_GUI_BUTTON_NO_IMAGE, OP_OR) Button.SetTooltip("") itemname = "" Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, None) Button.SetEvent(IE_GUI_BUTTON_ON_RIGHT_PRESS, None) Button.SetEvent(IE_GUI_BUTTON_ON_SHIFT_PRESS, None) Button.SetEvent(IE_GUI_BUTTON_ON_DOUBLE_PRESS, OpenItemAmountWindow) if (SlotType["Type"] & SLOT_INVENTORY) or not GemRB.CanUseItemType( SlotType["Type"], itemname): Button.SetState(IE_GUI_BUTTON_ENABLED) else: Button.SetState(IE_GUI_BUTTON_FAKEPRESSED) if slot_item and (GemRB.GetEquippedQuickSlot(pc) == slot + 1 or GemRB.GetEquippedAmmunition(pc) == slot + 1): Button.SetState(IE_GUI_BUTTON_FAKEDISABLED) return SlotType
def DCMainDonePress(): """Saves our dualclass changes and closes the window. This de-activates our old class and readjusts the basic actor stats, such as THAC0, spell casting, proficiencies, and so forth, to the new class.""" import GUIREC global ClassName # save our proficiencies LUProfsSelection.ProfsSave(pc, LUProfsSelection.LUPROFS_TYPE_DUALCLASS) # remove old class abilities KitIndex = GUICommon.GetKitIndex(pc) if KitIndex: ABTable = CommonTables.KitList.GetValue(str(KitIndex), "ABILITIES") else: ABTable = CommonTables.ClassSkills.GetValue(OldClassName, "ABILITIES") if ABTable != "*" and GemRB.HasResource(ABTable, RES_2DA, 1): GUICommon.RemoveClassAbilities(pc, ABTable, GemRB.GetPlayerStat(pc, IE_LEVEL)) # remove old class casting if not NewMageSpells: for i in range(9): GemRB.SetMemorizableSpellsCount(pc, 0, IE_SPELL_TYPE_WIZARD, i) Spellbook.RemoveKnownSpells(pc, IE_SPELL_TYPE_PRIEST, 1, 7, 1) # apply our class abilities ABTable = CommonTables.ClassSkills.GetValue(ClassName, "ABILITIES") if ABTable != "*" and GemRB.HasResource(ABTable, RES_2DA, 1): GUICommon.AddClassAbilities(pc, ABTable) # learn our new priest spells if NewPriestMask: Spellbook.LearnPriestSpells(pc, 1, NewPriestMask) GemRB.SetMemorizableSpellsCount(pc, 1, IE_SPELL_TYPE_PRIEST, 0) # save our thief skills if we have them LUSkillsSelection.SkillsSave(pc) # save our new class and say was multi OldClassId = GemRB.GetPlayerStat(pc, IE_CLASS) MultClassId = (1 << (NewClassId - 1)) | (1 << (OldClassId - 1)) MultClassId = CommonTables.Classes.FindValue("MULTI", MultClassId) MultClassId = CommonTables.Classes.GetRowName(MultClassId) MultClassId = CommonTables.Classes.GetValue(MultClassId, "ID") GemRB.SetPlayerStat(pc, IE_CLASS, MultClassId) GemRB.SetPlayerStat( pc, IE_MC_FLAGS, CommonTables.Classes.GetValue(OldClassName, "MC_WAS_ID", 1)) # update our levels and xp if GUICommon.IsDualSwap(pc): GemRB.SetPlayerStat(pc, IE_LEVEL2, 1) else: GemRB.SetPlayerStat(pc, IE_LEVEL2, GemRB.GetPlayerStat(pc, IE_LEVEL), 0) GemRB.SetPlayerStat(pc, IE_LEVEL, 1) GemRB.SetPlayerStat(pc, IE_XP, 0) # new thac0 ThacoTable = GemRB.LoadTable("THAC0") GemRB.SetPlayerStat(pc, IE_TOHIT, ThacoTable.GetValue(NewClassId - 1, 0, 1)) # new saves SavesTable = CommonTables.Classes.GetValue(ClassName, "SAVE", 0) SavesTable = GemRB.LoadTable(SavesTable) for i in range(5): GemRB.SetPlayerStat(pc, IE_SAVEVSDEATH + i, SavesTable.GetValue(i, 0)) # dump any equipped items that are now unusable SlotTypes = [ SLOT_ARMOUR, SLOT_SHIELD, SLOT_HELM, SLOT_RING, SLOT_CLOAK, SLOT_BOOT, SLOT_AMULET, SLOT_GLOVE, SLOT_BELT, SLOT_ITEM, SLOT_WEAPON, SLOT_QUIVER ] for type in SlotTypes: Slots = GemRB.GetSlots(pc, type) if not len(Slots): # nothing there continue for slot in Slots: SlotType = GemRB.GetSlotType(slot, pc) CREItem = GemRB.GetSlotItem(pc, slot) if not GemRB.CanUseItemType(SlotType["Type"], CREItem["ItemResRef"], pc): # move it to a free inventory slot by mimicking dragging Item = GemRB.GetItem(CREItem["ItemResRef"]) GemRB.DragItem(pc, slot, Item["ItemIcon"]) GemRB.DropDraggedItem(pc, -3) # close our window if DCMainWindow: DCMainWindow.Unload() GUIREC.UpdateRecordsWindow() return
def UpdateSlot(pc, i): Window = InventoryWindow # NOTE: there are invisible items (e.g. MORTEP) in inaccessible slots # used to assign powers and protections if slot_list[i] < 0: slot = i + 1 SlotType = GemRB.GetSlotType(slot) slot_item = 0 else: slot = slot_list[i] + 1 SlotType = GemRB.GetSlotType(slot) slot_item = GemRB.GetSlotItem(pc, slot) ControlID = SlotType["ID"] if ControlID < 0: return if GemRB.IsDraggingItem(): #get dragged item drag_item = GemRB.GetSlotItem(0, 0) itemname = drag_item["ItemResRef"] drag_item = GemRB.GetItem(itemname) else: itemname = "" Button = Window.GetControl(ControlID) ItemHash[ControlID] = [slot, slot_item] Button.SetSprites('IVSLOT', 0, 0, 1, 2, 3) if slot_item: item = GemRB.GetItem(slot_item['ItemResRef']) identified = slot_item['Flags'] & IE_INV_ITEM_IDENTIFIED Button.SetItemIcon(slot_item['ItemResRef']) if item['MaxStackAmount'] > 1: Button.SetText(str(slot_item['Usages0'])) else: Button.SetText('') if not identified or item['ItemNameIdentified'] == -1: Button.SetTooltip(item['ItemName']) Button.EnableBorder(0, 1) else: Button.SetTooltip(item['ItemNameIdentified']) Button.EnableBorder(0, 0) if GemRB.CanUseItemType(SLOT_ANY, slot_item['ItemResRef'], pc): Button.EnableBorder(1, 0) else: Button.EnableBorder(1, 1) Button.SetFlags(IE_GUI_BUTTON_NO_IMAGE, OP_NAND) Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, OnDragItem) Button.SetEvent(IE_GUI_BUTTON_ON_RIGHT_PRESS, InventoryCommon.OpenItemInfoWindow) Button.SetEvent(IE_GUI_BUTTON_ON_SHIFT_PRESS, OpenItemAmountWindow) Button.SetEvent(IE_GUI_BUTTON_ON_DRAG_DROP, OnDragItem) else: Button.SetItemIcon('') Button.SetText('') if slot_list[i] >= 0: Button.SetSprites(SlotType["ResRef"], 0, 0, 1, 2, 3) Button.SetFlags(IE_GUI_BUTTON_NO_IMAGE, OP_NAND) Button.SetEvent(IE_GUI_BUTTON_ON_DRAG_DROP, OnDragItem) Button.SetTooltip(SlotType["Tip"]) else: Button.SetFlags(IE_GUI_BUTTON_NO_IMAGE, OP_OR) Button.SetEvent(IE_GUI_BUTTON_ON_DRAG_DROP, None) Button.SetTooltip('') itemname = "" Button.EnableBorder(0, 0) Button.EnableBorder(1, 0) Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, None) Button.SetEvent(IE_GUI_BUTTON_ON_RIGHT_PRESS, None) Button.SetEvent(IE_GUI_BUTTON_ON_SHIFT_PRESS, None) if OverSlot == slot - 1: if GemRB.CanUseItemType(SlotType["Type"], itemname): Button.SetState(IE_GUI_BUTTON_SELECTED) else: Button.SetState(IE_GUI_BUTTON_ENABLED) else: if (SlotType["Type"] & SLOT_INVENTORY) or not GemRB.CanUseItemType( SlotType["Type"], itemname): Button.SetState(IE_GUI_BUTTON_ENABLED) else: Button.SetState(IE_GUI_BUTTON_SECOND) if slot_item and (GemRB.GetEquippedQuickSlot(pc) == slot or GemRB.GetEquippedAmmunition(pc) == slot): Button.SetState(IE_GUI_BUTTON_THIRD) return
def UpdateSlot(pc, slot): """Updates a specific slot.""" Window = GUIINV.InventoryWindow SlotType = GemRB.GetSlotType(slot + 1, pc) ControlID = SlotType["ID"] if not ControlID: return if GemRB.IsDraggingItem() == 1: #get dragged item drag_item = GemRB.GetSlotItem(0, 0) itemname = drag_item["ItemResRef"] drag_item = GemRB.GetItem(itemname) else: itemname = "" Button = Window.GetControl(ControlID) slot_item = GemRB.GetSlotItem(pc, slot + 1) Button.SetEvent(IE_GUI_BUTTON_ON_DRAG_DROP, OnDragItem) Button.SetFlags(IE_GUI_BUTTON_NO_IMAGE, OP_NAND) GUICommon.UpdateInventorySlot(pc, Button, slot_item, "inventory", SlotType["Type"] & SLOT_INVENTORY == 0) if slot_item: Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, OnDragItem) Button.SetEvent(IE_GUI_BUTTON_ON_RIGHT_PRESS, OpenItemInfoWindow) Button.SetEvent(IE_GUI_BUTTON_ON_SHIFT_PRESS, OpenItemAmountWindow) else: if SlotType["ResRef"] == "*": Button.SetBAM("", 0, 0) Button.SetTooltip(SlotType["Tip"]) itemname = "" elif SlotType["ResRef"] == "": Button.SetBAM("", 0, 0) Button.SetFlags(IE_GUI_BUTTON_NO_IMAGE, OP_OR) Button.SetTooltip("") itemname = "" else: Button.SetBAM(SlotType["ResRef"], 0, 0) Button.SetTooltip(SlotType["Tip"]) Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, None) Button.SetEvent(IE_GUI_BUTTON_ON_RIGHT_PRESS, None) Button.SetEvent(IE_GUI_BUTTON_ON_SHIFT_PRESS, None) Button.SetEvent(IE_GUI_BUTTON_ON_DOUBLE_PRESS, OpenItemAmountWindow) if OverSlot == slot + 1: if GemRB.CanUseItemType(SlotType["Type"], itemname): Button.SetState(IE_GUI_BUTTON_SELECTED) else: Button.SetState(IE_GUI_BUTTON_ENABLED) else: if (SlotType["Type"] & SLOT_INVENTORY) or not GemRB.CanUseItemType( SlotType["Type"], itemname): Button.SetState(IE_GUI_BUTTON_ENABLED) else: Button.SetState(IE_GUI_BUTTON_SECOND) if slot_item and (GemRB.GetEquippedQuickSlot(pc) == slot + 1 or GemRB.GetEquippedAmmunition(pc) == slot + 1): Button.SetState(IE_GUI_BUTTON_THIRD) return