From 14ef69c0f6309d64a358b25cf6395bc80a4c6ff5 Mon Sep 17 00:00:00 2001 From: Kae <80987908+Novaenia@users.noreply.github.com> Date: Mon, 26 Jun 2023 20:40:32 +1000 Subject: [PATCH] Move error screen over title --- source/client/StarClientApplication.cpp | 33 +++++++++++++------------ source/frontend/StarErrorScreen.cpp | 31 ++++++++++++----------- source/frontend/StarErrorScreen.hpp | 4 +-- source/game/StarUniverseClient.cpp | 6 ++--- 4 files changed, 36 insertions(+), 38 deletions(-) diff --git a/source/client/StarClientApplication.cpp b/source/client/StarClientApplication.cpp index 542e41b..907f357 100644 --- a/source/client/StarClientApplication.cpp +++ b/source/client/StarClientApplication.cpp @@ -274,12 +274,12 @@ void ClientApplication::processInput(InputEvent const& event) { }); } + if (!m_errorScreen->accepted() && m_errorScreen->handleInputEvent(event)) + return; + if (m_state == MainAppState::Splash) { m_cinematicOverlay->handleInputEvent(event); - } else if (m_state == MainAppState::ModsWarning || m_state == MainAppState::Error) { - m_errorScreen->handleInputEvent(event); - } else if (m_state == MainAppState::Title) { if (!m_cinematicOverlay->handleInputEvent(event)) m_titleScreen->handleInputEvent(event); @@ -305,10 +305,14 @@ void ClientApplication::update() { } } + if (!m_errorScreen->accepted()) + m_errorScreen->update(); + if (m_state == MainAppState::Mods) updateMods(); else if (m_state == MainAppState::ModsWarning) updateModsWarning(); + if (m_state == MainAppState::Splash) updateSplash(); else if (m_state == MainAppState::Error) @@ -351,9 +355,10 @@ void ClientApplication::render() { m_mainInterface->render(); m_cinematicOverlay->render(); - } else if (m_state == MainAppState::ModsWarning || m_state == MainAppState::Error) { - m_errorScreen->render(); } + + if (!m_errorScreen->accepted()) + m_errorScreen->render(m_state == MainAppState::ModsWarning || m_state == MainAppState::Error); } void ClientApplication::getAudioData(int16_t* sampleData, size_t frameCount) { @@ -395,9 +400,11 @@ void ClientApplication::changeState(MainAppState newState) { } } - if (oldState > MainAppState::Title && m_state == MainAppState::Title) + if (oldState > MainAppState::Title && m_state == MainAppState::Title) { m_titleScreen->resetState(); - + m_mainMixer->setUniverseClient({}); + m_mainMixer->setWorldPainter({}); + } if (oldState >= MainAppState::Title && m_state < MainAppState::Title) { m_playerStorage.reset(); @@ -547,13 +554,12 @@ void ClientApplication::changeState(MainAppState newState) { void ClientApplication::setError(String const& error) { Logger::error(error.utf8Ptr()); m_errorScreen->setMessage(error); - changeState(MainAppState::Error); + changeState(MainAppState::Title); } void ClientApplication::setError(String const& error, std::exception const& e) { Logger::error("%s\n%s", error, outputException(e, true)); m_errorScreen->setMessage(strf("%s\n%s", error, outputException(e, false))); - changeState(MainAppState::Error); } void ClientApplication::updateMods() { @@ -596,8 +602,6 @@ void ClientApplication::updateMods() { } void ClientApplication::updateModsWarning() { - m_errorScreen->update(); - if (m_errorScreen->accepted()) changeState(MainAppState::Splash); } @@ -609,8 +613,6 @@ void ClientApplication::updateSplash() { } void ClientApplication::updateError() { - m_errorScreen->update(); - if (m_errorScreen->accepted()) changeState(MainAppState::Title); } @@ -761,9 +763,8 @@ void ClientApplication::updateRunning() { errMessage = strf("You were disconnected from the server for the following reason:\n%s", *disconnectReason); else errMessage = "Client-server connection no longer valid!"; - Logger::error(errMessage.utf8Ptr()); - m_errorScreen->setMessage(errMessage); - changeState(MainAppState::Error); + setError(errMessage); + changeState(MainAppState::Title); return true; } diff --git a/source/frontend/StarErrorScreen.cpp b/source/frontend/StarErrorScreen.cpp index 6d4e6b3..6367d05 100644 --- a/source/frontend/StarErrorScreen.cpp +++ b/source/frontend/StarErrorScreen.cpp @@ -12,7 +12,7 @@ namespace Star { ErrorScreen::ErrorScreen() { m_paneManager = make_shared(); - m_accepted = false; + m_accepted = true; auto assets = Root::singleton().assets(); @@ -39,25 +39,26 @@ bool ErrorScreen::accepted() { return m_accepted; } -void ErrorScreen::render() { - auto assets = Root::singleton().assets(); +void ErrorScreen::render(bool useBackdrop) { + if (useBackdrop) { + auto assets = Root::singleton().assets(); - for (auto backdropImage : assets->json("/interface/windowconfig/title.config:backdropImages").toArray()) { - Vec2F offset = jsonToVec2F(backdropImage.get(0)) * interfaceScale(); - String image = backdropImage.getString(1); - float scale = backdropImage.getFloat(2); - Vec2F imageSize = Vec2F(m_guiContext->textureSize(image)) * interfaceScale() * scale; + for (auto backdropImage : assets->json("/interface/windowconfig/title.config:backdropImages").toArray()) { + Vec2F offset = jsonToVec2F(backdropImage.get(0)) * interfaceScale(); + String image = backdropImage.getString(1); + float scale = backdropImage.getFloat(2); + Vec2F imageSize = Vec2F(m_guiContext->textureSize(image)) * interfaceScale() * scale; - Vec2F lowerLeft = Vec2F(windowWidth() / 2.0f, windowHeight()); - lowerLeft[0] -= imageSize[0] / 2; - lowerLeft[1] -= imageSize[1]; - lowerLeft += offset; - RectF screenCoords(lowerLeft, lowerLeft + imageSize); - m_guiContext->drawQuad(image, screenCoords); + Vec2F lowerLeft = Vec2F(windowWidth() / 2.0f, windowHeight()); + lowerLeft[0] -= imageSize[0] / 2; + lowerLeft[1] -= imageSize[1]; + lowerLeft += offset; + RectF screenCoords(lowerLeft, lowerLeft + imageSize); + m_guiContext->drawQuad(image, screenCoords); + } } m_paneManager->render(); - renderCursor(); } bool ErrorScreen::handleInputEvent(InputEvent const& event) { diff --git a/source/frontend/StarErrorScreen.hpp b/source/frontend/StarErrorScreen.hpp index b289678..eb1f73e 100644 --- a/source/frontend/StarErrorScreen.hpp +++ b/source/frontend/StarErrorScreen.hpp @@ -23,7 +23,7 @@ public: bool accepted(); - void render(); + void render(bool useBackdrop = false); bool handleInputEvent(InputEvent const& event); void update(); @@ -31,8 +31,6 @@ public: private: void renderCursor(); - void back(); - float interfaceScale() const; unsigned windowHeight() const; unsigned windowWidth() const; diff --git a/source/game/StarUniverseClient.cpp b/source/game/StarUniverseClient.cpp index dcfd0c7..d67d498 100644 --- a/source/game/StarUniverseClient.cpp +++ b/source/game/StarUniverseClient.cpp @@ -493,7 +493,7 @@ void UniverseClient::handlePackets(List const& packets) { } else if (auto serverDisconnectPacket = as(packet)) { reset(); m_disconnectReason = serverDisconnectPacket->reason; - m_mainPlayer = {}; + break; // Stop handling other packets } else if (auto celestialResponse = as(packet)) { m_celestialDatabase->pushResponses(move(celestialResponse->responses)); @@ -542,10 +542,8 @@ void UniverseClient::reset() { m_warpDelay = GameTimer(assets->json("/client.config:playerWarpDelay").toFloat()); m_respawnTimer = GameTimer(assets->json("/client.config:playerReviveTime").toFloat()); - if (m_mainPlayer) { - m_mainPlayer->setClientContext({}); + if (m_mainPlayer) m_playerStorage->savePlayer(m_mainPlayer); - } m_connection.reset(); }