Save level name now defaults to name of last map loaded in singleplayer or saved (Thanks Neonium)

Whenever a new level is generated or loaded in multiplayer, this is reset back to empty string
This commit is contained in:
UnknownShadow200 2022-05-31 20:46:14 +10:00
parent 63280b8519
commit 271b5faa4a
4 changed files with 17 additions and 6 deletions

View file

@ -1401,6 +1401,7 @@ static void SaveLevelScreen_Save(void* screen, void* widget, const char* fmt) {
}
String_InitArray(path, pathBuffer);
String_Format1(&path, fmt, &file);
String_Copy(&World.Name, &file);
if (File_Exists(&path) && !btn->optName) {
btn->optName = "";
@ -1521,7 +1522,7 @@ static void SaveLevelScreen_Init(void* screen) {
#endif
ButtonWidget_Init(&s->cancel, 400, Menu_SwitchPause);
TextInputWidget_Create(&s->input, 500, &String_Empty, &desc);
TextInputWidget_Create(&s->input, 500, &World.Name, &desc);
TextWidget_Init(&s->desc);
s->input.onscreenPlaceholder = "Map name";
}
@ -1743,13 +1744,17 @@ void HotkeyListScreen_Show(void) {
static void LoadLevelScreen_EntryClick(void* screen, void* widget) {
cc_string path; char pathBuffer[FILENAME_SIZE];
struct ListScreen* s = (struct ListScreen*)screen;
cc_string relPath, fileName, fileExt;
cc_result res;
cc_string relPath = ListScreen_UNSAFE_GetCur(s, widget);
relPath = ListScreen_UNSAFE_GetCur(s, widget);
String_InitArray(path, pathBuffer);
String_Format1(&path, "maps/%s", &relPath);
res = Map_LoadFrom(&path);
String_UNSAFE_Separate(&relPath, '.', &fileName, &fileExt);
String_Copy(&World.Name, &fileName);
/* FileNotFound error may be because user deleted maps from disc */
if (res != ReturnCode_FileNotFound) return;
Chat_AddRaw("&eReloading level list as it may be out of date");

View file

@ -359,9 +359,10 @@ static cc_result MapState_Read(struct MapState* m) {
m->sizeIndex += read;
if (res) return res;
/* 0.01% chance to happen, but still possible */
if (m->sizeIndex < MAP_SIZE_LEN) return 0;
}
/* 0.01% chance to happen, but still possible */
if (m->sizeIndex < MAP_SIZE_LEN) return 0;
if (!map_volume) map_volume = Stream_GetU32_BE(m->size);
@ -540,7 +541,7 @@ static void Classic_LevelDataChunk(cc_uint8* data) {
if (res) { DisconnectInvalidMap(res); return; }
}
progress = !map1.blocks ? 0.0f : (float)map1.index / map_volume;
progress = !map_volume ? 0.0f : (float)map1.index / map_volume;
Event_RaiseFloat(&WorldEvents.Loading, progress);
}

View file

@ -12,6 +12,7 @@
#include "Window.h"
struct _WorldData World;
static char nameBuffer[STRING_SIZE];
/*########################################################################################################################*
*----------------------------------------------------------World----------------------------------------------------------*
*#########################################################################################################################*/
@ -44,6 +45,7 @@ void World_Reset(void) {
#endif
Mem_Free(World.Blocks);
World.Blocks = NULL;
String_InitArray(World.Name, nameBuffer);
World_SetDimensions(0, 0, 0);
World.Loaded = false;
@ -61,7 +63,8 @@ void World_SetNewMap(BlockRaw* blocks, int width, int height, int length) {
if (!blocks) { width = 0; height = 0; length = 0; }
World_SetDimensions(width, height, length);
World.Blocks = blocks;
World.Blocks = blocks;
World.Name.length = 0;
if (!World.Volume) World.Blocks = NULL;
#ifdef EXTENDED_BLOCKS

View file

@ -46,6 +46,8 @@ CC_VAR extern struct _WorldData {
cc_bool Loaded;
/* Point in time the current world was last saved at */
double LastSave;
/* Default name of the world when saving */
cc_string Name;
} World;
/* Frees the blocks array, sets dimensions to 0, resets environment to default. */