コード例 #1
0
        public void Play()
        {
            bool   skipped = false;
            ushort x       = (ushort)((_vm.Settings.Game.Width - _decoder.GetWidth()) / 2);
            ushort y       = (ushort)((_vm.Settings.Game.Height - _decoder.GetHeight()) / 2);

            while (!SwordEngine.ShouldQuit && !_decoder.EndOfVideo && !skipped)
            {
                if (_decoder.NeedsUpdate)
                {
                    var frame = _decoder.DecodeNextFrame();
                    if (frame != null)
                    {
                        if (SystemVars.Platform == Core.IO.Platform.PSX)
                        {
                            DrawFramePSX(frame);
                        }
                        else
                        {
                            _vm.GraphicsManager.CopyRectToScreen(frame.Pixels, frame.Pitch, x, y, frame.Width, frame.Height);
                        }
                    }

                    if (_decoder.HasDirtyPalette)
                    {
                        var palette = ToPalette(_decoder.Palette);
                        _vm.GraphicsManager.SetPalette(palette, 0, 256);

                        UpdateColors();
                    }

                    var pixels = _vm.GraphicsManager.Pixels;
                    PerformPostProcessing(pixels);
                    _vm.GraphicsManager.CopyRectToScreen(pixels, _vm.Settings.Game.Width * Surface.GetBytesPerPixel(_vm.GraphicsManager.PixelFormat), 0, 0, _vm.Settings.Game.Width, _vm.Settings.Game.Height);
                    _vm.GraphicsManager.UpdateScreen();
                }

                int count;
                var lastState = new ScummInputState();
                do
                {
                    var state = _vm.System.InputManager.GetState();
                    count = state.GetKeys().Count;
                    if (state.IsKeyDown(KeyCode.Escape) || (lastState.IsLeftButtonDown && !state.IsLeftButtonDown))
                    {
                        skipped = true;
                    }
                    _vm.System.InputManager.ResetKeys();
                    lastState = state;
                } while (!skipped && count != 0);

                ServiceLocator.Platform.Sleep(10);
            }

            // Need to jump back to paletted color
            if (SystemVars.Platform == Core.IO.Platform.PSX)
            {
                _vm.GraphicsManager.PixelFormat = PixelFormat.Indexed8;
            }
        }
コード例 #2
0
        internal void ParseEvents()
        {
            var newInput = _inputManager.GetState();

            if (newInput != _inputState)
            {
                _inputState = newInput;
                if (_inputState.IsLeftButtonDown)
                {
                    _leftBtnPressed = MouseButtonStatus.Clicked | MouseButtonStatus.Down;
                }
                else
                {
                    _leftBtnPressed &= ~MouseButtonStatus.Down;
                }
                if (_inputState.IsRightButtonDown)
                {
                    _rightBtnPressed = MouseButtonStatus.Clicked | MouseButtonStatus.Down;
                }
                else
                {
                    _rightBtnPressed &= ~MouseButtonStatus.Down;
                }
            }
        }
コード例 #3
0
 public ScummInputState GetState()
 {
     lock (_gate)
     {
         var inputState = new ScummInputState(_keysPressed.ToList(), _leftButtonPressed, _rightButtonPressed);
         return(inputState);
     }
 }
コード例 #4
0
        private void HandleKey()
        {
            if (_keyPressed.GetKeys().Count > 0 && SystemVars.Instance.Paused)
            {
                _skySound.FnUnPauseFx();
                SystemVars.Instance.Paused = false;
                _skyScreen.SetPaletteEndian(_skyCompact.FetchCptRaw((ushort)SystemVars.Instance.CurrentPalette));
            }
            else if (_keyPressed.IsKeyDown(KeyCode.LeftControl))
            {
                if (_keyPressed.IsKeyDown(KeyCode.F))
                {
                    _fastMode ^= 1;
                }
                else if (_keyPressed.IsKeyDown(KeyCode.G))
                {
                    _fastMode ^= 2;
                }
                // TODO: debugger
                //else if (_keyPressed.keycode == Common::KEYCODE_d)
                //    _debugger.attach();
            }
            else
            {
                // TODO: debugger
                //case Common::KEYCODE_BACKQUOTE:
                //case Common::KEYCODE_HASH:
                //    _debugger.attach();
                //    break;
                if (_keyPressed.IsKeyDown(KeyCode.F5))
                {
                    _skyControl.DoControlPanel();
                }

                if (_keyPressed.IsKeyDown(KeyCode.Escape))
                {
                    if (!SystemVars.Instance.PastIntro)
                    {
                        _skyControl.RestartGame();
                    }
                }
                if (_keyPressed.IsKeyDown(KeyCode.OemPeriod))
                {
                    _skyMouse.LogicClick();
                }
                if (_keyPressed.IsKeyDown(KeyCode.P))
                {
                    _skyScreen.HalvePalette();
                    _skySound.FnPauseFx();
                    SystemVars.Instance.Paused = true;
                }
            }
            _keyPressed = new ScummInputState();
            _system.InputManager.ResetKeys();
        }
コード例 #5
0
        private void Delay(int delayInMs)
        {
            int start = Environment.TickCount;

            do
            {
                var inputState = System.InputManager.GetState();
                _mouseCoord  = System.InputManager.GetMousePosition();
                _keyPressed  = inputState;
                _mouseState |= (ushort)(inputState.IsLeftButtonDown ? Mouse.BS1L_BUTTON_DOWN : Mouse.BS1L_BUTTON_UP);
                _mouseState |= (ushort)(inputState.IsRightButtonDown ? Mouse.BS1R_BUTTON_DOWN : Mouse.BS1R_BUTTON_UP);

                System.GraphicsManager.UpdateScreen();

                if (delayInMs > 0)
                {
                    ServiceLocator.Platform.Sleep(10);
                }
            } while (Environment.TickCount < start + delayInMs);
        }
コード例 #6
0
ファイル: ScummEngine_Input.cs プロジェクト: scemino/nscumm
 internal void ParseEvents()
 {
     var newInput = _inputManager.GetState();
     if (newInput != _inputState)
     {
         _inputState = newInput;
         if (_inputState.IsLeftButtonDown)
         {
             _leftBtnPressed = MouseButtonStatus.Clicked | MouseButtonStatus.Down;
         }
         else
         {
             _leftBtnPressed &= ~MouseButtonStatus.Down;
         }
         if (_inputState.IsRightButtonDown)
         {
             _rightBtnPressed = MouseButtonStatus.Clicked | MouseButtonStatus.Down;
         }
         else
         {
             _rightBtnPressed &= ~MouseButtonStatus.Down;
         }
     }
 }
コード例 #7
0
ファイル: Control.cs プロジェクト: scemino/nscumm
        private void Delay(int amount)
        {
            var start = Environment.TickCount;
            var cur = start;
            do
            {
                _keyPressed = _system.InputManager.GetState();
                var mousePos = _system.InputManager.GetMousePosition();

                if (!SystemVars.Instance.SystemFlags.HasFlag(SystemFlags.MouseLocked))
                    _skyMouse.MouseMoved((ushort)mousePos.X, (ushort)mousePos.Y);

                _mouseClicked = _keyPressed.IsLeftButtonDown;

                // TODO: mouse wheel ?
                //case Common::EVENT_WHEELUP:
                //	_mouseWheel = -1;
                //	break;
                //case Common::EVENT_WHEELDOWN:
                //	_mouseWheel = 1;
                //	break;

                var thisDelay = 20; // 1?
#if _WIN32_WCE
    this_delay = 10;
#endif
                if (thisDelay > amount)
                    thisDelay = amount;

                if (thisDelay > 0) ServiceLocator.Platform.Sleep(thisDelay);

                cur = Environment.TickCount;
            } while (cur < start + amount);
        }
コード例 #8
0
ファイル: Control.cs プロジェクト: scemino/nscumm
        private void HandleKeyPress(ScummInputState kbd, StringBuilder textBuf)
        {
            if (kbd.IsKeyDown(KeyCode.Backspace))
            { // backspace
                if (textBuf.Length > 0)
                    textBuf.Remove(textBuf.Length - 1, 1);
            }
            else
            {
                // TODO: do this in ScummInputState ?
                var key = (char?)kbd.GetKeys().Where(k => k >= (KeyCode)32 && k <= (KeyCode)126).Select(k => (KeyCode?)k).FirstOrDefault();
                if (!key.HasValue)
                    return;

                // Cannot enter text wider than the save/load panel
                if (_enteredTextWidth >= PanLineWidth - 10)
                    return;

                // Cannot enter text longer than MaxTextLen-1 chars, since
                // the storage is only so big. Note: The code used to incorrectly
                // allow up to MaxTextLen, which caused an out of bounds access,
                // overwriting the next entry in the list of savegames partially.
                // This could be triggered by e.g. entering lots of periods ".".
                if (textBuf.Length >= MaxTextLen - 1)
                    return;

                // Allow the key only if is a letter, a digit, or one of a selected
                // list of extra characters

                if (char.IsLetterOrDigit(key.Value) || " ,().='-&+!?\"".Contains(key.Value.ToString()))
                {
                    textBuf.Append(key);
                }
            }
        }
コード例 #9
0
ファイル: Control.cs プロジェクト: scemino/nscumm
        private ushort SaveRestorePanel(bool allowSave)
        {
            _keyPressed = new ScummInputState();
            _system.InputManager.ResetKeys();
            _mouseWheel = 0;
            ButtonControl(null);
            _text.DrawToScreen(WithMask); // flush text restore buffer

            ConResource[] lookList;
            ushort cnt;
            byte lookListLen;
            if (allowSave)
            {
                lookList = _savePanLookList;
                lookListLen = 6;
                _system.InputManager.ShowVirtualKeyboard();
            }
            else
            {
                lookList = _restorePanLookList;
                if (AutoSaveExists())
                    lookListLen = 7;
                else
                    lookListLen = 6;
            }
            bool withAutoSave = lookListLen == 7;

            var textSprites = new byte[MaxOnScreen + 1][];
            _firstText = 0;

            var saveGameTexts = LoadDescriptions().Select(s => new StringBuilder(s)).ToArray();
            _selectedGame = 0;

            bool quitPanel = false;
            bool refreshNames = true;
            bool refreshAll = true;
            ushort clickRes = 0;
            while (!quitPanel && !SkyEngine.ShouldQuit)
            {
                clickRes = 0;
                if (refreshNames || refreshAll)
                {
                    if (refreshAll)
                    {
                        _text.FlushForRedraw();
                        _savePanel.DrawToScreen(NoMask);
                        _quitButton.DrawToScreen(NoMask);
                        if (withAutoSave)
                            _autoSaveButton.DrawToScreen(NoMask);
                        refreshAll = false;
                    }
                    for (cnt = 0; cnt < MaxOnScreen; cnt++)
                        if (textSprites[cnt] != null)
                            textSprites[cnt] = null;
                    SetUpGameSprites(saveGameTexts, textSprites, _firstText, _selectedGame);
                    ShowSprites(textSprites, allowSave);
                    refreshNames = false;
                }

                _text.DrawToScreen(WithMask);
                _system.GraphicsManager.UpdateScreen();
                _mouseClicked = false;
                Delay(50);
                if (_controlPanel == null)
                    return clickRes;
                if (_keyPressed.IsKeyDown(KeyCode.Escape))
                { // escape pressed
                    _mouseClicked = false;
                    clickRes = CancelPressed;
                    quitPanel = true;
                }
                else if (_keyPressed.IsKeyDown(KeyCode.Return)) // TODO: || _keyPressed.IsKeyDown(KeyCode.Enter)
                {
                    clickRes = HandleClick(lookList[0]);
                    if (_controlPanel == null) //game state was destroyed
                        return clickRes;
                    if (clickRes == GameSaved)
                        SaveDescriptions(saveGameTexts);
                    else if (clickRes == NoDiskSpace)
                    {
                        // TODO: DisplayMessage(0, "Could not save the game. (%s)", _saveFileMan.popErrorDesc().c_str());
                    }
                    quitPanel = true;
                    _mouseClicked = false;
                    _keyPressed = new ScummInputState();
                    _system.InputManager.ResetKeys();
                }
                if (allowSave && _keyPressed.GetKeys().Count > 0)
                {
                    HandleKeyPress(_keyPressed, saveGameTexts[_selectedGame]);
                    refreshNames = true;
                    _keyPressed = new ScummInputState();
                    _system.InputManager.ResetKeys();
                }

                if (_mouseWheel != 0)
                {
                    if (_mouseWheel < 0)
                        clickRes = ShiftUp(Slow);
                    else if (_mouseWheel > 0)
                        clickRes = ShiftDown(Slow);
                    _mouseWheel = 0;
                    if (clickRes == Shifted)
                    {
                        _selectedGame = _firstText;
                        refreshNames = true;
                    }
                }

                bool haveButton = false;
                var mouse = _system.InputManager.GetMousePosition();
                for (cnt = 0; cnt < lookListLen; cnt++)
                    if (lookList[cnt].IsMouseOver((uint)mouse.X, (uint)mouse.Y))
                    {
                        ButtonControl(lookList[cnt]);
                        haveButton = true;

                        if (_mouseClicked && lookList[cnt].OnClick != 0)
                        {
                            _mouseClicked = false;

                            clickRes = HandleClick(lookList[cnt]);
                            if (_controlPanel == null) //game state was destroyed
                                return clickRes;

                            if (clickRes == Shifted)
                            {
                                _selectedGame = _firstText;
                                refreshNames = true;
                            }
                            if (clickRes == NoDiskSpace)
                            {
                                // TODO: DisplayMessage(0, "Could not save the game. (%s)", _saveFileMan.popErrorDesc().c_str());
                                quitPanel = true;
                            }
                            if ((clickRes == CancelPressed) || (clickRes == GameRestored))
                                quitPanel = true;

                            if (clickRes == GameSaved)
                            {
                                SaveDescriptions(saveGameTexts);
                                quitPanel = true;
                            }
                            if (clickRes == RestoreFailed)
                                refreshAll = true;
                        }
                    }

                if (_mouseClicked)
                {
                    if ((mouse.X >= GameNameX) && (mouse.X <= GameNameX + PanLineWidth) &&
                        (mouse.Y >= GameNameY) && (mouse.Y <= GameNameY + PanCharHeight * MaxOnScreen))
                    {

                        _selectedGame = (ushort)((mouse.Y - GameNameY) / PanCharHeight + _firstText);
                        refreshNames = true;
                    }
                }
                if (!haveButton)
                    ButtonControl(null);
            }

            for (cnt = 0; cnt < MaxOnScreen + 1; cnt++)
                textSprites[cnt] = null;

            if (allowSave)
            {
                _system.InputManager.HideVirtualKeyboard();
            }

            return clickRes;
        }
コード例 #10
0
ファイル: Control.cs プロジェクト: scemino/nscumm
 private void HandleSaveKey(ScummInputState kbd)
 {
     if (_selectedSavegame < 255)
     {
         var saveName = new StringBuilder(_saveNames[_selectedSavegame]);
         byte len = (byte)_saveNames[_selectedSavegame].Length;
         if (kbd.IsKeyDown(KeyCode.Backspace) && len != 0)  // backspace
             saveName.Remove(saveName.Length - 1, 1);
         else
         {
             var key = kbd.GetKeys().Select(k => (char?)k).LastOrDefault();
             if (key.HasValue && keyAccepted(key.Value) && (len < 31))
             {
                 saveName.Append(key.Value);
             }
         }
         _saveNames[_selectedSavegame] = saveName.ToString();
         ShowSavegameNames();
     }
 }
コード例 #11
0
ファイル: SkyEngine.cs プロジェクト: scemino/nscumm
        public void Run()
        {
            _keyPressed = new ScummInputState();

            ushort result = 0;
            // TODO: configuration
            //if (ConfMan.hasKey("save_slot"))
            //{
            //    var saveSlot = (int)ConfigurationManager["save_slot"];
            //    if (saveSlot >= 0 && saveSlot <= 999)
            //        result = _skyControl.QuickXRestore((int)ConfigurationManager["save_slot"]);
            //}

            if (result != Control.GameRestored)
            {
                bool introSkipped = false;
                if (SystemVars.Instance.GameVersion.Version.Minor > 272)
                {
                    // don't do intro for floppydemos
                    using (var skyIntro = new Intro(_skyDisk, _skyScreen, _skyMusic, _skySound, _skyText, _mixer, _system))
                    {
                        // TODO: configuration
                        //var floppyIntro = (bool)ConfigurationManager["alt_intro"];
                        var floppyIntro = false;
                        introSkipped = !skyIntro.DoIntro(floppyIntro);
                    }
                }

                if (!HasToQuit)
                {
                    // restartGame() takes us to the first scene, without showing the
                    // initial animation where Foster is being chased. initScreen0()
                    // shows the first scene together with that animation. We can't
                    // call both, as they both load the same scene.
                    if (introSkipped)
                        _skyControl.RestartGame();
                    else
                        _skyLogic.InitScreen0();
                }
            }

            _lastSaveTime = Environment.TickCount;

            var delayCount = Environment.TickCount;
            while (!HasToQuit)
            {
                // TODO: _debugger.onFrame();

                if (ShouldPerformAutoSave(_lastSaveTime))
                {
                    if (_skyControl.LoadSaveAllowed())
                    {
                        _lastSaveTime = Environment.TickCount;
                        _skyControl.DoAutoSave();
                    }
                    else
                        _lastSaveTime += 30 * 1000; // try again in 30 secs
                }
                _skySound.CheckFxQueue();
                _skyMouse.MouseEngine();
                HandleKey();
                if (SystemVars.Instance.Paused)
                {
                    do
                    {
                        _system.GraphicsManager.UpdateScreen();
                        Delay(50);
                        HandleKey();
                    } while (SystemVars.Instance.Paused);
                    delayCount = Environment.TickCount;
                }

                _skyLogic.Engine();
                _skyScreen.ProcessSequence();
                _skyScreen.Recreate();
                _skyScreen.SpriteEngine();

                // TODO: debugger
                //if (_debugger.showGrid())
                //{
                //    var grid = _skyLogic.Grid.GiveGrid(_skyLogic.ScriptVariables[Logic.SCREEN]);
                //    if (grid != null)
                //    {
                //        _skyScreen.ShowGrid(grid);
                //        _skyScreen.ForceRefresh();
                //    }
                //}
                _skyScreen.Flip();

                if ((_fastMode & 2) != 0)
                    Delay(0);
                else if ((_fastMode & 1) != 0)
                    Delay(10);
                else
                {
                    delayCount += SystemVars.Instance.GameSpeed;
                    int needDelay = delayCount - Environment.TickCount;
                    if ((needDelay < 0) || (needDelay > SystemVars.Instance.GameSpeed))
                    {
                        needDelay = 0;
                        delayCount = Environment.TickCount;
                    }
                    Delay(needDelay);
                }
            }

            _skyControl.ShowGameQuitMsg();
            _skyMusic.StopMusic();
            // TODO: configuration
            //ConfMan.flushToDisk();
            Delay(1500);
        }
コード例 #12
0
ファイル: MoviePlayer.cs プロジェクト: scemino/nscumm
        public void Play()
        {
            bool skipped = false;
            ushort x = (ushort)((_vm.Settings.Game.Width - _decoder.GetWidth()) / 2);
            ushort y = (ushort)((_vm.Settings.Game.Height - _decoder.GetHeight()) / 2);

            while (!SwordEngine.ShouldQuit && !_decoder.EndOfVideo && !skipped)
            {
                if (_decoder.NeedsUpdate)
                {
                    var frame = _decoder.DecodeNextFrame();
                    if (frame != null)
                    {
                        if (SystemVars.Platform == Core.IO.Platform.PSX)
                            DrawFramePSX(frame);
                        else
                            _vm.GraphicsManager.CopyRectToScreen(frame.Pixels, frame.Pitch, x, y, frame.Width, frame.Height);
                    }

                    if (_decoder.HasDirtyPalette)
                    {
                        var palette = ToPalette(_decoder.Palette);
                        _vm.GraphicsManager.SetPalette(palette, 0, 256);

                        UpdateColors();
                    }

                    var pixels = _vm.GraphicsManager.Pixels;
                    PerformPostProcessing(pixels);
                    _vm.GraphicsManager.CopyRectToScreen(pixels, _vm.Settings.Game.Width * Surface.GetBytesPerPixel(_vm.GraphicsManager.PixelFormat), 0, 0, _vm.Settings.Game.Width, _vm.Settings.Game.Height);
                    _vm.GraphicsManager.UpdateScreen();

                }

                int count;
                var lastState = new ScummInputState();
                do
                {
                    var state = _vm.System.InputManager.GetState();
                    count = state.GetKeys().Count;
                    if (state.IsKeyDown(KeyCode.Escape) || (lastState.IsLeftButtonDown && !state.IsLeftButtonDown))
                        skipped = true;
                    _vm.System.InputManager.ResetKeys();
                    lastState = state;
                } while (!skipped && count != 0);

                ServiceLocator.Platform.Sleep(10);
            }

            // Need to jump back to paletted color
            if (SystemVars.Platform == Core.IO.Platform.PSX)
                _vm.GraphicsManager.PixelFormat = PixelFormat.Indexed8;
        }
コード例 #13
0
        public void Run()
        {
            _keyPressed = new ScummInputState();

            ushort result = 0;

            // TODO: configuration
            //if (ConfMan.hasKey("save_slot"))
            //{
            //    var saveSlot = (int)ConfigurationManager["save_slot"];
            //    if (saveSlot >= 0 && saveSlot <= 999)
            //        result = _skyControl.QuickXRestore((int)ConfigurationManager["save_slot"]);
            //}

            if (result != Control.GameRestored)
            {
                bool introSkipped = false;
                if (SystemVars.Instance.GameVersion.Version.Minor > 272)
                {
                    // don't do intro for floppydemos
                    using (var skyIntro = new Intro(_skyDisk, _skyScreen, _skyMusic, _skySound, _skyText, _mixer, _system))
                    {
                        // TODO: configuration
                        //var floppyIntro = (bool)ConfigurationManager["alt_intro"];
                        var floppyIntro = false;
                        introSkipped = !skyIntro.DoIntro(floppyIntro);
                    }
                }

                if (!HasToQuit)
                {
                    // restartGame() takes us to the first scene, without showing the
                    // initial animation where Foster is being chased. initScreen0()
                    // shows the first scene together with that animation. We can't
                    // call both, as they both load the same scene.
                    if (introSkipped)
                    {
                        _skyControl.RestartGame();
                    }
                    else
                    {
                        _skyLogic.InitScreen0();
                    }
                }
            }

            _lastSaveTime = Environment.TickCount;

            var delayCount = Environment.TickCount;

            while (!HasToQuit)
            {
                // TODO: _debugger.onFrame();

                if (ShouldPerformAutoSave(_lastSaveTime))
                {
                    if (_skyControl.LoadSaveAllowed())
                    {
                        _lastSaveTime = Environment.TickCount;
                        _skyControl.DoAutoSave();
                    }
                    else
                    {
                        _lastSaveTime += 30 * 1000; // try again in 30 secs
                    }
                }
                _skySound.CheckFxQueue();
                _skyMouse.MouseEngine();
                HandleKey();
                if (SystemVars.Instance.Paused)
                {
                    do
                    {
                        _system.GraphicsManager.UpdateScreen();
                        Delay(50);
                        HandleKey();
                    } while (SystemVars.Instance.Paused);
                    delayCount = Environment.TickCount;
                }

                _skyLogic.Engine();
                _skyScreen.ProcessSequence();
                _skyScreen.Recreate();
                _skyScreen.SpriteEngine();

                // TODO: debugger
                //if (_debugger.showGrid())
                //{
                //    var grid = _skyLogic.Grid.GiveGrid(_skyLogic.ScriptVariables[Logic.SCREEN]);
                //    if (grid != null)
                //    {
                //        _skyScreen.ShowGrid(grid);
                //        _skyScreen.ForceRefresh();
                //    }
                //}
                _skyScreen.Flip();

                if ((_fastMode & 2) != 0)
                {
                    Delay(0);
                }
                else if ((_fastMode & 1) != 0)
                {
                    Delay(10);
                }
                else
                {
                    delayCount += SystemVars.Instance.GameSpeed;
                    int needDelay = delayCount - Environment.TickCount;
                    if ((needDelay < 0) || (needDelay > SystemVars.Instance.GameSpeed))
                    {
                        needDelay  = 0;
                        delayCount = Environment.TickCount;
                    }
                    Delay(needDelay);
                }
            }

            _skyControl.ShowGameQuitMsg();
            _skyMusic.StopMusic();
            // TODO: configuration
            //ConfMan.flushToDisk();
            Delay(1500);
        }
コード例 #14
0
ファイル: XnaInputManager.cs プロジェクト: scemino/nscumm
 public ScummInputState GetState()
 {
     lock (_gate)
     {
         var inputState = new ScummInputState(_keysPressed.ToList(), _leftButtonPressed, _rightButtonPressed);
         return inputState;
     }
 }
コード例 #15
0
ファイル: Control.cs プロジェクト: scemino/nscumm
        public byte RunPanel()
        {
            _panelShown = true;
            _mouseDown = false;
            _restoreBuf = null;
            _numButtons = 0;
            _screenBuf = new byte[640 * 480];
            _system.GraphicsManager.CopyRectToScreen(_screenBuf, 640, 0, 0, 640, 480);
            _sound.QuitScreen();

            uint fontId = SwordRes.SR_FONT, redFontId = SwordRes.SR_REDFONT;
            if (SystemVars.Language == Language.BS1_CZECH)
            {
                fontId = SwordRes.CZECH_SR_FONT;
                redFontId = SwordRes.CZECH_SR_REDFONT;
            }
            _font = _resMan.OpenFetchRes(fontId);
            _redFont = _resMan.OpenFetchRes(redFontId);

            var pal = _resMan.OpenFetchRes(SwordRes.SR_PALETTE);
            var palOut = new Color[256];
            for (ushort cnt = 1; cnt < 256; cnt++)
            {
                palOut[cnt] = Color.FromRgb(pal[cnt * 3 + 0] << 2, pal[cnt * 3 + 1] << 2, pal[cnt * 3 + 2] << 2);
            }
            palOut[0] = Color.FromRgb(0, 0, 0);
            _resMan.ResClose(SwordRes.SR_PALETTE);
            _system.GraphicsManager.SetPalette(palOut, 0, 256);
            ButtonIds mode = 0;
            ButtonIds newMode = ButtonIds.BUTTON_MAIN_PANEL;
            bool fullRefresh = false;
            _mouse.ControlPanel(true);
            byte retVal = CONTROL_NOTHING_DONE;
            _music.StartMusic(61, 1);

            do
            {
                if (newMode != 0)
                {
                    mode = newMode;
                    fullRefresh = true;
                    DestroyButtons();
                    Array.Clear(_screenBuf, 0, 640 * 480);
                    if (mode != ButtonIds.BUTTON_SAVE_PANEL)
                        _cursorVisible = false;
                }
                switch (mode)
                {
                    case ButtonIds.BUTTON_MAIN_PANEL:
                        if (fullRefresh)
                            SetupMainPanel();
                        break;
                    case ButtonIds.BUTTON_SAVE_PANEL:
                        if (fullRefresh)
                        {
                            SetupSaveRestorePanel(true);
                        }
                        if (_selectedSavegame < 255)
                        {
                            _system.InputManager.ShowVirtualKeyboard();
                            bool visible = _cursorVisible;
                            _cursorTick++;
                            if (_cursorTick == 7)
                                _cursorVisible = true;
                            else if (_cursorTick == 14)
                            {
                                _cursorVisible = false;
                                _cursorTick = 0;
                            }
                            if (_keyPressed.GetKeys().Count > 0)
                            {
                                HandleSaveKey(_keyPressed);
                                _keyPressed = new ScummInputState();
                                _system.InputManager.ResetKeys();
                            }
                            else if (_cursorVisible != visible)
                                ShowSavegameNames();
                        }
                        else
                        {
                            _system.InputManager.HideVirtualKeyboard();
                        }
                        break;
                    case ButtonIds.BUTTON_RESTORE_PANEL:
                        if (fullRefresh)
                            SetupSaveRestorePanel(false);
                        break;
                    case ButtonIds.BUTTON_VOLUME_PANEL:
                        if (fullRefresh)
                            SetupVolumePanel();
                        break;
                    default:
                        break;
                }
                if (fullRefresh)
                {
                    fullRefresh = false;
                    _system.GraphicsManager.CopyRectToScreen(_screenBuf, Screen.SCREEN_WIDTH, 0, 0, Screen.SCREEN_WIDTH, 480);
                }
                Delay(1000 / 12);
                newMode = GetClicks(mode, out retVal);
            } while ((newMode != ButtonIds.BUTTON_DONE) && (retVal == 0) && (!SwordEngine.ShouldQuit));

            if (SystemVars.ControlPanelMode == ControlPanelMode.CP_NORMAL)
            {
                byte volL, volR;
                _music.GiveVolume(out volL, out volR);
                // TODO:
                //ConfMan.setInt("music_volume", (int)((volR + volL) / 2));
                //ConfMan.setInt("music_balance", volToBalance(volL, volR));

                _sound.GiveSpeechVol(out volL, out volR);
                // TODO:
                //ConfMan.setInt("speech_volume", (int)((volR + volL) / 2));
                //ConfMan.setInt("speech_balance", volToBalance(volL, volR));

                _sound.GiveSfxVol(out volL, out volR);
                // TODO:
                //ConfMan.setInt("sfx_volume", (int)((volR + volL) / 2));
                //ConfMan.setInt("sfx_balance", volToBalance(volL, volR));

                //ConfMan.setBool("subtitles", SystemVars.ShowText == 1);
                //ConfMan.flushToDisk();
            }

            DestroyButtons();
            _resMan.ResClose(fontId);
            _resMan.ResClose(redFontId);
            Array.Clear(_screenBuf, 0, 640 * 480);
            _system.GraphicsManager.CopyRectToScreen(_screenBuf, 640, 0, 0, 640, 480);
            _screenBuf = null;
            _mouse.ControlPanel(false);
            // Can also be used to end the control panel music.
            _music.StartMusic((int)Logic.ScriptVars[(int)ScriptVariableNames.CURRENT_MUSIC], 1);
            _sound.NewScreen(Logic.ScriptVars[(int)ScriptVariableNames.SCREEN]);
            _panelShown = false;
            return retVal;
        }
コード例 #16
0
ファイル: SwordEngine.cs プロジェクト: scemino/nscumm
        private byte MainLoop()
        {
            byte retCode = 0;
            System.InputManager.ResetKeys();

            while ((retCode == 0) && !ShouldQuit)
            {
                // do we need the section45-hack from sword.c here?
                CheckCd();

                _screen.NewScreen(Logic.ScriptVars[(int)ScriptVariableNames.NEW_SCREEN]);
                _logic.NewScreen(Logic.ScriptVars[(int)ScriptVariableNames.NEW_SCREEN]);
                _sound.NewScreen(Logic.ScriptVars[(int)ScriptVariableNames.NEW_SCREEN]);
                Logic.ScriptVars[(int)ScriptVariableNames.SCREEN] = Logic.ScriptVars[(int)ScriptVariableNames.NEW_SCREEN];

                do
                {
                    int newTime;
                    bool scrollFrameShown = false;

                    int frameTime = Environment.TickCount;
                    _logic.Engine();
                    _logic.UpdateScreenParams(); // sets scrolling

                    _screen.Draw();
                    _mouse.Animate();
                    _sound.Engine();
                    _menu.Refresh(Menu.MENU_TOP);
                    _menu.Refresh(Menu.MENU_BOT);

                    newTime = Environment.TickCount;
                    if (newTime - frameTime < 1000 / FRAME_RATE)
                    {
                        scrollFrameShown = _screen.ShowScrollFrame();
                        Delay(1000 / (FRAME_RATE * 2) - (Environment.TickCount - frameTime));
                    }

                    newTime = Environment.TickCount;
                    if ((newTime - frameTime < 1000 / FRAME_RATE) || !scrollFrameShown)
                        _screen.UpdateScreen();
                    Delay(1000 / FRAME_RATE - (Environment.TickCount - frameTime));

                    _mouse.Engine((ushort)_mouseCoord.X, (ushort)_mouseCoord.Y, _mouseState);

                    if (SystemVars.ForceRestart)
                        retCode = Control.CONTROL_RESTART_GAME;

                    // The control panel is triggered by F5 or ESC.
                    else if (((_keyPressed.IsKeyDown(KeyCode.F5) || _keyPressed.IsKeyDown(KeyCode.Escape))
                             && (Logic.ScriptVars[(int)ScriptVariableNames.MOUSE_STATUS] & 1) != 0)
                             || (SystemVars.ControlPanelMode != 0))
                    {
                        retCode = _control.RunPanel();
                        if (retCode == Control.CONTROL_NOTHING_DONE)
                            _screen.FullRefresh();
                    }

                    // TODO: Check for Debugger Activation
                    //if (_keyPressed.hasFlags(Common::KBD_CTRL) && _keyPressed.keycode == Common::KEYCODE_d)
                    //{
                    //    this.getDebugger().attach();
                    //    this.getDebugger().onFrame();
                    //}

                    _mouseState = 0;
                    _keyPressed = new ScummInputState();
                } while ((Logic.ScriptVars[(int)ScriptVariableNames.SCREEN] == Logic.ScriptVars[(int)ScriptVariableNames.NEW_SCREEN]) && (retCode == 0) && !ShouldQuit);

                if ((retCode == 0) && (Logic.ScriptVars[(int)ScriptVariableNames.SCREEN] != 53) && SystemVars.WantFade && !ShouldQuit)
                {
                    _screen.FadeDownPalette();
                    int relDelay = Environment.TickCount;
                    while (_screen.StillFading())
                    {
                        relDelay += 1000 / FRAME_RATE;
                        _screen.UpdateScreen();
                        Delay(relDelay - Environment.TickCount);
                    }
                }

                _sound.QuitScreen();
                _screen.QuitScreen(); // close graphic resources
                _objectMan.CloseSection(Logic.ScriptVars[(int)ScriptVariableNames.SCREEN]); // close the section that PLAYER has just left, if it's empty now
            }
            return retCode;
        }
コード例 #17
0
ファイル: SwordEngine.cs プロジェクト: scemino/nscumm
        private void Delay(int delayInMs)
        {

            int start = Environment.TickCount;

            do
            {
                var inputState = System.InputManager.GetState();
                _mouseCoord = System.InputManager.GetMousePosition();
                _keyPressed = inputState;
                _mouseState |= (ushort)(inputState.IsLeftButtonDown ? Mouse.BS1L_BUTTON_DOWN : Mouse.BS1L_BUTTON_UP);
                _mouseState |= (ushort)(inputState.IsRightButtonDown ? Mouse.BS1R_BUTTON_DOWN : Mouse.BS1R_BUTTON_UP);

                System.GraphicsManager.UpdateScreen();

                if (delayInMs > 0)
                    ServiceLocator.Platform.Sleep(10);

            } while (Environment.TickCount < start + delayInMs);
        }
コード例 #18
0
        private byte MainLoop()
        {
            byte retCode = 0;

            System.InputManager.ResetKeys();

            while ((retCode == 0) && !ShouldQuit)
            {
                // do we need the section45-hack from sword.c here?
                CheckCd();

                _screen.NewScreen(Logic.ScriptVars[(int)ScriptVariableNames.NEW_SCREEN]);
                _logic.NewScreen(Logic.ScriptVars[(int)ScriptVariableNames.NEW_SCREEN]);
                _sound.NewScreen(Logic.ScriptVars[(int)ScriptVariableNames.NEW_SCREEN]);
                Logic.ScriptVars[(int)ScriptVariableNames.SCREEN] = Logic.ScriptVars[(int)ScriptVariableNames.NEW_SCREEN];

                do
                {
                    int  newTime;
                    bool scrollFrameShown = false;

                    int frameTime = Environment.TickCount;
                    _logic.Engine();
                    _logic.UpdateScreenParams(); // sets scrolling

                    _screen.Draw();
                    _mouse.Animate();
                    _sound.Engine();
                    _menu.Refresh(Menu.MENU_TOP);
                    _menu.Refresh(Menu.MENU_BOT);

                    newTime = Environment.TickCount;
                    if (newTime - frameTime < 1000 / FRAME_RATE)
                    {
                        scrollFrameShown = _screen.ShowScrollFrame();
                        Delay(1000 / (FRAME_RATE * 2) - (Environment.TickCount - frameTime));
                    }

                    newTime = Environment.TickCount;
                    if ((newTime - frameTime < 1000 / FRAME_RATE) || !scrollFrameShown)
                    {
                        _screen.UpdateScreen();
                    }
                    Delay(1000 / FRAME_RATE - (Environment.TickCount - frameTime));

                    _mouse.Engine((ushort)_mouseCoord.X, (ushort)_mouseCoord.Y, _mouseState);

                    if (SystemVars.ForceRestart)
                    {
                        retCode = Control.CONTROL_RESTART_GAME;
                    }

                    // The control panel is triggered by F5 or ESC.
                    else if (((_keyPressed.IsKeyDown(KeyCode.F5) || _keyPressed.IsKeyDown(KeyCode.Escape)) &&
                              (Logic.ScriptVars[(int)ScriptVariableNames.MOUSE_STATUS] & 1) != 0) ||
                             (SystemVars.ControlPanelMode != 0))
                    {
                        retCode = _control.RunPanel();
                        if (retCode == Control.CONTROL_NOTHING_DONE)
                        {
                            _screen.FullRefresh();
                        }
                    }

                    // TODO: Check for Debugger Activation
                    //if (_keyPressed.hasFlags(Common::KBD_CTRL) && _keyPressed.keycode == Common::KEYCODE_d)
                    //{
                    //    this.getDebugger().attach();
                    //    this.getDebugger().onFrame();
                    //}

                    _mouseState = 0;
                    _keyPressed = new ScummInputState();
                } while ((Logic.ScriptVars[(int)ScriptVariableNames.SCREEN] == Logic.ScriptVars[(int)ScriptVariableNames.NEW_SCREEN]) && (retCode == 0) && !ShouldQuit);

                if ((retCode == 0) && (Logic.ScriptVars[(int)ScriptVariableNames.SCREEN] != 53) && SystemVars.WantFade && !ShouldQuit)
                {
                    _screen.FadeDownPalette();
                    int relDelay = Environment.TickCount;
                    while (_screen.StillFading())
                    {
                        relDelay += 1000 / FRAME_RATE;
                        _screen.UpdateScreen();
                        Delay(relDelay - Environment.TickCount);
                    }
                }

                _sound.QuitScreen();
                _screen.QuitScreen();                                                       // close graphic resources
                _objectMan.CloseSection(Logic.ScriptVars[(int)ScriptVariableNames.SCREEN]); // close the section that PLAYER has just left, if it's empty now
            }
            return(retCode);
        }
コード例 #19
0
ファイル: SkyEngine.cs プロジェクト: scemino/nscumm
        private void HandleKey()
        {
            if (_keyPressed.GetKeys().Count > 0 && SystemVars.Instance.Paused)
            {
                _skySound.FnUnPauseFx();
                SystemVars.Instance.Paused = false;
                _skyScreen.SetPaletteEndian(_skyCompact.FetchCptRaw((ushort)SystemVars.Instance.CurrentPalette));
            }
            else if (_keyPressed.IsKeyDown(KeyCode.LeftControl))
            {
                if (_keyPressed.IsKeyDown(KeyCode.F))
                    _fastMode ^= 1;
                else if (_keyPressed.IsKeyDown(KeyCode.G))
                    _fastMode ^= 2;
                // TODO: debugger
                //else if (_keyPressed.keycode == Common::KEYCODE_d)
                //    _debugger.attach();
            }
            else
            {

                // TODO: debugger
                //case Common::KEYCODE_BACKQUOTE:
                //case Common::KEYCODE_HASH:
                //    _debugger.attach();
                //    break;
                if (_keyPressed.IsKeyDown(KeyCode.F5))
                {
                    _skyControl.DoControlPanel();
                }

                if (_keyPressed.IsKeyDown(KeyCode.Escape))
                {
                    if (!SystemVars.Instance.PastIntro)
                        _skyControl.RestartGame();
                }
                if (_keyPressed.IsKeyDown(KeyCode.OemPeriod))
                {
                    _skyMouse.LogicClick();
                }
                if (_keyPressed.IsKeyDown(KeyCode.P))
                {
                    _skyScreen.HalvePalette();
                    _skySound.FnPauseFx();
                    SystemVars.Instance.Paused = true;
                }
            }
            _keyPressed = new ScummInputState();
            _system.InputManager.ResetKeys();
        }
コード例 #20
0
ファイル: Control.cs プロジェクト: scemino/nscumm
        private void Delay(int msecs)
        {
            var now = Environment.TickCount;
            var endTime = now + msecs;
            _keyPressed = new ScummInputState();
            _mouseState = 0;

            do
            {
                _keyPressed = _system.InputManager.GetState();
                if (_keyPressed.GetKeys().Count > 0)
                {
                    // we skip the rest of the delay and return immediately
                    // to handle keyboard input
                    return;
                }

                _mouseCoord = _system.InputManager.GetMousePosition();
                _mouseDown = _keyPressed.IsLeftButtonDown;
                _mouseState |= (ushort)(_mouseDown ? Mouse.BS1L_BUTTON_DOWN : Mouse.BS1L_BUTTON_UP);

                _system.GraphicsManager.UpdateScreen();
                ServiceLocator.Platform.Sleep(10);
            } while (Environment.TickCount < endTime);
        }