ESO Lua File v100012

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
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(control, 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)
        end,
        activate = function()
            self.statusDropdown:SetSelectedColor(ZO_SELECTED_TEXT)
        end,
        deactivate = function()
            self.statusDropdown:SetSelectedColor(ZO_DISABLED_TEXT)
        end,
        highlight = statusButton:GetNamedChild("Highlight"),
    }
    self.focus:AddEntry(statusData)
    self.title = container:GetNamedChild("Title")
    self.subtitle = container:GetNamedChild("Subtitle")
    self:InitializeStatusButton(statusButton)
    local filterButton = container:GetNamedChild("FilterButton")
    local filterData = {
        callback = function() 
            if self.filterBox:HasFocus() then
                self.filterBox:LoseFocus()
            else
                self.filterBox:TakeFocus()
            end
        end,
        highlight = filterButton:GetNamedChild("Highlight"),
    }
    self.focus:AddEntry(filterData)
    self:InitializeFilterButton(filterButton)
end
function ZO_GamepadSocialOptionsBar:InitializeStatusButton(control)
    self.statusDropDownControl = control:GetNamedChild("Dropdown")
    self.statusDropdown = ZO_ComboBox_ObjectFromContainer(self.statusDropDownControl)
    self.statusDropdown:SetSelectedColor(ZO_DISABLED_TEXT)
    self.statusDropdown:SetSortsItems(false)
    local DropDownDeactivatedCallback = function() self:Activate() end 
    self.statusDropDownControl:RegisterForEvent(EVENT_PLAYER_STATUS_CHANGED, function(_, oldStatus, newStatus) self:UpdateStatusDropdownSelection() end)
end
function ZO_GamepadSocialOptionsBar:InitializeFilterButton(control)
    self.filterBox = control:GetNamedChild("Edit")
    local function SearchTextChangedCallback()
        ZO_EditDefaultText_OnTextChanged(self.filterBox)
        if self.filterChangedCallback then
            self.filterChangedCallback(self.filterBox:GetText())
        end
    end
    self.filterBox:SetHandler("OnTextChanged", SearchTextChangedCallback)
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:SetTitle(title)
    self.title:SetText(title)
end
function ZO_GamepadSocialOptionsBar:SetSubtitle(subtitle)
    self.subtitle:SetText(subtitle)
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 = GetGamepadPlayerStatusIcon(status)
    local statusString = GetString("SI_PLAYERSTATUS", status)
    local text = zo_strformat(SI_GAMEPAD_GUILD_STATUS_SELECTOR_FORMAT, statusTexture, statusString)
    self.statusDropdown:SetSelectedItem(text)
end
function ZO_GamepadSocialOptionsBar:UpdateStatusDropdown()
    self.statusDropdown:ClearItems()
        
    for i = 1, GetNumPlayerStatuses() do
        local function StatusSelect()
            self:AttemptStatusUpdate(i, GetFrameTimeSeconds())
        end
        local statusTexture = GetGamepadPlayerStatusIcon(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