Thread Tools Display Modes
10-20-10, 10:56 PM   #1
Yksrep
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 21
Post XML Make Button drag-able

Im having trouble with making a GameMenuButtonTemplate button drag-able, can anyone give me a hand or tell me where I can find a why to do it.

Thanks


Code:
<Ui xmlns="http://www.blizzard.com/wow/ui/"

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    xsi:schemaLocation="http://www.blizzard.com/wow/ui/

    http://wowprogramming.com/FrameXML/UI.xsd">


    <Button name="PointMe_Button"
 inherits="GameMenuButtonTemplate"
 parent="WorldMapFrame" text="Point Me">

        <Anchors>
            <Anchor point="TOPRIGHT">
                <Offset x="-213" y="-1"/>
            </Anchor>
        </Anchors>

        <Scripts>

            <OnClick>

                PointMe_ButtonOnClick(self, button, down)

            </OnClick>		

        </Scripts>

    </Button>

    <Frame name="PointMe_DropDown" inherits="UIDropDownMenuTemplate" frameStrata="FULLSCREEN_DIALOG">

        <Scripts>

            <OnLoad>

                PointMe_DropDownOnLoad(self)

            </OnLoad>

        </Scripts>

    </Frame>

</Ui>
  Reply With Quote
10-21-10, 03:32 AM   #2
Xubera
A Cobalt Mageweaver
 
Xubera's Avatar
AddOn Author - Click to view addons
Join Date: May 2009
Posts: 207
Code:
<Button name="PointMe_Button" inherits="GameMenuButtonTemaplte" parent="WorldMapFrame" text="Point Me" movable="true">
    <Anchors>
      <Anchor point="TOPRIGHT" x="-213" y="-1" />
    </Anchors>
    <Scripts>
      <OnLoad>self:RegisterForDrag("LeftButton")</OnLoad>
      <OnDragStart>self:StartMoving()</OnDragStart>
      <OnDragStop>self:StopMovingOrSizing()</OnDragStop>
      <OnClick>PointMe_ButtonOnClick(self,button,down)</OnClick>
    </Scripts>
  </Button>
I added movable=true to the button tag, I forget if its implied, but I set it just in case.

added 3 scripts, you must register the frame to listen for dragging, only the left mouse button works in this case.
other 2 scripts are self explanatory

hope this helps
__________________
Chat Consolidate is the solution to any out of control trade chat. Ignore lines, throttle chat, consolidate posts!Follow the link to find out how!

▲ ▲ WoWInterface wont let me triforce >.>
  Reply With Quote
10-21-10, 04:34 AM   #3
Yksrep
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 21
Thanks mate I got that working and I added
Code:
	<OnDragStart>
		if IsShiftKeyDown() then
		PointMe_Button:StartMoving()
		end
	</OnDragStart>
so that I have press shift and left click to move it.

But now for some strange reason it now appears behind the world map so that I cant click on it but I found by adding
Code:
toplevel="true">
to
Code:
<Button name="PointMe_Button" inherits="GameMenuButtonTemplate" parent="WorldMapFrame" text="Point Me" movable="true" toplevel="true">
and now it all works
  Reply With Quote
10-21-10, 04:53 AM   #4
Yksrep
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 21
Now with that working is it possible to reset it's position either via a /command or when you log in again. The only way I found to do this it to delete the saved variables folder, this wouldn't be a problem if it didn't delete all of there other addons configs

Last edited by Yksrep : 10-21-10 at 04:55 AM.
  Reply With Quote
10-21-10, 02:26 PM   #5
Xubera
A Cobalt Mageweaver
 
Xubera's Avatar
AddOn Author - Click to view addons
Join Date: May 2009
Posts: 207
to reset the position upon logout/login

myButton:SetUserPlaced(false)
http://www.wowwiki.com/API_Frame_SetUserPlaced

to reset mid game just call your command like

myButton:ClearAllPoints()
myButton:SetPoint("CENTER", xOffset, yOffset)


now, if you only have one point set, the ClearAllPoints() isnt necessary like in your case, as we only set the topright point.

SetPoint takes 5 parameters.
(point, referenceFrame, referencePoint, offX, offY)

if you only have 3 params like my example, the point and referencePoint will the the same, and the referenceFrame will default as the parent frame, which is the world map frame in this case.

also its good to note that you can also just have one param like so

:SetPoint("CENTER") and that implies an offset of 0,0 but just know, that if you do :SetPoint("CENTER", -217) that you have to include the y offset too. or the bbutton wont show. its either 1 param, 3 params, or 5 params.


edit::
oh, a good place to add the reset command might be
WorldMapFrame:HookScript("OnShow", function() resetPos() end)
__________________
Chat Consolidate is the solution to any out of control trade chat. Ignore lines, throttle chat, consolidate posts!Follow the link to find out how!

▲ ▲ WoWInterface wont let me triforce >.>
  Reply With Quote
10-22-10, 07:16 AM   #6
Yksrep
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 21
Thanks for you help mate but I found the easiest way is just to delete and reinstall the addon.
  Reply With Quote
10-22-10, 08:50 AM   #7
Xubera
A Cobalt Mageweaver
 
Xubera's Avatar
AddOn Author - Click to view addons
Join Date: May 2009
Posts: 207
the :SetUserPlaced(false) works as well... you just have to reload after you call it

edit::
also you dont have to uninstall/reinstall.

if the frame isnt in existance when the UI gets reloaded or is closing (logout) then it wont save its position.
So if you disable your addon, reload UI, then enable your addon, the frames saved locations are lost accrodign to your layout-cache.wtf which stores the position of frames between sessions
__________________
Chat Consolidate is the solution to any out of control trade chat. Ignore lines, throttle chat, consolidate posts!Follow the link to find out how!

▲ ▲ WoWInterface wont let me triforce >.>
  Reply With Quote
10-22-10, 11:27 PM   #8
Yksrep
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 21
Oh very nice I didnt know that.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » XML Make Button drag-able


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