+ Reply to Thread
Results 1 to 4 of 4

Thread: Creating buttons

  1. #1
    Soulwalker
    Join Date
    Jan 2017
    Posts
    7

    Question Creating buttons

    Could someone by any chance help me with executing code in a button? This API is a nightmare to work with, im used to working with this game... Runes of Magic API, which also allows the use of xml files to create frames. With Rift's API im at a complete loss until i start getting stuff to work then i'll be able to pick it up much faster.

    Here is the code i am trying to execute on a simple button press, keep in mind please it is just a test button for reloading the UI, i know i can do it in a macro but thats not going to help me with making a button function.

    If you have any ideas how to get this to work please let me know.

    Code:
    local TestRun = UI.CreateContext("TestRun")
    
    local TestButton = UI.CreateFrame("RiftButton", "TestButton", TestRun)
    
    TestButton:SetText("Reload UI")
    
    TestButton:SetPoint("CENTER", UIParent, "LEFT")
    
    function TestButton.Event:LeftPress ()
        print("Click!")
        ReloadUI()
    end


    Update:

    ok, so i have it working with the code below, the only problem is that i cant figure out how to make the button indent on right click like it does with left click ... im assuming it's because i use event:rightclick instead of event:rightpress, but the 2nd doesn't work.....any ideas anyone?

    Code:
    --Secure mode (allows :EventMacroSet(...)).
    local TestRun = UI.CreateContext("TestRun")
    local TestButton = UI.CreateFrame("RiftButton", "TestButton", TestRun)
    TestRun:SetSecureMode("restricted")
    TestButton:SetSecureMode("restricted")
    TestButton:SetText("Reload UI")
    TestButton:SetPoint("CENTER", UIParent, "CENTER")
    
    function TestButton.Event:LeftPress()
        TestButton:EventMacroSet(Event.UI.Input.Mouse.Left.Click, "reloadui")
    end
    
    function TestButton.Event:RightClick()
        print("right clicked")
    end
    Last edited by Lifefire; 02-08-2017 at 03:24 PM.

  2. #2
    Soulwalker
    Join Date
    Jan 2017
    Posts
    7

    Default

    Delete this extra post please.
    Last edited by Lifefire; 02-08-2017 at 03:25 PM. Reason: not needed

  3. #3
    General of Telara
    Join Date
    Mar 2014
    Posts
    942

    Default

    Rift's native buttons simply don't react to right clicks, hence there is no animation or event for it.

    Btw. using events this way is considered legacy, see Event API Redesign
    All UI elements have an EventAttach() function where you hook up event handler.

    RiftButton.Event.LeftPress is the old way to set an event handler for Event.UI.Button.Left.Press, which is specific to RiftButton, and as said, there is no Right.Press
    RiftButton.Event.LeftClick on the other hand refers to Event.UI.Input.Mouse.Left.Click, which is a more generic event available on all frames, no matter if they have some built-in behaviour for that or not.
    Dimension Addon 'Tinker Tools' is now available on Curse!
    Or grab the latest development code on GitHub.

  4. #4
    Soulwalker
    Join Date
    Jan 2017
    Posts
    7

    Default

    That makes much more sense and also just reduced my code a lot too. Thank you.
    Last edited by Lifefire; 02-08-2017 at 04:35 PM.

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts