]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
Merge PR 'Use the text from modinfo.txt as the mod menu entry' master
authorJames O'Neill <hemebond@gmail.com>
Sun, 21 Apr 2024 17:25:00 +0000 (02:25 +0900)
committerGitHub <noreply@github.com>
Sun, 21 Apr 2024 17:25:00 +0000 (03:25 +1000)
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 <bones_was_here@xonotic.au>
Co-authored-by: bones_was_here <bones_was_here@xonotic.au>
menu.c

diff --git a/menu.c b/menu.c
index 74e220040d67a515baef49948f1c1e57c7028a3d..8034f2f3d54fe70184cd83bac3f151ec11a9b592 100644 (file)
--- 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;
                }