Thread Tools Display Modes
04-01-09, 02:13 AM   #1
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
Making oUF_Frames movable

Some of you may know this already. Blizzard included a new "Drag" functionality some time ago which allows us to drag frames. The position is saved in the layout-cache.txt for each character. If "isUserPlaced" is set to true all the SetPoints will be ignored when there is a value in the layout-cache.txt.

To make this work you need give your oUF frames a global name when you spawn them.

Example
Code:
local player = oUF:Spawn("player", "oUF_Player")
local target = oUF:Spawn("target", "oUF_Target")
Now add the move function at the end and call it.

Code:
local function oUF_MoveThisFrame(frame,moveit,lock)
  local f = _G[frame]
  if moveit == 1 then
    f:SetMovable(true)
    f:SetUserPlaced(true)
    if lock ~= 1 then
      f:EnableMouse(true)
      f:RegisterForDrag("RightButton")
      f:SetScript("OnDragStart", function(self) self:StartMoving() end)
      f:SetScript("OnDragStop", function(self) self:StopMovingOrSizing() end)
    end
  else
    f:IsUserPlaced(false)
  end  
end

-- function(frame name, movable on/off, frame locked on/off)
oUF_MoveThisFrame("oUF_Player",1,0);
oUF_MoveThisFrame("oUF_Target",1,0);
If you have no more frames that overlap themselves this should work. Hover the frame, hold down the right mousebutton and start pulling the mouse. You can make this function global or local. Your choice.

You still need to give your spawned frames a default SetPoint. This will be used if you set the frame to not movable or if there is no value in the layout-cache.txt.

The function is untested yet.

*Update*

I made a set of two functions that should do it. Thanks Luzzifus
Check: http://www.wowinterface.com/forums/s...30&postcount=7

You are able to create a dragable frame for spawns of your liking and you can lock those frames when finished.
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW)

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)

Last edited by zork : 04-01-09 at 03:37 AM.
  Reply With Quote
04-01-09, 02:26 AM   #2
Luzzifus
A Warpwood Thunder Caller
 
Luzzifus's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2007
Posts: 94
Very helpful so far.

However, when moving the Party- and/or Raidframes, you run into the problem that oUF spawns those by their header frames. But you don't move the headers, only the so called unit buttons (those you actually see). Practically this can result in the frames resetting their position to the headers.

To avoid this I currently create a "master frame" in my layout, which all the party and raid headers are anchored to and then make only that master frame movable. That is also the easiest way to save the positions I guess.

Last edited by Luzzifus : 04-01-09 at 02:29 AM.
  Reply With Quote
04-01-09, 02:30 AM   #3
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
What may be possible is to generate so called "Holder"-frames and make them parents of your spawned units. Don't know if you can anchor Party frames to a specific holder-frame.

*edit* Oh you said it already
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW)

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)
  Reply With Quote
04-01-09, 02:37 AM   #4
Luzzifus
A Warpwood Thunder Caller
 
Luzzifus's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2007
Posts: 94
Well I don't make it a parent because I don't want the raidframes to inherit the visible state of that master frame. For my layout it's only visible when the frames are unlocked and correct anchoring already does the trick. ^^
  Reply With Quote
04-01-09, 02:54 AM   #5
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
Originally Posted by Luzzifus View Post
Well I don't make it a parent because I don't want the raidframes to inherit the visible state of that master frame. For my layout it's only visible when the frames are unlocked and correct anchoring already does the trick. ^^
Sweet

So this is basically how we could move the party too:
Code:

local party  = oUF:Spawn("header", "oUF_Party")

local f_tph = CreateFrame("Frame","oUF_PartyRaidHolder",UIParent)
f_tph:SetWidth(50)
f_tph:SetHeight(50)
--f_tph:SetBackdrop({bgFile = "Interface/Tooltips/UI-Tooltip-Background", edgeFile = "", tile = true, tileSize = 16, edgeSize = 16, insets = { left = 0, right = 0, top = 0, bottom = 0 }});
f_tph:SetPoint("TOLPEFT",20,-20)

-- 10px from the edge to make it overlap so it stays movable
party:SetPoint("TOPLEFT", f_tph, "TOPLEFT",10,-10)

oUF_MoveThisFrame("oUF_PartyRaidHolder",1,0);
Well this is pretty neat. We could create small move frames and just need to anchor the default oUF frames to that small move frames. Good thing is if you lock the move frame in the lua (via lua config) you can hide the Backdrop when its locked.
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW)

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)

Last edited by zork : 04-01-09 at 03:00 AM.
  Reply With Quote
04-01-09, 03:06 AM   #6
Luzzifus
A Warpwood Thunder Caller
 
Luzzifus's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2007
Posts: 94
Right. To be more particular that's how I do it:

Code:
prh = CreateFrame("Frame",nil,UIParent)
prh:SetWidth(nivDB.prx)
prh:SetHeight(nivDB.pry)
prh:SetScale(nivcfgDB.scale)
			
local tex1 = prh:CreateTexture(nil,"BACKGROUND")
tex1:SetTexture("Interface\\AddOns\\oUF_Nivaya\\textures\\Minimalist")
tex1:SetAllPoints(prh)
tex1:SetVertexColor(0,0,0,0.7)		
prh.texture = tex1

prh:SetPoint("TOPLEFT", UIParent, "BOTTOMLEFT", tX, tY)
local party = oUF:Spawn('header', 'oUF_Party')
party:SetPoint('TOPLEFT', prh, 'TOPLEFT')

oUF_Nivaya:SetPRvisible(false)
oUF_Nivaya:UpdatePrh()
"SetPRvisible" is called whenever the frames are locked or unlocked. It simply shows/hides the master frame:

Code:
function oUF_Nivaya:SetPRvisible(value)
	prh:SetFrameStrata(value and "HIGH" or "LOW")
	prh:EnableMouse(value)
	prh.texture:SetAlpha(value and 0.7 or 0)
	prh.text:SetAlpha(value and 1 or 0)
end
"UpdatePrh" just sets the size to 8 raidgroups according to custom scale and and raidframe settings. The result looks like this (unlocked, raid, 2 players in 2 different raidgroups):



Note that I didn't include the code for the text here, anyone who's interested in the full code may of course take a look at my layout.

Last edited by Luzzifus : 04-01-09 at 03:51 AM.
  Reply With Quote
04-01-09, 03:11 AM   #7
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
Ok I made a set of two functions that should be able to handle it all.

Code:

-- spawns
local player = oUF:Spawn("player", "oUF_Player")
local target = oUF:Spawn("target", "oUF_Target")
local party  = oUF:Spawn("header", "oUF_Party")

  -- move func
  local function oUF_MoveThisFrame(frame,moveit,lock)
    local f = _G[frame]
    if moveit == 1 then
      f:SetMovable(true)
      f:SetUserPlaced(true)
      if lock ~= 1 then
        f:EnableMouse(true)
        f:RegisterForDrag("RightButton")
        f:SetScript("OnDragStart", function(self) self:StartMoving() end)
        f:SetScript("OnDragStop", function(self) self:StopMovingOrSizing() end)
      end
    else
      f:IsUserPlaced(false)
    end  
  end
  
  -- create drag frame func
  local function oUF_CreateDragFrame(framename,movable,locked,anchorframe,anchorframename,anchorpoint,xpos,ypos)
    local f = CreateFrame("Frame",framename,UIParent)
    f:SetWidth(50)
    f:SetHeight(50)
    if locked ~= 1 then
      f:SetBackdrop({bgFile = "Interface/Tooltips/UI-Tooltip-Background", edgeFile = "", tile = true, tileSize = 16, edgeSize = 16, insets = { left = 0, right = 0, top = 0, bottom = 0 }})
    end
    f:SetPoint(anchorpoint,xpos,ypos)
    f:SetFrameStrata("DIALOG")
    if anchorframe == nil then
      anchorframe = _G[anchorframename]
    end
    anchorframe:ClearAllPoints()
    anchorframe:SetPoint("TOPLEFT", f, "TOPLEFT",0,0)
    oUF_MoveThisFrame(framename,movable,locked)
  end
  
  --calls
  -- oUF_CreateDragFrame(framename,movable,locked,anchorframe,anchorframename,anchorpoint,xpos,ypos)
  oUF_CreateDragFrame("oUF_TargetDragFrame",1,0,target,"oUF_Target","CENTER",0,0)
You spawn your frames as normal but whats different is that you call a createdragframe func at the end. This will create a dragable area on the unitframe. You can "lock" frames to hide the drag frame.
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW)

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)

Last edited by zork : 04-03-09 at 08:08 AM.
  Reply With Quote
04-01-09, 03:23 AM   #8
Luzzifus
A Warpwood Thunder Caller
 
Luzzifus's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2007
Posts: 94
Looks nice. However that workaround isn't necessary for the "normal" unit frames like player and target (since they don't have headers). It just makes it look nice when it's unlocked. ^^
  Reply With Quote
04-02-09, 02:32 PM   #9
Dawn
A Molten Giant
 
Dawn's Avatar
AddOn Author - Click to view addons
Join Date: May 2006
Posts: 918
That's really helpfull, thanks.
  Reply With Quote
04-03-09, 04:43 AM   #10
Soeters
A Warpwood Thunder Caller
 
Soeters's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 97
Thanks, I was trying to make such functions for my both raid and normal layout and that's very helpfull
__________________
  Reply With Quote
04-21-09, 06:29 PM   #11
Nubsy
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Mar 2009
Posts: 14
Hi ive bn fidling around with this but get it to work i keep getting

interface\addons\oUF_nubsy\oUF_nubsy.lau:536UF_TargetDragFrame:SetPoint(): Unkown Region Point

at first i got it to work but couldnt get rid of the drag boxes then this happened can some 1 please help ?

my code
-- spawns
`local player = oUF:Spawn("player", "oUF_Player")
local target = oUF:Spawn("target", "oUF_Target")
local pet = oUF:Spawn("pet", "oUF_pet")
local tt = oUF:Spawn("targettarget")
tt:SetPoint("TOPRIGHT", target, "BOTTOMRIGHT", 0, -1)

-- move func
local function oUF_MoveThisFrame(frame,moveit,lock)
local f = _G[frame]
if moveit == 1 then
f:SetMovable(true)
f:SetUserPlaced(true)
if lock ~= 1 then
f:EnableMouse(true)
f:RegisterForDrag("RightButton")
f:SetScript("OnDragStart", function(self) self:StartMoving() end)
f:SetScript("OnDragStop", function(self) self:StopMovingOrSizing() end)
end
else
f:IsUserPlaced(false)
end
end

-- create drag frame func
local function oUF_CreateDragFrame(framename,movable,locked,anchorframe,anchorframename,anchorpoint,xpos,ypos)
local f = CreateFrame("Frame",framename,UIParent)
f:SetWidth(50)
f:SetHeight(50)
if locked ~= 1 then
f:SetBackdrop({bgFile = "Interface/Tooltips/UI-Tooltip-Background", edgeFile = "", tile = true, tileSize = 16, edgeSize = 16, insets = { left = 0, right = 0, top = 0, bottom = 0 }})
end
f:SetPoint(anchorpoint,xpos,ypos)
f:SetFrameStrata("DIALOG")
if anchorframe == nil then
anchorframe = _G[anchorframename]
end
anchorframe:ClearAllPoints()
anchorframe:SetPoint("TOPLEFT", f, "TOPLEFT",0,0)
oUF_MoveThisFrame(framename,movable,locked)
end


--calls
-- oUF_CreateDragFrame(framename,movable,locked,anchorframe,anchorframename,anchorpoint,xpos,ypos)
oUF_CreateDragFrame("oUF_TargetDragFrame",1,0,target_area_dragable,target_area_locked,"oUF_Target","CENTER",1,0)
oUF_CreateDragFrame("oUF_PlayerDragFrame",1,0,player_area_dargable,player_area_locked,"oUF_Player","CENTER",1,0)
oUF_CreateDragFrame("oUF_PetDragFrame",1,0,pet_area_dragable,pet_area_locked,"oUF_Pet","CENTER",1,0)

Last edited by Nubsy : 04-21-09 at 06:33 PM.
  Reply With Quote

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » Making oUF_Frames movable


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