Back to Home

ESO Lua File v101038

ingame/housingeditor/gamepad/housingpathsettings_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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
ZO_HousingPathSettings_Gamepad = ZO_Gamepad_ParametricList_Screen:Subclass()
function ZO_HousingPathSettings_Gamepad:New(...)
    return ZO_Gamepad_ParametricList_Screen.New(self, ...)
end
function ZO_HousingPathSettings_Gamepad:Initialize(control)
end
function ZO_HousingPathSettings_Gamepad:InitializeControls(control)
    GAMEPAD_HOUSING_PATH_SETTINGS_SCENE = ZO_Scene:New("gamepad_housing_path_settings", SCENE_MANAGER)
    local ACTIVATE_ON_SHOW = true
    ZO_Gamepad_ParametricList_Screen.Initialize(self, control, ZO_GAMEPAD_HEADER_TABBAR_DONT_CREATE, ACTIVATE_ON_SHOW, GAMEPAD_HOUSING_PATH_SETTINGS_SCENE)
    GAMEPAD_HOUSING_PATH_SETTINGS_FRAGMENT = ZO_SimpleSceneFragment:New(control)
    SYSTEMS:RegisterGamepadObject("path_settings", self)
    SYSTEMS:RegisterGamepadRootScene("housing_path_settings", GAMEPAD_HOUSING_PATH_SETTINGS_SCENE)
end
function ZO_HousingPathSettings_Gamepad:InitializeHeader()
    self.headerData =
    {
        titleText = GetString(SI_HOUSING_EDITOR_PATH_SETTINGS),
        messageText = "",
    }
    ZO_GamepadGenericHeader_SetDataLayout(self.header, ZO_GAMEPAD_HEADER_LAYOUTS.DATA_PAIRS_SEPARATE)
end
function ZO_HousingPathSettings_Gamepad:InitializeKeybindStripDescriptors()
    local list = self:GetMainList()
    self.keybindStripDescriptor =
    {
        {
            alignment = KEYBIND_STRIP_ALIGN_LEFT,
            keybind = "UI_SHORTCUT_PRIMARY",
            name = function()
                if self:IsMainListActive() then
                    local data = list:GetSelectedData()
                    if data.callbackLabel then
                        return data.callbackLabel
                    end
                end
                return GetString(SI_GAMEPAD_SELECT_OPTION)
            end,
            visible = function()
                if self:IsMainListActive() then
                    local data = list:GetSelectedData()
                    if data and data.callback then
                        return true
                    end
                    return false
                else
                    local currentList = self:GetCurrentList()
                    return currentList and not currentList:IsEmpty()
                end
            end,
            callback = function()
                if self:IsMainListActive() then
                    local data = list:GetSelectedData()
                    if data and data.callback then
                        data.callback()
                    end
                else
                    self:OnSelectTargetObject()
                end
            end,
        },
    }
    local function OnClickCallback()
        if self:IsMainListActive() then
            SCENE_MANAGER:HideCurrentScene()
        else
            self:ShowMainList()
        end
    end
    ZO_Gamepad_AddBackNavigationKeybindDescriptorsWithSound(self.keybindStripDescriptor, GAME_NAVIGATION_TYPE_BUTTON, OnClickCallback)
end
function ZO_HousingPathSettings_Gamepad:InitializeLists()
    local ALLOW_EVEN_IF_DISABLED = true
    local NO_ANIMATION = true
    local function SetupPathStateControl(control, data, selected, reselectingDuringRebuild, enabled, active)
        local function OnToggled()
        end
        data.text = GetString(data.generalInfo.text)
        data.callbackLabel = GetString(SI_GAMEPAD_TOGGLE_OPTION)
        data.callback = OnToggled
        ZO_GamepadCheckBoxTemplate_Setup(control, data, selected, reselectingDuringRebuild, enabled, active)
        if HousingEditorGetSelectedFurniturePathState() == HOUSING_FURNITURE_PATH_STATE_ON then
            ZO_CheckButton_SetChecked(control.checkBox)
        else
            ZO_CheckButton_SetUnchecked(control.checkBox)
        end
    end
    local function SetupConformToGroundControl(control, data, selected, reselectingDuringRebuild, enabled, active)
        local function OnToggled()
        end
        data.text = GetString(data.generalInfo.text)
        data.callbackLabel = GetString(SI_GAMEPAD_TOGGLE_OPTION)
        data.callback = OnToggled
        ZO_GamepadCheckBoxTemplate_Setup(control, data, selected, reselectingDuringRebuild, enabled, active)
            ZO_CheckButton_SetChecked(control.checkBox)
        else
            ZO_CheckButton_SetUnchecked(control.checkBox)
        end
    end
    
    local function SetupCheckboxControl(control, data, selected, reselectingDuringRebuild, enabled, active)
        if data.index == ZO_HOUSING_PATH_SETTINGS_CONTROL_DATA_PATHING_STATE then
            SetupPathStateControl(control, data, selected, reselectingDuringRebuild, enabled, active)
        else
            SetupConformToGroundControl(control, data, selected, reselectingDuringRebuild, enabled, active)
        end
    end
    local function SetupPathTypeControl(control, data, selected, reselectingDuringRebuild, enabled, active)
        local label = control:GetNamedChild("Name")
        local color = selected and ZO_SELECTED_TEXT or ZO_DISABLED_TEXT
        local r, g, b, a = color:UnpackRGBA()
        label:SetColor(r, g, b, 1)
        label:SetText(GetString(data.generalInfo.text))
        
        control.horizontalListObject:Clear()
        local horizontalList = control.horizontalListObject
        for optionValue = PATH_FOLLOW_TYPE_ITERATION_BEGIN, PATH_FOLLOW_TYPE_ITERATION_END do
            if optionValue == PATH_FOLLOW_TYPE_ONE_WAY then
                -- skip this for now, it is not supported
            else
                local entryData = 
                {
                    text = GetString("SI_PATHFOLLOWTYPE", optionValue),
                    value = optionValue,
                    parentControl = control
                }
                horizontalList:AddEntry(entryData)
            end
        end
        horizontalList:SetOnSelectedDataChangedCallback(nil)
        horizontalList:SetSelectedFromParent(selected)
        horizontalList:Commit()
        horizontalList:SetActive(selected)
        local selectedValue = HousingEditorGetSelectedFurniturePathFollowType()
        local selectedIndex = selectedValue + 1
        horizontalList:SetSelectedDataIndex(selectedIndex, ALLOW_EVEN_IF_DISABLED, NO_ANIMATION)
        local function OnSelectionChanged(selectedData, oldData, reselectingDuringRebuild)
            if selectedData then
                local result = HousingEditorSetSelectedFurniturePathFollowType(selectedData.value)
                ZO_AlertEvent(EVENT_HOUSING_EDITOR_REQUEST_RESULT, result)
            end
        end
        horizontalList:SetOnSelectedDataChangedCallback(OnSelectionChanged)
    end
    local function SetupChangeCollectibleControl(control, data, selected, reselectingDuringRebuild, enabled, active)
        data.callback = function()
            self:ShowChangeObjectList()
        end
        data.text = GetString(data.generalInfo.buttonText)
        ZO_SharedGamepadEntry_OnSetup(control, data, selected, reselectingDuringRebuild, enabled, active)
    end
    self.mainList = self:GetMainList()
    self.mainList:AddDataTemplate("ZO_GamepadFullWidthLabelEntryTemplate", SetupChangeCollectibleControl)
    self.mainList:SetOnTargetDataChangedCallback(function(...) self:OnSettingsTargetChanged(...) end)
    self.changeObjectList = self:AddList("changeObject")
    local USE_DEFAULT_COMPARISON = nil
    self.changeObjectList:AddDataTemplateWithHeader("ZO_GamepadItemEntryTemplate", ZO_SharedGamepadEntry_OnSetup, ZO_GamepadMenuEntryTemplateParametricListFunction, USE_DEFAULT_COMPARISON, "ZO_GamepadMenuEntryHeaderTemplate")
    self.changeObjectList:SetNoItemText(GetString(SI_ANTIQUITY_EMPTY_LIST))
    local function OnHouseChanged()
        -- Refresh the Option List to show/hide the Change Object entry as appropriate.
        self.dirty = true
    end
    HOUSING_EDITOR_STATE:RegisterCallback("HouseChanged", OnHouseChanged)
end
function ZO_HousingPathSettings_Gamepad:OnSettingsTargetChanged(list, targetData, oldTargetData)
    GAMEPAD_TOOLTIPS:ClearTooltip(GAMEPAD_LEFT_TOOLTIP)
    if targetData and targetData.generalInfo then
        targetData.generalInfo.tooltipFunction()
    end
end
function ZO_HousingPathSettings_Gamepad:RefreshOptionList()
    self.mainList:Clear()
    for controlTypeIndex, controlInfo in ipairs(ZO_HOUSING_PATH_SETTINGS_CONTROL_DATA) do
        if controlInfo.visible == nil or controlInfo.visible() then
            local entry = ZO_GamepadEntryData:New(GetString(controlInfo.text))
            entry.generalInfo = controlInfo
            entry.index = controlTypeIndex
            self.mainList:AddEntry(controlInfo.gamepadTemplate, entry)
        end
    end
    self.mainList:Commit()
end
function ZO_HousingPathSettings_Gamepad:RefreshChangeObjectList()
    local objectList = self.changeObjectList
    objectList:Clear()
    local categoryTreeData = self:GetPathableFurnitureCategoryTreeData()
    if categoryTreeData then
        local allTopLevelCategories = categoryTreeData:GetAllSubcategories()
        for categoryIndex, categoryData in ipairs(allTopLevelCategories) do
            for subcategoryIndex, subcategoryData in ipairs(categoryData:GetAllSubcategories()) do
                for furnitureIndex, furnitureData in ipairs(subcategoryData:GetAllEntries()) do
                    local furnitureEntry = ZO_GamepadEntryData:New(furnitureData:GetFormattedName(), furnitureData:GetIcon())
                    furnitureEntry.furnitureId = furnitureData.furnitureId
                    furnitureEntry.collectibleId = furnitureData.collectibleId
                    if furnitureIndex == 1 then
                        local formattedCategoryName = string.format("%s - %s (%d)", categoryData:GetName(), subcategoryData:GetName(), subcategoryData:GetNumEntryItemsRecursive())
                        furnitureEntry:SetHeader(formattedCategoryName)
                        objectList:AddEntry("ZO_GamepadItemEntryTemplateWithHeader", furnitureEntry)
                    else
                        objectList:AddEntry("ZO_GamepadItemEntryTemplate", furnitureEntry)
                    end
                end
            end
        end
    end
    objectList:SetNoItemText(GetString(SI_HOUSING_FURNITURE_NO_PATHABLE_FURNITURE))
    objectList:Commit()
    return objectList:IsEmpty()
end    
function ZO_HousingPathSettings_Gamepad:PerformUpdate()
    self:RefreshHeader()
    self.dirty = false
end
function ZO_HousingPathSettings_Gamepad:OnHiding()
    ZO_Gamepad_ParametricList_Screen.OnHiding(self)
end
function ZO_HousingPathSettings_Gamepad:DeactivateSelectedControl()
    local selectedControl = self.mainList:GetSelectedControl()
    if selectedControl and selectedControl.horizontalListObject then
        selectedControl.horizontalListObject:Deactivate()
    end
end
function ZO_HousingPathSettings_Gamepad:RefreshHeader()
    if self:IsMainListActive() then
        local itemName, icon, furnitureDataId = GetPlacedHousingFurnitureInfo(HousingEditorGetSelectedFurnitureId())
        if itemName and itemName ~= "" then
            self.headerData.messageText = zo_strformat(SI_HOUSING_FURNITURE_NAME_FORMAT, itemName)
        else
            self.headerData.messageText = ""
        end
        self.headerData.titleText = GetString(SI_HOUSING_EDITOR_PATH_SETTINGS)
    else
        self.headerData.titleText = GetString(SI_HOUSING_PATH_SETTINGS_CHANGE_COLLECTIBLE_TEXT)
    end
end
function ZO_HousingPathSettings_Gamepad:OnSelectTargetObject()
    local list = self:GetCurrentList()
    if list then
        local data = list:GetTargetData()
        if data then
            local currentFurnitureId = HousingEditorGetSelectedFurnitureId()
            local newCollectibleId = data.collectibleId
            SCENE_MANAGER:HideCurrentScene()
            HousingEditorRequestModeChange(HOUSING_EDITOR_MODE_SELECTION)
            local result = HousingEditorRequestReplacePathCollectible(currentFurnitureId, newCollectibleId)
            ZO_AlertEvent(EVENT_HOUSING_EDITOR_REQUEST_RESULT, result)
        end
    end
end
function ZO_HousingPathSettings_Gamepad:IsMainListActive()
    local currentList = self:GetCurrentList()
    return currentList == self:GetMainList()
end
function ZO_HousingPathSettings_Gamepad:ShowMainList()
    self:RefreshHeader()
end
function ZO_HousingPathSettings_Gamepad:ShowChangeObjectList()
    self:SetCurrentList("changeObject")
    self:RefreshHeader()
end
function ZO_HousingPathSettings_Gamepad:GetPathableFurnitureCategoryTreeData()
    return SHARED_FURNITURE:GetPathableFurnitureCategoryTreeData()
end
function ZO_HousingPathSettings_Gamepad:SetPathData()
    self:Update()
end
function ZO_HousingPathSettings_Gamepad:ShowPathTypeTooltip()
    local title = GetString(SI_HOUSING_PATH_SETTINGS_PATHING_TYPE_TEXT)
    local body = GetString(SI_HOUSING_PATH_SETTINGS_PATHING_TYPE_TOOLTIP)
    GAMEPAD_TOOLTIPS:LayoutTitleAndDescriptionTooltip(GAMEPAD_LEFT_TOOLTIP, title, body)
end
function ZO_HousingPathSettings_Gamepad:ShowPathingStateTooltip()
    local title = GetString(SI_HOUSING_PATH_SETTINGS_PATHING_STATE_TEXT)
    local body = GetString(SI_HOUSING_PATH_SETTINGS_PATHING_STATE_TOOLTIP)
    GAMEPAD_TOOLTIPS:LayoutTitleAndDescriptionTooltip(GAMEPAD_LEFT_TOOLTIP, title, body)
end
function ZO_HousingPathSettings_Gamepad:ShowConformToGroundTooltip()
    local title = GetString(SI_HOUSING_PATH_SETTINGS_CONFORM_TO_GROUND_TEXT)
    local body = GetString(SI_HOUSING_PATH_SETTINGS_CONFORM_TO_GROUND_TOOLTIP)
    GAMEPAD_TOOLTIPS:LayoutTitleAndDescriptionTooltip(GAMEPAD_LEFT_TOOLTIP, title, body)
end
function ZO_HousingPathSettings_Gamepad:ShowChangeCollectibleTooltip()
    local title = GetString(SI_HOUSING_PATH_SETTINGS_CHANGE_COLLECTIBLE_BUTTON_TEXT)
    local body = GetString(SI_HOUSING_PATH_SETTINGS_CHANGE_COLLECTIBLE_TOOLTIP)
    GAMEPAD_TOOLTIPS:LayoutTitleAndDescriptionTooltip(GAMEPAD_LEFT_TOOLTIP, title, body)
end
-- Global UI
    GAMEPAD_HOUSING_PATH_SETTINGS = ZO_HousingPathSettings_Gamepad:New(control)
end