diff --git a/src/saland.cpp b/src/saland.cpp index 19956d2..e182c41 100644 --- a/src/saland.cpp +++ b/src/saland.cpp @@ -134,9 +134,15 @@ void UpdateMouseCoordinates(const SDL_Event& event, int& mousex, int& mousey) { } } +void ResetFullscreen(); + void RunGameState(sago::GameStateInterface& state ) { bool done = false; //We are done! while (!done && !globalData.isShuttingDown) { + if (globalData.resetVideo) { + ResetFullscreen(); + globalData.resetVideo = false; + } SDL_SetRenderDrawColor(globalData.screen, 0, 0, 0, 0); SDL_RenderClear(globalData.screen); state.Draw(globalData.screen); @@ -150,6 +156,13 @@ void RunGameState(sago::GameStateInterface& state ) { done = true; } + if (event.type == SDL_KEYDOWN) { + if (!globalData.resetVideo && event.key.keysym.sym == SDLK_RETURN && event.key.keysym.mod & KMOD_LALT) { + globalData.fullscreen = !globalData.fullscreen; + globalData.resetVideo = true; + } + } + bool processed = false; state.ProcessInput(event, processed); @@ -171,13 +184,16 @@ void startWorld() { RunGameState(g); } -void ResetFullscreen(SDL_Window* sdlWindow, sago::SagoDataHolder& dataHolder) { +static SDL_Window* win = nullptr; + +void ResetFullscreen() { + sago::SagoDataHolder& dataHolder = *globalData.dataHolder; Mix_HaltMusic(); //We need to reload all data in case the screen type changes. Music must be stopped before unload. if (globalData.fullscreen) { - SDL_SetWindowFullscreen(sdlWindow, SDL_WINDOW_FULLSCREEN_DESKTOP); + SDL_SetWindowFullscreen(win, SDL_WINDOW_FULLSCREEN_DESKTOP); } else { - SDL_SetWindowFullscreen(sdlWindow, 0); + SDL_SetWindowFullscreen(win, 0); } dataHolder.invalidateAll(globalData.screen); globalData.spriteHolder.reset(new sago::SagoSpriteHolder( dataHolder ) ); @@ -194,13 +210,13 @@ void runGame() { globalData.fullscreen = Config::getInstance()->getInt("fullscreen"); - SDL_Window* win = SDL_CreateWindow("Saland Adventures", posX, posY, width, height, 0); + win = SDL_CreateWindow("Saland Adventures", posX, posY, width, height, 0); globalData.screen = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED); //SDL_RenderSetLogicalSize(globalData.screen, 1024, 768); sago::SagoDataHolder holder(globalData.screen); globalData.spriteHolder.reset(new sago::SagoSpriteHolder(holder)); globalData.dataHolder = &holder; - ResetFullscreen(win, *globalData.dataHolder); + ResetFullscreen(); TitleScreen ts; RunGameState(ts); diff --git a/src/saland/console/Console.cpp b/src/saland/console/Console.cpp index 693a0e1..0d02685 100644 --- a/src/saland/console/Console.cpp +++ b/src/saland/console/Console.cpp @@ -84,6 +84,17 @@ void Console::removeChar() { } } +void Console::ProcessCommand(const std::string& command) { + sago::SagoTextField f; + SetFieldValues(f); + f.SetText(command); + historyField.push_back(std::move(f)); + sago::SagoTextField response; + SetFieldValues(response); + response.SetText(std::string(" \"")+command+"\" not recognized"); + historyField.push_back(std::move(response)); +} + bool Console::ReadKey(SDL_Keycode keyPressed) { if (keyPressed == SDLK_DELETE) { if ((editLine.length()>0)&& (editPosition 0) { commandHistory.push_back(editLine); - sago::SagoTextField f; - SetFieldValues(f); - f.SetText(editLine); - historyField.push_back(std::move(f)); + ProcessCommand(editLine); } editLine.clear(); editPosition = editLine.begin(); diff --git a/src/saland/console/Console.hpp b/src/saland/console/Console.hpp index 94eaf9f..fa99cb2 100644 --- a/src/saland/console/Console.hpp +++ b/src/saland/console/Console.hpp @@ -44,6 +44,7 @@ private: void putchar(const std::string& thing); bool ReadKey(SDL_Keycode keyPressed); void removeChar(); + void ProcessCommand(const std::string& command); bool active = true; std::vector commandHistory; std::string editLine; diff --git a/src/saland/globals.hpp b/src/saland/globals.hpp index 75613a3..bbe5247 100644 --- a/src/saland/globals.hpp +++ b/src/saland/globals.hpp @@ -30,6 +30,7 @@ https://github.com/sago007/saland struct GlobalData { bool isShuttingDown = false; bool fullscreen = false; + bool resetVideo = false; SDL_Renderer* screen = nullptr; std::unique_ptr spriteHolder; sago::SagoDataHolder* dataHolder;