Back to Home

ESO Lua File v101041

ingame/guildhistory/keyboard/guildhistory_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
ZO_GUILD_HISTORY_KEYBOARD_CATEGORY_TREE_WIDTH = 270
ZO_GUILD_HISTORY_KEYBOARD_ROW_HEIGHT = 60
ZO_GuildHistory_Keyboard = ZO_GuildHistory_Shared:MultiSubclass(ZO_SortFilterList)
function ZO_GuildHistory_Keyboard:Initialize(control)
    ZO_GuildHistory_Shared.Initialize(self, control)
    GUILD_HISTORY_KEYBOARD_SCENE = ZO_Scene:New("guildHistory", SCENE_MANAGER)
    GUILD_HISTORY_KEYBOARD_FRAGMENT = self:GetFragment()
end
function ZO_GuildHistory_Keyboard:OnDeferredInitialize()
    ZO_SortFilterList.Initialize(self, self.control)
    ZO_GuildHistory_Shared.OnDeferredInitialize(self)
end
function ZO_GuildHistory_Keyboard:InitializeSortFilterList(...)
    ZO_SortFilterList.InitializeSortFilterList(self, ...)
    ZO_GuildHistory_Shared.InitializeSortFilterList(self, "ZO_GuildHistoryRow_Keyboard", ZO_GUILD_HISTORY_KEYBOARD_ROW_HEIGHT)
end
function ZO_GuildHistory_Keyboard:InitializeControls()
    ZO_GuildHistory_Shared.InitializeControls(self)
    self.footer.previousButton:SetHandler("OnClicked", function()
        self:ShowPreviousPage()
    end)
    self.footer.nextButton:SetHandler("OnClicked", function()
        self:ShowNextPage()
    end)
end
function ZO_GuildHistory_Keyboard:InitializeCategoryTree()
    local DEFAULT_INDENT = 60
    local DEFAULT_SPACING = -10
    local NO_SELECTION_FUNCTION = nil
    local NO_EQUALITY_FUNCTION = nil
    local DEFAULT_CHILD_INDENT = nil
    local CHILD_SPACING = 0
    local TREE_WIDTH = ZO_GUILD_HISTORY_KEYBOARD_CATEGORY_TREE_WIDTH - ZO_SCROLL_BAR_WIDTH
    local TEXT_LABEL_MAX_WIDTH = TREE_WIDTH - ZO_TREE_ENTRY_ICON_HEADER_TEXT_OFFSET_X
    self.categoryTree = ZO_Tree:New(self.control:GetNamedChild("Categories"), DEFAULT_INDENT, DEFAULT_SPACING, TREE_WIDTH)
    local function BaseTreeHeaderIconSetup(control, data, open)
        local categoryInfo = ZO_GuildHistory_Manager.GetEventCategoryInfo(data.eventCategory)
        control.icon:SetTexture(open and categoryInfo.down or categoryInfo.up)
        control.iconHighlight:SetTexture(categoryInfo.over)
        ZO_IconHeader_Setup(control, open)
    end
    local function BaseTreeHeaderSetup(control, data, open)
        control.text:SetDimensionConstraints(0, 0, TEXT_LABEL_MAX_WIDTH, 0)
        control.text:SetModifyTextType(MODIFY_TEXT_TYPE_UPPERCASE)
        control.text:SetText(GetString("SI_GUILDHISTORYEVENTCATEGORY", data.eventCategory))
        BaseTreeHeaderIconSetup(control, data, open)
    end
    local function TreeEntrySelected(control, data, selected, reselectingDuringRebuild)
        control:SetSelected(selected)
        if selected then
            self:SetSelectedEventCategory(data.eventCategory, data.subcategoryIndex)
        end
    end
    
    local function TreeEntrySelected_Childless(control, data, selected, reselectingDuringRebuild)
        TreeEntrySelected(control, data, selected, reselectingDuringRebuild)
        BaseTreeHeaderIconSetup(control, data, selected)
    end
    -- Childless Category Header
    local function CategoryHeaderSetup_Childless(node, control, data, open)
        BaseTreeHeaderSetup(control, data, open)
    end
    self.categoryTree:AddTemplate("ZO_IconChildlessHeader", CategoryHeaderSetup_Childless, TreeEntrySelected_Childless, NO_EQUALITY_FUNCTION, DEFAULT_CHILD_INDENT, CHILD_SPACING)
    -- Parent Category Header
    local function CategoryHeaderSetup_Parent(node, control, data, open, userRequested)
        BaseTreeHeaderSetup(control, data, open)
        if open and userRequested then
            self.categoryTree:SelectFirstChild(node)
        end
    end
    self.categoryTree:AddTemplate("ZO_IconHeader", CategoryHeaderSetup_Parent, NO_SELECTION_FUNCTION, NO_EQUALITY_FUNCTION, DEFAULT_CHILD_INDENT, CHILD_SPACING)
    --Subcategory Entry
    local function SubcategoryEntrySetup(node, control, data, open)
        control:SetSelected(false)
        control:SetText(data.name)
    end
    self.categoryTree:AddTemplate("ZO_GuildHistorySubcategoryEntry", SubcategoryEntrySetup, TreeEntrySelected)
    --Build Tree
    for eventCategory = GUILD_HISTORY_EVENT_CATEGORY_ITERATION_BEGIN, GUILD_HISTORY_EVENT_CATEGORY_ITERATION_END do
        local categoryInfo = ZO_GuildHistory_Manager.GetEventCategoryInfo(eventCategory)
        if categoryInfo then
            local categoryData = { eventCategory = eventCategory }
            if #categoryInfo.subcategories > 1 then
                local categoryNode = self.categoryTree:AddNode("ZO_IconHeader", categoryData)
                for subcategoryIndex, subcategoryInfo in ipairs(categoryInfo.subcategories) do
                    local name = GetString("SI_GUILDHISTORYEVENTSUBCATEGORY", subcategoryInfo.subcategoryType)
                    local subcategoryData = { name = name, eventCategory = eventCategory, subcategoryIndex = subcategoryIndex }
                    self.categoryTree:AddNode("ZO_GuildHistorySubcategoryEntry", subcategoryData, categoryNode)
                end
            else
                -- Don't show a subcategory when there's only the one
                assert(#categoryInfo.subcategories == 1)
                categoryData.subcategoryIndex = 1
                self.categoryTree:AddNode("ZO_IconChildlessHeader", categoryData)
            end
        end
    end
    self.categoryTree:SetExclusive(true)
    self.categoryTree:SetOpenAnimation("ZO_TreeOpenAnimation")
    self.categoryTree:Commit()
end
function ZO_GuildHistory_Keyboard:InitializeKeybindDescriptors()
    {
        alignment = KEYBIND_STRIP_ALIGN_RIGHT,
        -- Show More
        {
            name = GetString(SI_GUILD_HISTORY_SHOW_MORE),
            keybind = "UI_SHORTCUT_PRIMARY",
            visible = function()
                return self:CanShowMore()
            end,
            callback = function()
                self:TryShowMore()
            end,
        },
    })
end
function ZO_GuildHistory_Keyboard:OnShowing()
    ZO_GuildHistory_Shared.OnShowing(self)
    self:AddKeybinds()
end
function ZO_GuildHistory_Keyboard:SetGuildId(guildId)
    if ZO_GuildHistory_Shared.SetGuildId(self, guildId) then
        self:UpdateKeybinds()
    end
end
function ZO_GuildHistory_Keyboard:ResetToTop()
end
    
do
    local function SetButtonStateEnabled(button, enabled)
        if enabled then
            button:SetState(BSTATE_NORMAL, false)
        else
            button:SetState(BSTATE_DISABLED, true)
        end
    end
    function ZO_GuildHistory_Keyboard:FilterScrollList()
        ZO_GuildHistory_Shared.FilterScrollList(self)
        local enablePrevious = self.currentPage > 1
        local enableNext = self.hasNextPage
        SetButtonStateEnabled(self.footer.previousButton, enablePrevious)
        SetButtonStateEnabled(self.footer.nextButton, enableNext)
        self.footer:SetHidden(not (enablePrevious or enableNext))
        self:UpdateKeybinds()
    end
end
function ZO_GuildHistory_Keyboard:SetupEventRow(control, eventData)
    ZO_SortFilterList.SetupRowBG(self, control, eventData)
    local IS_KEYBOARD = false
    ZO_GuildHistory_Shared.SetupEventRow(self, control, eventData, IS_KEYBOARD)
end
function ZO_GuildHistory_Keyboard:SetShowLoadingSpinner(showLoadingSpinner)
    if showLoadingSpinner then
        self.loadingIcon:Show()
    else
        self.loadingIcon:Hide()
    end
end
function ZO_GuildHistory_Keyboard.OnControlInitialized(control)
    GUILD_HISTORY_KEYBOARD = ZO_GuildHistory_Keyboard:New(control)
end