Example #1
0
 public Button(Position button_position, int button_width, int button_height, string asset_path, OnClickDelegate click)
 {
     path        = asset_path;
     area        = new Rectangle(button_position.X, button_position.Y, button_width, button_height);
     backgrounds = new Texture2D[3];
     Click       = click;
 }
 /// <summary>
 /// Removes an OnClick listener from the delegate.
 /// </summary>
 /// <param name="callback"></param>
 public void RemoveOnClickDelegate(OnClickDelegate callback)
 {
     if (callback != null)
     {
         onClickDelegate -= callback;
     }
 }
Example #3
0
 public UIButton(OnClickDelegate onClick, OnHoverDelegate onHover, Rectangle drawingRectangle, Texture2D background, int elevation, SpriteFont font, Color color, Color _hoverColor, TextAlign align) : base(drawingRectangle, background, elevation, font, color, align)
 {
     OnClick   += onClick;
     OnHover   += onHover;
     hoverColor = _hoverColor;
     idleColor  = color;
 }
Example #4
0
 public Button(Vector2 position, string text, OnClickDelegate onClick) : base(position)
 {
     // Load the sprite and set the initial values based on the passed arguments
     Sprite  = new Sprite("Menus/button", 2, 1);
     OnClick = onClick;
     Text    = text;
 }
Example #5
0
 public UIElementData(string gameobject_name, string button_text, OnClickDelegate on_click)
 {
     GameObject_Name = gameobject_name;
     Text            = button_text;
     On_Click        = on_click;
     Sprite_Name     = null;
     Sprite_Type     = SpriteManager.SpriteType.UI;
 }
 /// <summary>
 /// Add an OnClick listener to recieve element data.
 /// </summary>
 /// <param name="callback"></param>
 public void AddOnClickDelegate(OnClickDelegate callback)
 {
     if (callback != null)
     {
         // This ensures we never have duplicates, and it does nothing if the callback is not already in the delegate invocation list.
         onClickDelegate -= callback;
         onClickDelegate += callback;
     }
 }
        public static void OnRightClick(this Button button, OnClickDelegate callback)
        {
            TooltipTrigger trig = button.gameObject.GetComponent <TooltipTrigger>();

            if (trig == null)
            {
                trig = button.gameObject.AddComponent <TooltipTrigger>();
            }
            trig.AddRightClick(callback);
        }
Example #8
0
 public void CreateServerItem(string ip, string port, string name, string map, string version, string players, OnClickDelegate newCallback)
 {
     ServerName.text    = name;
     ServerMap.text     = map;
     ServerVersion.text = version;
     ServerPlayers.text = players;
     this.port          = port;
     ipAddress          = ip;
     onClickCallback    = newCallback;
 }
Example #9
0
 public static void RemoveClick(CUIHandle[] array, OnClickDelegate OnDelegate)
 {
     if (array == null)
     {
         return;
     }
     foreach (CUIHandle handle in array)
     {
         handle.OnCClick += OnDelegate;
     }
 }
Example #10
0
 public void OnClick(OnClickDelegate <T> onClick)
 {
     if (View is Button)
     {
         (View as Button).onClick.AddListener(() => onClick(View));
     }
     else
     {
         throw new IllegalOperationException("set click event on not button exception");
     }
 }
Example #11
0
        public ClickableText(Vector2 position, string name, string text, OnClickDelegate onClick) : base(position)
        {
            // Set the object's values for the correct text and method to call upon click
            Text    = text;
            OnClick = onClick;

            // Get the values to correctly display the text and when it is highlighted
            Vector2 textDimensions = Game1.FontManager.DefaultFont.MeasureString(Text);

            boundries = new Rectangle((int)position.X - (int)textDimensions.X / 2, (int)position.Y - (int)textDimensions.Y / 2, (int)textDimensions.X, (int)textDimensions.Y);
        }
        /// <summary>
        /// Called when this element is destroyed
        /// </summary>
        public virtual void OnDestroy()
        {
            if (onClickDelegate != null)
            {
                Delegate[] invocationList = onClickDelegate.GetInvocationList();

                for (int i = 0; i < invocationList.Length; ++i)
                {
                    invocationList[i] = null;
                }
            }
            onClickDelegate = null;
        }
Example #13
0
        private void CreateCell(ButtonCell cell, string caption, Color?font = null, OnClickDelegate onClick = null)
        {
            if (cell != null)
            {
                return;
            }
            Color fc = font == null ? Color.Black : (Color)font;

            cell = new ButtonCell()
            {
                Caption = caption, DefaultFontColor = fc
            };
            cell.OnClick += onClick;
        }
Example #14
0
    /// <summary>
    /// 添加点击事件
    /// </summary>
    /// <param name="go"></param>
    /// <param name="onClickFunc"></param>
    public void AddOnClickEvent(GameObject go, OnClickDelegate onClickFunc)
    {
        if (go == null)
        {
            return;
        }

        if (m_dicOnClickDelegate.ContainsKey(go))
        {
            m_dicOnClickDelegate[go] = onClickFunc;
        }
        else
        {
            m_dicOnClickDelegate.Add(go, onClickFunc);
        }
    }
Example #15
0
        private void CreateCell(ref TextCell cell, object value, string binding = "", int bindingIndex = -1, Color?back = null, Color?font = null, OnMouseEnterDelegate onMouseEnter = null, OnClickDelegate onClick = null, bool enable = false, string format = "", object tag = null)
        {
            if (cell != null)
            {
                return;
            }
            Color bc = back == null ? Color.White : (Color)back;
            Color fc = font == null ? Color.Black : (Color)font;

            cell = new TextCell(value, value.GetType())
            {
                DefaultBackColor = bc, DefaultFontColor = fc, Enable = enable, HasBorder = true, Border = Border, Format = format, FontName = CellBase.FontName.Verdana, FontSize = 8, Tag = tag
            };
            if (!string.IsNullOrEmpty(binding))
            {
                cell.SetDataBinding(this.GetType(), binding, this, bindingIndex);
            }
            cell.OnClick      += onClick;
            cell.OnMouseEnter += onMouseEnter;
        }
 public AlertDialogClickListener(OnClickDelegate clickDelegate) : base("android.content.DialogInterface$OnClickListener")
 {
     this.onClickDelegate = clickDelegate;
 }
Example #17
0
 protected override void onClickCall()
 {
     OnClickDelegate?.Invoke(this, card);
 }
Example #18
0
        public CommandBindingWrapper(UIElement uiElement, Key key, CanExecuteDelegate canExecute, OnClickDelegate onClick)
        {
            var keyGesture = new KeyGesture(key, ModifierKeys.Control);
            var keyBinding = new KeyBinding(_command, keyGesture);

            _keyBinding = keyBinding;
            var commandBinding = new CommandBinding();

            commandBinding.Command     = _command;
            commandBinding.CanExecute += (obj, args) => { args.CanExecute = canExecute(); };
            commandBinding.Executed   += (obj, args) => onClick();
            _commandBinding            = commandBinding;
            uiElement.CommandBindings.Add(_commandBinding);
            uiElement.InputBindings.Add(_keyBinding);
        }
Example #19
0
        public CommandBindingWrapper(UIElement uiElement, CanExecuteDelegate canExecute, OnClickDelegate onClick)
        {
            var commandBinding = new CommandBinding();

            commandBinding.Command     = _command;
            commandBinding.CanExecute += (obj, args) => { args.CanExecute = canExecute(); };
            commandBinding.Executed   += (obj, args) => onClick();
            _commandBinding            = commandBinding;
            uiElement.CommandBindings.Add(_commandBinding);
        }
Example #20
0
 void Start()
 {
     StatBlockDelegate = null;
 }
Example #21
0
 public void Show(string msgStr, string buttenStr, OnClickDelegate onClick)
 {
     this.onClick = onClick;
     Show(msgStr, buttenStr);
 }
Example #22
0
        public void Show(
            string content,
            bool enableOkBtn                 = true,
            string okBtnContent              = "确定",
            OnClickDelegate onOkListener     = null,
            bool enableCancelbtn             = false,
            string cancelBtnContent          = null,
            OnClickDelegate onCancelListener = null,
            bool enableBg       = true,
            bool closeOnBg      = false,
            bool enableCloseBtn = true
            )
        {
            // 设置内容。
            if (ContentTxt)
            {
                if (!ContentTxt.gameObject.activeSelf)
                {
                    ContentTxt.gameObject.SetActive(true);
                }

                ContentTxt.text = content;
            }

            if (Bg)
            {
                if (Bg.gameObject.activeSelf != enableBg)
                {
                    Bg.gameObject.SetActive(enableBg);
                }
            }

            // 背景按钮。
            if (BgBtn)
            {
                BgBtn.interactable = closeOnBg;
            }

            // 关闭按钮。
            if (CloseBtn && CloseBtn.gameObject.activeSelf != enableCloseBtn)
            {
                CloseBtn.gameObject.SetActive(enableCloseBtn);
            }

            // 确认按钮。
            if (OkBtn)
            {
                if (OkBtn.gameObject.activeSelf != enableOkBtn)
                {
                    OkBtn.gameObject.SetActive(enableOkBtn);
                }
            }

            if (enableOkBtn && OkBtnTxt)
            {
                OkBtnTxt.text = okBtnContent;
            }

            // 取消按钮。
            if (CancelBtn)
            {
                if (CancelBtn.gameObject.activeSelf != enableCancelbtn)
                {
                    CancelBtn.gameObject.SetActive(enableCancelbtn);
                }
            }

            if (enableCancelbtn && CancelBtnTxt)
            {
                CancelBtnTxt.text = cancelBtnContent;
            }

            // 确认按钮和取消按钮的容器。
            if (BtnContainer)
            {
                var enableContainer = enableOkBtn || enableCancelbtn;
                if (BtnContainer.activeSelf != enableContainer)
                {
                    BtnContainer.SetActive(enableContainer);
                }
            }

            _onOkListener     = onOkListener;
            _onCancelListener = onCancelListener;

            // 显示对话框。
            ResetAllTweeners();
            if (Frame)
            {
                // 显示对话框的时候,是应该必须显示内容的。
                if (!Frame.gameObject.activeSelf)
                {
                    Frame.gameObject.SetActive(true);
                }

                Frame.localScale = new Vector3(0, 0, 1);
                _frameTweener    = Frame
                                   .DOScale(new Vector3(1, 1, 1), ShowAnimationTime)
                                   .SetEase(Ease.OutBack, 1.1f);
            }

            if (Bg && Bg.gameObject.activeSelf)
            {
                _bgTweener = Bg.DOFade(150f / 255f, ShowAnimationTime);
            }
        }
Example #23
0
 private void CreateCell(ref CHeaderCell cell, string caption, OnDoubleClickDelegate onDoubleClick = null, OnClickDelegate onClick = null, Color?bc = null, Color?fc = null, int rowspan = 1, int colspan = 1)
 {
     if (cell != null)
     {
         return;
     }
     cell = new CHeaderCell()
     {
         Caption = caption, RowSpan = rowspan, ColumnSpan = colspan, DefaultBackColor = Color.LightGray, DefaultFontColor = Color.Black, FontSize = 8
     };
     if (bc != null)
     {
         cell.BackColor = (Color)bc;
     }
     if (fc != null)
     {
         cell.FontColor = (Color)fc;
     }
     cell.OnDoubleClick += onDoubleClick;
     cell.OnClick       += onClick;
 }
Example #24
0
    /*
     * void OnDrag (Vector2 delta){}
     * void OnScroll (float delta){}
     * void OnClick (){}
     * void OnDoubleClick () {}
     * void OnBecameVisible() {} //OnBecameVisible is called when the renderer became visible by any camera.
     * void OnBecameInvisible() {} //OnBecameInvisible is called when the renderer is no longer visible by any camera.
     * void OnLevelWasLoaded(int level) {}
     * void OnEnable() {}
     * void OnDisable() {}
     * void OnDestroy() {}
     */
    #endregion

    #region Event Listener & Đăng ký các Event

    public static void AddClick(CUIHandle handle, OnClickDelegate OnDelegate)
    {
        handle.OnCClick += OnDelegate;
    }
Example #25
0
 public static void RemoveClick(CUIHandle handle, OnClickDelegate OnDelegate)
 {
     handle.OnCClick -= OnDelegate;
 }
Example #26
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="OnClick">The method that's called when the entity is clicked.</param>
 public Clickable(OnClickDelegate OnClick)
 {
     this.OnClick = OnClick;
     name         = "Clickable";
 }
        public void AddServerItem(string ip, string port, string name, string map, string version, string players, OnClickDelegate clickFunction)
        {
            GameObject    newItem = GameObject.Instantiate(serverListItem, serverViewport.transform);
            RectTransform trans   = newItem.GetComponent <RectTransform>();

            ServerListItem listItem = newItem.GetComponent <ServerListItem>();

            if (listItem != null)
            {
                listItem.CreateServerItem(ip, port, name, map, version, players, clickFunction);
            }

            itemRealSize = new Vector2(trans.rect.width, trans.rect.height);

            int numChildren = 0;

            foreach (Transform t in serverListBox.transform)
            {
                if (t != serverListBox.transform)
                {
                    numChildren++;
                }
            }

            trans.anchorMin = new Vector2(trans.anchorMin.x, 1f);
            trans.anchorMax = new Vector2(trans.anchorMax.x, 1f);

            serverListBox.GetComponent <RectTransform>().SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, itemRealSize.y * (numChildren + 1));

            serverItems.Add(trans);

            newItem.transform.SetParent(serverListBox.transform);

            trans.offsetMax = new Vector2(trans.offsetMax.x, -itemRealSize.y * numChildren);

            foreach (RectTransform tran in serverItems)
            {
                tran.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, itemRealSize.y);
            }
        }
Example #28
0
    public Text CannonText;                             //Reference to text showing cannon count of ship

    void Start()
    {
        StatBlockDelegate = null;
    }