annotate ui/AmrUiFrame.lua @ 133:a0894ffebd15 v62

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