[WIP] SpoutModules - GUI with GUI modules [Spout]

Discussion in 'WIP and Development Status' started by Rahazan, Dec 30, 2011.

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

    Rahazan

    Hello there!

    I have been working on a plugin that creates a "mother" GUI for other GUIs. It is designed for performance and ease of hooking in. These modules can be anything, for example, admin utilities.



    As you can see, it made a small cock-up in the end, that is probably due to the way the example modules I have created clean themselves up the naughty way.
    The code of this example module is below, note the simplicity.

    Code:java
    1. package me.rahazan.spoutmodules.examplemodule;
    2.  
    3. import org.bukkit.entity.Player;
    4. import org.getspout.spoutapi.gui.Color;
    5. import org.getspout.spoutapi.gui.GenericLabel;
    6. import org.getspout.spoutapi.gui.GenericPopup;
    7. import org.getspout.spoutapi.gui.GenericTexture;
    8. import org.getspout.spoutapi.gui.WidgetAnchor;
    9.  
    10. import me.rahazan.spoutmodules.Module;
    11. import me.rahazan.spoutmodules.SpoutModules;
    12.  
    13. public class ExampleModule implements Module{
    14.  
    15. private String name;
    16. SpoutModules plugin;
    17. int value;
    18. int total;
    19.  
    20.  
    21. public ExampleModule(String name, int value, int total){
    22. this.setName(name);
    23. this.value = value;
    24. this.total = total;
    25. }
    26. @Override
    27. public void onModuleOpen(Player player, GenericPopup popup) {
    28.  
    29. /*
    30. * Whatever you want to do when the module gets opened.
    31. * In this example a progress bar + label get put on the popup.
    32. */
    33.  
    34.  
    35.  
    36. plugin = ((SpoutModules)player.getServer().getPluginManager().getPlugin("SpoutModules"));
    37.  
    38. GenericTexture bar = new GenericTexture(plugin.getProgressBarUrl(value, total));
    39. bar.setHeight(8).setWidth(34);
    40. bar.setAnchor(WidgetAnchor.CENTER_CENTER);
    41.  
    42.  
    43.  
    44. GenericLabel label = new GenericLabel(name);
    45. label.setHeight(16).setWidth(100);
    46. label.setAnchor(WidgetAnchor.CENTER_CENTER);
    47. label.shiftXPos(-label.getWidth()/2).shiftYPos(-20);
    48. label.setTextColor(new Color(0.0F, 1.0F, 0.0F, 1.0F));
    49.  
    50.  
    51. popup.attachWidget(plugin, label);
    52. popup.attachWidget(plugin, bar);
    53.  
    54.  
    55. }
    56.  
    57. @Override
    58. public void onModuleClose(Player player) {
    59. /*
    60. * Whatever you want to do when the module closes.
    61. * You can clean up manually, or you can use the two lines beneath, which will clean up everything for you but might be more resource-hogging.
    62. */
    63. plugin.playerMF.get(player).clearModule();
    64. plugin.debug("Clearing module " + getModuleName());
    65.  
    66. }
    67.  
    68. @Override
    69. public String getModuleName() {
    70. /*
    71. * Here you would normally return your module name, which may not contain spaces.
    72. */
    73. // TODO Auto-generated method stub
    74. return name;
    75. }
    76.  
    77. @Override
    78. public String getAuthor() {
    79. /*
    80. * Here, you return your name.
    81. */
    82. // TODO Auto-generated method stub
    83. return "Rahazan";
    84. }
    85.  
    86.  
    87.  
    88. /**
    89. * @return the name
    90. */
    91. public String getName() {
    92. return name;
    93. }
    94. /**
    95. * @param name the name to set
    96. */
    97. public void setName(String name) {
    98. this.name = name;
    99. }
    100.  
    101. }
    102.  
     
Thread Status:
Not open for further replies.

Share This Page