Skip to content

Instantly share code, notes, and snippets.

@icculus
Created May 2, 2024 15:00
Show Gist options
  • Save icculus/f027a79cfed5579a5cd3a0ae14d3ddc1 to your computer and use it in GitHub Desktop.
Save icculus/f027a79cfed5579a5cd3a0ae14d3ddc1 to your computer and use it in GitHub Desktop.
From Descent 3 Steam 2020: Sort mission menu to have retail game things first.
commit 8855673c539fad6949244e3914319ebc29e6885e
Author: Ryan C. Gordon <[email protected]>
Date: Sat Jun 15 00:07:18 2019 -0400
Sort mission menu to have retail game things first.
Pilot Training, Descent 3: Retribution (the main retail game) and
Mercenary (the mission pack) come first. Third party levels come after.
diff --git a/Main/menu.cpp b/Main/menu.cpp
index 6adeb07..b8354d7 100644
--- a/Main/menu.cpp
+++ b/Main/menu.cpp
@@ -1151,7 +1151,14 @@ inline int count_missions(const char *pathname, const char *wildcard)
}
return c;
}
-inline int generate_mission_listbox(newuiListBox *lb, int n_maxfiles, char **filelist, const char *pathname, const char *wildcard)
+
+struct mission_listbox_item
+{
+ char *title;
+ char *filename;
+};
+
+inline int generate_mission_listbox(int n_maxfiles, mission_listbox_item *filelist, const char *pathname, const char *wildcard)
{
int c = 0;
char fullpath[_MAX_PATH];
@@ -1168,8 +1175,8 @@ inline int generate_mission_listbox(newuiListBox *lb, int n_maxfiles, char **fil
continue;
if (GetMissionInfo(filename, &msninfo) && msninfo.name[0] && msninfo.single) {
//if (!msninfo.training || (msninfo.training && Current_pilot.find_mission_data(TRAINING_MISSION_NAME)!= -1)) {
- filelist[c] = mem_strdup(filename);
- lb->AddItem(msninfo.name);
+ filelist[c].filename = mem_strdup(filename);
+ filelist[c].title = mem_strdup(msninfo.name);
filename[0] = 0;
c++;
if (!(c %2)) DoWaitMessage(true);
@@ -1188,13 +1195,17 @@ extern bool Skip_next_movie;
#define OEM_MISSION_FILE "d3oem.mn3"
bool MenuNewGame()
{
+ int priority_slot = 0;
newuiTiledWindow menu;
newuiSheet *select_sheet;
newuiListBox *msn_lb;
- char **filelist = NULL;
+ mission_listbox_item *filelist = NULL;
int n_missions,i,res; //,k
bool found = false;
bool do_menu = true, load_mission = false, retval = true;
+
+ (void) priority_slot;
+
#ifdef DEMO
if(LoadMission("d3demo.mn3"))
{
@@ -1305,9 +1316,11 @@ bool MenuNewGame()
#endif
if (n_missions) {
// allocate extra mission slot because of check below which adds a name to the filelist.
- filelist = (char **)mem_malloc(sizeof(char *)*(n_missions+1));
- for (i = 0; i < (n_missions+1); i++)
- filelist[i] = NULL;
+ filelist = (mission_listbox_item *)mem_malloc(sizeof(mission_listbox_item)*(n_missions+1));
+ for (i = 0; i < (n_missions+1); i++) {
+ filelist[i].filename = NULL;
+ filelist[i].title = NULL;
+ }
}
else {
DoMessageBox(TXT_ERROR, TXT_NOMISSIONS, MSGBOX_OK);
@@ -1318,22 +1331,22 @@ bool MenuNewGame()
// generate real listbox now.
i = 0;
#ifndef RELEASE
- i = generate_mission_listbox(msn_lb, n_missions, filelist, LocalLevelsDir, "*.msn");
+ i = generate_mission_listbox(n_missions, filelist, LocalLevelsDir, "*.msn");
#endif
- i += generate_mission_listbox(msn_lb, n_missions - i, filelist+i, D3MissionsDir, "*.mn3");
+ i += generate_mission_listbox(n_missions - i, filelist+i, D3MissionsDir, "*.mn3");
//rcg10052000 let missions reside in the ~/.loki/descent3/missions dir.
#ifdef __LINUX__
- i += generate_mission_listbox(msn_lb, n_missions - i, filelist+i, homepath, "*.mn3");
+ i += generate_mission_listbox(n_missions - i, filelist+i, homepath, "*.mn3");
#endif
//#ifdef RELEASE
int k;
for(k=0;k<n_missions;k++)
{
- if(!filelist[k])
+ if(!filelist[k].filename)
continue;
- if(strcmpi(filelist[k],"d3.mn3")==0)
+ if(strcmpi(filelist[k].filename,"d3.mn3")==0)
{
found = true;
break;
@@ -1343,24 +1356,53 @@ bool MenuNewGame()
if(!found)
{
#ifdef MACINTOSH
- filelist[n_missions-1] = mem_strdup("d3.mn3");
+ filelist[n_missions-1].filename = mem_strdup("d3.mn3");
+ filelist[n_missions-1].title = mem_strdup(TXT_MAINMISSION);
#else
- filelist[n_missions] = mem_strdup("d3.mn3");
+ filelist[n_missions].filename = mem_strdup("d3.mn3");
+ filelist[n_missions].title = mem_strdup(TXT_MAINMISSION);
#endif
- msn_lb->AddItem(TXT_MAINMISSION);
n_missions++;
}
-//#endif
+
+ // Adjust the list so Pilot Training is first, the main game is second, and Mercenary is third. --ryan, 2019.
+ static const char *priority_missions[] = { "training.mn3", "d3.mn3", "merc.mn3", NULL };
+ for (const char **mission = priority_missions; *mission; mission++) {
+ for (i = 0; i < (n_missions+1); i++) {
+ if (!filelist[i].filename) continue;
+ if (strcmpi(filelist[i].filename, *mission) == 0) {
+ if (i != priority_slot) {
+ mission_listbox_item tmp;
+ memcpy(&tmp, &filelist[priority_slot], sizeof (mission_listbox_item));
+ memcpy(&filelist[priority_slot], &filelist[i], sizeof (mission_listbox_item));
+ memcpy(&filelist[i], &tmp, sizeof (mission_listbox_item));
+ }
+ priority_slot++;
+ break;
+ }
+ }
+ }
+
+//#endif
#else
#define OEM_MISSION_NAME "Descent 3: Sol Ascent"
#define OEM_TRAINING_NAME "Pilot Training "
n_missions=2;
- filelist = (char **)mem_malloc(sizeof(char *)*2);
- filelist[0] = mem_strdup(OEM_MISSION_FILE);;
- msn_lb->AddItem(OEM_MISSION_NAME);
- filelist[1] = mem_strdup(OEM_TRAINING_FILE);
- msn_lb->AddItem(OEM_TRAINING_NAME);
+ filelist = (mission_listbox_item *)mem_malloc(sizeof(mission_listbox_item *)*2);
+ filelist[0].filename = mem_strdup(OEM_MISSION_FILE);
+ filelist[0].title = mem_strdup(OEM_MISSION_NAME);
+ filelist[1].filename = mem_strdup(OEM_TRAINING_FILE);
+ filelist[1].title = mem_strdup(OEM_TRAINING_NAME);
#endif
+
+ // Add the items we dug up to the listbox UI.
+ msn_lb->SetFlag(UILB_NOSORT);
+ for (i = 0; i < (n_missions+1); i++) {
+ if (filelist[i].filename) {
+ msn_lb->AddItem(filelist[i].title);
+ }
+ }
+
DoWaitMessage(false);
redo_newgame_menu:
// run menu
@@ -1374,7 +1416,7 @@ redo_newgame_menu:
tMissionInfo msninfo;
int index = msn_lb->GetCurrentIndex();
if (index >= 0 && index < n_missions) {
- if (GetMissionInfo(filelist[index], &msninfo)) {
+ if (GetMissionInfo(filelist[index].filename, &msninfo)) {
if (msninfo.name[0]) {
newuiTiledWindow infownd;
newuiSheet *sheet;
@@ -1410,7 +1452,7 @@ redo_newgame_menu:
int index = msn_lb->GetCurrentIndex();
char *nameptr=NULL;
if (index >=0 && index < n_missions) {
- nameptr = filelist[index];
+ nameptr = filelist[index].filename;
}
#ifndef OEM
if (!nameptr || !LoadMission(nameptr)) {
@@ -1454,8 +1496,11 @@ missions_fail:
// free all memory
for (i = 0; i < n_missions; i++)
{
- if(filelist[i]) {
- mem_free(filelist[i]);
+ if(filelist[i].filename) {
+ mem_free(filelist[i].filename);
+ }
+ if(filelist[i].title) {
+ mem_free(filelist[i].title);
}
}
if (filelist) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment