Beispiel #1
0
        public void Update(ref ControlState state, double timeDelta)
        {
            UIElementCollection.BindCollection(_uiElementCollection);

            #region update input

            UIElementCollection.Collection.UpdateInput(ref state);
            _doodadUI.UpdateInput(ref state);
            _cameraController.UpdateInput(ref state);

            #endregion

            #region update logic

            UIElementCollection.Collection.UpdateLogic(timeDelta);
            _doodadUI.UpdateLogic(timeDelta);

            #endregion

            UIElementCollection.UnbindCollection();
        }
Beispiel #2
0
 public void UpdateInput(ref ControlState state)
 {
     _toolbar.UpdateInput(ref state);
 }
Beispiel #3
0
 public void UpdateInput(ref ControlState state){
     if (Enabled){
         _activeTool.UpdateInput(ref state);
     }
 }
        public void UpdateInput(ref ControlState state)
        {
            if (_boundingBox.Contains(state.MousePos.X, state.MousePos.Y)){
                if (state.RightButtonState == ButtonState.Pressed){
                    if (!state.KeyboardState.IsKeyDown(Keys.LeftControl)){
                        int dx = state.MousePos.X - state.PrevState.MousePos.X;
                        int dy = state.MousePos.Y - state.PrevState.MousePos.Y;

                        if (state.RightButtonState == ButtonState.Pressed){
                            _cameraPhi -= dy*0.01f;
                            _cameraTheta += dx*0.01f;

                            if (_cameraPhi > (float) Math.PI - 0.01f){
                                _cameraPhi = (float) Math.PI - 0.01f;
                            }
                            if (_cameraPhi < 0.01f){
                                _cameraPhi = 0.01f;
                            }

                            Renderer.CameraPosition.X = (float) (_cameraDistance*Math.Sin(_cameraPhi)*Math.Cos(_cameraTheta)) + Renderer.CameraTarget.X;
                            Renderer.CameraPosition.Z = (float) (_cameraDistance*Math.Sin(_cameraPhi)*Math.Sin(_cameraTheta)) + Renderer.CameraTarget.Z;
                            Renderer.CameraPosition.Y = (float) (_cameraDistance*Math.Cos(_cameraPhi)) + Renderer.CameraTarget.Y;
                        }

                        state.AllowMouseMovementInterpretation = false;
                    }
                    else{
                        int dx = state.MousePos.X - state.PrevState.MousePos.X;
                        int dy = state.MousePos.Y - state.PrevState.MousePos.Y;

                        _cameraPhi -= dy*0.005f;
                        _cameraTheta += dx*0.005f;

                        if (_cameraPhi > (float) Math.PI - 0.01f){
                            _cameraPhi = (float) Math.PI - 0.01f;
                        }
                        if (_cameraPhi < 0.01f){
                            _cameraPhi = 0.01f;
                        }

                        Renderer.CameraTarget.X = ((float) (_cameraDistance*Math.Sin(_cameraPhi + Math.PI)*Math.Cos(_cameraTheta + Math.PI)) - Renderer.CameraPosition.X)*-1;
                        Renderer.CameraTarget.Z = ((float) (_cameraDistance*Math.Sin(_cameraPhi + Math.PI)*Math.Sin(_cameraTheta + Math.PI)) - Renderer.CameraPosition.Z)*-1;
                        Renderer.CameraTarget.Y = ((float) (_cameraDistance*Math.Cos(_cameraPhi + Math.PI)) + Renderer.CameraPosition.Y)*1;

                        int f = 4;
                    }
                }
            }

            if (state.AllowMouseScrollInterpretation){
                if (_boundingBox.Contains(state.MousePos.X, state.MousePos.Y)){
                    _cameraDistance += -state.MouseScrollChange/20f;
                    if (_cameraDistance < 5){
                        _cameraDistance = 5;
                    }

                    Renderer.CameraPosition.X = (float) (_cameraDistance*Math.Sin(_cameraPhi)*Math.Cos(_cameraTheta)) + Renderer.CameraTarget.X;
                    Renderer.CameraPosition.Z = (float) (_cameraDistance*Math.Sin(_cameraPhi)*Math.Sin(_cameraTheta)) + Renderer.CameraTarget.Z;
                    Renderer.CameraPosition.Y = (float) (_cameraDistance*Math.Cos(_cameraPhi)) + Renderer.CameraTarget.Y;
                }
            }
        }
Beispiel #5
0
 public void UpdateInput(ref ControlState state)
 {
     //throw new NotImplementedException();
 }
Beispiel #6
0
        void HandleEditorKeyboardInput(ref ControlState state)
        {
            if (state.KeyboardState.IsKeyDown(Keys.LeftControl) && state.KeyboardState.IsKeyDown(Keys.S)){
                SaveCurves("save/");
            }

            if (state.KeyboardState.IsKeyDown(Keys.LeftControl) && state.KeyboardState.IsKeyDown(Keys.N)){
                var sideInfo = _sidepanel.Curves.GetControllerInfo();
                var backInfo = _backpanel.Curves.GetControllerInfo();
                var topInfo = _toppanel.Curves.GetControllerInfo();

                GamestateManager.ClearGameState();
                GamestateManager.SetGameState(new DoodadEditor(backInfo, sideInfo, topInfo));
            }
        }
Beispiel #7
0
 public void Update(ref ControlState state, double timeDelta)
 {
     UIElementCollection.BindCollection(_elementCollection);
     _sidepanel.Update();
     _toppanel.Update();
     _backpanel.Update();
     _previewRenderer.Update();
     UIElementCollection.Collection.UpdateInput(ref state);
     UIElementCollection.Collection.UpdateLogic(timeDelta);
     UIElementCollection.UnbindCollection();
     HandleEditorKeyboardInput(ref state);
 }
        public static void Update()
        {
            //all this crap updates the CurrentControlState to whatever the hell is going on

            //notice the conditions for whether fields such as AllowMouseMovementInterpretation should be true or not
            //these were originally intended to reduce overhead for when no difference between current state and previous existed
            //but they caused loads of problems. the actual bool state they were supposed to be set to has been commented out and set to true
            //maybe fix in future if run out of updateinput allowance

            var curMouseState = Mouse.GetState();
            var curKeyboardState = Keyboard.GetState();

            var curControlState = new ControlState();

            if (_prevMouseState.X != curMouseState.X || _prevMouseState.Y != curMouseState.Y){
                curControlState.AllowMouseMovementInterpretation = true;
            }
            else{
                curControlState.AllowMouseMovementInterpretation = true;
                //curControlState.AllowMouseMovementInterpretation = false;
            }
            //mouse movement stuff needs to be updated every time, regardless of change
            curControlState.MousePos = new Point();
            curControlState.MousePos.X = curMouseState.X;
            curControlState.MousePos.Y = curMouseState.Y;
            curControlState.LeftButtonState = curMouseState.LeftButton;
            curControlState.RightButtonState = curMouseState.RightButton;
            curControlState.MouseScrollChange = curMouseState.ScrollWheelValue - _prevMouseState.ScrollWheelValue;

            if (_prevMouseState.LeftButton != curMouseState.LeftButton){
                curControlState.AllowLeftButtonInterpretation = true;
                if (curMouseState.LeftButton == ButtonState.Released){
                    //check if this qualifies as a click
                    if (_clickTimer.ElapsedMilliseconds < 200){
                        curControlState.LeftButtonClick = true;
                        _clickTimer.Reset();
                    }
                    else{
                        _clickTimer.Reset();
                        curControlState.LeftButtonClick = false;
                    }
                }
                else{ //button was pressed so start the click timer
                    _clickTimer.Start();
                }
            }
            else
                curControlState.AllowLeftButtonInterpretation = true;
            //curControlState.AllowLeftButtonInterpretation = false;

            if (_prevMouseState.RightButton != curMouseState.RightButton){
                curControlState.AllowRightButtonInterpretation = true;
            }
            else
                curControlState.AllowRightButtonInterpretation = true;
            //curControlState.AllowRightButtonInterpretation = false;

            if (_prevMouseState.ScrollWheelValue != curMouseState.ScrollWheelValue){
                curControlState.AllowMouseScrollInterpretation = true;
            }
            else
                curControlState.AllowMouseScrollInterpretation = true;
            //curControlState.AllowMouseScrollInterpretation = false;

            curControlState.KeyboardState = curKeyboardState;

            _prevKeyboardState = curKeyboardState;
            _prevMouseState = curMouseState;

            curControlState.ViewMatrix = Matrix.CreateLookAt(Renderer.CameraPosition, Renderer.CameraTarget, Vector3.Up);

            if (CurrentControlState != null){
                curControlState.PrevState = CurrentControlState;
                CurrentControlState.PrevState = null;
            }
            else{
                curControlState.PrevState = new ControlState();
            }
            CurrentControlState = curControlState;
        }