CSComponentClassSelector.ts 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //
  2. // Copyright (c) 2014-2016 THUNDERBEAST GAMES LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. import EditorUI = require("ui/EditorUI");
  23. class CSComponentClassSelector extends Atomic.UIWindow {
  24. constructor(editField: Atomic.UIEditField, component: AtomicNETScript.CSComponent) {
  25. super();
  26. var assemblyFile = component.componentFile;
  27. this.text = "Select Class: " + assemblyFile.name;
  28. this.rect = [0, 0, 400, 512];
  29. var mainLayout = new Atomic.UILayout();
  30. mainLayout.gravity = Atomic.UI_GRAVITY.UI_GRAVITY_ALL;
  31. mainLayout.layoutDistribution = Atomic.UI_LAYOUT_DISTRIBUTION.UI_LAYOUT_DISTRIBUTION_AVAILABLE;
  32. mainLayout.axis = Atomic.UI_AXIS.UI_AXIS_Y;
  33. this.contentRoot.addChild(mainLayout);
  34. // really want a grid container
  35. var scrollContainer = new Atomic.UIScrollContainer();
  36. scrollContainer.gravity = Atomic.UI_GRAVITY.UI_GRAVITY_ALL;
  37. scrollContainer.scrollMode = Atomic.UI_SCROLL_MODE.UI_SCROLL_MODE_Y_AUTO;
  38. scrollContainer.adaptContentSize = true;
  39. var scrollLayout = new Atomic.UILayout();
  40. scrollLayout.layoutPosition = Atomic.UI_LAYOUT_POSITION.UI_LAYOUT_POSITION_LEFT_TOP;
  41. scrollLayout.layoutDistributionPosition = Atomic.UI_LAYOUT_DISTRIBUTION_POSITION.UI_LAYOUT_DISTRIBUTION_POSITION_LEFT_TOP;
  42. scrollLayout.axis = Atomic.UI_AXIS.UI_AXIS_Y;
  43. scrollContainer.contentRoot.addChild(scrollLayout);
  44. var window = this;
  45. for (var i in assemblyFile.classNames) {
  46. var classname = assemblyFile.classNames[i];
  47. var button = new Atomic.UIButton();
  48. button.text = classname;
  49. button.onClick = function() {
  50. editField.text = this.text;
  51. component.componentClassName = this.text;
  52. window.close();
  53. }.bind(button);
  54. scrollLayout.addChild(button);
  55. }
  56. mainLayout.addChild(scrollContainer);
  57. EditorUI.getMainFrame().addChild(this);
  58. this.center();
  59. this.subscribeToEvent("WidgetEvent", (data) => this.handleWidgetEvent(data));
  60. }
  61. handleWidgetEvent(ev: Atomic.UIWidgetEvent) {
  62. if (ev.type == Atomic.UI_EVENT_TYPE.UI_EVENT_TYPE_CLICK) {
  63. if (ev.target != this && !this.isAncestorOf(ev.target)) {
  64. //this.close();
  65. }
  66. }
  67. return false;
  68. }
  69. }
  70. export = CSComponentClassSelector;