From 0fbbac1cde50c11a61c252beb63b67e2dc78dcfa Mon Sep 17 00:00:00 2001 From: Sally Knight Date: Thu, 19 Mar 2026 15:05:32 +0300 Subject: [PATCH] feat(jui): add world leaving You will now be able to leave the world from all places where you'd usually be able to (Pause screen, death screen) Should be identical to the way it's done on Iggy/XUI --- Minecraft.Client/Minecraft.cpp | 10 ++++++++++ Minecraft.Client/Minecraft.h | 1 + .../Platform/Common/Consoles_App.cpp | 2 +- .../Platform/Common/UI/IUIScene_PauseMenu.cpp | 1 + Minecraft.Client/UI/Screens/DeathScreen.cpp | 5 ++++- Minecraft.Client/UI/Screens/PauseScreen.cpp | 17 ++++++++++++++++- Minecraft.Client/UI/Screens/PauseScreen.h | 1 + 7 files changed, 34 insertions(+), 3 deletions(-) diff --git a/Minecraft.Client/Minecraft.cpp b/Minecraft.Client/Minecraft.cpp index 3eec0758e..bf98a63cb 100644 --- a/Minecraft.Client/Minecraft.cpp +++ b/Minecraft.Client/Minecraft.cpp @@ -122,6 +122,7 @@ Minecraft::Minecraft(Component* mouseComponent, Canvas* parent, user = NULL; parent = NULL; pause = false; + exitingWorldRightNow = false; textures = NULL; font = NULL; screen = NULL; @@ -1254,6 +1255,15 @@ void Minecraft::run_middle() { if (lastTime == 0) lastTime = System::nanoTime(); static int frames = 0; +#ifdef ENABLE_JAVA_GUIS + // 4jcraft: while the java ui is leaving world, don't run the rest of + // run_middle + if (exitingWorldRightNow) { + screen->render(0, 0, 1); + return; + } +#endif + EnterCriticalSection(&m_setLevelCS); if (running) { diff --git a/Minecraft.Client/Minecraft.h b/Minecraft.Client/Minecraft.h index 07b4c1a3b..876801683 100644 --- a/Minecraft.Client/Minecraft.h +++ b/Minecraft.Client/Minecraft.h @@ -137,6 +137,7 @@ public: // 4J - per player ? volatile bool pause; + volatile bool exitingWorldRightNow; Textures* textures; Font *font, *altFont; diff --git a/Minecraft.Client/Platform/Common/Consoles_App.cpp b/Minecraft.Client/Platform/Common/Consoles_App.cpp index 4bcf758e5..e91f2adb2 100644 --- a/Minecraft.Client/Platform/Common/Consoles_App.cpp +++ b/Minecraft.Client/Platform/Common/Consoles_App.cpp @@ -2826,7 +2826,7 @@ void CMinecraftApp::HandleXuiActions(void) #endif case eAppAction_ExitWorld: - + pMinecraft->exitingWorldRightNow = true; SetAction(i,eAppAction_Idle); // If we're already leaving don't exit diff --git a/Minecraft.Client/Platform/Common/UI/IUIScene_PauseMenu.cpp b/Minecraft.Client/Platform/Common/UI/IUIScene_PauseMenu.cpp index c6daed5e5..d880ba677 100644 --- a/Minecraft.Client/Platform/Common/UI/IUIScene_PauseMenu.cpp +++ b/Minecraft.Client/Platform/Common/UI/IUIScene_PauseMenu.cpp @@ -627,6 +627,7 @@ void IUIScene_PauseMenu::_ExitWorld(void *lpParameter) app.SetChangingSessionType(false); app.SetReallyChangingSessionType(false); + pMinecraft->exitingWorldRightNow = false; #if defined(_XBOX_ONE) || defined(__ORBIS__) // Make sure we don't think saving is disabled in the menus diff --git a/Minecraft.Client/UI/Screens/DeathScreen.cpp b/Minecraft.Client/UI/Screens/DeathScreen.cpp index 432378076..2ac5f8960 100644 --- a/Minecraft.Client/UI/Screens/DeathScreen.cpp +++ b/Minecraft.Client/UI/Screens/DeathScreen.cpp @@ -3,6 +3,7 @@ #include "DeathScreen.h" #include "../Button.h" #include "../../Player/MultiPlayerLocalPlayer.h" +#include "PauseScreen.h" #include "TitleScreen.h" void DeathScreen::init() { @@ -30,9 +31,11 @@ void DeathScreen::buttonClicked(Button* button) { // minecraft.setScreen(new NewLevelScreen(this)); } if (button->id == 2) { - // TODO: proper world exits // minecraft->setLevel(NULL); // minecraft->setScreen(new TitleScreen()); + + // 4jcraft: use the static method from PauseScreen to exit + PauseScreen::exitWorld(minecraft, true); } } diff --git a/Minecraft.Client/UI/Screens/PauseScreen.cpp b/Minecraft.Client/UI/Screens/PauseScreen.cpp index fbc602586..fe8fd973c 100644 --- a/Minecraft.Client/UI/Screens/PauseScreen.cpp +++ b/Minecraft.Client/UI/Screens/PauseScreen.cpp @@ -2,6 +2,7 @@ #include "PauseScreen.h" #include "../Button.h" #include "../../GameState/StatsCounter.h" +#include "MessageScreen.h" #include "OptionsScreen.h" #include "TitleScreen.h" #include "../../Level/MultiPlayerLevel.h" @@ -48,12 +49,23 @@ void PauseScreen::init() { */ } +void PauseScreen::exitWorld(Minecraft* minecraft, bool save) { + // 4jcraft: made our own static method for use in the java gui (other + // places such as the deathscreen need this) + MinecraftServer* server = MinecraftServer::getInstance(); + + minecraft->setScreen(new MessageScreen(L"Leaving world")); + if (g_NetworkManager.IsHost()) { + server->setSaveOnExit(save); + } + app.SetAction(minecraft->player->GetXboxPad(), eAppAction_ExitWorld); +} + void PauseScreen::buttonClicked(Button* button) { if (button->id == 0) { minecraft->setScreen(new OptionsScreen(this, minecraft->options)); } if (button->id == 1) { - // TODO: proper disconnects // if (minecraft->isClientSide()) // { // minecraft->level->disconnect(); @@ -61,6 +73,9 @@ void PauseScreen::buttonClicked(Button* button) { // minecraft->setLevel(NULL); // minecraft->setScreen(new TitleScreen()); + + // 4jcraft: exit with our new exitWorld method + exitWorld(minecraft, true); } if (button->id == 4) { minecraft->setScreen(NULL); diff --git a/Minecraft.Client/UI/Screens/PauseScreen.h b/Minecraft.Client/UI/Screens/PauseScreen.h index 3f4f3fd6b..375d03eb6 100644 --- a/Minecraft.Client/UI/Screens/PauseScreen.h +++ b/Minecraft.Client/UI/Screens/PauseScreen.h @@ -9,6 +9,7 @@ private: public: PauseScreen(); // 4J added virtual void init(); + static void exitWorld(Minecraft* minecraft, bool save); protected: using Screen::buttonClicked;