Back to Home

ESO Lua File v100020

ingame/help/gamepad/help_mechanicassistance_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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
local LIST_REFRESH_VISIBLE = true
ZO_Help_MechanicAssistance_Gamepad = ZO_Help_GenericTicketSubmission_Gamepad:Subclass()
function ZO_Help_MechanicAssistance_Gamepad:New(...)
    return ZO_Help_GenericTicketSubmission_Gamepad.New(self, ...)
end
function ZO_Help_MechanicAssistance_Gamepad:Initialize(control, mechanicCategoriesData)
    ZO_Help_GenericTicketSubmission_Gamepad.Initialize(self, control)
    
    self.itemList = self:GetMainList()
    self.mechanicCategoriesData = mechanicCategoriesData
end
function ZO_Help_MechanicAssistance_Gamepad:GetFieldEntryMessage()
    return GetString(SI_GAMEPAD_HELP_CUSTOMER_SERVICE_FIELD_ENTRY_MESSAGE)
end
function ZO_Help_MechanicAssistance_Gamepad:BuildList()
    self:AddCategoriesEntry()
    self:AddDetailsEntry()
    self:AddDescriptionEntry()
    self:AddSubmitEntry()
    self.itemList:Commit()
end
function ZO_Help_MechanicAssistance_Gamepad:AddCategoriesEntry()
    local entryData = ZO_GamepadEntryData:New("")
    entryData.header = GetString(SI_GAMEPAD_HELP_FIELD_TITLE_CATEGORY)
    entryData.fieldType = ZO_HELP_TICKET_FIELD_TYPE.CATEGORY
    self.itemList:AddEntryWithHeader("ZO_Gamepad_Help_Dropdown_Item", entryData)
end
function ZO_Help_MechanicAssistance_Gamepad:AddDetailsEntry()
    local entryData = ZO_GamepadEntryData:New("")
    entryData.header = self.detailsHeader
    entryData.fieldType = ZO_HELP_TICKET_FIELD_TYPE.DETAILS
    self.itemList:AddEntryWithHeader("ZO_Help_MechanicAssistance_Gamepad_DetailsItem", entryData)
end
function ZO_Help_MechanicAssistance_Gamepad:AddDescriptionEntry()
    local entryData = ZO_GamepadEntryData:New("")
    entryData.header = GetString(SI_CUSTOMER_SERVICE_DESCRIPTION)
    entryData.fieldType = ZO_HELP_TICKET_FIELD_TYPE.DESCRIPTION
    self.itemList:AddEntryWithHeader("ZO_GamepadTextFieldItem_Multiline", entryData)
end
function ZO_Help_MechanicAssistance_Gamepad:AddSubmitEntry()
    local entryData = ZO_GamepadEntryData:New(GetString(SI_GAMEPAD_HELP_SUBMIT_TICKET), ZO_GAMEPAD_SUBMIT_ENTRY_ICON)
    entryData.fieldType = ZO_HELP_TICKET_FIELD_TYPE.SUBMIT
    self.itemList:AddEntry("ZO_GamepadTextFieldSubmitItem", entryData)
end
function ZO_Help_MechanicAssistance_Gamepad:GenerateSelectKeybindStripDescriptor()
    local keybindDescriptor =
    {
        name = function()
            local targetData = self.itemList:GetTargetData()
            local fieldType = targetData.fieldType
            if fieldType == ZO_HELP_TICKET_FIELD_TYPE.DETAILS then
                return self.goToDetailsSourceKeybindText
            elseif fieldType == ZO_HELP_TICKET_FIELD_TYPE.SUBMIT then
                return GetString(SI_GAMEPAD_HELP_SUBMIT_TICKET)
            else
                return GetString(SI_GAMEPAD_SELECT_OPTION)
            end
        end,
        keybind = "UI_SHORTCUT_PRIMARY",
        callback = function()
            local targetData = self.itemList:GetTargetData()
            local fieldType = targetData.fieldType
            if fieldType == ZO_HELP_TICKET_FIELD_TYPE.CATEGORY then
                self.categoryDropdown:Activate()
            elseif fieldType == ZO_HELP_TICKET_FIELD_TYPE.DETAILS then
                self:GoToDetailsSourceScene()
            elseif fieldType == ZO_HELP_TICKET_FIELD_TYPE.DESCRIPTION then
                local editBox = self.descriptionEditBox
                if editBox:HasFocus() then
                    editBox:LoseFocus()
                else
                    editBox:TakeFocus()
                end
            elseif fieldType == ZO_HELP_TICKET_FIELD_TYPE.SUBMIT then
                self:TrySubmitTicket()
                PlaySound(SOUNDS.DIALOG_ACCEPT)
            end
        end,
    }
    return keybindDescriptor
end
function ZO_Help_MechanicAssistance_Gamepad:DetailsRequired()
    return false
end
function ZO_Help_MechanicAssistance_Gamepad:ValidateTicketFields()
    local selectedCategoryData = self.categoryDropdown:GetSelectedItemData()
    local savedDetails = self:GetSavedField(ZO_HELP_TICKET_FIELD_TYPE.DETAILS)
    local savedCategoryValue = self:GetSavedField(ZO_HELP_TICKET_FIELD_TYPE.CATEGORY)
    local savedDescription = self:GetSavedField(ZO_HELP_TICKET_FIELD_TYPE.DESCRIPTION)
    if savedCategoryValue == self.mechanicCategoriesData.invalidCategory then
        return ZO_HELP_TICKET_VALIDATION_STATUS.FAILED_NO_CATEGORY
    elseif self:DetailsRequired() and (not savedDetails or savedDetails == "") then
        return ZO_HELP_TICKET_VALIDATION_STATUS.FAILED_NO_DETAILS
    elseif self.descriptionEditBox and (not savedDescription or savedDescription == "") then
        return ZO_HELP_TICKET_VALIDATION_STATUS.FAILED_NO_DESCRIPTION
    end
    return ZO_HELP_TICKET_VALIDATION_STATUS.SUCCESS
end
function ZO_Help_MechanicAssistance_Gamepad:SubmitTicket()
    self:RegisterDetails()
    local savedDescription = self:GetSavedField(ZO_HELP_TICKET_FIELD_TYPE.DESCRIPTION)
    if savedDescription then
        SetCustomerServiceTicketBody(savedDescription)
    end
end
function ZO_Help_MechanicAssistance_Gamepad:GetCurrentTicketCategory()
    local categoryIndex = self:GetSavedField(ZO_HELP_TICKET_FIELD_TYPE.CATEGORY)
    if categoryIndex then
        local categoryData = self.mechanicCategoriesData.ticketCategoryMap[categoryIndex]
        if categoryData then
            return categoryData.ticketCategory
        end
    end
end
function ZO_Help_MechanicAssistance_Gamepad:SetupList(list)
    ZO_Gamepad_ParametricList_Screen.SetupList(self, list)
    
    local function OnCategorySelectionChanged(control, name, entry, selectionChanged)
        self:SetSavedField(ZO_HELP_TICKET_FIELD_TYPE.CATEGORY, entry.categoryEnumValue)
    end
    local function SetupCategoryListEntry(control, data, selected, selectedDuringRebuild, enabled, activated)
        ZO_SharedGamepadEntry_OnSetup(control, data, selected, selectedDuringRebuild, enabled, active)
        local dropdown = control.dropdown
        dropdown:SetSortsItems(false)
        dropdown:ClearItems()
        local savedCategoryValue = self:GetSavedField(ZO_HELP_TICKET_FIELD_TYPE.CATEGORY)
        local savedDropdownIndex = 1
        local currentDropdownIndex = 1
        local mechanicCategoriesData = self.mechanicCategoriesData
        for _, enumValue in ipairs(mechanicCategoriesData.categoryEnumOrderedValues) do
            local name = GetString(mechanicCategoriesData.categoryEnumStringPrefix, enumValue)
            if name ~= nil then
                local entry = ZO_ComboBox:CreateItemEntry(name, OnCategorySelectionChanged)
                entry.categoryEnumValue = enumValue
                dropdown:AddItem(entry, ZO_COMBOBOX_SUPRESS_UPDATE)
                if savedCategoryValue == enumValue then
                    savedDropdownIndex = currentDropdownIndex
                end
                currentDropdownIndex = currentDropdownIndex + 1
            end
        end
        dropdown:UpdateItems()
        dropdown:SelectItemByIndex(savedDropdownIndex)
        self.categoryDropdown = dropdown
    end
    local function SetupDetailsListEntry(control, data, selected, reselectingDuringRebuild, enabled, active)
        data.text = self:GetDisplayedDetails()
        ZO_SharedGamepadEntry_OnSetup(control, data, selected, reselectingDuringRebuild, enabled, active)
    end
    local function OnDescriptionTextChanged(control)
        self:SetSavedField(ZO_HELP_TICKET_FIELD_TYPE.DESCRIPTION, control:GetText())
    end
    local function SetupDescriptionFieldListEntry(control, data, selected, reselectingDuringRebuild, enabled, active)
        ZO_SharedGamepadEntry_OnSetup(control, data, selected, reselectingDuringRebuild, enabled, active)
        local editContainer = control:GetNamedChild("TextField")
        local editBox = editContainer:GetNamedChild("Edit")
        editBox:SetHandler("OnTextChanged", OnDescriptionTextChanged)
        local savedText = self:GetSavedField(ZO_HELP_TICKET_FIELD_TYPE.DESCRIPTION)
        editBox:SetText(savedText or "")
        ZO_EditDefaultText_Initialize(editBox, GetString(SI_CUSTOMER_SERVICE_DEFAULT_DESCRIPTION_TEXT_GENERIC))
        control.highlight:SetHidden(not selected)
        self.descriptionEditBox = editBox
    end
    list:AddDataTemplateWithHeader("ZO_Gamepad_Help_Dropdown_Item", SetupCategoryListEntry, ZO_GamepadMenuEntryTemplateParametricListFunction, nil, "ZO_GamepadMenuEntryFullWidthHeaderTemplate", nil, "Categories")
    list:AddDataTemplateWithHeader("ZO_Help_MechanicAssistance_Gamepad_DetailsItem", SetupDetailsListEntry, ZO_GamepadMenuEntryTemplateParametricListFunction, nil, "ZO_GamepadMenuEntryFullWidthHeaderTemplate", nil, "Details")
    list:AddDataTemplateWithHeader("ZO_GamepadTextFieldItem_Multiline", SetupDescriptionFieldListEntry, ZO_GamepadMenuEntryTemplateParametricListFunction, nil, "ZO_GamepadMenuEntryFullWidthHeaderTemplate", nil, "Desc")
end
function ZO_Help_MechanicAssistance_Gamepad:OnSelectionChanged(list, selectedData, oldSelectedData)
    if self.descriptionEditBox then
        self.descriptionEditBox:LoseFocus()
    end
end
function ZO_Help_MechanicAssistance_Gamepad:SetGoToDetailsSourceKeybindText(keybindText)
    self.goToDetailsSourceKeybindText = keybindText
end
function ZO_Help_MechanicAssistance_Gamepad:SetDetailsHeader(detailsHeader)
    self.detailsHeader = detailsHeader
end
function ZO_Help_MechanicAssistance_Gamepad:GetDetailsInstructions()
    return self.detailsInstructions
end
function ZO_Help_MechanicAssistance_Gamepad:SetDetailsInstructions(detailsInstructions)
    self.detailsInstructions = detailsInstructions
end
function ZO_Help_MechanicAssistance_Gamepad:GoToDetailsSourceScene()
    assert(false) --Must be overriden
end
function ZO_Help_MechanicAssistance_Gamepad:RegisterDetails()
    assert(false) -- Must be overriden
end
function ZO_Help_MechanicAssistance_Gamepad:GetDisplayedDetails()
    local savedDetails = self:GetSavedField(ZO_HELP_TICKET_FIELD_TYPE.DETAILS)
    return savedDetails or self.detailsInstructions
end
function ZO_Help_MechanicAssistance_Gamepad:InitWithDetails(detailsData)
    self:ResetTicket()
    self:SetDetailsData(detailsData)
    self:ChangeTicketState(ZO_HELP_TICKET_STATE.FIELD_ENTRY)
end
function ZO_Help_MechanicAssistance_Gamepad:SetDetailsData(detailsData)
    self:SetSavedField(ZO_HELP_TICKET_FIELD_TYPE.DETAILS, detailsData, LIST_REFRESH_VISIBLE)
end