Back to Home

ESO Lua File v101044

ingame/stats/title_manager.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
ZO_Title_Manager = ZO_InitializingCallbackObject:Subclass()
function ZO_Title_Manager:Initialize()
    EVENT_MANAGER:RegisterForEvent("ZO_Title_Manager", EVENT_PLAYER_TITLES_UPDATE, function(_, ...) self:UpdateTitles() end)
    EVENT_MANAGER:RegisterForEvent("ZO_Title_Manager", EVENT_PLAYER_ACTIVATED, function(_, ...) self:UpdateTitles() end)
end 
function ZO_Title_Manager:UpdateTitles()
    if self.titles then
        -- Handle the delta
        local titles = {}
        local newUnlockedTitles = {}
        for i = 1, GetNumTitles() do
            local name = GetTitle(i)
            local titleInfo = self.titles[name]
            if titleInfo then
                titleInfo.index = i
            else
                titleInfo =
                {
                    index = i,
                    name = name,
                    isNew = true,
                }
                table.insert(newUnlockedTitles, titleInfo)
            end
            titles[name] = titleInfo
        end
        self.titles = titles
        self:FireCallbacks("UpdateTitlesData", newUnlockedTitles)
    else
        self.titles = {}
        for i = 1, GetNumTitles() do
            local name = GetTitle(i)
            local titleInfo =
            {
                index = i,
                name = name,
            }
            self.titles[name] = titleInfo
        end
        self:FireCallbacks("UpdateTitlesData")
    end
end
function ZO_Title_Manager:ClearTitleNew(titleName)
    if self.titles then
        local titleInfo = self.titles[titleName]
        if titleInfo and titleInfo.isNew then
            titleInfo.isNew = false
            self:FireCallbacks("TitleClearedNew", titleInfo)
        end
    end
end
function ZO_Title_Manager:GetTitles()
    return self.titles
end
function ZO_Title_Manager:GetSortedTitles(sortKeys, sortOrder)
    local sortedTitles = {}
    local titles = self:GetTitles()
    sortedTitles = ZO_CreateSortableTableFromValues(titles)
    local function CompareTitleItems(item1, item2) 
        return ZO_TableOrderingFunction(item1, item2, "name", sortKeys , sortOrder) 
    end
    table.sort(sortedTitles, CompareTitleItems)
    return sortedTitles
end
function ZO_Title_Manager:HasNewTitle()
    for _, titleInfo in pairs(self.titles) do
        if titleInfo.isNew then 
            return true
        end
    end
    return false
end
TITLE_MANAGER = ZO_Title_Manager:New()