Move error screen over title

This commit is contained in:
Kae 2023-06-26 20:40:32 +10:00
parent 68d20787cf
commit 14ef69c0f6
4 changed files with 36 additions and 38 deletions

View File

@ -274,12 +274,12 @@ void ClientApplication::processInput(InputEvent const& event) {
}); });
} }
if (!m_errorScreen->accepted() && m_errorScreen->handleInputEvent(event))
return;
if (m_state == MainAppState::Splash) { if (m_state == MainAppState::Splash) {
m_cinematicOverlay->handleInputEvent(event); m_cinematicOverlay->handleInputEvent(event);
} else if (m_state == MainAppState::ModsWarning || m_state == MainAppState::Error) {
m_errorScreen->handleInputEvent(event);
} else if (m_state == MainAppState::Title) { } else if (m_state == MainAppState::Title) {
if (!m_cinematicOverlay->handleInputEvent(event)) if (!m_cinematicOverlay->handleInputEvent(event))
m_titleScreen->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) if (m_state == MainAppState::Mods)
updateMods(); updateMods();
else if (m_state == MainAppState::ModsWarning) else if (m_state == MainAppState::ModsWarning)
updateModsWarning(); updateModsWarning();
if (m_state == MainAppState::Splash) if (m_state == MainAppState::Splash)
updateSplash(); updateSplash();
else if (m_state == MainAppState::Error) else if (m_state == MainAppState::Error)
@ -351,9 +355,10 @@ void ClientApplication::render() {
m_mainInterface->render(); m_mainInterface->render();
m_cinematicOverlay->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) { 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_titleScreen->resetState();
m_mainMixer->setUniverseClient({});
m_mainMixer->setWorldPainter({});
}
if (oldState >= MainAppState::Title && m_state < MainAppState::Title) { if (oldState >= MainAppState::Title && m_state < MainAppState::Title) {
m_playerStorage.reset(); m_playerStorage.reset();
@ -547,13 +554,12 @@ void ClientApplication::changeState(MainAppState newState) {
void ClientApplication::setError(String const& error) { void ClientApplication::setError(String const& error) {
Logger::error(error.utf8Ptr()); Logger::error(error.utf8Ptr());
m_errorScreen->setMessage(error); m_errorScreen->setMessage(error);
changeState(MainAppState::Error); changeState(MainAppState::Title);
} }
void ClientApplication::setError(String const& error, std::exception const& e) { void ClientApplication::setError(String const& error, std::exception const& e) {
Logger::error("%s\n%s", error, outputException(e, true)); Logger::error("%s\n%s", error, outputException(e, true));
m_errorScreen->setMessage(strf("%s\n%s", error, outputException(e, false))); m_errorScreen->setMessage(strf("%s\n%s", error, outputException(e, false)));
changeState(MainAppState::Error);
} }
void ClientApplication::updateMods() { void ClientApplication::updateMods() {
@ -596,8 +602,6 @@ void ClientApplication::updateMods() {
} }
void ClientApplication::updateModsWarning() { void ClientApplication::updateModsWarning() {
m_errorScreen->update();
if (m_errorScreen->accepted()) if (m_errorScreen->accepted())
changeState(MainAppState::Splash); changeState(MainAppState::Splash);
} }
@ -609,8 +613,6 @@ void ClientApplication::updateSplash() {
} }
void ClientApplication::updateError() { void ClientApplication::updateError() {
m_errorScreen->update();
if (m_errorScreen->accepted()) if (m_errorScreen->accepted())
changeState(MainAppState::Title); 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); errMessage = strf("You were disconnected from the server for the following reason:\n%s", *disconnectReason);
else else
errMessage = "Client-server connection no longer valid!"; errMessage = "Client-server connection no longer valid!";
Logger::error(errMessage.utf8Ptr()); setError(errMessage);
m_errorScreen->setMessage(errMessage); changeState(MainAppState::Title);
changeState(MainAppState::Error);
return true; return true;
} }

View File

@ -12,7 +12,7 @@ namespace Star {
ErrorScreen::ErrorScreen() { ErrorScreen::ErrorScreen() {
m_paneManager = make_shared<PaneManager>(); m_paneManager = make_shared<PaneManager>();
m_accepted = false; m_accepted = true;
auto assets = Root::singleton().assets(); auto assets = Root::singleton().assets();
@ -39,25 +39,26 @@ bool ErrorScreen::accepted() {
return m_accepted; return m_accepted;
} }
void ErrorScreen::render() { void ErrorScreen::render(bool useBackdrop) {
auto assets = Root::singleton().assets(); if (useBackdrop) {
auto assets = Root::singleton().assets();
for (auto backdropImage : assets->json("/interface/windowconfig/title.config:backdropImages").toArray()) { for (auto backdropImage : assets->json("/interface/windowconfig/title.config:backdropImages").toArray()) {
Vec2F offset = jsonToVec2F(backdropImage.get(0)) * interfaceScale(); Vec2F offset = jsonToVec2F(backdropImage.get(0)) * interfaceScale();
String image = backdropImage.getString(1); String image = backdropImage.getString(1);
float scale = backdropImage.getFloat(2); float scale = backdropImage.getFloat(2);
Vec2F imageSize = Vec2F(m_guiContext->textureSize(image)) * interfaceScale() * scale; Vec2F imageSize = Vec2F(m_guiContext->textureSize(image)) * interfaceScale() * scale;
Vec2F lowerLeft = Vec2F(windowWidth() / 2.0f, windowHeight()); Vec2F lowerLeft = Vec2F(windowWidth() / 2.0f, windowHeight());
lowerLeft[0] -= imageSize[0] / 2; lowerLeft[0] -= imageSize[0] / 2;
lowerLeft[1] -= imageSize[1]; lowerLeft[1] -= imageSize[1];
lowerLeft += offset; lowerLeft += offset;
RectF screenCoords(lowerLeft, lowerLeft + imageSize); RectF screenCoords(lowerLeft, lowerLeft + imageSize);
m_guiContext->drawQuad(image, screenCoords); m_guiContext->drawQuad(image, screenCoords);
}
} }
m_paneManager->render(); m_paneManager->render();
renderCursor();
} }
bool ErrorScreen::handleInputEvent(InputEvent const& event) { bool ErrorScreen::handleInputEvent(InputEvent const& event) {

View File

@ -23,7 +23,7 @@ public:
bool accepted(); bool accepted();
void render(); void render(bool useBackdrop = false);
bool handleInputEvent(InputEvent const& event); bool handleInputEvent(InputEvent const& event);
void update(); void update();
@ -31,8 +31,6 @@ public:
private: private:
void renderCursor(); void renderCursor();
void back();
float interfaceScale() const; float interfaceScale() const;
unsigned windowHeight() const; unsigned windowHeight() const;
unsigned windowWidth() const; unsigned windowWidth() const;

View File

@ -493,7 +493,7 @@ void UniverseClient::handlePackets(List<PacketPtr> const& packets) {
} else if (auto serverDisconnectPacket = as<ServerDisconnectPacket>(packet)) { } else if (auto serverDisconnectPacket = as<ServerDisconnectPacket>(packet)) {
reset(); reset();
m_disconnectReason = serverDisconnectPacket->reason; m_disconnectReason = serverDisconnectPacket->reason;
m_mainPlayer = {}; break; // Stop handling other packets
} else if (auto celestialResponse = as<CelestialResponsePacket>(packet)) { } else if (auto celestialResponse = as<CelestialResponsePacket>(packet)) {
m_celestialDatabase->pushResponses(move(celestialResponse->responses)); m_celestialDatabase->pushResponses(move(celestialResponse->responses));
@ -542,10 +542,8 @@ void UniverseClient::reset() {
m_warpDelay = GameTimer(assets->json("/client.config:playerWarpDelay").toFloat()); m_warpDelay = GameTimer(assets->json("/client.config:playerWarpDelay").toFloat());
m_respawnTimer = GameTimer(assets->json("/client.config:playerReviveTime").toFloat()); m_respawnTimer = GameTimer(assets->json("/client.config:playerReviveTime").toFloat());
if (m_mainPlayer) { if (m_mainPlayer)
m_mainPlayer->setClientContext({});
m_playerStorage->savePlayer(m_mainPlayer); m_playerStorage->savePlayer(m_mainPlayer);
}
m_connection.reset(); m_connection.reset();
} }