tercio@0
|
1 --[[-----------------------------------------------------------------------------
|
tercio@0
|
2 BlizOptionsGroup Container
|
tercio@0
|
3 Simple container widget for the integration of AceGUI into the Blizzard Interface Options
|
tercio@0
|
4 -------------------------------------------------------------------------------]]
|
tercio@0
|
5 local Type, Version = "BlizOptionsGroup", 21
|
tercio@0
|
6 local AceGUI = LibStub and LibStub("AceGUI-3.0", true)
|
tercio@0
|
7 if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end
|
tercio@0
|
8
|
tercio@0
|
9 -- Lua APIs
|
tercio@0
|
10 local pairs = pairs
|
tercio@0
|
11
|
tercio@0
|
12 -- WoW APIs
|
tercio@0
|
13 local CreateFrame = CreateFrame
|
tercio@0
|
14
|
tercio@0
|
15 --[[-----------------------------------------------------------------------------
|
tercio@0
|
16 Scripts
|
tercio@0
|
17 -------------------------------------------------------------------------------]]
|
tercio@0
|
18
|
tercio@0
|
19 local function OnShow(frame)
|
tercio@0
|
20 frame.obj:Fire("OnShow")
|
tercio@0
|
21 end
|
tercio@0
|
22
|
tercio@0
|
23 local function OnHide(frame)
|
tercio@0
|
24 frame.obj:Fire("OnHide")
|
tercio@0
|
25 end
|
tercio@0
|
26
|
tercio@0
|
27 --[[-----------------------------------------------------------------------------
|
tercio@0
|
28 Support functions
|
tercio@0
|
29 -------------------------------------------------------------------------------]]
|
tercio@0
|
30
|
tercio@0
|
31 local function okay(frame)
|
tercio@0
|
32 frame.obj:Fire("okay")
|
tercio@0
|
33 end
|
tercio@0
|
34
|
tercio@0
|
35 local function cancel(frame)
|
tercio@0
|
36 frame.obj:Fire("cancel")
|
tercio@0
|
37 end
|
tercio@0
|
38
|
tercio@0
|
39 local function default(frame)
|
tercio@0
|
40 frame.obj:Fire("default")
|
tercio@0
|
41 end
|
tercio@0
|
42
|
tercio@0
|
43 local function refresh(frame)
|
tercio@0
|
44 frame.obj:Fire("refresh")
|
tercio@0
|
45 end
|
tercio@0
|
46
|
tercio@0
|
47 --[[-----------------------------------------------------------------------------
|
tercio@0
|
48 Methods
|
tercio@0
|
49 -------------------------------------------------------------------------------]]
|
tercio@0
|
50
|
tercio@0
|
51 local methods = {
|
tercio@0
|
52 ["OnAcquire"] = function(self)
|
tercio@0
|
53 self:SetName()
|
tercio@0
|
54 self:SetTitle()
|
tercio@0
|
55 end,
|
tercio@0
|
56
|
tercio@0
|
57 -- ["OnRelease"] = nil,
|
tercio@0
|
58
|
tercio@0
|
59 ["OnWidthSet"] = function(self, width)
|
tercio@0
|
60 local content = self.content
|
tercio@0
|
61 local contentwidth = width - 63
|
tercio@0
|
62 if contentwidth < 0 then
|
tercio@0
|
63 contentwidth = 0
|
tercio@0
|
64 end
|
tercio@0
|
65 content:SetWidth(contentwidth)
|
tercio@0
|
66 content.width = contentwidth
|
tercio@0
|
67 end,
|
tercio@0
|
68
|
tercio@0
|
69 ["OnHeightSet"] = function(self, height)
|
tercio@0
|
70 local content = self.content
|
tercio@0
|
71 local contentheight = height - 26
|
tercio@0
|
72 if contentheight < 0 then
|
tercio@0
|
73 contentheight = 0
|
tercio@0
|
74 end
|
tercio@0
|
75 content:SetHeight(contentheight)
|
tercio@0
|
76 content.height = contentheight
|
tercio@0
|
77 end,
|
tercio@0
|
78
|
tercio@0
|
79 ["SetName"] = function(self, name, parent)
|
tercio@0
|
80 self.frame.name = name
|
tercio@0
|
81 self.frame.parent = parent
|
tercio@0
|
82 end,
|
tercio@0
|
83
|
tercio@0
|
84 ["SetTitle"] = function(self, title)
|
tercio@0
|
85 local content = self.content
|
tercio@0
|
86 content:ClearAllPoints()
|
tercio@0
|
87 if not title or title == "" then
|
tercio@0
|
88 content:SetPoint("TOPLEFT", 10, -10)
|
tercio@0
|
89 self.label:SetText("")
|
tercio@0
|
90 else
|
tercio@0
|
91 content:SetPoint("TOPLEFT", 10, -40)
|
tercio@0
|
92 self.label:SetText(title)
|
tercio@0
|
93 end
|
tercio@0
|
94 content:SetPoint("BOTTOMRIGHT", -10, 10)
|
tercio@0
|
95 end
|
tercio@0
|
96 }
|
tercio@0
|
97
|
tercio@0
|
98 --[[-----------------------------------------------------------------------------
|
tercio@0
|
99 Constructor
|
tercio@0
|
100 -------------------------------------------------------------------------------]]
|
tercio@0
|
101 local function Constructor()
|
tercio@0
|
102 local frame = CreateFrame("Frame")
|
tercio@0
|
103 frame:Hide()
|
tercio@0
|
104
|
tercio@0
|
105 -- support functions for the Blizzard Interface Options
|
tercio@0
|
106 frame.okay = okay
|
tercio@0
|
107 frame.cancel = cancel
|
tercio@0
|
108 frame.default = default
|
tercio@0
|
109 frame.refresh = refresh
|
tercio@0
|
110
|
tercio@0
|
111 frame:SetScript("OnHide", OnHide)
|
tercio@0
|
112 frame:SetScript("OnShow", OnShow)
|
tercio@0
|
113
|
tercio@0
|
114 local label = frame:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
|
tercio@0
|
115 label:SetPoint("TOPLEFT", 10, -15)
|
tercio@0
|
116 label:SetPoint("BOTTOMRIGHT", frame, "TOPRIGHT", 10, -45)
|
tercio@0
|
117 label:SetJustifyH("LEFT")
|
tercio@0
|
118 label:SetJustifyV("TOP")
|
tercio@0
|
119
|
tercio@0
|
120 --Container Support
|
tercio@0
|
121 local content = CreateFrame("Frame", nil, frame)
|
tercio@0
|
122 content:SetPoint("TOPLEFT", 10, -10)
|
tercio@0
|
123 content:SetPoint("BOTTOMRIGHT", -10, 10)
|
tercio@0
|
124
|
tercio@0
|
125 local widget = {
|
tercio@0
|
126 label = label,
|
tercio@0
|
127 frame = frame,
|
tercio@0
|
128 content = content,
|
tercio@0
|
129 type = Type
|
tercio@0
|
130 }
|
tercio@0
|
131 for method, func in pairs(methods) do
|
tercio@0
|
132 widget[method] = func
|
tercio@0
|
133 end
|
tercio@0
|
134
|
tercio@0
|
135 return AceGUI:RegisterAsContainer(widget)
|
tercio@0
|
136 end
|
tercio@0
|
137
|
tercio@0
|
138 AceGUI:RegisterWidgetType(Type, Constructor, Version)
|