mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-15 10:35:11 -04:00
Webclient: In singleplayer, show confirmation dialog before closing page unless map was saved within last 5 seconds
This commit is contained in:
parent
e60e852eee
commit
c8c7379289
@ -649,6 +649,11 @@ static void Game_RunLoop(void) {
|
|||||||
/* Now thats there's a main loop, Game_SetFpsLimit will actually do something */
|
/* Now thats there's a main loop, Game_SetFpsLimit will actually do something */
|
||||||
Game_SetFpsLimit(Options_GetEnum(OPT_FPS_LIMIT, 0, FpsLimit_Names, FPS_LIMIT_COUNT));
|
Game_SetFpsLimit(Options_GetEnum(OPT_FPS_LIMIT, 0, FpsLimit_Names, FPS_LIMIT_COUNT));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cc_bool Game_ShouldClose(void) {
|
||||||
|
/* Running in multiplayer or map was saved within last 5 seconds */
|
||||||
|
return !Server.IsSinglePlayer || (World.LastSave + 5 >= Game.Time);
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
static void Game_RunLoop(void) {
|
static void Game_RunLoop(void) {
|
||||||
cc_uint64 lastRender, render;
|
cc_uint64 lastRender, render;
|
||||||
|
@ -78,6 +78,8 @@ void Game_SetFpsLimit(int method);
|
|||||||
|
|
||||||
/* Runs the main game loop until the window is closed. */
|
/* Runs the main game loop until the window is closed. */
|
||||||
void Game_Run(int width, int height, const cc_string* title);
|
void Game_Run(int width, int height, const cc_string* title);
|
||||||
|
/* Whether the game should be allowed to automatically close */
|
||||||
|
cc_bool Game_ShouldClose(void);
|
||||||
|
|
||||||
/* Represents a game component. */
|
/* Represents a game component. */
|
||||||
struct IGameComponent;
|
struct IGameComponent;
|
||||||
|
@ -1398,6 +1398,7 @@ static void SaveLevelScreen_SaveMap(struct SaveLevelScreen* s, const cc_string*
|
|||||||
#else
|
#else
|
||||||
Chat_Add1("&eSaved map to: %s", path);
|
Chat_Add1("&eSaved map to: %s", path);
|
||||||
#endif
|
#endif
|
||||||
|
World.LastSave = Game.Time;
|
||||||
Gui_ShowPauseMenu();
|
Gui_ShowPauseMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2745,6 +2745,7 @@ void Window_FreeFramebuffer(struct Bitmap* bmp) {
|
|||||||
#include <emscripten/emscripten.h>
|
#include <emscripten/emscripten.h>
|
||||||
#include <emscripten/html5.h>
|
#include <emscripten/html5.h>
|
||||||
#include <emscripten/key_codes.h>
|
#include <emscripten/key_codes.h>
|
||||||
|
#include "Game.h"
|
||||||
static cc_bool keyboardOpen, needResize;
|
static cc_bool keyboardOpen, needResize;
|
||||||
|
|
||||||
static int RawDpiScale(int x) { return (int)(x * emscripten_get_device_pixel_ratio()); }
|
static int RawDpiScale(int x) { return (int)(x * emscripten_get_device_pixel_ratio()); }
|
||||||
@ -2908,6 +2909,12 @@ static EM_BOOL OnFullscreenChange(int type, const EmscriptenFullscreenChangeEven
|
|||||||
}
|
}
|
||||||
|
|
||||||
static const char* OnBeforeUnload(int type, const void* ev, void *data) {
|
static const char* OnBeforeUnload(int type, const void* ev, void *data) {
|
||||||
|
if (!Game_ShouldClose()) {
|
||||||
|
/* Exit pointer lock, otherwise when you press Ctrl+W, the */
|
||||||
|
/* cursor remains invisible in the confirmation dialog */
|
||||||
|
emscripten_exit_pointerlock();
|
||||||
|
return "You have unsaved changes. Are you sure you want to quit?";
|
||||||
|
}
|
||||||
Window_Close();
|
Window_Close();
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,8 @@ void World_Reset(void) {
|
|||||||
World.Blocks = NULL;
|
World.Blocks = NULL;
|
||||||
|
|
||||||
World_SetDimensions(0, 0, 0);
|
World_SetDimensions(0, 0, 0);
|
||||||
World.Loaded = false;
|
World.Loaded = false;
|
||||||
|
World.LastSave = -200;
|
||||||
Env_Reset();
|
Env_Reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,6 +44,8 @@ CC_VAR extern struct _WorldData {
|
|||||||
/* Whether the world has finished loading/generating. */
|
/* Whether the world has finished loading/generating. */
|
||||||
/* NOTE: Blocks may still be NULL. (e.g. error during loading) */
|
/* NOTE: Blocks may still be NULL. (e.g. error during loading) */
|
||||||
cc_bool Loaded;
|
cc_bool Loaded;
|
||||||
|
/* Point in time the current world was last saved at */
|
||||||
|
double LastSave;
|
||||||
} World;
|
} World;
|
||||||
|
|
||||||
/* Frees the blocks array, sets dimensions to 0, resets environment to default. */
|
/* Frees the blocks array, sets dimensions to 0, resets environment to default. */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user