Back to Home

ESO Lua File v100032

ingame/housingeditor/keyboard/housingpathsettings_keyboard.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
365
366
367
368
369
370
371
372
373
-- Path Settings Menu
----------------------
ZO_HousingPathSettingsMenu_Keyboard = ZO_Object:Subclass()
function ZO_HousingPathSettingsMenu_Keyboard:New(...)
    local menu = ZO_Object.New(self)
    menu:Initialize(...)
    return menu
end
function ZO_HousingPathSettingsMenu_Keyboard:Initialize(control)
    self.control = control
    KEYBOARD_HOUSING_PATH_SETTINGS_SCENE = ZO_Scene:New("keyboard_housing_path_settings_scene", SCENE_MANAGER)
    KEYBOARD_HOUSING_PATH_SETTINGS_SCENE:RegisterCallback("StateChange", function(oldState, newState)
        if newState == SCENE_SHOWING then
            KEYBIND_STRIP:RemoveDefaultExit()
            KEYBIND_STRIP:AddKeybindButtonGroup(self.exitKeybindButtonStripDescriptor)
            self:OnShowing()
        elseif newState == SCENE_HIDING then
            KEYBIND_STRIP:RemoveKeybindButtonGroup(self.exitKeybindButtonStripDescriptor)
            KEYBIND_STRIP:RestoreDefaultExit()
        end
    end)
    self.exitKeybindButtonStripDescriptor =
    {
        alignment = KEYBIND_STRIP_ALIGN_RIGHT,
        {
            name = GetString(SI_EXIT_BUTTON),
            keybind = "UI_SHORTCUT_EXIT",
            callback = function()
                    if self.currentPanel == self.pathSettingsPanel then
                        SCENE_MANAGER:HideCurrentScene()
                    else
                        self:ShowPathSettingsPanel()
                    end
                end,
        },
    }
    self.pathSettingsPanel = ZO_HousingPathSettings_Keyboard:New(ZO_HousingPathSettingsPanel_KeyboardTopLevel, self)
    self.changeObjectPanel = ZO_HousingPathChangeObject_Keyboard:New(ZO_HousingPathChangeObject_KeyboardTopLevel, self)
    self.pathableListDirty = true
    -- placeable and pathable furniture is updated in tandum
    SHARED_FURNITURE:RegisterCallback("PlaceableFurnitureChanged", function()
        if SCENE_MANAGER:IsShowing("keyboard_housing_path_settings_scene") then
            self.changeObjectPanel:UpdateChangeObjectPanel()
        else
            self.pathableListDirty = true
        end
    end)
    HOUSING_EDITOR_HUD_SCENE_GROUP:AddScene("keyboard_housing_path_settings_scene")
    SYSTEMS:RegisterKeyboardObject("path_settings", self)
    SYSTEMS:RegisterKeyboardRootScene("housing_path_settings", KEYBOARD_HOUSING_PATH_SETTINGS_SCENE)
end
function ZO_HousingPathSettingsMenu_Keyboard:OnShowing()
    self.pathSettingsPanel:UpdatePathSettings()
    
    if self.pathableListDirty then
        self.changeObjectPanel:UpdateChangeObjectPanel()
        self.pathableListDirty = false
    end
    self.changeObjectPanel:UpdateSearchText()
    SCENE_MANAGER:AddFragment(self.pathSettingsPanel:GetFragment())
    self.currentPanel = self.pathSettingsPanel
end
function ZO_HousingPathSettingsMenu_Keyboard:SetPathData(furnitureId)
    self.targetFurnitureId = furnitureId
end
function ZO_HousingPathSettingsMenu_Keyboard:ShowChangeObjectPanel()
    SCENE_MANAGER:RemoveFragment(self.pathSettingsPanel:GetFragment())
    SCENE_MANAGER:AddFragment(self.changeObjectPanel:GetFragment())
    self.currentPanel = self.changeObjectPanel
end
function ZO_HousingPathSettingsMenu_Keyboard:ShowPathSettingsPanel()
    SCENE_MANAGER:AddFragment(self.pathSettingsPanel:GetFragment())
    SCENE_MANAGER:RemoveFragment(self.changeObjectPanel:GetFragment())
    self.currentPanel = self.pathSettingsPanel
end
function ZO_HousingPathSettingsMenu_Keyboard:ShowChangeCollectibleTooltip(control)
    --TODO: show tooltip
end
function ZO_HousingPathSettingsMenu_Keyboard:ShowPathingStateTooltip(control)
    --TODO: show tooltip
end
function ZO_HousingPathSettingsMenu_Keyboard:ShowPathTypeTooltip(control)
    --TODO: show tooltip
end
-- Path Settings Panel
----------------------
ZO_HousingPathSettings_Keyboard = ZO_HousingBrowserList:Subclass()
function ZO_HousingPathSettings_Keyboard:New(...)
    return ZO_HousingBrowserList.New(self, ...)
end
function ZO_HousingPathSettings_Keyboard:Initialize(...)
    ZO_HousingBrowserList.Initialize(self, ...)
    self.settingsTreeData = ZO_RootFurnitureCategory:New()
        
    for name, topLevelSetting in pairs(ZO_PATH_SETTINGS) do
        local subsettingsTreeData = ZO_FurnitureCategory:New(self.settingsTreeData, name)
        self.settingsTreeData:AddSubcategory(name, subsettingsTreeData)
        for _, i in pairs(topLevelSetting) do
            subsettingsTreeData:AddSubcategory(i, ZO_FurnitureCategory:New(subsettingsTreeData, i))
        end
    end
end
function ZO_HousingPathSettings_Keyboard:InitializeSettingsPanel()
    self.categoryIndexToPanel = {}
    self.generalOptionsPanel = self.contents:GetNamedChild("General")
    self.activePanel = self.generalOptionsPanel
    self.generalOptionsScrollList = self.generalOptionsPanel:GetNamedChild("Settings")
    local generalOptionsScrollChild = GetControl(self.generalOptionsScrollList, "ScrollChild")
    local function OnChangeCollectibleClicked(button)
        KEYBOARD_HOUSING_PATH_SETTINGS:ShowChangeObjectPanel()
    end
    self:SetupTitleText()
    self.changeCollectibleSetting = self.generalOptionsPanel:GetNamedChild("ChangeCollectible")
    self.changeCollectibleSetting:SetParent(generalOptionsScrollChild)
    self.changeCollectibleButton = self.changeCollectibleSetting:GetNamedChild("Button")
    self.changeCollectibleButton:SetHandler("OnClicked", OnChangeCollectibleClicked)
    local changeCollectibleButtonLabel = self.changeCollectibleButton:GetLabelControl()
    changeCollectibleButtonLabel:SetWrapMode(TEXT_WRAP_MODE_ELLIPSIS)
    self.pathingStateOnButton = self.generalOptionsPanel:GetNamedChild("ChangePathingStateOn")
    local onButtonLabel = self.pathingStateOnButton:GetNamedChild("Label")
    onButtonLabel:SetText(GetString("SI_FURNITUREPATHSTATE", HOUSING_FURNITURE_PATH_STATE_ON))
    self.pathingStateOnButton.pathState = HOUSING_FURNITURE_PATH_STATE_ON
    self.pathingStateOffButton = self.generalOptionsPanel:GetNamedChild("ChangePathingStateOff")
    local offButtonLabel = self.pathingStateOffButton:GetNamedChild("Label")
    offButtonLabel:SetText(GetString("SI_FURNITUREPATHSTATE", HOUSING_FURNITURE_PATH_STATE_OFF))
    self.pathingStateOffButton.pathState = HOUSING_FURNITURE_PATH_STATE_OFF
    self.radioButtonGroup = ZO_RadioButtonGroup:New()
    self.radioButtonGroup:Add(self.pathingStateOnButton)
    self.radioButtonGroup:Add(self.pathingStateOffButton)
    self.radioButtonGroup:SetSelectionChangedCallback(function(radioButtonGroup, newControl, previousControl)
        if newControl.pathState ~= self.currentPathState then
            self.selectedPathState = newControl.pathState
            local result = HousingEditorToggleSelectedFurniturePathState()
            ZO_AlertEvent(EVENT_HOUSING_EDITOR_REQUEST_RESULT, result)
        end
    end)
    self.changePathingStateDropDown = self.generalOptionsPanel:GetNamedChild("ChangePathTypeDropDown")
    self:BuildPathTypeSettings(self.changePathingStateDropDown)
end
function ZO_HousingPathSettings_Keyboard:SetupTitleText()
    self:SetTitleTextFromData("ChangeCollectibleTitle")
    self:SetTitleTextFromData("ChangePathingStateTitle")
    self:SetTitleTextFromData("ChangePathTypeTitle")
end
function ZO_HousingPathSettings_Keyboard:SetTitleTextFromData(labelName)
    local titleControl = self.generalOptionsPanel:GetNamedChild(labelName)
    titleControl:SetText(GetString(titleControl.data.text))
end
function ZO_HousingPathSettings_Keyboard:InitializeKeybindStrip()
    self.keybindStripDescriptor =
    {
    }
end
function ZO_HousingPathSettings_Keyboard:UpdatePathSettings()
    self:UpdateButtonSettings(self.changeCollectibleSetting)
    self.changeCollectibleButton:SetEnabled(true)
    self.currentPathState = HousingEditorGetSelectedFurniturePathState(self.owner.targetFurnitureId)
    self.selectedPathState = self.currentPathState
    local selectedRadioButton = self.currentPathState == HOUSING_FURNITURE_PATH_STATE_ON and self.pathingStateOnButton or self.pathingStateOffButton
    self.radioButtonGroup:SetClickedButton(selectedRadioButton)
    self.currentFollowType = HousingEditorGetSelectedFurniturePathFollowType()
    self.selectedFollowType = self.currentFollowType
    self.comboBox:SetSelectedItemText(GetString("SI_PATHFOLLOWTYPE", self.currentFollowType))
end
function ZO_HousingPathSettings_Keyboard:UpdateButtonSettings(control)
    local data = control.data
    local buttonControl = GetControl(control, "Button")
    local nameControl = GetControl(control, "Name")
    local buttonText = GetString(data.buttonText)
    buttonControl:SetText(buttonText)
    local furnitureName = GetPlacedHousingFurnitureInfo(self.owner.targetFurnitureId)
    local labelText = zo_strformat(SI_HOUSING_FURNITURE_NAME_FORMAT, furnitureName)
    nameControl:SetText(labelText)
end
function ZO_HousingPathSettings_Keyboard:BuildPathTypeSettings(dropDownControl)
    local comboBox = ZO_ComboBox_ObjectFromContainer(dropDownControl)
    self.comboBox = comboBox
    comboBox:SetSortsItems(false)
    local function OnFollowTypeSelected(_, entryText, entry)
        comboBox:SetSelectedItemText(entry.name)
        HousingEditorSetSelectedFurniturePathFollowType(entry.followType)
        self.selectedFollowType = entry.followType
    end
    for i = PATH_FOLLOW_TYPE_ITERATION_BEGIN, PATH_FOLLOW_TYPE_ITERATION_END do
        if i == PATH_FOLLOW_TYPE_ONE_WAY then
            -- skip this for now, it is not supported
        else
            local entry = comboBox:CreateItemEntry(GetString("SI_PATHFOLLOWTYPE", i), OnFollowTypeSelected)
            entry.followType = i
            comboBox:AddItem(entry)
        end
    end
end
function ZO_HousingPathSettings_Keyboard:GetCategoryTreeData()
    return self.settingsTreeData
end
function ZO_HousingPathSettings_Keyboard:OnCategorySelected(data)
    --TODO: update panel from category data selected
end
function ZO_HousingPathSettings_Keyboard:GetCategoryInfo(categoryIndex)
    local normalIcon, pressedIcon, mouseoverIcon
    if categoryIndex == 0 then
        normalIcon = "EsoUI/Art/Housing/Keyboard/path_settings_icon_up.dds"
        pressedIcon = "EsoUI/Art/Housing/Keyboard/path_settings_icon_down.dds"
        mouseoverIcon = "EsoUI/Art/Housing/Keyboard/path_settings_icon_up.dds"
    end
    return GetString("SI_HOUSEPATHSETTINGCATEGORIES", categoryIndex), normalIcon, pressedIcon, mouseoverIcon
end
-- Change Object Panel
-----------------------
ZO_HousingPathChangeObject_Keyboard = ZO_HousingFurnitureList:Subclass()
function ZO_HousingPathChangeObject_Keyboard:New(...)
    return ZO_HousingFurnitureList.New(self, ...)
end
function ZO_HousingPathChangeObject_Keyboard:InitializeKeybindStrip()
    self.keybindStripDescriptor =
    {
        alignment = KEYBIND_STRIP_ALIGN_CENTER,
        {
            name = GetString(SI_HOUSING_EDITOR_REPLACE_OBJECT),
            keybind = "UI_SHORTCUT_PRIMARY",
            callback = function()
                local mostRecentlySelectedData = self:GetMostRecentlySelectedData()
                self:ReplaceWithCollectible(mostRecentlySelectedData.collectibleId)
            end,
            enabled = function()
                return self:GetMostRecentlySelectedData() ~= nil
            end,
        },
        {
            name = GetString(SI_CRAFTING_EXIT_PREVIEW_MODE),
            keybind = "UI_SHORTCUT_NEGATIVE",
            callback = function()
                self:ClearSelection()
            end,
            visible = function()
                local hasSelection = self:GetMostRecentlySelectedData() ~= nil and IsCurrentlyPreviewing()
                return hasSelection
            end,
        },
    }
end
function ZO_HousingPathChangeObject_Keyboard:ReplaceWithCollectible(collectibleId)
    SCENE_MANAGER:HideCurrentScene()
    HousingEditorRequestModeChange(HOUSING_EDITOR_MODE_SELECTION)
    local result = HousingEditorRequestReplacePathCollectible(self.owner.targetFurnitureId, collectibleId)
    ZO_AlertEvent(EVENT_HOUSING_EDITOR_REQUEST_RESULT, result)
end
function ZO_HousingPathChangeObject_Keyboard:OnSearchTextChanged(editBox)
    ZO_HousingFurnitureList.OnSearchTextChanged(self, editBox)
    SHARED_FURNITURE:SetPlaceableTextFilter(editBox:GetText())
end
function ZO_HousingPathChangeObject_Keyboard:AddListDataTypes()
    local function IsFurnitureCollectibleBlacklisted(collectibleId)
        if collectibleId then
            local collectibleData = ZO_COLLECTIBLE_DATA_MANAGER:GetCollectibleDataById(collectibleId)
            return collectibleData and collectibleData:IsBlacklisted()
        end
        return false
    end
    self.PathableFurnitureOnMouseClickCallback = function(control, buttonIndex, upInside)
        if buttonIndex == MOUSE_BUTTON_INDEX_LEFT and upInside then
            if control.furnitureObject and IsFurnitureCollectibleBlacklisted(control.furnitureObject.collectibleId) then
                ZO_AlertEvent(EVENT_HOUSING_EDITOR_REQUEST_RESULT, HOUSING_REQUEST_RESULT_BLOCKED_BY_BLACKLISTED_COLLECTIBLE)
            else
                ZO_ScrollList_MouseClick(self:GetList(), control)
            end
        end
    end
    self.PathableFurnitureOnMouseDoubleClickCallback = function(control, buttonIndex)
        if buttonIndex == MOUSE_BUTTON_INDEX_LEFT then
            if control.furnitureObject and IsFurnitureCollectibleBlacklisted(control.furnitureObject.collectibleId) then
                ZO_AlertEvent(EVENT_HOUSING_EDITOR_REQUEST_RESULT, HOUSING_REQUEST_RESULT_BLOCKED_BY_BLACKLISTED_COLLECTIBLE)
            else
                local data = ZO_ScrollList_GetData(control)
                self:ReplaceWithCollectible(data.collectibleId)
            end
        end
    end
    self:AddDataType(ZO_PLACEABLE_HOUSING_DATA_TYPE, "ZO_PlayerFurnitureSlot", ZO_HOUSING_FURNITURE_LIST_ENTRY_HEIGHT, function(...) self:SetupFurnitureRow(...) end, ZO_HousingFurnitureBrowser_Keyboard.OnHideFurnitureRow)
end
function ZO_HousingPathChangeObject_Keyboard:SetupFurnitureRow(control, data)
end
function ZO_HousingPathChangeObject_Keyboard:UpdateChangeObjectPanel()
    self:UpdateLists()
end
function ZO_HousingPathChangeObject_Keyboard:UpdateSearchText()
    self.searchEditBox:SetText(SHARED_FURNITURE:GetPlaceableTextFilter())
end
function ZO_HousingPathChangeObject_Keyboard:GetCategoryTreeData()
    return SHARED_FURNITURE:GetPathableFurnitureCategoryTreeData()
end
function ZO_HousingPathChangeObject_Keyboard:GetNoItemText()
    if SHARED_FURNITURE:DoesPlayerHavePathableFurniture() then
        return GetString(SI_HOUSING_FURNITURE_NO_SEARCH_RESULTS)
    else
        return GetString(SI_HOUSING_FURNITURE_NO_PATHABLE_FURNITURE)
    end
end
-- XML Functions
-------------------
    KEYBOARD_HOUSING_PATH_SETTINGS = ZO_HousingPathSettingsMenu_Keyboard:New(control)
end