yellowfive@57
|
1 --[[-----------------------------------------------------------------------------
|
yellowfive@57
|
2 AmrUiFrame container
|
yellowfive@57
|
3 -------------------------------------------------------------------------------]]
|
yellowfive@57
|
4 local Type, Version = "AmrUiFrame", 1
|
yellowfive@57
|
5 local AceGUI = LibStub and LibStub("AceGUI-3.0", true)
|
yellowfive@57
|
6 if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end
|
yellowfive@57
|
7
|
yellowfive@57
|
8 local L = LibStub("AceLocale-3.0"):GetLocale("AskMrRobot", true)
|
yellowfive@57
|
9 local Amr = LibStub("AceAddon-3.0"):GetAddon("AskMrRobot")
|
yellowfive@57
|
10
|
yellowfive@57
|
11 -- Lua APIs
|
yellowfive@57
|
12 local pairs, assert, type = pairs, assert, type
|
yellowfive@57
|
13 local wipe = table.wipe
|
yellowfive@57
|
14
|
yellowfive@57
|
15 -- WoW APIs
|
yellowfive@57
|
16 local PlaySound = PlaySound
|
yellowfive@57
|
17 local CreateFrame, UIParent = CreateFrame, UIParent
|
yellowfive@57
|
18
|
yellowfive@57
|
19 -- Global vars/functions that we don't upvalue since they might get hooked, or upgraded
|
yellowfive@57
|
20 -- List them here for Mikk's FindGlobals script
|
yellowfive@57
|
21 -- GLOBALS: CLOSE
|
yellowfive@57
|
22
|
yellowfive@57
|
23 -- width of the frame border
|
yellowfive@57
|
24 local _borderWidth = 1
|
yellowfive@57
|
25
|
yellowfive@57
|
26
|
yellowfive@57
|
27 --[[-----------------------------------------------------------------------------
|
yellowfive@57
|
28 Scripts
|
yellowfive@57
|
29 -------------------------------------------------------------------------------]]
|
yellowfive@57
|
30 local function buttonOnClick(frame)
|
yellowfive@57
|
31 PlaySound("gsTitleOptionExit")
|
yellowfive@57
|
32 frame.obj:Hide()
|
yellowfive@57
|
33 end
|
yellowfive@57
|
34
|
yellowfive@57
|
35 local function frameOnClose(frame)
|
yellowfive@57
|
36 frame.obj:Fire("OnClose")
|
yellowfive@57
|
37 end
|
yellowfive@57
|
38
|
yellowfive@57
|
39 local function frameOnMouseDown(frame)
|
yellowfive@57
|
40 AceGUI:ClearFocus()
|
yellowfive@57
|
41 end
|
yellowfive@57
|
42
|
yellowfive@57
|
43 local function titleOnMouseDown(frame)
|
yellowfive@57
|
44 frame.obj:StartMove()
|
yellowfive@57
|
45 end
|
yellowfive@57
|
46
|
yellowfive@57
|
47 local function titleOnMouseUp(frame)
|
yellowfive@57
|
48 frame.obj:EndMove()
|
yellowfive@57
|
49 end
|
yellowfive@57
|
50
|
yellowfive@57
|
51 --[[-----------------------------------------------------------------------------
|
yellowfive@57
|
52 Methods
|
yellowfive@57
|
53 -------------------------------------------------------------------------------]]
|
yellowfive@57
|
54 local methods = {
|
yellowfive@57
|
55 ["OnAcquire"] = function(self)
|
yellowfive@57
|
56 self:SetAutoAdjustHeight(false)
|
yellowfive@57
|
57 self.frame:SetParent(UIParent)
|
yellowfive@57
|
58 self.frame:SetFrameStrata("FULLSCREEN_DIALOG")
|
yellowfive@57
|
59 self:ApplyStatus()
|
yellowfive@57
|
60 self:Show()
|
yellowfive@57
|
61 end,
|
yellowfive@57
|
62
|
yellowfive@57
|
63 ["OnRelease"] = function(self)
|
yellowfive@57
|
64 self.status = nil
|
yellowfive@57
|
65 wipe(self.localstatus)
|
yellowfive@57
|
66 end,
|
yellowfive@57
|
67
|
yellowfive@57
|
68 ["Hide"] = function(self)
|
yellowfive@57
|
69 self.frame:Hide()
|
yellowfive@57
|
70 end,
|
yellowfive@57
|
71
|
yellowfive@57
|
72 ["Show"] = function(self)
|
yellowfive@57
|
73 self.frame:Show()
|
yellowfive@57
|
74 end,
|
yellowfive@57
|
75
|
yellowfive@57
|
76 -- called to set an external table to store status in
|
yellowfive@57
|
77 ["SetStatusTable"] = function(self, status)
|
yellowfive@57
|
78 assert(type(status) == "table")
|
yellowfive@57
|
79 self.status = status
|
yellowfive@57
|
80 self:ApplyStatus()
|
yellowfive@57
|
81 end,
|
yellowfive@57
|
82
|
yellowfive@57
|
83 ["ApplyStatus"] = function(self)
|
yellowfive@57
|
84 local status = self.status or self.localstatus
|
yellowfive@57
|
85 local frame = self.frame
|
yellowfive@57
|
86 frame:ClearAllPoints()
|
yellowfive@57
|
87 if status.top and status.left then
|
yellowfive@57
|
88 frame:SetPoint("TOP", UIParent, "BOTTOM", 0, status.top)
|
yellowfive@57
|
89 frame:SetPoint("LEFT", UIParent, "LEFT", status.left, 0)
|
yellowfive@57
|
90 else
|
yellowfive@57
|
91 frame:SetPoint("CENTER")
|
yellowfive@57
|
92 end
|
yellowfive@57
|
93 end,
|
yellowfive@57
|
94
|
yellowfive@57
|
95 -- color is an object with R, G, B
|
yellowfive@57
|
96 ["SetBackgroundColor"] = function(self, color)
|
yellowfive@57
|
97 self.bg:SetTexture(color.R, color.G, color.B, 1)
|
yellowfive@57
|
98 end,
|
yellowfive@57
|
99
|
yellowfive@57
|
100 ["SetBorderColor"] = function(self, color)
|
yellowfive@57
|
101 self.border:SetTexture(color.R, color.G, color.B, 1)
|
yellowfive@57
|
102 end,
|
yellowfive@57
|
103
|
yellowfive@57
|
104 ["Raise"] = function(self)
|
yellowfive@57
|
105 self.frame:Raise()
|
yellowfive@57
|
106 end,
|
yellowfive@57
|
107
|
yellowfive@57
|
108 ["StartMove"] = function(self)
|
yellowfive@57
|
109 self.frame:StartMoving()
|
yellowfive@57
|
110 AceGUI:ClearFocus()
|
yellowfive@57
|
111 end,
|
yellowfive@57
|
112
|
yellowfive@57
|
113 ["EndMove"] = function(self)
|
yellowfive@57
|
114 self.frame:StopMovingOrSizing()
|
yellowfive@57
|
115 local status = self.status or self.localstatus
|
yellowfive@57
|
116 status.top = self.frame:GetTop()
|
yellowfive@57
|
117 status.left = self.frame:GetLeft()
|
yellowfive@57
|
118 end,
|
yellowfive@57
|
119
|
yellowfive@57
|
120 ["OnWidthSet"] = function(self, width)
|
yellowfive@57
|
121 local content = self.content
|
yellowfive@57
|
122 content.width = width
|
yellowfive@57
|
123 end,
|
yellowfive@57
|
124
|
yellowfive@57
|
125 ["OnHeightSet"] = function(self, height)
|
yellowfive@57
|
126 local content = self.content
|
yellowfive@57
|
127 content.height = height
|
yellowfive@57
|
128 end
|
yellowfive@57
|
129 }
|
yellowfive@57
|
130
|
yellowfive@57
|
131 --[[-----------------------------------------------------------------------------
|
yellowfive@57
|
132 Constructor
|
yellowfive@57
|
133 -------------------------------------------------------------------------------]]
|
yellowfive@57
|
134 local function Constructor()
|
yellowfive@57
|
135 local num = AceGUI:GetNextWidgetNum(Type)
|
yellowfive@57
|
136 local frame = CreateFrame("Frame", "AmrUiFrame" .. num, UIParent)
|
yellowfive@57
|
137 frame:Hide()
|
yellowfive@57
|
138
|
yellowfive@57
|
139 -- make escape key close this window
|
yellowfive@57
|
140 table.insert(UISpecialFrames, frame:GetName())
|
yellowfive@57
|
141
|
yellowfive@57
|
142 frame:EnableMouse(true)
|
yellowfive@57
|
143 frame:SetMovable(true)
|
yellowfive@57
|
144 frame:SetResizable(false)
|
yellowfive@57
|
145 frame:SetFrameStrata("FULLSCREEN_DIALOG")
|
yellowfive@57
|
146 frame:SetToplevel(true)
|
yellowfive@57
|
147 frame:SetScript("OnHide", frameOnClose)
|
yellowfive@57
|
148 frame:SetScript("OnMouseDown", frameOnMouseDown)
|
yellowfive@57
|
149
|
yellowfive@57
|
150 Amr.DropShadow(frame)
|
yellowfive@57
|
151
|
yellowfive@57
|
152 local border = frame:CreateTexture(nil, "BACKGROUND", nil, 1)
|
yellowfive@57
|
153 border:SetAllPoints(true)
|
yellowfive@57
|
154
|
yellowfive@57
|
155 local bg = frame:CreateTexture(nil, "BORDER")
|
yellowfive@57
|
156 bg:SetPoint("TOPLEFT", frame, "TOPLEFT", _borderWidth, -_borderWidth)
|
yellowfive@57
|
157 bg:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -_borderWidth, _borderWidth)
|
yellowfive@57
|
158
|
yellowfive@57
|
159 local btnClose = CreateFrame("Button", nil, frame)
|
yellowfive@57
|
160 btnClose:SetNormalFontObject(Amr.CreateFont("Bold", 16, Amr.Colors.White))
|
yellowfive@57
|
161 btnClose:SetText("x")
|
yellowfive@57
|
162 btnClose:SetWidth(22)
|
yellowfive@57
|
163 btnClose:SetHeight(22)
|
yellowfive@57
|
164 btnClose:SetPoint("TOPRIGHT", frame, "TOPRIGHT", -4, -4)
|
yellowfive@57
|
165 btnClose:SetScript("OnClick", buttonOnClick)
|
yellowfive@57
|
166
|
yellowfive@57
|
167 local lbl = btnClose:GetFontString()
|
yellowfive@57
|
168 lbl:ClearAllPoints()
|
yellowfive@57
|
169 lbl:SetPoint("TOP", btnClose, "TOP", -1, -2)
|
yellowfive@57
|
170
|
yellowfive@57
|
171 -- style the button similar to AmrUiButton
|
yellowfive@57
|
172 Amr.DropShadow(btnClose)
|
yellowfive@57
|
173
|
yellowfive@57
|
174 local tex = Amr.CreateTexture(btnClose, Amr.Colors.Red)
|
yellowfive@57
|
175 tex:SetAllPoints(true)
|
yellowfive@57
|
176 btnClose:SetNormalTexture(tex)
|
yellowfive@57
|
177
|
yellowfive@57
|
178 tex = Amr.CreateTexture(btnClose, Amr.Colors.Red)
|
yellowfive@57
|
179 tex:SetPoint("TOPLEFT", btnClose, "TOPLEFT", 1, -1)
|
yellowfive@57
|
180 tex:SetPoint("BOTTOMRIGHT", btnClose, "BOTTOMRIGHT", 1, -1)
|
yellowfive@57
|
181 btnClose:SetPushedTexture(tex)
|
yellowfive@57
|
182
|
yellowfive@57
|
183 tex = Amr.CreateTexture(btnClose, Amr.Colors.White, 0.1)
|
yellowfive@57
|
184 tex:SetAllPoints(true)
|
yellowfive@57
|
185 btnClose:SetHighlightTexture(tex)
|
yellowfive@57
|
186
|
yellowfive@57
|
187 -- title
|
yellowfive@57
|
188 local titleFrame = CreateFrame("Frame", nil, frame)
|
yellowfive@57
|
189 titleFrame:SetPoint("TOPLEFT", frame, "TOPLEFT", 0, 0)
|
yellowfive@57
|
190 titleFrame:SetPoint("BOTTOMRIGHT", frame, "TOPRIGHT", 0, -40)
|
yellowfive@57
|
191 titleFrame:EnableMouse(true)
|
yellowfive@57
|
192 titleFrame:SetScript("OnMouseDown", titleOnMouseDown)
|
yellowfive@57
|
193 titleFrame:SetScript("OnMouseUp", titleOnMouseUp)
|
yellowfive@57
|
194
|
yellowfive@57
|
195 --Container Support
|
yellowfive@57
|
196 local content = CreateFrame("Frame", nil, frame)
|
yellowfive@57
|
197 content:SetPoint("TOPLEFT", titleFrame, "BOTTOMLEFT", 20, 0)
|
yellowfive@57
|
198 content:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -20, 20)
|
yellowfive@57
|
199
|
yellowfive@57
|
200 local widget = {
|
yellowfive@57
|
201 localstatus = {},
|
yellowfive@57
|
202 border = border,
|
yellowfive@57
|
203 bg = bg,
|
yellowfive@57
|
204 content = content,
|
yellowfive@57
|
205 frame = frame,
|
yellowfive@57
|
206 type = Type
|
yellowfive@57
|
207 }
|
yellowfive@57
|
208 for method, func in pairs(methods) do
|
yellowfive@57
|
209 widget[method] = func
|
yellowfive@57
|
210 end
|
yellowfive@57
|
211 btnClose.obj, titleFrame.obj = widget, widget
|
yellowfive@57
|
212
|
yellowfive@57
|
213 return AceGUI:RegisterAsContainer(widget)
|
yellowfive@57
|
214 end
|
yellowfive@57
|
215
|
yellowfive@57
|
216 AceGUI:RegisterWidgetType(Type, Constructor, Version)
|