ESO Lua File v100010

ingame/guild/guildheraldry.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
local STYLE_FRAME_INDEX = 3
ZO_GuildHeraldryManager = ZO_GuildHeraldryManager_Shared:Subclass()
function ZO_GuildHeraldryManager:New(...)
    return ZO_GuildHeraldryManager_Shared.New(self, ...)
end
function ZO_GuildHeraldryManager:Initialize(control)
    ZO_GuildHeraldryManager_Shared.Initialize(self, control, CURRENCY_OPTIONS)
    self.costControl = self.control:GetNamedChild("Cost")
    self.sharedColorSelectedHighlight = self.control:GetNamedChild("SharedColorHighlight")
    self.sharedStyleSelectedHighlight = self.control:GetNamedChild("SharedStyleHighlight")
    self.sharedStyleSelectedHighlight.animation = ANIMATION_MANAGER:CreateTimelineFromVirtual("ShowOnMouseOverLabelAnimation", self.sharedStyleSelectedHighlight)
    self.categoryList = self.control:GetNamedChild("Categories")
    self.categoryListScrollChild = self.categoryList:GetNamedChild("ScrollChild")
    self.panelNameLabel = self.control:GetNamedChild("PanelName")
    self.colorPane = self.control:GetNamedChild("ColorPane")
    self.colorPaneScrollChild = self.colorPane:GetNamedChild("ScrollChild")
    self.categoriesHeader = self.control:GetNamedChild("CategoriesHeader")
    self:InitializeSwatchPool("ZO_GuildHeraldry_DyeingSwatch", self.colorPaneScrollChild)
    self:InitializeStylePool("ZO_GuildHeraldry_Style")
    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()
        end
    end)
    self.control:RegisterForEvent(EVENT_HERALDRY_CUSTOMIZATION_START, function(eventCode)
        if not IsInGamepadPreferredMode() 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)
end
function ZO_GuildHeraldryManager:InitializeHeaderPool()
    self.colorHeaderPool = ZO_ControlPool:New("ZO_DyeingHeader", self.colorPaneScrollChild)
end
function ZO_GuildHeraldryManager:InitializeKeybindStripDescriptors()
    self.keybindStripDescriptor = 
    {
        alignment = KEYBIND_STRIP_ALIGN_CENTER,
        -- Apply Changes
        {
            name = function()
                local pendingCost = GetPendingHeraldryCost()
                local heraldryFunds = GetHeraldryGuildBankedMoney()
                if IsCreatingHeraldryForFirstTime() then
                    if heraldryFunds and pendingCost <= heraldryFunds then
                        return zo_strformat(SI_GUILD_HERALDRY_PURCHASE_HERALDRY, pendingCost)
                    else
                        return zo_strformat(SI_GUILD_HERALDRY_PURCHASE_HERALDRY_NOT_ENOUGH, pendingCost)
                    end
                else
                    if heraldryFunds and pendingCost <= heraldryFunds then
                        return zo_strformat(SI_GUILD_HERALDRY_APPLY_CHANGES, pendingCost)
                    else
                        return zo_strformat(SI_GUILD_HERALDRY_APPLY_CHANGES_NOT_ENOUGH, pendingCost)
                    end
                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()
                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:UpdateKeybindGroups()
    KEYBIND_STRIP:UpdateKeybindButtonGroup(self.keybindStripDescriptor)
end
local CURRENCY_OPTIONS =
{
    showTooltips = true,
    font = "ZoFontGameBold",
    iconSide = RIGHT,
}
function ZO_GuildHeraldryManager: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)
    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: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, nil, SOUNDS.GUILD_HERALDRY_CATEGORY_SELECTED)
    local function LayoutStyles()
        local function AnchorHeraldryStyle(currentAnchor, style, index)
            local STRIDE = 6
            local STYLE_SIZE = 64
            local PADDING = 18
            local INITIAL_OFFSET_X = 40
            local INITIAL_OFFSET_Y = 40
            ZO_Anchor_BoxLayout(currentAnchor, style, index - 1, STRIDE, PADDING, PADDING, STYLE_SIZE, STYLE_SIZE, INITIAL_OFFSET_X, INITIAL_OFFSET_Y)
        end
    end
    local function LayoutColors()
        self:LayoutColors()
    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,
        styleHeaderName = GetString(SI_GUILD_HERALDRY_PATTERN_HEADER),
    }
    self.navigationTree:AddNode("ZO_GuildHeraldry_ChildEntry", bgStyleData, parent, SOUNDS.GUILD_HERALDRY_SUBCATEGORY_SELECTED)
    local bgPrimaryColorData = {
        name = GetString(SI_GUILD_HERALDRY_PRIMARY_COLOR),
        mode = ZO_HERALDRY_COLOR_MODE,
        cost = bgPrimaryColorCost,
        layout = LayoutColors,
        setSelectedColor = function(index) self.selectedBackgroundPrimaryColor = index end,
        getSelectedColor = function() return self.selectedBackgroundPrimaryColor end,
    }
    self.navigationTree:AddNode("ZO_GuildHeraldry_ChildEntry", bgPrimaryColorData, parent, SOUNDS.GUILD_HERALDRY_SUBCATEGORY_SELECTED)
    local bgSecondaryColorData = {
        name = GetString(SI_GUILD_HERALDRY_SECONDARY_COLOR),
        mode = ZO_HERALDRY_COLOR_MODE,
        cost = bgSecondaryColorCost,
        layout = LayoutColors,
        setSelectedColor = function(index) self.selectedBackgroundSecondaryColor = index end,
        getSelectedColor = function() return self.selectedBackgroundSecondaryColor end,
    }
    self.navigationTree:AddNode("ZO_GuildHeraldry_ChildEntry", bgSecondaryColorData, parent, SOUNDS.GUILD_HERALDRY_SUBCATEGORY_SELECTED)
    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, nil, SOUNDS.GUILD_HERALDRY_CATEGORY_SELECTED)
    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,
        styleHeaderName = GetString(SI_GUILD_HERALDRY_DESIGN_HEADER),
    }
    self.navigationTree:AddNode("ZO_GuildHeraldry_ChildEntry", crestStyleData, parent, SOUNDS.GUILD_HERALDRY_SUBCATEGORY_SELECTED)
     local crestColorData = {
        name = GetString(SI_GUILD_HERALDRY_COLOR),
        mode = ZO_HERALDRY_COLOR_MODE,
        cost = crestColorCost,
        layout = LayoutColors,
        setSelectedColor = function(index) self.selectedCrestColor = index end,
        getSelectedColor = function() return self.selectedCrestColor end,
    }
    self.navigationTree:AddNode("ZO_GuildHeraldry_ChildEntry", crestColorData, parent, SOUNDS.GUILD_HERALDRY_SUBCATEGORY_SELECTED)
    self.navigationTree:Commit()
end
function ZO_GuildHeraldryManager:SwitchMode(mode)
    if mode == ZO_HERALDRY_COLOR_MODE then
        self.bgStyleCatListControl:SetHidden(true)
        self.crestStyleCatListControl:SetHidden(true)
        self.categoriesHeader:SetHidden(true)
        self.stylePane:SetHidden(true)
        self.colorPane:SetHidden(false)
    elseif mode == ZO_HERALDRY_BG_STYLE_MODE then
        self.bgStyleCatListControl:SetHidden(false)
        self.crestStyleCatListControl:SetHidden(true)
        self.categoriesHeader:SetHidden(false)
        self.stylePane:SetHidden(false)
        self.colorPane:SetHidden(true)
    elseif mode == ZO_HERALDRY_CREST_STYLE_MODE then
        self.bgStyleCatListControl:SetHidden(true)
        self.crestStyleCatListControl:SetHidden(false)
        self.categoriesHeader:SetHidden(false)
        self.stylePane:SetHidden(false)
        self.colorPane:SetHidden(true)
    else
        self.bgStyleCatListControl:SetHidden(true)
        self.crestStyleCatListControl:SetHidden(true)
        self.categoriesHeader:SetHidden(true)
        self.stylePane:SetHidden(true)
        self.colorPane:SetHidden(true)
    end
    self.currentMode = mode
end
function ZO_GuildHeraldryManager:SetSelectedHeraldryIndices()
    ZO_GuildHeraldryManager_Shared.SetSelectedHeraldryIndices(self)
    if self.activeData then
        self:OnCategorySelected(self.activeData)
    end
end
function ZO_GuildHeraldryManager:PopulateColors(activeSwatches, sortedCategories)
    local nextHeaderOffsetY = 0
    local lastHeader
    local selectedColor = self.activeData and self.activeData.getSelectedColor() or nil
    for i, category in ipairs(sortedCategories) do
        local swatches = activeSwatches[category]
        local header = self.colorHeaderPool:AcquireObject()
        header:SetAnchor(TOPLEFT, lastHeader or self.colorPaneScrollChild, TOPLEFT, 0, nextHeaderOffsetY)
        header:SetText(GetString("SI_DYEHUECATEGORY", category))
        local currentAnchor = ZO_Anchor:New(CENTER, header, BOTTOMLEFT)
        table.sort(swatches, ZO_Dyeing_DyeSortComparator)
        local maxHeaderOffsetY = 0
        for j, swatch in ipairs(swatches) do
            local offsetY = AnchorDyeSwatch(currentAnchor, swatch, j)
            maxHeaderOffsetY = zo_max(maxHeaderOffsetY, offsetY)
            if swatch.colorIndex == selectedColor then
                self:SelectColor(swatch.colorIndex, ZO_HERALDRY_SKIP_ANIM)
            end
        end
        nextHeaderOffsetY = GetNextDyeHeaderOffsetY(maxHeaderOffsetY, header)
        lastHeader = header
    end
end
--[[
Dialog functions.
--]]
function ZO_GuildHeraldryManager:SetupHeraldryDialog(control)
    local pendingCost = GetPendingHeraldryCost()
    local heraldryFunds = GetHeraldryGuildBankedMoney() or 0
    local descriptionLabel = control:GetNamedChild("Description")
    descriptionLabel:SetText(GetString(control.info.mainText.text))
    local guildBalanceControl = control:GetNamedChild("GuildBalance")
    ZO_CurrencyControl_SetSimpleCurrency(guildBalanceControl, CURRENCY_TYPE_MONEY, heraldryFunds, CURRENCY_OPTIONS)
    local costControl = control:GetNamedChild("Cost")
    ZO_CurrencyControl_SetSimpleCurrency(costControl, CURRENCY_TYPE_MONEY, pendingCost, CURRENCY_OPTIONS)
end
function ZO_GuildHeraldryManager:ConfirmHeraldryPurchase()
    ZO_GuildHeraldryManager_Shared.ConfirmHeraldryPurchase(self, ZO_GuildHeraldryConfirmationDialog, ZO_Dialogs_ShowDialog)
end
function ZO_GuildHeraldryManager:ConfirmHeraldryApplyChanges()
    ZO_GuildHeraldryManager_Shared.ConfirmHeraldryApplyChanges(self, ZO_GuildHeraldryConfirmationDialog, ZO_Dialogs_ShowDialog)
end
--[[
Global XML.
--]]
    GUILD_HERALDRY = ZO_GuildHeraldryManager:New(control)
end
do
    local TEXTURE_WIDTH = 256
    local TEXTURE_HEIGHT = 256
    local FRAME_WIDTH = 64
    local FRAME_HEIGHT = 64
    local FRAME_SLICE_WIDTH = 64
    local FRAME_SLICE_HEIGHT = 64
    local FRAME_PADDING_X = (FRAME_SLICE_WIDTH - FRAME_WIDTH)
    local FRAME_PADDING_Y = (FRAME_SLICE_HEIGHT - FRAME_HEIGHT)
    local FRAME_WIDTH_TEX_COORD = FRAME_WIDTH / TEXTURE_WIDTH
    local FRAME_HEIGHT_TEX_COORD = FRAME_HEIGHT / TEXTURE_HEIGHT
    local FRAME_PADDING_X_TEX_COORD = FRAME_PADDING_X / TEXTURE_WIDTH
    local FRAME_PADDING_Y_TEX_COORD = FRAME_PADDING_Y / TEXTURE_HEIGHT
    local FRAME_START_TEXCOORD_X = 0.0 + FRAME_PADDING_X_TEX_COORD * .5
    local FRAME_START_TEXCOORD_Y = 0.0 + FRAME_PADDING_Y_TEX_COORD * .5
    local FRAME_NUM_COLS = 4
    local FRAME_NUM_ROWS = 2
    local function PickRandomFrame(self)
        local col = zo_random(FRAME_NUM_COLS)
        local row = zo_random(FRAME_NUM_ROWS)
        local left = FRAME_START_TEXCOORD_X + (col - 1) * (FRAME_WIDTH_TEX_COORD + FRAME_PADDING_X_TEX_COORD)
        local right = left + FRAME_WIDTH_TEX_COORD 
        local top = FRAME_START_TEXCOORD_Y + (row - 1) * (FRAME_HEIGHT_TEX_COORD + FRAME_PADDING_Y_TEX_COORD)
        local bottom = top + FRAME_HEIGHT_TEX_COORD
        self:SetTextureCoords(STYLE_FRAME_INDEX, left, right, top, bottom)
    end
        PickRandomFrame(self)
    end
end