getting blank white images only in GUI

  • I can't help there. I haven't done anything with the mouse yet :D At a quick glance at the API, it'll involve PlayerGuiElementClickEvent. That returns the element (e.g. button) and X/Y floats relative to the element

    Yes it is is that is what the Red said in the post and is in the Javadoc. It is sort of hidden in the Player.GUI and hard to find. Do not turn on the cursor before you have the click event working or it will lock you out. The cursor being on will not allow you access to to the command line or RCON. Basically until you have the return to turn off the cursor it will lock you in cursor mode forever with no recourse but to log off.

  • The cursor being on will not allow you access to to the command line or RCON. Basically until you have the return to turn off the cursor it will lock you in cursor mode forever with no recourse but to log off.

    sorry for not replying earlier to help. I was away for a week :D


    I see @Trevor posted and implemented my example to help @angriff out very well done thank you for stepping in to help :)


    I would recommend opening the GUI and showing the cursor (player.setCursorVisible(true);) via command (PlayerCommandEvent) or by pressing a key (PlayerKeyEvent). Then on the GUI you can have a "close" button (i.e. GuiLabel with .setClickable(true);) which when clicked (PlayerGuiClickEvent) would close the GUI and hide the cursor for the player (player.setCursorVisible(false);)

  • Thanks Minos.. yes Trevor helped allot I am not at my normal home now so I cannot recompile the simpler code with the pictures in the jar to see if it would work but I learned some albeit complicated ways of making a bunch of callable routines to do the trick. Trevor stuck with me through my total an complete frustration with the issues and made it work. He deserves something for that for sure.


    I have been fooling around with GUIElementClickEvent and seems my server is giving me fits accessing it now so I not sure when I will be able to test this help but thanks I put it i my Notes notebook.

  • Hey minos I have the cursor event captured but I cannot get the GuiElementid from the event. I managed to get the event object into a string and can see the id but it is a long string net.RisingWorld.API.GUIlable@1F3. (or close). If the last bit is the ID I can stip that and compare the ID for If statements but that seems complicated. Is there a better way to identify the label? Keep in mind that Trevor's help has most of the labels in voids so I was trying to find it from the event and make sure it is the Close Button.


    The routine event method turns off the cursor too so that part works. ^^ I can click on each element and get the Not the below If does not catch it. I was hoping not to have to redeclare all the void variables and really stir up the code.


    }
    @EventMethod
    public void onPlayerGuiElementClickEvent(PlayerGuiElementClickEvent click){
    // if (click.getGui{}
    Player player = click.getPlayer();
    String box = String.valueOf(click.getGuiElement());
    if (box.equals(player.addGuiElement((GuiLabel) player.getAttribute ("closeme")))){
    player.sendTextMessage("checked if worked true");
    }
    player.sendTextMessage("Box you clicked'"+box);
    player.sendTextMessage("Turning off cursor");
    player.setMouseCursorVisible(false);

  • since you are saving the GuiElement as an attribute for each player you don't really need the internal id of the element. Not to mention that the internal ID can be different after every restart.


    So you could simply use something like this:


    Java
    @EventMethod
    public void onGuiElementClick(PlayerGuiElementClickEvent event){
    Player player = event.getPlayer();
    GuiElement element = event.getGuiElement();
    if (element == (GuiLabel) player.getAttribute("myLabel")){
    //Do something
    }
    }

    PS: if (box.equals(player.addGuiElement((GuiLabel) player.getAttribute ("closeme")))) this line is absolutely wrong, you are re-adding the element to the player while checking if the element has been clicked. Makes no sense at all :/

  • ok attribute.. I was thinking of text but then I want to click on just pictures. That was probably from late night clipping and pasting looking that is how the element was defined so I just cut and put that there. I told you the if statement was not correct. I had just moved that down so I did not want to retype it all from another line of code. I guess I did not look at it fully before I posted it.


    Since the player has the attribute you say we can get the definition it from him. I was initially looking for it to be defined in the event or something like comparing the text but get text is not available in PlayerGuiElementClickEvent just element. I am not sure I would have looked at the player having it.


    Thanks .. I will look at that.


    Still having trouble grasping why the player has to have it and I cant get it from the text or ID from the event but then only the single player has to see it. So thanks.

  • Thanks Minos that works.. I was just not snapping that the player clicked on the event so he knows it and I can compare that object with the event object. I did not even have GUI Element attached ... wierd..



    Thanks again for putting up with me. :thumbsup:



    Trevor you can see what I did with the PlayerGuiElementClickEvent though just test code mind you but it pulls the cursor out from the click event and you can capture what was clicked.. Then be sure to turn the cursor off in that routine or you will have to reload the plugins from the console to get rid of it. (Something I did on several occasions. <X


    ps Trevor I turned the cursor on in the command lines you gave me


    if(splitCommand[1].toLowerCase().equals("yes")){
    String key = cmds[1];
    Player player = event.getPlayer();
    player.sendTextMessage("setting up GUI") ;
    //turn on cursor for player to click- player cannot move with cursor on.
    player.setMouseCursorVisible(true);
    //GUI has both buttons
    showHideGUI(player,false);
    showButtonYes(player, true);


    }

  • Since the player has the attribute you say we can get the definition it from him. I was initially looking for it to be defined in the event or something like comparing the text but get text is not available in PlayerGuiElementClickEvent just element. I am not sure I would have looked at the player having it.

    The event can only give you the internal ID of the GuiElement, that ID is unique to that element but it can change every time the server restarts so I don't think of it as a reasonable number to use for defining my GuiElements.

    Still having trouble grasping why the player has to have it and I cant get it from the text or ID from the event but then only the single player has to see it. So thanks.

    If you want every player to have their own Gui and be able to interact with it independently of what other players do with the same Gui then the Gui must be saved as attributes on the Player object. If you just need a generic box that every player can click and something happens only for the player who clicked it but the Gui doesn't change by that click then you could have your Gui instanced only once and registering all the clicks from all players without it being player specific.


    For example if you wanted to implement a generic heal button them you could just put a GuiLabel always visible on all of the players' screens and when any one of them clicked it then that player got healed, in this scenario there is no point in having a separate GuiLabel saved to the player as the label is not altered by what the player does with it (i.e. click it).

  • Here you go Trevor -- Thanks Minos as ever.


    /respond Yes puts all three click areas on one GUI. Yes. No closeme
    the no was left sort of the same. for reference. you can build out from here like I will..

  • The event can only give you the internal ID of the GuiElement, that ID is unique to that element but it can change every time the server restarts so I don't think of it as a reasonable number to use for defining my GuiElements.

    If you want every player to have their own Gui and be able to interact with it independently of what other players do with the same Gui then the Gui must be saved as attributes on the Player object. If you just need a generic box that every player can click and something happens only for the player who clicked it but the Gui doesn't change by that click then you could have your Gui instanced only once and registering all the clicks from all players without it being player specific.
    For example if you wanted to implement a generic heal button them you could just put a GuiLabel always visible on all of the players' screens and when any one of them clicked it then that player got healed, in this scenario there is no point in having a separate GuiLabel saved to the player as the label is not altered by what the player does with it (i.e. click it).

    Yep I clicked :thumbsup:


    I am an old man and learn slow. But I get the logic just dont get the back and forth about it. So it is somewhat of an experimental process because the java routines you see in videos are not already interacting with a functioning game.. thanks for the tutorials and help.. really ..

Participate now!

Don’t have an account yet? Create a new account now and be part of our community!