Thread: nUI Layout Test
View Single Post
09-08-09, 06:49 AM   #1
Kodewulf
Premium Member
 
Kodewulf's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2005
Posts: 114
nUI Layout Test

First off, this is pre-alpha-alpha code...

This is an attempt to manage the nUI layout without editing the nUI core files. It's main purpose is to move the ui elements around a bit too fit nicely into all those new cool nUI dashboards, but it should be possible to override any layout info from nUI_DefaultConfig.

I used nUI Tribal for the artwork. Please download and install that prior to trying this out.

Right, now for the code.

Code:
local frame = CreateFrame( "Frame", "nUI_Test", UIParent )
This is the standard create frame code found in most artwork plugins.

Code:
local function setupSkin()
	if not nUI then return end
	if not nUI_DefaultConfig then return end

	if not nUI_Skins then nUI_Skins = {}; end
	local skin = nUI_Skins["custom"] or nUI_DefaultConfig
	
	-- skin.MicroMenu.options.enabled = "no"
	skin.MicroMenu.anchor = {
		-- anchor_pt   = "BOTTOM",
		-- relative_to = "nUI_TopBars",
		-- relative_pt = "BOTTOM",
		-- xOfs        = 15,
		-- yOfs        = 150,
		anchor_pt   = "TOP",
		relative_to = "nUI_Dashboard",
		relative_pt = "TOP",
		xOfs        = 440,
		yOfs        = -60,
	}
	
	-- skin.ButtonBars.nUI_ActionBar.btn_size = 53.5     -- 53.5
	-- skin.ButtonBars.nUI_ActionBar.gap      = 2        -- 2
	-- skin.ButtonBars.nUI_ActionBar.anchor   = "BOTTOM" -- "BOTTOM"
	skin.ButtonBars.nUI_ActionBar.xOfs     = -300        -- 0
	skin.ButtonBars.nUI_ActionBar.yOfs     = 150          -- 123
	-- skin.ButtonBars.nUI_ActionBar.rows     = 1        -- 1
	-- skin.ButtonBars.nUI_ActionBar.cols     = 12       -- 12
	
	nUI_Options.onebag = true
	
	skin.BagBar.anchor = "BOTTOM"
	skin.BagBar.xOfs = 130
	skin.BagBar.yOfs = 150

	skin.SpecialBars.anchor.xOfs        = -595
	skin.SpecialBars.anchor.yOfs        = 210

	nUI_Skins["custom"] = skin
	nUI_Options.skin = "custom"
	frame:UnregisterEvent("ADDON_LOADED")
end
This is where the magic happens.

Code:
local function setupArtwork()
	nUI_TopBars1:SetTexture( "Interface\\AddOns\\nUI_Carbon_Tribal_2\\nUI_Carbon_Tribal_2_Console" );
	nUI_TopBars2:SetTexture( "Interface\\AddOns\\nUI_Carbon_Tribal_2\\nUI_Carbon_Tribal_2_Console" );
	nUI_TopBars3:SetTexture( "Interface\\AddOns\\nUI_Carbon_Tribal_2\\nUI_Carbon_Tribal_2_Console" );
	nUI_TopBars4:SetTexture( "Interface\\AddOns\\nUI_Carbon_Tribal_2\\nUI_Carbon_Tribal_2_Console" );
	nUI_TopBars5:SetTexture( "Interface\\AddOns\\nUI_Carbon_Tribal_2\\nUI_Carbon_Tribal_2_Console" );

	nUI_BottomBars1:SetTexture( "Interface\\AddOns\\nUI_Carbon_Tribal_2\\nUI_Carbon_Tribal_21" );
	nUI_BottomBars2:SetTexture( "Interface\\AddOns\\nUI_Carbon_Tribal_2\\nUI_Carbon_Tribal_22" );
	nUI_BottomBars3:SetTexture( "Interface\\AddOns\\nUI_Carbon_Tribal_2\\nUI_Carbon_Tribal_23" );
	nUI_BottomBars4:SetTexture( "Interface\\AddOns\\nUI_Carbon_Tribal_2\\nUI_Carbon_Tribal_24" );
	nUI_BottomBars5:SetTexture( "Interface\\AddOns\\nUI_Carbon_Tribal_2\\nUI_Carbon_Tribal_25" );
	
	nUI_Dashboard_Panel1:SetTexture( "Interface\\AddOns\\nUI_Carbon_Tribal_2\\nUI_Carbon_Tribal_21" );
	nUI_Dashboard_Panel2:SetTexture( "Interface\\AddOns\\nUI_Carbon_Tribal_2\\nUI_Carbon_Tribal_22" );
	nUI_Dashboard_Panel3:SetTexture( "Interface\\AddOns\\nUI_Carbon_Tribal_2\\nUI_Carbon_Tribal_23" );
	nUI_Dashboard_Panel4:SetTexture( "Interface\\AddOns\\nUI_Carbon_Tribal_2\\nUI_Carbon_Tribal_24" );
	nUI_Dashboard_Panel5:SetTexture( "Interface\\AddOns\\nUI_Carbon_Tribal_2\\nUI_Carbon_Tribal_25" );

	frame:UnregisterEvent("PLAYER_ENTERING_WORLD");
end
I just wrapped the code from the onEvent from the skin into a new function.

Code:
local function onEvent(self, event, ...)
	if event == "ADDON_LOADED" then
		setupSkin()
	elseif event == "PLAYER_ENTERING_WORLD" then
		setupArtwork()
	end
end
This is the new onEvent code. Simple. On "ADDON_LOADED" it loads your skin settings, effectively overriding nUI_DefaultConfig. When "PLAYER_ENTERING_WORLD" fires the artwork gets loaded.

Code:
frame:SetScript("OnEvent", onEvent)
frame:RegisterEvent("ADDON_LOADED")
frame:RegisterEvent("PLAYER_ENTERING_WORLD")
The obligatory Setscript and RegisterEvent thingies.

Unfortunately I'm graphically challenged so all the layout coords and offsets might be all wrong, but I expect you skin guru's will be able to figure things out. Enjoy the code. If it works for you: "Wooooo!!!"; if not, then it wasn't me...

Feel free to tweak things, even calling me an idiot and fixing things would be ok. I'm off to bed now, haven't slept in 2 days so this code might very well make your goldfish swallow your cat.

-- Kodewulf
Attached Files
File Type: zip nUI_Test.zip (1.5 KB, 1072 views)
__________________
I will never forget. I will never regret. I will live my life.