Thread Tools Display Modes
12-14-14, 10:23 AM   #1
cokedrivers
A Rage Talon Dragon Guard
 
cokedrivers's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 325
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)
I'm trying to figure out how to I could add in game options to adjust settings.

Coke
  Reply With Quote
12-14-14, 11:49 AM   #2
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
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.
  Reply With Quote
12-14-14, 03:37 PM   #3
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
It's actually very easy:

Lua Code:
  1. local addonName, ns = ...
  2.  
  3. local Addon = { }
  4. ns.Addon = Addon
  5.  
  6. local frame = CreateFrame("Frame")
  7. frame:RegisterEvent("ADDON_LOADED")
  8.  
  9. frame:SetScript("OnEvent", function(self, event, ...)
  10.     Addon[event](Addon, ...)
  11. end)
  12.  
  13. function Addon:ADDON_LOADED(addon)
  14.     if addon == addonName then
  15.         self:OptionsAddonLoaded()
  16.         frame:UnregisterEvent("ADDON_LOADED")
  17.     end
  18. end
  19.  
  20. function Addon:OptionsAddonLoaded()
  21.     self.panel = CreateFrame("Frame", nil, UIParent)
  22.     self.panel.name = addonName
  23.     self:CreateBlizzardOptions(self.panel)
  24.     InterfaceOptions_AddCategory(self.panel)
  25.     self.panel.about = CreateFrame("Frame", nil, self.panel)
  26.     self.panel.about.name = "About"
  27.     self:CreateAboutPanel(self.panel.about)
  28.     self.panel.about.parent = self.panel.name
  29.     InterfaceOptions_AddCategory(self.panel.about)
  30. end
  31.  
  32. function Addon:CreateBlizzardOptions(frame)
  33.     -- Title
  34.     frame.Title = frame:CreateFontString(nil, "Artwork")
  35.     frame.Title:SetFontObject(GameFontNormalLarge)
  36.     frame.Title:SetPoint("TopLeft", 16, -16)
  37.     frame.Title:SetJustifyH("Right")
  38.     frame.Title:SetJustifyV("Top")
  39.     frame.Title:SetWordWrap(false)
  40.     frame.Title:SetText(addonName)
  41. end
  42.  
  43. function Addon:CreateAboutPanel(frame)
  44.     -- Title
  45.     frame.Title = frame:CreateFontString(nil, "Artwork")
  46.     frame.Title:SetFontObject(GameFontNormalLarge)
  47.     frame.Title:SetPoint("TopLeft", 16, -16)
  48.     frame.Title:SetJustifyH("Right")
  49.     frame.Title:SetJustifyV("Top")
  50.     frame.Title:SetWordWrap(false)
  51.     frame.Title:SetText(addonName.." - About")
  52.     -- Subtitle
  53.     frame.Subtitle = frame:CreateFontString(nil, "Artwork", "GameFontHighlight")
  54.     frame.Subtitle:SetHeight(32)
  55.     frame.Subtitle:SetPoint("TopLeft", frame.Title, "BottomLeft", 0, -12)
  56.     frame.Subtitle:SetPoint("Right", frame, -32, 0)
  57.     frame.Subtitle:SetNonSpaceWrap(true)
  58.     frame.Subtitle:SetJustifyH("Left")
  59.     frame.Subtitle:SetJustifyV("Top")
  60.     local notes = GetAddOnMetadata(addonName, "Notes")
  61.     frame.Subtitle:SetText(notes)
  62. end

The about panel here is just a template.

Last edited by Resike : 12-14-14 at 03:43 PM.
  Reply With Quote
12-15-14, 12:54 PM   #4
cokedrivers
A Rage Talon Dragon Guard
 
cokedrivers's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 325
@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:
  1. local addonName, ns = ...
  2.  
  3. local Addon = { }
  4. ns.Addon = Addon
  5.  
  6. local defaults = {
  7.     unitframesEnable = true,
  8.     unitframesCastbarScale = 1.193,
  9.     unitframesMainScale = 1.193,
  10.     unitframesPartyScale = 1.193,
  11.     --unitframesPartyPosition = {
  12.         --relAnchor = "TOPLEFT",
  13.         --offSetX = 10,
  14.         --offSetY = -200,
  15.     --},
  16.     unitframesArenaScale = 1.193,
  17.     unitframesBossScale = 1.193,   
  18. }
  19.  
  20. SlashCmdList['RELOADUI'] = function()
  21.     ReloadUI()
  22. end
  23. SLASH_RELOADUI1 = '/rl'
  24.  
  25. local frame = CreateFrame("Frame", addonName)
  26. frame:RegisterEvent("ADDON_LOADED")
  27.  
  28. frame:SetScript("OnEvent", function(self, event, ...)
  29.     Addon[event](Addon, ...)
  30. end)
  31.  
  32. function Addon:ADDON_LOADED(addon)
  33.     if addon == addonName then
  34.         -- Saved Variable
  35.         local function initDB(db, defaults)
  36.             if type(db) ~= "table" then db = {} end
  37.             if type(defaults) ~= "table" then return db end
  38.             for k, v in pairs(defaults) do
  39.                 if type(v) == "table" then
  40.                     db[k] = initDB(db[k], v)
  41.                 elseif type(v) ~= type(db[k]) then
  42.                     db[k] = v
  43.                 end
  44.             end
  45.         return db
  46.         end
  47.  
  48.         cUnitframesDB = initDB(defaults, cUnitframesDB)
  49.         cfg = cUnitframesDB
  50.        
  51.         -- Load Functions
  52.         self:OptionsAddonLoaded()
  53.         self:ChangeNameBackground()
  54.         self:ChangeNameFont()
  55.         self:CenterLevelText()
  56.         self:ChangeMainFramesScale()
  57.         self:ChangePartyFramesScale()
  58.         self:ChangeArenaFramesScale()
  59.         self:ChangeBossFramesScale()
  60.         self:ChangeCastingbarScale()
  61.        
  62.         -- Unregister ADDON_LOADED Event
  63.         frame:UnregisterEvent("ADDON_LOADED")
  64.     end
  65. end
  66.  
  67. --[[-----------------------
  68.     Unitframes Functions
  69. ---------------------------]]
  70.  
  71. function Addon:OnDisable()
  72.     if cfg.unitframesEnable ~= true then return end
  73. end
  74.  
  75. function Addon:ChangeNameBackground()
  76.     for _, region in pairs({
  77.         TargetFrameNameBackground,
  78.         FocusFrameNameBackground,
  79.         Boss1TargetFrameNameBackground,
  80.         Boss2TargetFrameNameBackground,
  81.         Boss3TargetFrameNameBackground,
  82.         Boss4TargetFrameNameBackground,
  83.         Boss5TargetFrameNameBackground,
  84.        
  85.     }) do
  86.         region:SetTexture(0, 0, 0, 0.5)
  87.     end
  88. end
  89.  
  90. function Addon:ChangeNameFont()
  91.     for _, names in pairs({
  92.         PlayerName,
  93.         TargetFrameTextureFrameName,
  94.         FocusFrameTextureFrameName,
  95.     }) do
  96.         names:SetFont([[Interface\AddOns\cUnitframes\Media\Expressway_Rg _BOLD.ttf]], 16)
  97.    
  98.     end
  99. end
  100.  
  101. function Addon:CenterLevelText()
  102.     -- PlayerFrame
  103.     hooksecurefunc("PlayerFrame_UpdateLevelTextAnchor", function(level)
  104.       if ( level >= 100 ) then
  105.         PlayerLevelText:SetPoint("CENTER", PlayerFrameTexture, "CENTER", -60.5, -15);
  106.       else
  107.         PlayerLevelText:SetPoint("CENTER", PlayerFrameTexture, "CENTER", -61, -15);
  108.       end
  109.     end)
  110.    
  111.     -- TargetFrame
  112.     hooksecurefunc("TargetFrame_UpdateLevelTextAnchor",  function(self, targetLevel)
  113.       if ( targetLevel >= 100 ) then
  114.         self.levelText:SetPoint("CENTER", 62, -15);
  115.       else
  116.         self.levelText:SetPoint("CENTER", 62, -15);
  117.       end
  118.     end)
  119. end
  120.  
  121. function Addon:ChangeMainFramesScale()
  122.     for _, frames in pairs({
  123.         PlayerFrame,
  124.         TargetFrame,
  125.         FocusFrame,
  126.     }) do
  127.         frames:SetScale(cfg.unitframesMainScale)
  128.     end
  129. end
  130.  
  131. function Addon:ChangePartyFramesScale()
  132.     for i = 1, MAX_PARTY_MEMBERS do
  133.         _G["PartyMemberFrame"..i]:SetScale(cfg.unitframesPartyScale)
  134.     end
  135. end
  136.  
  137. function Addon:ChangeArenaFramesScale()
  138.  
  139.     local function ScaleArenaFrames()
  140.         for i = 1, MAX_ARENA_ENEMIES do
  141.             _G["ArenaPrepFrame"..i]:SetScale(cfg.unitframesArenaScale)
  142.             _G["ArenaEnemyFrame"..i]:SetScale(cfg.unitframesArenaScale)
  143.         end
  144.     end
  145.  
  146.     if IsAddOnLoaded("Blizzard_ArenaUI") then
  147.         ScaleArenaFrames()
  148.     else
  149.         local f = CreateFrame("Frame")
  150.         f:RegisterEvent("ADDON_LOADED")
  151.         f:SetScript("OnEvent", function(self, event, addon)
  152.             if addon == "Blizzard_ArenaUI" then
  153.                 self:UnregisterEvent(event)
  154.                 ScaleArenaFrames()
  155.             end
  156.         end)
  157.     end
  158. end
  159.  
  160. function Addon:ChangeBossFramesScale()
  161.     for i = 1, MAX_BOSS_FRAMES do
  162.         _G["Boss"..i.."TargetFrame"]:SetScale(cfg.unitframesBossScale)
  163.     end
  164. end
  165.  
  166. function Addon:ChangeCastingbarScale()
  167.     CastingBarFrame:SetScale(cfg.unitframesCastbarScale)
  168. end
  169.  
  170.  
  171. --[[------------------
  172.     Addon Options
  173. ----------------------]]
  174.  
  175. function Addon:OptionsAddonLoaded()
  176.     self.panel = CreateFrame("Frame", nil, UIParent)
  177.     self.panel.name = addonName
  178.     self:CreateBlizzardOptions(self.panel)
  179.     InterfaceOptions_AddCategory(self.panel)
  180. end
  181.  
  182. function Addon:CreateBlizzardOptions(frame)
  183.     -- Title
  184.     frame.Title = frame:CreateFontString(nil, "Artwork")
  185.     frame.Title:SetFontObject(GameFontNormalLarge)
  186.     frame.Title:SetPoint("TopLeft", 16, -16)
  187.     frame.Title:SetJustifyH("Right")
  188.     frame.Title:SetJustifyV("Top")
  189.     frame.Title:SetWordWrap(false)
  190.     frame.Title:SetText(addonName)
  191.    
  192.     -- Subtitle
  193.     frame.Subtitle = frame:CreateFontString(nil, "Artwork", "GameFontHighlight")
  194.     frame.Subtitle:SetHeight(32)
  195.     frame.Subtitle:SetPoint("TopLeft", frame.Title, "BottomLeft", 0, -12)
  196.     frame.Subtitle:SetPoint("Right", frame, -32, 0)
  197.     frame.Subtitle:SetNonSpaceWrap(true)
  198.     frame.Subtitle:SetJustifyH("Left")
  199.     frame.Subtitle:SetJustifyV("Top")
  200.     local notes = GetAddOnMetadata(addonName, "Notes")
  201.     frame.Subtitle:SetText(notes)
  202.  
  203.     -- Enable Addon
  204.     frame.EnableAddon = CreateFrame("CheckButton", "$parentEnable", self.panel, "InterfaceOptionsCheckButtonTemplate")
  205.     frame.EnableAddon:SetPoint("TOPLEFT", frame.Subtitle, "BOTTOMLEFT", -2, -8)
  206.     frame.EnableAddon.Text:SetText("Enable cUnitframes")
  207.     frame.EnableAddon:SetScript("OnClick", function(self)
  208.         local checked = not not self:GetChecked()
  209.         PlaySound(checked and "igMainMenuOptionCheckBoxOn" or "igMainmenuOptionCheckBoxOff")
  210.         cfg.unitframesEnable = checked
  211.     end)
  212.    
  213.     frame.refresh = function(self)
  214.         frame.EnableAddon:SetChecked(cfg.unitframesEnable)
  215.     end
  216.    
  217. end



Thanks for any help in advance,
Coke
Attached Thumbnails
Click image for larger version

Name:	WoWScrnShot_121514_104910.jpg
Views:	249
Size:	330.2 KB
ID:	8366  
  Reply With Quote
12-15-14, 01:04 PM   #5
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Code:
    frame.EnableAddon:SetScript("OnClick", function(self)
        local checked = not not self:GetChecked()
        PlaySound(checked and "igMainMenuOptionCheckBoxOn" or "igMainmenuOptionCheckBoxOff")
        cfg.unitframesEnable = checked
    end)
On the second line there's no need to do that "not not" bit -- GetChecked now returns a proper boolean, since Patch 6.0.2, so you can just use its return value directly.

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.
  Reply With Quote
12-15-14, 02:04 PM   #6
cokedrivers
A Rage Talon Dragon Guard
 
cokedrivers's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 325
@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
  Reply With Quote
12-15-14, 02:25 PM   #7
cokedrivers
A Rage Talon Dragon Guard
 
cokedrivers's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 325
Question: Savedvariables are pretty much for different profiles correct. So if I just want it simple I could do something like:

Lua Code:
  1. local enableUnitframes = true
  2.  
  3. -- then I could do
  4. if enableUnitframes ~= true then return end

Then be done with it and only change setting in the lua file correct.

I'm realizing simple is better for noobies.

Coke
  Reply With Quote
12-15-14, 03:04 PM   #8
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by cokedrivers View Post
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.
OnEnable and OnDisable are methods specific to the AceAddon-3.0 library. You're not using that as far as I can see in the code you posted, so unless you're writing your own system that uses methods by those names, they will never be relevant to your addon.

Originally Posted by cokedrivers View Post
What I would like this check box to do is enable the addon if check disable if not checked.
If you want to enable/disable the entire addon you don't need a checkbox for that, since the default UI already provides a checkbox to enable/disable your addon. Adding your own checkbox anyway would be rather confusing for users, since once they un-check it and disable the addon, then your checkbox is no longer available (since the addon that creates it is disabled) and they can't use it to re-enable your addon.

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.
  Reply With Quote
12-15-14, 03:09 PM   #9
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by cokedrivers View Post
Question: Savedvariables are pretty much for different profiles correct.
No, and your code doesn't support profiles -- your saved variables table just saves settings. Profiles are whole sets of settings.

Originally Posted by cokedrivers View Post
Then be done with it and only change setting in the lua file correct.
Yes, though if you do it that way, there's no point in creating a variable, only to read it once on the next line. This would be simpler:

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.
Originally Posted by cokedrivers View Post
I'm realizing simple is better for noobies.
While that is generally true, changing a value in a Lua file is the opposite of simple for "noobies" -- even if it really is a simple action, most non-technical people will hear/read the words "open the code in Notepad" and just give up before they even try.
__________________
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.
  Reply With Quote
12-15-14, 03:09 PM   #10
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
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:
  1. frame.EnableAddon:SetScript("OnClick", function(self)
  2.     PlaySound(checked and "igMainMenuOptionCheckBoxOn" or "igMainmenuOptionCheckBoxOff")
  3.     local checked = self:GetChecked()
  4.     if checked then
  5.         Addon:EnableAddon()
  6.     else
  7.         Addon:DisableAddon()
  8.     end
  9.     cfg.unitframesEnable = checked
  10. end)
  11.  
  12. function Addon:EnableAddon()
  13.     -- Reregister events and show stuff.
  14. end
  15.  
  16. function Addon:DisableAddon()
  17.     -- Unregister events and hide stuff.
  18. end
  Reply With Quote
12-15-14, 03:42 PM   #11
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Resike View Post
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.
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.
  Reply With Quote
12-15-14, 03:55 PM   #12
cokedrivers
A Rage Talon Dragon Guard
 
cokedrivers's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 325
@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:
  1. --[[
  2. I would like to thank all the programmers at WoWInterface for the help
  3. they have given me over the years without them this addon would not exist.
  4.  
  5. Special thanks to Phanx for being patient with me.
  6. ]]
  7.  
  8. --[[----------
  9.     Variables
  10. --------------]]
  11. local unitframesEnable = true
  12. local unitframesCastbarScale = 1.193
  13. local unitframesMainScale = 1.193
  14. local unitframesPartyScale = 1.193
  15. --[[local unitframesPartyPosition = {
  16.     relAnchor = "TOPLEFT",
  17.     offSetX = 10,
  18.     offSetY = -200,
  19. }]]
  20. local unitframesArenaScale = 1.193
  21. local unitframesBossScale = 1.193  
  22. local Addon = CreateFrame("Frame", UIParent)
  23.  
  24. Addon:RegisterEvent("ADDON_LOADED")
  25. Addon:SetScript("OnEvent", function(self, event, arg1)
  26.     if event == "ADDON_LOADED" and arg1 == "cUnitframes" then
  27.        
  28.         if unitframesEnable ~= true then return end
  29.        
  30.         -- Change Name Background
  31.         for _, region in pairs({
  32.             TargetFrameNameBackground,
  33.             FocusFrameNameBackground,
  34.             Boss1TargetFrameNameBackground,
  35.             Boss2TargetFrameNameBackground,
  36.             Boss3TargetFrameNameBackground,
  37.             Boss4TargetFrameNameBackground,
  38.             Boss5TargetFrameNameBackground,
  39.            
  40.         }) do
  41.             region:SetTexture(0, 0, 0, 0.5)
  42.         end
  43.        
  44.         -- Change Name Font
  45.         for _, names in pairs({
  46.             PlayerName,
  47.             TargetFrameTextureFrameName,
  48.             FocusFrameTextureFrameName,
  49.         }) do
  50.             names:SetFont([[Interface\AddOns\cUnitframes\Media\Expressway_Rg _BOLD.ttf]], 16)
  51.        
  52.         end
  53.        
  54.         -- Make Level Text on all frame Centred (Thanks Blizzard for not doing this)
  55.         -- PlayerFrame
  56.         hooksecurefunc("PlayerFrame_UpdateLevelTextAnchor", function(level)
  57.           if ( level >= 100 ) then
  58.             PlayerLevelText:SetPoint("CENTER", PlayerFrameTexture, "CENTER", -60.5, -15);
  59.           else
  60.             PlayerLevelText:SetPoint("CENTER", PlayerFrameTexture, "CENTER", -61, -15);
  61.           end
  62.         end)
  63.         -- TargetFrame
  64.         hooksecurefunc("TargetFrame_UpdateLevelTextAnchor",  function(self, targetLevel)
  65.           if ( targetLevel >= 100 ) then
  66.             self.levelText:SetPoint("CENTER", 62, -15);
  67.           else
  68.             self.levelText:SetPoint("CENTER", 62, -15);
  69.           end
  70.         end)
  71.        
  72.         -- Change Main Frames Scale
  73.         for _, frames in pairs({
  74.             PlayerFrame,
  75.             TargetFrame,
  76.             FocusFrame,
  77.         }) do
  78.             frames:SetScale(unitframesMainScale)
  79.         end
  80.        
  81.         -- Change Party Frames Scale
  82.         for i = 1, MAX_PARTY_MEMBERS do
  83.             _G["PartyMemberFrame"..i]:SetScale(unitframesPartyScale)
  84.         end
  85.        
  86.         -- Change Arena Frames Scale
  87.         local function ScaleArenaFrames()
  88.             for i = 1, MAX_ARENA_ENEMIES do
  89.                 _G["ArenaPrepFrame"..i]:SetScale(unitframesArenaScale)
  90.                 _G["ArenaEnemyFrame"..i]:SetScale(unitframesArenaScale)
  91.             end
  92.         end
  93.  
  94.         if IsAddOnLoaded("Blizzard_ArenaUI") then
  95.             ScaleArenaFrames()
  96.         else
  97.             local f = CreateFrame("Frame")
  98.             f:RegisterEvent("ADDON_LOADED")
  99.             f:SetScript("OnEvent", function(self, event, addon)
  100.                 if addon == "Blizzard_ArenaUI" then
  101.                     self:UnregisterEvent(event)
  102.                     ScaleArenaFrames()
  103.                 end
  104.             end)
  105.         end
  106.        
  107.         -- Change Boss Frames Scale
  108.         for i = 1, MAX_BOSS_FRAMES do
  109.             _G["Boss"..i.."TargetFrame"]:SetScale(unitframesBossScale)
  110.         end
  111.        
  112.         -- Change Castbar Scale
  113.         CastingBarFrame:SetScale(unitframesCastbarScale)
  114.        
  115.         -- Change Party Frame Position
  116.         --PartyMemberFrame1:SetPoint(unitframesPartyPosition.relAnchor, UIParent, unitframesPartyPosition.offSetX, unitframesPartyPosition.offSetY);
  117.        
  118.         self:UnregisterEvent("ADDON_LOADED")
  119.     end
  120. end)

Last edited by cokedrivers : 12-15-14 at 04:13 PM.
  Reply With Quote
12-15-14, 04:02 PM   #13
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Originally Posted by Phanx View Post
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.
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.
  Reply With Quote
12-15-14, 06:45 PM   #14
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Resike View Post
I'm 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.
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.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Work In Progress


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