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) {
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;
}

View File

@ -12,7 +12,7 @@ namespace Star {
ErrorScreen::ErrorScreen() {
m_paneManager = make_shared<PaneManager>();
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) {

View File

@ -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;

View File

@ -493,7 +493,7 @@ void UniverseClient::handlePackets(List<PacketPtr> const& packets) {
} else if (auto serverDisconnectPacket = as<ServerDisconnectPacket>(packet)) {
reset();
m_disconnectReason = serverDisconnectPacket->reason;
m_mainPlayer = {};
break; // Stop handling other packets
} else if (auto celestialResponse = as<CelestialResponsePacket>(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();
}