Thread Tools Display Modes
12-30-09, 09:28 PM   #1
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
SetUserPlaced

So i got my chat frames to remember position but they dont close until log out. Trying to make it so that when you move things like the player paperdoll frame that it remembers where you m oved it to when you hit the x button. any ideas?
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
12-30-09, 10:46 PM   #2
Sythalin
Curse staff
 
Sythalin's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2006
Posts: 680
frame:SetUserPlaced(true)

This stores it's position with WoW itself and will restore to these points when you log back in (unless you have another mod that moves them, which typically occurs AFTER this placement).
  Reply With Quote
12-31-09, 03:18 AM   #3
nightcracker
A Molten Giant
 
nightcracker's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 716
lua Code:
  1. local dummy = function() end
  2. ChatFrame1:SetUserPlaced(nil)
  3. ChatFrame1:ClearAllPoints()
  4. ChatFrame1:SetPoint("TOPLEFT", ChatBackground, 3, -2)
  5. ChatFrame1:SetPoint("BOTTOMRIGHT", ChatBackground, -2, 5)
  6. ChatFrame1.ClearAllPoints = dummy
  7. ChatFrame1.SetPoint = dummy
  8. ChatFrame1.SetUserPlaced = dummy
This is what I use, it works for me(make sure you change the setpoint's though).
__________________
Three things are certain,
Death, taxes and site not found,
You, victim of one.
  Reply With Quote
12-31-09, 07:57 AM   #4
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
I can do it with the chat frames no problem but what about like the paperdoll frame? or achievement frame? or better yet your bags..... I can make them movable just fine but the problem is they do not save the position they were moved to once they are closed. They always appear in the same spots every time. I tried using SetUserPlaced but no method of inserting that anywhere has worked. My chat frame code looks a lot l ike what you posted and the chat frames are working just fine as far as saving the position after the user moves them after the initial setup of the interface. I know why to... it has to do with the fact the chat windows stay open until you log out. So how do i do that to a frame that closes before a log out? technically it should be able to take a user placed command since it is a blizzard frame but... maybe how i did the moving part? The code is originally from DragEmAll by Emelio, its been modified some and added to. Here is what i have right now, as you can see i have put the setuserplaced in a few spots but those spots nor any other spot does anything, setting it to true,false,nil makes no difference. Clearly im not doing something right?

lua Code:
  1. -----------------------------------
  2. -- Start Movable Blizzard Frames --
  3. -----------------------------------
  4.  
  5. local addon = CreateFrame("Frame")
  6. -- These frames are hooked on login.
  7. local frames = {
  8.   -- ["FrameName"] = true (the parent frame should be moved) or false (the frame itself should be moved)
  9.  
  10.   -- Blizzard Frames
  11.   ["RuneFrame"] = false,
  12.   ["SpellBookFrame"] = false,
  13.   ["QuestLogFrame"] = false,
  14.   ["FriendsFrame"] = false,
  15.   ["LFGParentFrame"] = false,
  16.   ["KnowledgeBaseFrame"] = true,
  17.   ["HelpFrame"] = false,
  18.   ["GossipFrame"] = false,
  19.   ["MerchantFrame"] = false,
  20.   ["MailFrame"] = false,
  21.   ["OpenMailFrame"] = false,
  22.   ["GuildRegistrarFrame"] = false,
  23.   ["DressUpFrame"] = false,
  24.   ["TabardFrame"] = false,
  25.   ["TaxiFrame"] = false,
  26.   ["QuestFrame"] = false,
  27.   ["TradeFrame"] = false,
  28.   ["LootFrame"] = false,
  29.   ["PetStableFrame"] = false,
  30.   ["StackSplitFrame"] = false,
  31.   ["PetitionFrame"] = false,
  32.   ["WorldStateScoreFrame"] = false,
  33.   ["BattlefieldFrame"] = false,
  34.   ["ArenaFrame"] = false,
  35.   ["ItemTextFrame"] = false,
  36.   ["GameMenuFrame"] = false,
  37.   ["InterfaceOptionsFrame"] = false,
  38.   ["MacOptionsFrame"] = false,
  39.   ["PetPaperDollFrame"] = true,
  40.   ["PetPaperDollFrameCompanionFrame"] = "CharacterFrame",
  41.   ["PetPaperDollFramePetFrame"] = "CharacterFrame",
  42.   ["PaperDollFrame"] = true,
  43.   ["ReputationFrame"] = true,
  44.   ["SkillFrame"] = true,
  45.   ["PVPFrame"] = true,
  46.   ["PVPBattlegroundFrame"] = true,
  47.   ["SendMailFrame"] = true,
  48.   ["TokenFrame"] = true,
  49.   ["InterfaceOptionsFrame"] = false,
  50.   ["VideoOptionsFrame"] = false,
  51.   ["AudioOptionsFrame"] = false,
  52.   ["BankFrame"] = false,
  53.   ["VehicleMenuBar"] = false,
  54.   -- AddOns
  55.   ["LudwigFrame"] = false,
  56. }
  57.  
  58. -- Frames provided by load on demand addons, hooked when the addon is loaded.
  59. local lodFrames = {
  60.   -- AddonName = { list of frames, same syntax as above }
  61.   Blizzard_AuctionUI = { ["AuctionFrame"] = false },
  62.   Blizzard_BindingUI = { ["KeyBindingFrame"] = false },
  63.   Blizzard_CraftUI = { ["CraftFrame"] = false },
  64.   Blizzard_GMSurveyUI = { ["GMSurveyFrame"] = false },
  65.   Blizzard_InspectUI = { ["InspectFrame"] = false, ["InspectPVPFrame"] = true, ["InspectTalentFrame"] = true },
  66.   Blizzard_ItemSocketingUI = { ["ItemSocketingFrame"] = false },
  67.   Blizzard_MacroUI = { ["MacroFrame"] = false },
  68.   Blizzard_TalentUI = { ["PlayerTalentFrame"] = false },
  69.   Blizzard_TradeSkillUI = { ["TradeSkillFrame"] = false },
  70.   Blizzard_TrainerUI = { ["ClassTrainerFrame"] = false },
  71.   Blizzard_GuildBankUI = { ["GuildBankFrame"] = false, ["GuildBankEmblemFrame"] = true },
  72.   Blizzard_TimeManager = { ["TimeManagerFrame"] = false },
  73.   Blizzard_AchievementUI = { ["AchievementFrame"] = false, ["AchievementFrameHeader"] = true, ["AchievementFrameCategoriesContainer"] = "AchievementFrame" },
  74.   Blizzard_TokenUI = { ["TokenFrame"] = true },
  75.   Blizzard_ItemSocketingUI = { ["ItemSocketingFrame"] = false },
  76.   Blizzard_GlyphUI = { ["GlyphFrame"] = "PlayerTalentFrame" },
  77.   Blizzard_BarbershopUI = { ["BarberShopFrame"] = false },
  78.   Blizzard_Calendar = { ["CalendarFrame"] = false, ["CalendarCreateEventFrame"] = true },
  79. }
  80.  
  81. local parentFrame = {}
  82. local hooked = {}
  83.  
  84. local function print(msg)
  85.   DEFAULT_CHAT_FRAME:AddMessage("GrimUI" .. msg)
  86. end
  87.  
  88. function addon:PLAYER_LOGIN()
  89.   self:HookFrames(frames)
  90.   -- Bugfix for 3.1+ Battleground frame (wrong anchor)
  91.   if PVPBattlegroundFrameFrameLabel and PVPBattlegroundFrame then
  92.     PVPBattlegroundFrameFrameLabel:ClearAllPoints()
  93.     PVPBattlegroundFrameFrameLabel:SetPoint("TOP", PVPBattlegroundFrame, "TOP", 0, -17)
  94.   end
  95.   -- Bugfix for 3.2 Battleground frame -.-
  96.   if PVPBattlegroundFrameNameHeader and PVPBattlegroundFrame then
  97.     PVPBattlegroundFrameNameHeader:ClearAllPoints()
  98.     PVPBattlegroundFrameNameHeader:SetPoint("TOPLEFT", PVPBattlegroundFrame, "TOPLEFT", 70, -55)
  99.     PVPBattlegroundFrameNameHeader2:ClearAllPoints()
  100.     PVPBattlegroundFrameNameHeader2:SetPoint("TOPLEFT", PVPBattlegroundFrame, "TOPLEFT", 70, -172)
  101.   end
  102. end
  103.  
  104. function addon:ADDON_LOADED(name)
  105.   local frameList = lodFrames[name]
  106.   if frameList then
  107.     self:HookFrames(frameList)
  108.   end
  109. end
  110.  
  111. local function MouseDownHandler(frame, button)
  112.   frame = parentFrame[frame] or frame
  113.   if frame and button == "LeftButton" then
  114.     frame:StartMoving()
  115.   end
  116. end
  117.  
  118. local function MouseUpHandler(frame, button)
  119.   frame = parentFrame[frame] or frame
  120.   if frame and button == "LeftButton" then
  121.     frame:StopMovingOrSizing()
  122.     frame:SetUserPlaced(true)
  123.   end
  124. end
  125.  
  126. function addon:HookFrames(list)
  127.   for name, child in pairs(list) do
  128.     self:HookFrame(name, child)
  129.   end
  130. end
  131.  
  132. function addon:HookFrame(name, moveParent)
  133.   local frame = _G[name]
  134.   local parent
  135.   if frame and not hooked[name] then
  136.     if moveParent then
  137.       if type(moveParent) == "string" then
  138.         parent = _G[moveParent]
  139.       else
  140.         parent = frame:GetParent()
  141.       end
  142.       if not parent then
  143.         print("Parent frame not found: " .. name)
  144.         return
  145.       end
  146.       parentFrame[frame] = parent
  147.     end
  148.     if parent then
  149.       parent:SetMovable(true)
  150.       parent:SetClampedToScreen(false)
  151.     end
  152.     frame:EnableMouse(true)
  153.     frame:SetMovable(true)
  154.     frame:SetClampedToScreen(false)
  155.     self:HookScript(frame, "OnMouseDown", MouseDownHandler)
  156.     self:HookScript(frame, "OnMouseUp", MouseUpHandler)
  157.     hooked[name] = true
  158.     frame:SetUserPlaced(true)
  159.   end
  160. end
  161.  
  162. function addon:HookScript(frame, script, handler)
  163.   if not frame.GetScript then return end
  164.   local oldHandler = frame:GetScript(script)
  165.   if oldHandler then
  166.     frame:SetScript(script, function(...)
  167.       handler(...)
  168.       oldHandler(...)
  169.     end)
  170.   else
  171.     frame:SetScript(script, handler)
  172.   end
  173. end
  174.  
  175. addon:SetScript("OnEvent", function(f, e, ...) f[e](f, ...) end)
  176. addon:RegisterEvent("PLAYER_LOGIN")
  177. addon:RegisterEvent("ADDON_LOADED")
  178.  
  179. -- Hook bag frames
  180. hooksecurefunc("ContainerFrame_GenerateFrame", function(frame, size, id)
  181.   if id <= NUM_BAG_FRAMES or id == KEYRING_CONTAINER then
  182.     addon:HookFrame(frame:GetName())
  183.   end
  184. end)
  185. ----------------------------------
  186. -- End Moveable Blizzard Frames --
  187. ----------------------------------
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]

Last edited by Grimsin : 12-31-09 at 08:23 AM.
  Reply With Quote
12-31-09, 08:06 AM   #5
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
hmm how are you transferring the code coloring when you post code?
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
12-31-09, 08:11 AM   #6
Zergreth
A Fallenroot Satyr
 
Zergreth's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 24
Originally Posted by Grimsin View Post
hmm how are you transferring the code coloring when you post code?
[highlight=lua]Add your code here[/highlight]
  Reply With Quote
12-31-09, 10:15 AM   #7
Sythalin
Curse staff
 
Sythalin's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2006
Posts: 680
Ah, I ran into this issue with CFM. In the end, I realized I couldn't rely on SetUserPlaced, especially when it came to the LoD stuff. I ended up hooking the "OnShow" script of the frames to adjust their positions:

lua Code:
  1. if _G[frame]:GetScript("OnShow") then
  2.         _G[frame]:HookScript("OnShow", function() CFM_ApplySettings(frame) end)
  3.     else
  4.         _G[frame]:SetScript("OnShow", function() CFM_ApplySettings(frame) end)
  5.     end

Worked like a dream.
  Reply With Quote
12-31-09, 04:38 PM   #8
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
Im confused haha. So you made it save to a variable when you moved the frame is that what its calling on with CFM_ApplySettings?
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
12-31-09, 04:49 PM   #9
Sythalin
Curse staff
 
Sythalin's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2006
Posts: 680
Originally Posted by Grimsin View Post
Im confused haha. So you made it save to a variable when you moved the frame is that what its calling on with CFM_ApplySettings?
Correct. Here's the save format I use (minus the toon name):

lua Code:
  1. CFM_Profiles = {
  2.     ["Thunderlord"] = {
  3.         [toon] = {
  4.             ["ChatFrame1"] = {
  5.                 ["strata"] = "BACKGROUND",
  6.                 ["point"] = "BOTTOMLEFT",
  7.                 ["parent"] = "UIParent",
  8.                 ["offsetX"] = 182.7555989829723,
  9.                 ["width"] = 302.6370598246784,
  10.                 ["forceHide"] = false,
  11.                 ["offsetY"] = 55.52592160182611,
  12.                 ["name"] = "ChatFrame1",
  13.                 ["relativePoint"] = "BOTTOMLEFT",
  14.                 ["sameXY"] = false,
  15.                 ["level"] = 12,
  16.                 ["height"] = 76.89630148815421,
  17.                 ["scale"] = 1,
  18.             },
  19.             ["TargetFrame"] = {
  20.                 ["strata"] = "LOW",
  21.                 ["point"] = "BOTTOM",
  22.                 ["parent"] = "UIParent",
  23.                 ["name"] = "TargetFrame",
  24.                 ["width"] = 232.0000136774479,
  25.                 ["offsetX"] = 250.0000077961453,
  26.                 ["offsetY"] = 120.0000016412938,
  27.                 ["forceHide"] = false,
  28.                 ["relativePoint"] = "BOTTOM",
  29.                 ["sameXY"] = false,
  30.                 ["level"] = 1,
  31.                 ["height"] = 100.0000013677448,
  32.                 ["scale"] = 1,
  33.             },
  34.             ["WorldFrame"] = {
  35.                 ["strata"] = "BACKGROUND",
  36.                 ["point"] = "TOPLEFT",
  37.                 ["parent"] = "UIParent",
  38.                 ["scale"] = 1,
  39.                 ["width"] = 1365.333426704711,
  40.                 ["sameXY"] = false,
  41.                 ["level"] = 0,
  42.                 ["name"] = "WorldFrame",
  43.                 ["relativePoint"] = "TOPLEFT",
  44.                 ["height"] = 630.0000042400088,
  45.                 ["offsetY"] = 0,
  46.                 ["forceHide"] = false,
  47.                 ["offsetX"] = 0,
  48.             },
  49.             ["MainMenuBar"] = {
  50.                 ["strata"] = "MEDIUM",
  51.                 ["point"] = "BOTTOM",
  52.                 ["parent"] = "UIParent",
  53.                 ["scale"] = 1,
  54.                 ["width"] = 1024,
  55.                 ["height"] = 53.00000116258307,
  56.                 ["level"] = 1,
  57.                 ["offsetX"] = 0,
  58.                 ["relativePoint"] = "BOTTOM",
  59.                 ["sameXY"] = false,
  60.                 ["offsetY"] = 100.0000013677448,
  61.                 ["name"] = "MainMenuBar",
  62.                 ["forceHide"] = false,
  63.             },
  64.             ["ChatFrame2"] = {
  65.                 ["strata"] = "BACKGROUND",
  66.                 ["point"] = "BOTTOMRIGHT",
  67.                 ["parent"] = "UIParent",
  68.                 ["name"] = "ChatFrame2",
  69.                 ["width"] = 264.0000421265395,
  70.                 ["offsetX"] = -220.7186445703849,
  71.                 ["offsetY"] = 52.32582771982377,
  72.                 ["forceHide"] = false,
  73.                 ["relativePoint"] = "BOTTOMRIGHT",
  74.                 ["height"] = 74.99999883741693,
  75.                 ["level"] = 10,
  76.                 ["sameXY"] = false,
  77.                 ["scale"] = 1,
  78.             },
  79.             ["Minimap"] = {
  80.                 ["strata"] = "BACKGROUND",
  81.                 ["point"] = "BOTTOM",
  82.                 ["parent"] = "UIParent",
  83.                 ["name"] = "Minimap",
  84.                 ["width"] = 140.0000106684094,
  85.                 ["offsetX"] = 0,
  86.                 ["offsetY"] = 40.00000054709792,
  87.                 ["forceHide"] = false,
  88.                 ["relativePoint"] = "BOTTOM",
  89.                 ["height"] = 140.0000106684094,
  90.                 ["level"] = 1,
  91.                 ["sameXY"] = true,
  92.                 ["scale"] = 1.100000023841858,
  93.             },
  94.             ["WatchFrame"] = {
  95.                 ["strata"] = "LOW",
  96.                 ["point"] = "TOPRIGHT",
  97.                 ["parent"] = "UIParent",
  98.                 ["name"] = "WatchFrame",
  99.                 ["width"] = 204.0000150451927,
  100.                 ["offsetX"] = -120.0000016412938,
  101.                 ["offsetY"] = 0,
  102.                 ["forceHide"] = false,
  103.                 ["relativePoint"] = "TOPRIGHT",
  104.                 ["sameXY"] = false,
  105.                 ["level"] = 1,
  106.                 ["height"] = 500.0000155922906,
  107.                 ["scale"] = 1,
  108.             },
  109.             ["PlayerFrame"] = {
  110.                 ["strata"] = "BACKGROUND",
  111.                 ["point"] = "BOTTOM",
  112.                 ["parent"] = "UIParent",
  113.                 ["name"] = "PlayerFrame",
  114.                 ["width"] = 232.0000136774479,
  115.                 ["offsetX"] = -250.0000077961453,
  116.                 ["offsetY"] = 120.0000016412938,
  117.                 ["forceHide"] = false,
  118.                 ["relativePoint"] = "BOTTOM",
  119.                 ["sameXY"] = false,
  120.                 ["level"] = 1,
  121.                 ["height"] = 100.0000013677448,
  122.                 ["scale"] = 1,
  123.             },
  124.         },
  125.     },
  126. }

The actual function:
lua Code:
  1. activeProfile = CFM_Profiles[realm][toon] -- declared earlier in file, including to avoid confusion
  2.  
  3. --[[ APPLY FRAME SETTINGS ]]
  4. function CFM_ApplySettings(frame)
  5.     if activeProfile[frame] == nil or _G[frame] == nil then print(frame.. " not found.") return end
  6.     -- apply frame's settings
  7.     if not UnitAffectingCombat("player") then
  8.         _G[frame]:ClearAllPoints()
  9.         _G[frame]:SetFrameStrata(activeProfile[frame].strata)
  10.         _G[frame]:SetFrameLevel(activeProfile[frame].level)
  11.         _G[frame]:SetScale(activeProfile[frame].scale)
  12.         _G[frame]:SetHeight(activeProfile[frame].height)
  13.         _G[frame]:SetWidth(activeProfile[frame].width)
  14.         if _G[activeProfile[frame].parent] == nil then
  15.             activeProfile[frame].parent = "UIParent"
  16.         end
  17.         _G[frame]:SetPoint(activeProfile[frame].point, activeProfile[frame].parent, activeProfile[frame].relativePoint, activeProfile[frame].offsetX, activeProfile[frame].offsetY)    
  18.         if activeProfile[frame].forceHide then
  19.             _G[frame]:ClearAllPoints()
  20.             _G[frame]:SetPoint("BOTTOMLEFT", UIParent, "TOPLEFT", 0, 0)
  21.             _G[frame]:Hide()
  22.         end
  23.     end
  24. end

Hope that helps a bit and/or gets the brain going.
  Reply With Quote
01-01-10, 10:32 AM   #10
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
Thanks! that certainly answers the question i need to use variables. Now to figure out how to work that into my code. I suck with variables still. Most of the grimUI core is optionless. so far the only variables i have done do not involve user input. It gets info and answers its own questions. Gonna play with it will see what happens.
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
01-01-10, 01:00 PM   #11
Sythalin
Curse staff
 
Sythalin's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2006
Posts: 680
No prob. Personally, I'd make a small lib file in addition to the main file in this case. It'll be easier to access for changes, just make sure that file is listed before the "main" file in the .toc

Glad to have helped though. If you need any more help with this functionality just gimme a ring. I know I had a bit of a time getting the hang of this concept and to get it to work correctly.
  Reply With Quote
01-01-10, 01:42 PM   #12
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
Well actually Cargor wrote a basic frame for modules for me so the addon is modular. So the module core works like the lib for the rest of the addon or at lest thats how i have been building things so far.
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
01-01-10, 01:57 PM   #13
Sythalin
Curse staff
 
Sythalin's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2006
Posts: 680
I see. Oh, and you should log into ICQ once in a while. Been trying to add you for quicker coms.
  Reply With Quote
01-01-10, 02:17 PM   #14
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
haha its on now.
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » SetUserPlaced

Thread Tools
Display Modes

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