2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2008-05-06 15:11:33 +00:00
|
|
|
/** @file settings_gui.cpp GUI for settings. */
|
2007-04-04 01:35:16 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "stdafx.h"
|
2005-06-02 19:30:21 +00:00
|
|
|
#include "openttd.h"
|
2005-08-06 14:59:54 +00:00
|
|
|
#include "currency.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "gui.h"
|
2007-12-19 20:45:46 +00:00
|
|
|
#include "window_gui.h"
|
|
|
|
#include "textbuf_gui.h"
|
2007-12-21 21:50:46 +00:00
|
|
|
#include "command_func.h"
|
2008-03-31 00:17:39 +00:00
|
|
|
#include "engine_func.h"
|
2004-11-15 19:25:59 +00:00
|
|
|
#include "screenshot.h"
|
2007-01-02 17:34:03 +00:00
|
|
|
#include "network/network.h"
|
2004-12-31 18:57:24 +00:00
|
|
|
#include "town.h"
|
2005-07-21 22:15:02 +00:00
|
|
|
#include "variables.h"
|
2008-01-07 00:19:09 +00:00
|
|
|
#include "settings_internal.h"
|
2007-06-18 23:00:55 +00:00
|
|
|
#include "newgrf_townname.h"
|
2007-12-21 19:49:27 +00:00
|
|
|
#include "strings_func.h"
|
2007-12-25 11:26:07 +00:00
|
|
|
#include "window_func.h"
|
2008-01-07 14:23:25 +00:00
|
|
|
#include "string_func.h"
|
2008-01-09 09:45:45 +00:00
|
|
|
#include "gfx_func.h"
|
2008-02-07 16:17:00 +00:00
|
|
|
#include "waypoint.h"
|
2008-01-17 00:21:43 +00:00
|
|
|
#include "widgets/dropdown_type.h"
|
2008-01-14 16:10:58 +00:00
|
|
|
#include "widgets/dropdown_func.h"
|
2008-03-31 00:06:17 +00:00
|
|
|
#include "station_func.h"
|
2009-01-03 18:44:20 +00:00
|
|
|
#include "highscore.h"
|
2009-02-07 01:01:02 +00:00
|
|
|
#include "gfxinit.h"
|
2008-06-24 09:05:24 +00:00
|
|
|
#include <map>
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-01-13 01:21:35 +00:00
|
|
|
#include "table/sprites.h"
|
|
|
|
#include "table/strings.h"
|
|
|
|
|
2006-03-26 21:50:57 +00:00
|
|
|
static const StringID _units_dropdown[] = {
|
|
|
|
STR_UNITS_IMPERIAL,
|
|
|
|
STR_UNITS_METRIC,
|
|
|
|
STR_UNITS_SI,
|
2004-08-09 17:04:08 +00:00
|
|
|
INVALID_STRING_ID
|
|
|
|
};
|
|
|
|
|
|
|
|
static const StringID _driveside_dropdown[] = {
|
|
|
|
STR_02E9_DRIVE_ON_LEFT,
|
|
|
|
STR_02EA_DRIVE_ON_RIGHT,
|
|
|
|
INVALID_STRING_ID
|
|
|
|
};
|
|
|
|
|
|
|
|
static const StringID _autosave_dropdown[] = {
|
|
|
|
STR_02F7_OFF,
|
|
|
|
STR_AUTOSAVE_1_MONTH,
|
|
|
|
STR_02F8_EVERY_3_MONTHS,
|
|
|
|
STR_02F9_EVERY_6_MONTHS,
|
|
|
|
STR_02FA_EVERY_12_MONTHS,
|
|
|
|
INVALID_STRING_ID,
|
|
|
|
};
|
|
|
|
|
|
|
|
static StringID *BuildDynamicDropdown(StringID base, int num)
|
|
|
|
{
|
|
|
|
static StringID buf[32 + 1];
|
|
|
|
StringID *p = buf;
|
2008-04-18 04:37:06 +00:00
|
|
|
while (--num >= 0) *p++ = base++;
|
2004-08-09 17:04:08 +00:00
|
|
|
*p = INVALID_STRING_ID;
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2007-06-18 23:00:55 +00:00
|
|
|
int _nb_orig_names = SPECSTR_TOWNNAME_LAST - SPECSTR_TOWNNAME_START + 1;
|
|
|
|
static StringID *_grf_names = NULL;
|
|
|
|
static int _nb_grf_names = 0;
|
2007-06-04 19:51:31 +00:00
|
|
|
|
2008-01-17 02:10:26 +00:00
|
|
|
void InitGRFTownGeneratorNames()
|
2007-06-04 19:51:31 +00:00
|
|
|
{
|
2007-06-18 23:00:55 +00:00
|
|
|
free(_grf_names);
|
|
|
|
_grf_names = GetGRFTownNameList();
|
|
|
|
_nb_grf_names = 0;
|
|
|
|
for (StringID *s = _grf_names; *s != INVALID_STRING_ID; s++) _nb_grf_names++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline StringID TownName(int town_name)
|
|
|
|
{
|
|
|
|
if (town_name < _nb_orig_names) return STR_TOWNNAME_ORIGINAL_ENGLISH + town_name;
|
|
|
|
town_name -= _nb_orig_names;
|
|
|
|
if (town_name < _nb_grf_names) return _grf_names[town_name];
|
|
|
|
return STR_UNDEFINED;
|
2007-06-04 19:51:31 +00:00
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
static int GetCurRes()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
int i;
|
2005-11-14 19:48:04 +00:00
|
|
|
|
|
|
|
for (i = 0; i != _num_resolutions; i++) {
|
2008-06-16 19:38:41 +00:00
|
|
|
if (_resolutions[i].width == _screen.width &&
|
|
|
|
_resolutions[i].height == _screen.height) {
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
2005-11-14 19:48:04 +00:00
|
|
|
}
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2008-01-04 02:32:58 +00:00
|
|
|
enum GameOptionsWidgets {
|
2008-01-17 18:10:27 +00:00
|
|
|
GAMEOPT_CURRENCY_BTN = 4,
|
|
|
|
GAMEOPT_DISTANCE_BTN = 6,
|
|
|
|
GAMEOPT_ROADSIDE_BTN = 8,
|
|
|
|
GAMEOPT_TOWNNAME_BTN = 10,
|
|
|
|
GAMEOPT_AUTOSAVE_BTN = 12,
|
2009-02-08 12:58:14 +00:00
|
|
|
GAMEOPT_LANG_BTN = 14,
|
|
|
|
GAMEOPT_RESOLUTION_BTN = 16,
|
2008-01-04 02:32:58 +00:00
|
|
|
GAMEOPT_FULLSCREEN,
|
2009-02-08 12:58:14 +00:00
|
|
|
GAMEOPT_SCREENSHOT_BTN = 19,
|
|
|
|
GAMEOPT_BASE_GRF_BTN = 21,
|
2008-01-04 02:32:58 +00:00
|
|
|
};
|
|
|
|
|
2008-01-17 02:10:26 +00:00
|
|
|
/**
|
|
|
|
* Update/redraw the townnames dropdown
|
|
|
|
* @param w the window the dropdown belongs to
|
|
|
|
* @param sel the currently selected townname generator
|
|
|
|
*/
|
|
|
|
static void ShowTownnameDropdown(Window *w, int sel)
|
|
|
|
{
|
|
|
|
typedef std::map<StringID, int, StringIDCompare> TownList;
|
|
|
|
TownList townnames;
|
|
|
|
|
|
|
|
/* Add and sort original townnames generators */
|
|
|
|
for (int i = 0; i < _nb_orig_names; i++) townnames[STR_TOWNNAME_ORIGINAL_ENGLISH + i] = i;
|
|
|
|
|
|
|
|
/* Add and sort newgrf townnames generators */
|
|
|
|
for (int i = 0; i < _nb_grf_names; i++) townnames[_grf_names[i]] = _nb_orig_names + i;
|
|
|
|
|
|
|
|
DropDownList *list = new DropDownList();
|
|
|
|
for (TownList::iterator it = townnames.begin(); it != townnames.end(); it++) {
|
2008-12-05 22:46:39 +00:00
|
|
|
list->push_back(new DropDownListStringItem((*it).first, (*it).second, !(_game_mode == GM_MENU || GetNumTowns() == 0 || (*it).second == sel)));
|
2008-01-17 02:10:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ShowDropDownList(w, list, sel, GAMEOPT_TOWNNAME_BTN);
|
|
|
|
}
|
|
|
|
|
2008-05-18 12:17:52 +00:00
|
|
|
static void ShowCustCurrency();
|
2008-01-17 00:21:43 +00:00
|
|
|
|
2009-02-07 01:01:02 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2008-05-18 12:17:52 +00:00
|
|
|
struct GameOptionsWindow : Window {
|
2008-05-29 15:13:28 +00:00
|
|
|
GameSettings *opt;
|
2009-02-07 01:01:02 +00:00
|
|
|
bool reload;
|
2008-05-25 12:57:39 +00:00
|
|
|
|
2008-05-18 12:17:52 +00:00
|
|
|
GameOptionsWindow(const WindowDesc *desc) : Window(desc)
|
|
|
|
{
|
2008-05-29 15:13:28 +00:00
|
|
|
this->opt = (_game_mode == GM_MENU) ? &_settings_newgame : &_settings_game;
|
2009-02-07 01:01:02 +00:00
|
|
|
this->reload = false;
|
2008-05-18 12:17:52 +00:00
|
|
|
this->FindWindowPlacementAndResize(desc);
|
2008-01-17 00:21:43 +00:00
|
|
|
}
|
|
|
|
|
2008-05-18 12:17:52 +00:00
|
|
|
~GameOptionsWindow()
|
|
|
|
{
|
|
|
|
DeleteWindowById(WC_CUSTOM_CURRENCY, 0);
|
2009-02-07 01:01:02 +00:00
|
|
|
if (this->reload) _switch_mode = SM_MENU;
|
2008-05-18 12:17:52 +00:00
|
|
|
}
|
2008-01-17 00:21:43 +00:00
|
|
|
|
2008-05-18 12:17:52 +00:00
|
|
|
virtual void OnPaint()
|
|
|
|
{
|
2008-06-05 11:26:38 +00:00
|
|
|
SetDParam(1, _currency_specs[this->opt->locale.currency].name);
|
|
|
|
SetDParam(2, STR_UNITS_IMPERIAL + this->opt->locale.units);
|
2008-05-25 22:36:44 +00:00
|
|
|
SetDParam(3, STR_02E9_DRIVE_ON_LEFT + this->opt->vehicle.road_side);
|
|
|
|
SetDParam(4, TownName(this->opt->game_creation.town_name));
|
2008-05-29 15:13:28 +00:00
|
|
|
SetDParam(5, _autosave_dropdown[_settings_client.gui.autosave]);
|
2008-05-18 12:17:52 +00:00
|
|
|
SetDParam(6, SPECSTR_LANGUAGE_START + _dynlang.curr);
|
|
|
|
int i = GetCurRes();
|
|
|
|
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);
|
2009-02-07 01:01:02 +00:00
|
|
|
SetDParamStr(9, GetGraphicsSetName(GetIndexOfCurrentGraphicsSet()));
|
2008-05-18 12:17:52 +00:00
|
|
|
|
|
|
|
this->DrawWidgets();
|
2009-03-22 14:39:20 +00:00
|
|
|
DrawString(20, this->width / 2, 175, STR_OPTIONS_FULLSCREEN, TC_FROMSTRING); // fullscreen
|
2008-05-18 12:17:52 +00:00
|
|
|
}
|
2006-01-05 12:40:50 +00:00
|
|
|
|
2008-05-18 12:17:52 +00:00
|
|
|
virtual void OnClick(Point pt, int widget)
|
|
|
|
{
|
|
|
|
switch (widget) {
|
|
|
|
case GAMEOPT_CURRENCY_BTN: // Setup currencies dropdown
|
2008-06-05 11:26:38 +00:00
|
|
|
ShowDropDownMenu(this, BuildCurrencyDropdown(), this->opt->locale.currency, GAMEOPT_CURRENCY_BTN, _game_mode == GM_MENU ? 0 : ~GetMaskOfAllowedCurrencies(), 0);
|
2008-05-18 12:17:52 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GAMEOPT_DISTANCE_BTN: // Setup distance unit dropdown
|
2008-06-05 11:26:38 +00:00
|
|
|
ShowDropDownMenu(this, _units_dropdown, this->opt->locale.units, GAMEOPT_DISTANCE_BTN, 0, 0);
|
2008-05-18 12:17:52 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GAMEOPT_ROADSIDE_BTN: { // Setup road-side dropdown
|
|
|
|
int i = 0;
|
2008-05-18 17:40:13 +00:00
|
|
|
extern bool RoadVehiclesAreBuilt();
|
2008-05-18 12:17:52 +00:00
|
|
|
|
|
|
|
/* You can only change the drive side if you are in the menu or ingame with
|
|
|
|
* no vehicles present. In a networking game only the server can change it */
|
|
|
|
if ((_game_mode != GM_MENU && RoadVehiclesAreBuilt()) || (_networking && !_network_server)) {
|
2008-05-25 22:36:44 +00:00
|
|
|
i = (-1) ^ (1 << this->opt->vehicle.road_side); // disable the other value
|
2008-05-18 12:17:52 +00:00
|
|
|
}
|
|
|
|
|
2008-05-25 22:36:44 +00:00
|
|
|
ShowDropDownMenu(this, _driveside_dropdown, this->opt->vehicle.road_side, GAMEOPT_ROADSIDE_BTN, i, 0);
|
2008-05-18 12:17:52 +00:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case GAMEOPT_TOWNNAME_BTN: // Setup townname dropdown
|
2008-05-25 22:36:44 +00:00
|
|
|
ShowTownnameDropdown(this, this->opt->game_creation.town_name);
|
2008-05-18 12:17:52 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GAMEOPT_AUTOSAVE_BTN: // Setup autosave dropdown
|
2008-05-29 15:13:28 +00:00
|
|
|
ShowDropDownMenu(this, _autosave_dropdown, _settings_client.gui.autosave, GAMEOPT_AUTOSAVE_BTN, 0, 0);
|
2008-05-18 12:17:52 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GAMEOPT_LANG_BTN: { // Setup interface language dropdown
|
|
|
|
typedef std::map<StringID, int, StringIDCompare> LangList;
|
|
|
|
|
|
|
|
/* Sort language names */
|
|
|
|
LangList langs;
|
|
|
|
for (int i = 0; i < _dynlang.num; i++) langs[SPECSTR_LANGUAGE_START + i] = i;
|
|
|
|
|
|
|
|
DropDownList *list = new DropDownList();
|
|
|
|
for (LangList::iterator it = langs.begin(); it != langs.end(); it++) {
|
|
|
|
list->push_back(new DropDownListStringItem((*it).first, (*it).second, false));
|
|
|
|
}
|
|
|
|
|
|
|
|
ShowDropDownList(this, list, _dynlang.curr, GAMEOPT_LANG_BTN);
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case GAMEOPT_RESOLUTION_BTN: // Setup resolution dropdown
|
|
|
|
ShowDropDownMenu(this, BuildDynamicDropdown(SPECSTR_RESOLUTION_START, _num_resolutions), GetCurRes(), GAMEOPT_RESOLUTION_BTN, 0, 0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GAMEOPT_FULLSCREEN: // Click fullscreen on/off
|
|
|
|
/* try to toggle full-screen on/off */
|
|
|
|
if (!ToggleFullScreen(!_fullscreen)) {
|
|
|
|
ShowErrorMessage(INVALID_STRING_ID, STR_FULLSCREEN_FAILED, 0, 0);
|
|
|
|
}
|
|
|
|
this->SetWidgetLoweredState(GAMEOPT_FULLSCREEN, _fullscreen);
|
|
|
|
this->SetDirty();
|
|
|
|
break;
|
|
|
|
|
|
|
|
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;
|
2009-02-07 01:01:02 +00:00
|
|
|
|
|
|
|
case GAMEOPT_BASE_GRF_BTN:
|
|
|
|
ShowGraphicsSetMenu(this);
|
|
|
|
break;
|
2008-05-18 12:17:52 +00:00
|
|
|
}
|
|
|
|
}
|
2008-01-04 02:32:58 +00:00
|
|
|
|
2008-05-18 12:17:52 +00:00
|
|
|
virtual void OnDropdownSelect(int widget, int index)
|
|
|
|
{
|
|
|
|
switch (widget) {
|
2009-03-15 00:32:18 +00:00
|
|
|
case GAMEOPT_CURRENCY_BTN: // Currency
|
2008-05-18 12:17:52 +00:00
|
|
|
if (index == CUSTOM_CURRENCY_ID) ShowCustCurrency();
|
2008-06-05 11:26:38 +00:00
|
|
|
this->opt->locale.currency = index;
|
2008-05-18 12:17:52 +00:00
|
|
|
MarkWholeScreenDirty();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GAMEOPT_DISTANCE_BTN: // Measuring units
|
2008-06-05 11:26:38 +00:00
|
|
|
this->opt->locale.units = index;
|
2008-05-18 12:17:52 +00:00
|
|
|
MarkWholeScreenDirty();
|
|
|
|
break;
|
|
|
|
|
2009-02-08 17:46:08 +00:00
|
|
|
case GAMEOPT_ROADSIDE_BTN: // Road side
|
|
|
|
if (this->opt->vehicle.road_side != index) { // only change if setting changed
|
|
|
|
uint i;
|
|
|
|
if (GetSettingFromName("vehicle.road_side", &i) == NULL) NOT_REACHED();
|
|
|
|
SetSettingValue(i, index);
|
|
|
|
MarkWholeScreenDirty();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2008-05-18 12:17:52 +00:00
|
|
|
case GAMEOPT_TOWNNAME_BTN: // Town names
|
2008-12-05 22:46:39 +00:00
|
|
|
if (_game_mode == GM_MENU || GetNumTowns() == 0) {
|
2008-05-25 22:36:44 +00:00
|
|
|
this->opt->game_creation.town_name = index;
|
2008-05-18 12:17:52 +00:00
|
|
|
InvalidateWindow(WC_GAME_OPTIONS, 0);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GAMEOPT_AUTOSAVE_BTN: // Autosave options
|
2008-05-29 15:13:28 +00:00
|
|
|
_settings_client.gui.autosave = index;
|
2008-05-18 12:17:52 +00:00
|
|
|
this->SetDirty();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GAMEOPT_LANG_BTN: // Change interface language
|
|
|
|
ReadLanguagePack(index);
|
|
|
|
CheckForMissingGlyphsInLoadedLanguagePack();
|
|
|
|
UpdateAllStationVirtCoord();
|
|
|
|
UpdateAllWaypointSigns();
|
|
|
|
MarkWholeScreenDirty();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GAMEOPT_RESOLUTION_BTN: // Change resolution
|
2008-06-16 19:38:41 +00:00
|
|
|
if (index < _num_resolutions && ChangeResInGame(_resolutions[index].width, _resolutions[index].height)) {
|
2008-05-18 12:17:52 +00:00
|
|
|
this->SetDirty();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GAMEOPT_SCREENSHOT_BTN: // Change screenshot format
|
|
|
|
SetScreenshotFormat(index);
|
|
|
|
this->SetDirty();
|
|
|
|
break;
|
2009-02-07 01:01:02 +00:00
|
|
|
|
|
|
|
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;
|
2008-05-18 12:17:52 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2008-05-18 12:17:52 +00:00
|
|
|
};
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
static const Widget _game_options_widgets[] = {
|
2008-07-31 17:45:52 +00:00
|
|
|
{ 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},
|
2009-02-08 12:58:14 +00:00
|
|
|
{ WWT_PANEL, RESIZE_NONE, COLOUR_GREY, 0, 369, 14, 242, 0x0, STR_NULL},
|
2008-07-31 17:45:52 +00:00
|
|
|
{ WWT_FRAME, RESIZE_NONE, COLOUR_GREY, 10, 179, 20, 55, STR_02E0_CURRENCY_UNITS, STR_NULL},
|
2009-03-23 00:08:59 +00:00
|
|
|
{ WWT_DROPDOWN, RESIZE_NONE, COLOUR_GREY, 20, 169, 34, 45, STR_02E1, STR_02E2_CURRENCY_UNITS_SELECTION},
|
2008-07-31 17:45:52 +00:00
|
|
|
{ WWT_FRAME, RESIZE_NONE, COLOUR_GREY, 190, 359, 20, 55, STR_MEASURING_UNITS, STR_NULL},
|
2009-03-23 00:08:59 +00:00
|
|
|
{ WWT_DROPDOWN, RESIZE_NONE, COLOUR_GREY, 200, 349, 34, 45, STR_02E4, STR_MEASURING_UNITS_SELECTION},
|
2008-07-31 17:45:52 +00:00
|
|
|
{ WWT_FRAME, RESIZE_NONE, COLOUR_GREY, 10, 179, 62, 97, STR_02E6_ROAD_VEHICLES, STR_NULL},
|
2009-03-23 00:08:59 +00:00
|
|
|
{ WWT_DROPDOWN, RESIZE_NONE, COLOUR_GREY, 20, 169, 76, 87, STR_02E7, STR_02E8_SELECT_SIDE_OF_ROAD_FOR},
|
2008-07-31 17:45:52 +00:00
|
|
|
{ WWT_FRAME, RESIZE_NONE, COLOUR_GREY, 190, 359, 62, 97, STR_02EB_TOWN_NAMES, STR_NULL},
|
2009-03-23 00:08:59 +00:00
|
|
|
{ WWT_DROPDOWN, RESIZE_NONE, COLOUR_GREY, 200, 349, 76, 87, STR_02EC, STR_02ED_SELECT_STYLE_OF_TOWN_NAMES},
|
2008-07-31 17:45:52 +00:00
|
|
|
{ WWT_FRAME, RESIZE_NONE, COLOUR_GREY, 10, 179, 104, 139, STR_02F4_AUTOSAVE, STR_NULL},
|
2009-03-23 00:08:59 +00:00
|
|
|
{ WWT_DROPDOWN, RESIZE_NONE, COLOUR_GREY, 20, 169, 118, 129, STR_02F5, STR_02F6_SELECT_INTERVAL_BETWEEN},
|
2008-07-31 17:45:52 +00:00
|
|
|
|
|
|
|
{ WWT_FRAME, RESIZE_NONE, COLOUR_GREY, 190, 359, 104, 139, STR_OPTIONS_LANG, STR_NULL},
|
2009-03-23 00:08:59 +00:00
|
|
|
{ WWT_DROPDOWN, RESIZE_NONE, COLOUR_GREY, 200, 349, 118, 129, STR_OPTIONS_LANG_CBO, STR_OPTIONS_LANG_TIP},
|
2008-07-31 17:45:52 +00:00
|
|
|
|
|
|
|
{ WWT_FRAME, RESIZE_NONE, COLOUR_GREY, 10, 179, 146, 190, STR_OPTIONS_RES, STR_NULL},
|
2009-03-23 00:08:59 +00:00
|
|
|
{ WWT_DROPDOWN, RESIZE_NONE, COLOUR_GREY, 20, 169, 160, 171, STR_OPTIONS_RES_CBO, STR_OPTIONS_RES_TIP},
|
2008-07-31 17:45:52 +00:00
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, COLOUR_GREY, 149, 169, 176, 184, STR_EMPTY, STR_OPTIONS_FULLSCREEN_TIP},
|
|
|
|
|
|
|
|
{ WWT_FRAME, RESIZE_NONE, COLOUR_GREY, 190, 359, 146, 190, STR_OPTIONS_SCREENSHOT_FORMAT, STR_NULL},
|
2009-03-23 00:08:59 +00:00
|
|
|
{ WWT_DROPDOWN, RESIZE_NONE, COLOUR_GREY, 200, 349, 160, 171, STR_OPTIONS_SCREENSHOT_FORMAT_CBO, STR_OPTIONS_SCREENSHOT_FORMAT_TIP},
|
2004-09-07 21:48:09 +00:00
|
|
|
|
2009-02-08 12:58:14 +00:00
|
|
|
{ WWT_FRAME, RESIZE_NONE, COLOUR_GREY, 10, 179, 197, 232, STR_OPTIONS_BASE_GRF, STR_NULL},
|
2009-03-23 00:08:59 +00:00
|
|
|
{ WWT_DROPDOWN, RESIZE_NONE, COLOUR_GREY, 20, 169, 211, 222, STR_OPTIONS_BASE_GRF_CBO, STR_OPTIONS_BASE_GRF_TIP},
|
2009-02-07 01:01:02 +00:00
|
|
|
|
2004-09-07 21:48:09 +00:00
|
|
|
{ WIDGETS_END},
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
2009-03-15 15:12:06 +00:00
|
|
|
static const WindowDesc _game_options_desc(
|
2009-02-08 12:58:14 +00:00
|
|
|
WDP_CENTER, WDP_CENTER, 370, 243, 370, 243,
|
2007-02-01 15:49:12 +00:00
|
|
|
WC_GAME_OPTIONS, WC_NONE,
|
2005-07-15 15:09:52 +00:00
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
|
2009-03-15 15:12:06 +00:00
|
|
|
_game_options_widgets
|
|
|
|
);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void ShowGameOptions()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
DeleteWindowById(WC_GAME_OPTIONS, 0);
|
2008-05-18 12:17:52 +00:00
|
|
|
new GameOptionsWindow(&_game_options_desc);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
extern void StartupEconomy();
|
2004-08-13 21:48:04 +00:00
|
|
|
|
2008-05-15 00:01:42 +00:00
|
|
|
/* Widget definition for the game difficulty settings window */
|
|
|
|
static const Widget _game_difficulty_widgets[] = {
|
2008-07-31 17:45:52 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, COLOUR_MAUVE, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, // GDW_CLOSEBOX
|
|
|
|
{ WWT_CAPTION, RESIZE_NONE, COLOUR_MAUVE, 11, 369, 0, 13, STR_6800_DIFFICULTY_LEVEL, STR_018C_WINDOW_TITLE_DRAG_THIS}, // GDW_CAPTION
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, COLOUR_MAUVE, 0, 369, 14, 41, 0x0, STR_NULL}, // GDW_UPPER_BG
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, COLOUR_YELLOW, 10, 96, 16, 27, STR_6801_EASY, STR_NULL}, // GDW_LVL_EASY
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, COLOUR_YELLOW, 97, 183, 16, 27, STR_6802_MEDIUM, STR_NULL}, // GDW_LVL_MEDIUM
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, COLOUR_YELLOW, 184, 270, 16, 27, STR_6803_HARD, STR_NULL}, // GDW_LVL_HARD
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, COLOUR_YELLOW, 271, 357, 16, 27, STR_6804_CUSTOM, STR_NULL}, // GDW_LVL_CUSTOM
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, COLOUR_GREEN, 10, 357, 28, 39, STR_6838_SHOW_HI_SCORE_CHART, STR_NULL}, // GDW_HIGHSCORE
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, COLOUR_MAUVE, 0, 369, 42, 262, 0x0, STR_NULL}, // GDW_SETTING_BG
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, COLOUR_MAUVE, 0, 369, 263, 278, 0x0, STR_NULL}, // GDW_LOWER_BG
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, COLOUR_YELLOW, 105, 185, 265, 276, STR_OPTIONS_SAVE_CHANGES, STR_NULL}, // GDW_ACCEPT
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, COLOUR_YELLOW, 186, 266, 265, 276, STR_012E_CANCEL, STR_NULL}, // GDW_CANCEL
|
2008-05-15 00:01:42 +00:00
|
|
|
{ WIDGETS_END},
|
2005-01-11 00:54:06 +00:00
|
|
|
};
|
|
|
|
|
2008-05-15 00:01:42 +00:00
|
|
|
/* Window definition for the game difficulty settings window */
|
2009-03-15 15:12:06 +00:00
|
|
|
static const WindowDesc _game_difficulty_desc(
|
2008-05-15 00:01:42 +00:00
|
|
|
WDP_CENTER, WDP_CENTER, 370, 279, 370, 279,
|
|
|
|
WC_GAME_OPTIONS, WC_NONE,
|
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
|
2009-03-15 15:12:06 +00:00
|
|
|
_game_difficulty_widgets
|
|
|
|
);
|
2008-01-24 18:35:35 +00:00
|
|
|
|
2008-05-26 00:31:36 +00:00
|
|
|
void SetDifficultyLevel(int mode, DifficultySettings *gm_opt);
|
|
|
|
|
2008-05-15 00:01:42 +00:00
|
|
|
struct GameDifficultyWindow : public Window {
|
|
|
|
private:
|
2008-05-26 00:31:36 +00:00
|
|
|
static const uint GAME_DIFFICULTY_NUM = 18;
|
2008-01-24 18:35:35 +00:00
|
|
|
bool clicked_increase;
|
|
|
|
uint8 clicked_button;
|
|
|
|
uint8 timeout;
|
2007-12-25 15:56:41 +00:00
|
|
|
|
2008-05-15 00:01:42 +00:00
|
|
|
/* Temporary holding place of values in the difficulty window until 'Save' is clicked */
|
2008-05-29 15:13:28 +00:00
|
|
|
GameSettings opt_mod_temp;
|
2008-05-15 00:01:42 +00:00
|
|
|
|
|
|
|
enum {
|
|
|
|
GAMEDIFF_WND_TOP_OFFSET = 45,
|
|
|
|
GAMEDIFF_WND_ROWSIZE = 9,
|
|
|
|
NO_SETTINGS_BUTTON = 0xFF,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Names of the game difficulty settings window */
|
|
|
|
enum GameDifficultyWidgets {
|
|
|
|
GDW_CLOSEBOX = 0,
|
|
|
|
GDW_CAPTION,
|
|
|
|
GDW_UPPER_BG,
|
|
|
|
GDW_LVL_EASY,
|
|
|
|
GDW_LVL_MEDIUM,
|
|
|
|
GDW_LVL_HARD,
|
|
|
|
GDW_LVL_CUSTOM,
|
|
|
|
GDW_HIGHSCORE,
|
|
|
|
GDW_SETTING_BG,
|
|
|
|
GDW_LOWER_BG,
|
|
|
|
GDW_ACCEPT,
|
|
|
|
GDW_CANCEL,
|
|
|
|
};
|
|
|
|
|
|
|
|
public:
|
|
|
|
GameDifficultyWindow() : Window(&_game_difficulty_desc)
|
|
|
|
{
|
|
|
|
/* Copy current settings (ingame or in intro) to temporary holding place
|
|
|
|
* change that when setting stuff, copy back on clicking 'OK' */
|
2008-05-29 15:13:28 +00:00
|
|
|
this->opt_mod_temp = (_game_mode == GM_MENU) ? _settings_newgame : _settings_game;
|
2008-05-15 00:01:42 +00:00
|
|
|
this->clicked_increase = false;
|
|
|
|
this->clicked_button = NO_SETTINGS_BUTTON;
|
|
|
|
this->timeout = 0;
|
|
|
|
/* Hide the closebox to make sure that the user aborts or confirms his changes */
|
|
|
|
this->HideWidget(GDW_CLOSEBOX);
|
|
|
|
this->widget[GDW_CAPTION].left = 0;
|
|
|
|
/* Setup disabled buttons when creating window
|
|
|
|
* disable all other difficulty buttons during gameplay except for 'custom' */
|
|
|
|
this->SetWidgetsDisabledState(_game_mode == GM_NORMAL,
|
|
|
|
GDW_LVL_EASY,
|
|
|
|
GDW_LVL_MEDIUM,
|
|
|
|
GDW_LVL_HARD,
|
|
|
|
GDW_LVL_CUSTOM,
|
|
|
|
WIDGET_LIST_END);
|
|
|
|
this->SetWidgetDisabledState(GDW_HIGHSCORE, _game_mode == GM_EDITOR || _networking); // highscore chart in multiplayer
|
|
|
|
this->SetWidgetDisabledState(GDW_ACCEPT, _networking && !_network_server); // Save-button in multiplayer (and if client)
|
2008-05-26 00:31:36 +00:00
|
|
|
this->LowerWidget(GDW_LVL_EASY + this->opt_mod_temp.difficulty.diff_level);
|
2008-05-15 00:01:42 +00:00
|
|
|
this->FindWindowPlacementAndResize(&_game_difficulty_desc);
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-15 00:01:42 +00:00
|
|
|
virtual void OnPaint()
|
|
|
|
{
|
2008-05-17 12:48:06 +00:00
|
|
|
this->DrawWidgets();
|
2008-05-15 00:01:42 +00:00
|
|
|
|
2008-05-26 00:31:36 +00:00
|
|
|
uint i;
|
2009-02-08 12:25:13 +00:00
|
|
|
const SettingDesc *sd = GetSettingFromName("difficulty.max_no_competitors", &i);
|
2008-05-15 00:01:42 +00:00
|
|
|
int y = GAMEDIFF_WND_TOP_OFFSET;
|
2009-01-19 01:16:50 +00:00
|
|
|
StringID str = STR_6805_MAXIMUM_NO_COMPETITORS;
|
2008-05-26 00:31:36 +00:00
|
|
|
for (i = 0; i < GAME_DIFFICULTY_NUM; i++, sd++) {
|
|
|
|
const SettingDescBase *sdb = &sd->desc;
|
2009-01-19 01:16:50 +00:00
|
|
|
/* skip deprecated difficulty options */
|
|
|
|
if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue;
|
2008-05-26 00:31:36 +00:00
|
|
|
int32 value = (int32)ReadValue(GetVariableAddress(&this->opt_mod_temp, &sd->save), sd->save.conv);
|
|
|
|
bool editable = (_game_mode == GM_MENU || (sdb->flags & SGF_NEWGAME_ONLY) == 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-08-08 03:37:00 +00:00
|
|
|
DrawArrowButtons(5, y, COLOUR_YELLOW,
|
2008-05-15 00:01:42 +00:00
|
|
|
(this->clicked_button == i) ? 1 + !!this->clicked_increase : 0,
|
2008-05-26 00:31:36 +00:00
|
|
|
editable && sdb->min != value,
|
|
|
|
editable && sdb->max != value);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-26 00:31:36 +00:00
|
|
|
value += sdb->str;
|
2008-05-15 00:01:42 +00:00
|
|
|
SetDParam(0, value);
|
2009-03-22 14:39:20 +00:00
|
|
|
DrawString(30, this->width, y, str, TC_FROMSTRING);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-15 00:01:42 +00:00
|
|
|
y += GAMEDIFF_WND_ROWSIZE + 2; // space items apart a bit
|
2009-01-19 01:16:50 +00:00
|
|
|
str++;
|
2008-05-15 00:01:42 +00:00
|
|
|
}
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-15 00:01:42 +00:00
|
|
|
virtual void OnClick(Point pt, int widget)
|
|
|
|
{
|
|
|
|
switch (widget) {
|
2009-03-15 00:32:18 +00:00
|
|
|
case GDW_SETTING_BG: { // Difficulty settings widget, decode click
|
2008-05-15 00:01:42 +00:00
|
|
|
/* Don't allow clients to make any changes */
|
|
|
|
if (_networking && !_network_server) return;
|
2008-01-04 02:32:58 +00:00
|
|
|
|
2008-05-15 00:01:42 +00:00
|
|
|
const int x = pt.x - 5;
|
|
|
|
if (!IsInsideMM(x, 0, 21)) return; // Button area
|
2008-01-04 03:11:36 +00:00
|
|
|
|
2008-05-15 00:01:42 +00:00
|
|
|
const int y = pt.y - GAMEDIFF_WND_TOP_OFFSET;
|
|
|
|
if (y < 0) return;
|
2008-01-04 03:11:36 +00:00
|
|
|
|
2008-05-15 00:01:42 +00:00
|
|
|
/* Get button from Y coord. */
|
2009-01-19 01:16:50 +00:00
|
|
|
uint8 btn = y / (GAMEDIFF_WND_ROWSIZE + 2);
|
|
|
|
if (btn >= 1) btn++; // Skip the deprecated option "competitor start time"
|
|
|
|
if (btn >= 8) btn++; // Skip the deprecated option "competitor intelligence"
|
2008-05-15 00:01:42 +00:00
|
|
|
if (btn >= GAME_DIFFICULTY_NUM || y % (GAMEDIFF_WND_ROWSIZE + 2) >= 9) return;
|
2008-01-04 03:11:36 +00:00
|
|
|
|
2008-05-26 00:31:36 +00:00
|
|
|
uint i;
|
2009-02-08 12:25:13 +00:00
|
|
|
const SettingDesc *sd = GetSettingFromName("difficulty.max_no_competitors", &i) + btn;
|
2008-05-26 00:31:36 +00:00
|
|
|
const SettingDescBase *sdb = &sd->desc;
|
|
|
|
|
2008-05-15 00:01:42 +00:00
|
|
|
/* Clicked disabled button? */
|
2008-05-26 00:31:36 +00:00
|
|
|
bool editable = (_game_mode == GM_MENU || (sdb->flags & SGF_NEWGAME_ONLY) == 0);
|
|
|
|
if (!editable) return;
|
2008-01-04 03:11:36 +00:00
|
|
|
|
2008-05-15 00:01:42 +00:00
|
|
|
this->timeout = 5;
|
2008-05-26 00:31:36 +00:00
|
|
|
int32 val = (int32)ReadValue(GetVariableAddress(&this->opt_mod_temp, &sd->save), sd->save.conv);
|
2008-01-04 03:11:36 +00:00
|
|
|
|
2008-05-15 00:01:42 +00:00
|
|
|
if (x >= 10) {
|
|
|
|
/* Increase button clicked */
|
2008-05-26 00:31:36 +00:00
|
|
|
val = min(val + sdb->interval, sdb->max);
|
2008-05-15 00:01:42 +00:00
|
|
|
this->clicked_increase = true;
|
|
|
|
} else {
|
|
|
|
/* Decrease button clicked */
|
2008-05-26 00:31:36 +00:00
|
|
|
val -= sdb->interval;
|
|
|
|
val = max(val, sdb->min);
|
2008-05-15 00:01:42 +00:00
|
|
|
this->clicked_increase = false;
|
|
|
|
}
|
|
|
|
this->clicked_button = btn;
|
|
|
|
|
|
|
|
/* save value in temporary variable */
|
2008-05-26 00:31:36 +00:00
|
|
|
WriteValue(GetVariableAddress(&this->opt_mod_temp, &sd->save), sd->save.conv, val);
|
|
|
|
this->RaiseWidget(GDW_LVL_EASY + this->opt_mod_temp.difficulty.diff_level);
|
|
|
|
SetDifficultyLevel(3, &this->opt_mod_temp.difficulty); // set difficulty level to custom
|
2008-05-15 00:01:42 +00:00
|
|
|
this->LowerWidget(GDW_LVL_CUSTOM);
|
|
|
|
this->SetDirty();
|
2008-01-04 03:11:36 +00:00
|
|
|
} break;
|
|
|
|
|
2008-05-15 00:01:42 +00:00
|
|
|
case GDW_LVL_EASY:
|
|
|
|
case GDW_LVL_MEDIUM:
|
|
|
|
case GDW_LVL_HARD:
|
|
|
|
case GDW_LVL_CUSTOM:
|
|
|
|
/* temporarily change difficulty level */
|
2008-05-26 00:31:36 +00:00
|
|
|
this->RaiseWidget(GDW_LVL_EASY + this->opt_mod_temp.difficulty.diff_level);
|
|
|
|
SetDifficultyLevel(widget - GDW_LVL_EASY, &this->opt_mod_temp.difficulty);
|
|
|
|
this->LowerWidget(GDW_LVL_EASY + this->opt_mod_temp.difficulty.diff_level);
|
2008-05-15 00:01:42 +00:00
|
|
|
this->SetDirty();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GDW_HIGHSCORE: // Highscore Table
|
2008-05-26 00:31:36 +00:00
|
|
|
ShowHighscoreTable(this->opt_mod_temp.difficulty.diff_level, -1);
|
2008-05-15 00:01:42 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GDW_ACCEPT: { // Save button - save changes
|
2008-05-29 15:13:28 +00:00
|
|
|
GameSettings *opt_ptr = (_game_mode == GM_MENU) ? &_settings_newgame : &_settings_game;
|
2008-05-26 00:31:36 +00:00
|
|
|
|
|
|
|
uint i;
|
2009-02-08 12:25:13 +00:00
|
|
|
const SettingDesc *sd = GetSettingFromName("difficulty.max_no_competitors", &i);
|
2008-05-26 00:31:36 +00:00
|
|
|
for (uint btn = 0; btn != GAME_DIFFICULTY_NUM; btn++, sd++) {
|
|
|
|
int32 new_val = (int32)ReadValue(GetVariableAddress(&this->opt_mod_temp, &sd->save), sd->save.conv);
|
|
|
|
int32 cur_val = (int32)ReadValue(GetVariableAddress(opt_ptr, &sd->save), sd->save.conv);
|
2008-05-15 00:01:42 +00:00
|
|
|
/* if setting has changed, change it */
|
2008-05-26 00:31:36 +00:00
|
|
|
if (new_val != cur_val) {
|
2009-02-08 12:25:13 +00:00
|
|
|
DoCommandP(0, i + btn, new_val, CMD_CHANGE_SETTING);
|
2008-05-25 12:57:39 +00:00
|
|
|
}
|
2008-05-15 00:01:42 +00:00
|
|
|
}
|
2008-05-26 00:31:36 +00:00
|
|
|
|
2009-02-08 12:25:13 +00:00
|
|
|
GetSettingFromName("difficulty.diff_level", &i);
|
|
|
|
DoCommandP(0, i, this->opt_mod_temp.difficulty.diff_level, CMD_CHANGE_SETTING);
|
2008-05-15 00:01:42 +00:00
|
|
|
delete this;
|
|
|
|
/* If we are in the editor, we should reload the economy.
|
|
|
|
* This way when you load a game, the max loan and interest rate
|
|
|
|
* are loaded correctly. */
|
|
|
|
if (_game_mode == GM_EDITOR) StartupEconomy();
|
|
|
|
break;
|
2008-01-04 03:11:36 +00:00
|
|
|
}
|
2005-03-12 21:21:47 +00:00
|
|
|
|
2008-05-15 00:01:42 +00:00
|
|
|
case GDW_CANCEL: // Cancel button - close window, abandon changes
|
|
|
|
delete this;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-15 00:01:42 +00:00
|
|
|
virtual void OnTick()
|
|
|
|
{
|
|
|
|
if (this->timeout != 0) {
|
|
|
|
this->timeout--;
|
|
|
|
if (this->timeout == 0) this->clicked_button = NO_SETTINGS_BUTTON;
|
|
|
|
this->SetDirty();
|
|
|
|
}
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void ShowGameDifficulty()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
DeleteWindowById(WC_GAME_OPTIONS, 0);
|
2008-05-15 00:01:42 +00:00
|
|
|
new GameDifficultyWindow();
|
2004-09-10 19:02:27 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-01-10 17:13:41 +00:00
|
|
|
static const int SETTING_HEIGHT = 11; ///< Height of a single setting in the tree view in pixels
|
|
|
|
static const int LEVEL_WIDTH = 15; ///< Indenting width of a sub-page in pixels
|
2009-01-03 10:53:49 +00:00
|
|
|
|
2009-01-10 16:42:28 +00:00
|
|
|
/**
|
2009-02-08 12:25:13 +00:00
|
|
|
* Flags for #SettingEntry
|
|
|
|
* @note The #SEF_BUTTONS_MASK matches expectations of the formal parameter 'state' of #DrawArrowButtons
|
2009-01-10 16:42:28 +00:00
|
|
|
*/
|
2009-02-08 12:25:13 +00:00
|
|
|
enum SettingEntryFlags {
|
|
|
|
SEF_LEFT_DEPRESSED = 0x01, ///< Of a numeric setting entry, the left button is depressed
|
|
|
|
SEF_RIGHT_DEPRESSED = 0x02, ///< Of a numeric setting entry, the right button is depressed
|
|
|
|
SEF_BUTTONS_MASK = (SEF_LEFT_DEPRESSED | SEF_RIGHT_DEPRESSED), ///< Bit-mask for button flags
|
2009-01-10 16:42:28 +00:00
|
|
|
|
2009-02-08 12:25:13 +00:00
|
|
|
SEF_LAST_FIELD = 0x04, ///< This entry is the last one in a (sub-)page
|
2009-01-10 16:39:18 +00:00
|
|
|
|
|
|
|
/* Entry kind */
|
2009-02-08 12:25:13 +00:00
|
|
|
SEF_SETTING_KIND = 0x10, ///< Entry kind: Entry is a setting
|
|
|
|
SEF_SUBTREE_KIND = 0x20, ///< Entry kind: Entry is a sub-tree
|
|
|
|
SEF_KIND_MASK = (SEF_SETTING_KIND | SEF_SUBTREE_KIND), ///< Bit-mask for fetching entry kind
|
2009-01-10 16:39:18 +00:00
|
|
|
};
|
|
|
|
|
2009-02-08 12:25:13 +00:00
|
|
|
struct SettingsPage; // Forward declaration
|
2009-01-10 16:39:18 +00:00
|
|
|
|
2009-02-08 12:25:13 +00:00
|
|
|
/** Data fields for a sub-page (#SEF_SUBTREE_KIND kind)*/
|
|
|
|
struct SettingEntrySubtree {
|
|
|
|
SettingsPage *page; ///< Pointer to the sub-page
|
|
|
|
bool folded; ///< Sub-page is folded (not visible except for its title)
|
|
|
|
StringID title; ///< Title of the sub-page
|
2009-01-10 16:39:18 +00:00
|
|
|
};
|
|
|
|
|
2009-02-08 12:25:13 +00:00
|
|
|
/** Data fields for a single setting (#SEF_SETTING_KIND kind) */
|
|
|
|
struct SettingEntrySetting {
|
2009-01-10 16:29:31 +00:00
|
|
|
const char *name; ///< Name of the setting
|
|
|
|
const SettingDesc *setting; ///< Setting description of the setting
|
2009-01-03 11:24:27 +00:00
|
|
|
uint index; ///< Index of the setting in the settings table
|
2009-01-10 16:39:18 +00:00
|
|
|
};
|
|
|
|
|
2009-02-08 12:25:13 +00:00
|
|
|
/** Data structure describing a single setting in a tab */
|
|
|
|
struct SettingEntry {
|
|
|
|
byte flags; ///< Flags of the setting entry. @see SettingEntryFlags
|
|
|
|
byte level; ///< Nesting level of this setting entry
|
2009-01-10 16:39:18 +00:00
|
|
|
union {
|
2009-02-08 12:25:13 +00:00
|
|
|
SettingEntrySetting entry; ///< Data fields if entry is a setting
|
|
|
|
SettingEntrySubtree sub; ///< Data fields if entry is a sub-page
|
2009-01-10 16:39:18 +00:00
|
|
|
} d; ///< Data fields for each kind
|
2009-01-10 16:29:31 +00:00
|
|
|
|
2009-02-08 12:25:13 +00:00
|
|
|
SettingEntry(const char *nm);
|
|
|
|
SettingEntry(SettingsPage *sub, StringID title);
|
2009-01-10 16:39:18 +00:00
|
|
|
|
|
|
|
void Init(byte level, bool last_field);
|
2009-01-10 17:27:11 +00:00
|
|
|
void FoldAll();
|
2009-01-10 16:42:28 +00:00
|
|
|
void SetButtons(byte new_val);
|
2009-01-10 16:44:51 +00:00
|
|
|
|
|
|
|
uint Length() const;
|
2009-02-08 12:25:13 +00:00
|
|
|
SettingEntry *FindEntry(uint row, uint *cur_row);
|
2009-01-10 16:51:27 +00:00
|
|
|
|
2009-02-24 22:23:47 +00:00
|
|
|
uint Draw(GameSettings *settings_ptr, int base_x, int base_y, int max_x, uint first_row, uint max_row, uint cur_row, uint parent_last);
|
2009-01-10 16:51:27 +00:00
|
|
|
|
|
|
|
private:
|
2009-02-24 22:23:47 +00:00
|
|
|
void DrawSetting(GameSettings *settings_ptr, const SettingDesc *sd, int x, int y, int max_x, int state);
|
2009-01-03 11:24:27 +00:00
|
|
|
};
|
|
|
|
|
2009-02-08 12:25:13 +00:00
|
|
|
/** Data structure describing one page of settings in the settings window. */
|
|
|
|
struct SettingsPage {
|
|
|
|
SettingEntry *entries; ///< Array of setting entries of the page.
|
|
|
|
byte num; ///< Number of entries on the page (statically filled).
|
2009-01-10 16:39:18 +00:00
|
|
|
|
|
|
|
void Init(byte level = 0);
|
2009-01-10 17:27:11 +00:00
|
|
|
void FoldAll();
|
2009-01-10 16:44:51 +00:00
|
|
|
|
|
|
|
uint Length() const;
|
2009-02-08 12:25:13 +00:00
|
|
|
SettingEntry *FindEntry(uint row, uint *cur_row) const;
|
2009-01-10 17:13:41 +00:00
|
|
|
|
2009-02-24 22:23:47 +00:00
|
|
|
uint Draw(GameSettings *settings_ptr, int base_x, int base_y, int max_x, uint first_row, uint max_row, uint cur_row = 0, uint parent_last = 0) const;
|
2009-01-03 11:24:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-02-08 12:25:13 +00:00
|
|
|
/* == SettingEntry methods == */
|
2009-01-10 16:29:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor for a single setting in the 'advanced settings' window
|
|
|
|
* @param nm Name of the setting in the setting table
|
|
|
|
*/
|
2009-02-08 12:25:13 +00:00
|
|
|
SettingEntry::SettingEntry(const char *nm)
|
2009-01-10 16:29:31 +00:00
|
|
|
{
|
2009-02-08 12:25:13 +00:00
|
|
|
this->flags = SEF_SETTING_KIND;
|
2009-01-10 16:39:18 +00:00
|
|
|
this->level = 0;
|
|
|
|
this->d.entry.name = nm;
|
|
|
|
this->d.entry.setting = NULL;
|
|
|
|
this->d.entry.index = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor for a sub-page in the 'advanced settings' window
|
|
|
|
* @param sub Sub-page
|
|
|
|
* @param title Title of the sub-page
|
|
|
|
*/
|
2009-02-08 12:25:13 +00:00
|
|
|
SettingEntry::SettingEntry(SettingsPage *sub, StringID title)
|
2009-01-10 16:39:18 +00:00
|
|
|
{
|
2009-02-08 12:25:13 +00:00
|
|
|
this->flags = SEF_SUBTREE_KIND;
|
2009-01-10 16:39:18 +00:00
|
|
|
this->level = 0;
|
|
|
|
this->d.sub.page = sub;
|
|
|
|
this->d.sub.folded = true;
|
|
|
|
this->d.sub.title = title;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-02-08 12:25:13 +00:00
|
|
|
* Initialization of a setting entry
|
2009-01-10 16:39:18 +00:00
|
|
|
* @param level Page nesting level of this entry
|
|
|
|
* @param last_field Boolean indicating this entry is the last at the (sub-)page
|
|
|
|
*/
|
2009-02-08 12:25:13 +00:00
|
|
|
void SettingEntry::Init(byte level, bool last_field)
|
2009-01-10 16:39:18 +00:00
|
|
|
{
|
|
|
|
this->level = level;
|
2009-02-08 12:25:13 +00:00
|
|
|
if (last_field) this->flags |= SEF_LAST_FIELD;
|
2009-01-10 16:39:18 +00:00
|
|
|
|
2009-02-08 12:25:13 +00:00
|
|
|
switch (this->flags & SEF_KIND_MASK) {
|
|
|
|
case SEF_SETTING_KIND:
|
|
|
|
this->d.entry.setting = GetSettingFromName(this->d.entry.name, &this->d.entry.index);
|
2009-01-10 16:39:18 +00:00
|
|
|
assert(this->d.entry.setting != NULL);
|
|
|
|
break;
|
2009-02-08 12:25:13 +00:00
|
|
|
case SEF_SUBTREE_KIND:
|
2009-01-10 16:39:18 +00:00
|
|
|
this->d.sub.page->Init(level + 1);
|
|
|
|
break;
|
|
|
|
default: NOT_REACHED();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-10 17:27:11 +00:00
|
|
|
/** Recursively close all folds of sub-pages */
|
2009-02-08 12:25:13 +00:00
|
|
|
void SettingEntry::FoldAll()
|
2009-01-10 17:27:11 +00:00
|
|
|
{
|
2009-02-08 12:25:13 +00:00
|
|
|
switch(this->flags & SEF_KIND_MASK) {
|
|
|
|
case SEF_SETTING_KIND:
|
2009-01-10 17:27:11 +00:00
|
|
|
break;
|
|
|
|
|
2009-02-08 12:25:13 +00:00
|
|
|
case SEF_SUBTREE_KIND:
|
2009-01-10 17:27:11 +00:00
|
|
|
this->d.sub.folded = true;
|
|
|
|
this->d.sub.page->FoldAll();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: NOT_REACHED();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-10 16:42:28 +00:00
|
|
|
/**
|
2009-02-08 12:25:13 +00:00
|
|
|
* Set the button-depressed flags (#SEF_LEFT_DEPRESSED and #SEF_RIGHT_DEPRESSED) to a specified value
|
2009-01-10 16:42:28 +00:00
|
|
|
* @param new_val New value for the button flags
|
2009-02-08 12:25:13 +00:00
|
|
|
* @see SettingEntryFlags
|
2009-01-10 16:42:28 +00:00
|
|
|
*/
|
2009-02-08 12:25:13 +00:00
|
|
|
void SettingEntry::SetButtons(byte new_val)
|
2009-01-10 16:42:28 +00:00
|
|
|
{
|
2009-02-08 12:25:13 +00:00
|
|
|
assert((new_val & ~SEF_BUTTONS_MASK) == 0); // Should not touch any flags outside the buttons
|
|
|
|
this->flags = (this->flags & ~SEF_BUTTONS_MASK) | new_val;
|
2009-01-10 16:42:28 +00:00
|
|
|
}
|
|
|
|
|
2009-01-10 16:44:51 +00:00
|
|
|
/** Return numbers of rows needed to display the entry */
|
2009-02-08 12:25:13 +00:00
|
|
|
uint SettingEntry::Length() const
|
2009-01-10 16:44:51 +00:00
|
|
|
{
|
2009-02-08 12:25:13 +00:00
|
|
|
switch (this->flags & SEF_KIND_MASK) {
|
|
|
|
case SEF_SETTING_KIND:
|
2009-01-10 16:44:51 +00:00
|
|
|
return 1;
|
2009-02-08 12:25:13 +00:00
|
|
|
case SEF_SUBTREE_KIND:
|
2009-01-10 16:44:51 +00:00
|
|
|
if (this->d.sub.folded) return 1; // Only displaying the title
|
|
|
|
|
|
|
|
return 1 + this->d.sub.page->Length(); // 1 extra row for the title
|
|
|
|
default: NOT_REACHED();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-10 16:49:30 +00:00
|
|
|
/**
|
2009-02-08 12:25:13 +00:00
|
|
|
* Find setting entry at row \a row_num
|
2009-01-10 16:49:30 +00:00
|
|
|
* @param row_num Index of entry to return
|
|
|
|
* @param cur_row Current row number
|
2009-02-08 12:25:13 +00:00
|
|
|
* @return The requested setting entry or \c NULL if it not found
|
2009-01-10 16:49:30 +00:00
|
|
|
*/
|
2009-02-08 12:25:13 +00:00
|
|
|
SettingEntry *SettingEntry::FindEntry(uint row_num, uint *cur_row)
|
2009-01-10 16:49:30 +00:00
|
|
|
{
|
|
|
|
if (row_num == *cur_row) return this;
|
|
|
|
|
2009-02-08 12:25:13 +00:00
|
|
|
switch (this->flags & SEF_KIND_MASK) {
|
|
|
|
case SEF_SETTING_KIND:
|
2009-01-10 16:49:30 +00:00
|
|
|
(*cur_row)++;
|
|
|
|
break;
|
2009-02-08 12:25:13 +00:00
|
|
|
case SEF_SUBTREE_KIND:
|
2009-01-10 16:49:30 +00:00
|
|
|
(*cur_row)++; // add one for row containing the title
|
|
|
|
if (this->d.sub.folded) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* sub-page is visible => search it too */
|
|
|
|
return this->d.sub.page->FindEntry(row_num, cur_row);
|
|
|
|
default: NOT_REACHED();
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-01-10 16:51:27 +00:00
|
|
|
/**
|
2009-01-10 17:13:41 +00:00
|
|
|
* Draw a row in the settings panel.
|
|
|
|
*
|
2009-02-08 12:25:13 +00:00
|
|
|
* See SettingsPage::Draw() for an explanation about how drawing is performed.
|
2009-01-10 17:13:41 +00:00
|
|
|
*
|
|
|
|
* The \a parent_last parameter ensures that the vertical lines at the left are
|
|
|
|
* only drawn when another entry follows, that it prevents output like
|
|
|
|
* \verbatim
|
|
|
|
* |-- setting
|
|
|
|
* |-- (-) - Title
|
|
|
|
* | |-- setting
|
|
|
|
* | |-- setting
|
|
|
|
* \endverbatim
|
|
|
|
* The left-most vertical line is not wanted. It is prevented by setting the
|
|
|
|
* appropiate bit in the \a parent_last parameter.
|
|
|
|
*
|
2009-02-08 12:25:13 +00:00
|
|
|
* @param settings_ptr Pointer to current values of all settings
|
|
|
|
* @param base_x Left-most position in window/panel to start drawing \a first_row
|
|
|
|
* @param base_y Upper-most position in window/panel to start drawing \a first_row
|
2009-02-24 22:23:47 +00:00
|
|
|
* @param max_x The maximum x position to draw strings add.
|
2009-02-08 12:25:13 +00:00
|
|
|
* @param first_row First row number to draw
|
|
|
|
* @param max_row Row-number to stop drawing (the row-number of the row below the last row to draw)
|
|
|
|
* @param cur_row Current row number (internal variable)
|
|
|
|
* @param parent_last Last-field booleans of parent page level (page level \e i sets bit \e i to 1 if it is its last field)
|
2009-01-10 17:13:41 +00:00
|
|
|
* @return Row number of the next row to draw
|
2009-01-10 16:51:27 +00:00
|
|
|
*/
|
2009-02-24 22:23:47 +00:00
|
|
|
uint SettingEntry::Draw(GameSettings *settings_ptr, int base_x, int base_y, int max_x, uint first_row, uint max_row, uint cur_row, uint parent_last)
|
2009-01-10 16:51:27 +00:00
|
|
|
{
|
2009-01-10 17:13:41 +00:00
|
|
|
if (cur_row >= max_row) return cur_row;
|
|
|
|
|
|
|
|
int x = base_x;
|
|
|
|
int y = base_y;
|
|
|
|
if (cur_row >= first_row) {
|
|
|
|
int colour = _colour_gradient[COLOUR_ORANGE][4];
|
|
|
|
y = base_y + (cur_row - first_row) * SETTING_HEIGHT; // Compute correct y start position
|
|
|
|
|
|
|
|
/* Draw vertical for parent nesting levels */
|
|
|
|
for (uint lvl = 0; lvl < this->level; lvl++) {
|
|
|
|
if (!HasBit(parent_last, lvl)) GfxDrawLine(x + 4, y, x + 4, y + SETTING_HEIGHT - 1, colour);
|
|
|
|
x += LEVEL_WIDTH;
|
|
|
|
}
|
|
|
|
/* draw own |- prefix */
|
|
|
|
int halfway_y = y + SETTING_HEIGHT / 2;
|
2009-02-08 12:25:13 +00:00
|
|
|
int bottom_y = (flags & SEF_LAST_FIELD) ? halfway_y : y + SETTING_HEIGHT - 1;
|
2009-01-10 17:13:41 +00:00
|
|
|
GfxDrawLine(x + 4, y, x + 4, bottom_y, colour);
|
|
|
|
/* Small horizontal line from the last vertical line */
|
|
|
|
GfxDrawLine(x + 4, halfway_y, x + LEVEL_WIDTH - 4, halfway_y, colour);
|
|
|
|
x += LEVEL_WIDTH;
|
|
|
|
}
|
|
|
|
|
2009-02-08 12:25:13 +00:00
|
|
|
switch(this->flags & SEF_KIND_MASK) {
|
|
|
|
case SEF_SETTING_KIND:
|
2009-01-10 17:13:41 +00:00
|
|
|
if (cur_row >= first_row) {
|
2009-02-24 22:23:47 +00:00
|
|
|
DrawSetting(settings_ptr, this->d.entry.setting, x, y, max_x, this->flags & SEF_BUTTONS_MASK);
|
2009-01-10 17:13:41 +00:00
|
|
|
}
|
|
|
|
cur_row++;
|
|
|
|
break;
|
2009-02-08 12:25:13 +00:00
|
|
|
case SEF_SUBTREE_KIND:
|
2009-01-10 17:13:41 +00:00
|
|
|
if (cur_row >= first_row) {
|
|
|
|
DrawSprite((this->d.sub.folded ? SPR_CIRCLE_FOLDED : SPR_CIRCLE_UNFOLDED), PAL_NONE, x, y);
|
2009-03-21 20:12:12 +00:00
|
|
|
DrawString(x + 12, max_x, y, this->d.sub.title, TC_FROMSTRING);
|
2009-01-10 17:13:41 +00:00
|
|
|
}
|
|
|
|
cur_row++;
|
|
|
|
if (!this->d.sub.folded) {
|
2009-02-08 12:25:13 +00:00
|
|
|
if (this->flags & SEF_LAST_FIELD) {
|
2009-01-10 17:13:41 +00:00
|
|
|
assert(this->level < sizeof(parent_last));
|
|
|
|
SetBit(parent_last, this->level); // Add own last-field state
|
|
|
|
}
|
|
|
|
|
2009-02-24 22:23:47 +00:00
|
|
|
cur_row = this->d.sub.page->Draw(settings_ptr, base_x, base_y, max_x, first_row, max_row, cur_row, parent_last);
|
2009-01-10 17:13:41 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default: NOT_REACHED();
|
|
|
|
}
|
|
|
|
return cur_row;
|
2009-01-10 16:51:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Private function to draw setting value (button + text + current value)
|
2009-02-08 12:25:13 +00:00
|
|
|
* @param settings_ptr Pointer to current values of all settings
|
|
|
|
* @param sd Pointer to value description of setting to draw
|
|
|
|
* @param x Left-most position in window/panel to start drawing
|
|
|
|
* @param y Upper-most position in window/panel to start drawing
|
2009-02-24 22:23:47 +00:00
|
|
|
* @param max_x The maximum x position to draw strings add.
|
2009-02-08 12:25:13 +00:00
|
|
|
* @param state State of the left + right arrow buttons to draw for the setting
|
2009-01-10 16:51:27 +00:00
|
|
|
*/
|
2009-02-24 22:23:47 +00:00
|
|
|
void SettingEntry::DrawSetting(GameSettings *settings_ptr, const SettingDesc *sd, int x, int y, int max_x, int state)
|
2009-01-10 16:51:27 +00:00
|
|
|
{
|
|
|
|
const SettingDescBase *sdb = &sd->desc;
|
2009-02-08 12:25:13 +00:00
|
|
|
const void *var = GetVariableAddress(settings_ptr, &sd->save);
|
2009-01-10 16:51:27 +00:00
|
|
|
bool editable = true;
|
|
|
|
bool disabled = false;
|
|
|
|
|
|
|
|
/* We do not allow changes of some items when we are a client in a networkgame */
|
|
|
|
if (!(sd->save.conv & SLF_NETWORK_NO) && _networking && !_network_server) editable = false;
|
|
|
|
if ((sdb->flags & SGF_NETWORK_ONLY) && !_networking) editable = false;
|
|
|
|
if ((sdb->flags & SGF_NO_NETWORK) && _networking) editable = false;
|
|
|
|
|
|
|
|
if (sdb->cmd == SDT_BOOLX) {
|
2009-02-09 02:57:15 +00:00
|
|
|
static const Colours _bool_ctabs[2][2] = {{COLOUR_CREAM, COLOUR_RED}, {COLOUR_DARK_GREEN, COLOUR_GREEN}};
|
2009-01-10 16:51:27 +00:00
|
|
|
/* Draw checkbox for boolean-value either on/off */
|
|
|
|
bool on = (*(bool*)var);
|
|
|
|
|
|
|
|
DrawFrameRect(x, y, x + 19, y + 8, _bool_ctabs[!!on][!!editable], on ? FR_LOWERED : FR_NONE);
|
2009-02-08 12:25:13 +00:00
|
|
|
SetDParam(0, on ? STR_CONFIG_SETTING_ON : STR_CONFIG_SETTING_OFF);
|
2009-01-10 16:51:27 +00:00
|
|
|
} else {
|
|
|
|
int32 value;
|
|
|
|
|
|
|
|
value = (int32)ReadValue(var, sd->save.conv);
|
|
|
|
|
|
|
|
/* Draw [<][>] boxes for settings of an integer-type */
|
|
|
|
DrawArrowButtons(x, y, COLOUR_YELLOW, state, editable && value != (sdb->flags & SGF_0ISDISABLED ? 0 : sdb->min), editable && value != sdb->max);
|
|
|
|
|
|
|
|
disabled = (value == 0) && (sdb->flags & SGF_0ISDISABLED);
|
|
|
|
if (disabled) {
|
2009-02-08 12:25:13 +00:00
|
|
|
SetDParam(0, STR_CONFIG_SETTING_DISABLED);
|
2009-01-10 16:51:27 +00:00
|
|
|
} else {
|
|
|
|
if (sdb->flags & SGF_CURRENCY) {
|
2009-02-08 12:25:13 +00:00
|
|
|
SetDParam(0, STR_CONFIG_SETTING_CURRENCY);
|
2009-01-10 16:51:27 +00:00
|
|
|
} else if (sdb->flags & SGF_MULTISTRING) {
|
|
|
|
SetDParam(0, sdb->str + value + 1);
|
|
|
|
} else {
|
2009-02-08 12:25:13 +00:00
|
|
|
SetDParam(0, (sdb->flags & SGF_NOCOMMA) ? STR_CONFIG_SETTING_INT32 : STR_7024);
|
2009-01-10 16:51:27 +00:00
|
|
|
}
|
|
|
|
SetDParam(1, value);
|
|
|
|
}
|
|
|
|
}
|
2009-03-21 20:12:12 +00:00
|
|
|
DrawString(x + 25, max_x, y, (sdb->str) + disabled, TC_FROMSTRING);
|
2009-01-10 16:51:27 +00:00
|
|
|
}
|
|
|
|
|
2009-01-10 16:39:18 +00:00
|
|
|
|
2009-02-08 12:25:13 +00:00
|
|
|
/* == SettingsPage methods == */
|
2009-01-10 16:39:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialization of an entire setting page
|
|
|
|
* @param level Nesting level of this page (internal variable, do not provide a value for it when calling)
|
|
|
|
*/
|
2009-02-08 12:25:13 +00:00
|
|
|
void SettingsPage::Init(byte level)
|
2009-01-10 16:39:18 +00:00
|
|
|
{
|
|
|
|
for (uint field = 0; field < this->num; field++) {
|
|
|
|
this->entries[field].Init(level, field + 1 == num);
|
|
|
|
}
|
2009-01-10 16:29:31 +00:00
|
|
|
}
|
|
|
|
|
2009-01-10 17:27:11 +00:00
|
|
|
/** Recursively close all folds of sub-pages */
|
2009-02-08 12:25:13 +00:00
|
|
|
void SettingsPage::FoldAll()
|
2009-01-10 17:27:11 +00:00
|
|
|
{
|
|
|
|
for (uint field = 0; field < this->num; field++) {
|
|
|
|
this->entries[field].FoldAll();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-10 16:44:51 +00:00
|
|
|
/** Return number of rows needed to display the whole page */
|
2009-02-08 12:25:13 +00:00
|
|
|
uint SettingsPage::Length() const
|
2009-01-10 16:44:51 +00:00
|
|
|
{
|
|
|
|
uint length = 0;
|
|
|
|
for (uint field = 0; field < this->num; field++) {
|
|
|
|
length += this->entries[field].Length();
|
|
|
|
}
|
|
|
|
return length;
|
|
|
|
}
|
|
|
|
|
2009-01-10 16:49:30 +00:00
|
|
|
/**
|
2009-02-08 12:25:13 +00:00
|
|
|
* Find the setting entry at row number \a row_num
|
2009-01-10 16:49:30 +00:00
|
|
|
* @param row_num Index of entry to return
|
|
|
|
* @param cur_row Variable used for keeping track of the current row number. Should point to memory initialized to \c 0 when first called.
|
2009-02-08 12:25:13 +00:00
|
|
|
* @return The requested setting entry or \c NULL if it does not exist
|
2009-01-10 16:49:30 +00:00
|
|
|
*/
|
2009-02-08 12:25:13 +00:00
|
|
|
SettingEntry *SettingsPage::FindEntry(uint row_num, uint *cur_row) const
|
2009-01-10 16:49:30 +00:00
|
|
|
{
|
2009-02-08 12:25:13 +00:00
|
|
|
SettingEntry *pe = NULL;
|
2009-01-10 16:49:30 +00:00
|
|
|
|
|
|
|
for (uint field = 0; field < this->num; field++) {
|
|
|
|
pe = this->entries[field].FindEntry(row_num, cur_row);
|
|
|
|
if (pe != NULL) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return pe;
|
|
|
|
}
|
|
|
|
|
2009-01-10 17:13:41 +00:00
|
|
|
/**
|
|
|
|
* Draw a selected part of the settings page.
|
|
|
|
*
|
2009-02-08 12:25:13 +00:00
|
|
|
* The scrollbar uses rows of the page, while the page data strucure is a tree of #SettingsPage and #SettingEntry objects.
|
2009-01-10 17:13:41 +00:00
|
|
|
* As a result, the drawing routing traverses the tree from top to bottom, counting rows in \a cur_row until it reaches \a first_row.
|
|
|
|
* Then it enables drawing rows while traversing until \a max_row is reached, at which point drawing is terminated.
|
|
|
|
*
|
2009-02-08 12:25:13 +00:00
|
|
|
* @param settings_ptr Pointer to current values of all settings
|
|
|
|
* @param base_x Left-most position in window/panel to start drawing of each setting row
|
|
|
|
* @param base_y Upper-most position in window/panel to start drawing of row number \a first_row
|
2009-02-24 22:23:47 +00:00
|
|
|
* @param max_x The maximum x position to draw strings add.
|
2009-02-08 12:25:13 +00:00
|
|
|
* @param first_row Number of first row to draw
|
|
|
|
* @param max_row Row-number to stop drawing (the row-number of the row below the last row to draw)
|
|
|
|
* @param cur_row Current row number (internal variable)
|
|
|
|
* @param parent_last Last-field booleans of parent page level (page level \e i sets bit \e i to 1 if it is its last field)
|
2009-01-10 17:13:41 +00:00
|
|
|
* @return Row number of the next row to draw
|
|
|
|
*/
|
2009-02-24 22:23:47 +00:00
|
|
|
uint SettingsPage::Draw(GameSettings *settings_ptr, int base_x, int base_y, int max_x, uint first_row, uint max_row, uint cur_row, uint parent_last) const
|
2009-01-10 17:13:41 +00:00
|
|
|
{
|
|
|
|
if (cur_row >= max_row) return cur_row;
|
|
|
|
|
|
|
|
for (uint i = 0; i < this->num; i++) {
|
2009-02-24 22:23:47 +00:00
|
|
|
cur_row = this->entries[i].Draw(settings_ptr, base_x, base_y, max_x, first_row, max_row, cur_row, parent_last);
|
2009-01-10 17:13:41 +00:00
|
|
|
if (cur_row >= max_row) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return cur_row;
|
|
|
|
}
|
|
|
|
|
2009-01-10 16:29:31 +00:00
|
|
|
|
2009-02-08 12:25:13 +00:00
|
|
|
static SettingEntry _settings_ui_display[] = {
|
|
|
|
SettingEntry("gui.vehicle_speed"),
|
|
|
|
SettingEntry("gui.status_long_date"),
|
|
|
|
SettingEntry("gui.date_format_in_default_names"),
|
|
|
|
SettingEntry("gui.population_in_label"),
|
|
|
|
SettingEntry("gui.measure_tooltip"),
|
|
|
|
SettingEntry("gui.loading_indicators"),
|
|
|
|
SettingEntry("gui.liveries"),
|
|
|
|
SettingEntry("gui.show_track_reservation"),
|
|
|
|
SettingEntry("gui.expenses_layout"),
|
2009-01-10 17:35:19 +00:00
|
|
|
};
|
|
|
|
/** Display options sub-page */
|
2009-02-08 12:25:13 +00:00
|
|
|
static SettingsPage _settings_ui_display_page = {_settings_ui_display, lengthof(_settings_ui_display)};
|
|
|
|
|
|
|
|
static SettingEntry _settings_ui_interaction[] = {
|
|
|
|
SettingEntry("gui.window_snap_radius"),
|
|
|
|
SettingEntry("gui.window_soft_limit"),
|
|
|
|
SettingEntry("gui.link_terraform_toolbar"),
|
|
|
|
SettingEntry("gui.prefer_teamchat"),
|
|
|
|
SettingEntry("gui.autoscroll"),
|
|
|
|
SettingEntry("gui.reverse_scroll"),
|
|
|
|
SettingEntry("gui.smooth_scroll"),
|
|
|
|
SettingEntry("gui.left_mouse_btn_scrolling"),
|
2007-03-11 10:55:35 +00:00
|
|
|
/* While the horizontal scrollwheel scrolling is written as general code, only
|
|
|
|
* the cocoa (OSX) driver generates input for it.
|
2007-03-11 21:53:46 +00:00
|
|
|
* Since it's also able to completely disable the scrollwheel will we display it on all platforms anyway */
|
2009-02-08 12:25:13 +00:00
|
|
|
SettingEntry("gui.scrollwheel_scrolling"),
|
|
|
|
SettingEntry("gui.scrollwheel_multiplier"),
|
2007-08-29 08:20:04 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
/* We might need to emulate a right mouse button on mac */
|
2009-02-08 12:25:13 +00:00
|
|
|
SettingEntry("gui.right_mouse_btn_emulation"),
|
2007-08-29 08:20:04 +00:00
|
|
|
#endif
|
2009-01-10 17:35:19 +00:00
|
|
|
};
|
|
|
|
/** Interaction sub-page */
|
2009-02-08 12:25:13 +00:00
|
|
|
static SettingsPage _settings_ui_interaction_page = {_settings_ui_interaction, lengthof(_settings_ui_interaction)};
|
|
|
|
|
|
|
|
static SettingEntry _settings_ui[] = {
|
|
|
|
SettingEntry(&_settings_ui_display_page, STR_CONFIG_SETTING_DISPLAY_OPTIONS),
|
|
|
|
SettingEntry(&_settings_ui_interaction_page, STR_CONFIG_SETTING_INTERACTION),
|
|
|
|
SettingEntry("gui.show_finances"),
|
|
|
|
SettingEntry("gui.errmsg_duration"),
|
|
|
|
SettingEntry("gui.toolbar_pos"),
|
|
|
|
SettingEntry("gui.pause_on_newgame"),
|
|
|
|
SettingEntry("gui.advanced_vehicle_list"),
|
|
|
|
SettingEntry("gui.timetable_in_ticks"),
|
|
|
|
SettingEntry("gui.quick_goto"),
|
|
|
|
SettingEntry("gui.default_rail_type"),
|
|
|
|
SettingEntry("gui.always_build_infrastructure"),
|
|
|
|
SettingEntry("gui.persistent_buildingtools"),
|
2009-02-09 02:57:15 +00:00
|
|
|
SettingEntry("gui.coloured_news_year"),
|
2004-08-11 21:48:27 +00:00
|
|
|
};
|
2009-01-10 17:14:59 +00:00
|
|
|
/** Interface subpage */
|
2009-02-08 12:25:13 +00:00
|
|
|
static SettingsPage _settings_ui_page = {_settings_ui, lengthof(_settings_ui)};
|
|
|
|
|
|
|
|
static SettingEntry _settings_construction_signals[] = {
|
|
|
|
SettingEntry("construction.signal_side"),
|
|
|
|
SettingEntry("gui.enable_signal_gui"),
|
|
|
|
SettingEntry("gui.drag_signals_density"),
|
|
|
|
SettingEntry("gui.semaphore_build_before"),
|
|
|
|
SettingEntry("gui.default_signal_type"),
|
|
|
|
SettingEntry("gui.cycle_signal_types"),
|
2009-01-10 17:35:19 +00:00
|
|
|
};
|
|
|
|
/** Signals subpage */
|
2009-02-08 12:25:13 +00:00
|
|
|
static SettingsPage _settings_construction_signals_page = {_settings_construction_signals, lengthof(_settings_construction_signals)};
|
|
|
|
|
|
|
|
static SettingEntry _settings_construction[] = {
|
|
|
|
SettingEntry(&_settings_construction_signals_page, STR_CONFIG_SETTING_CONSTRUCTION_SIGNALS),
|
|
|
|
SettingEntry("construction.build_on_slopes"),
|
|
|
|
SettingEntry("construction.autoslope"),
|
|
|
|
SettingEntry("construction.extra_dynamite"),
|
|
|
|
SettingEntry("construction.longbridges"),
|
|
|
|
SettingEntry("station.always_small_airport"),
|
|
|
|
SettingEntry("construction.freeform_edges"),
|
2006-03-17 22:47:52 +00:00
|
|
|
};
|
2009-01-10 17:14:59 +00:00
|
|
|
/** Construction sub-page */
|
2009-02-08 12:25:13 +00:00
|
|
|
static SettingsPage _settings_construction_page = {_settings_construction, lengthof(_settings_construction)};
|
2006-03-17 22:47:52 +00:00
|
|
|
|
2009-02-08 12:25:13 +00:00
|
|
|
static SettingEntry _settings_stations_cargo[] = {
|
|
|
|
SettingEntry("order.improved_load"),
|
|
|
|
SettingEntry("order.gradual_loading"),
|
|
|
|
SettingEntry("order.selectgoods"),
|
2009-01-10 17:35:19 +00:00
|
|
|
};
|
|
|
|
/** Cargo handling sub-page */
|
2009-02-08 12:25:13 +00:00
|
|
|
static SettingsPage _settings_stations_cargo_page = {_settings_stations_cargo, lengthof(_settings_stations_cargo)};
|
|
|
|
|
|
|
|
static SettingEntry _settings_stations[] = {
|
|
|
|
SettingEntry(&_settings_stations_cargo_page, STR_CONFIG_SETTING_STATIONS_CARGOHANDLING),
|
|
|
|
SettingEntry("station.join_stations"),
|
|
|
|
SettingEntry("station.nonuniform_stations"),
|
|
|
|
SettingEntry("station.adjacent_stations"),
|
|
|
|
SettingEntry("station.distant_join_stations"),
|
|
|
|
SettingEntry("station.station_spread"),
|
|
|
|
SettingEntry("economy.station_noise_level"),
|
|
|
|
SettingEntry("station.modified_catchment"),
|
|
|
|
SettingEntry("construction.road_stop_on_town_road"),
|
2009-03-02 22:57:47 +00:00
|
|
|
SettingEntry("construction.road_stop_on_competitor_road"),
|
2006-03-17 22:47:52 +00:00
|
|
|
};
|
2009-01-10 17:14:59 +00:00
|
|
|
/** Stations sub-page */
|
2009-02-08 12:25:13 +00:00
|
|
|
static SettingsPage _settings_stations_page = {_settings_stations, lengthof(_settings_stations)};
|
|
|
|
|
|
|
|
static SettingEntry _settings_economy_towns[] = {
|
|
|
|
SettingEntry("economy.bribe"),
|
|
|
|
SettingEntry("economy.exclusive_rights"),
|
|
|
|
SettingEntry("economy.town_layout"),
|
|
|
|
SettingEntry("economy.allow_town_roads"),
|
|
|
|
SettingEntry("economy.mod_road_rebuild"),
|
|
|
|
SettingEntry("economy.town_growth_rate"),
|
|
|
|
SettingEntry("economy.larger_towns"),
|
|
|
|
SettingEntry("economy.initial_city_size"),
|
2006-03-17 22:47:52 +00:00
|
|
|
};
|
2009-01-10 17:35:19 +00:00
|
|
|
/** Towns sub-page */
|
2009-02-08 12:25:13 +00:00
|
|
|
static SettingsPage _settings_economy_towns_page = {_settings_economy_towns, lengthof(_settings_economy_towns)};
|
2009-01-10 17:35:19 +00:00
|
|
|
|
2009-02-08 12:25:13 +00:00
|
|
|
static SettingEntry _settings_economy_industries[] = {
|
|
|
|
SettingEntry("construction.raw_industry_construction"),
|
|
|
|
SettingEntry("economy.multiple_industry_per_town"),
|
|
|
|
SettingEntry("economy.same_industry_close"),
|
|
|
|
SettingEntry("game_creation.oil_refinery_limit"),
|
2009-01-10 17:35:19 +00:00
|
|
|
};
|
|
|
|
/** Industries sub-page */
|
2009-02-08 12:25:13 +00:00
|
|
|
static SettingsPage _settings_economy_industries_page = {_settings_economy_industries, lengthof(_settings_economy_industries)};
|
2009-01-10 17:35:19 +00:00
|
|
|
|
2009-02-08 12:25:13 +00:00
|
|
|
static SettingEntry _settings_economy[] = {
|
|
|
|
SettingEntry(&_settings_economy_towns_page, STR_CONFIG_SETTING_ECONOMY_TOWNS),
|
|
|
|
SettingEntry(&_settings_economy_industries_page, STR_CONFIG_SETTING_ECONOMY_INDUSTRIES),
|
|
|
|
SettingEntry("economy.inflation"),
|
|
|
|
SettingEntry("economy.smooth_economy"),
|
2009-01-10 17:35:19 +00:00
|
|
|
};
|
2009-01-10 17:14:59 +00:00
|
|
|
/** Economy sub-page */
|
2009-02-08 12:25:13 +00:00
|
|
|
static SettingsPage _settings_economy_page = {_settings_economy, lengthof(_settings_economy)};
|
|
|
|
|
|
|
|
static SettingEntry _settings_ai_npc[] = {
|
|
|
|
SettingEntry("ai.ai_in_multiplayer"),
|
|
|
|
SettingEntry("ai.ai_disable_veh_train"),
|
|
|
|
SettingEntry("ai.ai_disable_veh_roadveh"),
|
|
|
|
SettingEntry("ai.ai_disable_veh_aircraft"),
|
|
|
|
SettingEntry("ai.ai_disable_veh_ship"),
|
|
|
|
SettingEntry("ai.ai_max_opcode_till_suspend"),
|
2006-03-17 22:47:52 +00:00
|
|
|
};
|
2009-01-10 17:35:19 +00:00
|
|
|
/** Computer players sub-page */
|
2009-02-08 12:25:13 +00:00
|
|
|
static SettingsPage _settings_ai_npc_page = {_settings_ai_npc, lengthof(_settings_ai_npc)};
|
2009-01-10 17:35:19 +00:00
|
|
|
|
2009-02-08 12:25:13 +00:00
|
|
|
static SettingEntry _settings_ai[] = {
|
|
|
|
SettingEntry(&_settings_ai_npc_page, STR_CONFIG_SETTING_AI_NPC),
|
|
|
|
SettingEntry("economy.give_money"),
|
|
|
|
SettingEntry("economy.allow_shares"),
|
2009-01-10 17:35:19 +00:00
|
|
|
};
|
2009-01-10 17:14:59 +00:00
|
|
|
/** AI sub-page */
|
2009-02-08 12:25:13 +00:00
|
|
|
static SettingsPage _settings_ai_page = {_settings_ai, lengthof(_settings_ai)};
|
|
|
|
|
|
|
|
static SettingEntry _settings_vehicles_routing[] = {
|
|
|
|
SettingEntry("pf.pathfinder_for_trains"),
|
|
|
|
SettingEntry("pf.forbid_90_deg"),
|
|
|
|
SettingEntry("pf.pathfinder_for_roadvehs"),
|
|
|
|
SettingEntry("pf.roadveh_queue"),
|
|
|
|
SettingEntry("pf.pathfinder_for_ships"),
|
2009-01-10 17:35:19 +00:00
|
|
|
};
|
|
|
|
/** Autorenew sub-page */
|
2009-02-08 12:25:13 +00:00
|
|
|
static SettingsPage _settings_vehicles_routing_page = {_settings_vehicles_routing, lengthof(_settings_vehicles_routing)};
|
2009-01-10 17:35:19 +00:00
|
|
|
|
2009-02-08 12:25:13 +00:00
|
|
|
static SettingEntry _settings_vehicles_autorenew[] = {
|
|
|
|
SettingEntry("gui.autorenew"),
|
|
|
|
SettingEntry("gui.autorenew_months"),
|
|
|
|
SettingEntry("gui.autorenew_money"),
|
2009-01-10 17:35:19 +00:00
|
|
|
};
|
|
|
|
/** Autorenew sub-page */
|
2009-02-08 12:25:13 +00:00
|
|
|
static SettingsPage _settings_vehicles_autorenew_page = {_settings_vehicles_autorenew, lengthof(_settings_vehicles_autorenew)};
|
|
|
|
|
|
|
|
static SettingEntry _settings_vehicles_servicing[] = {
|
|
|
|
SettingEntry("vehicle.servint_ispercent"),
|
|
|
|
SettingEntry("vehicle.servint_trains"),
|
|
|
|
SettingEntry("vehicle.servint_roadveh"),
|
|
|
|
SettingEntry("vehicle.servint_ships"),
|
|
|
|
SettingEntry("vehicle.servint_aircraft"),
|
|
|
|
SettingEntry("order.no_servicing_if_no_breakdowns"),
|
|
|
|
SettingEntry("order.serviceathelipad"),
|
2009-01-10 17:35:19 +00:00
|
|
|
};
|
|
|
|
/** Servicing sub-page */
|
2009-02-08 12:25:13 +00:00
|
|
|
static SettingsPage _settings_vehicles_servicing_page = {_settings_vehicles_servicing, lengthof(_settings_vehicles_servicing)};
|
|
|
|
|
|
|
|
static SettingEntry _settings_vehicles_trains[] = {
|
|
|
|
SettingEntry("vehicle.train_acceleration_model"),
|
|
|
|
SettingEntry("vehicle.mammoth_trains"),
|
|
|
|
SettingEntry("gui.lost_train_warn"),
|
|
|
|
SettingEntry("vehicle.wagon_speed_limits"),
|
|
|
|
SettingEntry("vehicle.disable_elrails"),
|
|
|
|
SettingEntry("vehicle.freight_trains"),
|
2009-01-10 17:35:19 +00:00
|
|
|
};
|
|
|
|
/** Trains sub-page */
|
2009-02-08 12:25:13 +00:00
|
|
|
static SettingsPage _settings_vehicles_trains_page = {_settings_vehicles_trains, lengthof(_settings_vehicles_trains)};
|
|
|
|
|
|
|
|
static SettingEntry _settings_vehicles[] = {
|
|
|
|
SettingEntry(&_settings_vehicles_routing_page, STR_CONFIG_SETTING_VEHICLES_ROUTING),
|
|
|
|
SettingEntry(&_settings_vehicles_autorenew_page, STR_CONFIG_SETTING_VEHICLES_AUTORENEW),
|
|
|
|
SettingEntry(&_settings_vehicles_servicing_page, STR_CONFIG_SETTING_VEHICLES_SERVICING),
|
|
|
|
SettingEntry(&_settings_vehicles_trains_page, STR_CONFIG_SETTING_VEHICLES_TRAINS),
|
|
|
|
SettingEntry("order.gotodepot"),
|
|
|
|
SettingEntry("gui.new_nonstop"),
|
|
|
|
SettingEntry("gui.order_review_system"),
|
|
|
|
SettingEntry("gui.vehicle_income_warn"),
|
|
|
|
SettingEntry("vehicle.never_expire_vehicles"),
|
|
|
|
SettingEntry("vehicle.max_trains"),
|
|
|
|
SettingEntry("vehicle.max_roadveh"),
|
|
|
|
SettingEntry("vehicle.max_aircraft"),
|
|
|
|
SettingEntry("vehicle.max_ships"),
|
|
|
|
SettingEntry("vehicle.plane_speed"),
|
|
|
|
SettingEntry("order.timetabling"),
|
|
|
|
SettingEntry("vehicle.dynamic_engines"),
|
2006-03-17 22:47:52 +00:00
|
|
|
};
|
2009-01-10 17:14:59 +00:00
|
|
|
/** Vehicles sub-page */
|
2009-02-08 12:25:13 +00:00
|
|
|
static SettingsPage _settings_vehicles_page = {_settings_vehicles, lengthof(_settings_vehicles)};
|
|
|
|
|
|
|
|
static SettingEntry _settings_main[] = {
|
|
|
|
SettingEntry(&_settings_ui_page, STR_CONFIG_SETTING_GUI),
|
|
|
|
SettingEntry(&_settings_construction_page, STR_CONFIG_SETTING_CONSTRUCTION),
|
|
|
|
SettingEntry(&_settings_vehicles_page, STR_CONFIG_SETTING_VEHICLES),
|
|
|
|
SettingEntry(&_settings_stations_page, STR_CONFIG_SETTING_STATIONS),
|
|
|
|
SettingEntry(&_settings_economy_page, STR_CONFIG_SETTING_ECONOMY),
|
|
|
|
SettingEntry(&_settings_ai_page, STR_CONFIG_SETTING_AI),
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
2009-01-10 17:14:59 +00:00
|
|
|
/** Main page, holding all advanced settings */
|
2009-02-08 12:25:13 +00:00
|
|
|
static SettingsPage _settings_main_page = {_settings_main, lengthof(_settings_main)};
|
2009-01-10 17:14:59 +00:00
|
|
|
|
2009-02-08 12:25:13 +00:00
|
|
|
/** Widget numbers of settings window */
|
|
|
|
enum GameSettingsWidgets {
|
|
|
|
SETTINGSEL_OPTIONSPANEL = 2, ///< Panel widget containing the option lists
|
|
|
|
SETTINGSEL_SCROLLBAR, ///< Scrollbar
|
|
|
|
SETTINGSEL_RESIZE, ///< Resize button
|
2008-01-04 02:32:58 +00:00
|
|
|
};
|
|
|
|
|
2009-02-08 12:25:13 +00:00
|
|
|
struct GameSettingsWindow : Window {
|
|
|
|
static const int SETTINGTREE_LEFT_OFFSET; ///< Position of left edge of setting values
|
|
|
|
static const int SETTINGTREE_TOP_OFFSET; ///< Position of top edge of setting values
|
2009-01-03 11:00:40 +00:00
|
|
|
|
2009-02-08 12:25:13 +00:00
|
|
|
static GameSettings *settings_ptr; ///< Pointer to the game settings being displayed and modified
|
2006-03-02 01:41:25 +00:00
|
|
|
|
2009-02-08 12:25:13 +00:00
|
|
|
SettingEntry *valuewindow_entry; ///< If non-NULL, pointer to setting for which a value-entering window has been opened
|
|
|
|
SettingEntry *clicked_entry; ///< If non-NULL, pointer to a clicked numeric setting (with a depressed left or right button)
|
2006-03-17 22:47:52 +00:00
|
|
|
|
2009-02-08 12:25:13 +00:00
|
|
|
GameSettingsWindow(const WindowDesc *desc) : Window(desc)
|
2008-05-15 21:48:47 +00:00
|
|
|
{
|
2009-01-03 11:00:40 +00:00
|
|
|
/* Check that the widget doesn't get moved without adapting the constant as well.
|
|
|
|
* - SETTINGTREE_LEFT_OFFSET should be 5 pixels to the right of the left edge of the panel
|
|
|
|
* - SETTINGTREE_TOP_OFFSET should be 5 pixels below the top edge of the panel
|
|
|
|
*/
|
2009-02-08 12:25:13 +00:00
|
|
|
assert(this->widget[SETTINGSEL_OPTIONSPANEL].left + 5 == SETTINGTREE_LEFT_OFFSET);
|
|
|
|
assert(this->widget[SETTINGSEL_OPTIONSPANEL].top + 5 == SETTINGTREE_TOP_OFFSET);
|
2009-01-03 11:00:40 +00:00
|
|
|
|
2008-05-15 21:48:47 +00:00
|
|
|
static bool first_time = true;
|
2006-03-17 22:47:52 +00:00
|
|
|
|
2009-02-08 12:25:13 +00:00
|
|
|
settings_ptr = (_game_mode == GM_MENU) ? &_settings_newgame : &_settings_game;
|
2006-03-17 22:47:52 +00:00
|
|
|
|
2008-05-15 21:48:47 +00:00
|
|
|
/* Build up the dynamic settings-array only once per OpenTTD session */
|
|
|
|
if (first_time) {
|
2009-02-08 12:25:13 +00:00
|
|
|
_settings_main_page.Init();
|
2008-05-15 21:48:47 +00:00
|
|
|
first_time = false;
|
2009-01-10 17:27:11 +00:00
|
|
|
} else {
|
2009-02-08 12:25:13 +00:00
|
|
|
_settings_main_page.FoldAll(); // Close all sub-pages
|
2008-05-15 21:48:47 +00:00
|
|
|
}
|
2008-02-18 12:36:10 +00:00
|
|
|
|
2009-02-08 12:25:13 +00:00
|
|
|
this->valuewindow_entry = NULL; // No setting entry for which a entry window is opened
|
|
|
|
this->clicked_entry = NULL; // No numeric setting buttons are depressed
|
2009-01-03 11:24:27 +00:00
|
|
|
this->vscroll.pos = 0;
|
2009-02-08 12:25:13 +00:00
|
|
|
this->vscroll.cap = (this->widget[SETTINGSEL_OPTIONSPANEL].bottom - this->widget[SETTINGSEL_OPTIONSPANEL].top - 8) / SETTING_HEIGHT;
|
|
|
|
SetVScrollCount(this, _settings_main_page.Length());
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-01-03 11:24:27 +00:00
|
|
|
this->resize.step_height = SETTING_HEIGHT;
|
|
|
|
this->resize.height = this->height;
|
|
|
|
this->resize.step_width = 1;
|
|
|
|
this->resize.width = this->width;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-15 21:48:47 +00:00
|
|
|
this->FindWindowPlacementAndResize(desc);
|
|
|
|
}
|
2006-03-02 01:41:25 +00:00
|
|
|
|
2008-05-15 21:48:47 +00:00
|
|
|
virtual void OnPaint()
|
|
|
|
{
|
2008-05-17 12:48:06 +00:00
|
|
|
this->DrawWidgets();
|
2009-02-08 12:25:13 +00:00
|
|
|
_settings_main_page.Draw(settings_ptr, SETTINGTREE_LEFT_OFFSET, SETTINGTREE_TOP_OFFSET,
|
2009-02-24 22:23:47 +00:00
|
|
|
this->width - 13, this->vscroll.pos, this->vscroll.pos + this->vscroll.cap);
|
2009-01-03 11:07:43 +00:00
|
|
|
}
|
2008-05-15 21:48:47 +00:00
|
|
|
|
|
|
|
virtual void OnClick(Point pt, int widget)
|
|
|
|
{
|
2009-02-08 12:25:13 +00:00
|
|
|
if (widget != SETTINGSEL_OPTIONSPANEL) return;
|
2008-05-15 21:48:47 +00:00
|
|
|
|
2009-01-10 19:22:05 +00:00
|
|
|
int y = pt.y - SETTINGTREE_TOP_OFFSET; // Shift y coordinate
|
|
|
|
if (y < 0) return; // Clicked above first entry
|
2009-01-03 11:03:53 +00:00
|
|
|
|
2009-01-10 19:22:05 +00:00
|
|
|
byte btn = this->vscroll.pos + y / SETTING_HEIGHT; // Compute which setting is selected
|
|
|
|
if (y % SETTING_HEIGHT > SETTING_HEIGHT - 2) return; // Clicked too low at the setting
|
2009-01-03 11:03:53 +00:00
|
|
|
|
2009-01-10 19:22:05 +00:00
|
|
|
uint cur_row = 0;
|
2009-02-08 12:25:13 +00:00
|
|
|
SettingEntry *pe = _settings_main_page.FindEntry(btn, &cur_row);
|
2008-05-15 21:48:47 +00:00
|
|
|
|
2009-01-10 19:22:05 +00:00
|
|
|
if (pe == NULL) return; // Clicked below the last setting of the page
|
2009-01-10 17:13:41 +00:00
|
|
|
|
2009-01-10 19:22:05 +00:00
|
|
|
int x = pt.x - SETTINGTREE_LEFT_OFFSET - (pe->level + 1) * LEVEL_WIDTH; // Shift x coordinate
|
|
|
|
if (x < 0) return; // Clicked left of the entry
|
2009-01-10 16:51:27 +00:00
|
|
|
|
2009-02-08 12:25:13 +00:00
|
|
|
if ((pe->flags & SEF_KIND_MASK) == SEF_SUBTREE_KIND) {
|
2009-01-10 19:22:05 +00:00
|
|
|
pe->d.sub.folded = !pe->d.sub.folded; // Flip 'folded'-ness of the sub-page
|
2009-01-10 16:51:27 +00:00
|
|
|
|
2009-02-08 12:25:13 +00:00
|
|
|
SetVScrollCount(this, _settings_main_page.Length());
|
2009-01-10 19:22:05 +00:00
|
|
|
this->SetDirty();
|
|
|
|
return;
|
|
|
|
}
|
2008-01-04 03:11:36 +00:00
|
|
|
|
2009-02-08 12:25:13 +00:00
|
|
|
assert((pe->flags & SEF_KIND_MASK) == SEF_SETTING_KIND);
|
2009-01-10 19:22:05 +00:00
|
|
|
const SettingDesc *sd = pe->d.entry.setting;
|
2008-05-15 21:48:47 +00:00
|
|
|
|
2009-01-10 19:22:05 +00:00
|
|
|
/* return if action is only active in network, or only settable by server */
|
|
|
|
if (!(sd->save.conv & SLF_NETWORK_NO) && _networking && !_network_server) return;
|
|
|
|
if ((sd->desc.flags & SGF_NETWORK_ONLY) && !_networking) return;
|
|
|
|
if ((sd->desc.flags & SGF_NO_NETWORK) && _networking) return;
|
|
|
|
|
2009-02-08 12:25:13 +00:00
|
|
|
void *var = GetVariableAddress(settings_ptr, &sd->save);
|
2009-01-10 19:22:05 +00:00
|
|
|
int32 value = (int32)ReadValue(var, sd->save.conv);
|
|
|
|
|
|
|
|
/* clicked on the icon on the left side. Either scroller or bool on/off */
|
|
|
|
if (x < 21) {
|
|
|
|
const SettingDescBase *sdb = &sd->desc;
|
|
|
|
int32 oldvalue = value;
|
|
|
|
|
|
|
|
switch (sdb->cmd) {
|
|
|
|
case SDT_BOOLX: value ^= 1; break;
|
|
|
|
case SDT_ONEOFMANY:
|
|
|
|
case SDT_NUMX: {
|
|
|
|
/* Add a dynamic step-size to the scroller. In a maximum of
|
|
|
|
* 50-steps you should be able to get from min to max,
|
|
|
|
* unless specified otherwise in the 'interval' variable
|
2009-02-08 12:25:13 +00:00
|
|
|
* of the current setting. */
|
2009-01-10 19:22:05 +00:00
|
|
|
uint32 step = (sdb->interval == 0) ? ((sdb->max - sdb->min) / 50) : sdb->interval;
|
|
|
|
if (step == 0) step = 1;
|
|
|
|
|
|
|
|
/* don't allow too fast scrolling */
|
|
|
|
if ((this->flags4 & WF_TIMEOUT_MASK) > WF_TIMEOUT_TRIGGER) {
|
|
|
|
_left_button_clicked = false;
|
|
|
|
return;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2004-08-16 21:02:06 +00:00
|
|
|
|
2009-01-10 19:22:05 +00:00
|
|
|
/* Increase or decrease the value and clamp it to extremes */
|
|
|
|
if (x >= 10) {
|
|
|
|
value += step;
|
|
|
|
if (value > sdb->max) value = sdb->max;
|
|
|
|
if (value < sdb->min) value = sdb->min; // skip between "disabled" and minimum
|
|
|
|
} else {
|
|
|
|
value -= step;
|
|
|
|
if (value < sdb->min) value = (sdb->flags & SGF_0ISDISABLED) ? 0 : sdb->min;
|
2008-05-15 21:48:47 +00:00
|
|
|
}
|
2009-01-10 19:22:05 +00:00
|
|
|
|
|
|
|
/* Set up scroller timeout for numeric values */
|
|
|
|
if (value != oldvalue && !(sd->desc.flags & SGF_MULTISTRING)) {
|
|
|
|
if (this->clicked_entry != NULL) { // Release previous buttons if any
|
|
|
|
this->clicked_entry->SetButtons(0);
|
|
|
|
}
|
|
|
|
this->clicked_entry = pe;
|
2009-02-08 12:25:13 +00:00
|
|
|
this->clicked_entry->SetButtons((x >= 10) ? SEF_RIGHT_DEPRESSED : SEF_LEFT_DEPRESSED);
|
2009-01-10 19:22:05 +00:00
|
|
|
this->flags4 |= WF_TIMEOUT_BEGIN;
|
|
|
|
_left_button_clicked = false;
|
2008-05-15 21:48:47 +00:00
|
|
|
}
|
2009-01-10 19:22:05 +00:00
|
|
|
} break;
|
|
|
|
|
|
|
|
default: NOT_REACHED();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (value != oldvalue) {
|
2009-02-08 12:25:13 +00:00
|
|
|
SetSettingValue(pe->d.entry.index, value);
|
2009-01-10 19:22:05 +00:00
|
|
|
this->SetDirty();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* only open editbox for types that its sensible for */
|
|
|
|
if (sd->desc.cmd != SDT_BOOLX && !(sd->desc.flags & SGF_MULTISTRING)) {
|
|
|
|
/* Show the correct currency-translated value */
|
|
|
|
if (sd->desc.flags & SGF_CURRENCY) value *= _currency->rate;
|
|
|
|
|
|
|
|
this->valuewindow_entry = pe;
|
|
|
|
SetDParam(0, value);
|
2009-02-08 12:25:13 +00:00
|
|
|
ShowQueryString(STR_CONFIG_SETTING_INT32, STR_CONFIG_SETTING_QUERY_CAPT, 10, 100, this, CS_NUMERAL, QSF_NONE);
|
2009-01-10 19:22:05 +00:00
|
|
|
}
|
2008-05-15 21:48:47 +00:00
|
|
|
}
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-15 21:48:47 +00:00
|
|
|
virtual void OnTimeout()
|
|
|
|
{
|
2009-01-10 16:42:28 +00:00
|
|
|
if (this->clicked_entry != NULL) { // On timeout, release any depressed buttons
|
|
|
|
this->clicked_entry->SetButtons(0);
|
|
|
|
this->clicked_entry = NULL;
|
|
|
|
this->SetDirty();
|
|
|
|
}
|
2008-05-15 21:48:47 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-15 21:48:47 +00:00
|
|
|
virtual void OnQueryTextFinished(char *str)
|
|
|
|
{
|
|
|
|
if (!StrEmpty(str)) {
|
2009-01-10 16:46:10 +00:00
|
|
|
assert(this->valuewindow_entry != NULL);
|
2009-02-08 12:25:13 +00:00
|
|
|
assert((this->valuewindow_entry->flags & SEF_KIND_MASK) == SEF_SETTING_KIND);
|
2009-01-10 16:46:10 +00:00
|
|
|
const SettingDesc *sd = this->valuewindow_entry->d.entry.setting;
|
2008-05-15 21:48:47 +00:00
|
|
|
int32 value = atoi(str);
|
2006-03-02 01:41:25 +00:00
|
|
|
|
2008-05-15 21:48:47 +00:00
|
|
|
/* Save the correct currency-translated value */
|
|
|
|
if (sd->desc.flags & SGF_CURRENCY) value /= _currency->rate;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-02-08 12:25:13 +00:00
|
|
|
SetSettingValue(this->valuewindow_entry->d.entry.index, value);
|
2008-05-15 21:48:47 +00:00
|
|
|
this->SetDirty();
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2009-01-03 11:24:27 +00:00
|
|
|
|
|
|
|
virtual void OnResize(Point new_size, Point delta)
|
|
|
|
{
|
|
|
|
this->vscroll.cap += delta.y / SETTING_HEIGHT;
|
2009-02-08 12:25:13 +00:00
|
|
|
SetVScrollCount(this, _settings_main_page.Length());
|
2009-01-03 11:24:27 +00:00
|
|
|
}
|
2008-05-15 21:48:47 +00:00
|
|
|
};
|
|
|
|
|
2009-02-08 12:25:13 +00:00
|
|
|
GameSettings *GameSettingsWindow::settings_ptr = NULL;
|
|
|
|
const int GameSettingsWindow::SETTINGTREE_LEFT_OFFSET = 5;
|
|
|
|
const int GameSettingsWindow::SETTINGTREE_TOP_OFFSET = 19;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-02-08 12:25:13 +00:00
|
|
|
static const Widget _settings_selection_widgets[] = {
|
2008-07-31 17:45:52 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, COLOUR_MAUVE, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
2009-02-08 12:25:13 +00:00
|
|
|
{ WWT_CAPTION, RESIZE_RIGHT, COLOUR_MAUVE, 11, 411, 0, 13, STR_CONFIG_SETTING_CAPTION, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
|
|
{ WWT_PANEL, RESIZE_RB, COLOUR_MAUVE, 0, 399, 14, 187, 0x0, STR_NULL}, // SETTINGSEL_OPTIONSPANEL
|
|
|
|
{ WWT_SCROLLBAR, RESIZE_LRB, COLOUR_MAUVE, 400, 411, 14, 175, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, // SETTINGSEL_SCROLLBAR
|
|
|
|
{ WWT_RESIZEBOX, RESIZE_LRTB, COLOUR_MAUVE, 400, 411, 176, 187, 0x0, STR_RESIZE_BUTTON}, // SETTINGSEL_RESIZE
|
2004-09-07 21:48:09 +00:00
|
|
|
{ WIDGETS_END},
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
2009-03-15 15:12:06 +00:00
|
|
|
static const WindowDesc _settings_selection_desc(
|
2009-01-10 17:27:11 +00:00
|
|
|
WDP_CENTER, WDP_CENTER, 412, 188, 450, 397,
|
2007-02-01 15:49:12 +00:00
|
|
|
WC_GAME_OPTIONS, WC_NONE,
|
2009-01-03 11:24:27 +00:00
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_RESIZABLE,
|
2009-03-15 15:12:06 +00:00
|
|
|
_settings_selection_widgets
|
|
|
|
);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-02-08 12:25:13 +00:00
|
|
|
void ShowGameSettings()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
DeleteWindowById(WC_GAME_OPTIONS, 0);
|
2009-02-08 12:25:13 +00:00
|
|
|
new GameSettingsWindow(&_settings_selection_desc);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2004-11-21 22:44:13 +00:00
|
|
|
|
|
|
|
|
2006-08-02 18:36:53 +00:00
|
|
|
/**
|
|
|
|
* Draw [<][>] boxes.
|
|
|
|
* @param x the x position to draw
|
|
|
|
* @param y the y position to draw
|
2008-08-08 03:37:00 +00:00
|
|
|
* @param button_colour the colour of the button
|
2006-08-02 18:36:53 +00:00
|
|
|
* @param state 0 = none clicked, 1 = first clicked, 2 = second clicked
|
|
|
|
* @param clickable_left is the left button clickable?
|
|
|
|
* @param clickable_right is the right button clickable?
|
|
|
|
*/
|
2008-08-08 06:02:06 +00:00
|
|
|
void DrawArrowButtons(int x, int y, Colours button_colour, byte state, bool clickable_left, bool clickable_right)
|
2004-12-22 13:19:26 +00:00
|
|
|
{
|
2008-11-23 12:35:02 +00:00
|
|
|
int colour = _colour_gradient[button_colour][2];
|
2006-08-02 18:36:53 +00:00
|
|
|
|
2008-08-08 03:37:00 +00:00
|
|
|
DrawFrameRect(x, y + 1, x + 9, y + 9, button_colour, (state == 1) ? FR_LOWERED : FR_NONE);
|
|
|
|
DrawFrameRect(x + 10, y + 1, x + 19, y + 9, button_colour, (state == 2) ? FR_LOWERED : FR_NONE);
|
2009-03-21 22:00:00 +00:00
|
|
|
DrawString(x, x + 9, y + 1, STR_6819, TC_FROMSTRING, SA_CENTER); // [<]
|
|
|
|
DrawString(x + 10, x + 19, y + 1, STR_681A, TC_FROMSTRING, SA_CENTER); // [>]
|
2006-08-02 18:36:53 +00:00
|
|
|
|
|
|
|
/* Grey out the buttons that aren't clickable */
|
2008-08-08 06:02:06 +00:00
|
|
|
if (!clickable_left) {
|
2008-08-08 03:37:00 +00:00
|
|
|
GfxFillRect(x + 1, y + 1, x + 1 + 8, y + 8, colour, FILLRECT_CHECKER);
|
2008-08-08 06:02:06 +00:00
|
|
|
}
|
|
|
|
if (!clickable_right) {
|
|
|
|
GfxFillRect(x + 11, y + 1, x + 11 + 8, y + 8, colour, FILLRECT_CHECKER);
|
|
|
|
}
|
2004-12-22 13:19:26 +00:00
|
|
|
}
|
|
|
|
|
2008-01-04 02:32:58 +00:00
|
|
|
/** These are not, strickly speaking, widget enums,
|
|
|
|
* since they have been changed as line coordinates.
|
|
|
|
* So, rather, they are more like order of appearance */
|
|
|
|
enum CustomCurrenciesWidgets {
|
|
|
|
CUSTCURR_EXCHANGERATE = 0,
|
|
|
|
CUSTCURR_SEPARATOR,
|
|
|
|
CUSTCURR_PREFIX,
|
|
|
|
CUSTCURR_SUFFIX,
|
|
|
|
CUSTCURR_TO_EURO,
|
|
|
|
};
|
|
|
|
|
2008-05-15 21:48:47 +00:00
|
|
|
struct CustomCurrencyWindow : Window {
|
|
|
|
char separator[2];
|
|
|
|
int click;
|
|
|
|
int query_widget;
|
2004-12-22 13:19:26 +00:00
|
|
|
|
2008-05-15 21:48:47 +00:00
|
|
|
CustomCurrencyWindow(const WindowDesc *desc) : Window(desc)
|
|
|
|
{
|
|
|
|
this->separator[0] = _custom_currency.separator;
|
|
|
|
this->separator[1] = '\0';
|
|
|
|
this->FindWindowPlacementAndResize(desc);
|
|
|
|
}
|
2006-08-31 14:12:08 +00:00
|
|
|
|
2008-05-15 21:48:47 +00:00
|
|
|
virtual void OnPaint()
|
|
|
|
{
|
2009-03-21 22:46:17 +00:00
|
|
|
int const right = this->width - 1;
|
2008-05-15 21:48:47 +00:00
|
|
|
int y = 20;
|
2008-05-17 12:48:06 +00:00
|
|
|
this->DrawWidgets();
|
2004-12-27 18:18:44 +00:00
|
|
|
|
2008-05-15 21:48:47 +00:00
|
|
|
/* exchange rate */
|
2008-08-08 03:37:00 +00:00
|
|
|
DrawArrowButtons(10, y, COLOUR_YELLOW, GB(this->click, 0, 2), true, true);
|
2008-05-15 21:48:47 +00:00
|
|
|
SetDParam(0, 1);
|
|
|
|
SetDParam(1, 1);
|
2009-03-21 22:46:17 +00:00
|
|
|
DrawString(35, right, y + 1, STR_CURRENCY_EXCHANGE_RATE, TC_FROMSTRING);
|
2008-05-15 21:48:47 +00:00
|
|
|
y += 12;
|
|
|
|
|
|
|
|
/* separator */
|
2008-08-01 03:43:53 +00:00
|
|
|
DrawFrameRect(10, y + 1, 29, y + 9, COLOUR_DARK_BLUE, GB(this->click, 2, 2) ? FR_LOWERED : FR_NONE);
|
2009-03-24 20:03:02 +00:00
|
|
|
SetDParamStr(0, this->separator);
|
|
|
|
DrawString(35, right, y + 1, STR_CURRENCY_SEPARATOR, TC_FROMSTRING);
|
2008-05-15 21:48:47 +00:00
|
|
|
y += 12;
|
|
|
|
|
|
|
|
/* prefix */
|
2008-08-01 03:43:53 +00:00
|
|
|
DrawFrameRect(10, y + 1, 29, y + 9, COLOUR_DARK_BLUE, GB(this->click, 4, 2) ? FR_LOWERED : FR_NONE);
|
2009-03-24 20:03:02 +00:00
|
|
|
SetDParamStr(0, _custom_currency.prefix);
|
|
|
|
DrawString(35, right, y + 1, STR_CURRENCY_PREFIX, TC_FROMSTRING);
|
2008-05-15 21:48:47 +00:00
|
|
|
y += 12;
|
|
|
|
|
|
|
|
/* suffix */
|
2008-08-01 03:43:53 +00:00
|
|
|
DrawFrameRect(10, y + 1, 29, y + 9, COLOUR_DARK_BLUE, GB(this->click, 6, 2) ? FR_LOWERED : FR_NONE);
|
2009-03-24 20:03:02 +00:00
|
|
|
SetDParamStr(0, _custom_currency.suffix);
|
|
|
|
DrawString(35, right, y + 1, STR_CURRENCY_SUFFIX, TC_FROMSTRING);
|
2008-05-15 21:48:47 +00:00
|
|
|
y += 12;
|
|
|
|
|
|
|
|
/* switch to euro */
|
2008-08-08 03:37:00 +00:00
|
|
|
DrawArrowButtons(10, y, COLOUR_YELLOW, GB(this->click, 8, 2), true, true);
|
2008-05-15 21:48:47 +00:00
|
|
|
SetDParam(0, _custom_currency.to_euro);
|
2009-03-21 22:46:17 +00:00
|
|
|
DrawString(35, right, y + 1, (_custom_currency.to_euro != CF_NOEURO) ? STR_CURRENCY_SWITCH_TO_EURO : STR_CURRENCY_SWITCH_TO_EURO_NEVER, TC_FROMSTRING);
|
2008-05-15 21:48:47 +00:00
|
|
|
y += 12;
|
|
|
|
|
|
|
|
/* Preview */
|
|
|
|
y += 12;
|
|
|
|
SetDParam(0, 10000);
|
2009-03-21 22:46:17 +00:00
|
|
|
DrawString(35, right, y + 1, STR_CURRENCY_PREVIEW, TC_FROMSTRING);
|
2008-05-15 21:48:47 +00:00
|
|
|
}
|
2005-11-14 19:48:04 +00:00
|
|
|
|
2008-05-15 21:48:47 +00:00
|
|
|
virtual void OnClick(Point pt, int widget)
|
|
|
|
{
|
|
|
|
int line = (pt.y - 20) / 12;
|
|
|
|
int len = 0;
|
|
|
|
int x = pt.x;
|
|
|
|
StringID str = 0;
|
|
|
|
CharSetFilter afilter = CS_ALPHANUMERAL;
|
|
|
|
|
|
|
|
switch (line) {
|
|
|
|
case CUSTCURR_EXCHANGERATE:
|
|
|
|
if (IsInsideMM(x, 10, 30)) { // clicked buttons
|
|
|
|
if (x < 20) {
|
|
|
|
if (_custom_currency.rate > 1) _custom_currency.rate--;
|
|
|
|
this->click = 1 << (line * 2 + 0);
|
|
|
|
} else {
|
2008-12-29 15:46:14 +00:00
|
|
|
if (_custom_currency.rate < UINT16_MAX) _custom_currency.rate++;
|
2008-05-15 21:48:47 +00:00
|
|
|
this->click = 1 << (line * 2 + 1);
|
2006-08-31 14:12:08 +00:00
|
|
|
}
|
2008-05-15 21:48:47 +00:00
|
|
|
} else { // enter text
|
|
|
|
SetDParam(0, _custom_currency.rate);
|
2009-02-08 12:25:13 +00:00
|
|
|
str = STR_CONFIG_SETTING_INT32;
|
2008-12-29 15:46:14 +00:00
|
|
|
len = 5;
|
2008-05-15 21:48:47 +00:00
|
|
|
afilter = CS_NUMERAL;
|
|
|
|
}
|
|
|
|
break;
|
2005-11-14 19:48:04 +00:00
|
|
|
|
2008-05-15 21:48:47 +00:00
|
|
|
case CUSTCURR_SEPARATOR:
|
|
|
|
if (IsInsideMM(x, 10, 30)) { // clicked button
|
|
|
|
this->click = 1 << (line * 2 + 1);
|
|
|
|
}
|
2008-07-17 13:47:04 +00:00
|
|
|
SetDParamStr(0, this->separator);
|
|
|
|
str = STR_JUST_RAW_STRING;
|
2008-05-15 21:48:47 +00:00
|
|
|
len = 1;
|
|
|
|
break;
|
2005-11-14 19:48:04 +00:00
|
|
|
|
2008-05-15 21:48:47 +00:00
|
|
|
case CUSTCURR_PREFIX:
|
|
|
|
if (IsInsideMM(x, 10, 30)) { // clicked button
|
|
|
|
this->click = 1 << (line * 2 + 1);
|
|
|
|
}
|
2008-07-17 13:47:04 +00:00
|
|
|
SetDParamStr(0, _custom_currency.prefix);
|
|
|
|
str = STR_JUST_RAW_STRING;
|
2008-05-15 21:48:47 +00:00
|
|
|
len = 12;
|
|
|
|
break;
|
2005-11-14 19:48:04 +00:00
|
|
|
|
2008-05-15 21:48:47 +00:00
|
|
|
case CUSTCURR_SUFFIX:
|
|
|
|
if (IsInsideMM(x, 10, 30)) { // clicked button
|
|
|
|
this->click = 1 << (line * 2 + 1);
|
|
|
|
}
|
2008-07-17 13:47:04 +00:00
|
|
|
SetDParamStr(0, _custom_currency.suffix);
|
|
|
|
str = STR_JUST_RAW_STRING;
|
2008-05-15 21:48:47 +00:00
|
|
|
len = 12;
|
|
|
|
break;
|
2004-12-27 18:18:44 +00:00
|
|
|
|
2008-05-15 21:48:47 +00:00
|
|
|
case CUSTCURR_TO_EURO:
|
|
|
|
if (IsInsideMM(x, 10, 30)) { // clicked buttons
|
|
|
|
if (x < 20) {
|
2008-12-29 15:46:14 +00:00
|
|
|
_custom_currency.to_euro = (_custom_currency.to_euro <= 2000) ? CF_NOEURO : _custom_currency.to_euro - 1;
|
2008-05-15 21:48:47 +00:00
|
|
|
this->click = 1 << (line * 2 + 0);
|
|
|
|
} else {
|
2008-12-29 15:46:14 +00:00
|
|
|
_custom_currency.to_euro = Clamp(_custom_currency.to_euro + 1, 2000, MAX_YEAR);
|
2008-05-15 21:48:47 +00:00
|
|
|
this->click = 1 << (line * 2 + 1);
|
|
|
|
}
|
|
|
|
} else { // enter text
|
|
|
|
SetDParam(0, _custom_currency.to_euro);
|
2009-02-08 12:25:13 +00:00
|
|
|
str = STR_CONFIG_SETTING_INT32;
|
2008-12-29 15:46:14 +00:00
|
|
|
len = 7;
|
2008-05-15 21:48:47 +00:00
|
|
|
afilter = CS_NUMERAL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2004-12-27 18:18:44 +00:00
|
|
|
|
2008-05-15 21:48:47 +00:00
|
|
|
if (len != 0) {
|
|
|
|
this->query_widget = line;
|
2008-09-15 16:29:40 +00:00
|
|
|
ShowQueryString(str, STR_CURRENCY_CHANGE_PARAMETER, len + 1, 250, this, afilter, QSF_NONE);
|
2008-05-15 21:48:47 +00:00
|
|
|
}
|
2004-12-22 13:19:26 +00:00
|
|
|
|
2008-09-23 15:24:15 +00:00
|
|
|
this->flags4 |= WF_TIMEOUT_BEGIN;
|
2008-05-15 21:48:47 +00:00
|
|
|
this->SetDirty();
|
|
|
|
}
|
2008-05-10 08:58:52 +00:00
|
|
|
|
2008-05-15 21:48:47 +00:00
|
|
|
virtual void OnQueryTextFinished(char *str)
|
|
|
|
{
|
|
|
|
if (str == NULL) return;
|
2004-12-22 13:19:26 +00:00
|
|
|
|
2008-05-15 21:48:47 +00:00
|
|
|
switch (this->query_widget) {
|
|
|
|
case CUSTCURR_EXCHANGERATE:
|
2008-12-29 15:46:14 +00:00
|
|
|
_custom_currency.rate = Clamp(atoi(str), 1, UINT16_MAX);
|
2008-05-15 21:48:47 +00:00
|
|
|
break;
|
2006-08-31 14:12:08 +00:00
|
|
|
|
2009-03-15 00:32:18 +00:00
|
|
|
case CUSTCURR_SEPARATOR: // Thousands seperator
|
2008-05-15 21:48:47 +00:00
|
|
|
_custom_currency.separator = StrEmpty(str) ? ' ' : str[0];
|
2008-11-02 11:20:15 +00:00
|
|
|
strecpy(this->separator, str, lastof(this->separator));
|
2008-05-15 21:48:47 +00:00
|
|
|
break;
|
2006-08-31 14:12:08 +00:00
|
|
|
|
2008-05-15 21:48:47 +00:00
|
|
|
case CUSTCURR_PREFIX:
|
2008-11-02 11:20:15 +00:00
|
|
|
strecpy(_custom_currency.prefix, str, lastof(_custom_currency.prefix));
|
2008-05-15 21:48:47 +00:00
|
|
|
break;
|
2006-08-31 14:12:08 +00:00
|
|
|
|
2008-05-15 21:48:47 +00:00
|
|
|
case CUSTCURR_SUFFIX:
|
2008-11-02 11:20:15 +00:00
|
|
|
strecpy(_custom_currency.suffix, str, lastof(_custom_currency.suffix));
|
2008-05-15 21:48:47 +00:00
|
|
|
break;
|
2006-08-31 14:12:08 +00:00
|
|
|
|
2009-03-15 00:32:18 +00:00
|
|
|
case CUSTCURR_TO_EURO: { // Year to switch to euro
|
2008-05-15 21:48:47 +00:00
|
|
|
int val = atoi(str);
|
2006-08-31 14:12:08 +00:00
|
|
|
|
2008-05-15 21:48:47 +00:00
|
|
|
_custom_currency.to_euro = (val < 2000 ? CF_NOEURO : min(val, MAX_YEAR));
|
|
|
|
break;
|
2008-01-04 02:32:58 +00:00
|
|
|
}
|
2008-05-15 21:48:47 +00:00
|
|
|
}
|
|
|
|
MarkWholeScreenDirty();
|
|
|
|
}
|
2006-08-31 14:12:08 +00:00
|
|
|
|
2008-05-15 21:48:47 +00:00
|
|
|
virtual void OnTimeout()
|
|
|
|
{
|
|
|
|
this->click = 0;
|
|
|
|
this->SetDirty();
|
2004-12-22 13:19:26 +00:00
|
|
|
}
|
2008-05-15 21:48:47 +00:00
|
|
|
};
|
2004-12-22 13:19:26 +00:00
|
|
|
|
|
|
|
static const Widget _cust_currency_widgets[] = {
|
2008-07-31 17:45:52 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, COLOUR_GREY, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
|
|
{ WWT_CAPTION, RESIZE_NONE, COLOUR_GREY, 11, 229, 0, 13, STR_CURRENCY_WINDOW, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, COLOUR_GREY, 0, 229, 14, 119, 0x0, STR_NULL},
|
2004-12-22 13:19:26 +00:00
|
|
|
{ WIDGETS_END},
|
|
|
|
};
|
|
|
|
|
2009-03-15 15:12:06 +00:00
|
|
|
static const WindowDesc _cust_currency_desc(
|
2007-07-27 12:49:04 +00:00
|
|
|
WDP_CENTER, WDP_CENTER, 230, 120, 230, 120,
|
2007-02-01 15:49:12 +00:00
|
|
|
WC_CUSTOM_CURRENCY, WC_NONE,
|
2004-12-22 13:19:26 +00:00
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
|
2009-03-15 15:12:06 +00:00
|
|
|
_cust_currency_widgets
|
|
|
|
);
|
2004-12-22 13:19:26 +00:00
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
static void ShowCustCurrency()
|
2004-12-22 13:19:26 +00:00
|
|
|
{
|
|
|
|
DeleteWindowById(WC_CUSTOM_CURRENCY, 0);
|
2008-05-15 21:48:47 +00:00
|
|
|
new CustomCurrencyWindow(&_cust_currency_desc);
|
2004-12-22 13:19:26 +00:00
|
|
|
}
|