Back to Home

ESO Lua File v101041

ingame/map/maplocationtooltip.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
local function HasMapLocationTooltip(self, locationIndex)
    local headerText = GetMapLocationTooltipHeader(locationIndex)
    if(headerText == "") then
        return false
    end
    local numTooltipLines = GetNumMapLocationTooltipLines(locationIndex)
    if(numTooltipLines == 0) then
        return false
    end
    return true
end
local MIN_HEADER_WIDTH = 150
local function SortGroupings(a, b)
    return a.id < b.id
end
local function SortGrouping(a, b)
    return a.name < b.name
end
local function GetMapLocationLines(locationIndex)
    local groupings = {}
    local numTooltipLines = GetNumMapLocationTooltipLines(locationIndex)
    for lineIndex = 1, numTooltipLines do
        if(IsMapLocationTooltipLineVisible(locationIndex, lineIndex)) then
            --Create labels for the lines. The size of the header depends on the lines.
            local icon, name, groupingId, categoryName = GetMapLocationTooltipLineInfo(locationIndex, lineIndex)
            --Search for an existing grouping
            local grouping
            for groupingIndex = 1, #groupings do
                if(groupings[groupingIndex].id == groupingId) then
                    grouping = groupings[groupingIndex]
                end
            end
            --if there isn't an existing one, make it
            if(grouping == nil) then
                grouping = {}
                grouping.id = groupingId
                table.insert(groupings, grouping)
            end
            local showName = name ~= categoryName
            table.insert(grouping, { name = name, categoryName = categoryName, icon = icon, showName = showName, })
        end
    end
    table.sort(groupings, SortGroupings)
    for groupingIndex = 1, #groupings do
        local grouping = groupings[groupingIndex]
        table.sort(grouping, SortGrouping)
    end
    return groupings
end
local function CreateLineLabel(self, text, indentation, currentLargestWidth)
    if indentation > 0 then
        self:AddVerticalPadding(-5)
    end
    local label = self.labelPool:AcquireObject()
    label.indentation = indentation
    label:SetDimensions(0,0)
    label:SetText(text)
    self:AddControl(label)
    label:SetAnchor(CENTER, nil, CENTER, indentation, 0)
    local labelWidth = label:GetTextWidth() + indentation + 5
    return zo_max(currentLargestWidth, labelWidth)
end
local function SetMapLocation(self, locationIndex)
    self:ClearLines()
    local largestWidth = MIN_HEADER_WIDTH
    --add header
    local headerText = GetMapLocationTooltipHeader(locationIndex)
    if headerText ~= "" then
        self.header:SetWidth(0)
        self.header:SetText(headerText)
        self:AddControl(self.header)
        self.header:SetAnchor(CENTER)
        largestWidth = zo_max(self.header:GetTextWidth(), largestWidth)
        self:AddVerticalPadding(-5)
        self:AddControl(self.divider)
        self.divider:SetAnchor(CENTER)
    end
    --add lines
    local groupings = GetMapLocationLines(locationIndex)
    for groupingIndex = 1, #groupings do
        local grouping = groupings[groupingIndex]
        for _, entry in ipairs(grouping) do
            local iconText = zo_iconFormat(entry.icon, 32, 32)
            local NO_INDENT = 0 
            largestWidth = CreateLineLabel(self, zo_strformat(SI_TOOLTIP_MAP_LOCATION_CATEGORY_FORMAT, iconText, entry.categoryName), NO_INDENT, largestWidth)
            
            if entry.showName then
                local NAME_INDENT = 32
                largestWidth = CreateLineLabel(self, zo_strformat(SI_TOOLTIP_UNIT_NAME, entry.name), NAME_INDENT, largestWidth)
            end
        end
    end
    self.header:SetWidth(largestWidth)
    self.divider:SetWidth(largestWidth)
    local labels = self.labelPool:GetActiveObjects()
    for _, label in pairs(labels) do
        label:SetWidth(largestWidth - label.indentation)
    end
end
local function SetMapLocation_Gamepad(self, locationIndex)
    local mainSection = self.tooltip:AcquireSection(self.tooltip:GetStyle("mapLocationSection"))
    --add header
    local headerText = GetMapLocationTooltipHeader(locationIndex)
    if headerText ~= "" then
        self:LayoutGroupHeader(mainSection, nil, headerText, self.tooltip:GetStyle("mapTitle"))
    end
    local groupsSection = self.tooltip:AcquireSection(self.tooltip:GetStyle("mapGroupsSection"))
    local groupSectionStyle = self.tooltip:GetStyle("mapLocationGroupSection")
    local entryStyle = self.tooltip:GetStyle("mapLocationEntrySection")
    local titleStyle = self.tooltip:GetStyle("mapLocationTooltipContentTitle")
    local nameSectionStyle = self.tooltip:GetStyle("mapLocationTooltipNameSection")
    local nameStyle = self.tooltip:GetStyle("mapLocationTooltipContentName")
    --add lines
    local groupings = GetMapLocationLines(locationIndex)
    for _, grouping in ipairs(groupings) do
        local groupSection = groupsSection:AcquireSection(groupSectionStyle)
        for _, entry in ipairs(grouping) do
            local entrySection = groupSection:AcquireSection(entryStyle)
            local name = zo_strformat(SI_TOOLTIP_UNIT_NAME, entry.name)
            local icon = entry.icon
            icon = icon:gsub("servicetooltipicons/", "servicetooltipicons/gamepad/gp_")
            self:LayoutLargeIconStringLine(entrySection, icon, entry.categoryName, titleStyle)
            if entry.showName then
                local nameSection = entrySection:AcquireSection(nameSectionStyle)
                self:LayoutStringLine(nameSection, name, nameStyle)
                entrySection:AddSection(nameSection)
            end
            groupSection:AddSection(entrySection)
        end
        groupsSection:AddSection(groupSection)
    end
    mainSection:AddSection(groupsSection)
    self.tooltip:AddSection(mainSection)
end
--Global XML
    self.labelPool:ReleaseAllObjects()
end
    self.labelPool = ZO_ControlPool:New("ZO_MapLocationTooltipLabel", self, "Label")
    self.header = self:GetNamedChild("Header")
    self.divider = self:GetNamedChild("Divider")
end
    ZO_ScrollTooltip_Gamepad:Initialize(self, ZO_TOOLTIP_STYLES, "worldMapTooltip")
    zo_mixin(self, ZO_MapInformationTooltip_Gamepad_Mixin)
    local ALWAYS_ANIMATE = true
    GAMEPAD_WORLD_MAP_TOOLTIP_FRAGMENT = ZO_FadeSceneFragment:New(self:GetParent(), ALWAYS_ANIMATE)
    ZO_Scroll_Gamepad_SetScrollIndicatorSide(self.scrollIndicator, self:GetParent(), LEFT)
end