Back to Home

ESO Lua File v100022

libraries/zo_dialog/zo_listdialog.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
ZO_ListDialog = ZO_Object:Subclass()
LIST_DIALOG_CUSTOM_CONTROL_LOCATION_TOP = 1
LIST_DIALOG_CUSTOM_CONTROL_LOCATION_BOTTOM = 2
function ZO_ListDialog:New(...)
    local listDialog = ZO_Object.New(self)
    listDialog:Initialize(...)
    return listDialog
end
local SCROLL_TYPE_ITEM = 1
local listDialogId = 1
function ZO_ListDialog:Initialize(listTemplate, listItemHeight, listSetupFunction)
    self.control = CreateControlFromVirtual("ZO_ListDialog", GuiRoot, "ZO_ListDialogTemplate", listDialogId)
    self.control.owner = self
    listDialogId = listDialogId + 1
    
    self.aboveText = self.control:GetNamedChild("AboveText")
    self.belowText = self.control:GetNamedChild("BelowText")
    self.firstButton = self.control:GetNamedChild("Button1")
    self.secondButton = self.control:GetNamedChild("Button2")
    self.list = self.control:GetNamedChild("List")
    self.emptyListText = self.control:GetNamedChild("EmptyListText")
    self.topCustomControlContainer = self.control:GetNamedChild("TopCustomControlContainer")
    self.bottomCustomControlContainer = self.control:GetNamedChild("BottomCustomControlContainer")
    self.customControls = {}
    local function OnMouseUp(rowControl, button, upInside)
        if upInside then
            local data = ZO_ScrollList_GetData(rowControl)
            ZO_ScrollList_SelectData(self.list, data, rowControl)
        end
    end
    local function Setup(rowControl, ...)
        rowControl:SetHandler("OnMouseUp", OnMouseUp)
        listSetupFunction(rowControl, ...)
    end
    ZO_ScrollList_AddDataType(self.list, SCROLL_TYPE_ITEM, listTemplate, listItemHeight, Setup)
    self.listItemHeight = listItemHeight
    self.minVisibleItems = zo_max(zo_floor(220 / listItemHeight), 2)
    self.maxVisibleItems = zo_max(zo_floor(300 / listItemHeight), self.minVisibleItems)
    local function OnListSelection(previouslySelected, selected)
        self.selectedItem = selected
        if self.onSelectedCallback then
            self.onSelectedCallback(selected)
        end
    end
         
end
function ZO_ListDialog:SetAboveText(text)
    self.aboveText:SetText(text)
end
function ZO_ListDialog:SetBelowText(text)
    self.belowText:SetText(text)
end
function ZO_ListDialog:GetButton(index)
    if index == 1 then
        return self.firstButton
    elseif index == 2 then
        return self.secondButton
    end
end
function ZO_ListDialog:SetFirstButtonEnabled(enabled)
    self.firstButton:SetEnabled(enabled)
end
function ZO_ListDialog:SetSecondButtonEnabled(enabled)
    self.firstButton:SetEnabled(enabled)
end
function ZO_ListDialog:SetEmptyListText(text)
    self.emptyListText:SetText(text)
end
function ZO_ListDialog:ClearList()
end
function ZO_ListDialog:CommitList(sortFunction)
    local scrollData = ZO_ScrollList_GetDataList(self.list)
    local numListItems = #scrollData
    self.list:SetHeight(self.listItemHeight * zo_clamp(numListItems, self.minVisibleItems, self.maxVisibleItems))
    if sortFunction then
        table.sort(scrollData, sortFunction)
    end
    self.emptyListText:SetHidden(numListItems > 0)
end
function ZO_ListDialog:AddListItem(itemData)
    local scrollData = ZO_ScrollList_GetDataList(self.list)
    scrollData[#scrollData + 1] = ZO_ScrollList_CreateDataEntry(SCROLL_TYPE_ITEM, itemData)
end
function ZO_ListDialog:AddCustomControl(control, location)
    if self.customControls[location] then
        self.customControls[location]:ClearAnchors()
    end
    local container = self:GetCustomContainerFromLocation(location)
    control:SetAnchor(TOP, container, TOP)
    control:SetParent(container)
    self.customControls[location] = control
end
function ZO_ListDialog:GetCustomContainerFromLocation(location)
    if location == LIST_DIALOG_CUSTOM_CONTROL_LOCATION_TOP then
        return self.topCustomControlContainer
    elseif location == LIST_DIALOG_CUSTOM_CONTROL_LOCATION_BOTTOM then
        return self.bottomCustomControlContainer
    end
end
function ZO_ListDialog:GetSelectedItem()
    return self.selectedItem
end
function ZO_ListDialog:SetOnSelectedCallback(selectedCallback)
end
function ZO_ListDialog:SetHidden(hidden)
    self.control:SetHidden(hidden)
end
function ZO_ListDialog:GetControl()
    return self.control
end
local function ClearCustomControl(control)
    if control then
        control:ClearAnchors()
        control:SetParent(nil)
        control:SetHidden(true)
    end
end
function ZO_ListDialog:OnHide()
    self.aboveText:SetText("")
    self.belowText:SetText("")
    self.firstButton:SetEnabled(true)
    self.secondButton:SetEnabled(true)
    self.emptyListText:SetText("")
    self.selectedItem = nil
    self.onSelectedCallback = nil
    self.customControls[LIST_DIALOG_CUSTOM_CONTROL_LOCATION_TOP] = ClearCustomControl(self.customControls[LIST_DIALOG_CUSTOM_CONTROL_LOCATION_TOP])
    self.customControls[LIST_DIALOG_CUSTOM_CONTROL_LOCATION_BOTTOM] = ClearCustomControl(self.customControls[LIST_DIALOG_CUSTOM_CONTROL_LOCATION_BOTTOM])
    self:ClearList()
end
function ZO_ListDialog_OnHide(dialog)
    dialog.owner:OnHide()
end