Back to Home

ESO Lua File v100019

ingame/inventory/itemslotactioncontroller.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
ZO_ItemSlotActionsController = ZO_Object:Subclass()
function ZO_ItemSlotActionsController:New(...)
    local command = ZO_Object.New(self)
    command:Initialize(...)
    return command
end
function ZO_ItemSlotActionsController:Initialize(alignmentOverride, additionalMouseOverbinds)
    self.alignment = KEYBIND_STRIP_ALIGN_RIGHT
    local slotActions = ZO_InventorySlotActions:New(INVENTORY_SLOT_ACTIONS_PREVENT_CONTEXT_MENU)
    self.slotActions = slotActions
    local primaryCommand =
    {
        alignment = alignmentOverride,
        name = function()
            if(self.selectedAction) then
                return slotActions:GetRawActionName(self.selectedAction)
            end
            return self.actionName or ""
        end,
        keybind = "UI_SHORTCUT_PRIMARY",
        order = 500,
        callback = function()
            if self.selectedAction then
                self:DoSelectedAction()
            else
                slotActions:DoPrimaryAction()
            end
        end,
        visible =   function()
                        return slotActions:CheckPrimaryActionVisibility() or self:HasSelectedAction()
                    end,
    }
    local function PrimaryCommandHasBind()
        return (self.actionName ~= nil) or self:HasSelectedAction()
    end
    local function PrimaryCommandActivate(inventorySlot)
        slotActions:Clear()
        slotActions:SetInventorySlot(inventorySlot)
        self.selectedAction = nil -- Do not call the update function, just clear the selected action
        if not inventorySlot then
            self.actionName = nil
        else
            ZO_InventorySlot_DiscoverSlotActionsFromActionList(inventorySlot, slotActions)
            self.actionName = slotActions:GetPrimaryActionName()
        end
    end
    if additionalMouseOverbinds then
        local mouseOverCommand, mouseOverCommandIsVisible
        for i=1, #additionalMouseOverbinds do
            mouseOverCommand =
            {
                alignment = alignmentOverride,
                name = function()
                    return slotActions:GetKeybindActionName(i)
                end,
                keybind = additionalMouseOverbinds[i],
                callback = function() slotActions:DoKeybindAction(i) end,
                visible =   function()
                                return slotActions:CheckKeybindActionVisibility(i)
                            end,
            }
            mouseOverCommandIsVisible = function()
                return slotActions:GetKeybindActionName(i) ~= nil
            end
            self:AddSubCommand(mouseOverCommand, mouseOverCommandIsVisible)
        end
    end
end
function ZO_ItemSlotActionsController:AddSubCommand(command, hasBind, activateCallback)
    self[#self + 1] = { command, hasBind = hasBind, activateCallback = activateCallback }
end
function ZO_ItemSlotActionsController:RefreshKeybindStrip()
    for i, command in ipairs(self) do
        if command.hasBind() then
            if KEYBIND_STRIP:HasKeybindButtonGroup(command) then
                KEYBIND_STRIP:UpdateKeybindButtonGroup(command)
            else
                KEYBIND_STRIP:AddKeybindButtonGroup(command)
            end
        else
            KEYBIND_STRIP:RemoveKeybindButtonGroup(command)
        end
    end
end
function ZO_ItemSlotActionsController:SetInventorySlot(inventorySlot)
    self.inventorySlot = inventorySlot
    for i, command in ipairs(self) do
        if command.activateCallback then
            command.activateCallback(inventorySlot)
        end
    end
    self:RefreshKeybindStrip()
end
function ZO_ItemSlotActionsController:GetSlotActions()
    return self.slotActions
end
function ZO_ItemSlotActionsController:SetSelectedAction(action)
    self.selectedAction = action
end
function ZO_ItemSlotActionsController:HasSelectedAction()
    return self.selectedAction ~= nil
end
function ZO_ItemSlotActionsController:GetSelectedAction()
    return self.selectedAction
end
function ZO_ItemSlotActionsController:DoSelectedAction()
    self.slotActions:DoAction(self.selectedAction)
end
function ZO_ItemSlotActionsController:GetActions()
    return self.slotActions
end