Mercurial > wow > askmrrobot
comparison Libs/AceGUI-3.0/widgets/AceGUIContainer-DropDownGroup.lua @ 57:01b63b8ed811 v21
total rewrite to version 21
| author | yellowfive |
|---|---|
| date | Fri, 05 Jun 2015 11:05:15 -0700 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 56:75431c084aa0 | 57:01b63b8ed811 |
|---|---|
| 1 --[[----------------------------------------------------------------------------- | |
| 2 DropdownGroup Container | |
| 3 Container controlled by a dropdown on the top. | |
| 4 -------------------------------------------------------------------------------]] | |
| 5 local Type, Version = "DropdownGroup", 21 | |
| 6 local AceGUI = LibStub and LibStub("AceGUI-3.0", true) | |
| 7 if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end | |
| 8 | |
| 9 -- Lua APIs | |
| 10 local assert, pairs, type = assert, pairs, type | |
| 11 | |
| 12 -- WoW APIs | |
| 13 local CreateFrame = CreateFrame | |
| 14 | |
| 15 --[[----------------------------------------------------------------------------- | |
| 16 Scripts | |
| 17 -------------------------------------------------------------------------------]] | |
| 18 local function SelectedGroup(self, event, value) | |
| 19 local group = self.parentgroup | |
| 20 local status = group.status or group.localstatus | |
| 21 status.selected = value | |
| 22 self.parentgroup:Fire("OnGroupSelected", value) | |
| 23 end | |
| 24 | |
| 25 --[[----------------------------------------------------------------------------- | |
| 26 Methods | |
| 27 -------------------------------------------------------------------------------]] | |
| 28 local methods = { | |
| 29 ["OnAcquire"] = function(self) | |
| 30 self.dropdown:SetText("") | |
| 31 self:SetDropdownWidth(200) | |
| 32 self:SetTitle("") | |
| 33 end, | |
| 34 | |
| 35 ["OnRelease"] = function(self) | |
| 36 self.dropdown.list = nil | |
| 37 self.status = nil | |
| 38 for k in pairs(self.localstatus) do | |
| 39 self.localstatus[k] = nil | |
| 40 end | |
| 41 end, | |
| 42 | |
| 43 ["SetTitle"] = function(self, title) | |
| 44 self.titletext:SetText(title) | |
| 45 self.dropdown.frame:ClearAllPoints() | |
| 46 if title and title ~= "" then | |
| 47 self.dropdown.frame:SetPoint("TOPRIGHT", -2, 0) | |
| 48 else | |
| 49 self.dropdown.frame:SetPoint("TOPLEFT", -1, 0) | |
| 50 end | |
| 51 end, | |
| 52 | |
| 53 ["SetGroupList"] = function(self,list,order) | |
| 54 self.dropdown:SetList(list,order) | |
| 55 end, | |
| 56 | |
| 57 ["SetStatusTable"] = function(self, status) | |
| 58 assert(type(status) == "table") | |
| 59 self.status = status | |
| 60 end, | |
| 61 | |
| 62 ["SetGroup"] = function(self,group) | |
| 63 self.dropdown:SetValue(group) | |
| 64 local status = self.status or self.localstatus | |
| 65 status.selected = group | |
| 66 self:Fire("OnGroupSelected", group) | |
| 67 end, | |
| 68 | |
| 69 ["OnWidthSet"] = function(self, width) | |
| 70 local content = self.content | |
| 71 local contentwidth = width - 26 | |
| 72 if contentwidth < 0 then | |
| 73 contentwidth = 0 | |
| 74 end | |
| 75 content:SetWidth(contentwidth) | |
| 76 content.width = contentwidth | |
| 77 end, | |
| 78 | |
| 79 ["OnHeightSet"] = function(self, height) | |
| 80 local content = self.content | |
| 81 local contentheight = height - 63 | |
| 82 if contentheight < 0 then | |
| 83 contentheight = 0 | |
| 84 end | |
| 85 content:SetHeight(contentheight) | |
| 86 content.height = contentheight | |
| 87 end, | |
| 88 | |
| 89 ["LayoutFinished"] = function(self, width, height) | |
| 90 self:SetHeight((height or 0) + 63) | |
| 91 end, | |
| 92 | |
| 93 ["SetDropdownWidth"] = function(self, width) | |
| 94 self.dropdown:SetWidth(width) | |
| 95 end | |
| 96 } | |
| 97 | |
| 98 --[[----------------------------------------------------------------------------- | |
| 99 Constructor | |
| 100 -------------------------------------------------------------------------------]] | |
| 101 local PaneBackdrop = { | |
| 102 bgFile = "Interface\\ChatFrame\\ChatFrameBackground", | |
| 103 edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", | |
| 104 tile = true, tileSize = 16, edgeSize = 16, | |
| 105 insets = { left = 3, right = 3, top = 5, bottom = 3 } | |
| 106 } | |
| 107 | |
| 108 local function Constructor() | |
| 109 local frame = CreateFrame("Frame") | |
| 110 frame:SetHeight(100) | |
| 111 frame:SetWidth(100) | |
| 112 frame:SetFrameStrata("FULLSCREEN_DIALOG") | |
| 113 | |
| 114 local titletext = frame:CreateFontString(nil, "OVERLAY", "GameFontNormal") | |
| 115 titletext:SetPoint("TOPLEFT", 4, -5) | |
| 116 titletext:SetPoint("TOPRIGHT", -4, -5) | |
| 117 titletext:SetJustifyH("LEFT") | |
| 118 titletext:SetHeight(18) | |
| 119 | |
| 120 local dropdown = AceGUI:Create("Dropdown") | |
| 121 dropdown.frame:SetParent(frame) | |
| 122 dropdown.frame:SetFrameLevel(dropdown.frame:GetFrameLevel() + 2) | |
| 123 dropdown:SetCallback("OnValueChanged", SelectedGroup) | |
| 124 dropdown.frame:SetPoint("TOPLEFT", -1, 0) | |
| 125 dropdown.frame:Show() | |
| 126 dropdown:SetLabel("") | |
| 127 | |
| 128 local border = CreateFrame("Frame", nil, frame) | |
| 129 border:SetPoint("TOPLEFT", 0, -26) | |
| 130 border:SetPoint("BOTTOMRIGHT", 0, 3) | |
| 131 border:SetBackdrop(PaneBackdrop) | |
| 132 border:SetBackdropColor(0.1,0.1,0.1,0.5) | |
| 133 border:SetBackdropBorderColor(0.4,0.4,0.4) | |
| 134 | |
| 135 --Container Support | |
| 136 local content = CreateFrame("Frame", nil, border) | |
| 137 content:SetPoint("TOPLEFT", 10, -10) | |
| 138 content:SetPoint("BOTTOMRIGHT", -10, 10) | |
| 139 | |
| 140 local widget = { | |
| 141 frame = frame, | |
| 142 localstatus = {}, | |
| 143 titletext = titletext, | |
| 144 dropdown = dropdown, | |
| 145 border = border, | |
| 146 content = content, | |
| 147 type = Type | |
| 148 } | |
| 149 for method, func in pairs(methods) do | |
| 150 widget[method] = func | |
| 151 end | |
| 152 dropdown.parentgroup = widget | |
| 153 | |
| 154 return AceGUI:RegisterAsContainer(widget) | |
| 155 end | |
| 156 | |
| 157 AceGUI:RegisterWidgetType(Type, Constructor, Version) |
