View Single Post
02-12-16, 04:28 PM   #18
tyroneexe
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Feb 2016
Posts: 13
Originally Posted by Fizzlemizz View Post
You don't want to actually drag the buttons themselves, you want to activate the container frame onDragxxx

Code:
            
btn:RegisterForDrag("LeftButton");--    Register for left drag
btn:SetScript("OnDragStart", function(self) 
	local f = frame:GetScript("OnDragStart") -- Get the frame OnDragStart script
	f(frame) -- run it
end);
btn:SetScript("OnDragStop", function(self) 
	local f = frame:GetScript("OnDragStop") -- Get the frame OnDragStop script
	f(frame) -- run it
end);
This requires that the frame creation be above the CeateButton function ie. at the top of the file.
I not sure what I'm to change (which parts and where in the code). I think here:
Lua Code:
  1. --      Register handlers
  2.         btn:RegisterForClicks("AnyUp");--   Register all buttons
  3.         btn:RegisterForDrag("LeftButton");--    Register for left drag
  4.         btn:SetScript("OnDragStart",OnDragStart);
  5.         btn:SetScript("OnDragStop",OnDragStop);
  6.         btn:SetScript("OnEnter",OnEnter);
  7.         btn:SetScript("OnLeave",OnLeave);
  8.         btn.Tooltip=tooltip;
  9.         btn:SetClampedToScreen(enable);
While also moving
Lua Code:
  1. local frame = CreateFrame("Frame","ACFrame",UIParent)
  2. frame:SetPoint("CENTER",UIParent)
  3. frame:SetSize(40+40+20,(7*40)+20)
  4. frame:SetBackdrop(StaticPopup1:GetBackdrop())
  5.  
  6. frame:SetScale(0.8)
  7. frame:SetMovable(true)
  8. frame:RegisterForDrag("LeftButton")--   Register left button for dragging
  9. frame:SetScript("OnDragStart",frame.StartMoving)--  Set script for drag start
  10. frame:SetScript("OnDragStop",frame.StopMovingOrSizing)--    Set script for drag stop
to the Top. Sorry for asking, I should just do it and see what happens really.

With the current code the frame and buttons all move together when dragging on one of the buttons. Feels nice and easy. I suppose if the player, in the heat of battle, could move the frame by accident. On the other hand it's easier to move without having the click the small area which is the frame.


On another matter.
I'm looking into having the frame only show in Ashran, similar to AshranBuddy.
I'm guessing I'm looking for something like
Fragment Lua from AshranBuddy Code:
  1. if (not Api:IsInAshran()) then
  2.         self.Component:Hide()
  3.     end
although I'm also looking around http://wowprogramming.com/ for something useful.

note to self, should remember to load a char which is actually in Ashran for testing this.
  Reply With Quote