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@61
|
59 self.frame:SetScale(1)
|
yellowfive@57
|
60 self:ApplyStatus()
|
yellowfive@57
|
61 self:Show()
|
yellowfive@57
|
62 end,
|
yellowfive@57
|
63
|
yellowfive@57
|
64 ["OnRelease"] = function(self)
|
yellowfive@57
|
65 self.status = nil
|
yellowfive@57
|
66 wipe(self.localstatus)
|
yellowfive@57
|
67 end,
|
yellowfive@57
|
68
|
yellowfive@57
|
69 ["Hide"] = function(self)
|
yellowfive@57
|
70 self.frame:Hide()
|
yellowfive@57
|
71 end,
|
yellowfive@57
|
72
|
yellowfive@57
|
73 ["Show"] = function(self)
|
yellowfive@57
|
74 self.frame:Show()
|
yellowfive@57
|
75 end,
|
yellowfive@57
|
76
|
yellowfive@57
|
77 -- called to set an external table to store status in
|
yellowfive@57
|
78 ["SetStatusTable"] = function(self, status)
|
yellowfive@57
|
79 assert(type(status) == "table")
|
yellowfive@57
|
80 self.status = status
|
yellowfive@57
|
81 self:ApplyStatus()
|
yellowfive@57
|
82 end,
|
yellowfive@57
|
83
|
yellowfive@57
|
84 ["ApplyStatus"] = function(self)
|
yellowfive@57
|
85 local status = self.status or self.localstatus
|
yellowfive@57
|
86 local frame = self.frame
|
yellowfive@57
|
87 frame:ClearAllPoints()
|
yellowfive@57
|
88 if status.top and status.left then
|
yellowfive@57
|
89 frame:SetPoint("TOP", UIParent, "BOTTOM", 0, status.top)
|
yellowfive@57
|
90 frame:SetPoint("LEFT", UIParent, "LEFT", status.left, 0)
|
yellowfive@57
|
91 else
|
yellowfive@57
|
92 frame:SetPoint("CENTER")
|
yellowfive@57
|
93 end
|
yellowfive@57
|
94 end,
|
yellowfive@57
|
95
|
yellowfive@57
|
96 -- color is an object with R, G, B
|
yellowfive@57
|
97 ["SetBackgroundColor"] = function(self, color)
|
yellowfive@57
|
98 self.bg:SetTexture(color.R, color.G, color.B, 1)
|
yellowfive@57
|
99 end,
|
yellowfive@57
|
100
|
yellowfive@57
|
101 ["SetBorderColor"] = function(self, color)
|
yellowfive@57
|
102 self.border:SetTexture(color.R, color.G, color.B, 1)
|
yellowfive@57
|
103 end,
|
yellowfive@57
|
104
|
yellowfive@57
|
105 ["Raise"] = function(self)
|
yellowfive@57
|
106 self.frame:Raise()
|
yellowfive@57
|
107 end,
|
yellowfive@57
|
108
|
yellowfive@57
|
109 ["StartMove"] = function(self)
|
yellowfive@57
|
110 self.frame:StartMoving()
|
yellowfive@57
|
111 AceGUI:ClearFocus()
|
yellowfive@57
|
112 end,
|
yellowfive@57
|
113
|
yellowfive@57
|
114 ["EndMove"] = function(self)
|
yellowfive@57
|
115 self.frame:StopMovingOrSizing()
|
yellowfive@57
|
116 local status = self.status or self.localstatus
|
yellowfive@57
|
117 status.top = self.frame:GetTop()
|
yellowfive@57
|
118 status.left = self.frame:GetLeft()
|
yellowfive@57
|
119 end,
|
yellowfive@57
|
120
|
yellowfive@57
|
121 ["OnWidthSet"] = function(self, width)
|
yellowfive@57
|
122 local content = self.content
|
yellowfive@57
|
123 content.width = width
|
yellowfive@57
|
124 end,
|
yellowfive@57
|
125
|
yellowfive@57
|
126 ["OnHeightSet"] = function(self, height)
|
yellowfive@57
|
127 local content = self.content
|
yellowfive@57
|
128 content.height = height
|
yellowfive@61
|
129 end,
|
yellowfive@61
|
130
|
yellowfive@61
|
131 ["SetScale"] = function(self, scale)
|
yellowfive@61
|
132 self.frame:SetScale(scale)
|
yellowfive@57
|
133 end
|
yellowfive@57
|
134 }
|
yellowfive@57
|
135
|
yellowfive@57
|
136 --[[-----------------------------------------------------------------------------
|
yellowfive@57
|
137 Constructor
|
yellowfive@57
|
138 -------------------------------------------------------------------------------]]
|
yellowfive@57
|
139 local function Constructor()
|
yellowfive@57
|
140 local num = AceGUI:GetNextWidgetNum(Type)
|
yellowfive@57
|
141 local frame = CreateFrame("Frame", "AmrUiFrame" .. num, UIParent)
|
yellowfive@57
|
142 frame:Hide()
|
yellowfive@57
|
143
|
yellowfive@57
|
144 -- make escape key close this window
|
yellowfive@57
|
145 table.insert(UISpecialFrames, frame:GetName())
|
yellowfive@57
|
146
|
yellowfive@57
|
147 frame:EnableMouse(true)
|
yellowfive@57
|
148 frame:SetMovable(true)
|
yellowfive@57
|
149 frame:SetResizable(false)
|
yellowfive@57
|
150 frame:SetFrameStrata("FULLSCREEN_DIALOG")
|
yellowfive@57
|
151 frame:SetToplevel(true)
|
yellowfive@57
|
152 frame:SetScript("OnHide", frameOnClose)
|
yellowfive@57
|
153 frame:SetScript("OnMouseDown", frameOnMouseDown)
|
yellowfive@57
|
154
|
yellowfive@57
|
155 Amr.DropShadow(frame)
|
yellowfive@57
|
156
|
yellowfive@57
|
157 local border = frame:CreateTexture(nil, "BACKGROUND", nil, 1)
|
yellowfive@57
|
158 border:SetAllPoints(true)
|
yellowfive@57
|
159
|
yellowfive@57
|
160 local bg = frame:CreateTexture(nil, "BORDER")
|
yellowfive@57
|
161 bg:SetPoint("TOPLEFT", frame, "TOPLEFT", _borderWidth, -_borderWidth)
|
yellowfive@57
|
162 bg:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -_borderWidth, _borderWidth)
|
yellowfive@57
|
163
|
yellowfive@57
|
164 local btnClose = CreateFrame("Button", nil, frame)
|
yellowfive@69
|
165 btnClose:SetNormalTexture("Interface\\AddOns\\" .. Amr.ADDON_NAME .. "\\Media\\IconClose")
|
yellowfive@69
|
166 btnClose:SetHighlightTexture("Interface\\AddOns\\" .. Amr.ADDON_NAME .. "\\Media\\IconCloseOver")
|
yellowfive@69
|
167
|
yellowfive@69
|
168 --btnClose:SetNormalFontObject(Amr.CreateFont("Bold", 16, Amr.Colors.White))
|
yellowfive@69
|
169 --btnClose:SetText("x")
|
yellowfive@57
|
170 btnClose:SetWidth(22)
|
yellowfive@57
|
171 btnClose:SetHeight(22)
|
yellowfive@57
|
172 btnClose:SetPoint("TOPRIGHT", frame, "TOPRIGHT", -4, -4)
|
yellowfive@57
|
173 btnClose:SetScript("OnClick", buttonOnClick)
|
yellowfive@57
|
174
|
yellowfive@69
|
175 --local lbl = btnClose:GetFontString()
|
yellowfive@69
|
176 --lbl:ClearAllPoints()
|
yellowfive@69
|
177 --lbl:SetPoint("TOP", btnClose, "TOP", -1, -2)
|
yellowfive@57
|
178
|
yellowfive@57
|
179 -- style the button similar to AmrUiButton
|
yellowfive@69
|
180 --[[
|
yellowfive@57
|
181 Amr.DropShadow(btnClose)
|
yellowfive@57
|
182
|
yellowfive@57
|
183 local tex = Amr.CreateTexture(btnClose, Amr.Colors.Red)
|
yellowfive@57
|
184 tex:SetAllPoints(true)
|
yellowfive@57
|
185 btnClose:SetNormalTexture(tex)
|
yellowfive@57
|
186
|
yellowfive@57
|
187 tex = Amr.CreateTexture(btnClose, Amr.Colors.Red)
|
yellowfive@57
|
188 tex:SetPoint("TOPLEFT", btnClose, "TOPLEFT", 1, -1)
|
yellowfive@57
|
189 tex:SetPoint("BOTTOMRIGHT", btnClose, "BOTTOMRIGHT", 1, -1)
|
yellowfive@57
|
190 btnClose:SetPushedTexture(tex)
|
yellowfive@57
|
191
|
yellowfive@57
|
192 tex = Amr.CreateTexture(btnClose, Amr.Colors.White, 0.1)
|
yellowfive@57
|
193 tex:SetAllPoints(true)
|
yellowfive@57
|
194 btnClose:SetHighlightTexture(tex)
|
yellowfive@69
|
195 ]]
|
yellowfive@57
|
196
|
yellowfive@57
|
197 -- title
|
yellowfive@57
|
198 local titleFrame = CreateFrame("Frame", nil, frame)
|
yellowfive@57
|
199 titleFrame:SetPoint("TOPLEFT", frame, "TOPLEFT", 0, 0)
|
yellowfive@57
|
200 titleFrame:SetPoint("BOTTOMRIGHT", frame, "TOPRIGHT", 0, -40)
|
yellowfive@57
|
201 titleFrame:EnableMouse(true)
|
yellowfive@57
|
202 titleFrame:SetScript("OnMouseDown", titleOnMouseDown)
|
yellowfive@57
|
203 titleFrame:SetScript("OnMouseUp", titleOnMouseUp)
|
yellowfive@57
|
204
|
yellowfive@57
|
205 --Container Support
|
yellowfive@57
|
206 local content = CreateFrame("Frame", nil, frame)
|
yellowfive@57
|
207 content:SetPoint("TOPLEFT", titleFrame, "BOTTOMLEFT", 20, 0)
|
yellowfive@57
|
208 content:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -20, 20)
|
yellowfive@57
|
209
|
yellowfive@57
|
210 local widget = {
|
yellowfive@57
|
211 localstatus = {},
|
yellowfive@57
|
212 border = border,
|
yellowfive@57
|
213 bg = bg,
|
yellowfive@57
|
214 content = content,
|
yellowfive@57
|
215 frame = frame,
|
yellowfive@57
|
216 type = Type
|
yellowfive@57
|
217 }
|
yellowfive@57
|
218 for method, func in pairs(methods) do
|
yellowfive@57
|
219 widget[method] = func
|
yellowfive@57
|
220 end
|
yellowfive@57
|
221 btnClose.obj, titleFrame.obj = widget, widget
|
yellowfive@57
|
222
|
yellowfive@57
|
223 return AceGUI:RegisterAsContainer(widget)
|
yellowfive@57
|
224 end
|
yellowfive@57
|
225
|
yellowfive@57
|
226 AceGUI:RegisterWidgetType(Type, Constructor, Version)
|