Back to Home

ESO Lua File v101041

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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
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, useKeybindStrip)
    local slotActions = ZO_InventorySlotActions:New(INVENTORY_SLOT_ACTIONS_PREVENT_CONTEXT_MENU)
    self.slotActions = slotActions
    self.useKeybindStrip = useKeybindStrip == nil and true or useKeybindStrip
    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:SetUseKeybindStrip(useKeybindStrip)
    self.useKeybindStrip = useKeybindStrip
end
function ZO_ItemSlotActionsController:AddSubCommand(command, hasBind, activateCallback)
    self[#self + 1] = { command, hasBind = hasBind, activateCallback = activateCallback }
end
function ZO_ItemSlotActionsController:RefreshKeybindStrip()
    if not self.useKeybindStrip then
        return
    end
    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
    self:RebuildActions()
end
function ZO_ItemSlotActionsController:RebuildActions()
    for i, command in ipairs(self) do
        if command.activateCallback then
            command.activateCallback(self.inventorySlot)
        end
    end
end
function ZO_ItemSlotActionsController:GetSlotActions()
    return self.slotActions
end
function ZO_ItemSlotActionsController:GetSlotActionAtIndex(index)
    return self.slotActions:GetSlotAction(index)
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