12-14-14, 10:23 AM | #1 |
Work In Progress
Below is my code for my Unitframes addon.
Code:
--[[ I would like to thank all the programmers at WoWInterface for the help they have given me over the years without them this addon would not exist. Special thanks to Phanx foe being patient with me. ]] local defaults = { unitframesEnable = true, unitframesCastbarScale = 1.193, unitframesMainScale = 1.193, unitframesPartyScale = 1.193, --unitframesPartyPosition = { --relAnchor = "TOPLEFT", --offSetX = 10, --offSetY = -200, --}, unitframesArenaScale = 1.193, unitframesBossScale = 1.193, } local MyAddon = CreateFrame("Frame") MyAddon:RegisterEvent("ADDON_LOADED") MyAddon:SetScript("OnEvent", function(self, event, arg1) if event == "ADDON_LOADED" and arg1 == "cUnitframes" then local function initDB(db, defaults) if type(db) ~= "table" then db = {} end if type(defaults) ~= "table" then return db end for k, v in pairs(defaults) do if type(v) == "table" then db[k] = initDB(db[k], v) elseif type(v) ~= type(db[k]) then db[k] = v end end return db end cUnitframesDB = initDB(defaults, cUnitframesDB) cfg = cUnitframesDB self:UnregisterEvent("ADDON_LOADED") if cfg.unitframesEnable ~= true then return end -- Change Name Background for _, region in pairs({ TargetFrameNameBackground, FocusFrameNameBackground, Boss1TargetFrameNameBackground, Boss2TargetFrameNameBackground, Boss3TargetFrameNameBackground, Boss4TargetFrameNameBackground, Boss5TargetFrameNameBackground, }) do region:SetTexture(0, 0, 0, 0.5) end -- Change Name Font for _, names in pairs({ PlayerName, TargetFrameTextureFrameName, FocusFrameTextureFrameName, }) do names:SetFont([[Interface\AddOns\cUnitframes\Media\Expressway_Rg _BOLD.ttf]], 16) end -- Make Level Text on all frame Centred (Thanks Blizzard for not doing this) hooksecurefunc("PlayerFrame_UpdateLevelTextAnchor", function(level) if ( level >= 100 ) then PlayerLevelText:SetPoint("CENTER", PlayerFrameTexture, "CENTER", -60.5, -15); else PlayerLevelText:SetPoint("CENTER", PlayerFrameTexture, "CENTER", -61, -15); end end) hooksecurefunc("TargetFrame_UpdateLevelTextAnchor", function(self, targetLevel) if ( targetLevel >= 100 ) then self.levelText:SetPoint("CENTER", 62, -15); else self.levelText:SetPoint("CENTER", 62, -15); end end) -- Change Main Frames Scale for _, frames in pairs({ PlayerFrame, TargetFrame, FocusFrame, }) do frames:SetScale(cfg.unitframesMainScale) end -- Change Party Frames Scale for i = 1, MAX_PARTY_MEMBERS do _G["PartyMemberFrame"..i]:SetScale(cfg.unitframesPartyScale) end -- Change Arena Frames Scale local function ScaleArenaFrames() for i = 1, MAX_ARENA_ENEMIES do _G["ArenaPrepFrame"..i]:SetScale(cfg.unitframesArenaScale) _G["ArenaEnemyFrame"..i]:SetScale(cfg.unitframesArenaScale) end end if IsAddOnLoaded("Blizzard_ArenaUI") then ScaleArenaFrames() else local f = CreateFrame("Frame") f:RegisterEvent("ADDON_LOADED") f:SetScript("OnEvent", function(self, event, addon) if addon == "Blizzard_ArenaUI" then self:UnregisterEvent(event) ScaleArenaFrames() end end) end -- Change Boss Frames Scale for i = 1, MAX_BOSS_FRAMES do _G["Boss"..i.."TargetFrame"]:SetScale(cfg.unitframesBossScale) end -- Change Frame Position --PartyMemberFrame1:SetPoint(cfg.unitframesPartyPosition.relAnchor, UIParent, cfg.unitframesPartyPosition.offSetX, cfg.unitframesPartyPosition.offSetY); end end) Coke |
|
12-14-14, 11:49 AM | #2 |
You could use a library like http://www.wowinterface.com/download...ssist-1.1.html
Or you could review stuff from http://www.wowinterface.com/downloads/search.php using something like "options" as the search term to get an idea on how options are made. Or you could use http://www.wowace.com/addons/ace3/pa...ace-config-3-0. And http://wow.gamepedia.com/Creating_GU...ration_options describes the basics of building config stuff. [e] I am just realizing that the page above is kind of outdated as the interface version is 1600. But I guess there are others related to options/settings at wowpedia. Like http://wow.gamepedia.com/Using_the_I...s_Addons_panel or http://wow.gamepedia.com/Creating_a_slash_command Last edited by Duugu : 12-14-14 at 12:08 PM. |
|
12-14-14, 03:37 PM | #3 |
It's actually very easy:
Lua Code:
The about panel here is just a template. Last edited by Resike : 12-14-14 at 03:43 PM. |
|
12-15-14, 12:54 PM | #4 |
@Resike thank you for the code, I put it to use.
I cant seem to get my function for the options to work. I can see my frame, I can see the checkbox created with it checked but when I uncheck it nothing changes. (see image below) Am I trying to get it to work correctly? Here is the new file: Lua Code:
Thanks for any help in advance, Coke |
|
12-15-14, 01:04 PM | #5 |
Code:
frame.EnableAddon:SetScript("OnClick", function(self) local checked = not not self:GetChecked() PlaySound(checked and "igMainMenuOptionCheckBoxOn" or "igMainmenuOptionCheckBoxOff") cfg.unitframesEnable = checked end) Other than that, I'm not sure what you're expecting to happen when you check or uncheck that box -- you don't check the saved "unitframesEnable" value anywhere (other than in an OnDisable function that isn't called anywhere) so changing it shouldn't have any effect on anything.
__________________
Retired author of too many addons. Message me if you're interested in taking over one of my addons. Don’t message me about addon bugs or programming questions. |
|
12-15-14, 02:04 PM | #6 |
@Phanx - I was using your code from your addon BetterBattlePetTooltip-6.0.2.66 as a guide for the checkbox.
As for the OnDisable() I remember from when I tried to use ace this function was used and figured it would come into play sometime during this process. What I would like this check box to do is enable the addon if check disable if not checked. In the future I will be trying to add the sliders for the scale of the frames. Hope this helps with what im trying to accomplish. Coke |
|
12-15-14, 02:25 PM | #7 |
Question: Savedvariables are pretty much for different profiles correct. So if I just want it simple I could do something like:
Lua Code:
Then be done with it and only change setting in the lua file correct. I'm realizing simple is better for noobies. Coke |
|
12-15-14, 03:04 PM | #8 | ||
If you just want it to enable/disable part of your addon then you should check the saved variable when that part of your addon loads, and if it says that part should be disabled, don't continue loading. For example: Code:
cUnitframesDB = initDB(defaults, cUnitframesDB) cfg = cUnitframesDB -- Unregister ADDON_LOADED Event (move this up to here) frame:UnregisterEvent("ADDON_LOADED") if not cfg.unitframesEnable then return end -- not enabled, stop here -- Load Functions self:OptionsAddonLoaded() self:ChangeNameBackground()
__________________
Retired author of too many addons. Message me if you're interested in taking over one of my addons. Don’t message me about addon bugs or programming questions. |
|||
12-15-14, 03:09 PM | #9 | ||
Code:
-- Remove the two dashes in front of the line below this one to disable this module: -- do return end -- To re-enable the module later, add two dashes to the beginning of the line above this one.
__________________
Retired author of too many addons. Message me if you're interested in taking over one of my addons. Don’t message me about addon bugs or programming questions. |
|||
12-15-14, 03:09 PM | #10 |
I not sure whats wrong with your code, but if you don't use ace then you have to build the EnableAddon and DisableAddon functions for yourself.
Lua Code:
|
|
12-15-14, 03:42 PM | #11 |
I would advise not doing this right now, since it would require rewriting your entire addon to support doing and undoing all its changes to the default UI frames on the fly. Just let the user know they have to reload the UI after enabling/disabling parts of the addon.
__________________
Retired author of too many addons. Message me if you're interested in taking over one of my addons. Don’t message me about addon bugs or programming questions. |
|
12-15-14, 03:55 PM | #12 |
@Phanx the noobie I was talking about is me :P
@Resike thanks for all your help. This is what I'm going to stick with I'm not going to make it public so no need to add options because I wont change anything cause it is all the items I want Thanks for all the help. Coke Lua Code:
Last edited by cokedrivers : 12-15-14 at 04:13 PM. |
|
12-15-14, 04:02 PM | #13 |
I don't want to use the EnableAddOn API, i just simply want to show/hide frames with thoose functions, it's better then disable the whole addon, since you can reenable it on the fly at any time.
Last edited by Resike : 12-15-14 at 08:24 PM. |
|
12-15-14, 06:45 PM | #14 |
The "you" in that post was directed at Cokedrivers, as following your previous advice (what I'd quoted) would require him to rewrite everything to support disabling/reenabling on the fly, which would be a lot of work and largely a waste of time since users are generally not toggling major features like "unit frames" on the fly.
__________________
Retired author of too many addons. Message me if you're interested in taking over one of my addons. Don’t message me about addon bugs or programming questions. |
|
WoWInterface » Developer Discussions » Lua/XML Help » Work In Progress |
«
Previous Thread
|
Next Thread
»
|
Display Modes |
Linear Mode |
Switch to Hybrid Mode |
Switch to Threaded Mode |
|
|