ESO Lua File v100011

ingame/inventory/stack.lua

[◄ back to folders ]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
function ZO_StackSplit_SplitItem(inventorySlotControl)
    local slot = PLAYER_INVENTORY:SlotForInventoryControl(inventorySlotControl)
    if(slot) then
        if(slot.locked) then        
            ZO_Alert(UI_ALERT_CATEGORY_ERROR, SOUNDS.NEGATIVE_CLICK, GetString(SI_ERROR_ITEM_LOCKED))
            return false
        end
        
        local bagId, slotIndex = ZO_Inventory_GetBagAndIndex(inventorySlotControl)
        local stackSize = GetSlotStackSize(bagId, slotIndex)
        if(stackSize <= 1 or not ZO_InventorySlot_IsSplittableType(inventorySlotControl)) then
            return false
        end
        if IsInGamepadPreferredMode() then
            local gamepadData = 
                {
                     inventorySlotControl = inventorySlotControl,
                     bagId = bagId,
                     slotIndex = slotIndex,   
                }
            ZO_Dialogs_ShowGamepadDialog(ZO_GAMEPAD_SPLIT_STACK_DIALOG, gamepadData)
        else
            ZO_Dialogs_ShowDialog("SPLIT_STACK", inventorySlotControl)
        end
        return true
    end
    
    return false
end
local function RefreshDestinations(stackControl)
    local stackLabel = GetControl(stackControl, "Destination1StackCount")
    stackLabel:SetText(stackControl.stackSize - stackControl.spinner:GetValue())
end
local function SetupStackSplit(stackControl, inventorySlotControl)
    local bagId, slotIndex = ZO_Inventory_GetBagAndIndex(inventorySlotControl)
    local stackSize = GetSlotStackSize(bagId, slotIndex)
    stackControl.stackSize = stackSize
    stackControl.slotControl = inventorySlotControl
    local itemIcon, _, _, _, _, _, _, quality = GetItemInfo(bagId, slotIndex)
    local itemName = GetItemName(bagId, slotIndex)
    local qualityColor = GetItemQualityColor(quality)
    GetControl(stackControl, "Prompt"):SetText(zo_strformat(SI_INVENTORY_SPLIT_STACK_PROMPT, qualityColor:Colorize(itemName)))
    local sourceSlot = GetControl(stackControl, "Source")
    local destinationSlot1 = GetControl(stackControl, "Destination1")
    local destinationSlot2 = GetControl(stackControl, "Destination2")
    ZO_ItemSlot_SetupSlot(sourceSlot, stackSize, itemIcon)
    ZO_ItemSlot_SetupSlot(destinationSlot1, 0, itemIcon)
    ZO_ItemSlot_SetupSlot(destinationSlot2, 0, itemIcon)
    ZO_Inventory_BindSlot(sourceSlot, SLOT_TYPE_STACK_SPLIT, slotIndex, bagId)
    ZO_Inventory_BindSlot(destinationSlot1, SLOT_TYPE_STACK_SPLIT, slotIndex, bagId)
    ZO_Inventory_BindSlot(destinationSlot2, SLOT_TYPE_STACK_SPLIT, slotIndex, bagId)
    stackControl.spinner:SetMinMax(1, stackSize - 1)
    stackControl.spinner:SetValue(zo_floor(stackSize / 2))
    RefreshDestinations(stackControl)
end
    ZO_Dialogs_RegisterCustomDialog("SPLIT_STACK",   
    {
        customControl = self,
        setup = SetupStackSplit,
        title =
        {
            text = SI_INVENTORY_SPLIT_STACK_TITLE,
        },
        buttons =
        {
            [1] =
            {
                control =   GetControl(self, "Split"),
                text =      SI_INVENTORY_SPLIT_STACK,
                callback =  function(stackControl)
                                local bag, index = ZO_Inventory_GetBagAndIndex(stackControl.slotControl)
                                PickupInventoryItem(bag, index, stackControl.spinner:GetValue())
                                -- Auto-drop into whatever bag this came from
                                ZO_InventoryLandingArea_DropCursorInBag(bag)
                            end,
            },
        
            [2] =
            {
                control =   GetControl(self, "Cancel"),
                text =      SI_DIALOG_CANCEL,
            }
        }
    })
    local function HandleCursorPickup(eventId, cursorType)
        if(cursorType == MOUSE_CONTENT_INVENTORY_ITEM) then
            ZO_Dialogs_ReleaseAllDialogsOfName("STACK_SPLIT")
        end
    end
    local function OnSpinnerValueChanged()
        RefreshDestinations(self)
    end
    self.spinner = ZO_Spinner:New(GetControl(self, "Spinner"))
    self.spinner:RegisterCallback("OnValueChanged", OnSpinnerValueChanged)
    EVENT_MANAGER:RegisterForEvent("ZO_Stack", EVENT_CURSOR_PICKUP, HandleCursorPickup)
end