comparison ui/AmrUiFrame.lua @ 57:01b63b8ed811 v21

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