WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   LibDBIcon ... how to hide ? (https://www.wowinterface.com/forums/showthread.php?t=57893)

gmarco 03-29-20 03:46 AM

LibDBIcon ... how to hide ?
 
Hi everyone.

I have done a lot of addon using LDB (and recently I am trying to convert them to libqtip).
Some friends of mine dont use a databroker display so I thought to use the minimap to attach these addons to an icon on it.

I usually use a code like this:

Lua Code:
  1. local LibQTip = LibStub('LibQTip-1.0')
  2. local ldb = LibStub:GetLibrary("LibDataBroker-1.1")
  3.  
  4. local dataobj = ldb:NewDataObject(ADDON, {
  5.     type = "data source",
  6.     icon = "Interface\\Addons\\"..ADDON.."\\icon.tga",
  7.     text = ""
  8. })
  9.  
  10. local icon = LibStub("LibDBIcon-1.0")
  11. icon:Register(ADDON, dataobj, minimapicondb)
  12.  
  13. -- or it works the same:
  14. -- LibStub("LibDBIcon-1.0"):Register(ADDON, dataobj, minimapicondb)

and it works.

But if I want to Hide/Show the icon with what I think I have to use, in this way:

Lua Code:
  1. icon:Hide(ADDON)
  2. icon:Show(ADDON)

It doesn't works.

Probably I miss something, but reading the home page of LibDBIcon and some sample here and there I thought I have put everything I need (excepts for bunnies :)

Thanks.

Rilgamon 03-29-20 09:00 AM

The lib provides a function that takes the name.
ldbicon:Hide(objname)

myrroddin 03-29-20 09:03 AM

Code:

local addon = LibStub("AceAddon-3.0"):NewAddon("MyAddOn")
local icon = LibStub("LibDBIcon-1.0")

local defaults = {
    profile = {
        enableaddon = true,
    },
    global = { -- global setting because people hate setting the icon on every profile or character
        minimap = {
            hide = false,
            lock = true,
            -- radius = 90, -- how many pixels from 0 / top of minimap
            -- minimapPos = 200 -- how far away from minimap center in pixels
        }
    }
}

local options = {
    type = "group",
    childgroups = "tab",
    name = "MyAddOn",
    desc = L["My AddOn which does stuff"],
    args = {
        enableaddon = {
            order = 10,
            name = ENABLE,
            type = "toggle",
            -- etc
        end
        },
        hideminimapbutton = {
            order = 20,
            name = L["Hide Minimap Button"],
            desc = L["Toggle hiding the button"],
            type = "toggle",
            get = function() return db.minimap.hide end,
            set = function(info, value)
                MyAddOnDB.db.minimap.hide = value
                if value then
                    icon:Hide("MyAddOn")
                else
                    icon:Show("MyAddOn")
                end
            end
        }
    }
}

function addon:OnInitialize()
    self.db = LibStub("AceDB-3.0"):New("MyAddOnDB", defaults, true)
   
    -- other setup here including registering options table

    local ldb = LibStub:GetLibrary("LibDataBroker-1.1")
 
    local dataobj = ldb:NewDataObject(addon, {
        type = "data source",
        icon = "Interface\\Addons\\MyAddOn\\icon.tga",
        label = "MyAddOn",
        OnClick = function(object, button)
            -- open configuration
        end,
        OnTooltipShow = function(tip)
            tip:AddLine(L["Click to open configuration."], NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b)
            tip:Show()
        end
    })
    icon:Register("MyAddOn", dataobj, self.db.global.minimap)
end


gmarco 03-29-20 11:44 AM

Hi myrroddin,

thanks so much for your reply.

At the moment I am using only a minimal set of libraries.

Lua Code:
  1. libs\LibStub.lua
  2. libs\CallbackHandler-1.0.lua
  3. libs\LibDataBroker-1.1.lua
  4. libs\LibQTip-1.0.lua

I don't think I can use your code. Most of it relies on ACE libraries I think, or am I wrong ?!

Btw I have make it works thanks to your inputs.

Lua Code:
  1. local ldb = LibStub:GetLibrary("LibDataBroker-1.1")
  2.  
  3. local dataobj = ldb:NewDataObject(ADDON, {
  4.     type    = "data source",
  5.     label   = "gmLm",
  6.     icon    = "Interface\\Addons\\"..ADDON.."\\icon.tga",
  7.     text    = ""
  8. })
  9.  
  10. local icon = LibStub("LibDBIcon-1.0")
  11. icon:Register("gmLm", dataobj, minimapicondb)

And then I can call:

Lua Code:
  1. icon:Show("gmLm")
  2. or
  3. icon:Hide("gmLm")

Obviusly it is a very simple solutions and it doesnt take care of saved positions and preferences, but I dont have the libs to do it I think ... or I am wrong ?

Btw thanks so much for your help.
It is so much appreciated.

myrroddin 03-29-20 12:00 PM

I'll write up something without Ace (not ACE, it isn't an acronym) later. Yes, you can use LibDBIcon-1.0 without Ace3 and you are doing it most of it already.

I do not think lines 3 and 6 sync. On line 3 ADDON is presumably a table while on line 6 you use ADDON as a string.
Code:

local addonName, ADDON = ... -- returns string, table

gmarco 03-29-20 01:43 PM

Hi myrroddin,

I always start my addons in this way:

Lua Code:
  1. local ADDON, namespace = ...
  2. local L = namespace.L
  3.  
  4. -- bla bla
  5.  
  6.  
  7. local LibQTip = LibStub('LibQTip-1.0')
  8. local ldb = LibStub:GetLibrary("LibDataBroker-1.1")
  9.  
  10. local dataobj = ldb:NewDataObject(ADDON, {
  11.     type    = "data source",
  12.     label   = "gmLm",
  13.     icon    = "Interface\\Addons\\"..ADDON.."\\icon.tga",
  14.     text    = ""
  15. })
  16.  
  17. local icon = LibStub("LibDBIcon-1.0")
  18. icon:Register("gmLm", dataobj, minimapicondb)
  19.  
  20. -- bla bla

And then I ever used ADDON as string everywhere :)

I think it is a string, but I can be wrong.
Do you think it can be a table ?

Thanks so much for your help.

Fizzlemizz 03-29-20 06:04 PM

ADDON (or whatever you call it) is always a string containing the name of the addon. You treat the ... passed to your .lua file as you would the ... passed to an OnEvent function ie. a variable number of parameters.

Blizzard may add a third or fourth ... parameter in future but as of today, it's just the two (first, a string containing the addon name (ADDON) and the second, a table that is unique to the addon (namespace)).


All times are GMT -6. The time now is 04:38 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI