Back to Home

ESO Lua File v100019

ingame/leaderboards/housingleaderboards_shared.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
---------------
-- Housing Leaderboards
---------------
HOUSING_LEADERBOARD_SYSTEM_NAME = "housingLeaderboards"
local HOME_SHOW_HEADER_ICONS =
{
    up = "EsoUI/Art/Journal/leaderboard_indexIcon_housing_up.dds", 
    down = "EsoUI/Art/Journal/leaderboard_indexIcon_housing_down.dds", 
    over = "EsoUI/Art/Journal/leaderboard_indexIcon_housing_over.dds",
}
ZO_HousingLeaderboardsManager_Shared = ZO_LeaderboardBase_Shared:Subclass()
function ZO_HousingLeaderboardsManager_Shared:New(...)
    return ZO_LeaderboardBase_Shared.New(self, ...)
end
function ZO_HousingLeaderboardsManager_Shared:Initialize(...)
    ZO_LeaderboardBase_Shared.Initialize(self, ...)
    self.homeshowListNodes = {}
end
do
    local function GetSingleHomeShowEntryInfo(entryIndex, categoryData)
        return GetHomeShowLeaderboardEntryInfo(categoryData.voteCategory, categoryData.houseCategory, entryIndex)
    end
    local function GetHousingLeaderboardEntryConsoleIdRequestParams(entryIndex, categoryData)
        return ZO_ID_REQUEST_TYPE_HOME_SHOW_LEADERBOARD, categoryData.voteCategory, categoryData.houseCategory, entryIndex
    end
    function ZO_HousingLeaderboardsManager_Shared:AddCategoriesToParentSystem()
        ZO_ClearNumericallyIndexedTable(self.homeshowListNodes)
        local function GetNumEntries(categoryData)
            self:UpdateAllInfo()
            return GetNumHomeShowLeaderboardEntries(categoryData.voteCategory, categoryData.houseCategory)
        end
        local function AddEntry(parent, name, categoryData)
            local node = self.leaderboardSystem:AddEntry(self, name, nil, parent, categoryData, GetNumEntries, nil, GetSingleHomeShowEntryInfo, nil, GetString(SI_LEADERBOARDS_HEADER_POINTS), GetHousingLeaderboardEntryConsoleIdRequestParams, "EsoUI/Art/Leaderboards/gamepad/gp_leaderBoards_menuIcon_housing.dds", LEADERBOARD_TYPE_HOUSE)
            if node then
                local nodeData = node.GetData and node:GetData() or node
                nodeData.voteCategory = categoryData.voteCategory
                nodeData.houseCategory= categoryData.houseCategory
            end
            table.insert(self.homeshowListNodes, node)
            return node
        end
        local numVoteCategories = GetNumHomeShowVoteCategories()
        --Create the category header
        if numVoteCategories > 0 then
            self.header = self.leaderboardSystem:AddCategory(GetString(SI_HOUSING_LEADERBOARDS_CATEGORIES_HEADER), HOME_SHOW_HEADER_ICONS.up, HOME_SHOW_HEADER_ICONS.down, HOME_SHOW_HEADER_ICONS.over)
            for voteCategory = 0, numVoteCategories - 1 do
                local houseEventName = GetHomeShowLeaderboardVoteCategoryName(voteCategory)
                for houseCategory = HOUSE_CATEGORY_TYPE_MIN_VALUE, HOUSE_CATEGORY_TYPE_MAX_VALUE do
                    local houseCategoryDisplayName = houseCategory == HOUSE_CATEGORY_TYPE_NONE and GetString(SI_HOUSING_LEADERBOARDS_ALL_HOMES) or GetString("SI_HOUSECATEGORYTYPE", houseCategory)
                    local homeShowName = zo_strformat(SI_HOUSING_LEADERBOARDS_HOME_SHOW_NAME_AND_CATEGORY, houseEventName, houseCategoryDisplayName)
                    local categoryData = 
                    {
                        voteCategory = voteCategory,
                        houseCategory = houseCategory
                    }
                    AddEntry(self.header, homeShowName, categoryData)
                end
            end
        end
    end
end
function ZO_HousingLeaderboardsManager_Shared:SelectHomeShowByCategory(voteCategory, houseCategory, openLeaderboards)
    local selectedNode
    for _, node in ipairs(self.homeshowListNodes) do
        local nodeData = node.GetData and node:GetData() or node
        if nodeData.voteCategory == voteCategory and nodeData.houseCategory == houseCategory then
            selectedNode = node
            break
        end
    end
    if selectedNode then
        self.leaderboardSystem:SelectNode(selectedNode)
        if openLeaderboards then
            SCENE_MANAGER:Push(self.leaderboardScene:GetName())
        end
    end
end
do
    local timerLabelLastUpdateSecs = 0
    local UPDATE_INTERVAL_SECS = 1
    function ZO_HousingLeaderboardsManager_Shared:TimerLabelOnUpdate(currentTime)
        if currentTime - timerLabelLastUpdateSecs >= UPDATE_INTERVAL_SECS then
            local secsUntilNextUpdate = GetHomeShowLeaderboardTimeInfo()
            if secsUntilNextUpdate > 0 then
                self.timerLabelIdentifier = SI_HOUSING_LEADERBOARDS_HOME_SHOW_UPDATES_IN_TIMER
                self.timerLabelData = ZO_FormatTime(secsUntilNextUpdate, TIME_FORMAT_STYLE_COLONS, TIME_FORMAT_PRECISION_TWELVE_HOUR)
            else
                self.timerLabelIdentifier = nil
                self.timerLabelData = nil
                QueryHomeShowLeaderboardData()
            end
            timerLabelLastUpdateSecs = currentTime
            self:RefreshHeaderTimer()
        end
    end
    function ZO_HousingLeaderboardsManager_Shared:UpdatePlayerInfo()
        if not self.selectedSubType then
            return
        end
        local bestRank, bestScore = GetHomeShowLeaderboardLocalPlayerInfo(self.selectedSubType.voteCategory, self.selectedSubType.houseCategory)
        self.currentRankData = bestRank and bestRank > 0 and bestRank
        self.currentScoreData = bestScore and bestScore > 0 and bestScore
        self.control:SetHandler("OnUpdate", function(_, currentTime) self:TimerLabelOnUpdate(currentTime) end)
        self:RefreshHeaderPlayerInfo()
    end
end
function ZO_HousingLeaderboardsManager_Shared:OnSubtypeSelected(subType)
    ZO_LeaderboardBase_Shared.OnSubtypeSelected(self, subType)
    self:UpdateAllInfo()
end
function ZO_HousingLeaderboardsManager_Shared:UpdateAllInfo()
    self:UpdatePlayerInfo()
end