Back to Home

ESO Lua File v101032

ingame/crafting/keyboard/smithingresearch_keyboard.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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
ZO_SmithingResearch = ZO_SharedSmithingResearch:Subclass()
function ZO_SmithingResearch:Initialize(control, owner)
    ZO_SharedSmithingResearch.Initialize(self, control, owner, "ZO_SmithingResearchSlot")
    self.numResearchingLabel = control:GetNamedChild("NumResearching")
    self:InitializeResearchLineList(ZO_HorizontalScrollList, "ZO_SmithingResearchListSlot")
    self.includeBankedItemsCheckbox = self.control:GetNamedChild("IncludeBanked")
    
    local function OnAddOnLoaded(event, name)
        if name == "ZO_Ingame" then
            self:SetupSavedVars()
            self.control:UnregisterForEvent(EVENT_ADD_ON_LOADED)
        end
    end
    self.control:RegisterForEvent(EVENT_ADD_ON_LOADED, OnAddOnLoaded)
end
function ZO_SmithingResearch:SetHidden(hidden)
    self.control:SetHidden(hidden)
    if not hidden and self.dirty then
        self:Refresh()
    end
end
function ZO_SmithingResearch:InitializeFilterTypeBar()
    local MENU_BAR_DATA =
    {
        initialButtonAnchorPoint = RIGHT,
        buttonTemplate = "ZO_CraftingInventoryTab",
        normalSize = 51,
        downSize = 64,
        buttonPadding = -15,
        animationDuration = 180,
    }
    self.tabs = self.control:GetNamedChild("Tabs")
    self.activeTab = self.control:GetNamedChild("TabsActive")
    ZO_MenuBar_SetData(self.tabs, MENU_BAR_DATA)
    local function CreateNewTabFilterData(filterType, name, normal, pressed, highlight, disabled, visible)
        return {
            tooltipText = name,
            descriptor = filterType,
            normal = normal,
            pressed = pressed,
            highlight = highlight,
            disabled = disabled,
            visible = visible,
            callback = function(filterData) self.activeTab:SetText(name) self:ChangeTypeFilter(filterData) end,
        }
    end
    ZO_MenuBar_AddButton(self.tabs, CreateNewTabFilterData(SMITHING_FILTER_TYPE_JEWELRY, GetString("SI_SMITHINGFILTERTYPE", SMITHING_FILTER_TYPE_JEWELRY), "EsoUI/Art/Crafting/jewelry_tabIcon_icon_up.dds", "EsoUI/Art/Crafting/jewelry_tabIcon_down.dds", "EsoUI/Art/Crafting/jewelry_tabIcon_icon_over.dds", "EsoUI/Art/Inventory/inventory_tabIcon_jewelry_disabled.dds", CanSmithingJewelryPatternsBeCraftedHere))
    ZO_MenuBar_AddButton(self.tabs, CreateNewTabFilterData(SMITHING_FILTER_TYPE_ARMOR, GetString("SI_SMITHINGFILTERTYPE", SMITHING_FILTER_TYPE_ARMOR), "EsoUI/Art/Inventory/inventory_tabIcon_armor_up.dds", "EsoUI/Art/Inventory/inventory_tabIcon_armor_down.dds", "EsoUI/Art/Inventory/inventory_tabIcon_armor_over.dds", "EsoUI/Art/Inventory/inventory_tabIcon_armor_disabled.dds", CanSmithingApparelPatternsBeCraftedHere))
    ZO_MenuBar_AddButton(self.tabs, CreateNewTabFilterData(SMITHING_FILTER_TYPE_WEAPONS, GetString("SI_SMITHINGFILTERTYPE", SMITHING_FILTER_TYPE_WEAPONS), "EsoUI/Art/Inventory/inventory_tabIcon_weapons_up.dds", "EsoUI/Art/Inventory/inventory_tabIcon_weapons_down.dds", "EsoUI/Art/Inventory/inventory_tabIcon_weapons_over.dds", "EsoUI/Art/Inventory/inventory_tabIcon_weapons_disabled.dds", CanSmithingWeaponPatternsBeCraftedHere))
end
function ZO_SmithingResearch:InitializeFilters()
    local function SaveFilters()
        self:SaveFilters()
    end
    ZO_CheckButton_SetToggleFunction(self.includeBankedItemsCheckbox, SaveFilters)
    ZO_CheckButton_SetLabelText(self.includeBankedItemsCheckbox, GetString(SI_CRAFTING_INCLUDE_BANKED))
    CALLBACK_MANAGER:RegisterCallback("CraftingAnimationsStarted", function() 
        ZO_CheckButton_SetCheckState(self.includeBankedItemsCheckbox, self.savedVars.includeBankedItemsChecked)
    end)
    --This needs to happen AFTER the above CraftingAnimationsStarted callback is registered, so the disabled state doesn't get clobbered by setting the check state for the button
    ZO_CraftingUtils_ConnectCheckBoxToCraftingProcess(self.includeBankedItemsCheckbox)
end
function ZO_SmithingResearch:SetupSavedVars()
    local defaults =
    {
        includeBankedItemsChecked = true
    }
    local savedVars = ZO_SavedVars:New("ZO_Ingame_SavedVariables", 1, "SmithingResearch", defaults)
    self:SetSavedVars(savedVars)
    ZO_CheckButton_SetCheckState(self.includeBankedItemsCheckbox, self.savedVars.includeBankedItemsChecked)
end
function ZO_SmithingResearch:IsIncludeBankedItemsChecked()
    return self.savedVars.includeBankedItemsChecked
end
function ZO_SmithingResearch:RefreshAvailableFilters()
end
function ZO_SmithingResearch:SaveFilters()
    local includeBankedItemsChecked = ZO_CheckButton_IsChecked(self.includeBankedItemsCheckbox)
    if self.savedVars.includeBankedItemsChecked ~= includeBankedItemsChecked then
        self.savedVars.includeBankedItemsChecked = includeBankedItemsChecked
        self:HandleDirtyEvent()
    end
end
function ZO_SmithingResearch:SetupTooltip(row)
    InitializeTooltip(InformationTooltip, row, RIGHT, -10)
    SetTooltipText(InformationTooltip, GetString("SI_ITEMTRAITTYPE", row.traitType))
    ZO_Tooltip_AddDivider(InformationTooltip)
    local r, g, b = ZO_SELECTED_TEXT:UnpackRGB()
    local SET_TO_FULL_SIZE = true
    InformationTooltip:AddLine(row.traitDescription, "", r, g, b, CENTER, MODIFY_TEXT_TYPE_NONE, TEXT_ALIGN_CENTER, SET_TO_FULL_SIZE)
    if row.traitResearchSourceDescription then
        InformationTooltip:AddLine(zo_strformat(SI_SMITHING_TRAIT_RESEARCH_SOURCE_DESCRIPTION, row.traitResearchSourceDescription), "", r, g, b, CENTER, MODIFY_TEXT_TYPE_NONE, TEXT_ALIGN_CENTER, SET_TO_FULL_SIZE)
        InformationTooltip:AddLine(zo_strformat(SI_SMITHING_TRAIT_MATERIAL_SOURCE_DESCRIPTION, row.traitMaterialSourceDescription), "", r, g, b, CENTER, MODIFY_TEXT_TYPE_NONE, TEXT_ALIGN_CENTER, SET_TO_FULL_SIZE)
    end
end
function ZO_SmithingResearch:ClearTooltip(row)
    ClearTooltip(InformationTooltip)
end
function ZO_SmithingResearch:Research(overrideRow)
    local canResearchCurrentTrait = self:CanResearchCurrentTraitLine()
    if self.atMaxResearchLimit then
        local craftingSkillLineData = SKILLS_DATA_MANAGER:GetCraftingSkillLineData(GetCraftingInteractionType())
        ZO_Alert(UI_ALERT_CATEGORY_ALERT, SOUNDS.NEGATIVE_CLICK, SI_SMITHING_RESEARCH_ALL_SLOTS_IN_USE, craftingSkillLineData:GetName())
    elseif not canResearchCurrentTrait then
        ZO_Alert(UI_ALERT_CATEGORY_ALERT, SOUNDS.NEGATIVE_CLICK, SI_SMITHING_RESEARCH_TRAIT_ALREADY_BEING_RESEARCHED, self.traitLineText)
    else
        ZO_Dialogs_ShowDialog("SMITHING_RESEARCH_SELECT", overrideRow or self.activeRow)
    end
end
do
    local TRAIT_COLORS =
    {
        ZO_SELECTED_TEXT,
        ZO_NORMAL_TEXT,
    }
    function ZO_SmithingResearch:GetTraitColors()
        return TRAIT_COLORS[1], TRAIT_COLORS[2]
    end
end
function ZO_SmithingResearch:GetResearchTimeString(...)
    return zo_strformat(SI_SMITHING_RESEARCH_TIME_FOR_NEXT, ...)
end
function ZO_SmithingResearch:GetExtraInfoColor()
    return ZO_NORMAL_TEXT:UnpackRGBA()
end
function ZO_SmithingResearch:SetupTraitDisplay(slotControl, researchLine, known, duration, traitIndex)
    local iconControl = GetControl(slotControl, "Icon")
    local selectedColor, normalColor = self:GetTraitColors()
    if known then
        iconControl:SetAlpha(1)
        slotControl.nameLabel:SetColor(selectedColor:UnpackRGBA())
    else
        iconControl:SetAlpha(.3)
        slotControl.nameLabel:SetColor(ZO_DISABLED_TEXT:UnpackRGBA())
    end
    if known then
        slotControl.statusLabel:SetText("")
        slotControl.lockIcon:SetHidden(true)
        slotControl.timerIcon:SetHidden(true)
    elseif duration then
        slotControl.statusLabel:SetText(GetString(SI_SMITHING_RESEARCH_IN_PROGRESS))
        slotControl.statusLabel:SetColor(ZO_SECOND_CONTRAST_TEXT:UnpackRGBA())
        slotControl.nameLabel:SetColor(ZO_SECOND_CONTRAST_TEXT:UnpackRGBA())
        slotControl.lockIcon:SetHidden(true)
        slotControl.timerIcon:SetHidden(false)
        slotControl.timerIcon:SetAlpha(1)
        slotControl.timerIcon:SetColor(ZO_SECOND_CONTRAST_TEXT:UnpackRGBA())
    elseif researchLine.itemTraitCounts and researchLine.itemTraitCounts[traitIndex] then
        slotControl.statusLabel:SetText(GetString(SI_SMITHING_RESEARCH_RESEARCHABLE))
        slotControl.statusLabel:SetColor(normalColor:UnpackRGBA())
        slotControl.researchable = true
        slotControl.lockIcon:SetHidden(true)
        slotControl.nameLabel:SetColor(normalColor:UnpackRGBA())
        slotControl.timerIcon:SetHidden(true)
    else
        slotControl.statusLabel:SetText(GetString(SI_SMITHING_RESEARCH_UNKNOWN))
        slotControl.statusLabel:SetColor(ZO_DISABLED_TEXT:UnpackRGBA())
        slotControl.lockIcon:SetHidden(false)
        slotControl.timerIcon:SetHidden(true)
    end
end
function ZO_SmithingResearch:RefreshCurrentResearchStatusDisplay(currentlyResearching, maxResearchable)
    if currentlyResearching >= maxResearchable then
        self.numResearchingLabel:SetText(zo_strformat(SI_SMITHING_RESEARCH_SLOTS_FULL, maxResearchable))
    else
        self.numResearchingLabel:SetText(zo_strformat(SI_SMITHING_RESEARCH_USED_SLOTS, currentlyResearching, maxResearchable))
    end
end
ZO_SmithingResearchSelect = ZO_SharedSmithingResearchSelect:Subclass()
function ZO_SmithingResearchSelect:Initialize(control)
    ZO_SharedSmithingResearchSelect.Initialize(self, control)
    ZO_Dialogs_RegisterCustomDialog("SMITHING_RESEARCH_SELECT",
    {
        customControl = function() return ZO_InventorySlot_GetItemListDialog():GetControl() end,
        setup = function(dialog, data) self:SetupDialog(data.craftingType, data.researchLineIndex, data.traitIndex) end,
        title =
        {
            text = SI_SMITHING_RESEARCH_DIALOG_TITLE,
        },
        buttons =
        {
            {
                control = ZO_InventorySlot_GetItemListDialog():GetButton(1),
                text = SI_SMITHING_RESEARCH_DIALOG_CONFIRM,
                clickSound = SOUNDS.SMITHING_START_RESEARCH,
                callback = function()
                    local selectedData = ZO_InventorySlot_GetItemListDialog():GetSelectedItem()
                    if selectedData then
                        ResearchSmithingTrait(selectedData.bag, selectedData.index)
                    end
                end,
            },
            {
                control = ZO_InventorySlot_GetItemListDialog():GetButton(2),
                text = SI_DIALOG_CANCEL,
            }
        }
    })
end
local function SortComparator(left, right)
    return left.data.name < right.data.name
end
function ZO_SmithingResearchSelect:OnItemSelected(bagId, slotIndex)
    if IsItemInArmory(bagId, slotIndex) then
        local armoryBuildListNames = { GetItemArmoryBuildList(bagId, slotIndex) }
        local armoryBuildList = ZO_GenerateCommaSeparatedList(armoryBuildListNames)
        local armoryBuildText = zo_strformat(SI_RESEARCH_ARMORY_EQUIPMENT_NOTICE, ZO_SELECTED_TEXT:Colorize(armoryBuildList), #armoryBuildListNames)
        local researchText = zo_strformat(SI_SMITHING_RESEARCH_DIALOG_CONSUME, self.formattedTime)
        self.listDialog:SetBelowText(string.format("|t32:32:%s|t\n%s\n\n%s", ZO_IN_ARMORY_BUILD_ICON, armoryBuildText, researchText))
    else
        self.listDialog:SetBelowText(zo_strformat(SI_SMITHING_RESEARCH_DIALOG_CONSUME, self.formattedTime))
    end
end
function ZO_SmithingResearchSelect:SetupDialog(craftingType, researchLineIndex, traitIndex)
    self.listDialog = ZO_InventorySlot_GetItemListDialog()
    local _, _, _, timeRequiredForNextResearchSecs = GetSmithingResearchLineInfo(craftingType, researchLineIndex)
    self.formattedTime = ZO_FormatTime(timeRequiredForNextResearchSecs, TIME_FORMAT_STYLE_COLONS, TIME_FORMAT_PRECISION_TWELVE_HOUR)
    self.listDialog:SetAboveText(GetString(SI_SMITHING_RESEARCH_DIALOG_SELECT))
    self.listDialog:SetBelowText(zo_strformat(SI_SMITHING_RESEARCH_DIALOG_CONSUME, self.formattedTime))
    self.listDialog:SetEmptyListText("")
    self.listDialog:ClearList()
    local function IsResearchableItem(bagId, slotIndex)
        return ZO_SharedSmithingResearch.IsResearchableItem(bagId, slotIndex, craftingType, researchLineIndex, traitIndex)
    end
    local virtualInventoryList = PLAYER_INVENTORY:GenerateListOfVirtualStackedItems(INVENTORY_BACKPACK, IsResearchableItem)
    if SMITHING:GetResearchPanel():IsIncludeBankedItemsChecked() then
        PLAYER_INVENTORY:GenerateListOfVirtualStackedItems(INVENTORY_BANK, IsResearchableItem, virtualInventoryList)
    end
    for itemId, itemInfo in pairs(virtualInventoryList) do
        itemInfo.name = zo_strformat(SI_TOOLTIP_ITEM_NAME, GetItemName(itemInfo.bag, itemInfo.index))
        self.listDialog:AddListItem(itemInfo)
    end
    self.listDialog:CommitList(SortComparator)
    self.listDialog:AddCustomControl(self.control, LIST_DIALOG_CUSTOM_CONTROL_LOCATION_BOTTOM)
    self.listDialog:SetOnSelectedCallback(function(selectedData) self:OnItemSelected(selectedData.bag, selectedData.index) end)
end
--Global XML
    self.nameLabel = self:GetNamedChild("Name")
    self.statusLabel = self:GetNamedChild("Status")
    self.lockIcon = self:GetNamedChild("LockIcon")
    self.timerIcon = self:GetNamedChild("TimerIcon")
end
    if self.owner:IsResearchable() then
        self.owner:Research()
    end
end
    if button == MOUSE_BUTTON_INDEX_RIGHT then
        if self.owner:IsResearchable() then
            ClearMenu()
            AddMenuItem(GetString(SI_ITEM_ACTION_RESEARCH), function() self.owner:Research(self) end)
            ShowMenu(self)
        elseif self.owner:IsResearching() then
            ClearMenu()
            AddMenuItem(GetString(SI_CRAFTING_CANCEL_RESEARCH), function() self.owner:CancelResearch() end)
            ShowMenu(self)
        end
    end
end
    if not self.fadeAnimation then
        self.fadeAnimation = ANIMATION_MANAGER:CreateTimelineFromVirtual("ShowOnMouseOverLabelAnimation", self:GetNamedChild("Highlight"))
        self.scaleAnimation = ANIMATION_MANAGER:CreateTimelineFromVirtual("IconSlotMouseOverAnimation", self.icon)
    end
    self.fadeAnimation:PlayForward()
    self.scaleAnimation:PlayForward()
end
    if self.fadeAnimation then
        self.fadeAnimation:PlayBackward()
        self.scaleAnimation:PlayBackward()
    end
                
end
    SMITHING_RESEARCH_SELECT = ZO_SmithingResearchSelect:New(control)
end