(svn r13158) -Codechange: make a class of the GameOptionsWindow.

replace/41b28d7194a279bdc17475d4fbe2ea6ec885a466
rubidium 17 years ago
parent 3455844ea3
commit fc7e8100e1

@ -151,37 +151,25 @@ static void ShowTownnameDropdown(Window *w, int sel)
ShowDropDownList(w, list, sel, GAMEOPT_TOWNNAME_BTN); ShowDropDownList(w, list, sel, GAMEOPT_TOWNNAME_BTN);
} }
/** static void ShowCustCurrency();
* Update/redraw the languages dropdown
* @param w the window the dropdown belongs to
*/
static void ShowLangDropdown(Window *w)
{
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(); struct GameOptionsWindow : Window {
for (LangList::iterator it = langs.begin(); it != langs.end(); it++) { GameOptionsWindow(const WindowDesc *desc) : Window(desc)
list->push_back(new DropDownListStringItem((*it).first, (*it).second, false)); {
this->FindWindowPlacementAndResize(desc);
} }
ShowDropDownList(w, list, _dynlang.curr, GAMEOPT_LANG_BTN); ~GameOptionsWindow()
{
DeleteWindowById(WC_CUSTOM_CURRENCY, 0);
} }
static void ShowCustCurrency(); virtual void OnPaint()
static void GameOptionsWndProc(Window *w, WindowEvent *e)
{ {
switch (e->event) {
case WE_PAINT: {
int i;
StringID str = STR_02BE_DEFAULT; StringID str = STR_02BE_DEFAULT;
w->SetWidgetDisabledState(GAMEOPT_VEHICLENAME_SAVE, !(_vehicle_design_names & 1)); this->SetWidgetDisabledState(GAMEOPT_VEHICLENAME_SAVE, !(_vehicle_design_names & 1));
if (!w->IsWidgetDisabled(GAMEOPT_VEHICLENAME_SAVE)) str = STR_02BF_CUSTOM; if (!this->IsWidgetDisabled(GAMEOPT_VEHICLENAME_SAVE)) str = STR_02BF_CUSTOM;
SetDParam(0, str); SetDParam(0, str);
SetDParam(1, _currency_specs[_opt_ptr->currency].name); SetDParam(1, _currency_specs[_opt_ptr->currency].name);
SetDParam(2, STR_UNITS_IMPERIAL + _opt_ptr->units); SetDParam(2, STR_UNITS_IMPERIAL + _opt_ptr->units);
@ -189,78 +177,92 @@ static void GameOptionsWndProc(Window *w, WindowEvent *e)
SetDParam(4, TownName(_opt_ptr->town_name)); SetDParam(4, TownName(_opt_ptr->town_name));
SetDParam(5, _autosave_dropdown[_opt_ptr->autosave]); SetDParam(5, _autosave_dropdown[_opt_ptr->autosave]);
SetDParam(6, SPECSTR_LANGUAGE_START + _dynlang.curr); SetDParam(6, SPECSTR_LANGUAGE_START + _dynlang.curr);
i = GetCurRes(); int i = GetCurRes();
SetDParam(7, i == _num_resolutions ? STR_RES_OTHER : SPECSTR_RESOLUTION_START + i); SetDParam(7, i == _num_resolutions ? STR_RES_OTHER : SPECSTR_RESOLUTION_START + i);
SetDParam(8, SPECSTR_SCREENSHOT_START + _cur_screenshot_format); SetDParam(8, SPECSTR_SCREENSHOT_START + _cur_screenshot_format);
w->SetWidgetLoweredState(GAMEOPT_FULLSCREEN, _fullscreen); this->SetWidgetLoweredState(GAMEOPT_FULLSCREEN, _fullscreen);
w->DrawWidgets(); this->DrawWidgets();
DrawString(20, 175, STR_OPTIONS_FULLSCREEN, TC_FROMSTRING); // fullscreen DrawString(20, 175, STR_OPTIONS_FULLSCREEN, TC_FROMSTRING); // fullscreen
} break; }
case WE_CLICK: virtual void OnClick(Point pt, int widget)
switch (e->we.click.widget) { {
case GAMEOPT_CURRENCY_BTN: /* Setup currencies dropdown */ switch (widget) {
ShowDropDownMenu(w, BuildCurrencyDropdown(), _opt_ptr->currency, GAMEOPT_CURRENCY_BTN, _game_mode == GM_MENU ? 0 : ~GetMaskOfAllowedCurrencies(), 0); case GAMEOPT_CURRENCY_BTN: // Setup currencies dropdown
ShowDropDownMenu(this, BuildCurrencyDropdown(), _opt_ptr->currency, GAMEOPT_CURRENCY_BTN, _game_mode == GM_MENU ? 0 : ~GetMaskOfAllowedCurrencies(), 0);
break; break;
case GAMEOPT_DISTANCE_BTN: /* Setup distance unit dropdown */ case GAMEOPT_DISTANCE_BTN: // Setup distance unit dropdown
ShowDropDownMenu(w, _units_dropdown, _opt_ptr->units, GAMEOPT_DISTANCE_BTN, 0, 0); ShowDropDownMenu(this, _units_dropdown, _opt_ptr->units, GAMEOPT_DISTANCE_BTN, 0, 0);
break; break;
case GAMEOPT_ROADSIDE_BTN: { /* Setup road-side dropdown */ case GAMEOPT_ROADSIDE_BTN: { // Setup road-side dropdown
int i = 0; int i = 0;
/* You can only change the drive side if you are in the menu or ingame with /* 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 */ * no vehicles present. In a networking game only the server can change it */
if ((_game_mode != GM_MENU && RoadVehiclesAreBuilt()) || (_networking && !_network_server)) if ((_game_mode != GM_MENU && RoadVehiclesAreBuilt()) || (_networking && !_network_server)) {
i = (-1) ^ (1 << _opt_ptr->road_side); // disable the other value i = (-1) ^ (1 << _opt_ptr->road_side); // disable the other value
}
ShowDropDownMenu(w, _driveside_dropdown, _opt_ptr->road_side, GAMEOPT_ROADSIDE_BTN, i, 0); ShowDropDownMenu(this, _driveside_dropdown, _opt_ptr->road_side, GAMEOPT_ROADSIDE_BTN, i, 0);
} break; } break;
case GAMEOPT_TOWNNAME_BTN: /* Setup townname dropdown */ case GAMEOPT_TOWNNAME_BTN: // Setup townname dropdown
ShowTownnameDropdown(w, _opt_ptr->town_name); ShowTownnameDropdown(this, _opt_ptr->town_name);
break; break;
case GAMEOPT_AUTOSAVE_BTN: /* Setup autosave dropdown */ case GAMEOPT_AUTOSAVE_BTN: // Setup autosave dropdown
ShowDropDownMenu(w, _autosave_dropdown, _opt_ptr->autosave, GAMEOPT_AUTOSAVE_BTN, 0, 0); ShowDropDownMenu(this, _autosave_dropdown, _opt_ptr->autosave, GAMEOPT_AUTOSAVE_BTN, 0, 0);
break; break;
case GAMEOPT_VEHICLENAME_BTN: /* Setup customized vehicle-names dropdown */ case GAMEOPT_VEHICLENAME_BTN: // Setup customized vehicle-names dropdown
ShowDropDownMenu(w, _designnames_dropdown, (_vehicle_design_names & 1) ? 1 : 0, GAMEOPT_VEHICLENAME_BTN, (_vehicle_design_names & 2) ? 0 : 2, 0); ShowDropDownMenu(this, _designnames_dropdown, (_vehicle_design_names & 1) ? 1 : 0, GAMEOPT_VEHICLENAME_BTN, (_vehicle_design_names & 2) ? 0 : 2, 0);
break; break;
case GAMEOPT_VEHICLENAME_SAVE: /* Save customized vehicle-names to disk */ case GAMEOPT_VEHICLENAME_SAVE: // Save customized vehicle-names to disk
break; // not implemented break; // not implemented
case GAMEOPT_LANG_BTN: /* Setup interface language dropdown */ case GAMEOPT_LANG_BTN: { // Setup interface language dropdown
ShowLangDropdown(w); typedef std::map<StringID, int, StringIDCompare> LangList;
break;
/* 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));
}
case GAMEOPT_RESOLUTION_BTN: /* Setup resolution dropdown */ ShowDropDownList(this, list, _dynlang.curr, GAMEOPT_LANG_BTN);
ShowDropDownMenu(w, BuildDynamicDropdown(SPECSTR_RESOLUTION_START, _num_resolutions), GetCurRes(), GAMEOPT_RESOLUTION_BTN, 0, 0); } break;
case GAMEOPT_RESOLUTION_BTN: // Setup resolution dropdown
ShowDropDownMenu(this, BuildDynamicDropdown(SPECSTR_RESOLUTION_START, _num_resolutions), GetCurRes(), GAMEOPT_RESOLUTION_BTN, 0, 0);
break; break;
case GAMEOPT_FULLSCREEN: /* Click fullscreen on/off */ case GAMEOPT_FULLSCREEN: // Click fullscreen on/off
/* try to toggle full-screen on/off */ /* try to toggle full-screen on/off */
if (!ToggleFullScreen(!_fullscreen)) { if (!ToggleFullScreen(!_fullscreen)) {
ShowErrorMessage(INVALID_STRING_ID, STR_FULLSCREEN_FAILED, 0, 0); ShowErrorMessage(INVALID_STRING_ID, STR_FULLSCREEN_FAILED, 0, 0);
} }
w->SetWidgetLoweredState(GAMEOPT_FULLSCREEN, _fullscreen); this->SetWidgetLoweredState(GAMEOPT_FULLSCREEN, _fullscreen);
w->SetDirty(); this->SetDirty();
break; break;
case GAMEOPT_SCREENSHOT_BTN: /* Setup screenshot format dropdown */ case GAMEOPT_SCREENSHOT_BTN: // Setup screenshot format dropdown
ShowDropDownMenu(w, BuildDynamicDropdown(SPECSTR_SCREENSHOT_START, _num_screenshot_formats), _cur_screenshot_format, GAMEOPT_SCREENSHOT_BTN, 0, 0); ShowDropDownMenu(this, BuildDynamicDropdown(SPECSTR_SCREENSHOT_START, _num_screenshot_formats), _cur_screenshot_format, GAMEOPT_SCREENSHOT_BTN, 0, 0);
break; break;
} }
break; }
case WE_DROPDOWN_SELECT: virtual void OnDropdownSelect(int widget, int index)
switch (e->we.dropdown.button) { {
case GAMEOPT_VEHICLENAME_BTN: /* Vehicle design names */ switch (widget) {
if (e->we.dropdown.index == 0) { case GAMEOPT_VEHICLENAME_BTN: // Vehicle design names
if (index == 0) {
DeleteCustomEngineNames(); DeleteCustomEngineNames();
MarkWholeScreenDirty(); MarkWholeScreenDirty();
} else if (!(_vehicle_design_names & 1)) { } else if (!(_vehicle_design_names & 1)) {
@ -270,61 +272,56 @@ static void GameOptionsWndProc(Window *w, WindowEvent *e)
break; break;
case GAMEOPT_CURRENCY_BTN: /* Currency */ case GAMEOPT_CURRENCY_BTN: /* Currency */
if (e->we.dropdown.index == CUSTOM_CURRENCY_ID) ShowCustCurrency(); if (index == CUSTOM_CURRENCY_ID) ShowCustCurrency();
_opt_ptr->currency = e->we.dropdown.index; _opt_ptr->currency = index;
MarkWholeScreenDirty(); MarkWholeScreenDirty();
break; break;
case GAMEOPT_DISTANCE_BTN: /* Measuring units */ case GAMEOPT_DISTANCE_BTN: // Measuring units
_opt_ptr->units = e->we.dropdown.index; _opt_ptr->units = index;
MarkWholeScreenDirty(); MarkWholeScreenDirty();
break; break;
case GAMEOPT_ROADSIDE_BTN: /* Road side */ case GAMEOPT_ROADSIDE_BTN: // Road side
if (_opt_ptr->road_side != e->we.dropdown.index) { // only change if setting changed if (_opt_ptr->road_side != index) { // only change if setting changed
DoCommandP(0, e->we.dropdown.index, 0, NULL, CMD_SET_ROAD_DRIVE_SIDE | CMD_MSG(STR_00B4_CAN_T_DO_THIS)); DoCommandP(0, index, 0, NULL, CMD_SET_ROAD_DRIVE_SIDE | CMD_MSG(STR_00B4_CAN_T_DO_THIS));
MarkWholeScreenDirty(); MarkWholeScreenDirty();
} }
break; break;
case GAMEOPT_TOWNNAME_BTN: /* Town names */ case GAMEOPT_TOWNNAME_BTN: // Town names
if (_game_mode == GM_MENU) { if (_game_mode == GM_MENU) {
_opt_ptr->town_name = e->we.dropdown.index; _opt_ptr->town_name = index;
InvalidateWindow(WC_GAME_OPTIONS, 0); InvalidateWindow(WC_GAME_OPTIONS, 0);
} }
break; break;
case GAMEOPT_AUTOSAVE_BTN: /* Autosave options */ case GAMEOPT_AUTOSAVE_BTN: // Autosave options
_opt.autosave = _opt_newgame.autosave = e->we.dropdown.index; _opt.autosave = _opt_newgame.autosave = index;
w->SetDirty(); this->SetDirty();
break; break;
case GAMEOPT_LANG_BTN: /* Change interface language */ case GAMEOPT_LANG_BTN: // Change interface language
ReadLanguagePack(e->we.dropdown.index); ReadLanguagePack(index);
CheckForMissingGlyphsInLoadedLanguagePack(); CheckForMissingGlyphsInLoadedLanguagePack();
UpdateAllStationVirtCoord(); UpdateAllStationVirtCoord();
UpdateAllWaypointSigns(); UpdateAllWaypointSigns();
MarkWholeScreenDirty(); MarkWholeScreenDirty();
break; break;
case GAMEOPT_RESOLUTION_BTN: /* Change resolution */ case GAMEOPT_RESOLUTION_BTN: // Change resolution
if (e->we.dropdown.index < _num_resolutions && ChangeResInGame(_resolutions[e->we.dropdown.index][0], _resolutions[e->we.dropdown.index][1])) if (index < _num_resolutions && ChangeResInGame(_resolutions[index][0], _resolutions[index][1])) {
w->SetDirty(); this->SetDirty();
break;
case GAMEOPT_SCREENSHOT_BTN: /* Change screenshot format */
SetScreenshotFormat(e->we.dropdown.index);
w->SetDirty();
break;
} }
break; break;
case WE_DESTROY: case GAMEOPT_SCREENSHOT_BTN: // Change screenshot format
DeleteWindowById(WC_CUSTOM_CURRENCY, 0); SetScreenshotFormat(index);
this->SetDirty();
break; break;
} }
} }
};
/** Change the side of the road vehicles drive on (server only). /** Change the side of the road vehicles drive on (server only).
* @param tile unused * @param tile unused
@ -382,14 +379,14 @@ static const WindowDesc _game_options_desc = {
WC_GAME_OPTIONS, WC_NONE, WC_GAME_OPTIONS, WC_NONE,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
_game_options_widgets, _game_options_widgets,
GameOptionsWndProc NULL
}; };
void ShowGameOptions() void ShowGameOptions()
{ {
DeleteWindowById(WC_GAME_OPTIONS, 0); DeleteWindowById(WC_GAME_OPTIONS, 0);
new Window(&_game_options_desc); new GameOptionsWindow(&_game_options_desc);
} }
struct GameSettingData { struct GameSettingData {

Loading…
Cancel
Save