Back to Home

ESO Lua File v101044

ingame/guild/keyboard/guildheraldry_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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
-----------------------------------
-- GuildHeraldryManager Keyboard
-----------------------------------
ZO_GUILD_HERALDRY_STYLE_ICON_SIZE = 64
ZO_GUILD_HERALDRY_STYLE_OFFSET = 16
ZO_GUILD_HERALDRY_DYE_SWATCH_DIMENSIONS = 30
ZO_GUILD_HERALDRY_HEADER_TEMPLATE_KEYBOARD_HEIGHT = 35
ZO_GuildHeraldryManager_Keyboard = ZO_GuildHeraldryManager_Shared:Subclass()
function ZO_GuildHeraldryManager_Keyboard:New(...)
    return ZO_GuildHeraldryManager_Shared.New(self, ...)
end
function ZO_GuildHeraldryManager_Keyboard:Initialize(control)
    local function StyleGridEntrySetup(control, data, list)
        local iconContainer = control:GetNamedChild("IconContainer")
        local checkButton = iconContainer:GetNamedChild("Frame")
        local function OnClick()
            self:SelectStyle(data.index)
        end
        iconContainer:GetNamedChild("Icon"):SetTexture(data.icon)
        ZO_CheckButton_SetToggleFunction(checkButton, OnClick)
    end
    local function DyeSwatchGridEntrySetup(control, data, list)
        local function OnClicked(swatchControl, button, upInside)
            if upInside then
                if button == MOUSE_BUTTON_INDEX_LEFT then
                    self:SelectColor(data.colorIndex)
                end
            end
        end
        control:SetHandler("OnMouseUp", OnClicked)
        control:SetColor(ZO_DYEING_SWATCH_INDEX, data.r, data.g, data.b)
        control:SetSurfaceHidden(ZO_DYEING_LOCK_INDEX, data.known)
        control:SetSurfaceHidden(ZO_DYEING_NEW_INDEX, not data:IsNew())
        data:SetControl(control)
        data.selected = data.checked
        data:UpdateSelectedState()
    end
    local function GeneralGridEntryReset(control)
    end
    local templateData =
    {
        gridListClass = ZO_GridScrollList_Keyboard,
        styleEntryTemplate = "ZO_GuildHeraldry_Style",
        styleEntryWidth = ZO_GAMEPAD_DEFAULT_SELECTION_ICON_SIZE,
        styleEntryHeight = ZO_GAMEPAD_DEFAULT_SELECTION_ICON_SIZE,
        styleGridPadding = ZO_GUILD_HERALDRY_STYLE_OFFSET,
        styleEntrySetup = StyleGridEntrySetup,
        styleHasGridHeader = true,
        colorEntryTemplate = "ZO_GuildHeraldry_DyeingSwatch",
        colorEntryWidth = ZO_GUILD_HERALDRY_DYE_SWATCH_DIMENSIONS,
        colorEntryHeight = ZO_GUILD_HERALDRY_DYE_SWATCH_DIMENSIONS,
        headerTemplate = "ZO_GuildHeraldry_Style_Keyboard_Header_Template",
        headerHeight = ZO_GUILD_HERALDRY_HEADER_TEMPLATE_KEYBOARD_HEIGHT,
    }
    ZO_GuildHeraldryManager_Shared.Initialize(self, control, CURRENCY_OPTIONS, templateData)
    self.costControl = self.control:GetNamedChild("Cost")
    self.costLabel = self.control:GetNamedChild("CostLabel")
    self.categoryList = self.control:GetNamedChild("Categories")
    self.categoryListScrollChild = self.categoryList:GetNamedChild("ScrollChild")
    self.panelNameLabel = self.control:GetNamedChild("PanelName")
    self:InitializeStyleCategoryLists(ZO_HorizontalScrollList, "ZO_GuildHeraldry_StyleCategory")
    GUILD_HERALDRY_SCENE = ZO_Scene:New("guildHeraldry", SCENE_MANAGER)
    GUILD_HERALDRY_SCENE:RegisterCallback("StateChange", function(oldState, newState)
        if newState == SCENE_SHOWING then
            StartHeraldryCustomization(self.guildId)
        elseif newState == SCENE_HIDDEN then
            KEYBIND_STRIP:RemoveKeybindButtonGroup(self.keybindStripDescriptor)
            EndHeraldryCustomization()
            self:SetPendingExit(false)
        end
    end)
    GUILD_HERALDRY_SCENE:SetHideSceneConfirmationCallback(function(...) self:OnConfirmHideScene(...) end)
    self.control:RegisterForEvent(EVENT_HERALDRY_CUSTOMIZATION_START, function(eventCode)
        if not IsInGamepadPreferredMode() and GUILD_HERALDRY_SCENE:IsShowing() then
            self.initialized = true
            self:SetSelectedHeraldryIndices()
            KEYBIND_STRIP:AddKeybindButtonGroup(self.keybindStripDescriptor)
        end
    end)
    self.control:RegisterForEvent(EVENT_HERALDRY_CUSTOMIZATION_END, function(eventCode)
        if not IsInGamepadPreferredMode() then
            self.initialized = false
        end
    end)
    self.control:RegisterForEvent(EVENT_HERALDRY_SAVED, function(eventCode)
        if not IsInGamepadPreferredMode() then
            self:SetSelectedHeraldryIndices()
            self:UpdateKeybindGroups()
            PlaySound(SOUNDS.GUILD_HERALDRY_APPLIED)
        end
    end)
    self.control:RegisterForEvent(EVENT_HERALDRY_FUNDS_UPDATED, function(eventCode)
        if not IsInGamepadPreferredMode() then
            self:UpdateKeybindGroups()
        end
    end)
    local function OnGuildSelected()
        self:UpdateKeybindGroups()
    end
    CALLBACK_MANAGER:RegisterCallback("OnGuildSelected", OnGuildSelected)
end
function ZO_GuildHeraldryManager_Keyboard:GetPurchaseDialogName()
    return "CONFIRM_HERALDRY_PURCHASE"
end
function ZO_GuildHeraldryManager_Keyboard:GetApplyChangesDialogName()
    return "CONFIRM_HERALDRY_APPLY_CHANGES"
end
function ZO_GuildHeraldryManager_Keyboard:ChangeSelectedGuild(changeGuildCallback, changeGuildParams)
    self.changeGuildParams = changeGuildParams
end
function ZO_GuildHeraldryManager_Keyboard:SetEntryDataSelected(entryData, selected)
    if entryData.control then
        entryData.control.object:SetSelected(selected)
    end
end
function ZO_GuildHeraldryManager_Keyboard:ConfirmExit()
    if self.changeGuildCallback then
        local callback = self.changeGuildCallback
        local params = self.changeGuildParams
        self.changeGuildCallback = nil
        self.changeGuildParams = nil
        callback(params)
    else
        GUILD_HERALDRY_SCENE:AcceptHideScene()
    end
end
function ZO_GuildHeraldryManager_Keyboard:CancelExit()
    GUILD_HERALDRY_SCENE:RejectHideScene()
    self:SetPendingExit(false)
end
function ZO_GuildHeraldryManager_Keyboard:NoChoiceExitCallback()
    GUILD_HERALDRY_SCENE:RejectHideScene()
    self:SetPendingExit(false)
end
function ZO_GuildHeraldryManager_Keyboard:InitializeKeybindStripDescriptors()
    self.keybindStripDescriptor = 
    {
        alignment = KEYBIND_STRIP_ALIGN_CENTER,
        -- Apply Changes
        {
            name = function()
                local pendingCost = GetPendingHeraldryCost()
                local heraldryFunds = GetHeraldryGuildBankedMoney()
                local format
                if heraldryFunds and pendingCost <= heraldryFunds then
                    format = ZO_CURRENCY_FORMAT_WHITE_AMOUNT_ICON
                else
                    format = ZO_CURRENCY_FORMAT_ERROR_AMOUNT_ICON
                end
                if IsCreatingHeraldryForFirstTime() then
                    return zo_strformat(SI_GUILD_HERALDRY_PURCHASE_HERALDRY, ZO_Currency_FormatKeyboard(CURT_MONEY, pendingCost, format))
                else
                    return zo_strformat(SI_GUILD_HERALDRY_APPLY_CHANGES, ZO_Currency_FormatKeyboard(CURT_MONEY, pendingCost, format))
                end
            end,
            keybind = "UI_SHORTCUT_SECONDARY",
            callback = function()
                local pendingCost = GetPendingHeraldryCost()
                local heraldryFunds = GetHeraldryGuildBankedMoney()
                if heraldryFunds and pendingCost <= heraldryFunds then
                    if IsCreatingHeraldryForFirstTime() then
                        self:ConfirmHeraldryPurchase()
                    else
                        self:ConfirmHeraldryApplyChanges()
                    end
                else
                    ZO_AlertNoSuppression(UI_ALERT_CATEGORY_ALERT, nil, SI_GUILD_HERALDRY_ERROR_NOT_ENOUGH_GOLD)
                end
            end,
            visible = function()
                return HasPendingHeraldryChanges()
            end,
            enabled = function()
                local pendingCost = GetPendingHeraldryCost()
                local heraldryFunds = GetHeraldryGuildBankedMoney()
                return heraldryFunds and (pendingCost <= heraldryFunds)
            end,
        },
        -- Undo Changes
        {
            name = GetString(SI_GUILD_HERALDRY_UNDO_CHANGES),
            keybind = "UI_SHORTCUT_NEGATIVE",
            callback = function()
                RevertToSavedHeraldry(false)
                self:SetSelectedHeraldryIndices()
                KEYBIND_STRIP:UpdateKeybindButtonGroup(self.keybindStripDescriptor)
                PlaySound(SOUNDS.GUILD_HERALDRY_UNDO_CHANGES)
            end,
            visible = function()
                return HasPendingHeraldryChanges() and not IsCreatingHeraldryForFirstTime()
            end,
        },
    }
end
function ZO_GuildHeraldryManager_Keyboard:UpdateKeybindGroups()
    KEYBIND_STRIP:UpdateKeybindButtonGroup(self.keybindStripDescriptor)
end
local CURRENCY_OPTIONS =
{
    showTooltips = true,
    font = "ZoFontGameBold",
    iconSide = RIGHT,
}
function ZO_GuildHeraldryManager_Keyboard:InitializeNavigationTree()
    self.navigationTree = ZO_Tree:New(self.categoryListScrollChild, 60, -10, 374)
    local function BaseTreeHeaderIconSetup(control, data, open)
        control.text:SetDimensionConstraints(0, 0, 300, 0)
        local iconTexture = (open and data.pressedIcon or data.normalIcon) or "EsoUI/Art/Icons/icon_missing.dds"
        local mouseoverTexture = data.mouseoverIcon or "EsoUI/Art/Icons/icon_missing.dds"
        
        control.icon:SetTexture(iconTexture)
        control.iconHighlight:SetTexture(mouseoverTexture)
        ZO_IconHeader_Setup(control, open)
    end
    local function BaseTreeHeaderSetup(node, control, data, open)
        control.text:SetModifyTextType(MODIFY_TEXT_TYPE_UPPERCASE)
        control.text:SetText(data.name)
        BaseTreeHeaderIconSetup(control, data, open)
    end
    local function TreeHeaderSetup(node, control, data, open, userRequested)
        BaseTreeHeaderSetup(node, control, data, open)
        if open and userRequested then
            self.navigationTree:SelectFirstChild(node)
        end
    end
    local function TreeChildSetup(node, control, data, open)
        control:SetText(data.name)
    end
    local function TreeChildOnSelected(control, data, selected, reselectingDuringRebuild)
        control:SetSelected(selected)
        if selected and not reselectingDuringRebuild then
            self:OnCategorySelected(data)
        end
    end
    local function TreeChildlessHeaderOnSelected(control, data, selected, reselectingDuringRebuild)
        TreeChildOnSelected(control, data, selected, reselectingDuringRebuild)
        BaseTreeHeaderIconSetup(control, data, selected)
    end
    local function TreeChildEquality(left, right)
        return left.name == right.name
    end
    self.navigationTree:AddTemplate("ZO_IconHeader", TreeHeaderSetup, nil, nil, nil, 0)
    self.navigationTree:AddTemplate("ZO_GuildHeraldry_ChildlessHeader", BaseTreeHeaderSetup, TreeChildlessHeaderOnSelected)
    self.navigationTree:AddTemplate("ZO_GuildHeraldry_ChildEntry", TreeChildSetup, TreeChildOnSelected, TreeChildEquality)
    self.navigationTree:SetExclusive(true)
    self.navigationTree:SetOpenAnimation("ZO_TreeOpenAnimation")
end
function ZO_GuildHeraldryManager_Keyboard:InitializeCategories()
    local bgMenuData =
    {
        name = GetString(SI_GUILD_HERALDRY_BACKGROUND),
        normalIcon = "EsoUI/Art/Guild/guildHeraldry_indexIcon_background_up.dds",
        pressedIcon = "EsoUI/Art/Guild/guildHeraldry_indexIcon_background_down.dds",
        mouseoverIcon = "EsoUI/Art/Guild/guildHeraldry_indexIcon_background_over.dds",
    }
    local parent = self.navigationTree:AddNode("ZO_IconHeader", bgMenuData)
    local function LayoutStyles()
        self:BuildStyleGridList()
    end
    local function LayoutColors()
        self:BuildColorGridList()
    end
    local bgStyleCost, bgPrimaryColorCost, bgSecondaryColorCost, crestStyleCost, crestColorCost = GetHeraldryCustomizationCosts()
    local bgStyleData =
    {
        name = GetString(SI_GUILD_HERALDRY_STYLE),
        mode = ZO_HERALDRY_BG_STYLE_MODE,
        cost = bgStyleCost,
        layout = LayoutStyles,
        getNum = function() return GetNumHeraldryBackgroundStyles(self.viewBackgroundCategory) end,
        getInfo = function(index) return GetHeraldryBackgroundStyleInfo(self.viewBackgroundCategory, index) end,
        setSelectedCategory = function(index) self.selectedBackgroundCategory = index end,
        getSelectedCategory = function() return self.selectedBackgroundCategory end,
        setViewCategory = function(index) self.viewBackgroundCategory = index end,
        getViewCategory = function() return self.viewBackgroundCategory end,
        resetToSelectedCategory = function() self.bgStyleCatList:SetSelectedDataIndex(self.selectedBackgroundCategory) end,
        setSelectedStyle = function(index) self.selectedBackgroundStyle = index end,
        getSelectedStyle = function() return self.selectedBackgroundStyle end,
    }
    self.navigationTree:AddNode("ZO_GuildHeraldry_ChildEntry", bgStyleData, parent)
    local bgPrimaryColorData =
    {
        name = GetString(SI_GUILD_HERALDRY_PRIMARY_COLOR),
        mode = ZO_HERALDRY_COLOR_MODE,
        cost = bgPrimaryColorCost,
        layout = LayoutColors,
        setSelectedColorIndex = function(index) self.selectedBackgroundPrimaryColor = index end,
        getSelectedColorIndex = function() return self.selectedBackgroundPrimaryColor end,
    }
    self.navigationTree:AddNode("ZO_GuildHeraldry_ChildEntry", bgPrimaryColorData, parent)
    local bgSecondaryColorData =
    {
        name = GetString(SI_GUILD_HERALDRY_SECONDARY_COLOR),
        mode = ZO_HERALDRY_COLOR_MODE,
        cost = bgSecondaryColorCost,
        layout = LayoutColors,
        setSelectedColorIndex = function(index) self.selectedBackgroundSecondaryColor = index end,
        getSelectedColorIndex = function() return self.selectedBackgroundSecondaryColor end,
    }
    self.navigationTree:AddNode("ZO_GuildHeraldry_ChildEntry", bgSecondaryColorData, parent)
    local crestMenuData =
    {
        name = GetString(SI_GUILD_HERALDRY_CREST),
        normalIcon = "EsoUI/Art/Guild/guildHeraldry_indexIcon_crest_up.dds",
        pressedIcon = "EsoUI/Art/Guild/guildHeraldry_indexIcon_crest_down.dds",
        mouseoverIcon = "EsoUI/Art/Guild/guildHeraldry_indexIcon_crest_over.dds",
    }
    parent = self.navigationTree:AddNode("ZO_IconHeader", crestMenuData)
    local crestStyleData =
    {
        name = GetString(SI_GUILD_HERALDRY_STYLE),
        mode = ZO_HERALDRY_CREST_STYLE_MODE,
        cost = crestStyleCost,
        layout = LayoutStyles,
        getNum = function() return GetNumHeraldryCrestStyles(self.viewCrestCategory) end,
        getInfo = function(index) return GetHeraldryCrestStyleInfo(self.viewCrestCategory, index) end,
        setSelectedCategory = function(index) self.selectedCrestCategory = index end,
        getSelectedCategory = function() return self.selectedCrestCategory end,
        setViewCategory = function(index) self.viewCrestCategory = index end,
        getViewCategory = function() return self.viewCrestCategory end,
        resetToSelectedCategory = function() self.crestStyleCatList:SetSelectedDataIndex(self.selectedCrestCategory) end,
        setSelectedStyle = function(index) self.selectedCrestStyle = index end,
        getSelectedStyle = function() return self.selectedCrestStyle end,
    }
    self.navigationTree:AddNode("ZO_GuildHeraldry_ChildEntry", crestStyleData, parent)
     local crestColorData =
     {
        name = GetString(SI_GUILD_HERALDRY_COLOR),
        mode = ZO_HERALDRY_COLOR_MODE,
        cost = crestColorCost,
        layout = LayoutColors,
        setSelectedColorIndex = function(index) self.selectedCrestColor = index end,
        getSelectedColorIndex = function() return self.selectedCrestColor end,
    }
    self.navigationTree:AddNode("ZO_GuildHeraldry_ChildEntry", crestColorData, parent)
    self.navigationTree:Commit()
end
function ZO_GuildHeraldryManager_Keyboard:SetSelectedHeraldryIndices()
    ZO_GuildHeraldryManager_Shared.SetSelectedHeraldryIndices(self)
    if self.activeData then
        self:OnCategorySelected(self.activeData)
    end
end
function ZO_GuildHeraldryManager_Keyboard:OnCategorySelected(data)
    ZO_GuildHeraldryManager_Shared.OnCategorySelected(self, data)
    if self.initialized then
        if data.cost then
            self.costControl:SetHidden(false)
            self.costLabel:SetHidden(false)
            ZO_CurrencyControl_SetSimpleCurrency(self.costControl, CURT_MONEY,  data.cost)
        else
            self.costControl:SetHidden(true)
            self.costLabel:SetHidden(true)
        end
    end
end
--[[
Dialog functions.
--]]
function ZO_GuildHeraldryManager_Keyboard:SetupHeraldryDialog(control)
    local pendingCost = GetPendingHeraldryCost()
    local heraldryFunds = GetHeraldryGuildBankedMoney() or 0
    local descriptionLabel = control:GetNamedChild("Description")
    local textInfo = type(control.info.mainText.text) == "function" and control.info.mainText.text() or control.info.mainText.text
    descriptionLabel:SetText(GetString(textInfo))
    local guildBalanceControl = control:GetNamedChild("GuildBalance")
    ZO_CurrencyControl_SetSimpleCurrency(guildBalanceControl, CURT_MONEY, heraldryFunds, CURRENCY_OPTIONS)
    local costControl = control:GetNamedChild("Cost")
    ZO_CurrencyControl_SetSimpleCurrency(costControl, CURT_MONEY, pendingCost, CURRENCY_OPTIONS)
end
function ZO_GuildHeraldryManager_Keyboard:ConfirmHeraldryPurchase()
    ZO_GuildHeraldryManager_Shared.ConfirmHeraldryPurchase(self, ZO_GuildHeraldryConfirmationDialog, ZO_Dialogs_ShowDialog)
end
function ZO_GuildHeraldryManager_Keyboard:ConfirmHeraldryApplyChanges()
    ZO_GuildHeraldryManager_Shared.ConfirmHeraldryApplyChanges(self, ZO_GuildHeraldryConfirmationDialog, ZO_Dialogs_ShowDialog)
end
--[[
Global XML.
--]]
    GUILD_HERALDRY = ZO_GuildHeraldryManager_Keyboard:New(control)
    SYSTEMS:RegisterKeyboardObject("guild_heraldry", GUILD_HERALDRY)
end
    if ZO_CheckButton_IsEnabled(self:GetNamedChild("IconContainerFrame")) then
        self:GetNamedChild("Highlight"):SetHidden(false)
    end
end
    self:GetNamedChild("Highlight"):SetHidden(true)
end