Thread Tools Display Modes
06-29-16, 02:27 AM   #1
Layback_
An Onyxian Warder
Join Date: Feb 2016
Posts: 358
Safest way to move default player&target unitframe?

Hi all,

For this time, I'm here to ask a question regarding unit frames.

Basically it seems like the following script won't work in .lua file.

Code:
PlayerFrame:ClearAllPoints();
PlayerFrame:SetPoint("LEFT", UIParent, "LEFT");

TargetFrame:ClearAllPoints();
TargetFrame:SetPoint("RIGHT", UIParent, "RIGHT");
I have been told that this is because some default Blizzard functions run after this addon is being called(?).

So, I have tried to add the following lines of code at the end:

Code:
PlayerFrame.SetPoint = function() end;

TargetFrame.SetPoint = function() end;
However, the problem with this attempt would be that it is going to taint frames when I enter or leave the vehicle.

So, the next thing that I have tried was to hook "PlayerFrame_ToPlayerArt" function(?) which seemed to work fine, but it also had a problem with entering or leaving a vehicle.

I would like to know what would be the best way to maintain unit frame's position via .lua file.

Could I ask some advice regarding this?

Thank you.
  Reply With Quote
06-29-16, 03:55 AM   #2
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
I can poin you to this thread:
http://www.wowinterface.com/forums/s...ht=move+target
  Reply With Quote
06-29-16, 04:49 AM   #3
Layback_
An Onyxian Warder
Join Date: Feb 2016
Posts: 358
Originally Posted by Resike View Post
Hi Resike,

I just have tested that method and it seems to work well for PlayerFrame, but does not seem to work for TargetFrame

Code:
local moving;

hooksecurefunc(PlayerFrame, "SetPoint", function(self)
	if moving then
        return;
    end

    moving = true;
    self:SetMovable(true);
    self:SetUserPlaced(true);
    self:ClearAllPoints();
    self:SetPoint("RIGHT", UIParent, "CENTER", -100, -100);
    self:SetMovable(false);
    moving = nil;
end);

hooksecurefunc(TargetFrame, "SetPoint", function(self)
	if moving then
        return;
    end

    moving = true;
    self:SetMovable(true);
    self:SetUserPlaced(true);
    self:ClearAllPoints();
    self:SetPoint("LEFT", UIParent, "CENTER", 100, -100);
    self:SetMovable(false);
    moving = nil;
end);
  Reply With Quote
06-29-16, 10:59 AM   #4
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
Just do this and run it on PLAYER_LOGIN or something.
Code:
PlayerFrame:ClearAllPoints();
PlayerFrame:SetPoint("LEFT", UIParent, "LEFT");
PlayerFrame:SetUserPlaced(true);

TargetFrame:ClearAllPoints();
TargetFrame:SetPoint("RIGHT", UIParent, "RIGHT");
TargetFrame:SetUserPlaced(true);
__________________
Grab your sword and fight the Horde!
  Reply With Quote
06-29-16, 07:23 PM   #5
Layback_
An Onyxian Warder
Join Date: Feb 2016
Posts: 358
Originally Posted by Lombra View Post
Just do this and run it on PLAYER_LOGIN or something.
Code:
PlayerFrame:ClearAllPoints();
PlayerFrame:SetPoint("LEFT", UIParent, "LEFT");
PlayerFrame:SetUserPlaced(true);

TargetFrame:ClearAllPoints();
TargetFrame:SetPoint("RIGHT", UIParent, "RIGHT");
TargetFrame:SetUserPlaced(true);
I tried this as well, but the problem is that this method will permanently position the frame at its new position via calling SetUserPlaced function.

I would like the frames to be moved to new position only when the addon is enabled.

Last edited by Layback_ : 06-29-16 at 08:09 PM.
  Reply With Quote
06-30-16, 04:35 AM   #6
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Originally Posted by Layback_ View Post
I tried this as well, but the problem is that this method will permanently position the frame at its new position via calling SetUserPlaced function.

I would like the frames to be moved to new position only when the addon is enabled.
You can't really do that securely.
  Reply With Quote
06-30-16, 04:51 AM   #7
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
Probably can do SetUserPlaced(false) on PLAYER_LOGOUT, then.
__________________
Grab your sword and fight the Horde!
  Reply With Quote
06-30-16, 06:56 AM   #8
Layback_
An Onyxian Warder
Join Date: Feb 2016
Posts: 358
Hi, Resike, Leatrix and Lombra,

So, overall it would be like the following:

Lua Code:
  1. UFPosition:RegisterEvent("VARIABLES_LOADED");
  2. UFPosition:RegisterEvent("PLAYER_LOGOUT");
  3.  
  4. function UFPosition:OnEvent(event, arg1)
  5.     if event == "VARIABLES_LOADED" then
  6.         PlayerFrame:ClearAllPoints();
  7.         PlayerFrame:SetPoint("RIGHT", UIParent, "CENTER", -100, -200);
  8.         PlayerFrame:SetUserPlaced(true);
  9.  
  10.         TargetFrame:ClearAllPoints();
  11.         TargetFrame:SetPoint("LEFT", UIParent, "CENTER", 100, -200);
  12.         TargetFrame:SetUserPlaced(true);
  13.     elseif event == "PLAYER_LOGOUT" then
  14.         PlayerFrame:SetUserPlaced(false);
  15.  
  16.         TargetFrame:SetUserPlaced(false);
  17.     end
  18. end
  19.  
  20. UFPosition:SetScript("OnEvent", UFPosition.OnEvent);

Please let me know or correct me if I am missing something!


BTW... where did all those syntax highlight go D:

Last edited by Layback_ : 06-30-16 at 05:28 PM.
  Reply With Quote
06-30-16, 08:11 AM   #9
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
Looks good.

Syntax highlighting is [highlight="Lua"]
__________________
Grab your sword and fight the Horde!
  Reply With Quote
06-30-16, 05:27 PM   #10
Layback_
An Onyxian Warder
Join Date: Feb 2016
Posts: 358
Originally Posted by Lombra View Post
Looks good.

Syntax highlighting is [highlight="Lua"]
Sweet!

Thank you for your help
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Safest way to move default player&target unitframe?


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