Esempio n. 1
0
        public Button(Vector2f position, string value)
        {
            Size = new Vector2f(Width, Height);
            Position = position - Size / 2.0f;
            Visible = true;
            this.value = value;

            mouseIn = false;

            myState = Game.PeekState();

            Input.MouseMove = args =>
            {
                mouseIn = BoundingBox.Contains(args.Position.X, args.Position.Y);
                return mouseIn;
            };

            Input.MouseButton[Mouse.Button.Left] = args =>
            {
                if (!mouseIn || !args.Pressed || !Clickable)
                    return false;

                if (OnClick != null && OnClick())
                    Assets.PlaySound("Click.wav");

                return true;
            };

            // Simulate mouse move
            Vector2i mousePosition = Mouse.GetPosition(Game.Window);
            Input.MouseMove(new MouseMoveInputArgs(mousePosition.X, mousePosition.Y));
        }
Esempio n. 2
0
 internal static bool IsActive(State state)
 {
     return states.IndexOf(state) == (states.Count - 1);
 }
Esempio n. 3
0
        public static void SetState(State state)
        {
            foreach (var s in states)
            {
                s.Leave();
            }

            states.Clear();
            PushState(state);
        }
Esempio n. 4
0
 public static void PushState(State state)
 {
     states.Add(state);
     state.Enter();
 }
Esempio n. 5
0
        internal static bool IsActive(State state)
        {
            if (state.IsOverlay)
                return StateStack.IndexOf(state) == (StateStack.Count - 1);

            return StateStack.FindLast(s => !s.IsOverlay) == state;
        }
Esempio n. 6
0
 /// <summary>
 /// Pushes a state onto the state stack.
 /// </summary>
 public static void PushState(State state)
 {
     StateStack.Add(state);
     state.Enter();
 }
Esempio n. 7
0
        /// <summary>
        /// Pops all states off the stack and pushes one onto it.
        /// </summary>
        public static void SetState(State state)
        {
            foreach (var s in StateStack)
            {
                s.Leave();
            }

            StateStack.Clear();
            PushState(state);
        }
Esempio n. 8
0
        public Textbox(string label)
        {
            OnReturn = null;
            Selected = false;
            mouseIn = false;
            cursorVisible = true;

            Value = "";

            this.label = label;

            myState = Game.PeekState();

            Size = new Vector2f((GameOptions.Width / 3.0f) * 2.0f - 64.0f, 48.0f);

            Timer.Every(0.65f, () =>
            {
                cursorVisible = !cursorVisible;
                return false;
            });

            Input.MouseMove = args =>
            {
                mouseIn = BoundingBox.Contains(args.Position.X, args.Position.Y);
                return mouseIn;
            };

            Input.MouseButton[Mouse.Button.Left] = args =>
            {
                if (!mouseIn || !args.Pressed)
                    return false;

                foreach (var textbox in Parent.Entities.OfType<Textbox>())
                    textbox.Selected = false;

                Selected = !Selected;

                return true;
            };

            Input.Text = args =>
            {
                if (!Selected || !myState.Equals(Game.PeekState()))
                    return false;

                // 0x16 is Control + V
                if (args.Text[0] == 0x16)
                {
                    Value += GameUtility.GetClipboardText();
                    if (Value.Length >= 36)
                        Value = Value.Remove(36, Value.Length - 36);

                    return true;
                }

                if (args.Text == "\t")
                {
                    foreach (var textbox in Parent.Entities.OfType<Textbox>())
                        textbox.Selected = !textbox.Selected;

                    return true;
                }

                if (args.Text == "\b")
                {
                    if (Value.Length == 0)
                        return true;

                    Value = Value.Remove(Value.Length - 1);
                    return true;
                }

                if (args.Text == "\r")
                {
                    if (OnReturn != null && Selected)
                    {
                        Assets.PlaySound("Click.wav");
                        if (OnReturn(Value))
                            Value = "";
                    }

                    return true;
                }

                if (!Char.IsControl(args.Text[0]) && Value.Length < 36)
                    Value += Regex.Replace(args.Text, "[\x01-\x1F]", "");

                return true;
            };
        }