Checking which spout button is pressed

Discussion in 'Plugin Development' started by randomman159, Nov 7, 2011.

Thread Status:
Not open for further replies.
  1. Offline


    So in any language really, elements such as buttons have a name so you could check if == "closeScreen4btn" or whatever. However i can't find an equivalent in spout.

    There is the UUID, however im pretty sure that would be different each time the plugin is run, so i couldn't simply check for a specific UUID. I could of course store each UUID on the creation of the button, but i simply wanted to know if there was a more efficient way of doing this.
  2. Offline


    you probably name it yourself with something like:

    Button closeScreen4btn = genericButton

    could be way off though i havnt worked with spout yet and just got genericButton off a quick peek at the javadoc.
  3. Offline


    there is no way of determining previously used variable names. It would have to be a variable stored within the class, or externally in an array, or something else i havn't thought of.... I'm trying to avoid having to store an array however.
  4. Offline


    Here's a class from my GUI:
    2. import org.getspout.spoutapi.event.screen.ButtonClickEvent;
    3. import org.getspout.spoutapi.gui.GenericButton;
    5. public class Player_button extends GenericButton
    6. {
    7. public static Admin_GUI GUI;
    8. public int page_start;
    9. public Player_button(String label, Admin_GUI instance)
    10. {
    11. super();
    12. setText(label);
    13. maxWidth = 100;
    14. minWidth = 100;
    15. setMargin(1, 1);
    16. setColor(Admin_GUI.PLAYER_BUTTON_COLOUR);
    17. setHoverColor(Admin_GUI.BUTTON_HOVER_COLOUR);
    18. GUI = instance;
    19. }
    21. public void onButtonClick(ButtonClickEvent event)
    22. {
    23. GUI.select_player((Player_button)event.getButton());
    24. }
    25. }

    This lets me set up the button properties and change the colour of the "selected" player. I also have similar classes for screen buttons, command buttons, etc.

    So you can make a special class for the close button, or add an Id (or something) property to the button which you an check against later.
  5. Offline


    Thanks, didn't even cross my mind.... Yay for blank moments at midnight :p

    Anyway thanks heaps, definitely what i was after
  6. Offline


    Just realised that wasn't the best example :) I have a navigation button class (for previous/next buttons) which looks more or less the same, but I added properties to let me know whether the button clicked referred to the next screen of players or of screens, and also an index property to let me know where the next page should start from.

    Have a look at the code for the plugin in my sig if you get stuck.
  7. Offline


    I'm just going to use this, to avoid having to have a new class for each type of button.

    package ...;
    import org.getspout.spoutapi.gui.GenericButton;
    public class IdButton extends GenericButton
        public IdButton(String name, String id)
            identification = id;
        private String identification;
        public String getID()
            return identification;
Thread Status:
Not open for further replies.

Share This Page