Esempio n. 1
0
 public void HandleMenu(ActionMenu menu)
 {
     if (InputUtils.MouseWithin(Bounds))
     {
         for (var i = 0; i < optionDisplays.Length; i++)
         {
             var factory = factories[i];
             if (factory != null)
             {
                 menu.Add(factory());
             }
         }
         menu.Add(new SwitchChatTabAction(this));
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Performs a frame update on the chat widget.
        /// </summary>
        public void Update()
        {
            var     updated = false;
            KeyCode key;

            while ((key = InputManager.Instance.GetNextKey()) != KeyCode.None)
            {
                var text = InputUtils.ToText(key);
                if (InputManager.Instance.Pressed[(int)KeyCode.LeftShift] ||
                    InputManager.Instance.Pressed[(int)KeyCode.RightShift])
                {
                    text = StringUtils.ToUpper(text);
                }

                if (key == KeyCode.Backspace)
                {
                    if (input.Length > 0)
                    {
                        input   = input.Substring(0, input.Length - 1);
                        updated = true;
                    }
                }

                if (key == KeyCode.Return)
                {
                    ProcessMessage();
                    input   = "";
                    updated = true;
                }

                if (text.Length > 0)
                {
                    input  += text;
                    updated = true;
                }
            }

            if (updated)
            {
                CreateInputTex();
            }
        }
Esempio n. 3
0
        public void Render()
        {
            var isHovered = false;

            if (!GameContext.Menu.Visible)
            {
                if (InputUtils.MouseWithin(Bounds))
                {
                    isHovered = true;
                }
            }

            var tex = button;

            if (isHovered)
            {
                tex = hovered;
            }

            GUI.DrawTexture(new Rect(Bounds.x, Bounds.y, tex.width, tex.height), tex);

            var hasDisplay = DisplayType < displayTextures.Length;

            if (hasDisplay)
            {
                var text = displayTextures[DisplayType];
                GUI.DrawTexture(new Rect(Bounds.x + (tex.width / 2) - (text.width / 2), Bounds.y + (tex.height / 2), text.width, text.height), text);
            }

            var y = Bounds.y;

            if (!hasDisplay)
            {
                y += (tex.height / 2) - (nameTexture.height / 2);
            }
            GUI.DrawTexture(new Rect(Bounds.x + (tex.width / 2) - (nameTexture.width / 2), y, nameTexture.width, nameTexture.height), nameTexture);
        }
Esempio n. 4
0
        public /* override */ void Update()
        {
            if (Input.GetMouseButtonDown(0))
            {
                if (InputUtils.MouseWithin(usernameBounds))
                {
                    selected = SelectedElement.Username;
                }
                else if (InputUtils.MouseWithin(passwordBounds))
                {
                    selected = SelectedElement.Password;
                }
                else if (InputUtils.MouseWithin(loginButtonBounds))
                {
                    AttemptLogin();
                }
                else
                {
                    selected = SelectedElement.None;
                }
            }

            while (InputManager.Instance.HasKeys())
            {
                var key  = InputManager.Instance.GetNextKey();
                var text = InputUtils.ToText(key);
                if (InputManager.Instance.Pressed[(int)KeyCode.LeftShift] ||
                    InputManager.Instance.Pressed[(int)KeyCode.RightShift])
                {
                    text = StringUtils.ToUpper(text);
                }

                switch (selected)
                {
                case SelectedElement.Username:
                    if (key == KeyCode.Backspace)
                    {
                        if (username.Length > 0)
                        {
                            username = username.Substring(0, username.Length - 1);
                            CreateUsernameTex();
                        }
                    }
                    if (text.Length > 0)
                    {
                        username += text;
                        CreateUsernameTex();
                    }
                    break;

                case SelectedElement.Password:
                    if (key == KeyCode.Backspace)
                    {
                        if (username.Length > 0)
                        {
                            password = password.Substring(0, password.Length - 1);
                            CreatePasswordTex();
                        }
                    }
                    if (text.Length > 0)
                    {
                        password += text;
                        CreatePasswordTex();
                    }

                    break;
                }
            }
        }
Esempio n. 5
0
        public void Draw(int x, int y, Rect rect)
        {
            var tmp = hovered;

            hovered = InputUtils.MouseWithin(new Rect(x, y, Config.Width, Config.Height));
            var hoverUpdated = (tmp != hovered);
            var mpos         = InputUtils.mousePosition;

            switch (Config.Type)
            {
            case 2:
            {
                var slot = 0;
                for (var slotY = 0; slotY < Config.Height; slotY++)
                {
                    for (var slotX = 0; slotX < Config.Width; slotX++)
                    {
                        int drawX  = x + slotX * (32 + Config.ItemMarginX);
                        int drawY  = y + slotY * (32 + Config.ItemMarginY);
                        var dragDx = 0;
                        var dragDy = 0;

                        if (slot < 20)
                        {
                            drawX += Config.ItemSlotX[slot];
                            drawY += Config.ItemSlotY[slot];
                        }

                        var back = GetSlotImage(slot);
                        if (Config.ItemIndices[slot] > 0)
                        {
                            var tex = GetSlotItemImage(slot);
                            if (tex != null)
                            {
                                if (GameContext.DragArea != 0 && GameContext.DragSlot == slot && GameContext.DragWidget == Config.Index)
                                {
                                    dragDx = (int)mpos.x - GameContext.DragStartX;
                                    dragDy = (int)mpos.y - GameContext.DragStartY;

                                    if (dragDx < 5 && dragDx > -5)
                                    {
                                        dragDx = 0;
                                    }

                                    if (dragDy < 5 && dragDy > -5)
                                    {
                                        dragDy = 0;
                                    }

                                    if (GameContext.DragCycle < 5)
                                    {
                                        dragDx = 0;
                                        dragDy = 0;
                                    }

                                    ResourceCache.ItemClickedMaterial.SetTexture("_MainTex", tex);
                                    Graphics.DrawTexture(new Rect(drawX + dragDx, drawY + dragDy, tex.width, tex.height), tex, ResourceCache.ItemClickedMaterial);
                                }
                                else
                                {
                                    GUI.DrawTexture(new Rect(drawX, drawY, tex.width, tex.height), tex);
                                }
                            }

                            if (Config.ItemAmounts[slot] != 1)
                            {
                                var stex = GetSlotAmountImage(slot);
                                if (stex != null)
                                {
                                    GUI.DrawTexture(new Rect(drawX + dragDx, drawY + dragDy, stex.width, stex.height), stex);
                                }
                            }
                        }
                        else if (back != null)
                        {
                            GUI.DrawTexture(new Rect(drawX, drawY, back.width, back.height), back);
                        }

                        slot++;
                    }
                }
                break;
            }

            case 4:
            {
                var bounds = new Rect(x, y, Config.Width, Config.Height);
                if (LineUpdateRequired() || hoverUpdated)
                {
                    UpdateTextLines(hovered);
                }

                foreach (var line in lines)
                {
                    GUI.BeginGroup(rect);
                    GUI.DrawTexture(new Rect(x + line.X - rect.x, y + line.Y - rect.y, line.Texture.width, line.Texture.height), line.Texture);
                    GUI.EndGroup();
                }
                break;
            }

            case 5:
            {
                Texture2D tex = null;
                if (IsEnabled())
                {
                    tex = GetImageEnabled();
                }
                else
                {
                    tex = GetImageDisabled();
                }

                if (tex != null)
                {
                    GUI.BeginGroup(rect);
                    GUI.DrawTexture(new Rect(x - rect.x, y - rect.y, tex.width, tex.height), tex);
                    GUI.EndGroup();
                }
                break;
            }
            }
        }