View Single Post
02-09-12, 11:14 PM   #2
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
yea thinking about it and looking at whats going on and how the game is responding my tweaks to what vrul originally wrote has created some bizarre and what one would think is impossible behavior. Ive been struggling with this for years now heh. Always come back to the same problem or rather set of problems. My frame mover system needs to load up during the addon loaded event to avoid taint bugs and just because frame positioning should be done right after the variables are available. Or so they say... Im constantly having issues with it not being able to return a value out of the saved variables. Possibly because i still em confused by the saved variables and tables and their working in conjunction, the prime example of this issue is in the frame mover system all the way around... as you can see i had to do all kinds of funny business to get the LOD config panels listings to function with the frame movers moveable frame table and oh my... it just gets out of control or rather just becomes a lot to wrap your brain around or at least for me to wrap mine around... The following code chunks are my "settings" setup, the small chunk in the core that deals with the event registering just incase and then the whole of the frame mover system. I should be able to change the frame mover event to have everything in the hookframes function in an addon loaded event along with the stuff at the top of that, with some minor changes well i made all proper changes and it loads with no errors but its not hooking the frames somthing is happening. Or rather not... Any thoughts on any of this? any recomendations even if its not addressing what appears to be the issue? as far as how is it an addon loaded fires after a player login? whats going on here?

Core -
Code:
local addonName, addon = ...
_G[addonName] = addon

--[[-----------------------------------------------------------------------------
Event handling - Use one frame to process multiple individual OnEvent needs
-------------------------------------------------------------------------------]]
do
	local frame, select, next, events = CreateFrame('Frame'), select, pairs({ })
	local register, unregister = frame.RegisterEvent, frame.UnregisterEvent
	frame:Hide()

	frame:SetScript('OnEvent', function(self, event, ...)
		for reference, func in next, events[event], nil do
			func(reference, event, ...)
		end
	end)

	function addon.RegisterEvent(reference, event, func, ...)
		if not events[event] then
			events[event] = { }
			register(frame, event)
		end
		events[event][reference] = func
	end

	function addon.RegisterEvents(reference, func, ...)
		local event
		for index = 1, select('#', ...) do
			event = select(index, ...)
			if not events[event] then
				events[event] = { }
				register(frame, event)
			end
			events[event][reference] = func
		end
	end

	function addon.UnregisterEvent(reference, event)
		if events[event] then
			events[event][reference] = nil
			if not next(events[event]) then
				events[event] = nil
				unregister(frame, event)
			end
		end
	end

	function addon.UnregisterAllEvents(reference)
		for event, registry in next, events, nil do
			registry[reference] = nil
			if not next(registry) then
				events[event] = nil
				unregister(frame, event)
			end
		end
	end
end

--[[-----------------------------------------------------------------------------
SafeCall - Queue a method of addon to run once combat ends if needed
-------------------------------------------------------------------------------]]
do
	local combatLockdown, queue = InCombatLockdown(), { }

	addon.RegisterEvent("Core-SafeCall-EnterCombat", 'PLAYER_REGEN_DISABLED', function(self)
		combatLockdown = true
	end)

	addon.RegisterEvent("Core-SafeCall-LeaveCombat", 'PLAYER_REGEN_ENABLED', function(self)
		combatLockdown = nil
		for method, arg in pairs(queue) do
			addon[method](addon, arg)
			queue[method] = nil
		end
	end)

	function addon:SafeCall(method, arg)
		if combatLockdown then
			queue[method] = arg or false
		else
			addon[method](addon, arg)
		end
	end
end

--[[-----------------------------------------------------------------------------
Localized class name to file class name look up table
-------------------------------------------------------------------------------]]
local CLASS = { }
for fileName, localName in pairs(LOCALIZED_CLASS_NAMES_MALE) do
	CLASS[localName] = fileName
end
for fileName, localName in pairs(LOCALIZED_CLASS_NAMES_FEMALE) do
	CLASS[localName] = fileName
end
addon.CLASS = CLASS
Settings Setup - note i did not include all default registrations the bottom of this file goes on for ever
Code:
local addonName, addon = ...
local defaults = {
	class = true
}

--[[-----------------------------------------------------------------------------
RegisterDefaultSetting - Allow modules to set their defaults
-------------------------------------------------------------------------------]]
function addon:RegisterDefaultSetting(key, value)	-- Use caution if using this after ADDON_LOADED
	defaults[key] = value
end

--[[-----------------------------------------------------------------------------
Load settings, apply version conversions as needed, and link to defaults
-------------------------------------------------------------------------------]]
addon.RegisterEvent("Settings-Load", 'ADDON_LOADED', function(self, event, name)
	if name ~= addonName then return end
	addon.UnregisterEvent(self, event)
	
	local name, class = UnitClass('player')
	name = UnitName('player')
	local realm = GetRealmName()

	local settings = _G[addonName .. "Settings"]
	if type(settings) ~= 'table' then
		settings = { }
		_G[addonName .. "Settings"] = settings
	end
	if type(settings[realm]) ~= 'table' then
		settings[realm] = { }
	end
	if type(settings[realm][name]) ~= 'table' then
		settings[realm][name] = { class = class }
	end

	settings.version = nil		-- Reset value on logout (so can iterate over data without issue)
	addon.settings = setmetatable(settings[realm][name], { __index = defaults })
	return settings
end)



--[[-----------------------------------------------------------------------------
Character Specific WTF Reset.
-------------------------------------------------------------------------------]]
function addon:ResetWTF()
	local name, class = UnitClass('player')
	name = UnitName('player')
	local realm = GetRealmName()
	local settings = _G[addonName .. "Settings"]
	
	if type(settings[realm][name]) == 'table' then
		settings[realm][name] = { class = class }
	end
	settings.version = nil	-- Reset value on logout 
	return settings 
end

--[[-----------------------------------------------------------------------------
Remove unused settings or settings that are the same as defaults
-------------------------------------------------------------------------------]]
addon.RegisterEvent("Settings-Unload", 'PLAYER_LOGOUT', function()
	local settings = addon.settings
	for key, value in pairs(settings) do
		if value == defaults[key] or defaults[key] == nil then
			settings[key] = nil
		end
	end
	_G[addonName .. "Settings"].version = GetAddOnMetadata(addonName, 'Version')
	_G[addonName .. "Settings"].lastVersion = GetAddOnMetadata(addonName, 'Version')
end)

--[[-----------------------------------------------------------------------------
LOD Configuration
-------------------------------------------------------------------------------]]
-- options
local LOA = LibStub and LibStub('LibOptionsAssist-1.0', true)
if not (LOA and select(2, GetAddOnInfo(addonName .. "_Config"))) then return end	-- Make sure config support exists

addon.configPanel = LOA:AddEntry(addonName, nil, addonName .. "_Config")

_G['SLASH_' .. addonName .. 1] = '/' .. addonName
_G['SLASH_' .. addonName .. 2] = '/' .. addonName:lower()
_G['SLASH_' .. addonName .. 3] = '/' .. addonName:upper()
_G['SLASH_' .. addonName .. 4] = '/gui'
SlashCmdList[addonName] = addon.configPanel

InterfaceOptionsFrame:SetFrameStrata('HIGH')
InterfaceOptionsFrame.SetFrameStrata = addon.DoNothing

--[[-----------------------------------------------------------------------------
GrimUI Options Frame Logo
-------------------------------------------------------------------------------]]
local GUI_Logo = CreateFrame('Frame', "GUI_Logo", InterfaceOptionsFrame)
GUI_Logo:SetHeight(256)
GUI_Logo:SetWidth(256)
GUI_Logo:SetPoint('BOTTOM', InterfaceOptionsFrame, 'TOP', 0, -75)
GUI_Logo:SetBackdrop({
	bgFile = [[Interface\AddOns\GrimUI\Media\GrimUILogo]],
	edgeFile = nil,
	edgeSize = 0,
	tile = false,
	insets = { left = 0, right = 0, top = 0, bottom = 0 }
})
GUI_Logo:Hide()

--[[-----------------------------------------------------------------------------
In Game Help System Setup
-------------------------------------------------------------------------------]]
function addon:LoadGUIHelp()
	addon.configPanel()
	GUI_HelpInitiate()
end

local GUI_HelpButton = CreateFrame('Button', "GUI_HelpButton", InterfaceOptionsFrame)
GUI_HelpButton:SetHeight(40)
GUI_HelpButton:SetWidth(25)
GUI_HelpButton:SetPoint('TOP', InterfaceOptionsFrame, 'TOP', 190, -37)
GUI_HelpButton:RegisterForClicks("AnyUp")
GUI_HelpButton:SetFrameStrata("DIALOG")
GUI_HelpButton:SetNormalTexture([[Interface\BUTTONS\UI-MicroButton-Help-Up]])
GUI_HelpButton:SetHighlightTexture([[Interface\BUTTONS\UI-MicroButton-Hilight]])
GUI_HelpButton:SetPushedTexture([[Interface\BUTTONS\UI-MicroButton-Help-Down]])
local HelpText = GUI_HelpButton:CreateFontString(nil, 'DIALOG')
HelpText:SetFont([[Fonts\FRIZQT__.TTF]], 14)
HelpText:SetText("Help")
HelpText:SetPoint("RIGHT", GUI_HelpButton, "LEFT", 0, -5)
HelpText:SetTextColor(1, .10, .10, 1)

GUI_HelpButton:SetScript('OnClick', function(self)
	
	if button == 'LeftButton' then
		GUI_HelpInitiate()
	else
		GUI_HelpInitiate()
	end
	
end)
GUI_HelpButton:Hide()

-- Auto load help on first use.
addon.RegisterEvent("Settings-Help", 'PLAYER_ENTERING_WORLD', function(self, event, name)
	addon.UnregisterEvent(self, event)
	if not addon.settings.HelpViewed or addon.settings.HelpViewed == false then
		addon:LoadGUIHelp()
	end
	if IsAddOnLoadOnDemand("GrimUI_DevTools") then 
		if addon.settings.loadDevTools == true then
			LoadAddOn("GrimUI_DevTools")
		end
	end
end)

--[[-------------------------------------------------------------------------------
Config Panel Show/Hide Scripts - Put all config panel adjustment functions here!
---------------------------------------------------------------------------------]]
addon.configPanel:SetScript('OnHide', function()
	GUI_Logo:Hide()
	GUI_HelpButton:Hide()
end)

addon.configPanel:SetScript('OnShow', function()
	GUI_Logo:Show()
	GUI_HelpButton:Show()
end)

--[[-------------------------------------------------------------------------------
Default WTF Settings - Try them here to stop nextto error and other errors.
---------------------------------------------------------------------------------]]
--Settings.lua settings
addon:RegisterDefaultSetting("HelpViewed", false)

--DevTools.lua settings
addon:RegisterDefaultSetting("loadDevTools", false)
addon:RegisterDefaultSetting("showDevBar", true)

--HideFrames.lua

--Skins.lua settings
addon:RegisterDefaultSetting("useViewPort", false)
addon:RegisterDefaultSetting("VPLeftPos", 0)
addon:RegisterDefaultSetting("VPRightPos", 0)
addon:RegisterDefaultSetting("VPTopPos", 0)
addon:RegisterDefaultSetting("VPBottomPos", 90)
addon:RegisterDefaultSetting("artSetPoint", 0)
addon:RegisterDefaultSetting("artSetAlpha", 1)
addon:RegisterDefaultSetting("ShowAggroArt", true)
addon:RegisterDefaultSetting("resolution", false)
addon:RegisterDefaultSetting("uiSkin", [[Interface\AddOns\]] .. addonName .. [[\Skins\]] .. UnitFactionGroup('player'))

--Anchors.lua settings
addon:RegisterDefaultSetting("LootGrowDirection", true)

--FrameMover.lua
--addon:RegisterDefaultSetting("movedFrames", true)
addon:RegisterDefaultSetting("lockFrames", false)

--ChatFrames.lua settings
addon:RegisterDefaultSetting("chatInitialized", false)
addon:RegisterDefaultSetting("showCombatLog", true)
addon:RegisterDefaultSetting("showInfoLog", true)
addon:RegisterDefaultSetting("showChatTabs", false)
addon:RegisterDefaultSetting("useGrimChat", true)

--MiniMap.lua settings
addon:RegisterDefaultSetting("NotSoMinimap", false)
addon:RegisterDefaultSetting("ShowMiniMap", true)
addon:RegisterDefaultSetting("MapArt", true)
addon:RegisterDefaultSetting("MapButStyle", 1)
addon:RegisterDefaultSetting("GmapMask", "Interface\\BUTTONS\\WHITE8X8")
addon:RegisterDefaultSetting("NSmapMask", "Interface\\BUTTONS\\WHITE8X8")
addon:RegisterDefaultSetting("GmapAlpha", 1)
addon:RegisterDefaultSetting("NSmapAlpha", 1)
addon:RegisterDefaultSetting("NSmapScale", 1.5)
Frame Mover - I think this is the cause of why sometimes it cant find things
Code:
local addonName, addon = ...

--[[-----------------------------------------------------------------------------
Frames to allow moving and saving
-------------------------------------------------------------------------------]]
--["FrameName"] =	false  - move the frame
--true   - move the frame's parent instead
--string - move the named frame instead
DefGMoveableFrames = {
			['MiniMapLFGFrame'] = false,
			['ShardBarFrame'] = false,
			['SpellBookFrame'] = false,
			['QuestLogFrame'] = false,
			['FriendsFrame'] = false,
			['LFDParentFrame'] = false,
			['KnowledgeBaseFrame'] = true,
			['MerchantFrame'] = false,
			['MailFrame'] = false,
			['DressUpFrame'] = false,
			['TaxiFrame'] = false,
			['QuestLogFrame'] = false,
			['PaperDollFrame'] = true,
			['PVPFrame'] = false,
			['WatchFrameHeader'] = true,
			['InspectFrame'] = false,
			['PlayerTalentFrame'] = false,
			['AchievementFrame'] = false,
			['AchievementFrameHeader'] = true,
			['AchievementFrameCategoriesContainer'] = 'AchievementFrame',
			['GlyphFrame'] = 'PlayerTalentFrame',
			['CalendarFrame'] = false,
			['ContainerFrame1'] = false,
			['ContainerFrame2'] = false,
			['ContainerFrame3'] = false,
			['ContainerFrame4'] = false,
			['ContainerFrame5'] = false,
			['Minimap'] = false,
			
			--GrimUI Frames
			['GrimUIPlayerFrame'] = false,
			['GrimUIPartyFrame1'] = false,
			['GrimUIPartyFrame2'] = false,
			['GrimUIPartyFrame3'] = false,
			['GrimUIPartyFrame4'] = false,
			['GrimExpBar'] = false,
			['GrimRepBar'] = false,
			['GUI_DevBar'] = false,
			['Audio_UI_Control'] = true,
			['GUI_AnchorPoint1'] = false,
			['GUI_AnchorPoint2'] = false,
			['GUI_AnchorPoint3'] = false,
			['GUI_AnchorPoint4'] = false,
			['GUI_AnchorPoint5'] = false,
			['GUI_AnchorPoint6'] = false,
			['GUI_AnchorPoint7'] = false,
			['GUI_AnchorPoint8'] = false,
			['GUI_AnchorPoint9'] = false,
			['GUI_AnchorPoint10'] = false,
			['GUI_AnchorPoint11'] = false,

}

function addon:DefaultMoveableFrames()
	if not GMoveableFrames then
		GMoveableFrames = GMoveableFrames or DefGMoveableFrames
	end
end

--[[-----------------------------------------------------------------------------
Frame hooking
-------------------------------------------------------------------------------]]
local hookedFrame, parentFrame, movedFrames, oldPoint, oldX, oldY = { }, { }
local function GetRelativePosition(frame)
	local _, _, uiWidth, uiHeight = UIParent:GetRect()
	local left, bottom, width, height = frame:GetRect()
	if bottom + height / 2 >= uiHeight / 2 then
		if left + width / 2 >= uiWidth / 2 then
			return 'TOPRIGHT', left + width - uiWidth - 1, bottom + height - uiHeight - 1
		else
			return 'TOPLEFT', left, bottom + height - uiHeight - 1
		end
	elseif left + width / 2 >= uiWidth / 2 then
		return 'BOTTOMRIGHT', left + width - uiWidth - 1, bottom
	end
	return 'BOTTOMLEFT', left, bottom
end

local function OnShow(self)
	local frame = parentFrame[self] or self
	if self == Minimap then
		if addon.settings.NotSoMinimap == true then
			self = _G["NSMiniMapAnchor"] -- needed for extra minimap functions
			frame = _G["NSMiniMapAnchor"] 
		else 
			self = _G["GMiniMapAnchor"] 
			frame = _G["GMiniMapAnchor"] 
		end
	end
	local position = movedFrames[self:GetName()]
	if position then
		addon:UnlockFrame(frame)
		frame:ClearAllPoints()
		frame:SetPoint(unpack(position))
		addon:LockFrame(frame)
	end
end

local function OnMouseDown(self, button)
	if button ~= 'LeftButton' or addon.settings.lockFrames then return end
	if IsControlKeyDown() and button == 'LeftButton' then
	local frame = parentFrame[self] or self
	if self == Minimap then
		if addon.settings.NotSoMinimap == true then
			self = _G["NSMiniMapAnchor"] -- needed for extra minimap functions
			frame = _G["NSMiniMapAnchor"]
		else 
			self = _G["GMiniMapAnchor"]
			frame = _G["GMiniMapAnchor"]
		end
	end
	oldPoint, oldX, oldY = GetRelativePosition(frame)
	addon:UnlockFrame(frame)
	frame:StartMoving()
	end
end

local function OnMouseUp(self, button)
	if button ~= 'LeftButton' or not oldPoint then return end
	local frame = parentFrame[self] or self
	if self == Minimap then
		if addon.settings.NotSoMinimap == true then
			self = _G["NSMiniMapAnchor"] -- needed for extra minimap functions
			frame = _G["NSMiniMapAnchor"]
		else 
			self = _G["GMiniMapAnchor"]
			frame = _G["GMiniMapAnchor"]
		end
	end
	frame:StopMovingOrSizing()
	addon:LockFrame(frame)
	local point, x, y = GetRelativePosition(frame)
	if point ~= oldPoint or x ~= oldX or y ~= oldY then
		movedFrames[frame:GetName()] = { point, 'UIParent', x, y }
	end
	oldPoint, oldX, oldY = nil, nil, nil
end

function HookFrame(name, parent)
	if hookedFrame[name] then 
		return true
	end
	local frame = _G[name]
	if not frame then
		return 
	end
	if parent then
		if type(parent) == 'string' then
			parent = _G[parent]
		else
			if frame:GetParent() ~= UIParent then
				parent = frame:GetParent()
			else
				parent = frame
			end
		end
		if not parent then 
			return 
		end
		HookFrame(parent:GetName())
		while(parentFrame[parent]) do
			parent = parentFrame[parent]
		end
		parentFrame[frame] = parent
	elseif not name:match("^" .. addonName) then
		frame:HookScript('OnShow', OnShow)
	end
	frame:EnableMouse(true)
	frame:EnableKeyboard(true)
	frame:SetMovable(true)
	frame:SetClampedToScreen(false)
	frame:HookScript('OnMouseDown', OnMouseDown)
	frame:HookScript('OnMouseUp', OnMouseUp)
	hookedFrame[name] = true
	if movedFrames[name] and frame:IsShown() then
		OnShow(frame)
	end
	return true
end

--[[-----------------------------------------------------------------------------
Initialize
-------------------------------------------------------------------------------]]
local moveableframes = {}
local function VerCheckUpdate()
	local CurVer = GetAddOnMetadata(addonName, 'Version')
	local LastVer = _G[addonName .. "Settings"].lastVersion
	if LastVer then
		if CurVer > LastVer then 
			for gname, gparent in pairs(DefGMoveableFrames) do 
				local TabCont = tContains( GMoveableFrames, gname )
				if TabCont == nil then
					GMoveableFrames[gname] = gparent
				end
			end
		end
	_G[addonName .. "Settings"].lastVersion = nil
	end
end

addon.RegisterEvent("MoveFrames-Initialize", 'PLAYER_LOGIN', function(self, event)
	addon.UnregisterEvent(self, event)
	movedFrames = addon.settings.movedFrames
	if type(movedFrames) ~= 'table' then
		movedFrames = { }
		addon.settings.movedFrames = movedFrames
	end
	addon:RegisterDefaultSetting("movedFrames", true)	-- Prevent it from being removed on PLAYER_LOGOUT
	local function HookFrames(self, event)
		addon:DefaultMoveableFrames()
		VerCheckUpdate()
		
		moveableframes = CopyTable(GMoveableFrames)
		for name, parent in pairs(moveableframes) do
			if HookFrame(name, parent) then
				moveableframes[name] = nil
			end
		end
		if next(moveableframes) then return end
		addon.UnregisterEvent(self, event)
	end
	addon.RegisterEvent("MoveFrames-Hook", 'ADDON_LOADED', HookFrames)
	HookFrames("MoveFrames-Hook", 'ADDON_LOADED')
end)

--[[-----------------------------------------------------------------------------
in game add remove functions
-------------------------------------------------------------------------------]]
function addon:AddMoveableFrame(name, parvar)
	if parvar then
		if parvar == string then
			parvar = _G[parvar]
		end
		GMoveableFrames[name] = parvar
		HookFrame(name, parvar)
	elseif not parvar or parvar == "" or parvar == nil then 
		parvar = false
		GMoveableFrames[name] = parvar
		HookFrame(name, parvar)
	end
end

function addon:RemMoveableFrame(name)
	GMoveableFrames[name] = nil
end

SlashCmdList["GADDMOVE_SHORTHAND"] = function(cmd)
	local name, parvar = strsplit(" ", cmd) 
	if parvar then
		if parvar == "true" then
			parvar = true
		elseif parvar == "false" then
			parvar = false
		end
	end
	if not parvar then parvar = false end
	addon:AddMoveableFrame(name, parvar)
end
SLASH_GADDMOVE_SHORTHAND1 = "/gaddmove"

SlashCmdList["GREMMOVE_SHORTHAND"] = function(cmd)
	addon:RemMoveableFrame(cmd)
end
SLASH_GREMMOVE_SHORTHAND1 = "/gremmove"
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote