getting blank white images only in GUI

  • Englisch
  • Without your code, or even a description of what your image should look like, no one can troubleshoot for you.

    I'm a java rookie myself. Following is how I adapted what an established author sent me a couple of days ago. Perhaps this will help.

    Outside the code snippet:public static final String FILE_CONFIRMATION_GRAPHIC = "/resources/images/confirmation.png";This pulls the image data from the specified location under my ~/src folder.

    Quellcode

    1. public static GuiImage createConfirmationGraphic(){
    2. ImageInformation confirmationGraphicFile = new ImageInformation(plugin, FILE_CONFIRMATION_GRAPHIC);
    3. GuiImage confirmationGraphic = new GuiImage(confirmationGraphicFile, 0.5f, 0.2f, true, 80, 32, false);
    4. confirmationGraphic.setPivot(PivotPosition.CenterBottom);
    5. confirmationGraphic.setVisible(false);
    6. return confirmationGraphic;
    7. }
    8. public static GuiPanel createMainPanel(){
    9. GuiPanel mainPanel = new GuiPanel(0.5f, 0.5f, true, 0.65f, 0.9f, true);
    10. mainPanel.setColor(0.0f, 0.0f, 0.0f, 1.0f);
    11. mainPanel.setPivot(PivotPosition.Center);
    12. mainPanel.setBorderColor(0.0f, 0.6f, 0.933f, 1.0f);
    13. mainPanel.setBorderThickness(2, false);
    14. mainPanel.setVisible(false); //I use this as false so that the elements don't appear one I add them to the player but only when I call my show/hide function
    15. return mainPanel;
    16. }
    17. public static GuiLabel createHeaderLabel(){
    18. GuiLabel headerLabel = new GuiLabel("SomeLabel", 0.0f, 1.0f, true);
    19. headerLabel.setPivot(PivotPosition.TopLeft);
    20. headerLabel.setFontSize(20);
    21. headerLabel.setFontColor(1.0f, 0.533f, 0.0f, 1.0f);
    22. headerLabel.setColor(0.0f, 0.0f, 0.0f, 0.0f);
    23. headerLabel.setVisible(false);
    24. return headerLabel;
    25. }
    26. Then you need to instance your panel, add to the player as an atribute and add it to their Gui.
    27. //This method should be called in the PlayerSpawnEvent
    28. public static void setMainPanelAttributes(Player player){
    29. GuiPanel personalMainPanel = createMainPanel();
    30. GuiLabel personalHeaderLabel = createHeaderLabel();
    31. GuiImage personalConfirmationGraphic = createConfirmationGraphic();
    32. //if your element is a label or child to the panel you also need to call the .addChild Method here e.g.
    33. personalMainPanel.addChild(personalHeaderLabel);
    34. player.setAttribute("MainPanel", personalMainPanel);
    35. player.setAttribute("HeaderLabel", personalHeaderLabel);
    36. player.setAttribute("ConfirmationGraphic", personalConfirmationGraphic);
    37. player.addGuiElement((GuiPanel) player.getAttribute("MainPanel"));
    38. player.addGuiElement((GuiLabel) player.getAttribute("HeaderLabel"));
    39. player.addGuiElement((GuiImage) player.getAttribute("ConfirmationGraphic"));
    40. }
    41. Then I create my show/hide method to display the panel and label
    42. //This method can be called by e.g. a PlayerCommandEvent, or a PlayerKeyEvent to show the GUI, then you can call it with showhide-false to hide the GUI after the player has clicked something on it via the PlayerGuiClickEvent
    43. public static void showHideMainGui(Player player, boolean showHide){
    44. GuiPanel personalMainPanel = (GuiPanel) player.getAttribute("MainPanel");
    45. GuiLabel personalHeaderLabel = (GuiLabel) player.getAttribute("HeaderLabel");
    46. personalMainPanel.setVisible(showHide);
    47. personalHeaderLabel.setVisible(showHide);
    48. }
    Alles anzeigen
  • From your description, and without access to the code, I don't know what's causing the white rectangle. Is it a gui element that's blocking the image from being seen? The result a result of a bad file? Improper sizing? Are you creating the gui in the right place? Are other elements working OK? There are so many possible problems and no one can nail it down from your descriptions thus far.

    If you can upload your plugin to github, folks can take a look with a fresh pair of eyes.
  • Cannot even recreate your example Trevor which is full of public void objects for something bigger. I am trying to simply turn on a picture and display it and the picture will not load PERIOD
    I turned off the panel to see if it was covering even though it seems to be ontop and still a blank perfectly proportioned white rectangle. i am sure it is something as simple as the database read issue I had all the the examples everyone gave me did not have the "/" in front of the filename which was what was keeping it from being found. There is no examples in the JavaDoc that even remotely works for a picture other than turns on a blank rectangle. It would be nice if this system would use JAVAFX but it seems it wont display those either.



    public ImageInformation singley = new ImageInformation(getPath() + "/assets/singleyes.jpg");
    public ImageInformation n = new ImageInformation(getPath() + "/singleno");
    // public GuiPanel panel = new GuiPanel(0.5f, 0.5f, true, 200, 200, false);
    public GuiImage ybutton = new GuiImage(singley,0.5f,0.5f,true,178,68,false);
  • I understand your frustration but if other people can get it working, then so can you!

    Apologies if some of the following is already known. I'm not sure how much you already understand of the way RW works. All five parts of my sample code are important. We're right on the limits of my knowledge right now, so if you need further help, please put your code on github or wait for others to offer advice.

    Quellcode

    1. public static GuiImage createConfirmationGraphic(){
    2. ...
    3. public static GuiPanel createMainPanel(){
    4. ...
    5. public static GuiLabel createHeaderLabel(){
    6. ...
    These three define the Gui elements. This is where you get the image file and embed it in the GuiImage.

    Quellcode

    1. public static void setMainPanelAttributes(Player player)
    2. ...
    As noted in the comment, this must be called from a PlayerSpawnEvent. It creates a generic GUI template then copies the elements as player attributes that are unique to the player. This is necessary, otherwise a GUI operation (e.g. closing it) would affect everyone on the server.
    In here, we create a GuiPanel mainPanel to hold the other elements. The other elements are added as children of the GuiPanel. (I see that in the prior example I forgot to add GuiImage as a child.)

    In my case, I've put the GUI code in a separate class rwtpaGUI and I call setMainPanelAttributes() from the main class.

    Quellcode

    1. @EventMethod
    2. public static void onPlayerSpawn(PlayerSpawnEvent event) {
    3. Player player = event.getPlayer();
    4. // Prepare GUI
    5. setMainPanelAttributes(player);
    6. }
    Finally, the following toggles visibility of the player's personal GUI so you can turn it on and off as needed (in my case from within the teleportPlayer() method).

    Quellcode

    1. public static void showHideMainGui(Player player, boolean showHide){
    2. ...
    If you'd like to see it altogether... github.com/trevorjd/rwtpa/tree/master/src/com/trevorjd/rwtpa
  • My project is not a project it is just an experiment to see how it works. It will have a mishmash of different stuff being experimented with. I turned off all the panel stuff. It is about the 5th interaction on the path so what you see is not necessarily what I have tried in the past.
    The name of the file has been changed the location of the file has been changed. The type of picture has been both png and jpg. The size of the picture has been checked to be the same pixels as called so I dont think it is off to one side outside of hte box but who knows at this point.

    import net.risingworld.api.Plugin;
    //import java.sql.ResultSet;
    //import java.sql.Connection;
    //import java.sql.SQLException;
    //import net.risingworld.api.database.Database;
    import net.risingworld.api.events.EventMethod;
    import net.risingworld.api.events.Listener;
    import net.risingworld.api.events.player.PlayerCommandEvent;
    import net.risingworld.api.objects.Player;
    import net.risingworld.api.gui.GuiElement;
    import net.risingworld.api.gui.GuiLabel;
    import net.risingworld.api.gui.GuiPanel;
    import net.risingworld.api.gui.PivotPosition;
    import net.risingworld.api.utils.ImageInformation;
    import net.risingworld.api.gui.GuiImage;



    public class GUIreply extends Plugin implements Listener {

    public Plugin plugin = this;
    // public void setImage(y);
    // public void setImage(n);
    String[] splitCommand;
    public ImageInformation singley = new ImageInformation(getPath() + "/assets/singleyes.jpg");
    public ImageInformation n = new ImageInformation(getPath() + "/singleno");
    // public GuiPanel panel = new GuiPanel(0.5f, 0.5f, true, 200, 200, false);
    public GuiImage ybutton = new GuiImage(singley,0.5f,0.5f,true,178,68,false);
    public Player player;
    @Override

    @EventMethod
    public void onPlayerCommand(PlayerCommandEvent event){
    String command = event.getCommand();
    String[] cmd = command.split(" ");
    if (cmd.length >= 2 && cmd[0].equals("/respond")){
    splitCommand = event.getCommand().split(" ");
    if(splitCommand[0].equals("/respond")){
    //3 in command line /antaz getArea areaID
    if(splitCommand.length==2){
    if(splitCommand[0].equals("/respond")){
    {String[] cmds = command.split(" ");
    if (cmds.length == 2){
    if(splitCommand[1].equals("Yes")){
    String key = cmds[1];
    Player player = event.getPlayer();
    player.sendTextMessage("setting up GUI") ;
    // Set up GUI
    //
    // panel = new GuiPanel(0.5f, 0.5f, true, 200, 200, false);
    // panel.setColor(1f, 0f, 0f, 0.8f);
    // panel.setPivot(PivotPosition.Center);
    // panel.setBorderThickness(4f, false);
    // panel.setBorderColor(0f, .74f, 1f, 1f);
    // panel.setClickable(false);
    ybutton.setImage(singley);
    ybutton.getImage();
    ybutton.setClickable(true);
    ybutton.setPivot(PivotPosition.Center);
    // panel.addChild(ybutton);
    Player p = event.getPlayer();
    // p.addGuiElement(panel);
    p.addGuiElement(ybutton);
    // p.getAttribute("singley");
    }
    if(splitCommand[1].equals("remove")){
    ybutton.destroy();
    // panel.destroy();
  • OK, that was only a few pieces of your code so I had to do a lot of reconstruction, but I got it working.
    With images singleyes.png and singleno.png in the assets folder within the jar file, the commands /respond yes, no and off perform as you might expect.

    As you can see, I've implemented the method I've been taught while preserving as much of your code as I could. I'm not sure if it's the best way, but it's modular, pretty easy to understand and it works.

    * Called from a PlayerSpawnEvent, the setupGUI() method defines the GUI elements and sets them as attributes to the player that just spawned.
    * Called from anywhere in the code, the showHideGUI (or variations therepon) can be used to show/hide various elements. As the images are children of the main panel object, in the code below I'm toggling that as well. I haven't tested if that's strictly necessary.

    Anyway, I'm off to bed then away for about 3 days. Good luck. I hope this helps.

    Quellcode

    1. import net.risingworld.api.Plugin;
    2. import net.risingworld.api.events.EventMethod;
    3. import net.risingworld.api.events.Listener;
    4. import net.risingworld.api.events.player.PlayerCommandEvent;
    5. import net.risingworld.api.events.player.PlayerSpawnEvent;
    6. import net.risingworld.api.gui.GuiPanel;
    7. import net.risingworld.api.objects.Player;
    8. import net.risingworld.api.gui.PivotPosition;
    9. import net.risingworld.api.utils.ImageInformation;
    10. import net.risingworld.api.gui.GuiImage;
    11. public class GUIreply extends Plugin implements Listener {
    12. // changed this to static
    13. public static Plugin plugin;
    14. // public void setImage(y);
    15. // public void setImage(singleNo);
    16. String[] splitCommand;
    17. // moved GUI elements to setupGUI()
    18. public Player player;
    19. @Override
    20. public void onEnable()
    21. {
    22. plugin = this;
    23. registerEventListener(this);
    24. }
    25. public void onDisable()
    26. {
    27. unregisterEventListener(this);
    28. }
    29. // added this method
    30. @EventMethod
    31. public static void onPlayerSpawn(PlayerSpawnEvent event)
    32. {
    33. Player player = event.getPlayer();
    34. // Set up GUI
    35. setupGUI(player);
    36. // show GUI
    37. showHideGUI(player, false);
    38. }
    39. public static void setupGUI(Player player)
    40. {
    41. // define a panel
    42. GuiPanel panel = new GuiPanel(0.5f, 0.5f, true, 200, 200, false);
    43. panel.setColor(1f, 0f, 0f, 0.8f);
    44. panel.setPivot(PivotPosition.Center);
    45. panel.setBorderThickness(4f, false);
    46. panel.setBorderColor(0f, .74f, 1f, 1f);
    47. panel.setClickable(false);
    48. panel.setVisible(false);
    49. // define a button
    50. GuiImage buttonYes = new GuiImage(0.5f,0.5f,true,178,68,false);
    51. buttonYes.setImage(new ImageInformation(plugin, "/assets/singleyes.png"));
    52. buttonYes.setClickable(true);
    53. buttonYes.setPivot(PivotPosition.Center);
    54. buttonYes.setVisible(false);
    55. // define a button
    56. GuiImage buttonNo = new GuiImage(0.5f,0.5f,true,178,68,false);
    57. buttonNo.setImage(new ImageInformation(plugin,"/assets/singleno.png"));
    58. buttonNo.setClickable(true);
    59. buttonNo.setPivot(PivotPosition.Center);
    60. buttonNo.setVisible(false);
    61. // add buttons as children of panel
    62. panel.addChild(buttonYes);
    63. panel.addChild(buttonNo);
    64. // assign GUI elements to player
    65. // I don't know if it's necessary to do them individually, but that's the way I was taught
    66. player.setAttribute("panel", panel);
    67. player.setAttribute("buttonYes", buttonYes);
    68. player.setAttribute("buttonNo", buttonNo);
    69. // add GUI elements to HUD
    70. player.addGuiElement((GuiPanel) player.getAttribute("panel"));
    71. player.addGuiElement((GuiImage) player.getAttribute("buttonYes"));
    72. player.addGuiElement((GuiImage) player.getAttribute("buttonNo"));
    73. }
    74. public static void showHideGUI(Player player, boolean visible)
    75. {
    76. GuiPanel myPanel = (GuiPanel) player.getAttribute("panel");
    77. GuiImage myButtonYes = (GuiImage) player.getAttribute("buttonYes");
    78. GuiImage myButtonNo = (GuiImage) player.getAttribute("buttonNo");
    79. myPanel.setVisible(visible);
    80. myButtonYes.setVisible(visible);
    81. myButtonNo.setVisible(visible);
    82. }
    83. public static void showButtonYes(Player player, boolean visible)
    84. {
    85. GuiPanel myPanel = (GuiPanel) player.getAttribute("panel");
    86. GuiImage myButtonYes = (GuiImage) player.getAttribute("buttonYes");
    87. myPanel.setVisible(visible);
    88. myButtonYes.setVisible(visible);
    89. }
    90. public static void showButtonNo(Player player, boolean visible)
    91. {
    92. GuiPanel myPanel = (GuiPanel) player.getAttribute("panel");
    93. GuiImage myButtonNo = (GuiImage) player.getAttribute("buttonNo");
    94. myPanel.setVisible(visible);
    95. myButtonNo.setVisible(visible);
    96. }
    97. @EventMethod
    98. public void onPlayerCommand(PlayerCommandEvent event){
    99. String command = event.getCommand();
    100. String[] cmd = command.split(" ");
    101. if (cmd.length >= 2 && cmd[0].equals("/respond")){
    102. splitCommand = event.getCommand().split(" ");
    103. if(splitCommand[0].equals("/respond")){
    104. //3 in command line /antaz getArea areaID
    105. if(splitCommand.length==2){
    106. if(splitCommand[0].equals("/respond")){
    107. {
    108. String[] cmds = command.split(" ");
    109. if (cmds.length == 2){
    110. if(splitCommand[1].toLowerCase().equals("yes")){
    111. String key = cmds[1];
    112. Player player = event.getPlayer();
    113. player.sendTextMessage("setting up GUI") ;
    114. showHideGUI(player, false);
    115. showButtonYes(player, true);
    116. }
    117. if(splitCommand[1].toLowerCase().equals("no"))
    118. {
    119. Player player = event.getPlayer();
    120. player.sendTextMessage("setting up GUI") ;
    121. showHideGUI(player, false);
    122. showButtonNo(player, true);
    123. }
    124. if(splitCommand[1].toLowerCase().equals("off"))
    125. {
    126. Player player = event.getPlayer();
    127. player.sendTextMessage("Turning off GUI");
    128. showHideGUI(player, false);
    129. }
    130. }
    131. }
    132. }
    133. }
    134. }
    135. }
    136. }
    137. }
    Alles anzeigen
  • Well it loaded ok and seems to turn on and off the GUI exactly the same but seems I get the same exact issue. A white button rectangle in the middle of the red panel. There must be a compatibility issue in the .png or jpg. I will look for this issue. I left it up on my sever if you want to look. Maybe it needs to be in the main directory or in the script file when compiled. Not sure .

    Well I should have read your original email closer as I was looking at the code. I fell into putting them in the jar then went back and read your post with the code.

    So the good news is it works!!!!

    Yes the directory has to be in the jar file which is sort of a problem if you want to keep to date pictures and a trick I did not see anyplace other than remembering something about that in a post for pnb plugin and the textures.

    So in any case thank you verymuch. I left it on my server if you wish to go and look. I suspect my original code would have worked too. I might try it. Another small inside knowledge thing that I learned the hard way.

    THANK YOU VERY MUCH. I am a bit of crab apple and was fully frustrated. I will study your code and see what I can learn.. on to the next phase now. THANK THANKS THANKS. :thumbsup: :thumbup: :D 8o :S

    Hope somebody else reads this and gets inspired .. the community is great

    Dieser Beitrag wurde bereits 3 mal editiert, zuletzt von angriff () aus folgendem Grund: Did not read the entire instructions

  • Glad you got it working! I totally understand your frustration :D

    You can change:
    new ImageInformation(this, "/rw/plugin/images/filename.png");
    to
    new ImageInformation(plugin.getPath() + "/assets/filename.png");

    So far I've only needed to use images which won't change (confirmation buttons, etc.) so I store them in the jar.

    Remember that if you want to have some external process updating the images outside the jar, you'll need to re-execute not just the ImageInfo statement, but also the bits that depend on it (setImage and visibile on/off at the least).