+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 15 of 19

Thread: Button and images

  1. #1
    Soulwalker
    Join Date
    Mar 2013
    Posts
    20

    Default Button and images

    I want to play around with addons.
    only use for myself. and for fun to start.
    But what I wanted:
    Make some buttons with my own icon
    and by pressing a rewarding icon, then it could be the wrote in the chat "hi" or whatever you could think of ..
    I will not do some complicatet right now because i am new in this. so i will try in the small code and learn.

    So my question is:
    How to make a button with icon / image
    and how do you get by pressing the button on to write in the chat .. or something else.

    And the last thing that I like to learn how to make a window / bar with wallpaper(images)

    Hope someone will help me progress. do not expect everything comes without work. but then I could see how and what the code looks like.
    have now searched the net and can not really find any guide to how or what.i do
    nevertheless found one that looks like this .: - but it fails.

    --------------------
    -- Create our context --
    local context = UI.CreateContext("SampleContext")
    -- Create our text frame --
    local texture = UI.CreateFrame("Texture", "SampleTexture", context)
    -- This will load a file named "sample.jpg" in your addon's directory --
    texture:SetTexture("bg/", "sample.jpg")
    -- Sets the Texture frame size to the dimensions of the loaded file --
    texture:ResizeToTexture()
    -- Put it at the top center of the game --
    texture:SetPoint("TOPCENTER", UIParent, "TOPCENTER")


    And i dont know what its wrong..

    Right now i have this code :
    i play whit and try to do alittle there and there, but this use Rift's own button. i will like to use my own button

    here the code
    -- Create our context
    local context = UI.CreateContext("SampleContext")
    -- Create our button
    local button = UI.CreateFrame("RiftButton", "SampleButton", context)
    local button1 = UI.CreateFrame("RiftButton", "SampleButton", context)
    -- Set some text
    button:SetText("Click Me!")
    button1:SetText("Check")
    -- Put the button in the middle of the screen
    button:SetPoint("CENTER", UIParent, "CENTER", -125, 10)
    button1:SetPoint("CENTER", UIParent, "CENTER", 0, 10)
    -- Run a function when the button is pressed
    function button.Event:LeftPress ()
    print("Click!")
    end
    function button1.Event:LeftPress ()
    print("Check")
    end

    Sorry my bad english... so i there are something your guys not understand please ask and i will try to explain the best way i could.

  2. #2
    Sword of Telara DoomSprout's Avatar
    Join Date
    Apr 2011
    Posts
    876

    Default

    OK, let's assume you have an addon with the identifier "MyAddon".

    Within your addon's folder, you have added an image file "MyImage.png".

    So, your addons folder looks something like this:

    Code:
    /Interface
      /Addons
        /MyAddon
          RiftAddon.toc
          main.lua
          MyImage.png
    Setup RiftAddon.toc to give your addon an ID of "MyAddon", and tell it to run "main.lua".

    Within main.lua, put the following code:

    Code:
    local context = UI.CreateContext("MyContext")
    local texture = UI.CreateFrame("Texture", "MyTextureName", context)
    texture:SetTexture("MyAddon", "MyImage.png")
    texture:SetPoint("CENTER", UIParent, "CENTER")
    What this is doing is...

    1. Creating a context. Every frame that you create needs to belong to a context. It's like the invisible parent of all of your frames.

    2. Creating a texture frame, as a child of the context we just created.

    3. Setting the texture on this frame to our image. We tell RIFT to look inside our addon's folder by giving it our addon ID, and we provide the filename of the image within our folder.

    4. Attaching the center of the texture frame to the center of the screen.

    Once you've got this working, you're well on the way to having your own button. Adding something like this should work:

    Code:
    function texture.Event:LeftClick()
      print("Click!")
    end
    This method of adding events is actually being removed soon, but it'll work for now.
    Last edited by DoomSprout; 03-12-2013 at 02:20 PM.

    Gadgets: Unit Frames and Other Stuff for RIFT

  3. #3
    Soulwalker
    Join Date
    Mar 2013
    Posts
    20

    Default

    DoomSprout

    Thanks :-) its works

    so now can i try to set my text into the chat..
    I have some idear. then i play, and i shell write same think to my frinds. so i coult have a text in a button.. some like: thanks for the play or have at nice day..
    so i could just click on my button and vupti its write in chat to the guys..

    But your info give me a lot.. and now i know i shell use the Toc. Id to.. thanks again..


    i just delete my last comment...
    Its was me.. i code in wrong map... LOL --- i have the working map and then i copy to the rift.
    damm.. mayby alittle rest will help :-)
    Last edited by SnookieWar; 03-12-2013 at 03:04 PM.

  4. #4
    Sword of Telara DoomSprout's Avatar
    Join Date
    Apr 2011
    Posts
    876

    Default

    No problem, glad I could help

    To say something in chat, you need to use a macro. Using a macro also means you need to put your context and your texture frame into secure mode.

    The code should end up looking something like this:

    Code:
    local context = UI.CreateContext("MyContext")
    context:SetSecureMode("restricted")
    
    local texture = UI.CreateFrame("Texture", "MyTextureName", context)
    texture:SetSecureMode("restricted")
    
    texture:SetTexture("MyAddon", "MyImage.png")
    texture:SetPoint("CENTER", UIParent, "CENTER")
    
    texture.Event.LeftClick = "say Hello"

    Gadgets: Unit Frames and Other Stuff for RIFT

  5. #5
    Soulwalker
    Join Date
    Mar 2013
    Posts
    20

    Default

    Thanks again...

    Its a big help you give me.. ;-)

    are there some place or lessons i can read ?

    i can see its more defrence in asp or visual studio (basic)
    in this code there
    i miss the guide there i can see color code and just like what stuff..

    But i dont give up.. i have learn : asp and Basic and visual studio(basic) and know this..
    so i will keep working and learn..

  6. #6
    Soulwalker
    Join Date
    Mar 2013
    Posts
    20

    Default

    sorry to ask again.

    but there is a certain way to make mouse over a button.
    button will light up when the mouse is over the button. and then you open a window.

    I do not know, but can i do the same way i doit in visual ..

    Example: you have a button when the mouse is over. then there's a bubble with some text in and the clicking the button you will be able to open a window or that you beat me to write to the chat ...
    Last edited by SnookieWar; 03-12-2013 at 04:35 PM.

  7. #7
    RIFT Guide Writer Noshei's Avatar
    Join Date
    Feb 2011
    Posts
    1,886

    Default

    So to make a button that changes when you mouse over it you will need images for each "state" of the button. One for the normal button, one for when you mouse over it, one for when you press it.

    So the easiest way to do this is using a function.

    So we will go off of what doomsprout posted. So like I said you will need at least 2 more images that you will add to your addon folder. We will call these MyImageHover.png and MyImageDown.png

    Code:
    local context = UI.CreateContext("MyContext")
    context:SetSecureMode("restricted")
    
    local texture = UI.CreateFrame("Texture", "MyTextureName", context)
    texture:SetSecureMode("restricted")
    
    texture:SetTexture("MyAddon", "MyImage.png")
    texture:SetPoint("CENTER", UIParent, "CENTER")
    
    texture.Event.MouseIn = function()
    	texture:SetTexture("MyAddon", "MyImageHover.png")
    end
    
    texture.Event.MouseOut = function()
    	texture:SetTexture("MyAddon", "MyImage.png")
    end
    
    texture.Event.MouseDown = function()
    	texture:SetTexture("MyAddon", "MyImageDown.png")
    end
    
    texture.Event.MouseUp = function()
    	texture:SetTexture("MyAddon", "MyImage.png")
    end
    
    texture.Event.LeftClick = "say Hello"

    Now there is one issue here and that is that the LeftClick event will not get ran, and I'm not really sure how to do a macro with this setup. So someone else might be able to do this better.

  8. #8
    Soulwalker
    Join Date
    Mar 2013
    Posts
    20

    Default

    thanks..

    i just try but i get error on it..

    Error: Unknown: Unknown event MouseDown
    In MyAddon / main.lua
    stack traceback:
    [C]: in function 'INTERNAL_EventNewIndex'
    MyAddon/main.lua:25: in main chunk

    and linie 25 is :
    end on the first function line

  9. #9
    RIFT Guide Writer Noshei's Avatar
    Join Date
    Feb 2011
    Posts
    1,886

    Default

    oh my bad, copy and paste error

    replace:
    Code:
    texture.Event.MouseDown = function()
    	texture:SetTexture("MyAddon", "MyImageDown.png")
    end
    
    texture.Event.MouseUp = function()
    	texture:SetTexture("MyAddon", "MyImage.png")
    end
    with:
    Code:
    texture.Event.LeftDown = function()
    	texture:SetTexture("MyAddon", "MyImageDown.png")
    end
    
    texture.Event.LeftUp = function()
    	texture:SetTexture("MyAddon", "MyImage.png")
    end

  10. #10
    Soulwalker
    Join Date
    Mar 2013
    Posts
    20

    Default

    Thanks..

    I can see its blink and my icon its gone..
    I think i will look on it tomorrow.. i will go to sleep now.
    but thanks for help. :-)

  11. #11
    Shield of Telara Adelea's Avatar
    Join Date
    Mar 2011
    Posts
    734

    Default

    Quote Originally Posted by Noshei View Post
    SNow there is one issue here and that is that the LeftClick event will not get ran, and I'm not really sure how to do a macro with this setup. So someone else might be able to do this better.
    This is where the new event system comes in handy, since we can attach multiple handlers to the same event.

    Code:
    texture:EventAttach(Event.UI.Input.Mouse.Left.Down, function(self, h)
    	texture:SetTexture("MyAddon", "MyImageDown.png")
    end, "Event.UI.Input.Mouse.Left.Down")
    
    texture:EventAttach(Event.UI.Input.Mouse.Left.Down, "say hello!", "Event.UI.Input.Mouse.Left.Down")
    http://forums.riftgame.com/image.php?type=sigpic&userid=125779&dateline=13553  38065

  12. #12
    Soulwalker
    Join Date
    Mar 2013
    Posts
    20

    Default

    Thanks..
    I will look on it later to day.

    'll try to explain it as best I can.

    In the code where I could press a button when it wrote to the chat.
    The chat has a code name or a name to indicate that you are writing to chat

    just like that for opening bank, guild, bags

    can anyone tell me or refer to a place where you can see what regulatory call different things.

    a little difficult to make a button that you want to open the bags, but do not know what to write in commandoen to indicate the bags.

    hope it made sense what I wrote.

  13. #13
    Shield of Telara Adelea's Avatar
    Join Date
    Mar 2011
    Posts
    734

    Default

    Quote Originally Posted by SnookieWar View Post
    Thanks..
    I will look on it later to day.

    'll try to explain it as best I can.

    In the code where I could press a button when it wrote to the chat.
    The chat has a code name or a name to indicate that you are writing to chat

    just like that for opening bank, guild, bags

    can anyone tell me or refer to a place where you can see what regulatory call different things.

    a little difficult to make a button that you want to open the bags, but do not know what to write in commandoen to indicate the bags.

    hope it made sense what I wrote.
    Our ability to interact with the default UI via the addon system is so limited as to be almost non-existant.

    Using macros you can do anything that you would use a normal ingame macro for - and opening bags isnt one of them.
    http://forums.riftgame.com/image.php?type=sigpic&userid=125779&dateline=13553  38065

  14. #14
    Soulwalker
    Join Date
    Mar 2013
    Posts
    20

    Default

    its was only a question what are the name of the defrence thing in rift.
    And if i will have a button to open my charater. what are the name of the command or window to open charater

    its was what stoff i looking for...
    i know its not possible or easy to open bank or bags..

    do you know whar commant to close my addons. not go into addon an disable but just push on button

  15. #15
    Soulwalker
    Join Date
    Mar 2013
    Posts
    20

    Default

    adelea

    i have just try that code you wrote..

    texture:EventAttach(Event.UI.Input.Mouse.Left.Down , function(self, h)
    texture:SetTexture("MyAddon", "btnBlue.png")
    end, "Event.UI.Input.Mouse.Left.Down")

    texture:EventAttach(Event.UI.Input.Mouse.Left.Down , "say hello!", "Event.UI.Input.Mouse.Left.Down")


    and i get this error
    Error: MyAddon/main.lua:1: attempt to index global 'texture' (a nil value)
    In MyAddon / main.lua
    stack traceback:
    MyAddon/main.lua:1: in main chunk

+ Reply to Thread
Page 1 of 2 1 2 LastLast

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