1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-15 19:13:07 +01:00

Adapt scenario select screen based on scenario source game.

This commit is contained in:
Aaron van Geffen
2015-12-28 17:15:34 +09:00
committed by IntelOrca
parent 3bad0870fb
commit eb87c5284f
2 changed files with 67 additions and 12 deletions

View File

@@ -19,6 +19,7 @@
*****************************************************************************/
#include "addresses.h"
#include "config.h"
#include "platform/platform.h"
#include "util/util.h"
#include "scenario.h"
@@ -31,7 +32,8 @@ rct_scenario_basic *gScenarioList = NULL;
static void scenario_list_add(const char *path);
static void scenario_list_sort();
static int scenario_list_sort_compare(const void *a, const void *b);
static int scenario_list_sort_by_name(const void *a, const void *b);
static int scenario_list_sort_by_index(const void *a, const void *b);
static int scenario_scores_load();
rct_scenario_basic *get_scenario_by_filename(const char *filename)
@@ -54,6 +56,26 @@ sint16 get_scenario_index(rct_scenario_basic *scenario)
return -1;
}
void normalize_scenario_name(rct_scenario_basic *scenario)
{
char* name = scenario->name;
// Strip "RCT2 " prefix off scenario names.
if (name[0] == 'R' && name[1] == 'C' && name[2] == 'T' && name[3] == '2') {
log_verbose("Stripping RCT2 from name: %s", name);
safe_strncpy(scenario->name, name + 5, 64);
}
// American scenario titles should be handled by their British counterpart, internally.
for (int i = 0; i < NUM_ALIASES; i++) {
if (strcmp(scenario_aliases[i * 2], name) == 0)
{
log_verbose("Found alias: %s; will treat as: %s", scenario->name, scenario_aliases[i * 2 + 1]);
safe_strncpy(scenario->name, scenario_aliases[i * 2 + 1], 64);
}
}
}
scenario_source source_by_index(uint8 index)
{
if (index >= SCENARIO_SOURCE_RCT1_CLASSIC_INDEX && index < SCENARIO_SOURCE_RCT1_CORKSCREW_INDEX) {
@@ -163,8 +185,12 @@ static void scenario_list_add(const char *path)
safe_strncpy(scenario->details, s6Info.details, 256);
}
sint16 index = get_scenario_index(scenario);
printf("Name: %-50s -- Index: %d -- Source: %d\n", scenario->name, index, source_by_index(index));
// Normalize the name to make the scenario as recognisable as possible.
normalize_scenario_name(scenario);
// Look up and store information regarding the origins of this scenario.
scenario->source_index = get_scenario_index(scenario);
scenario->source_game = source_by_index(scenario->source_index);
}
/**
@@ -175,14 +201,25 @@ static void scenario_list_add(const char *path)
*/
static void scenario_list_sort()
{
qsort(gScenarioList, gScenarioListCount, sizeof(rct_scenario_basic), scenario_list_sort_compare);
if (gConfigGeneral.scenario_select_mode == 1) // and not tabIndex > REAL, OTHER
qsort(gScenarioList, gScenarioListCount, sizeof(rct_scenario_basic), scenario_list_sort_by_index);
else
qsort(gScenarioList, gScenarioListCount, sizeof(rct_scenario_basic), scenario_list_sort_by_name);
}
static int scenario_list_sort_by_index(const void *a, const void *b)
{
if (((rct_scenario_basic*)a)->source_game == SCENARIO_SOURCE_OTHER && ((rct_scenario_basic*)b)->source_game == SCENARIO_SOURCE_OTHER)
return scenario_list_sort_by_name(a, b);
return ((rct_scenario_basic*)a)->source_index - ((rct_scenario_basic*)b)->source_index;
}
/**
* Basic scenario information compare function for sorting.
* rct2: 0x00677C08
*/
static int scenario_list_sort_compare(const void *a, const void *b)
static int scenario_list_sort_by_name(const void *a, const void *b)
{
return strcmp(((rct_scenario_basic*)a)->name, ((rct_scenario_basic*)b)->name);
}

View File

@@ -151,15 +151,20 @@ static void window_scenarioselect_init_tabs()
for (int i = 0; i < gScenarioListCount; i++) {
rct_scenario_basic* scenario = &gScenarioList[i];
if (scenario->flags & SCENARIO_FLAGS_VISIBLE)
show_pages |= 1 << scenario->category;
{
if (gConfigGeneral.scenario_select_mode == 1)
show_pages |= 1 << scenario->source_game;
else
show_pages |= 1 << scenario->category;
}
}
int x = 3;
for (int i = 0; i < 8; i++) {
rct_widget* widget = &window_scenarioselect_widgets[i + 4];
if (!(show_pages & (1 << i))) {
// widget->type = WWT_EMPTY;
// continue;
widget->type = WWT_EMPTY;
continue;
}
widget->type = WWT_TAB;
@@ -193,8 +198,11 @@ static void window_scenarioselect_scrollgetsize(rct_window *w, int scrollIndex,
*height = 0;
for (int i = 0; i < gScenarioListCount; i++) {
rct_scenario_basic *scenario = &gScenarioList[i];
if (scenario->category != w->selected_tab)
if ((gConfigGeneral.scenario_select_mode == 1 && scenario->source_game != w->selected_tab) ||
(gConfigGeneral.scenario_select_mode == 2 && scenario->category != w->selected_tab))
continue;
if (scenario->flags & SCENARIO_FLAGS_VISIBLE)
*height += 24;
}
@@ -208,8 +216,11 @@ static void window_scenarioselect_scrollmousedown(rct_window *w, int scrollIndex
{
for (int i = 0; i < gScenarioListCount; i++) {
rct_scenario_basic *scenario = &gScenarioList[i];
if (scenario->category != w->selected_tab)
if ((gConfigGeneral.scenario_select_mode == 1 && scenario->source_game != w->selected_tab) ||
(gConfigGeneral.scenario_select_mode == 2 && scenario->category != w->selected_tab))
continue;
if (!(scenario->flags & SCENARIO_FLAGS_VISIBLE))
continue;
@@ -232,7 +243,11 @@ static void window_scenarioselect_scrollmouseover(rct_window *w, int scrollIndex
rct_scenario_basic *selected = NULL;
for (int i = 0; i < gScenarioListCount; i++) {
rct_scenario_basic *scenario = &gScenarioList[i];
if (scenario->category != w->selected_tab || !(scenario->flags & SCENARIO_FLAGS_VISIBLE))
if ((gConfigGeneral.scenario_select_mode == 1 && scenario->source_game != w->selected_tab) ||
(gConfigGeneral.scenario_select_mode == 2 && scenario->category != w->selected_tab))
continue;
if (!(scenario->flags & SCENARIO_FLAGS_VISIBLE))
continue;
y -= 24;
@@ -335,8 +350,11 @@ static void window_scenarioselect_scrollpaint(rct_window *w, rct_drawpixelinfo *
y = 0;
for (i = 0; i < gScenarioListCount; i++) {
scenario = &gScenarioList[i];
if (scenario->category != w->selected_tab)
if ((gConfigGeneral.scenario_select_mode == 1 && scenario->source_game != w->selected_tab) ||
(gConfigGeneral.scenario_select_mode == 2 && scenario->category != w->selected_tab))
continue;
if (!(scenario->flags & SCENARIO_FLAGS_VISIBLE))
continue;