Back to Home

ESO Lua File v100036

ingame/storewindow/gamepad/storewindowrepair_gamepad.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
ZO_GamepadStoreRepair = ZO_GamepadStoreListComponent:Subclass()
function ZO_GamepadStoreRepair:New(...)
    return ZO_GamepadStoreListComponent.New(self, ...)
end
function ZO_GamepadStoreRepair:Initialize(scene)
    ZO_GamepadStoreListComponent.Initialize(self, scene, ZO_MODE_STORE_REPAIR, GetString(SI_STORE_MODE_REPAIR))
    self.fragment:RegisterCallback("StateChange", function(oldState, newState)
        if newState == SCENE_SHOWING then
            self:RegisterEvents()
            self.list:UpdateList()
        elseif newState == SCENE_HIDING then
            self:UnregisterEvents()
        end
    end)
    self:CreateModeData(SI_STORE_MODE_REPAIR, ZO_MODE_STORE_REPAIR, "EsoUI/Art/Vendor/vendor_tabIcon_repair_up.dds", fragment, self.keybindStripDescriptor)
    self.list:SetNoItemText(GetString(SI_GAMEPAD_NO_DAMAGED_ITEMS))
end
function ZO_GamepadStoreRepair:RegisterEvents()
    local OnInventoryUpdated = function(eventId, bagId, slotId, isNewItem, soundCategory, reason)
        if reason == INVENTORY_UPDATE_REASON_DURABILITY_CHANGE then
            self.isCurrentSelectionDirty = true
            self:Refresh()
            KEYBIND_STRIP:UpdateKeybindButtonGroup(self.keybindStripDescriptor)
        end
    end
    self.control:RegisterForEvent(EVENT_INVENTORY_FULL_UPDATE, OnInventoryUpdated)
    self.control:RegisterForEvent(EVENT_INVENTORY_SINGLE_SLOT_UPDATE, OnInventoryUpdated)
    local OnCurrencyChanged = function()
        self.list:RefreshVisible()
    end
    self.control:RegisterForEvent(EVENT_MONEY_UPDATE, OnCurrencyChanged)
    self.control:RegisterForEvent(EVENT_ALLIANCE_POINT_UPDATE, OnCurrencyChanged)
end
function ZO_GamepadStoreRepair:UnregisterEvents()
    self.control:UnregisterForEvent(EVENT_INVENTORY_FULL_UPDATE)
    self.control:UnregisterForEvent(EVENT_INVENTORY_SINGLE_SLOT_UPDATE)
    self.control:UnregisterForEvent(EVENT_MONEY_UPDATE)
    self.control:UnregisterForEvent(EVENT_ALLIANCE_POINT_UPDATE)
end
function ZO_GamepadStoreRepair:InitializeKeybindStrip()
    -- Repair screen keybind
    self.keybindStripDescriptor =
    {
        alignment = KEYBIND_STRIP_ALIGN_LEFT,
        STORE_WINDOW_GAMEPAD:GetRepairAllKeybind()
    }
                                                    GAME_NAVIGATION_TYPE_BUTTON,
                                                    function() self:ConfirmRepair() end,
                                                    GetString(SI_ITEM_ACTION_REPAIR),
                                                    function() return #self.list.dataList > 0 end,
                                                    function() return self:CanRepair() end)
    ZO_Gamepad_AddBackNavigationKeybindDescriptors(self.keybindStripDescriptor, GAME_NAVIGATION_TYPE_BUTTON)
    ZO_Gamepad_AddListTriggerKeybindDescriptors(self.keybindStripDescriptor, self.list)
end
function ZO_GamepadStoreRepair:AddKeybinds()
    if not KEYBIND_STRIP:HasKeybindButtonGroup(self.keybindStripDescriptor) then
        KEYBIND_STRIP:AddKeybindButtonGroup(self.keybindStripDescriptor)
    end
end
function ZO_GamepadStoreRepair:RemoveKeybinds()
    KEYBIND_STRIP:RemoveKeybindButtonGroup(self.keybindStripDescriptor)
end
function ZO_GamepadStoreRepair:CanRepair()
    local selectedItem = self.list:GetTargetData()
    local cost = selectedItem.repairCost
    if cost <= GetCurrencyAmount(CURT_MONEY, CURRENCY_LOCATION_CHARACTER) then
        return true
    else
        return false, GetString("SI_ITEMREPAIRREASON", ITEM_REPAIR_CANT_AFFORD_REPAIR) -- "You can't afford to repair this item"
    end
end
function ZO_GamepadStoreRepair:ConfirmRepair()
    local selectedItem = self.list:GetTargetData() --All items in this list are damaged
    local bagId = selectedItem.bagId
    local slotIndex = selectedItem.slotIndex
    RepairItem(bagId, slotIndex)
    PlaySound(SOUNDS.INVENTORY_ITEM_REPAIR)
end
function ZO_GamepadStoreRepair:SetupEntry(control, data, selected, selectedDuringRebuild, enabled, activated)
    self:SetupStoreItem(control, data, selected, selectedDuringRebuild, enabled, activated, data.repairCost, not ZO_STORE_FORCE_VALID_PRICE, ZO_MODE_STORE_REPAIR)
     local conditionControl = control:GetNamedChild("Condition")
     if conditionControl then
          conditionControl:SetHidden(false)
          conditionControl:SetText(zo_strformat(SI_ITEM_CONDITION_PERCENT, data.condition))
     end
end
function ZO_GamepadStoreRepair:OnSelectedItemChanged(inventoryData)
    GAMEPAD_TOOLTIPS:ClearLines(GAMEPAD_LEFT_TOOLTIP)
    if inventoryData then
        GAMEPAD_TOOLTIPS:LayoutBagItem(GAMEPAD_LEFT_TOOLTIP, inventoryData.bagId, inventoryData.slotIndex)
    end
end
function ZO_GamepadStoreRepair:GetNumRepairItems()
    return #self.list.dataList
end