ESO Lua File v100011

ingame/contacts/gamepad/socialoptions_gamepad.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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
local STATUS_UPDATE_DELAY = 1
-----------------
-- Options Bar
-----------------
ZO_GamepadSocialOptionsBar = ZO_Object:Subclass()
function ZO_GamepadSocialOptionsBar:New(control)
    local list = ZO_Object.New(self)
    return list
end
function ZO_GamepadSocialOptionsBar:Initialize(control)
end
function ZO_GamepadSocialOptionsBar:InitializeFocus(control)
    self.control = control
    local container = control:GetNamedChild("Container")
    self.movementController = ZO_MovementController:New(MOVEMENT_CONTROLLER_DIRECTION_HORIZONTAL)
    self.focus = ZO_GamepadFocus:New(self.movementController)
    local FocusChangedCallback = function()
        self.filterBox:LoseFocus()
    end
    local statusButton = container:GetNamedChild("StatusButton")
    local statusData = {
        callback = function() 
            self.focus:Deactivate()
            self.statusDropdown:Activate()
            local status = self.cachedUpdateStatus
            if not status then
                status = GetPlayerStatus()
            end
            self.statusDropdown:SetHighlightedItem(status)
            self.statusControl:SetHidden(true)
        end,
        activate = function()
            self.statusControl:SetHidden(true)
            self.statusDropDownControl:SetHidden(false)
        end,
        deactivate = function()
            self.statusControl:SetHidden(false)
            self.statusDropDownControl:SetHidden(true)
        end,
        highlight = statusButton:GetNamedChild("Highlight"),
    }
    self.focus:AddEntry(statusData)
    self:InitializeStatusButton(statusButton)
    local filterButton = container:GetNamedChild("FilterButton")
    local filterData = {
        callback = function() 
            self.filterBox:OpenVirtualKeyboard()
        end,
        activate = function()
            self.filterControl:SetHidden(true)
            self.filterBox:SetHidden(false)
            local filterText = self.filterBox:GetText()
            self:UpdateFilterText(filterText)
        end,
        deactivate = function()
            self.filterControl:SetHidden(false)
            self.filterBox:SetHidden(true)
            self.filterEmptyLabel:SetHidden(true)
        end,
        highlight = filterButton:GetNamedChild("Highlight"),
    }
    self.focus:AddEntry(filterData)
    self:InitializeFilterButton(filterButton)
end
function ZO_GamepadSocialOptionsBar:InitializeStatusButton(control)
    self.statusControl = control:GetNamedChild("Status")
    self.statusLabel = self.statusControl:GetNamedChild("Label")
    self.statusIcon = self.statusControl:GetNamedChild("Icon")
    self.statusDropDownControl = control:GetNamedChild("Dropdown")
    self.statusDropdown = ZO_ComboBox_ObjectFromContainer(self.statusDropDownControl)
    self.statusDropdown:SetSortsItems(false)
    local DropDownDeactivatedCallback = function() self:Activate() end 
    self.statusDropDownControl:RegisterForEvent(EVENT_PLAYER_STATUS_CHANGED, function(_, oldStatus, newStatus) self:UpdateStatusDropdownSelection() end)
    self.statusDropDownControl:SetHidden(true)
end
function ZO_GamepadSocialOptionsBar:InitializeFilterButton(control)
    
    self.filterControl = control:GetNamedChild("Filter")
    self.filterLabel = self.filterControl:GetNamedChild("Label")
    
    self.filterBox = control:GetNamedChild("Edit")
    self.filterEmptyLabel = self.filterBox:GetNamedChild("EmptyText")
    
    self:UpdateFilterText("")
    local SearchTextChangedCallback = function()
        ZO_EditDefaultText_OnTextChanged(self.filterBox)
        local filterText = self.filterBox:GetText()
        self:UpdateFilterText(filterText)
        if self.filterChangedCallback then
            self.filterChangedCallback(filterText)
        end
    end
    self.filterBox:SetHandler("OnTextChanged", SearchTextChangedCallback)
end
function ZO_GamepadSocialOptionsBar:UpdateFilterText(filterText)
    local showEmptyText = not filterText or filterText == ""
    if showEmptyText then
        filterText = GetString(SI_GAMEPAD_CONTACTS_OPTIONS_FILTER_NONE)
    end
    self.filterEmptyLabel:SetHidden(not showEmptyText)
    self.filterLabel:SetText(filterText)
end
function ZO_GamepadSocialOptionsBar:SetFilterChangedCallback(callback)
end
function ZO_GamepadSocialOptionsBar:GetFilterText()
    return self.filterBox:GetText()
end
function ZO_GamepadSocialOptionsBar:SetFilterText(text)
    self.filterBox:SetText(text)
end
function ZO_GamepadSocialOptionsBar:GetSelectKeybind()
    local keybind = {
        name = GetString(SI_GAMEPAD_SELECT_OPTION),
        keybind = "UI_SHORTCUT_PRIMARY",
        callback = function()
            local data = self.focus:GetFocusItem()
            if data.callback then
                data.callback()
            end
        end,
    }
    return keybind
end
function ZO_GamepadSocialOptionsBar:AttemptStatusUpdate(status, currentTime)
    if not self.lastStatusUpdateTime then
        self.lastStatusUpdateTime = -STATUS_UPDATE_DELAY
    end
    self.cachedUpdateStatus = status
    if self.lastStatusUpdateTime + STATUS_UPDATE_DELAY <= currentTime then
        self:ForceStatusUpdate()
        self.lastStatusUpdateTime = currentTime
    end
end
function ZO_GamepadSocialOptionsBar:ForceStatusUpdate()
    if self.cachedUpdateStatus then
        SelectPlayerStatus(self.cachedUpdateStatus)
        self.cachedUpdateStatus = nil
    end
end
function ZO_GamepadSocialOptionsBar:Activate()
    self.focus:Activate()
    if not self.updateCachedStatus then 
        self.updateCachedStatus = function(updateControl, currentFrameTimeSeconds)
            if self.cachedUpdateStatus then
                self:AttemptStatusUpdate(self.cachedUpdateStatus, currentFrameTimeSeconds)
            end
        end
    end
end
function ZO_GamepadSocialOptionsBar:Deactivate()
    self.statusDropdown:Deactivate()
    self.focus:Deactivate()
    
    self.control:SetHandler("OnUpdate", nil)
end
-----------------
-- Status Dropdown
-----------------
function ZO_GamepadSocialOptionsBar:UpdateStatusDropdownSelection()
    local status = GetPlayerStatus()
    local statusTexture = GetPlayerStatusIcon(status)
    local statusString = GetString("SI_PLAYERSTATUS", status)
    local text = zo_strformat(SI_GAMEPAD_GUILD_STATUS_SELECTOR_FORMAT, statusTexture, statusString)
    self.statusDropdown:SetSelectedItem(text)
    
    self.statusLabel:SetText(statusString)
    self.statusIcon:SetTexture(statusTexture)
end
function ZO_GamepadSocialOptionsBar:UpdateStatusDropdown()
    self.statusDropdown:ClearItems()
        
    for i = 1, GetNumPlayerStatuses() do
        local function StatusSelect()
            self:AttemptStatusUpdate(i, GetFrameTimeSeconds())
        end
        local statusTexture = GetPlayerStatusIcon(i)
        local text = zo_strformat(SI_GAMEPAD_GUILD_STATUS_SELECTOR_FORMAT, statusTexture, GetString("SI_PLAYERSTATUS", i))
        local entry = ZO_ComboBox:CreateItemEntry(text, StatusSelect)
        self.statusDropdown:AddItem(entry, ZO_COMBOBOX_SUPRESS_UPDATE)
    end
    self.statusDropdown:UpdateItems()
end