Beispiel #1
0
        private void UpdateCamera()
        {
            var state = Mouse.GetState();

            if (state.ScrollWheelValue - laststate < 0)
            {
                cam.Zoom += (state.ScrollWheelValue - laststate) * 0.001f * cam.Zoom;
            }
            else
            if (state.ScrollWheelValue - laststate > 0)
            {
                cam.Zoom += (state.ScrollWheelValue - laststate) * 0.001f * cam.Zoom;
            }
            laststate = state.ScrollWheelValue;

            if (KeyBindings.CheckKeyPressed("KEY_CAMMOVE_UP"))
            {
                cam.Position -= new Vector2(0, 10f / cam.Zoom);
            }
            else
            if (KeyBindings.CheckKeyPressed("KEY_CAMMOVE_DOWN"))
            {
                cam.Position += new Vector2(0, 10f / cam.Zoom);
            }

            if (KeyBindings.CheckKeyPressed("KEY_CAMMOVE_LEFT"))
            {
                cam.Position -= new Vector2(10f / cam.Zoom, 0);
            }
            else
            if (KeyBindings.CheckKeyPressed("KEY_CAMMOVE_RIGHT"))
            {
                cam.Position += new Vector2(10f / cam.Zoom, 0);
            }

            var maprectoffs = Map.GetMapRectangle(1);
            var maprect     = Map.GetMapRectangle(0);
            var FirstVect   = new Vector2(maprectoffs.X, maprectoffs.Y);
            var LastVect    = new Vector2(maprectoffs.X + maprectoffs.Width, maprectoffs.Y + maprectoffs.Height);
            var LastMapVect = new Vector2(maprect.X + maprect.Width, maprect.Y + maprect.Height);

            if (cam.Position.X < FirstVect.X)
            {
                cam.Position = new Vector2(FirstVect.X, cam.Position.Y);
            }
            if (cam.Position.Y < FirstVect.Y)
            {
                cam.Position = new Vector2(cam.Position.X, FirstVect.Y);
            }

            if (cam.Position.X + cam.ScreenRes.X / cam.Zoom > LastVect.X)
            {
                cam.Position = new Vector2(LastVect.X - cam.ScreenRes.X / cam.Zoom, cam.Position.Y);
            }
            if (cam.Position.Y + cam.ScreenRes.Y / cam.Zoom > LastVect.Y)
            {
                cam.Position = new Vector2(cam.Position.X, LastVect.Y - cam.ScreenRes.Y / cam.Zoom);
            }
        }
Beispiel #2
0
        public void Update()
        {
            var Upd = base.Update();

            if (Visible)
            {
                if (MouseControl.IsLeftBtnClicked)
                {
                    if (Upd == ButtonStates.CLICKED)
                    {
                        if (!Focused)
                        {
                            Focused    = true;
                            base.Text += "|";
                        }
                    }
                    else
                    if (Focused)
                    {
                        Focused   = false;
                        base.Text = base.Text.Remove(base.Text.Length - 1);
                    }
                }

                if (Focused)
                {
                    var    IsKeyFinded = false;
                    string Symbol      = "";

                    if (RealText.Length < MaxLength)
                    {
                        for (var i = 48; i < 58; i++)
                        {
                            if (KeyBindings.CheckKeyReleased((Keys)i) == true)
                            {
                                IsKeyFinded = true;
                                Symbol      = char.ConvertFromUtf32(i);
                                break;
                            }
                        }
                        if (!IsKeyFinded)
                        {
                            for (var i = 65; i < 91; i++)
                            {
                                if (KeyBindings.CheckKeyReleased((Keys)i) == true)
                                {
                                    IsKeyFinded = true;
                                    Symbol      = char.ConvertFromUtf32(i);
                                    break;
                                }
                            }
                        }
                        if (!IsKeyFinded)
                        {
                            for (var i = 96; i < 106; i++)
                            {
                                if (KeyBindings.CheckKeyReleased((Keys)i) == true)
                                {
                                    IsKeyFinded = true;
                                    Symbol      = char.ConvertFromUtf32(i - 48);
                                    break;
                                }
                            }
                        }
                        if (IsKeyFinded)
                        {
                            base.Text = base.Text.Remove(base.Text.Length - 1);
                            if (!(KeyBindings.CheckKeyPressed(Keys.LeftShift) || KeyBindings.CheckKeyPressed(Keys.RightShift)))
                            {
                                Symbol = Symbol.ToLower();
                            }
                            RealText += Symbol;
                            if (IsMasked)
                            {
                                base.Text += "*";
                            }
                            else
                            {
                                base.Text += Symbol;
                            }
                            base.Text += "|";
                        }
                    }

                    if (KeyBindings.CheckKeyReleased(Keys.Back))
                    {
                        base.Text = base.Text.Remove(base.Text.Length - 1);
                        if (base.Text.Length > 0)
                        {
                            base.Text = base.Text.Remove(base.Text.Length - 1);
                        }
                        if (RealText.Length > 0)
                        {
                            RealText = RealText.Remove(RealText.Length - 1);
                        }
                        base.Text += "|";
                    }
                }
            }
        }