(svn r15389) -Feature: Add ability to select which base graphics set is used from the Game Options window. The change takes effect when the window is closed. This option can only be used from the intro menu, as reloading graphics during a game may cause issues.

This commit is contained in:
peter1138 2009-02-07 01:01:02 +00:00
parent ae2fda6c02
commit 967491a22d
4 changed files with 88 additions and 2 deletions

View File

@ -569,3 +569,43 @@ bool HasGraphicsSet(const ContentInfo *ci, bool md5sum)
}
#endif /* ENABLE_NETWORK */
/**
* Count the number of available graphics sets.
*/
int GetNumGraphicsSets()
{
int n = 0;
for (const GraphicsSet *g = _available_graphics_sets; g != NULL; g = g->next) {
if (g->found_grfs <= 1) continue;
n++;
}
return n;
}
/**
* Get the index of the currently active graphics set
*/
int GetIndexOfCurrentGraphicsSet()
{
int n = 0;
for (const GraphicsSet *g = _available_graphics_sets; g != NULL; g = g->next) {
if (g->found_grfs <= 1) continue;
if (g == _used_graphics_set) return n;
n++;
}
return -1;
}
/**
* Get the name of the graphics set at the specified index
*/
const char *GetGraphicsSetName(int index)
{
for (const GraphicsSet *g = _available_graphics_sets; g != NULL; g = g->next) {
if (g->found_grfs <= 1) continue;
if (index == 0) return g->name;
index--;
}
error("GetGraphicsSetName: index %d out of range", index);
}

View File

@ -15,6 +15,10 @@ void FindGraphicsSets();
bool SetGraphicsSet(const char *name);
char *GetGraphicsSetsList(char *p, const char *last);
int GetNumGraphicsSets();
int GetIndexOfCurrentGraphicsSet();
const char *GetGraphicsSetName(int index);
extern char *_ini_graphics_set;
#endif /* GFXINIT_H */

View File

@ -969,6 +969,10 @@ STR_OPTIONS_SCREENSHOT_FORMAT :{BLACK}Screensh
STR_OPTIONS_SCREENSHOT_FORMAT_CBO :{BLACK}{SKIP}{SKIP}{SKIP}{SKIP}{SKIP}{SKIP}{SKIP}{SKIP}{STRING}
STR_OPTIONS_SCREENSHOT_FORMAT_TIP :{BLACK}Select the screenshot format to use
STR_OPTIONS_BASE_GRF :{BLACK}Base graphics set
STR_OPTIONS_BASE_GRF_CBO :{BLACK}{SKIP}{SKIP}{SKIP}{SKIP}{SKIP}{SKIP}{SKIP}{SKIP}{SKIP}{RAW_STRING}
STR_OPTIONS_BASE_GRF_TIP :{BLACK}Select the base graphics set to use
STR_AUTOSAVE_1_MONTH :Every month
STR_AUTOSAVE_FAILED :{WHITE}Autosave failed

View File

@ -25,6 +25,7 @@
#include "widgets/dropdown_func.h"
#include "station_func.h"
#include "highscore.h"
#include "gfxinit.h"
#include <map>
#include "table/sprites.h"
@ -112,6 +113,7 @@ enum GameOptionsWidgets {
GAMEOPT_RESOLUTION_BTN = 19,
GAMEOPT_FULLSCREEN,
GAMEOPT_SCREENSHOT_BTN = 22,
GAMEOPT_BASE_GRF_BTN = 24,
};
/**
@ -140,18 +142,34 @@ static void ShowTownnameDropdown(Window *w, int sel)
static void ShowCustCurrency();
static void ShowGraphicsSetMenu(Window *w)
{
int n = GetNumGraphicsSets();
int current = GetIndexOfCurrentGraphicsSet();
DropDownList *list = new DropDownList();
for (int i = 0; i < n; i++) {
list->push_back(new DropDownListCharStringItem(GetGraphicsSetName(i), i, (_game_mode == GM_MENU) ? false : (current != i)));
}
ShowDropDownList(w, list, current, GAMEOPT_BASE_GRF_BTN);
}
struct GameOptionsWindow : Window {
GameSettings *opt;
bool reload;
GameOptionsWindow(const WindowDesc *desc) : Window(desc)
{
this->opt = (_game_mode == GM_MENU) ? &_settings_newgame : &_settings_game;
this->reload = false;
this->FindWindowPlacementAndResize(desc);
}
~GameOptionsWindow()
{
DeleteWindowById(WC_CUSTOM_CURRENCY, 0);
if (this->reload) _switch_mode = SM_MENU;
}
virtual void OnPaint()
@ -171,6 +189,7 @@ struct GameOptionsWindow : Window {
SetDParam(7, i == _num_resolutions ? STR_RES_OTHER : SPECSTR_RESOLUTION_START + i);
SetDParam(8, SPECSTR_SCREENSHOT_START + _cur_screenshot_format);
this->SetWidgetLoweredState(GAMEOPT_FULLSCREEN, _fullscreen);
SetDParamStr(9, GetGraphicsSetName(GetIndexOfCurrentGraphicsSet()));
this->DrawWidgets();
DrawString(20, 175, STR_OPTIONS_FULLSCREEN, TC_FROMSTRING); // fullscreen
@ -246,6 +265,10 @@ struct GameOptionsWindow : Window {
case GAMEOPT_SCREENSHOT_BTN: // Setup screenshot format dropdown
ShowDropDownMenu(this, BuildDynamicDropdown(SPECSTR_SCREENSHOT_START, _num_screenshot_formats), _cur_screenshot_format, GAMEOPT_SCREENSHOT_BTN, 0, 0);
break;
case GAMEOPT_BASE_GRF_BTN:
ShowGraphicsSetMenu(this);
break;
}
}
@ -312,6 +335,18 @@ struct GameOptionsWindow : Window {
SetScreenshotFormat(index);
this->SetDirty();
break;
case GAMEOPT_BASE_GRF_BTN:
if (_game_mode == GM_MENU) {
const char *name = GetGraphicsSetName(index);
free(_ini_graphics_set);
_ini_graphics_set = strdup(name);
SetGraphicsSet(name);
this->reload = true;
}
break;
}
}
};
@ -319,7 +354,7 @@ struct GameOptionsWindow : Window {
static const Widget _game_options_widgets[] = {
{ WWT_CLOSEBOX, RESIZE_NONE, COLOUR_GREY, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_CAPTION, RESIZE_NONE, COLOUR_GREY, 11, 369, 0, 13, STR_00B1_GAME_OPTIONS, STR_018C_WINDOW_TITLE_DRAG_THIS},
{ WWT_PANEL, RESIZE_NONE, COLOUR_GREY, 0, 369, 14, 238, 0x0, STR_NULL},
{ WWT_PANEL, RESIZE_NONE, COLOUR_GREY, 0, 369, 14, 280, 0x0, STR_NULL},
{ WWT_FRAME, RESIZE_NONE, COLOUR_GREY, 10, 179, 20, 55, STR_02E0_CURRENCY_UNITS, STR_NULL},
{ WWT_DROPDOWNIN, RESIZE_NONE, COLOUR_GREY, 20, 169, 34, 45, STR_02E1, STR_02E2_CURRENCY_UNITS_SELECTION},
{ WWT_FRAME, RESIZE_NONE, COLOUR_GREY, 190, 359, 20, 55, STR_MEASURING_UNITS, STR_NULL},
@ -345,11 +380,14 @@ static const Widget _game_options_widgets[] = {
{ WWT_FRAME, RESIZE_NONE, COLOUR_GREY, 190, 359, 146, 190, STR_OPTIONS_SCREENSHOT_FORMAT, STR_NULL},
{ WWT_DROPDOWNIN, RESIZE_NONE, COLOUR_GREY, 200, 349, 160, 171, STR_OPTIONS_SCREENSHOT_FORMAT_CBO, STR_OPTIONS_SCREENSHOT_FORMAT_TIP},
{ WWT_FRAME, RESIZE_NONE, COLOUR_GREY, 10, 179, 235, 270, STR_OPTIONS_BASE_GRF, STR_NULL},
{ WWT_DROPDOWNIN, RESIZE_NONE, COLOUR_GREY, 20, 169, 249, 260, STR_OPTIONS_BASE_GRF_CBO, STR_OPTIONS_BASE_GRF_TIP},
{ WIDGETS_END},
};
static const WindowDesc _game_options_desc = {
WDP_CENTER, WDP_CENTER, 370, 239, 370, 239,
WDP_CENTER, WDP_CENTER, 370, 281, 370, 281,
WC_GAME_OPTIONS, WC_NONE,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
_game_options_widgets,