|
| 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 | + |
| 23 | +import EditorUI = require("ui/EditorUI"); |
| 24 | + |
| 25 | +class CSComponentClassSelector extends Atomic.UIWindow { |
| 26 | + |
| 27 | + constructor(editField: Atomic.UIEditField, component: AtomicNETScript.CSComponent) { |
| 28 | + |
| 29 | + super(); |
| 30 | + |
| 31 | + var assemblyFile = component.assemblyFile; |
| 32 | + |
| 33 | + this.text = "Select Class: " + assemblyFile.name; |
| 34 | + |
| 35 | + this.rect = [0, 0, 400, 512]; |
| 36 | + |
| 37 | + var mainLayout = new Atomic.UILayout(); |
| 38 | + mainLayout.gravity = Atomic.UI_GRAVITY_ALL; |
| 39 | + mainLayout.layoutDistribution = Atomic.UI_LAYOUT_DISTRIBUTION_AVAILABLE; |
| 40 | + mainLayout.axis = Atomic.UI_AXIS_Y; |
| 41 | + this.contentRoot.addChild(mainLayout); |
| 42 | + |
| 43 | + // really want a grid container |
| 44 | + var scrollContainer = new Atomic.UIScrollContainer(); |
| 45 | + scrollContainer.gravity = Atomic.UI_GRAVITY_ALL; |
| 46 | + scrollContainer.scrollMode = Atomic.UI_SCROLL_MODE_Y_AUTO; |
| 47 | + scrollContainer.adaptContentSize = true; |
| 48 | + |
| 49 | + var scrollLayout = new Atomic.UILayout(); |
| 50 | + scrollLayout.layoutPosition = Atomic.UI_LAYOUT_POSITION_LEFT_TOP; |
| 51 | + scrollLayout.layoutDistributionPosition = Atomic.UI_LAYOUT_DISTRIBUTION_POSITION_LEFT_TOP; |
| 52 | + scrollLayout.axis = Atomic.UI_AXIS_Y; |
| 53 | + |
| 54 | + scrollContainer.contentRoot.addChild(scrollLayout); |
| 55 | + |
| 56 | + var window = this; |
| 57 | + |
| 58 | + for (var i in assemblyFile.classNames) { |
| 59 | + |
| 60 | + var classname = assemblyFile.classNames[i]; |
| 61 | + var button = new Atomic.UIButton(); |
| 62 | + button.text = classname; |
| 63 | + |
| 64 | + button.onClick = function() { |
| 65 | + editField.text = this.text; |
| 66 | + component.componentClassName = this.text; |
| 67 | + window.close(); |
| 68 | + }.bind(button); |
| 69 | + |
| 70 | + scrollLayout.addChild(button); |
| 71 | + } |
| 72 | + |
| 73 | + mainLayout.addChild(scrollContainer); |
| 74 | + |
| 75 | + EditorUI.getMainFrame().addChild(this); |
| 76 | + |
| 77 | + this.center(); |
| 78 | + |
| 79 | + this.subscribeToEvent("WidgetEvent", (data) => this.handleWidgetEvent(data)); |
| 80 | + |
| 81 | + } |
| 82 | + |
| 83 | + handleWidgetEvent(ev: Atomic.UIWidgetEvent) { |
| 84 | + |
| 85 | + if (ev.type == Atomic.UI_EVENT_TYPE_CLICK) { |
| 86 | + |
| 87 | + if (ev.target != this && !this.isAncestorOf(ev.target)) { |
| 88 | + |
| 89 | + //this.close(); |
| 90 | + |
| 91 | + } |
| 92 | + |
| 93 | + } |
| 94 | + |
| 95 | + return false; |
| 96 | + |
| 97 | + } |
| 98 | + |
| 99 | +} |
| 100 | + |
| 101 | +export = CSComponentClassSelector; |
0 commit comments