-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathOptions.lua
More file actions
231 lines (210 loc) · 8.3 KB
/
Options.lua
File metadata and controls
231 lines (210 loc) · 8.3 KB
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
--------------
-- 配置面板 --
--------------
local LibEvent = LibStub:GetLibrary("LibEvent.7000")
local VERSION = 1.0
local addon, ns = ...
ns.GameVersion = select(4, GetBuildInfo())
ns.IsClassic = _G.WOW_PROJECT_ID == _G.WOW_PROJECT_CLASSIC
ns.IsClassicSoD = ns.IsClassic and C_Engraving and C_Engraving.IsEngravingEnabled()
ns.IsWrath = _G.WOW_PROJECT_ID == _G.WOW_PROJECT_WRATH_CLASSIC
ns.IsCata = _G.WOW_PROJECT_ID == _G.WOW_PROJECT_CATACLYSM_CLASSIC
ns.IsMists = _G.WOW_PROJECT_ID == _G.WOW_PROJECT_MISTS_CLASSIC
local L = ns.L or {}
setmetatable(L, { __index = function(_, k)
return k:gsub("([a-z])([A-Z])", "%1 %2")
end})
ns.L = L
local DefaultDB = {
version = VERSION,
ShowItemSlotString = false, --物品部位文字
ShowItemBorder = true, --物品直角邊框
ShowCharacterItemSheet = true, --玩家自己裝備列表
ShowCharacterItemStats = false, --玩家自己屬性統計
ShowInspectAngularBorder = false, --觀察面板直角邊框
ShowInspectColoredLabel = true, --觀察面板顔色隨物品品質
ShowInspectItemSheet = true, --顯示观察对象装备列表
ShowOwnFrameWhenInspecting = false, --觀察同時顯示自己裝備列表
ShowItemStats = false, --顯示裝備屬性統計
}
local options = {
{ key = "ShowItemBorder" },
{ key = "ShowItemSlotString" },
{ key = "ShowCharacterItemSheet" },
{ key = "ShowCharacterItemStats" },
{ key = "ShowInspectAngularBorder" },
{ key = "ShowInspectColoredLabel" },
{ key = "ShowInspectItemSheet",
child = {
{ key = "ShowOwnFrameWhenInspecting" },
{ key = "ShowItemStats" },
}
},
}
MerInspectDB = DefaultDB
local function CallCustomFunc(self)
local checked = self:GetChecked()
if (checked and self.checkedFunc) then
self.checkedFunc(self)
end
if (not checked and self.uncheckedFunc) then
self.uncheckedFunc(self)
end
end
local function StatusSubCheckbox(self, status)
local checkbox
for i = 1, self:GetNumChildren() do
checkbox = select(i, self:GetChildren())
if (checkbox.key) then
checkbox:SetEnabled(status)
StatusSubCheckbox(checkbox, status)
end
end
if (status and self.SubtypeFrame) then
self.SubtypeFrame:Show()
elseif (not status and self.SubtypeFrame) then
self.SubtypeFrame:Hide()
end
end
local function OnClickCheckbox(self)
local status = self:GetChecked()
MerInspectDB[self.key] = status
StatusSubCheckbox(self, status)
CallCustomFunc(self)
end
local function CreateSubtypeFrame(list, parent)
if (not list) then return end
if (not parent.SubtypeFrame) then
parent.SubtypeFrame = CreateFrame("Frame", nil, parent, "BackdropTemplate")
parent.SubtypeFrame:SetScale(0.92)
parent.SubtypeFrame:SetPoint("TOPLEFT", 333, 0)
parent.SubtypeFrame:SetBackdrop({
bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
tile = true,
tileSize = 8,
edgeSize = 16,
insets = {left = 4, right = 4, top = 4, bottom = 4}
})
parent.SubtypeFrame:SetBackdropColor(0, 0, 0, 0.6)
parent.SubtypeFrame:SetBackdropBorderColor(0.6, 0.6, 0.6)
parent.SubtypeFrame.title = parent.SubtypeFrame:CreateFontString(nil, "BORDER", "GameFontNormalOutline")
parent.SubtypeFrame.title:SetPoint("TOPLEFT", 16, -18)
parent.SubtypeFrame.title:SetText(L[parent.key])
end
local checkbox
for i, v in ipairs(list) do
checkbox = CreateFrame("CheckButton", nil, parent.SubtypeFrame, "InterfaceOptionsCheckButtonTemplate")
checkbox.key = parent.key .. v.key
checkbox.checkedFunc = v.checkedFunc
checkbox.uncheckedFunc = v.uncheckedFunc
checkbox.Text:SetText(L[v.key])
checkbox:SetScript("OnClick", OnClickCheckbox)
checkbox:SetPoint("TOPLEFT", parent.SubtypeFrame, "TOPLEFT", 16, -46-(i-1)*32)
end
parent.SubtypeFrame:SetSize(168, #list*32+58)
end
local function CreateAnchorFrame(anchorkey, parent)
if (not anchorkey) then return end
local CreateAnchorButton = function(frame, anchorPoint)
local button = CreateFrame("Button", nil, frame)
button.anchorPoint = anchorPoint
button:SetSize(12, 12)
button:SetPoint(anchorPoint)
button:SetNormalTexture("Interface\\Buttons\\WHITE8X8")
if (MerInspectDB[frame.anchorkey] == anchorPoint) then
button:GetNormalTexture():SetVertexColor(1, 0.2, 0.1)
end
button:SetScript("OnClick", function(self)
local parent = self:GetParent()
local anchorPoint = self.anchorPoint
local anchorOrig = MerInspectDB[parent.anchorkey]
if (parent[anchorOrig]) then
parent[anchorOrig]:GetNormalTexture():SetVertexColor(1, 1, 1)
end
self:GetNormalTexture():SetVertexColor(1, 0.2, 0.1)
MerInspectDB[parent.anchorkey] = anchorPoint
end)
frame[anchorPoint] = button
end
local frame = CreateFrame("Frame", nil, parent.SubtypeFrame or parent, "ThinBorderTemplate,BackdropTemplate")
frame.anchorkey = anchorkey
frame:SetBackdrop({
bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
tile = true, tileSize = 8, edgeSize = 16,
insets = {left = 4, right = 4, top = 4, bottom = 4}
})
frame:SetBackdropColor(0, 0, 0, 0.7)
frame:SetBackdropBorderColor(1, 1, 1, 0)
frame:SetSize(80, 80)
frame:SetPoint("TOPRIGHT", 100, -5)
CreateAnchorButton(frame, "TOPLEFT")
CreateAnchorButton(frame, "LEFT")
CreateAnchorButton(frame, "BOTTOMLEFT")
CreateAnchorButton(frame, "TOP")
CreateAnchorButton(frame, "BOTTOM")
CreateAnchorButton(frame, "TOPRIGHT")
CreateAnchorButton(frame, "RIGHT")
CreateAnchorButton(frame, "BOTTOMRIGHT")
CreateAnchorButton(frame, "CENTER")
end
local function CreateCheckbox(list, parent, anchor, offsetx, offsety)
local checkbox, subbox
local stepx, stepy = 20, 27
if (not list) then return offsety end
for i, v in ipairs(list) do
checkbox = CreateFrame("CheckButton", nil, parent, "InterfaceOptionsCheckButtonTemplate")
checkbox.key = v.key
checkbox.checkedFunc = v.checkedFunc
checkbox.uncheckedFunc = v.uncheckedFunc
checkbox.Text:SetText(L[v.key])
checkbox:SetScript("OnClick", OnClickCheckbox)
checkbox:SetPoint("TOPLEFT", anchor, "BOTTOMLEFT", offsetx, -6-offsety)
offsety = offsety + stepy
offsety = CreateCheckbox(v.child, checkbox, anchor, offsetx+stepx, offsety)
CreateSubtypeFrame(v.subtype, checkbox)
CreateAnchorFrame(v.anchorkey, checkbox)
end
return offsety
end
local function InitCheckbox(parent)
local checkbox
for i = 1, parent:GetNumChildren() do
checkbox = select(i, parent:GetChildren())
if (checkbox.key) then
checkbox:SetChecked(MerInspectDB[checkbox.key])
StatusSubCheckbox(checkbox, checkbox:GetChecked())
CallCustomFunc(checkbox)
InitCheckbox(checkbox)
end
end
if (parent.SubtypeFrame) then
InitCheckbox(parent.SubtypeFrame)
end
end
local frame = CreateFrame("Frame")
frame.title = frame:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
frame.title:SetPoint("TOPLEFT", 18, -16)
frame.title:SetText(addon)
CreateCheckbox(options, frame, frame.title, 18, 9)
local category = Settings.RegisterCanvasLayoutCategory(frame, addon)
Settings.RegisterAddOnCategory(category)
LibEvent:attachEvent("VARIABLES_LOADED", function()
if (not MerInspectDB or not MerInspectDB.version) then
MerInspectDB = DefaultDB
elseif (MerInspectDB.version <= DefaultDB.version) then
MerInspectDB.version = DefaultDB.version
for k, v in pairs(DefaultDB) do
if (MerInspectDB[k] == nil) then
MerInspectDB[k] = v
end
end
end
InitCheckbox(frame)
end)
SLASH_MerInspect1 = "/merinspect"
SLASH_MerInspect2 = "/mi"
function SlashCmdList.MerInspect(msg, editbox)
Settings.OpenToCategory(category.ID)
end