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