Home Reference Source Test

src/manager/UIManager.js

  1. import Manager from './Manager';
  2. import { TextureManager } from '../entry';
  3.  
  4. export class _UIManager extends Manager {
  5. constructor() {
  6. super();
  7.  
  8. this.defaultStyle = {
  9. buttonTexture: TextureManager.getTexture('uiButtonDefault'),
  10. buttonSubImage: 0,
  11. buttonHoverSubImage: 0,
  12. buttonPressedSubImage: 1,
  13. buttonReleasedSubImage: 1,
  14. fontTexture: TextureManager.getTexture('fontDefault'),
  15. textInputBoxTexture: TextureManager.getTexture('uiButtonDefault'),
  16. };
  17. this.styles = [];
  18. this.currentStyle = null;
  19. this.addStyle('Default', {});
  20. this.setCurrentStyle('Default');
  21. }
  22.  
  23. /**
  24. *
  25. *
  26. * @param {JSONObject} jsonStyleObject A JSON formatted object containing generic drawing data for styles.
  27. */
  28. addStyle(uiStyleName, jsonStyleObject) {
  29. this.styles[uiStyleName] = Object.assign({}, this.defaultStyle, jsonStyleObject);
  30. }
  31.  
  32. setCurrentStyle(uiStyleName) {
  33. this.currentStyle = this.getStyle(uiStyleName);
  34. }
  35.  
  36. getCurrentStyle() {
  37. return this.currentStyle;
  38. }
  39.  
  40. getStyle(styleName) {
  41. let style = this.styles[styleName];
  42.  
  43. if (style == null)
  44. throw 'UI style does not exist!';
  45.  
  46. return style;
  47. }
  48. }
  49.  
  50. /**
  51. * Singleton reference to the UIManager.
  52. */
  53. const UIManager = new _UIManager();
  54. export default UIManager;