ESO Lua File v100012

ingame/zo_loot/console/loothistory_console.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
local GAMEPAD_LOOT_HISTORY_ENTRY_TEMPLATE = "ZO_LootGamepad_HistoryEntry"
local ZO_LootHistory_Gamepad = ZO_Object:Subclass()
function ZO_LootHistory_Gamepad:New(control)
    history = ZO_Object.New(self)
    history:Initialize(control)
    return history
end
function ZO_LootHistory_Gamepad:Initialize(control)
    self.fadeAnim = ZO_AlphaAnimation:New(control)
    self.fadeAnim:SetMinMaxAlpha(0.0, 1.0)
    self.lootQueue = {}
end
local MONEY_TEXT = {
    [CURT_MONEY] = GetString(SI_CURRENCY_GOLD),
    [CURT_ALLIANCE_POINTS] = GetString(SI_CURRENCY_ALLIANCE_POINTS),
    [CURT_TELVAR_STONES] = GetString(SI_CURRENCY_TELVAR_STONES),
}
local MONEY_ICONS = {
    [CURT_MONEY] = LOOT_MONEY_ICON,
    [CURT_ALLIANCE_POINTS] = "EsoUI/Art/currency/gamepad/gp_alliancePoints.dds",
    [CURT_TELVAR_STONES] = LOOT_TELVAR_STONE_ICON,
}
local MONEY_TEXT_COLOR = ZO_SELECTED_TEXT
local MONEY_BACKGROUND_COLORS = {
    [CURT_MONEY] = ZO_ColorDef:New(GetInterfaceColor(INTERFACE_COLOR_TYPE_CURRENCY, CURRENCY_COLOR_GOLD)),
    [CURT_ALLIANCE_POINTS] = ZO_ColorDef:New(GetInterfaceColor(INTERFACE_COLOR_TYPE_CURRENCY, CURRENCY_COLOR_ALLIANCE_POINTS)),
    [CURT_TELVAR_STONES] = ZO_ColorDef:New(GetInterfaceColor(INTERFACE_COLOR_TYPE_CURRENCY, CURRENCY_COLOR_TELVAR_STONES)),
}
function ZO_LootHistory_Gamepad:RegisterForEvents(control)
    local function InsertOrQueue(lootData)
        if self.hidden then
            table.insert(self.lootQueue, lootData)
        else
            self.loot:AddEntry(GAMEPAD_LOOT_HISTORY_ENTRY_TEMPLATE, lootData)
        end
    end
    local function OnLootReceived(_, _, itemLink, stackCount, _, lootType, lootedBySelf, _, questItemIcon, itemId)
        if lootedBySelf and not SCENE_MANAGER:IsSceneOnStack("gamepad_inventory_root") then
            local itemName
            local icon
            local color
            local quality
            if lootType == LOOT_TYPE_QUEST_ITEM then
                itemName = itemLink --quest items don't support item linking, this just returns their name.
                icon = questItemIcon
                color = ZO_ColorDef:New(GetInterfaceColor(INTERFACE_COLOR_TYPE_ITEM_TOOLTIP, ITEM_TOOLTIP_COLOR_QUEST_ITEM_NAME))
            else
                itemName = GetItemLinkName(itemLink)
                icon = GetItemLinkInfo(itemLink)
                quality = GetItemLinkQuality(itemLink)
                color = ZO_ColorDef:New(GetInterfaceColor(INTERFACE_COLOR_TYPE_ITEM_QUALITY_COLORS, quality))
            end
            local lootData = {
                lines = {
                    { text = zo_strformat(SI_TOOLTIP_ITEM_NAME, itemName), icon = icon, stackCount = stackCount, color = color, backgroundColor = color, itemId = itemId, quality = quality }
                }
            }
            InsertOrQueue(lootData)
        end
    end
    local function AddMoneyEntry(moneyAdded, moneyType)
        local lootData = {
            lines = {
                { text = MONEY_TEXT[moneyType], icon = MONEY_ICONS[moneyType], stackCount = moneyAdded, color = MONEY_TEXT_COLOR, backgroundColor = MONEY_BACKGROUND_COLORS[moneyType], moneyType = moneyType }
            }
        }
        InsertOrQueue(lootData)
    end
    local function OnGoldUpdate(_, newGold, oldGold, reason)
        if not SCENE_MANAGER:IsSceneOnStack("gamepad_inventory_root") then
            if reason == CURRENCY_CHANGE_REASON_LOOT or reason == CURRENCY_CHANGE_REASON_LOOT_STOLEN or reason == CURRENCY_CHANGE_REASON_QUESTREWARD then
                local goldAdded = newGold - oldGold
                AddMoneyEntry(goldAdded, CURT_MONEY)
            end
        end
    end
    local function OnGoldPickpocket(_, goldAmount)
        AddMoneyEntry(goldAmount, CURT_MONEY)
    end
    local function OnAlliancePointUpdate(_, _, _, alliancePoints)
        if SCENE_MANAGER:IsShowing("gamepadInteract") then
            AddMoneyEntry(alliancePoints, CURT_ALLIANCE_POINTS)
        end
    end
    local function OnTelvarStoneUpdate(_, newTelvarStones, oldTelvarStones, reason)
        if not SCENE_MANAGER:IsSceneOnStack("gamepad_inventory_root") then
            if reason == CURRENCY_CHANGE_REASON_LOOT or reason == CURRENCY_CHANGE_REASON_PVP_KILL_TRANSFER then
                local tvStonesAdded = newTelvarStones - oldTelvarStones
                if tvStonesAdded > 0 then
                    AddMoneyEntry(tvStonesAdded, CURT_TELVAR_STONES)
                end
            end
        end
    end
    control:RegisterForEvent(EVENT_LOOT_RECEIVED, OnLootReceived)
    control:RegisterForEvent(EVENT_MONEY_UPDATE, OnGoldUpdate)
    control:RegisterForEvent(EVENT_JUSTICE_GOLD_PICKPOCKETED, OnGoldPickpocket)
    control:RegisterForEvent(EVENT_ALLIANCE_POINT_UPDATE, OnAlliancePointUpdate)
    control:RegisterForEvent(EVENT_TELVAR_STONE_UPDATE, OnTelvarStoneUpdate)
end
function ZO_LootHistory_Gamepad:InitializeFragment()
    GAMEPAD_LOOT_HISTORY_FRAGMENT = ZO_HUDFadeSceneFragment:New(ZO_LootGamepad_History)
    GAMEPAD_LOOT_HISTORY_FRAGMENT:RegisterCallback("StateChange", function(oldState, newState)
        if newState == SCENE_FRAGMENT_SHOWN then
            self.hidden = false
            self:DisplayLootQueue()
        elseif newState == SCENE_FRAGMENT_HIDING then
            self.hidden = true
            self.loot:FadeAll()
        end
    end)
    SCENE_MANAGER:GetScene("lootGamepad"):AddFragment(GAMEPAD_LOOT_HISTORY_FRAGMENT)
end
do
    local function LootSetupFunction(control, data)
        control.label:SetText(data.text)
        control.label:SetColor(data.color:UnpackRGBA())
        control.icon:SetTexture(data.icon)
        local background = control:GetNamedChild("Bg")
        background:SetColor(data.backgroundColor:UnpackRGBA())
    
        control.stackCountLabel:SetText(data.stackCount)
        control.stackCountLabel:SetHidden(data.stackCount <= 1)
    end
    local function AreEntriesEqual(entry1, entry2)
        -- entry1 and entry2 are tables of one item
        local data1 = entry1[1]
        local data2 = entry2[1]
        if data1.moneyType then
            return data1.moneyType == data2.moneyType
        elseif data1.itemId then
            local itemIdsMatch = data1.itemId == data2.itemId
            if data1.quality or data2.quality then
                return itemIdsMatch and data1.quality == data2.quality
            else
                return itemIdsMatch
            end
        else
            return false
        end
    end
    local function EqualitySetup(fadingControlBuffer, currentEntry, newEntry)
        local currentEntryData = currentEntry.lines[1]
        local newEntryData = newEntry.lines[1]
        local control = ZO_FadingControlBuffer_GetLineControl(currentEntryData)
        currentEntryData.stackCount = currentEntryData.stackCount + newEntryData.stackCount
        control.stackCountLabel:SetText(currentEntryData.stackCount)
        control.stackCountLabel:SetHidden(false)
        ZO_CraftingResults_Base_PlayPulse(control.stackCountLabel)
    end
    function ZO_LootHistory_Gamepad:InitializeFadingControlBuffer(control)
        local MAX_HEIGHT = 364
        local HORIZ_OFFSET = ZO_GAMEPAD_SCREEN_PADDING + ZO_GAMEPAD_CONTENT_INSET_X
        local VERTICAL_OFFSET = -164
        local anchor = ZO_Anchor:New(BOTTOMLEFT, GuiRoot, BOTTOMLEFT, HORIZ_OFFSET, VERTICAL_OFFSET)
        local MAX_LINES_PER_ENTRY = 1
        self.loot = ZO_FadingControlBuffer:New(control, nil, MAX_HEIGHT, MAX_LINES_PER_ENTRY, "AlertFadeGamepad", "AlertTranslateGamepad", anchor)
        self.loot:AddTemplate(GAMEPAD_LOOT_HISTORY_ENTRY_TEMPLATE, {setup = LootSetupFunction, equalityCheck = AreEntriesEqual, equalitySetup = EqualitySetup })
        self.loot:SetTranslateDuration(1500) -- in milliseconds
        self.loot:SetHoldTimes(6000) -- in milliseconds
        self.loot:SetAdditionalVerticalSpacing(5)
        self.loot:SetFadesInImmediately(true)
        self.loot:SetPushDirection(FCB_PUSH_DIRECTION_UP)
    end
end
function ZO_LootHistory_Gamepad:DisplayLootQueue()
    for i, entry in ipairs(self.lootQueue) do
        self.loot:AddEntry(GAMEPAD_LOOT_HISTORY_ENTRY_TEMPLATE, entry)
        self.lootQueue[i] = nil
    end
end
    LOOT_HISTORY_GAMEPAD = ZO_LootHistory_Gamepad:New(control)
end