From: James O'Neill Date: Sun, 21 Apr 2024 17:25:00 +0000 (+0900) Subject: Merge PR 'Use the text from modinfo.txt as the mod menu entry' X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=3848c33ee1e2f6e06afa17984d5f3d3c077fe131;p=xonotic%2Fdarkplaces.git Merge PR 'Use the text from modinfo.txt as the mod menu entry' Copies the text from the `modinfo.txt` into the name field for the mod list entry. If there is no text the mod directory name is used as before. ![image](https://github.com/DarkPlacesEngine/darkplaces/assets/424218/b6b5da57-7590-407e-920c-21bca23ef2bb) Fixes Alkaline 1.2 failing to appear in the mod list (its dir is `alk1.2`). See https://github.com/DarkPlacesEngine/darkplaces/pull/168 --------- Signed-off-by: bones_was_here Co-authored-by: bones_was_here --- diff --git a/menu.c b/menu.c index 74e22004..8034f2f3 100644 --- a/menu.c +++ b/menu.c @@ -4524,7 +4524,7 @@ typedef struct modlist_entry_s qbool loaded; // used to determine whether this entry is loaded and running int enabled; // index to array of modlist_enabled - // name of the modification, this is (will...be) displayed on the menu entry + // name of the modification, this is displayed on the menu entry char name[128]; // directory where we will find it char dir[MAX_QPATH]; @@ -4549,8 +4549,7 @@ static void ModList_RebuildList(void) modlist_numenabled = fs_numgamedirs; for (i = 0;i < list.numstrings && modlist_count < MODLIST_TOTALSIZE;i++) { - // quickly skip names with dot characters - generally these are files, not directories - if (strchr(list.strings[i], '.')) continue; + int desc_len; // reject any dirs that are part of the base game if (gamedirname1 && !strcasecmp(gamedirname1, list.strings[i])) continue; @@ -4562,6 +4561,14 @@ static void ModList_RebuildList(void) description = FS_CheckGameDir(list.strings[i]); if (description == NULL || description == fs_checkgamedir_missing) continue; + desc_len = min(strlen(description), sizeof(modlist[modlist_count].name)); + for (j = 0; j < desc_len; ++j) + if (!ISWHITESPACE(description[j])) + { + dp_strlcpy(modlist[modlist_count].name, description, sizeof(modlist[modlist_count].name)); + break; + } + dp_strlcpy (modlist[modlist_count].dir, list.strings[i], sizeof(modlist[modlist_count].dir)); //check currently loaded mods modlist[modlist_count].loaded = false; @@ -4681,8 +4688,10 @@ static void M_ModList_Draw (void) { for (n = start;n < end;n++) { + const char *item_label = (modlist[n].name[0] != '\0') ? modlist[n].name : modlist[n].dir; + DrawQ_Pic(menu_x + 40, menu_y + y, NULL, 360, 8, n == modlist_cursor ? (0.5 + 0.2 * sin(host.realtime * M_PI)) : 0, 0, 0, 0.5, 0); - M_ItemPrint(80, y, modlist[n].dir, true); + M_ItemPrint(80, y, item_label, true); M_DrawCheckbox(48, y, modlist[n].loaded); y +=8; }