WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   General Authoring Discussion (https://www.wowinterface.com/forums/forumdisplay.php?f=20)
-   -   Config.lua to ingame GUI? (https://www.wowinterface.com/forums/showthread.php?t=41256)

dreamcatcher 08-25-11 08:17 PM

Config.lua to ingame GUI?
 
Ok so I have been trying for weeks to make a in game GUI with no luck. I was hopping to do this just with lua code and no libs.
I tried looking into doing it with Ace3 but I can't understand all that has to be done and were to place the code. I added my SavedVariables field to my TOC, put all my settings into a single table. That's as far as I can get with out then getting completely lost.

Her is all of my code.

http://www.wowace.com/paste/3767/

O also when using Ace3 were do I put the files and which ones do I use, or do I just place the whole Ace3 file in the addons?

dreamcatcher 08-27-11 02:47 AM

So i finely got the GUI to show up but im getting lots of errors.

Code:

Message: Interface\AddOns\Tweaks\Core.lua:536: attempt to index upvalue 'db' (a nil value)
Time: 08/27/11 01:47:06
Count: 1
Stack: Interface\AddOns\Tweaks\Core.lua:536: in function <Interface\AddOns\Tweaks\Core.lua:534>
[C]: in function `UIParent_ManageFramePositions'
Interface\FrameXML\InterfaceOptionsPanels.lua:1284: in function `InterfaceOptions_UpdateMultiActionBars'
[string "*:OnLoad"]:4: in function `setFunc'
Interface\FrameXML\InterfaceOptionsPanels.lua:1253: in function <Interface\FrameXML\InterfaceOptionsPanels.lua:1246>

Locals: (*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = "attempt to index upvalue 'db' (a nil value)"
db = nil

Here is link to whole code.
http://www.wowace.com/paste/3784/

Nibelheim 08-27-11 03:00 AM

First, I don't see you declaring your addon at the very top in Ace fashion. Ie:

Core.lua
Code:

local MyAddon = LibStub("AceAddon-3.0"):NewAddon("MyAddon")
Config.lua
Code:

local MyAddon = LibStub("AceAddon-3.0"):GetAddon("MyAddon")

For getting DB, you'll want to put this line in:
Code:

self.db = LibStub("AceDB-3.0"):New("MyAddonDB", defaults, "Default")
I generally put my defaults table in Core.lua, along with the above line in the MyAddon:OnInitialize() function. MyAddonDB is the SavedVariable table name declared in .toc, and Default is the name of your initial profile.

To get the DB into a variable, something like this in a MyAddon:Anything() function.
Code:

db = self.db.profile

Quote:

O also when using Ace3 were do I put the files and which ones do I use, or do I just place the whole Ace3 file in the addons?
For now, you can just install Ace3 like a regular addon, this will ensure you have all the components necessary. When you finalize your addon later on, you can set up dependencies and an Embeds.xml, as well as store required Ace folders inside your addon.

Nibelheim 08-27-11 03:18 AM

Here's some quick examples of a basic Ace addon. You can install Ace3 components under MyAddon\libs\

MyAddon.toc
Embeds.xml
Core.lua
Config.lua

dreamcatcher 08-28-11 03:48 AM

First thank you for your help, I got the options to show up now and there are no errors. :D
Now I'm trying to set up all the functions and I'm having some problems. :confused:
  1. One
I don't know how to set it so I can have the option to re position the bars. My code for that is this.

Core.lua
Code:

local defaults = {
        profile = {
                MAB = {
                        Enable = true,
                        HideMacronames = true,
                        HideGryphons = false,
                        Scale = .8,
                        ["Position"] = {"BOTTOMLEFT",Minimap,-510,0},
                },

local function ActionBars()

-- MainActionBar
        for i = 1, 12 do
                local MAB = _G["ActionButton"..i]
                if (i == 1) then
        MAB:ClearAllPoints()
        MAB:SetPoint(unpack(db.MAB.Position))
                MAB:SetScale(db.MAB.Scale)
        else
        MAB:ClearAllPoints()
        MAB:SetPoint("LEFT", _G["ActionButton"..i-1],"RIGHT",6,0)
                MAB:SetScale(db.MAB.Scale)
                end
        end

Config.lua
Code:

MAB = {
        name = "MainActionBar",
        type = "group",
        order = 30,
        args = {
                Position= {
                        type = "input",
                        name = "Position",
                        order = 1,
                        set = function(info, val)
                        db.MAB.Position = val
                        MyAddon:UpdateStuff()
                        end,
                        get = function(info) return db.MAB.Position end,
                },
        },

  1. Second
I can get the end caps to show and hide but I can't get the micro names to do the same.

Core.lua
Code:

function Style(self) 
        local name = self:GetName()
        local action = self.action
        local Button = self
        local Count = _G[name.."Count"]
        local HotKey = _G[name.."HotKey"]
        local Border  = _G[name.."Border"]
        local Btname = _G[name.."Name"]
        local Normal  = _G[name.."NormalTexture"]
Btname:Show()
        Button:SetNormalTexture[[Interface\AddOns\MyAddon\Media\button]]
        Border:Hide()
        if db.MAB.HideMacronames then
        Btname:Hide()
        end
end

Config.lua
Code:

HideMacronames = {
        type = "toggle",
        name = "HideMacronames",
        order = 2,
        set = function(info, val)
        db.MAB.HideMacronames = val
        MyAddon:UpdateStuff()
        end,
        get = function(info) return db.MAB.HideMacronames end,
},


cokedrivers 08-28-11 01:16 PM

Quote:

Originally Posted by dreamcatcher (Post 243839)
First thank you for your help, I got the options to show up now and there are no errors. :D
Now I'm trying to set up all the functions and I'm having some problems. :confused:
  1. One
I don't know how to set it so I can have the option to re position the bars. My code for that is this.

Core.lua
Code:

local defaults = {
        profile = {
                MAB = {
                        Enable = true,
                        HideMacronames = true,
                        HideGryphons = false,
                        Scale = .8,
                        ["Position"] = {"BOTTOMLEFT",Minimap,-510,0},
                },

local function ActionBars()

-- MainActionBar
        for i = 1, 12 do
                local MAB = _G["ActionButton"..i]
                if (i == 1) then
        MAB:ClearAllPoints()
        MAB:SetPoint(unpack(db.MAB.Position))
                MAB:SetScale(db.MAB.Scale)
        else
        MAB:ClearAllPoints()
        MAB:SetPoint("LEFT", _G["ActionButton"..i-1],"RIGHT",6,0)
                MAB:SetScale(db.MAB.Scale)
                end
        end

Config.lua
Code:

MAB = {
        name = "MainActionBar",
        type = "group",
        order = 30,
        args = {
                Position= {
                        type = "input",
                        name = "Position",
                        order = 1,
                        set = function(info, val)
                        db.MAB.Position = val
                        MyAddon:UpdateStuff()
                        end,
                        get = function(info) return db.MAB.Position end,
                },
        },

  1. Second
I can get the end caps to show and hide but I can't get the micro names to do the same.

Core.lua
Code:

function Style(self) 
        local name = self:GetName()
        local action = self.action
        local Button = self
        local Count = _G[name.."Count"]
        local HotKey = _G[name.."HotKey"]
        local Border  = _G[name.."Border"]
        local Btname = _G[name.."Name"]
        local Normal  = _G[name.."NormalTexture"]
Btname:Show()
        Button:SetNormalTexture[[Interface\AddOns\MyAddon\Media\button]]
        Border:Hide()
        if db.MAB.HideMacronames then
        Btname:Hide()
        end
end

Config.lua
Code:

HideMacronames = {
        type = "toggle",
        name = "HideMacronames",
        order = 2,
        set = function(info, val)
        db.MAB.HideMacronames = val
        MyAddon:UpdateStuff()
        end,
        get = function(info) return db.MAB.HideMacronames end,
},


dreamcatcher im getting close maybe something in my code will help you solve your issue.

Post from wowace.com
Quote:

WOOT!!



ok so i have my options in game now and its almost working right LOL.

Issues are:

1) does not load default setting to start yet in the options everything is checked. (see screenshot)

2) does not save option changes.

Here are my core.lua and config.lua for you to look at (fair warning the core is huge) did i do forget something did i add something i shouldn't have.

Any Help would be great.

And thank you to everyone who as helped me with the long process.

Coke
Hopefully we both can be up and running soon... havent played WoW in a week been to obsessed with getting this to work LOL

Hope this helps ya.

Coke

dreamcatcher 08-28-11 01:48 PM

I to have not played wow in two weeks been like you say obsessed with my coding

I have been looking at your stuff on the WowAce Forums. But yours is so so so much bigger then mine that i get lost in your code. Also you don't have any gui command for positions.

dreamcatcher 08-28-11 03:20 PM

Woot figured out how to change position of bar.

Config.lua
Code:

        offsetX = {
                name = "X Offset",
                type = "input",
                width = "half",
                order = 13,
                desc = "Offsets from the tooltip's anchor left/right",
                set = function(info, value)
                db.MAB.offsetX = value
                MyAddon:UpdateStuff()
                end,
                get = function(info) return tostring(db.MAB.offsetX) end,
        },
        offsetY = {
                name = "Y Offset",
                type = "input",
                width = "half",
                order = 14,
                desc = "Offsets from the anchor up/down",
                set = function(info, value)
                db.MAB.offsetY = value
                MyAddon:UpdateStuff()
                end,
                get = function(info) return tostring(db.MAB.offsetY) end,
        },
        anchor = {
                name = "Anchor To...",
                type = "select",
                order = 11,
                desc = "What side of the screen you would like the located at.",
                values = positions,
                set = function(info, value)
                db.MAB.anchor = positions[value]
                MyAddon:UpdateStuff()
                end,
                get = function()
                    for k, v in pairs(positions) do
                        if v == db.MAB.anchor then
                                return k
                        end
                    end
                end,
        },

Core.lua
Code:

local defaults = {
        profile = {
                MAB = {
                        Enable = true,
                        HideMacronames = true,
                        HideGryphons = false,
                        Scale = .8,
                        anchor = "BOTTOMLEFT",
                        offsetX = "-510",
                        offsetY = "0",
                },

-- MainActionBar
        for i = 1, 12 do
                local MAB = _G["ActionButton"..i]
                if (i == 1) then
        MAB:ClearAllPoints()
        MAB:SetPoint(db.MAB.anchor, Minimap, db.MAB.anchor, db.MAB.offsetX, db.MAB.offsetY)
                MAB:SetScale(db.MAB.Scale)
        else
        MAB:ClearAllPoints()
        MAB:SetPoint("LEFT", _G["ActionButton"..i-1],"RIGHT",6,0)
                MAB:SetScale(db.MAB.Scale)
                end
        end

Now still need to figure out how to get the micro names to show and hide.

dreamcatcher 08-28-11 03:50 PM

Another problem I just noticed is when I do a reload it is resenting all options to default.

Config.lua
Code:

function MyAddon:ConfigRefresh()
        db = self.db.profile;
end

function MyAddon:SetUpOptions()
        db = self.db.profile;

        LibStub("AceConfig-3.0"):RegisterOptionsTable("MyAddon", GetOptions);
        LibStub("AceConfig-3.0"):RegisterOptionsTable("MyAddon-Profiles", LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db));
       
        self.optionsFrame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("MyAddon", "MyAddon");
        self.profilesFrame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("MyAddon-Profiles", "Profiles", "MyAddon");
       
        self:RegisterChatCommand("MyAddon", "ChatCommand");
end

Core.lua
Code:

function MyAddon:UpdateStuff()
        Hideblz();
        Quest();
        Buffs_N_Debuffs();
        Chat();
        Map();
        ActionBars();
        MicroMenu();
        OneBag();
        ExpBar();
        CreateFrames();

        hooksecurefunc("VehicleMenuBar_MoveMicroButtons",MicroMenu)
        hooksecurefunc("ActionButton_Update", Style)
        hooksecurefunc("PetActionBar_Update", StylePet)
        hooksecurefunc("ShapeshiftBar_Update", StyleShapeshift)
        hooksecurefunc("UIParent_ManageFramePositions",ActionBars)

end

---- EVENTS
function MyAddon:PLAYER_ENTERING_WORLD()
        self:UpdateStuff();
end

---- INIT
function MyAddon:ProfChange()
        db = self.db.profile;
        self:ConfigRefresh();
        self:Refresh();
end

function MyAddon:Refresh()
        self:UpdateStuff();
        -- self:UpdatePosition();       
        -- self:UpdateColors();
end

function MyAddon:PLAYER_LOGIN()
        self:UpdateStuff();
        self:Refresh();
end

function MyAddon:OnInitialize()
        self.db = LibStub("AceDB-3.0"):New("MyAddonDB", defaults, "Default");
               
        self.db.RegisterCallback(self, "OnProfileChanged", "ProfChange");
        self.db.RegisterCallback(self, "OnProfileCopied", "ProfChange");
        self.db.RegisterCallback(self, "OnProfileReset", "ProfChange");
       
        self:SetUpOptions();
       
        db = self.db.profile;
       
        self:RegisterEvent("PLAYER_LOGIN");
        self:RegisterEvent("PLAYER_ENTERING_WORLD");
end


Seerah 08-28-11 04:54 PM

I would have given you permission to use my code had you asked...

Nibelheim 08-28-11 04:59 PM

Quote:

Originally Posted by dreamcatcher (Post 243868)
Another problem I just noticed is when I do a reload it is resenting all options to default.

Do the settings stick before a reload? I.e, you can change an option and it will stay that way? If so, it may be a WTF folder permissions/read-only issue.

dreamcatcher 08-28-11 11:46 PM

Quote:

Originally Posted by Seerah (Post 243872)
I would have given you permission to use my code had you asked...

Code for a GUI with ace or with out?

dreamcatcher 08-28-11 11:52 PM

Quote:

Originally Posted by Nibelheim (Post 243873)
Do the settings stick before a reload? I.e, you can change an option and it will stay that way? If so, it may be a WTF folder permissions/read-only issue.

Yes the settings stay when i set them but on a reload they go back to the default setting.

Xrystal 08-29-11 12:10 AM

If your game installation is in the program files folder then try running with administrator rights.

I apologise if this has already been suggested and tried without success.

dreamcatcher 08-29-11 01:18 AM

Quote:

Originally Posted by Xrystal (Post 243884)
If your game installation is in the program files folder then try running with administrator rights.

I apologise if this has already been suggested and tried without success.

Don't know what the problem was but after I changed the name from MyAddon to DreamTweaks it now saves the profile changes. I was just using MyAddon name for it as a test name so I would not have it mess up my working addon. Since I had both installed. lol o well I will just have to transfer them in and out of the addons file or make a new name for the one I'm working on. I'm rambling on a bought stuff that don't matter.

So any way, question. I still cant get the option for hide/show micro names to work.

Config.lua
Code:

        HideMacronames = {
                name = "HideMacronames",
                type = "toggle",
                order = 2,
                set = function(info, val)
                db.MAB.HideMacronames = val
                DreamTweaks:UpdateStuff()
                end,
                get = function(info) return db.MAB.HideMacronames end,
        },

Core.lua
Code:

function Style(self) 
        local name = self:GetName()
        local action = self.action
        local Button = self
        local Count = _G[name.."Count"]
        local HotKey = _G[name.."HotKey"]
        local Border  = _G[name.."Border"]
        local Btname = _G[name.."Name"]
        local Normal  = _G[name.."NormalTexture"]
       
        Button:SetNormalTexture[[Interface\AddOns\DreamTweaks\Media\button]]
        Border:Hide()
       
        if db.MAB.HideMacronames then
        Btname:Hide()
        else
        Btname:Show()
        end
end


Xrystal 08-29-11 02:46 AM

Ah yes, each addon needs a unique name. If you want to use a TestAddon temporary folder for one you are working on then you would have to make sure that the old wtf file for that last addon you used it with has been deleted so as to not confuse things. I usually just create a new folder with a new name and rename it later if I needed to.

As to it not seeming to work do a test printout of the values. If the values are stored as "1" and "0" for one reason or another the test of if x then .. will not work if I remember rightly. try doing the following before the if statements.

Quote:

print(db.MAB.HideMacronames,type(db.MAB.HideMacronames))
if db.MAB.HideMacronames then
print("Hiding")
Btname:Hide()
else
print("Showing")
Btname:Show()
end
Hopefully that little test will highlight the problem for you.

Seerah 08-29-11 04:57 PM

Quote:

Originally Posted by dreamcatcher (Post 243882)
Code for a GUI with ace or with out?

Well, considering your above AceConfig options table code mostly originated in TipTop, with. :cool:

dreamcatcher 08-29-11 05:44 PM

Quote:

Originally Posted by Seerah (Post 243927)
Well, considering your above AceConfig options table code mostly originated in TipTop, with. :cool:

o hehe well I got most working good now but the micro names hide/show option.

The thing is it works fine if i do it manually in the default config but it dos nothing in the gui.

Config.lua
Code:

        HideMacronames = {
                name = "HideMacronames",
                type = "toggle",
                order = 2,
                set = function(info, val)
                db.HideMacronames = val
                DreamTweaks:UpdateStuff()
                end,
                get = function(info) return db.HideMacronames end,
        },

Core.lua
Code:

local defaults = {
        profile = {
                HideMacronames = true,


hooksecurefunc('ActionButton_Update', function(self)
        for _, icon in pairs({
            self:GetName(),
            'MultiCastRecallSpellButton',
            'MultiCastSummonSpellButton',
        }) do
        local macroname = _G[self:GetName()..'Name']
        if (db.HideMacronames) then
            macroname:SetAlpha(0)
        end
    end
end)


function DreamTweaks:UpdateStuff()
        hooksecurefunc("ActionButton_Update", Style)


dreamcatcher 08-29-11 06:03 PM

Ok well I'm confused. :confused: The option to show or hide micro names from the gui is working but only if i do a reload after selecting it in the gui.

Nibelheim 08-29-11 06:22 PM

Quote:

Originally Posted by dreamcatcher (Post 243930)
Ok well I'm confused. :confused: The option to show or hide micro names from the gui is working but only if i do a reload after selecting it in the gui.

Why are you hooking 'ActionButton_Update' twice? I'd hook it once, call Style() function from the hook, and call Style() function in UpdateStuff()

Code:

function UpdateActionButtonStyle()
    for _, icon in pairs({
        self:GetName(),
        'MultiCastRecallSpellButton',
        'MultiCastSummonSpellButton',
    }) do
        local macroname = _G[self:GetName()..'Name']
        if (db.HideMacronames) then
            macroname:SetAlpha(0)
        end
    end
end

function DreamTweaks:UpdateStuff()
        UpdateActionButtonStyle()
        -- etc
end

function StickThisIntoAFunctionSomewhere()
        hooksecurefunc("ActionButton_Update", UpdateActionButtonStyle)
end



All times are GMT -6. The time now is 01:15 AM.

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