-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOptionHouse.lua
288 lines (241 loc) · 7.52 KB
/
OptionHouse.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
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
--[[
OptionHouse, by Shadow - Mal'Ganis (US)
Thanks Tekkub and Cladhaire for the original idea and some of the code... which I mutilated shortly thereafter!
This version further updated and modified by Phanx <[email protected]>
]]
local OPTIONHOUSE, L = ...
setmetatable(L, { __index = function(t, k)
local v = tostring(k)
t[k] = v
return v
end })
OptionHouse = {}
local tabFunctions = {}
local openedByMenu
-- TABS
local function setTab(id)
local frame = OptionHouse.frame
if( not frame.tabs[id] ) then return end
if( frame.selectedTab ) then
PanelTemplates_DeselectTab(frame.tabs[frame.selectedTab])
end
frame.selectedTab = id
PanelTemplates_SelectTab(frame.tabs[id])
end
local function tabOnClick(self)
local id = type(self) == "number" and self or self:GetID()
setTab(id)
local frame = OptionHouse.frame
for tabID, tab in pairs(tabFunctions) do
if tabID == id then
if type(tab.func) == "function" then
tab.func()
else
tab.handler[tab.func](tab.handler)
end
elseif type(tab.func) == "function" then
tab.func(true)
else
tab.handler[tab.func](tab.handler, true)
end
end
end
function OptionHouse:CreateTab(text, id)
if not self.frame then
self:CreateUI()
end
local tab = self.frame.tabs[id]
if not tab then
tab = CreateFrame("Button", "$parentTab"..id, self.frame, "PanelTabButtonTemplate")
tab:GetFontString():SetPoint("CENTER", 0, 2)
-- tab:GetHighlightTexture():SetPoint("TOPLEFT", -1, 4)
-- tab:GetHighlightTexture():SetPoint("BOTTOMRIGHT", 0, 0)
tab:UnregisterEvent("DISPLAY_SIZE_CHANGED")
tab:SetScript("OnEvent", nil)
tab:SetID(id)
tab:SetSize(115, 32)
tab:SetScript("OnClick", tabOnClick)
tab:SetScript("OnShow", function(tab) PanelTemplates_TabResize(tab, 10) end)
tinsert(self.frame.tabs, tab)
end
tab:SetText(text)
tab:Show()
PanelTemplates_DeselectTab(tab)
PanelTemplates_TabResize(tab, 0)
if id > 1 then
tab:SetPoint("TOPLEFT", self.frame.tabs[id - 1], "TOPRIGHT", -8, 0)
else
tab:SetPoint("TOPLEFT", self.frame, "BOTTOMLEFT", 15, 1)
end
end
-- SCROLL FRAME
local function onVerticalScroll(self, offset)
self.offset = ceil(offset / self.displayNum)
if self.offset < 0 then
self.offset = 0
end
self.updateFunc(self.updateHandler)
end
local function onParentMouseWheel(self, value)
ScrollFrameTemplate_OnMouseWheel(self.scroll, value, self.scroll.bar)
end
function OptionHouse:UpdateScroll(scroll, totalRows)
local max = (totalRows - scroll.displayNum) * scroll.displayNum
-- Macs are unhappy if max is less then the min
if max < 0 then
max = 0
end
-- scroll.bar:SetMinMaxValues(0, max)
if( totalRows > scroll.displayNum ) then
scroll:Show()
scroll.bar:Show()
scroll.up:Show()
scroll.down:Show()
scroll.bar:GetThumbTexture():Show()
else
scroll:Hide()
scroll.bar:Hide()
scroll.up:Hide()
scroll.down:Hide()
scroll.bar:GetThumbTexture():Hide()
end
end
local function onValueChanged(self, offset)
self:GetParent():SetVerticalScroll(offset)
end
local function scrollButtonUp(self)
local parent = self:GetParent()
parent:SetValue(parent:GetValue() - (parent:GetHeight() / 2))
end
local function scrollButtonDown(self)
local parent = self:GetParent()
parent:SetValue(parent:GetValue() + (parent:GetHeight() / 2))
end
function OptionHouse:CreateScrollFrame(frame, displayNum, onScroll)
frame:EnableMouseWheel(true)
frame:SetScript("OnMouseWheel", onParentMouseWheel)
local scroll = CreateFrame("ScrollFrame", "$parentScrollFrame", frame, "UIPanelScrollFrameTemplate")--"ButtonFrameTemplate")--"UIPanelScrollFrameTemplate2")
scroll:SetPoint("TOPLEFT", 10, -65)
scroll:SetPoint("BOTTOMRIGHT", -31, 30)
scroll:EnableMouseWheel(true)
scroll:SetWidth(16)
scroll:SetHeight(370)
scroll:HookScript("OnVerticalScroll", onVerticalScroll)
scroll.offset = 0
scroll.displayNum = displayNum
scroll.updateHandler = frame
scroll.updateFunc = onScroll
scroll.bar = scroll.ScrollBar
scroll.up = scroll.ScrollBar.ScrollUpButton
scroll.down = scroll.ScrollBar.ScrollDownButton
-- scroll.barUpTexture = _G[scroll:GetName().."Top"]
-- scroll.barUpTexture:SetPoint("TOPLEFT", scroll.up, -6, 5)
-- scroll.barUpTexture:SetWidth(29)
-- scroll.barDownTexture = _G[scroll:GetName().."Bottom"]
-- scroll.barDownTexture:SetPoint("BOTTOMLEFT", scroll.down, -6, -2)
-- scroll.barDownTexture:SetWidth(29)
frame.scroll = scroll
return scroll
end
-- SEARCH INPUT
function OptionHouse:CreateSearchInput(frame, onChange)
local search = CreateFrame("EditBox", "$parentSearchBox", frame, "SearchBoxTemplate")
search:SetPoint("BOTTOMLEFT", frame, 10, 3)
search:SetHeight(22)
search:SetWidth(160)
search:SetAutoFocus(false)
search:HookScript("OnTextChanged", onChange)
--search.Left:SetTexture("")
--search.Right:SetTexture("")
--search.Middle:SetTexture("")
frame.search = search
return search
end
-- Main container frame
function OptionHouse:CreateUI()
if InCombatLockdown() then return end --DiscordGregory, error if you try to open UI in combat
if self.frame then return end
collectgarbage("collect") --DiscordGregory, safe to remove if you want
local frame = CreateFrame("Frame", "OptionHouseFrame", UIParent, "ButtonFrameTemplate")
frame:EnableMouse(true) -- @Phanx: don't allow clickthrough
frame:SetMovable(true)
frame:SetClampedToScreen(true)
frame:SetFrameStrata("HIGH")
frame:SetWidth(832)
frame:SetHeight(647)
frame:SetPoint("TOPLEFT", 0, -104)
frame:RegisterForDrag("LeftButton")
frame:SetScript("OnDragStart", function(self)
frame:StartMoving()
end)
frame:SetScript("OnDragStop", function(self)
frame:StopMovingOrSizing()
frame.userPlaced = true
end)
-- If it's not hidden first, the panel layout becomes messed up
-- because dynamically created frames are created shown
frame:Hide()
frame:SetScript("OnHide", function()
if openedByMenu then
openedByMenu = nil
ShowUIPanel(GameMenuFrame)
end
end)
-- Frame type info
frame:SetAttribute("UIPanelLayout-defined", true)
frame:SetAttribute("UIPanelLayout-enabled", true)
frame:SetAttribute("UIPanelLayout-area", "doublewide")
frame:SetAttribute("UIPanelLayout-pushable", 3)
frame:SetAttribute("UIPanelLayout-whileDead", true)
tinsert(UISpecialFrames, "OptionHouseFrame")
frame.TitleText = frame:CreateFontString("OptionHouseTitle", "OVERLAY", "GameTooltipText")
frame.TitleText:SetText(L["Option House"])
frame.portrait = frame:CreateTexture()
SetPortraitToTexture(frame.portrait, "Interface\\ICONS\\Achievement_Faction_Craftsman")
frame.portrait:SetPoint("TOPLEFT", -4, 12)
frame.portrait:SetDrawLayer("OVERLAY")
self.frame = frame
-- Create tabs
frame.tabs = {}
for id, tab in pairs(tabFunctions) do
self:CreateTab(tab.text, id)
end
end
function OptionHouse:RegisterTab(text, func)
tinsert(tabFunctions, { func = func, text = text })
-- Will create all of the tabs when the frame is created if needed
if not self.frame then return end
self:CreateTab(text, #(tabFunctions))
end
function OptionHouse:Open(id)
if self.frame and self.frame:IsShown() then return end
self:CreateUI()
tabOnClick(tonumber(tab) or 1)
if self.frame.userPlaced then
self.frame:Show()
else
ShowUIPanel(self.frame)
end
end
function OptionHouse:Close()
if not self.frame or not self.frame:IsShown() then return end
if self.frame.userPlaced then
self.frame:Hide()
else
HideUIPanel(self.frame)
end
end
function OptionHouse:Toggle(tab)
if self.frame and self.frame:IsShown() then
self:Close()
else
self:Open(tab)
end
end
-- Slash commands
SLASH_OPTIONHOUSE1 = "/opthouse"
SLASH_OPTIONHOUSE2 = "/optionhouse"
SLASH_OPTIONHOUSE3 = "/oh"
SlashCmdList["OPTIONHOUSE"] = function(tab)
OptionHouse:Toggle(tab)
end