Back to Home

ESO Lua File v100034

ingame/soulgemitemcharger/soulgemitemcharger.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
ZO_SoulGemItemCharger = ZO_Object:Subclass()
function ZO_SoulGemItemCharger:New(...)
    local object = ZO_Object.New(self)
    object:Initialize(...)
    return object
end
function ZO_SoulGemItemCharger:Initialize(control)
    self.control = control
    self:SetupPreviewControls()
    local function ChargeItem()
        local selectedData = ZO_InventorySlot_GetItemListDialog():GetSelectedItem()
        if selectedData then
            ChargeItemWithSoulGem(self.currentBag, self.currentIndex, selectedData.bag, selectedData.index)
        end
    end
    ZO_Dialogs_RegisterCustomDialog("CHARGE_ITEM",
    {
        customControl = function() return ZO_InventorySlot_GetItemListDialog():GetControl() end,
        setup = function(dialog, data) self:SetupDialog(data.bag, data.index) end,
        title =
        {
            text = SI_CHARGE_WEAPON_TITLE,
        },        
        buttons =
        {
            {
                control = ZO_InventorySlot_GetItemListDialog():GetButton(1),
                text = SI_CHARGE_WEAPON_CONFIRM,
                clickSound = SOUNDS.INVENTORY_ITEM_APPLY_CHARGE,
                callback = ChargeItem,
            },
            {
                control = ZO_InventorySlot_GetItemListDialog():GetButton(2),
                text = SI_DIALOG_CANCEL,
            }
        }
    })
end
function ZO_SoulGemItemCharger:SetupPreviewControls()
    local previewContainer = self.control:GetNamedChild("ImprovementPreviewContainer")
    self.inventorySlot = previewContainer:GetNamedChild("Slot")
    local improvementContainer = previewContainer:GetNamedChild("ImprovementContainer")
    self.chargesBar = improvementContainer:GetNamedChild("Bar")
    self.chargesUnderlayBar = improvementContainer:GetNamedChild("Underlay")
    ZO_StatusBar_SetGradientColor(self.chargesBar, ZO_CONDITION_GRADIENT_COLORS)
    self.previewControlsInitialized = true
end
function ZO_SoulGemItemCharger:SetItemInfo(bag, index)
    self.control:SetHidden(false)
    local icon, stackCount = GetItemInfo(bag, index)
    ZO_Inventory_BindSlot(self.inventorySlot, SLOT_TYPE_PENDING_CHARGE, index, bag)
    ZO_Inventory_SetupSlot(self.inventorySlot, stackCount, icon)
    local charges, maxCharges = GetChargeInfoForItem(bag, index)
    self.chargesBar:SetMinMax(0, maxCharges)
    self.chargesBar:SetValue(charges)
    local FORCE = true
    ZO_StatusBar_SmoothTransition(self.chargesUnderlayBar, charges, maxCharges, FORCE)
end
function ZO_SoulGemItemCharger:OnSoulGemSelected(itemBagId, itemSlotIndex, soulGemBagId, soulGemSlotIndex)
    local chargesToAdd = GetAmountSoulGemWouldChargeItem(itemBagId, itemSlotIndex, soulGemBagId, soulGemSlotIndex)
    local _, max = self.chargesUnderlayBar:GetMinMax()
    local newCharges = zo_clamp(self.chargesBar:GetValue() + chargesToAdd, 0, max)
    ZO_StatusBar_SmoothTransition(self.chargesUnderlayBar, newCharges, max)
end
local function SortComparator(left, right)
    return GetSoulGemItemInfo(left.data.bag, left.data.index) < GetSoulGemItemInfo(right.data.bag, right.data.index)
end
local function IsFilledSoulGem(bagId, slotIndex)
    return IsItemSoulGem(SOUL_GEM_TYPE_FILLED, bagId, slotIndex)
end
function ZO_SoulGemItemCharger:SetupDialog(bag, index)
    local listDialog = ZO_InventorySlot_GetItemListDialog()
    listDialog:SetAboveText(GetString(SI_CHARGE_WEAPON_SELECT))
    listDialog:SetBelowText(GetString(SI_CHARGE_WEAPON_CONSUME))
    listDialog:SetEmptyListText(GetString(SI_CHARGE_WEAPON_NONE_FOUND))
    listDialog:ClearList()
    local itemList = PLAYER_INVENTORY:GenerateListOfVirtualStackedItems(INVENTORY_BACKPACK, IsFilledSoulGem)
    for itemId, itemInfo in pairs(itemList) do
        listDialog:AddListItem(itemInfo)
    end
    listDialog:CommitList(SortComparator)
    listDialog:AddCustomControl(self.control, LIST_DIALOG_CUSTOM_CONTROL_LOCATION_TOP)
    self:SetItemInfo(bag, index)
    listDialog:SetOnSelectedCallback(function(selectedData) self:OnSoulGemSelected(bag, index, selectedData.bag, selectedData.index) end)
    self.currentBag = bag
    self.currentIndex = index
end
function ZO_SoulGemItemCharger:BeginItemImprovement(bag, index)
    ZO_Dialogs_ShowDialog("CHARGE_ITEM", {bag = bag, index = index})
end
    SOUL_GEM_ITEM_CHARGER = ZO_SoulGemItemCharger:New(control)
    SYSTEMS:RegisterKeyboardObject("soulgem", SOUL_GEM_ITEM_CHARGER)
end