indicator.adoc 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. = indicator
  2. :revnumber: 2.0
  3. :revdate: 2020/07/23
  4. == Indicator Class
  5. An indicator is a highly customizable progress bar, which can be used showing/displaying player stats, etc
  6. The Indicator uses the 3 standard constructors as shown in the xref:gui/tonegodgui/quickstart.adoc[Quick Start Guide] with the addition of one extra parameter:
  7. * Orientation appended to the end of the param list for each
  8. *Features include:*
  9. * Clipping + an alpha mask to create any shaped indicator you would like
  10. * Display the indicator in any color you choose.
  11. * Image based indicators in place of color+clipping
  12. * An overlay image for transparent indicator containers
  13. === Constructor example:
  14. [source,java]
  15. ----
  16. /**
  17. * Parameters:
  18. * Screen screen
  19. * String UID
  20. * Vector2f position
  21. * Orientation orientation
  22. */
  23. Indicator ind = new Indicator(
  24. screen,
  25. "SomeID",
  26. new Vector2f(10,10),
  27. Orientation.VERTICAL
  28. );
  29. ----
  30. === Changing & Reshaping the Indicator
  31. [source,java]
  32. ----
  33. // Using an image in place of a colored indicator
  34. ind.setBaseImage(String imgPath);
  35. // Use a clipped image for the indicator
  36. ind.setIndicatorImage(String imgPath);
  37. // Changing the color of the indicator or colorize the image-based indicator
  38. ind.setIndicatorColor(ColorRGBA indicatorColor);
  39. // Add padding (margins) to the indicator portion of the indicator
  40. ind.setIndicatorPadding(Vector4f padding);
  41. // Reshape the indicator !IMPORTANT! setIndicatorAlphaMap is now @Deprecated, use this instead:
  42. ind.setAlphaMap(String alphaMapPath);
  43. ----
  44. === Methods specific to the Indicator class
  45. [source,java]
  46. ----
  47. // Get the indicator's orientation
  48. ind.getOrientation();
  49. // Adjust value ranges
  50. ind.setMaxValue(float maxValue);
  51. ind.setCurrentValue(float currentValue);
  52. // Get current info
  53. ind.getCurrentPercentage();
  54. ind.getCurrentValue();
  55. ind.getMaxValue();
  56. ind.getTextDisplayElement(); // Return the text element for formatting purposes
  57. ind.setDisplayValues(); // Display value in format: current/max or 10/100
  58. ind.setDisplayPercentage(); // Displays percentage: 82% etc
  59. ind.setHideText(); // removes display text (default)
  60. ----
  61. == Indicator Examples
  62. Cut & Paste the following code into the simpleInitApp method of a new JME project. Use the slider to adjust the indicator.
  63. [source,java]
  64. ----
  65. flyCam.setDragToRotate(true);
  66. inputManager.setCursorVisible(true);
  67. screen = new Screen(this);
  68. guiNode.addControl(screen);
  69. final ColorRGBA color = new ColorRGBA();
  70. final Indicator ind = new Indicator(
  71. screen,
  72. new Vector2f(50,50),
  73. new Vector2f(300,30),
  74. Orientation.HORIZONTAL
  75. ) {
  76. @Override
  77. public void onChange(float currentValue, float currentPercentage) { }
  78. };
  79. ind.setBaseImage(screen.getStyle("Window").getString("defaultImg"));
  80. //ind.setIndicatorImage(screen.getStyle("Window").getString("defaultImg"));
  81. ind.setIndicatorColor(ColorRGBA.randomColor());
  82. ind.setAlphaMap(screen.getStyle("Indicator").getString("alphaImg"));
  83. ind.setIndicatorPadding(new Vector4f(7,7,7,7));
  84. ind.setMaxValue(100);
  85. ind.setDisplayPercentage();
  86. screen.addElement(ind);
  87. Slider slider = new Slider(screen, new Vector2f(100,100), Orientation.HORIZONTAL, true) {
  88. @Override
  89. public void onChange(int selectedIndex, Object value) {
  90. float blend = selectedIndex*0.01f;
  91. color.interpolate(ColorRGBA.Red, ColorRGBA.Green, blend);
  92. ind.setIndicatorColor(color);
  93. ind.setCurrentValue((Integer)value);
  94. }
  95. };
  96. screen.addElement(slider);
  97. ----
  98. image:gui/tonegodgui/indicatorexample.png[indicatorexample.png,width="",height=""]