Ejemplo n.º 1
0
        public static bool UpdateGameLogic(CKeys keys, CMouse mouse)
        {
            bool run = true;

            _Cursor.Visible = mouse.Visible;

            mouse.CopyEvents();
            keys.CopyEvents();

            CVideo.Update();
            CSound.Update();
            CBackgroundMusic.Update();
            CController.Update();
            CProfiles.Update();

            if (CSettings.ProgramState != EProgramState.EditTheme)
            {
                run &= _HandleInputs(keys, mouse);
                run &= _Update();
                CParty.UpdateGame();
            }
            else
            {
                run &= _HandleInputThemeEditor(keys, mouse);
                run &= _Update();
            }

            return(run);
        }
Ejemplo n.º 2
0
        private static bool _HandleInputThemeEditor(CKeys keys, CMouse mouse)
        {
            SKeyEvent   keyEvent   = new SKeyEvent();
            SMouseEvent mouseEvent = new SMouseEvent();

            while (keys.PollEvent(ref keyEvent))
            {
                if (keyEvent.ModShift && (keyEvent.Key == Keys.F1))
                {
                    CSettings.ProgramState = EProgramState.Normal;
                    CurrentScreen.NextElement();
                }
                else if (keyEvent.ModAlt && (keyEvent.Key == Keys.Enter))
                {
                    CConfig.Config.Graphics.FullScreen = (CConfig.Config.Graphics.FullScreen == EOffOn.TR_CONFIG_ON) ? EOffOn.TR_CONFIG_OFF : EOffOn.TR_CONFIG_ON;
                }
                else if (keyEvent.ModAlt && (keyEvent.Key == Keys.P))
                {
                    CDraw.MakeScreenShot();
                }
                else
                {
                    if (_Fading == null)
                    {
                        CurrentScreen.HandleInputThemeEditor(keyEvent);
                    }
                }
            }

            while (mouse.PollEvent(ref mouseEvent))
            {
                if (_Fading == null)
                {
                    CurrentScreen.HandleMouseThemeEditor(mouseEvent);
                }

                _UpdateMousePosition(mouseEvent.X, mouseEvent.Y);
            }
            return(true);
        }
Ejemplo n.º 3
0
        private static bool _HandleInputs(CKeys keys, CMouse mouse)
        {
            SKeyEvent   keyEvent        = new SKeyEvent();
            SMouseEvent mouseEvent      = new SMouseEvent();
            SKeyEvent   inputKeyEvent   = new SKeyEvent();
            SMouseEvent inputMouseEvent = new SMouseEvent();

            bool popupPlayerControlAllowed = CurrentScreen.CurrentMusicType == EMusicType.Background;
            bool popupVolumeControlAllowed = CurrentScreen.CurrentMusicType != EMusicType.None;

            //Hide volume control for bg-music if bg-music is disabled
            if (popupVolumeControlAllowed && (CurrentScreen.CurrentMusicType == EMusicType.Background || CurrentScreen.CurrentMusicType == EMusicType.BackgroundPreview) && CConfig.Config.Sound.BackgroundMusic == EBackgroundMusicOffOn.TR_CONFIG_OFF)
            {
                popupVolumeControlAllowed = false;
            }

            bool resume = true;
            bool eventsAvailable;
            bool inputEventsAvailable = CController.PollKeyEvent(ref inputKeyEvent);

            while ((eventsAvailable = keys.PollEvent(ref keyEvent)) || inputEventsAvailable)
            {
                if (!eventsAvailable)
                {
                    keyEvent = inputKeyEvent;
                }

                if (keyEvent.IsArrowKey() || keyEvent.Key == Keys.NumPad0 || keyEvent.Key == Keys.D0 || keyEvent.Key == Keys.Add)
                {
                    _Cursor.Deactivate();

                    if (keyEvent.ModAlt && keyEvent.ModCtrl)
                    {
                        switch (keyEvent.Key)
                        {
                        case Keys.Right:
                            if (keyEvent.ModShift)
                            {
                                CConfig.Config.Graphics.BorderLeft++;
                            }
                            else
                            {
                                CConfig.Config.Graphics.BorderRight--;
                            }
                            break;

                        case Keys.Left:
                            if (keyEvent.ModShift)
                            {
                                CConfig.Config.Graphics.BorderLeft--;
                            }
                            else
                            {
                                CConfig.Config.Graphics.BorderRight++;
                            }
                            break;

                        case Keys.Down:
                            if (keyEvent.ModShift)
                            {
                                CConfig.Config.Graphics.BorderTop++;
                            }
                            else
                            {
                                CConfig.Config.Graphics.BorderBottom--;
                            }
                            break;

                        case Keys.Up:
                            if (keyEvent.ModShift)
                            {
                                CConfig.Config.Graphics.BorderTop--;
                            }
                            else
                            {
                                CConfig.Config.Graphics.BorderBottom++;
                            }
                            break;

                        case Keys.D0:
                        case Keys.NumPad0:
                            CConfig.Config.Graphics.BorderLeft      =
                                CConfig.Config.Graphics.BorderRight = CConfig.Config.Graphics.BorderTop = CConfig.Config.Graphics.BorderBottom = 0;
                            break;

                        case Keys.Add:
                            switch (CConfig.Config.Graphics.ScreenAlignment)
                            {
                            case EGeneralAlignment.Middle:
                                CConfig.Config.Graphics.ScreenAlignment = EGeneralAlignment.End;
                                break;

                            case EGeneralAlignment.End:
                                CConfig.Config.Graphics.ScreenAlignment = EGeneralAlignment.Start;
                                break;

                            default:
                                CConfig.Config.Graphics.ScreenAlignment = EGeneralAlignment.Middle;
                                break;
                            }
                            break;
                        }
                        CConfig.SaveConfig();
                        break;
                    }
                }

                if (keyEvent.Key == Keys.F11)
                {
                    if (_CurrentPopupScreen == EPopupScreens.NoPopup)
                    {
                        ShowPopup(EPopupScreens.PopupServerQR);
                    }
                    else
                    {
                        HidePopup(EPopupScreens.PopupServerQR);
                    }
                }

                if (keyEvent.Key == Keys.F8)
                {
                    CLog.ShowLogAssistant("", null);
                }

                if (popupPlayerControlAllowed && keyEvent.Key == Keys.Tab)
                {
                    if (_CurrentPopupScreen == EPopupScreens.NoPopup && CConfig.Config.Sound.BackgroundMusic == EBackgroundMusicOffOn.TR_CONFIG_ON)
                    {
                        ShowPopup(EPopupScreens.PopupPlayerControl);
                    }
                    else
                    {
                        HidePopup(EPopupScreens.PopupPlayerControl);
                    }
                }

                if (popupPlayerControlAllowed && CConfig.Config.Sound.BackgroundMusic != EBackgroundMusicOffOn.TR_CONFIG_OFF)
                {
                    if (keyEvent.Key == Keys.MediaNextTrack)
                    {
                        CBackgroundMusic.Next();
                    }
                    else if (keyEvent.Key == Keys.MediaPreviousTrack)
                    {
                        CBackgroundMusic.Previous();
                    }
                    else if (keyEvent.Key == Keys.MediaPlayPause)
                    {
                        if (CBackgroundMusic.IsPlaying)
                        {
                            CBackgroundMusic.Pause();
                        }
                        else
                        {
                            CBackgroundMusic.Play();
                        }
                    }
                }

                if (keyEvent.ModShift && (keyEvent.Key == Keys.F1))
                {
                    CSettings.ProgramState = EProgramState.EditTheme;
                }
                else if (keyEvent.ModAlt && (keyEvent.Key == Keys.Enter))
                {
                    CConfig.Config.Graphics.FullScreen = (CConfig.Config.Graphics.FullScreen == EOffOn.TR_CONFIG_ON) ? EOffOn.TR_CONFIG_OFF : EOffOn.TR_CONFIG_ON;
                }
                else if (keyEvent.ModAlt && (keyEvent.Key == Keys.P))
                {
                    CDraw.MakeScreenShot();
                }
                else
                {
                    if (_Fading == null)
                    {
                        bool handled = false;
                        if (_CurrentPopupScreen != EPopupScreens.NoPopup)
                        {
                            handled = _PopupScreens[(int)_CurrentPopupScreen].HandleInput(keyEvent);
                            if (popupVolumeControlAllowed && _CurrentPopupScreen == EPopupScreens.PopupVolumeControl && handled)
                            {
                                _VolumePopupTimer.Restart();
                            }
                        }
                        else if (popupVolumeControlAllowed && _PopupScreens[(int)EPopupScreens.PopupVolumeControl].HandleInput(keyEvent))
                        {
                            ShowPopup(EPopupScreens.PopupVolumeControl);
                            _VolumePopupTimer.Restart();
                        }

                        if (!handled)
                        {
                            resume &= CurrentScreen.HandleInput(keyEvent);
                        }
                    }
                }

                if (!eventsAvailable)
                {
                    inputEventsAvailable = CController.PollKeyEvent(ref inputKeyEvent);
                }
            }

            inputEventsAvailable = CController.PollMouseEvent(ref inputMouseEvent);

            while ((eventsAvailable = mouse.PollEvent(ref mouseEvent)) || inputEventsAvailable)
            {
                if (!eventsAvailable)
                {
                    mouseEvent = inputMouseEvent;
                }

                if (mouseEvent.Wheel != 0)
                {
                    _Cursor.Activate();
                }

                _UpdateMousePosition(mouseEvent.X, mouseEvent.Y);

                bool isOverPopupPlayerControl = CHelper.IsInBounds(_PopupScreens[(int)EPopupScreens.PopupPlayerControl].ScreenArea, mouseEvent);
                if (popupPlayerControlAllowed && isOverPopupPlayerControl)
                {
                    if (_CurrentPopupScreen == EPopupScreens.NoPopup && CConfig.Config.Sound.BackgroundMusic == EBackgroundMusicOffOn.TR_CONFIG_ON)
                    {
                        ShowPopup(EPopupScreens.PopupPlayerControl);
                    }
                }

                if (!isOverPopupPlayerControl && _CurrentPopupScreen == EPopupScreens.PopupPlayerControl)
                {
                    HidePopup(EPopupScreens.PopupPlayerControl);
                }

                bool isOverPopupVolumeControl = CHelper.IsInBounds(_PopupScreens[(int)EPopupScreens.PopupVolumeControl].ScreenArea, mouseEvent);
                if (popupVolumeControlAllowed && isOverPopupVolumeControl)
                {
                    if (_CurrentPopupScreen == EPopupScreens.NoPopup)
                    {
                        ShowPopup(EPopupScreens.PopupVolumeControl);
                        _VolumePopupTimer.Reset();
                        _VolumePopupTimer.Start();
                    }
                }

                if (_CursorOverVolumeControl && !isOverPopupVolumeControl)
                {
                    if (_CurrentPopupScreen == EPopupScreens.PopupVolumeControl)
                    {
                        HidePopup(EPopupScreens.PopupVolumeControl);
                        _VolumePopupTimer.Reset();
                    }
                }
                _CursorOverVolumeControl = isOverPopupVolumeControl;


                bool handled = false;
                if (_CurrentPopupScreen != EPopupScreens.NoPopup)
                {
                    handled = _PopupScreens[(int)_CurrentPopupScreen].HandleMouse(mouseEvent);
                }

                if (!handled && _Fading == null && (_Cursor.IsActive || mouseEvent.LB || mouseEvent.RB || mouseEvent.MB))
                {
                    resume &= CurrentScreen.HandleMouse(mouseEvent);
                }

                if (!eventsAvailable)
                {
                    inputEventsAvailable = CController.PollMouseEvent(ref inputMouseEvent);
                }
            }
            return(resume);
        }