Go to Page... |
Thread Tools | Display Modes |
11-02-10, 11:02 AM | #21 | |
|
||
11-02-10, 11:08 AM | #22 |
okay, with all that said i see and understand a few things better going to play with it and see if i can get it to function correct. on a side note if i do the table get function and print it, if things are working correct, the whole table should print right?
|
|
11-02-10, 11:25 AM | #23 | |
if GrimUIPreviouslyLoaded = nil or false then GMoveableFrames = { list of frames} end which should setup the default saved variable entrys, then have a statement that says... moveableframes = CopyTable(GMoveableFrames) this in theory would make it so it would only write those default frames to the saved vars the very first time the interface was loaded then it would copy the saved vars into the active table on each load. Then for the addframe function i just do somthing like function addon:AddMoveableFrame(name, parent) local nameandparent = name, parent GMoveableFrames[name] = parent tinsert(moveableframes, nameandparent) HookFrame(name, parent) end for the add function. the add function would add it to the table for immediate use, and the saved variables for remembering the next time you log in, then the hookframe would activate it. and yes i know my formatting of the name and parent part are wrong lol. this is theory right now not actual code. |
||
11-02-10, 12:04 PM | #24 |
WOOOO HOOO okay well now i have them loading/saving proper. time to finish that addframe function. This is what worked in the end.
Code:
local addonName, addon = ... addon:RegisterDefaultSetting("lockFrames", false) --[[----------------------------------------------------------------------------- Frames to allow moving and saving -------------------------------------------------------------------------------]] --["FrameName"] = false - move the frame --true - move the frame's parent instead --string - move the named frame instead function addon:DefaultMoveableFrames() GMoveableFrames = GMoveableFrames or { ['MiniMapLFGFrame'] = false, ['MiniMapBattlefieldFrame'] = false, ['ShardBarFrame'] = false, ['BNToastFrame'] = false, ['RuneFrame'] = false, ['SpellBookFrame'] = false, ['QuestLogFrame'] = false, ['FriendsFrame'] = false, ['LFGParentFrame'] = false, ['KnowledgeBaseFrame'] = true, ['MerchantFrame'] = false, ['MailFrame'] = false, ['DressUpFrame'] = false, ['TaxiFrame'] = false, ['QuestLogFrame'] = false, ['PaperDollFrame'] = true, ['PVPFrame'] = false, ['WatchFrameHeader'] = true, ['VehicleMenuBar'] = false, ['InspectFrame'] = false, ['PlayerTalentFrame'] = false, ['AchievementFrame'] = false, ['AchievementFrameHeader'] = true, ['AchievementFrameCategoriesContainer'] = 'AchievementFrame', ['GlyphFrame'] = 'PlayerTalentFrame', ['CalendarFrame'] = false, ['GrimUIPlayerFrame'] = false, ['GrimUIPartyFrame1'] = false, ['GrimUIPartyFrame2'] = false, ['GrimUIPartyFrame3'] = false, ['GrimUIPartyFrame4'] = false, ['GrimExpBar'] = false, ['GrimRepBar'] = false, ['GDevBar'] = false, ['ContainerFrame1'] = false, ['ContainerFrame2'] = false, ['ContainerFrame3'] = false, ['ContainerFrame4'] = false, ['ContainerFrame5'] = false, } end --end --addon:DefaultMoveableFrames() --[[----------------------------------------------------------------------------- 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 local position = movedFrames[frame: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 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 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 local HookFrame 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 parent = frame:GetParent() 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 = {} 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() 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, parent) end function addon:RemMoveableFrame(name, parent) end |
|
11-02-10, 12:26 PM | #25 |
hmm so my current attempt at a function was BAD! lol. stackoverflow its dumping a whole lot of data that i dont even know where its coming from when i try to do the following for the add function...
Code:
function addon:AddMoveableFrame(name, parent) GMoveableFrames[name] = parent HookFrame(name, parent) end function addon:RemMoveableFrame(name, parent) end SlashCmdList["GMOVE_SHORTHAND"] = function(name, parent) addon:AddMoveableFrame(name, parent) end SLASH_GMOVE_SHORTHAND1 = "/gmove" |
|
11-02-10, 01:03 PM | #26 |
I'm pretty sure it's your slash handler. I should be home in about an hour with real comp access to show you what the issue is extensively (again, if someone doesn't get to it before then)
|
|
11-02-10, 01:06 PM | #27 | |
Code:
function addon:AddMoveableFrame(name, parvar) if parvar then if type(parvar) == 'string' then parvar = _G[parvar] end GMoveableFrames[name] = parvar HookFrame(name, parvar) elseif not parvar then parvar = false GMoveableFrames[name] = parvar end end function addon:RemMoveableFrame(name, arg1) end SlashCmdList["GMOVE_SHORTHAND"] = function(name, parvar) addon:AddMoveableFrame(name, parvar) end SLASH_GMOVE_SHORTHAND1 = "/gmove" Last edited by Grimsin : 11-02-10 at 01:09 PM. |
||
11-02-10, 02:46 PM | #28 |
Yey, home to a real comp!
Ok, back to business. When you pass slash arguments, it gets passed as one string. In your current code, if someone were to "/gmove PlayerFrame UIParent" (assuming "parvar" is supposed to indicate the parent, not clear from the snippet to me) it would get passed to the function like this (inserted as literal terms): lua Code:
The 2nd argument is passing nil to the slash handler of the API and breaking stuff (as you know). To fix this, you need separate your arguments before you pass them: lua Code:
That should get that part working for you. On a side note, you may want to explore what I like to call "universal" slash/event handlers to make your coding a bit less tedious and confusing along the way. Examples: Slash Handler: lua Code:
In this case, you can add slash commands without having to add a bunch of "if-then-else" which is just a pain. Just add the function myAddon:<cmd> and off you go. Event Handler (maybe a bit easier to understand, was for me when learning it): lua Code:
Same concept. Instead of adding a bunch of new "if-then-else" event comparisons, it simply goes to function if it exists. If not, it ignores the event. Adding new event watchers is a simple addition of registering the event and adding the new function. If something ends up being removed just delete the function without worrying about possibly having to change "elseif" statements. Just something I thought I'd throw out there for you since your project is becoming "a beast" to help clean/organize a bit easier. |
|
11-02-10, 03:01 PM | #29 |
okay... parvar = a value OR a string. So in game you would do /gmove GameMenuFrame true
where true could be either true, false, or a frame name. So i need to do the strsplit part obviously, but then how would that translate over? rather this part in particular- local name, parvar = strsplit(" ", cmd) i need to do something with the " " but im not sure what if " " represents the break then would it be (.. name " " .. parvar) ? this is in the top of the file... --["FrameName"] = false - move the frame --true - move the frame's parent instead --string - move the named frame instead |
|
11-02-10, 03:10 PM | #30 | |
EDIT: Looking over your code, you will most likely HAVE to do the boolean convert. Anything passed from a slash command is automatically converted into a string (true => "true" when passed). Currently, type() will always be "string" if directly taken from the slash command as it is now. Last edited by Sythalin : 11-02-10 at 03:16 PM. |
||
11-02-10, 03:27 PM | #31 |
"do stuff" in the slash command or the add function? if i do it in the slashcommand then i wont have any problems when it comes time to build the GUI. when i do the GUI and those commands are passed from lua rather then a slashcommand it will not always be a string correct? its only because im passing it through the slash command that everything is a string right?
|
|
11-02-10, 03:32 PM | #32 |
so it would look like this right?
Code:
function addon:AddMoveableFrame(name, parvar) if parvar then if type(parvar) == 'string' then parvar = _G[parvar] end GMoveableFrames[name] = parvar HookFrame(name, parvar) elseif not parvar then parvar = false GMoveableFrames[name] = parvar HookFrame(name, parvar) end end function addon:RemMoveableFrame(name, parvar) 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 addon:AddMoveableFrame(name, parvar) end SLASH_GADDMOVE_SHORTHAND1 = "/gaddmove" |
|
11-02-10, 03:34 PM | #33 | |
If that makes any sense, lol. I'm off to take a much needed shower. Be back in a bit if you have any more questions. EDIT: You posted as I did. Yes, that should theoretically work. |
||
11-02-10, 03:38 PM | #34 |
im gonna take a break for a half hour or so myself... im singing a song whos only verse is "parvar" ROFL
|
|
11-02-10, 03:46 PM | #35 |
IT WORKS IT WORKS!!! although ive already thought of a few problems... like... what will happen if i do the /gaddmove twice... will it enter two entrys for the same frame or overwrite the first entry??? and i have no idea how you remove an entry without wiping all the entrys lol.
the answer is if you do it twice in a row it overwrites the first one good deal! Last edited by Grimsin : 11-02-10 at 03:52 PM. |
|
11-02-10, 04:08 PM | #36 |
Glad it works. Later down the line you can even add the option to prompt the user to override or ignore. But like you said, one step at a time.
Off to do homework now. |
|
11-02-10, 04:23 PM | #37 |
yea, fixing the problem where if you put true and it parents to the UIParent your moving the UIParent lol. that was no good. Then im going to poke at the GUI again. Do you know much about the AceConfig and AceGUI libs?
|
|
11-02-10, 04:59 PM | #38 |
Nothing against Ace or any other lib files, but I tend to avoid using other people's libraries when building my addons. As such, I haven't even cracked open Ace# at any point to even look at it. I build all my stuff from scratch (also helps me learn better that way).
|
|
11-02-10, 05:01 PM | #39 |
well thats usually my take to but Vrul used ace to setup the GrimUI LOD config. im pretty lost trying to use it lol. i have it partly understood but... in a minute here ill post what i have so far and see if it makes any sense.
|
|
11-02-10, 07:04 PM | #40 |
Blah okay so as for ace config i have no idea how to make this work.. ultimately i need a text entry field and then to list the contents of the GMoveableFrames saved variable... does anyone know much about the AceConfig and AceGUI? this is what it looks like so far you can see where i started the move frames tab. Is there no help file anywhere about AceGUI? other then this one http://www.wowace.com/addons/ace3/pa...ustom-controls ?
heres my code right now for the ace settings Code:
local addonName, addon = ... addonName = addonName:match("^(.+)_Config$") addon = _G[addonName] if not addon then return end local AceGUI = LibStub("AceGUI-3.0") local path = [[Interface\AddOns\]] .. addonName .. [[\Skins\]] local skins = { [path .. "Alliance"] = "Alliance", [path .. "Horde"] = "Horde", [path .. "BlackMetal"] = "Black Metal", [path .. "Elf"] = "Elf", } local styles = { "Vertical", "Horizontal" } function addon:MoveFrameList() local i, v for i,v in ipairs(GMoveableFrames) do print(i..":"..v) end end --[[----------------------------------------------------------------------------- Common for all options -------------------------------------------------------------------------------]] local function Get(info) return addon.settings[info[#info]] end local function Set(info, value) addon.settings[info[#info]] = value or false end --[[----------------------------------------------------------------------------- Options -------------------------------------------------------------------------------]] local options = { type = 'group', childGroups = "tab", get = Get, set = Set, args = { option1 = { name = "General", desc = "General Options.", type = "group", order = 1, args = { lockFrames = { type = 'toggle', order = 1, name = "Lock Frames", desc = "Prevent frames from being moved by the mouse." }, tooltipIconSize = { type = 'range', order = 3, name = "Tooltip Icon Size", desc = "Set the size of icons added to tooltips.", min = 8, max = 32, step = 1 }, showWatchFrame = { type = 'toggle', order = 2, name = "Show Objectives", desc = "Show Objectives/Watch Frame.", set = function(info, value) Set(info, value) addon:SafeCall("InitWatchFrame") end }, showExpBar = { type = 'toggle', order = 4, name = "Show XP Bar", desc = "Show GrimUI Experiance Bar.", set = function(info, value) Set(info, value) addon:SafeCall("ConfigureExpBar") end }, showRepBar = { type = 'toggle', order = 5, name = "Show Rep Bar", desc = "Show GrimUI Reputatiom/Faction Bar.", set = function(info, value) Set(info, value) addon:SafeCall("ConfigureRepBar") end }, useViewPort = { type = 'toggle', order = 5, name = "Use ViewPort", desc = "Moves world frame up - currently causes water problems turn water detail down in order to us without glitch.", set = function(info, value) Set(info, value) addon:SafeCall("SetupViewPort") end }, uiSkin = { type = 'select', order = 6, name = "Art Skin", desc = "Choose which skin to use.", values = skins, set = function(info, value) Set(info, value) addon:SafeCall("ConfigureSkin") end }, artSetPoint = { type = 'range', order = 7, name = "Art Skin Width", desc = "Set the width of the main art skin.", min = -1920, max = 1920, step = 2, set = function(info, value) Set(info, value) addon:SafeCall("ArtSetPoint") end }, artSetAlpha = { type = 'range', order = 8, name = "Art Skin Alpha", desc = "Set the Alpha of the main art skin.", min = 0, max = 1, step = 0.01, set = function(info, value) Set(info, value) addon:SafeCall("ArtSetAlpha") end }, ResetFrames = { type = 'execute', order = 11, name = "Reset Frames", desc = "Wipe all frame position data.", func = function(info) local movedFrames = addon.settings.movedFrames for name in pairs(movedFrames) do addon:UnlockFrame(name) movedFrames[name] = nil end addon:LockFrame(WatchFrame) addon:SafeCall("ResetPlayerFrame") addon:SafeCall("ResetPartyFrames") addon:SafeCall("ResetExpRepBar") addon:SafeCall("PlayerFrameRESetScale") addon:SafeCall("ResetDevBar") addon:SafeCall("ArtSetPointReset") addon:SafeCall("LFGEyeFix") addon:SafeCall("MiniMapPVPFix") end }, ResetWTF = { type = 'execute', order = 11, name = "Reset WTF File", desc = "Wipe all WTF file settings. !!**WARNING**!! This will reset everything! Including Macaroon!", func = function(info) addon:SafeCall("ResetWTF") ReloadUI() end }, }, }, option2 = { name = "PlayerFrame", desc = "PlayerFrame Options.", type = "group", order = 2, args = { PlayerFrame = { type = 'group', inline = true, order = -4, name = "Player Frame", args = { playerFrameScale = { type = 'range', order = 3, name = "Scale", desc = "Set the Scale of PlayerFrame.", min = 0.4, max = 2.4, step = 0.1, set = function(info, value) Set(info, value) addon:SafeCall("ConfigurePlayerFrame") end }, showPlayerFrame = { type = 'toggle', order = 1, name = "Enable", desc = "Show " .. addonName .. "'s player frame.", set = function(info, value) Set(info, value) addon:SafeCall("ConfigurePlayerFrame") end }, hideBlizPlayerFrame = { type = 'toggle', order = 2, name = "Hide Blizzard", desc = "Disable Blizzard's default player frame.", set = function(info, value) Set(info, value) addon:SafeCall("ConfigureBlizPlayerFrame") end } } }, }, }, option3 = { name = "PartyFrames", desc = "PartyFrames Options.", type = "group", order = 3, args = { PartyFrames = { type = 'group', inline = true, order = -3, name = "Party Frames", args = { showPartyFrames = { type = 'toggle', order = 1, name = "Enable", desc = "Show " .. addonName .. "'s party frames.", set = function(info, value) Set(info, value) addon:SafeCall("ConfigurePartyFrames") end }, hideGrimPartyInRaid = { type = 'toggle', order = 2, name = "Hide Party in Raid", desc = "Hide GrimUI Party Frames in Raid.", set = function(info, value) Set(info, value) addon:SafeCall("ConfigurePartyFrames") end }, hideBlizPartyFrames = { type = 'toggle', order = 3, name = "Hide Blizzard", desc = "Disable Blizzard's default party frames.", set = function(info, value) Set(info, value) addon:SafeCall("ConfigureBlizPartyFrames") end }, stylePartyFrames = { type = 'select', order = 4, name = "Party Frames Style", desc = "Choose which style to use for party frames.", values = styles, set = function(info, value) Set(info, value) addon:SafeCall("StylePartyFrames") end } } }, }, }, option4 = { name = "TargetFrame", desc = "TargetFrame Options.", type = "group", order = 4, args = { TargetFrame = { type = 'group', inline = true, order = -3, name = "Target Frame", args = { hideBlizTargetFrame = { type = 'toggle', order = 1, name = "Hide Blizzard", desc = "Hide Blizzard Target Frame.", set = function(info, value) Set(info, value) addon:SafeCall("ConfigureBlizTargetFrame") end }, } }, }, }, option5 = { name = "Chat", desc = "Chat Options.", type = "group", order = 5, args = { showCombatLog = { type = 'toggle', order = 2, name = "Show Combat Log", desc = "Enable the combat log window.", set = function(info, value) Set(info, value) addon:SafeCall("ConfigureCombatLog") end }, showChatTabs = { type = 'toggle', order = 3, name = "Show Chat Tabs", desc = "Show Chat Frame 2 and 6's Chat Tabs.", set = function(info, value) Set(info, value) addon:SafeCall("ConfigureChatTabs") end }, ResetChat = { type = 'execute', order = -4, name = "Reset Chat", desc = "Reset the chat windows to " .. addonName .. "'s defaults.", func = function(info) addon:SafeCall("ResetChatFrames") end }, }, }, option6 = { name = "Hud", desc = "Heads Up Display Options.", type = "group", order = 6, args = { Hud = { type = 'group', inline = true, order = -3, name = "Hud", args = { } }, }, }, option7 = { name = "DashBoard", desc = "DasrhBoard Options.", type = "group", order = 6, args = { DashBoard = { type = 'group', inline = true, order = -3, name = "DasrhBoard", args = { latencyShow = { type = 'toggle', order = 1, name = "FPS/Latency", desc = "Show DashBoard FPS and Latency frames.", set = function(info, value) Set(info, value) addon:SafeCall("DashLayout") end }, speedShow = { type = 'toggle', order = 1, name = "Speed", desc = "Show DashBoard Speed frame.", set = function(info, value) Set(info, value) addon:SafeCall("DashLayout") end }, } }, }, }, option8 = { name = "Frame Mover", desc = "Make Frames Move-Able.", type = "group", order = 7, args = { listFrame = { type = 'group', inline = true, order = 1, name = "Moveable Frames List", args = { } }, addFrame = { type = 'input', order = 11, name = "Add Frame", desc = "Add Frame to Moveable Frames List", } }, }, option20 = { name = "Dev Tools", desc = "Development Tools.", type = "group", order = 8, args = { showDevBar = { type = 'toggle', order = 1, name = "GrimUI DevBar", desc = "GrimUI Development Bar, easy /framestack /reload button.", set = function(info, value) Set(info, value) addon:SafeCall("ShowDevBar") end }, toggleTaintLog = { type = 'toggle', order = 2, name = "Taint Logging", desc = "Enable Taint Logging - MAY REQUIRE RELOAD.", set = function(info, value) Set(info, value) addon:SafeCall("ToggleTaintLog") end }, BlizBuildInfo = { type = 'execute', order = 3, name = "Blizzard Build Info", desc = "Retrive current Blizzard build infomration.", func = function(info) addon:SafeCall("BlizBuildInfo") end }, }, }, }, } --[[----------------------------------------------------------------------------- Initialize -------------------------------------------------------------------------------]] LibStub('AceConfigRegistry-3.0'):RegisterOptionsTable(addonName, options) addon.configPanel:AssignOptions(addonName) --addon.configPanel:SetDesc("These options allow you to change the appearance and behavior of " .. addonName .. ".") addon.configPanel:SetInfo("Version: " .. GetAddOnMetadata(addonName, 'Version')) |
|
WoWInterface » Developer Discussions » Lua/XML Help » saving tables as variables in the saved variables |
«
Previous Thread
|
Next Thread
»
|
Display Modes |
Linear Mode |
Switch to Hybrid Mode |
Switch to Threaded Mode |
|
|