Mercurial > wow > reaction
comparison Bar.lua @ 71:3d2cef5dc459
Implemented state anchoring and scaling
| author | Flick <flickerstreak@gmail.com> |
|---|---|
| date | Wed, 04 Jun 2008 21:46:51 +0000 |
| parents | 2c12e2b1752e |
| children | aa88aed52124 |
comparison
equal
deleted
inserted
replaced
| 70:2c12e2b1752e | 71:3d2cef5dc459 |
|---|---|
| 5 local InCombatLockdown = InCombatLockdown | 5 local InCombatLockdown = InCombatLockdown |
| 6 local floor = math.floor | 6 local floor = math.floor |
| 7 local min = math.min | 7 local min = math.min |
| 8 local format = string.format | 8 local format = string.format |
| 9 local GameTooltip = GameTooltip | 9 local GameTooltip = GameTooltip |
| 10 local SecureStateHeader_Refresh = SecureStateHeader_Refresh | |
| 10 | 11 |
| 11 | 12 |
| 12 | 13 |
| 13 -- update ReAction revision if this file is newer | 14 -- update ReAction revision if this file is newer |
| 14 local revision = tonumber(("$Revision$"):match("%d+")) | 15 local revision = tonumber(("$Revision$"):match("%d+")) |
| 167 f:SetPoint("TOPLEFT",x/scale,-y/scale) | 168 f:SetPoint("TOPLEFT",x/scale,-y/scale) |
| 168 f:SetScale(scale) | 169 f:SetScale(scale) |
| 169 self.buttons[f] = true | 170 self.buttons[f] = true |
| 170 end | 171 end |
| 171 | 172 |
| 173 | |
| 174 -- multi-state functions -- | |
| 172 function Bar:GetNumPages() | 175 function Bar:GetNumPages() |
| 173 return self.config.nPages or 1 | 176 return self.config.nPages or 1 |
| 174 end | 177 end |
| 175 | 178 |
| 176 function Bar:SetHideStates(s) | 179 function Bar:SetHideStates(s) |
| 181 end | 184 end |
| 182 SecureStateHeader_Refresh(self.frame) | 185 SecureStateHeader_Refresh(self.frame) |
| 183 end | 186 end |
| 184 | 187 |
| 185 function Bar:SetStateKeybind(key, state, defaultstate) | 188 function Bar:SetStateKeybind(key, state, defaultstate) |
| 189 -- set a keybind to toggle transitioning unconditionally to a state | |
| 186 -- use a tiny offscreen button to get around making the bar itself a clickable button | 190 -- use a tiny offscreen button to get around making the bar itself a clickable button |
| 187 local f = self.statebuttonframe | 191 local f = self.statebuttonframe |
| 188 local off = ("%s_off"):format(state) | 192 local off = ("%s_off"):format(state) |
| 189 if key then | 193 if key then |
| 190 if not f then | 194 if not f then |
| 218 | 222 |
| 219 function Bar:SetStatePageMap(state, map) -- map is a { ["statename"] = pagenumber } table | 223 function Bar:SetStatePageMap(state, map) -- map is a { ["statename"] = pagenumber } table |
| 220 local f = self.frame | 224 local f = self.frame |
| 221 local tmp = { } | 225 local tmp = { } |
| 222 for s, p in pairs(map) do | 226 for s, p in pairs(map) do |
| 223 table.insert(tmp, ("%s:%d"):format(s,p)) | 227 table.insert(tmp, ("%s:page%d"):format(s,p)) |
| 224 end | 228 end |
| 225 local spec = table.concat(tmp,";") | 229 local spec = table.concat(tmp,";") |
| 226 f:SetAttribute("statebutton",spec) | 230 f:SetAttribute("statebutton",spec) |
| 231 SecureStateHeader_Refresh(f) | |
| 227 end | 232 end |
| 228 | 233 |
| 229 function Bar:SetStateKeybindOverrideMap(states) -- 'states' is an array of state-names that should have keybind overrides enabled | 234 function Bar:SetStateKeybindOverrideMap(states) -- 'states' is an array of state-names that should have keybind overrides enabled |
| 230 local f = self.frame | 235 local f = self.frame |
| 231 for i = 1, #states do | 236 for i = 1, #states do |
| 232 local s = states[i] | 237 local s = states[i] |
| 233 states[i] = ("%s:%s"):format(s,s) | 238 states[i] = ("%s:%s"):format(s,s) |
| 234 end | 239 end |
| 235 table.insert(states,"_default") | 240 table.insert(states,"_defaultbindings") |
| 236 f:SetAttribute("statebindings",table.concat(states,";")) | 241 f:SetAttribute("statebindings",table.concat(states,";")) |
| 242 SecureStateHeader_Refresh(f) | |
| 237 for b in pairs(self.buttons) do | 243 for b in pairs(self.buttons) do |
| 238 -- TODO: signal child frames that they should | 244 -- TODO: signal child frames that they should maintain multiple bindings |
| 239 -- maintain multiple bindings | 245 end |
| 240 end | 246 end |
| 241 end | 247 |
| 248 local _ofskeys = { "point", "relpoint", "x", "y" } | |
| 249 function Bar:SetStateAnchorMap( map ) -- 'map' is a { ["statename"] = { point=point, relpoint=relpoint, x=x, y=y } } table | |
| 250 local f = self.frame | |
| 251 local c = self.config | |
| 252 local default = { point = c.anchor, relpoint = c.relativePoint, x = c.x, y = c.y } | |
| 253 for _, key in pairs(_ofskeys) do | |
| 254 local t = { } | |
| 255 for state, info in pairs(map) do | |
| 256 if info[key] then | |
| 257 table.insert(t, ("%s:%s"):format(state, info[key])) | |
| 258 end | |
| 259 end | |
| 260 if #t > 0 and default[key] then table.insert(t, tostring(default[key])) end | |
| 261 f:SetAttribute(("headofs%s"):format(key), table.concat(t,";") or "") | |
| 262 end | |
| 263 SecureStateHeader_Refresh(f) | |
| 264 end | |
| 265 | |
| 266 function Bar:SetStateScaleMap( map ) -- 'map' is a { ["statename"] = scalevalue } table | |
| 267 local f = self.frame | |
| 268 local t = { } | |
| 269 for state, scale in pairs(map) do | |
| 270 table.insert( t, ("%s:%s"):format(state,scale) ) | |
| 271 end | |
| 272 if #t > 0 then table.insert(t, "1.0") end | |
| 273 f:SetAttribute("headscale",table.concat(t,";") or "") | |
| 274 SecureStateHeader_Refresh(f) | |
| 275 end | |
| 276 | |
| 242 | 277 |
| 243 -- | 278 -- |
| 244 -- Bar config overlay | 279 -- Bar config overlay |
| 245 -- | 280 -- |
| 246 local CreateControls | 281 local CreateControls |
| 595 si1:Hide() | 630 si1:Hide() |
| 596 si2:Hide() | 631 si2:Hide() |
| 597 end | 632 end |
| 598 end | 633 end |
| 599 | 634 |
| 600 CreateControls = function(bar) | 635 function CreateControls(bar) |
| 601 local f = bar.frame | 636 local f = bar.frame |
| 602 | 637 |
| 603 f:SetMovable(true) | 638 f:SetMovable(true) |
| 604 f:SetResizable(true) | 639 f:SetResizable(true) |
| 605 f:SetClampedToScreen(true) | 640 f:SetClampedToScreen(true) |
| 645 label:SetTextColor(1,1,1,1) | 680 label:SetTextColor(1,1,1,1) |
| 646 label:SetText(bar:GetName()) | 681 label:SetText(bar:GetName()) |
| 647 label:Show() | 682 label:Show() |
| 648 bar.controlLabelString = label -- so that bar:SetName() can update it | 683 bar.controlLabelString = label -- so that bar:SetName() can update it |
| 649 | 684 |
| 650 local StopResize = function() | 685 local function StopResize() |
| 651 f:StopMovingOrSizing() | 686 f:StopMovingOrSizing() |
| 652 f.isMoving = false | 687 f.isMoving = false |
| 653 f:SetScript("OnUpdate",nil) | 688 f:SetScript("OnUpdate",nil) |
| 654 StoreSize(bar) | 689 StoreSize(bar) |
| 655 ClampToButtons(bar) | 690 ClampToButtons(bar) |
| 713 local tex = corner:CreateTexture(nil,"HIGHLIGHT") | 748 local tex = corner:CreateTexture(nil,"HIGHLIGHT") |
| 714 tex:SetTexture(1.0,0.82,0,0.7) | 749 tex:SetTexture(1.0,0.82,0,0.7) |
| 715 tex:SetBlendMode("ADD") | 750 tex:SetBlendMode("ADD") |
| 716 tex:SetAllPoints() | 751 tex:SetAllPoints() |
| 717 corner:RegisterForDrag("LeftButton","RightButton") | 752 corner:RegisterForDrag("LeftButton","RightButton") |
| 718 local updateTooltip = function() | 753 local function updateTooltip() |
| 719 local size, size2 = bar:GetButtonSize() | 754 local size, size2 = bar:GetButtonSize() |
| 720 local rows, cols, spacing = bar:GetButtonGrid() | 755 local rows, cols, spacing = bar:GetButtonGrid() |
| 721 size = (size == size2) and tostring(size) or format("%dx%d",size,size2) | 756 size = (size == size2) and tostring(size) or format("%dx%d",size,size2) |
| 722 GameTooltipTextRight4:SetText(size) | 757 GameTooltipTextRight4:SetText(size) |
| 723 GameTooltipTextRight5:SetText(tostring(spacing)) | 758 GameTooltipTextRight5:SetText(tostring(spacing)) |
| 861 -- Looking for a lightweight AceConfig3-struct-compatible | 896 -- Looking for a lightweight AceConfig3-struct-compatible |
| 862 -- replacement for Dewdrop, encapsulate here | 897 -- replacement for Dewdrop, encapsulate here |
| 863 -- Considering Blizzard's EasyMenu/UIDropDownMenu, but that's | 898 -- Considering Blizzard's EasyMenu/UIDropDownMenu, but that's |
| 864 -- a bit tricky to convert from AceConfig3-struct | 899 -- a bit tricky to convert from AceConfig3-struct |
| 865 local Dewdrop = AceLibrary("Dewdrop-2.0") | 900 local Dewdrop = AceLibrary("Dewdrop-2.0") |
| 866 OpenMenu = function(frame, opts) | 901 function OpenMenu (frame, opts) |
| 867 Dewdrop:Open(frame, "children", opts, "cursorX", true, "cursorY", true) | 902 Dewdrop:Open(frame, "children", opts, "cursorX", true, "cursorY", true) |
| 868 end | 903 end |
| 869 CloseMenu = function(frame) | 904 function CloseMenu(frame) |
| 870 if Dewdrop:GetOpenedParent() == frame then | 905 if Dewdrop:GetOpenedParent() == frame then |
| 871 Dewdrop:Close() | 906 Dewdrop:Close() |
| 872 end | 907 end |
| 873 end | 908 end |
| 874 end | 909 end |
