public override void Initialize()
 {
     _graphicsDevice = Game.GraphicsDevice;
     _mouse          = GetComponent <MouseComponent>();
     _keyboard       = GetComponent <KeyboardComponent>();
     base.Initialize();
 }
Exemple #2
0
        protected override void InitInput()
        {
            var mouse = new MouseComponent(this, ResolutionBuddy.Resolution.ScreenToGameCoord);

            //add the input helper for menus
            var input = new MouseInputHandler(this);
        }
        public void Update(MouseComponent mouse, KeyboardComponent keyboard)
        {
            if (!mouse.IsMouseOwner(this))
            {
                return;
            }

            var deltaMouseX     = mouse.DeltaPosition().X;
            var deltaMouseY     = mouse.DeltaPosition().Y;
            var deltaMouseWheel = mouse.DeletaScrollWheel();

            if (keyboard.IsKeyReleased(Keys.F4))
            {
                Zoom    = 10;
                _lookAt = Vector3.Zero;
            }

            var ownsMouse = mouse.MouseOwner;

            if (keyboard.IsKeyDown(Keys.LeftAlt))
            {
                mouse.MouseOwner = this;
            }
            else
            {
                if (ownsMouse == this)
                {
                    mouse.MouseOwner = null;
                    mouse.ClearStates();
                    return;
                }
            }


            if (keyboard.IsKeyDown(Keys.LeftAlt))
            {
                mouse.MouseOwner = this;
                if (mouse.IsMouseButtonDown(MouseButton.Left))
                {
                    Yaw   += deltaMouseX * 0.01f;
                    Pitch += deltaMouseY * 0.01f;
                }
                if (mouse.IsMouseButtonDown(MouseButton.Right))
                {
                    MoveCameraRight(deltaMouseX * 0.01f * Zoom * .1f);
                    MoveCameraUp(-deltaMouseY * 0.01f * Zoom * .1f);
                }
                else if (deltaMouseWheel != 0)
                {
                    if (Math.Abs(deltaMouseWheel) > 250)   // Weird bug, sometimes this value is very large, probably related to state clearing. Temp fix
                    {
                        deltaMouseWheel = 250 * Math.Sign(deltaMouseWheel);
                    }

                    var oldZoom = (Zoom / 10);
                    Zoom += (deltaMouseWheel * 0.005f) * oldZoom;
                    //_logger.Here().Information($"Setting zoom {Zoom} - {deltaMouseWheel} - {oldZoom}");
                }
            }
        }
Exemple #4
0
        public TrueCraftGame(MultiplayerClient client, IPEndPoint endPoint)
        {
            Window.Title          = "TrueCraft";
            Content.RootDirectory = "Content";
            Graphics = new GraphicsDeviceManager(this);
            Graphics.SynchronizeWithVerticalRetrace = false;
            Graphics.IsFullScreen              = UserSettings.Local.IsFullscreen;
            Graphics.PreferredBackBufferWidth  = UserSettings.Local.WindowResolution.Width;
            Graphics.PreferredBackBufferHeight = UserSettings.Local.WindowResolution.Height;
            Client                   = client;
            EndPoint                 = endPoint;
            NextPhysicsUpdate        = DateTime.MinValue;
            ChunkMeshes              = new List <Mesh>();
            IncomingChunks           = new ConcurrentBag <Mesh>();
            PendingMainThreadActions = new ConcurrentBag <Action>();
            MouseCaptured            = true;

            var keyboardComponent = new KeyboardComponent(this);

            KeyboardComponent = keyboardComponent;
            Components.Add(keyboardComponent);

            var mouseComponent = new MouseComponent(this);

            MouseComponent = mouseComponent;
            Components.Add(mouseComponent);
        }
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            var input = new MouseComponent(this, EchoCoord);

            var debug = new DebugInputComponent(this, Identity);

            base.Initialize();
        }
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            var input = new MouseComponent(this);

            var debug = new DebugInputComponent(this);

            base.Initialize();
        }
Exemple #7
0
        public void Update(GameTime gameTime)
        {
            int delta = MouseComponent.ScrolledInBounds(_historyField.Bounds);

            HistoryRenderer.ScrollDelta += (int)(delta / gameTime.ElapsedGameTime.TotalMilliseconds) * ScrollSpeed;

            UpdateInputText();
        }
Exemple #8
0
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                KeyboardComponent.Dispose();
                MouseComponent.Dispose();
            }

            base.Dispose(disposing);
        }
Exemple #9
0
        public void updateActionStates(MouseComponent mouseComp)
        {
            MouseState newState = mouseComp.NewState;
            MouseState oldState = mouseComp.OldState;

            // LeftButton
            UpdateMouseButton(mouseComp, newState.LeftButton, oldState.LeftButton, "LeftButton");
            // MiddleButton
            UpdateMouseButton(mouseComp, newState.MiddleButton, oldState.MiddleButton, "MiddleButton");
            // RightButton
            UpdateMouseButton(mouseComp, newState.RightButton, oldState.RightButton, "RightButton");
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="gameTime"></param>
        public void update(GameTime gameTime)
        {
            UpdateStates();

            List <int> entities = ComponentManager.Instance.GetAllEntitiesWithComponentType <MouseComponent>();

            if (entities != null)
            {
                foreach (var item in entities)
                {
                    MouseComponent mouse = ComponentManager.Instance.GetEntityComponent <MouseComponent>(item);
                    UpdateActionStates(mouse);
                }
            }
        }
Exemple #11
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            //Setup for reolution independent rendering
            Resolution.SetDesiredResolution(1280, 720);
            Resolution.SetScreenResolution(1024, 768, false);

            //Create the input things for listening for mouse clicks
            MouseInput = new MouseComponent(this, Resolution.ScreenToGameCoord);
            var debug = new DebugInputComponent(this, Resolution.TransformationMatrix);

            debug.DrawOrder = 100;

            //Create the water ripple component
            _water           = new WaterRippleComponent(this);
            _water.DrawOrder = 101;

            base.Initialize();
        }
Exemple #12
0
 private void UpdateMouseButton(MouseComponent mouseComp, ButtonState newState, ButtonState oldState, string button)
 {
     if (newState == ButtonState.Pressed && oldState != ButtonState.Pressed)
     {
         mouseComp.actionStates[button] = BUTTON_STATE.PRESSED;
     }
     else if (newState == ButtonState.Pressed && oldState == ButtonState.Pressed)
     {
         mouseComp.actionStates[button] = BUTTON_STATE.HELD;
     }
     else if (newState != ButtonState.Pressed && oldState == ButtonState.Pressed)
     {
         mouseComp.actionStates[button] = BUTTON_STATE.RELEASED;
     }
     else
     {
         mouseComp.actionStates[button] = BUTTON_STATE.NOT_PRESSED;
     }
 }
 /// <summary>
 /// updates state of a specific mousebutton
 /// </summary>
 /// <param name="mouse"></param>
 /// <param name="curState"></param>
 /// <param name="prevState"></param>
 /// <param name="button"></param>
 private void updateBtn(MouseComponent mouse, ButtonState curState, ButtonState prevState, string button)
 {
     if (curState == ButtonState.Pressed && prevState != ButtonState.Pressed)
     {
         mouse.mouseActionState[button] = ButtonStates.Pressed;
     }
     else if (curState == ButtonState.Pressed && prevState == ButtonState.Pressed)
     {
         mouse.mouseActionState[button] = ButtonStates.Hold;
     }
     else if (curState != ButtonState.Pressed && prevState == ButtonState.Pressed)
     {
         mouse.mouseActionState[button] = ButtonStates.Released;
     }
     else
     {
         mouse.mouseActionState[button] = ButtonStates.Not_Pressed;
     }
 }
        public override void Initialize()
        {
            UpdateOrder = (int)ComponentUpdateOrderEnum.SelectionComponent;
            DrawOrder   = (int)ComponentDrawOrderEnum.SelectionComponent;

            _mouseComponent    = GetComponent <MouseComponent>();
            _keyboardComponent = GetComponent <KeyboardComponent>();
            _camera            = GetComponent <ArcBallCamera>();
            _sceneManger       = GetComponent <SceneManager>();
            _selectionManager  = GetComponent <SelectionManager>();
            _commandManager    = GetComponent <CommandExecutor>();

            _spriteBatch = new SpriteBatch(GraphicsDevice);
            _textTexture = new Texture2D(GraphicsDevice, 1, 1);
            _textTexture.SetData(new Color[1 * 1] {
                Color.White
            });

            base.Initialize();
        }
        public override void Initialize()
        {
            _commandManager   = GetComponent <CommandExecutor>();
            _selectionManager = GetComponent <SelectionManager>();
            _keyboard         = GetComponent <KeyboardComponent>();
            _mouse            = GetComponent <MouseComponent>();
            var camera         = GetComponent <ArcBallCamera>();
            var resourceLibary = GetComponent <ResourceLibary>();

            _selectionManager.SelectionChanged += OnSelectionChanged;

            var font = resourceLibary.Content.Load <SpriteFont>("Fonts\\DefaultFont");

            _gizmo                 = new Gizmo(camera, _mouse, GraphicsDevice, new SpriteBatch(GraphicsDevice), font);
            _gizmo.ActivePivot     = PivotType.ObjectCenter;
            _gizmo.TranslateEvent += GizmoTranslateEvent;
            _gizmo.RotateEvent    += GizmoRotateEvent;
            _gizmo.ScaleEvent     += GizmoScaleEvent;
            _gizmo.StartEvent     += GizmoTransformStart;
            _gizmo.StopEvent      += GizmoTransformEnd;
        }
Exemple #16
0
 public void UpdateState(MouseComponent mouseComp)
 {
     mouseComp.OldState = mouseComp.NewState;
     mouseComp.NewState = Mouse.GetState();
 }
 /// <summary>
 /// updates the states of left, right & middle click
 /// </summary>
 /// <param name="mouseComponent"></param>
 public void UpdateActionStates(MouseComponent mouseComponent)
 {
     updateBtn(mouseComponent, curState.RightButton, prevState.RightButton, "RightButton");
     updateBtn(mouseComponent, curState.LeftButton, prevState.RightButton, "LeftButton");
     updateBtn(mouseComponent, curState.MiddleButton, prevState.RightButton, "MiddleButton");
 }