Skip to content

Commit

Permalink
feat: rework the minimap icon to use default implementation
Browse files Browse the repository at this point in the history
This should make it addon compatible and probably work with minimaps that are like square
  • Loading branch information
nulian committed Apr 21, 2024
1 parent a48fb82 commit 1fc1bd5
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 342 deletions.
83 changes: 23 additions & 60 deletions Libraries/CallbackHandler-1.0.lua
Original file line number Diff line number Diff line change
@@ -1,61 +1,26 @@
--[[ $Id: CallbackHandler-1.0.lua 3 2008-09-29 16:54:20Z nevcairiel $ ]]
local MAJOR, MINOR = "CallbackHandler-1.0", 3
--[[ $Id: CallbackHandler-1.0.lua 26 2022-12-12 15:09:39Z nevcairiel $ ]]
local MAJOR, MINOR = "CallbackHandler-1.0", 8
local CallbackHandler = LibStub:NewLibrary(MAJOR, MINOR)

if not CallbackHandler then return end -- No upgrade needed

local meta = {__index = function(tbl, key) tbl[key] = {} return tbl[key] end}

local type = type
local pcall = pcall
local pairs = pairs
local assert = assert
local concat = table.concat
local loadstring = loadstring
local next = next
local select = select
local type = type
local xpcall = xpcall

local function errorhandler(err)
return geterrorhandler()(err)
end

local function CreateDispatcher(argCount)
local code = [[
local next, xpcall, eh = ...
local method, ARGS
local function call() method(ARGS) end
local function dispatch(handlers, ...)
local index
index, method = next(handlers)
if not method then return end
local OLD_ARGS = ARGS
ARGS = ...
repeat
xpcall(call, eh)
index, method = next(handlers, index)
until not method
ARGS = OLD_ARGS
end
-- Lua APIs
local securecallfunction, error = securecallfunction, error
local setmetatable, rawget = setmetatable, rawget
local next, select, pairs, type, tostring = next, select, pairs, type, tostring

return dispatch
]]

local ARGS, OLD_ARGS = {}, {}
for i = 1, argCount do ARGS[i], OLD_ARGS[i] = "arg"..i, "old_arg"..i end
code = code:gsub("OLD_ARGS", concat(OLD_ARGS, ", ")):gsub("ARGS", concat(ARGS, ", "))
return assert(loadstring(code, "safecall Dispatcher["..argCount.."]"))(next, xpcall, errorhandler)
local function Dispatch(handlers, ...)
local index, method = next(handlers)
if not method then return end
repeat
securecallfunction(method, ...)
index, method = next(handlers, index)
until not method
end

local Dispatchers = setmetatable({}, {__index=function(self, argCount)
local dispatcher = CreateDispatcher(argCount)
rawset(self, argCount, dispatcher)
return dispatcher
end})

--------------------------------------------------------------------------
-- CallbackHandler:New
--
Expand All @@ -64,9 +29,7 @@ end})
-- UnregisterName - name of the callback unregistration API, default "UnregisterCallback"
-- UnregisterAllName - name of the API to unregister all callbacks, default "UnregisterAllCallbacks". false == don't publish this API.

function CallbackHandler:New(target, RegisterName, UnregisterName, UnregisterAllName, OnUsed, OnUnused)
-- TODO: Remove this after beta has gone out
assert(not OnUsed and not OnUnused, "ACE-80: OnUsed/OnUnused are deprecated. Callbacks are now done to registry.OnUsed and registry.OnUnused")
function CallbackHandler.New(_self, target, RegisterName, UnregisterName, UnregisterAllName)

RegisterName = RegisterName or "RegisterCallback"
UnregisterName = UnregisterName or "UnregisterCallback"
Expand All @@ -88,19 +51,19 @@ function CallbackHandler:New(target, RegisterName, UnregisterName, UnregisterAll
local oldrecurse = registry.recurse
registry.recurse = oldrecurse + 1

Dispatchers[select('#', ...) + 1](events[eventname], eventname, ...)
Dispatch(events[eventname], eventname, ...)

registry.recurse = oldrecurse

if registry.insertQueue and oldrecurse==0 then
-- Something in one of our callbacks wanted to register more callbacks; they got queued
for eventname,callbacks in pairs(registry.insertQueue) do
local first = not rawget(events, eventname) or not next(events[eventname]) -- test for empty before. not test for one member after. that one member may have been overwritten.
for self,func in pairs(callbacks) do
events[eventname][self] = func
for event,callbacks in pairs(registry.insertQueue) do
local first = not rawget(events, event) or not next(events[event]) -- test for empty before. not test for one member after. that one member may have been overwritten.
for object,func in pairs(callbacks) do
events[event][object] = func
-- fire OnUsed callback?
if first and registry.OnUsed then
registry.OnUsed(registry, target, eventname)
registry.OnUsed(registry, target, event)
first = nil
end
end
Expand Down Expand Up @@ -146,9 +109,9 @@ function CallbackHandler:New(target, RegisterName, UnregisterName, UnregisterAll
regfunc = function(...) self[method](self,...) end
end
else
-- function ref with self=object or self="addonId"
if type(self)~="table" and type(self)~="string" then
error("Usage: "..RegisterName.."(self or \"addonId\", eventname, method): 'self or addonId': table or string expected.", 2)
-- function ref with self=object or self="addonId" or self=thread
if type(self)~="table" and type(self)~="string" and type(self)~="thread" then
error("Usage: "..RegisterName.."(self or \"addonId\", eventname, method): 'self or addonId': table or string or thread expected.", 2)
end

if select("#",...)>=1 then -- this is not the same as testing for arg==nil!
Expand Down
81 changes: 51 additions & 30 deletions Libraries/LibStub.lua
Original file line number Diff line number Diff line change
@@ -1,30 +1,51 @@
-- LibStub is a simple versioning stub meant for use in Libraries. http://www.wowace.com/wiki/LibStub for more info
-- LibStub is hereby placed in the Public Domain Credits: Kaelten, Cladhaire, ckknight, Mikk, Ammo, Nevcairiel, joshborke
local LIBSTUB_MAJOR, LIBSTUB_MINOR = "LibStub", 2 -- NEVER MAKE THIS AN SVN REVISION! IT NEEDS TO BE USABLE IN ALL REPOS!
local LibStub = _G[LIBSTUB_MAJOR]

if not LibStub or LibStub.minor < LIBSTUB_MINOR then
LibStub = LibStub or {libs = {}, minors = {} }
_G[LIBSTUB_MAJOR] = LibStub
LibStub.minor = LIBSTUB_MINOR

function LibStub:NewLibrary(major, minor)
assert(type(major) == "string", "Bad argument #2 to `NewLibrary' (string expected)")
minor = assert(tonumber(strmatch(minor, "%d+")), "Minor version must either be a number or contain a number.")

local oldminor = self.minors[major]
if oldminor and oldminor >= minor then return nil end
self.minors[major], self.libs[major] = minor, self.libs[major] or {}
return self.libs[major], oldminor
end

function LibStub:GetLibrary(major, silent)
if not self.libs[major] and not silent then
error(("Cannot find a library instance of %q."):format(tostring(major)), 2)
end
return self.libs[major], self.minors[major]
end

function LibStub:IterateLibraries() return pairs(self.libs) end
setmetatable(LibStub, { __call = LibStub.GetLibrary })
end
-- $Id: LibStub.lua 76 2007-09-03 01:50:17Z mikk $
-- LibStub is a simple versioning stub meant for use in Libraries. http://www.wowace.com/wiki/LibStub for more info
-- LibStub is hereby placed in the Public Domain
-- Credits: Kaelten, Cladhaire, ckknight, Mikk, Ammo, Nevcairiel, joshborke
local LIBSTUB_MAJOR, LIBSTUB_MINOR = "LibStub", 2 -- NEVER MAKE THIS AN SVN REVISION! IT NEEDS TO BE USABLE IN ALL REPOS!
local LibStub = _G[LIBSTUB_MAJOR]

-- Check to see is this version of the stub is obsolete
if not LibStub or LibStub.minor < LIBSTUB_MINOR then
LibStub = LibStub or {libs = {}, minors = {} }
_G[LIBSTUB_MAJOR] = LibStub
LibStub.minor = LIBSTUB_MINOR

-- LibStub:NewLibrary(major, minor)
-- major (string) - the major version of the library
-- minor (string or number ) - the minor version of the library
--
-- returns nil if a newer or same version of the lib is already present
-- returns empty library object or old library object if upgrade is needed
function LibStub:NewLibrary(major, minor)
assert(type(major) == "string", "Bad argument #2 to `NewLibrary' (string expected)")
minor = assert(tonumber(strmatch(minor, "%d+")), "Minor version must either be a number or contain a number.")

local oldminor = self.minors[major]
if oldminor and oldminor >= minor then return nil end
self.minors[major], self.libs[major] = minor, self.libs[major] or {}
return self.libs[major], oldminor
end

-- LibStub:GetLibrary(major, [silent])
-- major (string) - the major version of the library
-- silent (boolean) - if true, library is optional, silently return nil if its not found
--
-- throws an error if the library can not be found (except silent is set)
-- returns the library object if found
function LibStub:GetLibrary(major, silent)
if not self.libs[major] and not silent then
error(("Cannot find a library instance of %q."):format(tostring(major)), 2)
end
return self.libs[major], self.minors[major]
end

-- LibStub:IterateLibraries()
--
-- Returns an iterator for the currently registered libraries
function LibStub:IterateLibraries()
return pairs(self.libs)
end

setmetatable(LibStub, { __call = LibStub.GetLibrary })
end
23 changes: 3 additions & 20 deletions Outfitter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1377,7 +1377,6 @@ function Outfitter:UpdateCurrentOutfitIcon()
if type(vTexture) == "number" then
vTexture = self:ConvertTextureIDToPath(vTexture)
end
SetPortraitToTexture(OutfitterMinimapButton.CurrentOutfitTexture, vTexture)
end

function Outfitter:BankFrameOpened()
Expand Down Expand Up @@ -2338,9 +2337,9 @@ function Outfitter:SetShowMinimapButton(pShowButton)
self.Settings.Options.HideMinimapButton = not pShowButton

if self.Settings.Options.HideMinimapButton then
OutfitterMinimapButton:Hide()
Outfitter.LDB:HideIcon()
else
OutfitterMinimapButton:Show()
Outfitter.LDB:ShowIcon()
end

self:Update(false)
Expand Down Expand Up @@ -4761,23 +4760,7 @@ function Outfitter:Initialize()
end
end

-- Set the minimap button
if self.Settings.Options.HideMinimapButton then
OutfitterMinimapButton:Hide()
else
OutfitterMinimapButton:Show()
end

if not self.Settings.Options.MinimapButtonAngle
and not self.Settings.Options.MinimapButtonX then
self.Settings.Options.MinimapButtonAngle = -1.5708
end

if self.Settings.Options.MinimapButtonAngle then
OutfitterMinimapButton:SetPositionAngle(self.Settings.Options.MinimapButtonAngle)
else
OutfitterMinimapButton:SetPosition(self.Settings.Options.MinimapButtonX, self.Settings.Options.MinimapButtonY)
end
Outfitter.LDB:CreateIcon(self.Settings.Options.HideMinimapButton)

-- Move the Blizzard UI over a bit
PaperDollSidebarTabs:SetPoint("BOTTOMRIGHT", CharacterFrameInsetRight, "TOPRIGHT", -30, -1)
Expand Down
5 changes: 3 additions & 2 deletions Outfitter.toc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## Interface: 100200
## Interface: 100206
## Author: John Stephen
## Title: Outfitter
## Version: 10.2.0.0
## Version: 10.2.6.0
## Notes: Clothing and weapon management and automated equipment changes
## OptionalDeps:
## RequiredDeps:
Expand All @@ -19,6 +19,7 @@ Libraries/UTF8/utf8.lua
Libraries/LibStub.lua
Libraries/CallbackHandler-1.0.lua
Libraries/LibDataBroker-1.1.lua
Libraries/LibDBIcon-1.0.lua
Libraries/LibBabble-3.0.lua
Libraries/LibBabble-SubZone-3.0.lua
Libraries/LibBabble-Inventory-3.0.lua
Expand Down
36 changes: 0 additions & 36 deletions Outfitter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1289,42 +1289,6 @@
</Frame>
</Frames>
</Frame>
<Button name="OutfitterMinimapButton" hidden="false" enableMouse="true" movable="true" parent="MinimapBackdrop">
<Size>
<AbsDimension x="32" y="32"/>
</Size>
<Anchors>
<Anchor point="CENTER">
<Offset><AbsDimension x="-80" y="0"/></Offset>
</Anchor>
</Anchors>
<Scripts>
<OnLoad>
self.Inherit = Outfitter.Inherit
self:Inherit(Outfitter._MinimapButton)
</OnLoad>
<OnDragStart>
self:DragStart()
</OnDragStart>
<OnDragStop>
self:DragEnd()
</OnDragStop>
<OnMouseDown>
self:MouseDown()
</OnMouseDown>
<OnMouseUp>
self:ToggleMenu()
</OnMouseUp>
<OnEnter>
Outfitter.AddNewbieTip(self, Outfitter.cMinimapButtonTitle, 1, 1, 1, Outfitter.cMinimapButtonDescription, 1)
</OnEnter>
<OnLeave>
GameTooltip:Hide()
</OnLeave>
</Scripts>
<NormalTexture file="Interface\Addons\Outfitter\Textures\MinimapButton"/>
<HighlightTexture alphaMode="ADD" file="Interface\Minimap\UI-Minimap-ZoomButton-Highlight"/>
</Button>

<GameTooltip name="OutfitterTooltip" parent="UIParent" hidden="true" inherits="GameTooltipTemplate">
<Anchors>
Expand Down
14 changes: 14 additions & 0 deletions OutfitterLDB.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@ function Outfitter.LDB:Initialize()
Outfitter:RegisterOutfitEvent("OUTFITTER_INIT", function (...) self:OutfitEvent(...) end)
end

function Outfitter.LDB:CreateIcon(hideMinimapButton)
self.icon = LibStub("LibDBIcon-1.0")

self.icon:Register(Outfitter.cTitle, self.DataObj, { hide = hideMinimapButton })
end

function Outfitter.LDB:ShowIcon()
self.icon:Show(Outfitter.cTitle)
end

function Outfitter.LDB:HideIcon()
self.icon:Hide(Outfitter.cTitle)
end

function Outfitter.LDB:OnClick(pFrame, pButton)
if pButton == "LeftButton" then
self:ToggleMenu()
Expand Down
Loading

0 comments on commit 1fc1bd5

Please sign in to comment.