public GUIDropDown(Action<GUIObject> callback = null) : base() { _options = new List<GUIText>(); Action<GUIObject> initHelper = (obj) => { if (!isReady()) return; styleInit(); addChild(_mainBack); _mainBack.position(Vector2.zero); _mainBack.size(_selected.size()); _mainBack.size(size()); _mainBack.imageColor(Color.white); addChild(_selected); _selected.position(Vector2.zero); _selected.size(size()); _selected.font(_rm.font("Fonts/Sans")); _selected.fontSize(14); _selected.fontColor(Color.black); _selected.addListener(EventTriggerType.PointerEnter, (e) => { _selected.fontColor(Color.blue); _arrow.image(_rm.sprite("Textures/GUI/Buttons/DownArrowHover")); }); _selected.addListener(EventTriggerType.PointerExit, (e) => { _selected.fontColor(Color.black); _arrow.image(_rm.sprite("Textures/GUI/Buttons/DownArrow")); }); _selected.addListener(EventTriggerType.PointerClick, (e) => { if (_optionContainer.visible()) _optionContainer.hide(); else _optionContainer.show(); }); addChild(_arrow); _arrow.anchor(new Vector2(1.0f, 0.5f)); _arrow.position(new Vector2(- size().y / 2, 0.0f), POSITION_TYPE.RELATIVE); _arrow.size(new Vector2(size().y, size().y)); _arrow.image(_rm.sprite("Textures/GUI/Buttons/DownArrow")); _arrow.addListener(EventTriggerType.PointerClick, (e) => { Debug.Log("Showing container!"); _optionContainer.show(); }); addChild(_optionContainer); _optionContainer.anchor(new Vector2(0.5f, 0.0f)); _optionContainer.size(size()); _optionContainer.position(new Vector2(0, -_optionContainer.size().y / 2), POSITION_TYPE.RELATIVE); _optionContainer.imageColor(Color.white); _optionContainer.hide(); callback(this); }; _selected = new GUIText(initHelper); _arrow = new GUIImage(initHelper); _optionContainer = new GUIImage(initHelper); _mainBack = new GUIImage(initHelper); }
public GUIHorizontalDialog(Action<GUIObject> callback = null) : base((obj) => { GUIHorizontalDialog _this = obj as GUIHorizontalDialog; _this._contentWidth = _this.size().x; _this._scrollDelta = 0; _this._currentScroll = new Vector2(0, 0); }) { int readyCounter = 0; Action<GUIObject> initHelper = (obj) => { Debug.Log("readyCounter: " + readyCounter); if (readyCounter++ < 3) return; base.addChild(background); base.addChild(content); base.addChild(leftButton); base.addChild(rightButton); background.name("Background"); background.position(Vector2.zero); background.size(base.size()); background.imageColor(new Color(0, 0, 0, 0)); leftButton.name("Left Button"); leftButton.anchor(new Vector2(0.0f, 0.0f)); leftButton.position(new Vector2(ARROW_SIZE.x / 2, ARROW_SIZE.y), POSITION_TYPE.RELATIVE); leftButton.size(ARROW_SIZE); leftButton.setBaseBackground(_rm.sprite("Textures/GUI/Buttons/LeftArrow"), Color.white); leftButton.setOverBackground(_rm.sprite("Textures/GUI/Buttons/LeftArrowHover"), Color.white); leftButton.setDownBackground(_rm.sprite("Textures/GUI/Buttons/LeftArrowHover"), Color.white); rightButton.name("Right Button"); rightButton.anchor(new Vector2(1.0f, 0.0f)); rightButton.position(new Vector2(-ARROW_SIZE.x / 2, ARROW_SIZE.y), POSITION_TYPE.RELATIVE); rightButton.size(ARROW_SIZE); rightButton.setBaseBackground(_rm.sprite("Textures/GUI/Buttons/RightArrow"), Color.white); rightButton.setOverBackground(_rm.sprite("Textures/GUI/Buttons/RightArrowHover"), Color.white); rightButton.setDownBackground(_rm.sprite("Textures/GUI/Buttons/RightArrowHover"), Color.white); content.name("Content"); IEnumerator scrollUpdate = null; CoroutineManager CO = CoroutineManager.Get(); // Up Button =========================================================================================== rightButton.addListener(EventTriggerType.PointerDown, (e) => { _scrollDelta = -SCROLL_DELTA; if (scrollUpdate != null) return; scrollUpdate = this.scrollUpdate(); CO.StartCoroutine(scrollUpdate); }); rightButton.addListener(EventTriggerType.PointerUp, (e) => { _scrollDelta = 0; if (scrollUpdate == null) return; CO.StopCoroutine(scrollUpdate); scrollUpdate = null; }); rightButton.addListener(EventTriggerType.PointerExit, (e) => { _scrollDelta = 0; if (scrollUpdate == null) return; CO.StopCoroutine(scrollUpdate); scrollUpdate = null; }); // Down Button ========================================================================================= leftButton.addListener(EventTriggerType.PointerDown, (e) => { _scrollDelta = SCROLL_DELTA; if (scrollUpdate != null) return; scrollUpdate = this.scrollUpdate(); CO.StartCoroutine(scrollUpdate); }); leftButton.addListener(EventTriggerType.PointerUp, (e) => { _scrollDelta = 0; if (scrollUpdate == null) return; CO.StopCoroutine(scrollUpdate); scrollUpdate = null; }); leftButton.addListener(EventTriggerType.PointerExit, (e) => { _scrollDelta = 0; if (scrollUpdate == null) return; CO.StopCoroutine(scrollUpdate); scrollUpdate = null; }); if (callback != null) callback(this); }; content = new GUIObject(initHelper); background = new GUIImage(initHelper); leftButton = new GUIButton(initHelper); rightButton = new GUIButton(initHelper); }
public GUICheckbox(Action<GUIObject> callback = null) : base() { _state = STATE.UNCHECKED; Action<GUIObject> initHelper = (obj) => { if (!isReady()) return; size(new Vector2(100, 20)); addChild(_checkbox); addChild(_label); _checkbox.size(CHECKBOX_SIZE); _checkbox.anchor(new Vector2(0.0f, 0.5f)); _checkbox.position(new Vector2(CHECKBOX_SIZE.x / 2, 0), POSITION_TYPE.RELATIVE); _checkbox.imageColor(Color.white); _checkbox.addListener(EventTriggerType.PointerClick, (e) => { switch (_state) { case STATE.CHECKED: _checkbox.imageColor(Color.white); _state = STATE.UNCHECKED; break; case STATE.UNCHECKED: _checkbox.imageColor(Color.blue); _state = STATE.CHECKED; break; } if (onToggle != null) onToggle(_state); }); _checkbox.addListener(EventTriggerType.PointerEnter, (e) => { _checkbox.imageColor(new Color(0.3f, 0.3f, 1.0f)); }); _checkbox.addListener(EventTriggerType.PointerExit, (e) => { switch (_state) { case STATE.CHECKED: _checkbox.imageColor(Color.blue); break; case STATE.UNCHECKED: _checkbox.imageColor(Color.white); break; } }); _label.size(new Vector2(size().x - CHECKBOX_SIZE.x - PADDING, CHECKBOX_SIZE.y)); _label.anchor(new Vector2(1.0f, 0.5f)); _label.position(new Vector2(-_label.size().x / 2, 0), POSITION_TYPE.RELATIVE); _label.text("Checkbox"); _label.fontSize(14); _label.font(_rm.font("Fonts/Sans")); if (callback != null) callback(this); }; _checkbox = new GUIButton(initHelper); _label = new GUIText(initHelper); }