Quantcast
LibDBIcon ... how to hide ? - WoWInterface
Thread Tools Display Modes
03-29-20, 03:46 AM   #1
gmarco
A Frostmaul Preserver
 
gmarco's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 290
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.
__________________
This is Unix-Land. In quiet nights, you can hear the Windows machines reboot.
  Reply With Quote
03-29-20, 09:00 AM   #2
Rilgamon
Premium Member
 
Rilgamon's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 778
The lib provides a function that takes the name.
ldbicon:Hide(objname)
__________________
The cataclysm broke the world ... and the pandas could not fix it!
  Reply With Quote
03-29-20, 09:03 AM   #3
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,117
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
  Reply With Quote
03-29-20, 11:44 AM   #4
gmarco
A Frostmaul Preserver
 
gmarco's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 290
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.
__________________
This is Unix-Land. In quiet nights, you can hear the Windows machines reboot.
  Reply With Quote
03-29-20, 12:00 PM   #5
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,117
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
  Reply With Quote
03-29-20, 01:43 PM   #6
gmarco
A Frostmaul Preserver
 
gmarco's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 290
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.
__________________
This is Unix-Land. In quiet nights, you can hear the Windows machines reboot.
  Reply With Quote
03-29-20, 06:04 PM   #7
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,257
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)).
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 03-30-20 at 12:07 AM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » LibDBIcon ... how to hide ?

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off