forked from AssemblerManiac/InventoryInsight
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInventoryInsight_SceneFuncs.lua
159 lines (137 loc) · 5.72 KB
/
InventoryInsight_SceneFuncs.lua
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
-- scene related functions (show/hide/determine/register)
function IIfA:GetCurrentSceneName()
local ret = IIfA.EMPTY_STRING
-- [16:20] scene name: 65553, hidden: false
if not SCENE_MANAGER or not SCENE_MANAGER:GetCurrentScene() then
ret = "hud"
elseif SCENE_MANAGER:GetCurrentScene().name == "hudui" then
ret = "hud"
else
ret = SCENE_MANAGER:GetCurrentScene().name
end
if tostring(ret) == "65553" then ret = "hud" end
if ret == "inventory" and KEYBOARD_QUICKSLOT_FRAGMENT:IsHidden() == false then
ret = ret .. "_quickslots"
end
--IIfA:DebugOut("Get Current Scene Name: '<<1>>', '<<2>>'", SCENE_MANAGER:GetCurrentScene().name, ret)
return ret
end
function IIfA:RegisterForSceneChanges()
local scenes = IIFA_DATABASE[IIfA.currentAccount].characters[IIfA.currentCharacterId].frameSettings
for sceneName, settings in pairs(scenes) do
if (sceneName ~= "hudui") then
local scene = SCENE_MANAGER:GetScene(sceneName)
if scene then
scene:RegisterCallback("StateChange", function(...)
IIfA:ProcessSceneChange(sceneName, ...)
end)
end
-- For reasons unknown, hudui doesn't always appear to be "found" for items in the list
-- (get cur scene from scene_manager sometimes says hud, when it's hudui), force it to work same as HUD here
if (sceneName == "hud") then
local scene = SCENE_MANAGER:GetScene("hudui")
if scene then
scene:RegisterCallback("StateChange", function(...)
IIfA:ProcessSceneChange(sceneName, ...)
end)
end
end
end
end
INVENTORY_FRAGMENT:RegisterCallback("StateChange", function(...)
IIfA:ProcessInventoryTabChange("", ...)
end)
CRAFT_BAG_FRAGMENT:RegisterCallback("StateChange", function(...)
IIfA:ProcessInventoryTabChange("", ...)
end)
WALLET_FRAGMENT:RegisterCallback("StateChange", function(...)
IIfA:ProcessInventoryTabChange("", ...)
end)
KEYBOARD_QUICKSLOT_FRAGMENT:RegisterCallback("StateChange", function(...)
IIfA:ProcessInventoryTabChange("_quickslots", ...)
end)
end
function IIfA:GetSceneSettings(sceneName)
sceneName = sceneName or IIfA:GetCurrentSceneName()
local settings = IIFA_DATABASE[IIfA.currentAccount].characters[IIfA.currentCharacterId].frameSettings
if not settings[sceneName] then
-- If we have to create a new set of scene info, register it in the scene change too
-- It will be set again during the next opening
local scene = SCENE_MANAGER:GetScene(sceneName)
if scene then
scene:RegisterCallback("StateChange", function(...)
IIfA:ProcessSceneChange(sceneName, ...)
end)
end
-- Save the settings in the settings table, base it on HUD
settings[sceneName] = ZO_DeepTableCopy(settings["hud"])
settings[sceneName].hidden = true
settings[sceneName].docked = false
end
IIfA:DebugOut("GetSceneSettings: name=<<1>>, hidden=<<2>>", sceneName, tostring(settings[sceneName].hidden))
return settings[sceneName]
end
function IIfA:ProcessSceneChange(sceneName, oldState, newState)
IIfA:DebugOut("ProcessSceneChange <<1>>: <<2>> -> <<3>>", sceneName, oldState, newState)
-- IIfA:DebugOut("scene.disallowEvaluateTransitionCompleteCount = <<1>>", SCENE_MANAGER:GetCurrentScene().disallowEvaluateTransitionCompleteCount)
if SCENE_SHOWN == newState then
sceneName = IIfA:GetCurrentSceneName()
if sceneName == "inventory" then
if not KEYBOARD_QUICKSLOT_FRAGMENT:IsHidden() then
sceneName = sceneName .. "_quickslots"
end
end
local settings = IIfA:GetSceneSettings(sceneName)
self:RePositionFrame(settings)
elseif SCENE_HIDDEN == newState then
IIFA_GUI:SetHidden(true)
end
end
function IIfA:ProcessInventoryTabChange(tabName, oldState, newState)
IIfA:DebugOut("ProcessInventoryTabChange <<1>>: <<2>> -> <<3>>", tabName, oldState, newState)
local sceneName = IIfA:GetCurrentSceneName()
if sceneName:find("inventory") == nil then return end
if newState == SCENE_SHOWN then
sceneName = "inventory" .. tabName
local settings = IIfA:GetSceneSettings(sceneName)
self:RePositionFrame(settings)
elseif SCENE_HIDDEN == newState then
IIFA_GUI:SetHidden(true)
end
end
function IIfA:SaveFrameInfo(calledFrom)
IIfA:DebugOut("SaveFrameInfo: <<1>>", calledFrom)
if (calledFrom == "onHide") then return end
local sceneName = IIfA:GetCurrentSceneName()
-- Additional check to skip saving if scene is housingEditorHudUI or housingEditorHud
if (sceneName == "housingEditorHudUI" or sceneName == "housingEditorHud") then
IIfA:DebugOut("Don't Save because we are in : <<1>>", sceneName)
return
end
local settings = IIfA:GetSceneSettings(sceneName)
settings.hidden = IIFA_GUI:IsControlHidden()
IIfA:DebugOut("SaveFrameInfo scene: <<1>>, hidden=<<2>>", sceneName, tostring(settings.hidden))
if (not settings.docked and (calledFrom == "onMoveStop" or calledFrom == "onResizeStop")) then
settings.lastX = IIFA_GUI:GetLeft()
settings.lastY = IIFA_GUI:GetTop()
if not settings.minimized then
settings.width = IIFA_GUI:GetWidth()
settings.height = IIFA_GUI:GetHeight()
end
end
end
-- called from bindings.xml on keypress, and on /iifa toggle chat cmd
function IIfA:ToggleInventoryFrame()
IIFA_GUI:SetHidden(not IIFA_GUI:IsControlHidden())
if not IIFA_GUI:IsControlHidden() then
-- IIfA:OnFirstInventoryOpen()
-- Get current camera mode so when we toggle off, we put it back to where it was (maybe, can think of some weird circumstances where it might screw it up)
SetGameCameraUIMode(true)
IIfA:GuiResizeScroll()
IIfA:RefreshInventoryScroll()
end
if not IIFA_DATABASE[IIfA.currentAccount].settings.dontFocusSearch then
IIfA.GUI_SearchBox:TakeFocus()
end
IIfA:SaveFrameInfo("ToggleInventoryFrame")
end