tron@2186: /* $Id$ */ tron@2186: truelight@0: #include "stdafx.h" Darkvater@1891: #include "openttd.h" tron@2291: #include "currency.h" tron@2163: #include "functions.h" tron@1317: #include "string.h" tron@1309: #include "strings.h" // XXX GetCurrentCurrencyRate() tron@1363: #include "table/sprites.h" tron@507: #include "table/strings.h" truelight@0: #include "window.h" truelight@0: #include "gui.h" truelight@0: #include "gfx.h" truelight@0: #include "command.h" truelight@0: #include "engine.h" tron@430: #include "screenshot.h" dominik@478: #include "newgrf.h" truelight@543: #include "network.h" truelight@835: #include "town.h" tron@2159: #include "variables.h" Darkvater@3118: #include "settings.h" celestar@3577: #include "vehicle.h" rubidium@4261: #include "date.h" truelight@0: truelight@0: static uint32 _difficulty_click_a; truelight@0: static uint32 _difficulty_click_b; truelight@0: static byte _difficulty_timeout; truelight@0: peter1138@3342: static const StringID _units_dropdown[] = { peter1138@3342: STR_UNITS_IMPERIAL, peter1138@3342: STR_UNITS_METRIC, peter1138@3342: STR_UNITS_SI, truelight@0: INVALID_STRING_ID truelight@0: }; truelight@0: truelight@0: static const StringID _driveside_dropdown[] = { truelight@0: STR_02E9_DRIVE_ON_LEFT, truelight@0: STR_02EA_DRIVE_ON_RIGHT, truelight@0: INVALID_STRING_ID truelight@0: }; truelight@0: truelight@0: static const StringID _autosave_dropdown[] = { truelight@0: STR_02F7_OFF, truelight@0: STR_AUTOSAVE_1_MONTH, truelight@0: STR_02F8_EVERY_3_MONTHS, truelight@0: STR_02F9_EVERY_6_MONTHS, truelight@0: STR_02FA_EVERY_12_MONTHS, truelight@0: INVALID_STRING_ID, truelight@0: }; truelight@0: truelight@0: static const StringID _designnames_dropdown[] = { truelight@0: STR_02BE_DEFAULT, truelight@0: STR_02BF_CUSTOM, truelight@0: INVALID_STRING_ID truelight@0: }; truelight@0: truelight@0: static StringID *BuildDynamicDropdown(StringID base, int num) truelight@0: { truelight@0: static StringID buf[32 + 1]; truelight@0: StringID *p = buf; truelight@0: while (--num>=0) *p++ = base++; truelight@0: *p = INVALID_STRING_ID; truelight@0: return buf; truelight@0: } truelight@0: tron@1093: static int GetCurRes(void) truelight@0: { truelight@0: int i; tron@2639: tron@2639: for (i = 0; i != _num_resolutions; i++) { darkvater@306: if (_resolutions[i][0] == _screen.width && tron@2639: _resolutions[i][1] == _screen.height) { truelight@0: break; tron@2639: } tron@2639: } truelight@0: return i; truelight@0: } truelight@0: darkvater@871: static inline bool RoadVehiclesAreBuilt(void) darkvater@871: { tron@2639: const Vehicle* v; tron@2639: tron@915: FOR_ALL_VEHICLES(v) { darkvater@871: if (v->type == VEH_Road) return true; darkvater@871: } darkvater@871: return false; darkvater@871: } darkvater@871: tron@2817: tron@2817: static void ShowCustCurrency(void); tron@2817: truelight@0: static void GameOptionsWndProc(Window *w, WindowEvent *e) truelight@0: { Darkvater@1500: switch (e->event) { truelight@0: case WE_PAINT: { darkvater@871: int i; truelight@0: StringID str = STR_02BE_DEFAULT; belugas@4709: belugas@4709: SetWindowWidgetDisabledState(w, 21, !(_vehicle_design_names & 1)); belugas@4709: if (!IsWindowWidgetDisabled(w, 21)) str = STR_02BF_CUSTOM; tron@534: SetDParam(0, str); belugas@4377: SetDParam(1, _currency_specs[_opt_ptr->currency].name); peter1138@3342: SetDParam(2, STR_UNITS_IMPERIAL + _opt_ptr->units); Darkvater@1500: SetDParam(3, STR_02E9_DRIVE_ON_LEFT + _opt_ptr->road_side); Darkvater@1500: SetDParam(4, STR_TOWNNAME_ORIGINAL_ENGLISH + _opt_ptr->town_name); Darkvater@1500: SetDParam(5, _autosave_dropdown[_opt_ptr->autosave]); tron@534: SetDParam(6, SPECSTR_LANGUAGE_START + _dynlang.curr); truelight@0: i = GetCurRes(); tron@534: SetDParam(7, i == _num_resolutions ? STR_RES_OTHER : SPECSTR_RESOLUTION_START + i); tron@534: SetDParam(8, SPECSTR_SCREENSHOT_START + _cur_screenshot_format); belugas@4727: SetWindowWidgetLoweredState(w, 28, _fullscreen); darkvater@298: truelight@0: DrawWindowWidgets(w); darkvater@298: DrawString(20, 175, STR_OPTIONS_FULLSCREEN, 0); // fullscreen truelight@0: } break; truelight@0: truelight@0: case WE_CLICK: belugas@4634: switch (e->we.click.widget) { Darkvater@1806: case 4: case 5: /* Setup currencies dropdown */ belugas@4377: ShowDropDownMenu(w, BuildCurrencyDropdown(), _opt_ptr->currency, 5, _game_mode == GM_MENU ? 0 : ~GetMaskOfAllowedCurrencies(), 0);; truelight@0: return; Darkvater@1806: case 7: case 8: /* Setup distance unit dropdown */ peter1138@3342: ShowDropDownMenu(w, _units_dropdown, _opt_ptr->units, 8, 0, 0); truelight@0: return; Darkvater@1806: case 10: case 11: { /* Setup road-side dropdown */ darkvater@871: int i = 0; darkvater@871: darkvater@871: /* You can only change the drive side if you are in the menu or ingame with darkvater@871: * no vehicles present. In a networking game only the server can change it */ darkvater@871: if ((_game_mode != GM_MENU && RoadVehiclesAreBuilt()) || (_networking && !_network_server)) Darkvater@1500: i = (-1) ^ (1 << _opt_ptr->road_side); // disable the other value darkvater@871: Darkvater@1806: ShowDropDownMenu(w, _driveside_dropdown, _opt_ptr->road_side, 11, i, 0); darkvater@871: } return; Darkvater@1806: case 13: case 14: { /* Setup townname dropdown */ Darkvater@1500: int i = _opt_ptr->town_name; Darkvater@1806: ShowDropDownMenu(w, BuildDynamicDropdown(STR_TOWNNAME_ORIGINAL_ENGLISH, SPECSTR_TOWNNAME_LAST - SPECSTR_TOWNNAME_START + 1), i, 14, (_game_mode == GM_MENU) ? 0 : (-1) ^ (1 << i), 0); truelight@0: return; truelight@0: } Darkvater@1806: case 16: case 17: /* Setup autosave dropdown */ Darkvater@1806: ShowDropDownMenu(w, _autosave_dropdown, _opt_ptr->autosave, 17, 0, 0); truelight@0: return; Darkvater@1806: case 19: case 20: /* Setup customized vehicle-names dropdown */ Darkvater@1806: ShowDropDownMenu(w, _designnames_dropdown, (_vehicle_design_names & 1) ? 1 : 0, 20, (_vehicle_design_names & 2) ? 0 : 2, 0); truelight@0: return; darkvater@871: case 21: /* Save customized vehicle-names to disk */ truelight@0: return; Darkvater@1806: case 23: case 24: /* Setup interface language dropdown */ Darkvater@1806: ShowDropDownMenu(w, _dynlang.dropdown, _dynlang.curr, 24, 0, 0); truelight@0: return; Darkvater@1806: case 26: case 27: /* Setup resolution dropdown */ Darkvater@1806: ShowDropDownMenu(w, BuildDynamicDropdown(SPECSTR_RESOLUTION_START, _num_resolutions), GetCurRes(), 27, 0, 0); truelight@0: return; darkvater@298: case 28: /* Click fullscreen on/off */ belugas@4727: SetWindowWidgetLoweredState(w, 28, !_fullscreen); darkvater@298: ToggleFullScreen(!_fullscreen); // toggle full-screen on/off darkvater@298: SetWindowDirty(w); darkvater@298: return; Darkvater@1806: case 30: case 31: /* Setup screenshot format dropdown */ Darkvater@1806: ShowDropDownMenu(w, BuildDynamicDropdown(SPECSTR_SCREENSHOT_START, _num_screenshot_formats), _cur_screenshot_format, 31, 0, 0); truelight@0: return; truelight@0: } truelight@0: break; truelight@0: truelight@193: case WE_DROPDOWN_SELECT: belugas@4634: switch (e->we.dropdown.button) { darkvater@871: case 20: /* Vehicle design names */ belugas@4634: if (e->we.dropdown.index == 0) { truelight@0: DeleteCustomEngineNames(); truelight@0: MarkWholeScreenDirty(); Darkvater@1500: } else if (!(_vehicle_design_names & 1)) { truelight@0: LoadCustomEngineNames(); truelight@0: MarkWholeScreenDirty(); truelight@0: } truelight@0: break; darkvater@871: case 5: /* Currency */ belugas@4634: if (e->we.dropdown.index == CUSTOM_CURRENCY_ID) ShowCustCurrency(); belugas@4634: _opt_ptr->currency = e->we.dropdown.index; truelight@0: MarkWholeScreenDirty(); truelight@0: break; peter1138@3342: case 8: /* Measuring units */ belugas@4634: _opt_ptr->units = e->we.dropdown.index; truelight@0: MarkWholeScreenDirty(); truelight@0: break; darkvater@871: case 11: /* Road side */ belugas@4634: if (_opt_ptr->road_side != e->we.dropdown.index) { // only change if setting changed belugas@4634: DoCommandP(0, e->we.dropdown.index, 0, NULL, CMD_SET_ROAD_DRIVE_SIDE | CMD_MSG(STR_00B4_CAN_T_DO_THIS)); dominik@1113: MarkWholeScreenDirty(); dominik@1113: } truelight@0: break; darkvater@871: case 14: /* Town names */ Darkvater@1794: if (_game_mode == GM_MENU) { belugas@4634: _opt_ptr->town_name = e->we.dropdown.index; Darkvater@1794: InvalidateWindow(WC_GAME_OPTIONS, 0); Darkvater@1794: } truelight@0: break; darkvater@871: case 17: /* Autosave options */ belugas@4634: _opt.autosave = _opt_newgame.autosave = e->we.dropdown.index; truelight@0: SetWindowDirty(w); truelight@0: break; darkvater@871: case 24: /* Change interface language */ belugas@4634: ReadLanguagePack(e->we.dropdown.index); truelight@0: MarkWholeScreenDirty(); truelight@0: break; darkvater@871: case 27: /* Change resolution */ belugas@4634: if (e->we.dropdown.index < _num_resolutions && ChangeResInGame(_resolutions[e->we.dropdown.index][0],_resolutions[e->we.dropdown.index][1])) truelight@0: SetWindowDirty(w); truelight@0: break; darkvater@871: case 31: /* Change screenshot format */ belugas@4634: SetScreenshotFormat(e->we.dropdown.index); truelight@0: SetWindowDirty(w); truelight@0: break; truelight@0: } truelight@0: break; dominik@759: dominik@759: case WE_DESTROY: dominik@759: DeleteWindowById(WC_CUSTOM_CURRENCY, 0); dominik@759: break; truelight@0: } dominik@759: truelight@0: } truelight@0: Darkvater@1794: /** Change the side of the road vehicles drive on (server only). tron@3491: * @param tile unused Darkvater@1794: * @param p1 the side of the road; 0 = left side and 1 = right side Darkvater@1794: * @param p2 unused Darkvater@1794: */ tron@3491: int32 CmdSetRoadDriveSide(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) truelight@0: { Darkvater@1803: /* Check boundaries and you can only change this if NO vehicles have been built yet, Darkvater@1803: * except in the intro-menu where of course it's always possible to do so. */ Darkvater@1803: if (p1 > 1 || (_game_mode != GM_MENU && RoadVehiclesAreBuilt())) return CMD_ERROR; Darkvater@1794: truelight@0: if (flags & DC_EXEC) { Darkvater@1500: _opt_ptr->road_side = p1; truelight@0: InvalidateWindow(WC_GAME_OPTIONS,0); truelight@0: } truelight@0: return 0; truelight@0: } truelight@0: truelight@0: static const Widget _game_options_widgets[] = { rubidium@4344: { WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, rubidium@4344: { WWT_CAPTION, RESIZE_NONE, 14, 11, 369, 0, 13, STR_00B1_GAME_OPTIONS, STR_018C_WINDOW_TITLE_DRAG_THIS}, rubidium@4344: { WWT_PANEL, RESIZE_NONE, 14, 0, 369, 14, 238, 0x0, STR_NULL}, rubidium@4344: { WWT_FRAME, RESIZE_NONE, 14, 10, 179, 20, 55, STR_02E0_CURRENCY_UNITS, STR_NULL}, Darkvater@4939: { WWT_INSET, RESIZE_NONE, 14, 20, 169, 34, 45, STR_02E1, STR_02E2_CURRENCY_UNITS_SELECTION}, rubidium@4344: { WWT_TEXTBTN, RESIZE_NONE, 14, 158, 168, 35, 44, STR_0225, STR_02E2_CURRENCY_UNITS_SELECTION}, rubidium@4344: { WWT_FRAME, RESIZE_NONE, 14, 190, 359, 20, 55, STR_MEASURING_UNITS, STR_NULL}, Darkvater@4939: { WWT_INSET, RESIZE_NONE, 14, 200, 349, 34, 45, STR_02E4, STR_MEASURING_UNITS_SELECTION}, rubidium@4344: { WWT_TEXTBTN, RESIZE_NONE, 14, 338, 348, 35, 44, STR_0225, STR_MEASURING_UNITS_SELECTION}, rubidium@4344: { WWT_FRAME, RESIZE_NONE, 14, 10, 179, 62, 97, STR_02E6_ROAD_VEHICLES, STR_NULL}, Darkvater@4939: { WWT_INSET, RESIZE_NONE, 14, 20, 169, 76, 87, STR_02E7, STR_02E8_SELECT_SIDE_OF_ROAD_FOR}, rubidium@4344: { WWT_TEXTBTN, RESIZE_NONE, 14, 158, 168, 77, 86, STR_0225, STR_02E8_SELECT_SIDE_OF_ROAD_FOR}, rubidium@4344: { WWT_FRAME, RESIZE_NONE, 14, 190, 359, 62, 97, STR_02EB_TOWN_NAMES, STR_NULL}, Darkvater@4939: { WWT_INSET, RESIZE_NONE, 14, 200, 349, 76, 87, STR_02EC, STR_02ED_SELECT_STYLE_OF_TOWN_NAMES}, rubidium@4344: { WWT_TEXTBTN, RESIZE_NONE, 14, 338, 348, 77, 86, STR_0225, STR_02ED_SELECT_STYLE_OF_TOWN_NAMES}, rubidium@4344: { WWT_FRAME, RESIZE_NONE, 14, 10, 179, 104, 139, STR_02F4_AUTOSAVE, STR_NULL}, Darkvater@4939: { WWT_INSET, RESIZE_NONE, 14, 20, 169, 118, 129, STR_02F5, STR_02F6_SELECT_INTERVAL_BETWEEN}, rubidium@4344: { WWT_TEXTBTN, RESIZE_NONE, 14, 158, 168, 119, 128, STR_0225, STR_02F6_SELECT_INTERVAL_BETWEEN}, truelight@0: rubidium@4344: { WWT_FRAME, RESIZE_NONE, 14, 10, 359, 194, 228, STR_02BC_VEHICLE_DESIGN_NAMES, STR_NULL}, Darkvater@4939: { WWT_INSET, RESIZE_NONE, 14, 20, 119, 207, 218, STR_02BD, STR_02C1_VEHICLE_DESIGN_NAMES_SELECTION}, rubidium@4344: { WWT_TEXTBTN, RESIZE_NONE, 14, 108, 118, 208, 217, STR_0225, STR_02C1_VEHICLE_DESIGN_NAMES_SELECTION}, rubidium@4344: { WWT_TEXTBTN, RESIZE_NONE, 14, 130, 349, 207, 218, STR_02C0_SAVE_CUSTOM_NAMES, STR_02C2_SAVE_CUSTOMIZED_VEHICLE}, truelight@0: rubidium@4344: { WWT_FRAME, RESIZE_NONE, 14, 190, 359, 104, 139, STR_OPTIONS_LANG, STR_NULL}, Darkvater@4939: { WWT_INSET, RESIZE_NONE, 14, 200, 349, 118, 129, STR_OPTIONS_LANG_CBO, STR_OPTIONS_LANG_TIP}, rubidium@4344: { WWT_TEXTBTN, RESIZE_NONE, 14, 338, 348, 119, 128, STR_0225, STR_OPTIONS_LANG_TIP}, darkvater@298: rubidium@4344: { WWT_FRAME, RESIZE_NONE, 14, 10, 179, 146, 190, STR_OPTIONS_RES, STR_NULL}, Darkvater@4939: { WWT_INSET, RESIZE_NONE, 14, 20, 169, 160, 171, STR_OPTIONS_RES_CBO, STR_OPTIONS_RES_TIP}, rubidium@4344: { WWT_TEXTBTN, RESIZE_NONE, 14, 158, 168, 161, 170, STR_0225, STR_OPTIONS_RES_TIP}, rubidium@4344: { WWT_TEXTBTN, RESIZE_NONE, 14, 149, 169, 176, 184, STR_EMPTY, STR_OPTIONS_FULLSCREEN_TIP}, truelight@0: rubidium@4344: { WWT_FRAME, RESIZE_NONE, 14, 190, 359, 146, 190, STR_OPTIONS_SCREENSHOT_FORMAT, STR_NULL}, Darkvater@4939: { WWT_INSET, RESIZE_NONE, 14, 200, 349, 160, 171, STR_OPTIONS_SCREENSHOT_FORMAT_CBO, STR_OPTIONS_SCREENSHOT_FORMAT_TIP}, rubidium@4344: { WWT_TEXTBTN, RESIZE_NONE, 14, 338, 348, 161, 170, STR_0225, STR_OPTIONS_SCREENSHOT_FORMAT_TIP}, truelight@0: darkvater@176: { WIDGETS_END}, truelight@0: }; truelight@0: truelight@0: static const WindowDesc _game_options_desc = { darkvater@298: WDP_CENTER, WDP_CENTER, 370, 239, truelight@0: WC_GAME_OPTIONS,0, ludde@2064: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, truelight@0: _game_options_widgets, truelight@0: GameOptionsWndProc truelight@0: }; truelight@0: truelight@0: tron@1093: void ShowGameOptions(void) truelight@0: { truelight@0: DeleteWindowById(WC_GAME_OPTIONS, 0); truelight@0: AllocateWindowDesc(&_game_options_desc); truelight@0: } truelight@0: truelight@0: typedef struct { truelight@0: int16 min; truelight@0: int16 max; truelight@0: int16 step; truelight@0: StringID str; truelight@0: } GameSettingData; truelight@0: truelight@0: static const GameSettingData _game_setting_info[] = { Darkvater@1500: { 0, 7, 1, STR_NULL}, Darkvater@1500: { 0, 3, 1, STR_6830_IMMEDIATE}, Darkvater@1500: { 0, 2, 1, STR_6816_LOW}, Darkvater@1500: { 0, 3, 1, STR_26816_NONE}, Darkvater@1500: {100, 500, 50, STR_NULL}, Darkvater@1500: { 2, 4, 1, STR_NULL}, Darkvater@1500: { 0, 2, 1, STR_6820_LOW}, Darkvater@1500: { 0, 4, 1, STR_681B_VERY_SLOW}, Darkvater@1500: { 0, 2, 1, STR_6820_LOW}, Darkvater@1500: { 0, 2, 1, STR_6823_NONE}, Darkvater@1500: { 0, 3, 1, STR_6826_X1_5}, Darkvater@1500: { 0, 2, 1, STR_6820_LOW}, Darkvater@1500: { 0, 3, 1, STR_682A_VERY_FLAT}, Darkvater@1500: { 0, 3, 1, STR_VERY_LOW}, Darkvater@1500: { 0, 1, 1, STR_682E_STEADY}, Darkvater@1500: { 0, 1, 1, STR_6834_AT_END_OF_LINE_AND_AT_STATIONS}, Darkvater@1500: { 0, 1, 1, STR_6836_OFF}, Darkvater@1500: { 0, 2, 1, STR_6839_PERMISSIVE}, truelight@0: }; truelight@0: tron@536: static inline bool GetBitAndShift(uint32 *b) truelight@0: { truelight@0: uint32 x = *b; truelight@0: *b >>= 1; Darkvater@1500: return HASBIT(x, 0); truelight@0: } truelight@0: celestar@1385: /* rubidium@4549: * A: competitors rubidium@4549: * B: start time in months / 3 rubidium@4549: * C: town count (2 = high, 0 = low) rubidium@4549: * D: industry count (3 = high, 0 = none) rubidium@4549: * E: inital loan / 1000 (in GBP) rubidium@4549: * F: interest rate rubidium@4549: * G: running costs (0 = low, 2 = high) rubidium@4549: * H: construction speed of competitors (0 = very slow, 4 = very fast) rubidium@4549: * I: intelligence (0-2) rubidium@4549: * J: breakdowns (0 = off, 2 = normal) rubidium@4549: * K: subsidy multiplier (0 = 1.5, 3 = 4.0) rubidium@4549: * L: construction cost (0-2) rubidium@4549: * M: terrain type (0 = very flat, 3 = mountainous) rubidium@4549: * N: amount of water (0 = very low, 3 = high) rubidium@4549: * O: economy (0 = steady, 1 = fluctuating) rubidium@4549: * P: Train reversing (0 = end of line + stations, 1 = end of line) rubidium@4549: * Q: disasters rubidium@4549: * R: area restructuring (0 = permissive, 2 = hostile) rubidium@4549: */ celestar@1385: static const int16 _default_game_diff[3][GAME_DIFFICULTY_NUM] = { /* celestar@1385: A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R*/ rubidium@4344: {2, 2, 1, 3, 300, 2, 0, 2, 0, 1, 2, 0, 1, 0, 0, 0, 0, 0}, //easy rubidium@4344: {4, 1, 1, 2, 150, 3, 1, 3, 1, 2, 1, 1, 2, 1, 1, 1, 1, 1}, //medium rubidium@4344: {7, 0, 2, 2, 100, 4, 1, 3, 2, 2, 0, 2, 3, 2, 1, 1, 1, 2}, //hard truelight@0: }; truelight@0: truelight@0: void SetDifficultyLevel(int mode, GameOptions *gm_opt) truelight@0: { truelight@0: int i; truelight@0: assert(mode <= 3); truelight@0: truelight@0: gm_opt->diff_level = mode; truelight@0: if (mode != 3) { // not custom Darkvater@1500: for (i = 0; i != GAME_DIFFICULTY_NUM; i++) truelight@0: ((int*)&gm_opt->diff)[i] = _default_game_diff[mode][i]; truelight@0: } truelight@0: } truelight@0: tron@1093: extern void StartupEconomy(void); darkvater@46: darkvater@983: enum { darkvater@983: GAMEDIFF_WND_TOP_OFFSET = 45, darkvater@983: GAMEDIFF_WND_ROWSIZE = 9 darkvater@983: }; darkvater@983: Darkvater@1500: // Temporary holding place of values in the difficulty window until 'Save' is clicked Darkvater@1500: static GameOptions _opt_mod_temp; Darkvater@1500: // 0x383E = (1 << 13) | (1 << 12) | (1 << 11) | (1 << 5) | (1 << 4) | (1 << 3) | (1 << 2) | (1 << 1) Darkvater@1500: #define DIFF_INGAME_DISABLED_BUTTONS 0x383E Darkvater@1500: truelight@0: static void GameDifficultyWndProc(Window *w, WindowEvent *e) truelight@0: { Darkvater@1500: switch (e->event) { belugas@4709: case WE_CREATE: // Setup disabled buttons when creating window belugas@4709: /* disable all other difficulty buttons during gameplay except for 'custom' */ belugas@4709: SetWindowWidgetDisabledState(w, 3, _game_mode == GM_NORMAL); belugas@4709: SetWindowWidgetDisabledState(w, 4, _game_mode == GM_NORMAL); belugas@4709: SetWindowWidgetDisabledState(w, 5, _game_mode == GM_NORMAL); belugas@4709: SetWindowWidgetDisabledState(w, 6, _game_mode == GM_NORMAL); belugas@4709: SetWindowWidgetDisabledState(w, 7, _game_mode == GM_EDITOR || _networking); // highscore chart in multiplayer belugas@4709: SetWindowWidgetDisabledState(w, 10, _networking && !_network_server); // Save-button in multiplayer (and if client) Darkvater@1794: Darkvater@1794: break; truelight@0: case WE_PAINT: { truelight@0: uint32 click_a, click_b, disabled; truelight@0: int i; Darkvater@1500: int y, value; truelight@0: truelight@0: DrawWindowWidgets(w); truelight@0: truelight@0: click_a = _difficulty_click_a; truelight@0: click_b = _difficulty_click_b; truelight@0: Darkvater@1500: /* XXX - Disabled buttons in normal gameplay. Bitshifted for each button to see if Darkvater@1500: * that bit is set. If it is set, the button is disabled */ Darkvater@1500: disabled = (_game_mode == GM_NORMAL) ? DIFF_INGAME_DISABLED_BUTTONS : 0; truelight@0: darkvater@983: y = GAMEDIFF_WND_TOP_OFFSET; truelight@0: for (i = 0; i != GAME_DIFFICULTY_NUM; i++) { tron@4437: DrawFrameRect( 5, y, 5 + 8, y + 8, 3, GetBitAndShift(&click_a) ? FR_LOWERED : 0); tron@4437: DrawFrameRect(15, y, 15 + 8, y + 8, 3, GetBitAndShift(&click_b) ? FR_LOWERED : 0); truelight@543: if (GetBitAndShift(&disabled) || (_networking && !_network_server)) { tron@4444: int color = PALETTE_MODIFIER_GREYOUT | _colour_gradient[COLOUR_YELLOW][2]; Darkvater@1500: GfxFillRect( 6, y + 1, 6 + 8, y + 8, color); Darkvater@1500: GfxFillRect(16, y + 1, 16 + 8, y + 8, color); truelight@0: } truelight@0: Darkvater@1500: DrawStringCentered(10, y, STR_6819, 0); Darkvater@1500: DrawStringCentered(20, y, STR_681A, 0); truelight@0: truelight@0: truelight@0: value = _game_setting_info[i].str + ((int*)&_opt_mod_temp.diff)[i]; Darkvater@1500: if (i == 4) value *= 1000; // XXX - handle currency option tron@534: SetDParam(0, value); Darkvater@1500: DrawString(30, y, STR_6805_MAXIMUM_NO_COMPETITORS + i, 0); truelight@0: darkvater@983: y += GAMEDIFF_WND_ROWSIZE + 2; // space items apart a bit truelight@0: } truelight@0: } break; truelight@0: truelight@0: case WE_CLICK: belugas@4634: switch (e->we.click.widget) { Darkvater@1500: case 8: { /* Difficulty settings widget, decode click */ Darkvater@1500: const GameSettingData *info; Darkvater@1500: int x, y; truelight@0: uint btn, dis; truelight@0: int val; truelight@193: truelight@543: // Don't allow clients to make any changes truelight@543: if (_networking && !_network_server) truelight@543: return; truelight@543: belugas@4634: x = e->we.click.pt.x - 5; Darkvater@1500: if (!IS_INT_INSIDE(x, 0, 21)) // Button area truelight@0: return; truelight@0: belugas@4634: y = e->we.click.pt.y - GAMEDIFF_WND_TOP_OFFSET; truelight@0: if (y < 0) truelight@0: return; truelight@0: truelight@0: // Get button from Y coord. darkvater@983: btn = y / (GAMEDIFF_WND_ROWSIZE + 2); darkvater@983: if (btn >= GAME_DIFFICULTY_NUM || y % (GAMEDIFF_WND_ROWSIZE + 2) >= 9) truelight@0: return; truelight@0: truelight@0: // Clicked disabled button? Darkvater@1500: dis = (_game_mode == GM_NORMAL) ? DIFF_INGAME_DISABLED_BUTTONS : 0; darkvater@983: truelight@0: if (HASBIT(dis, btn)) truelight@0: return; truelight@0: truelight@0: _difficulty_timeout = 5; truelight@0: truelight@0: val = ((int*)&_opt_mod_temp.diff)[btn]; truelight@0: Darkvater@1500: info = &_game_setting_info[btn]; // get information about the difficulty setting truelight@0: if (x >= 10) { truelight@0: // Increase button clicked truelight@0: val = min(val + info->step, info->max); truelight@0: SETBIT(_difficulty_click_b, btn); truelight@0: } else { truelight@0: // Decrease button clicked truelight@0: val = max(val - info->step, info->min); truelight@0: SETBIT(_difficulty_click_a, btn); truelight@0: } truelight@0: truelight@0: // save value in temporary variable truelight@0: ((int*)&_opt_mod_temp.diff)[btn] = val; truelight@0: SetDifficultyLevel(3, &_opt_mod_temp); // set difficulty level to custom truelight@0: SetWindowDirty(w); Darkvater@1500: } break; darkvater@983: case 3: case 4: case 5: case 6: /* Easy / Medium / Hard / Custom */ truelight@0: // temporarily change difficulty level belugas@4719: RaiseWindowWidget(w, _opt_mod_temp.diff_level + 3); belugas@4634: SetDifficultyLevel(e->we.click.widget - 3, &_opt_mod_temp); belugas@4719: LowerWindowWidget(w, _opt_mod_temp.diff_level + 3); truelight@0: SetWindowDirty(w); truelight@0: break; darkvater@983: case 7: /* Highscore Table */ darkvater@983: ShowHighscoreTable(_opt_mod_temp.diff_level, -1); truelight@0: break; darkvater@983: case 10: { /* Save button - save changes */ truelight@0: int btn, val; truelight@0: for (btn = 0; btn != GAME_DIFFICULTY_NUM; btn++) { truelight@0: val = ((int*)&_opt_mod_temp.diff)[btn]; truelight@0: // if setting has changed, change it Darkvater@1501: if (val != ((int*)&_opt_ptr->diff)[btn]) truelight@0: DoCommandP(0, btn, val, NULL, CMD_CHANGE_DIFFICULTY_LEVEL); truelight@0: } truelight@0: DoCommandP(0, -1, _opt_mod_temp.diff_level, NULL, CMD_CHANGE_DIFFICULTY_LEVEL); truelight@0: DeleteWindow(w); dominik@42: // If we are in the editor, we should reload the economy. dominik@42: // This way when you load a game, the max loan and interest rate dominik@42: // are loaded correctly. dominik@42: if (_game_mode == GM_EDITOR) dominik@42: StartupEconomy(); truelight@0: break; truelight@0: } Darkvater@1500: case 11: /* Cancel button - close window, abandon changes */ truelight@0: DeleteWindow(w); truelight@0: break; Darkvater@1500: } break; truelight@0: Darkvater@1500: case WE_MOUSELOOP: /* Handle the visual 'clicking' of the buttons */ truelight@0: if (_difficulty_timeout != 0 && !--_difficulty_timeout) { truelight@0: _difficulty_click_a = 0; truelight@0: _difficulty_click_b = 0; truelight@0: SetWindowDirty(w); truelight@0: } truelight@0: break; truelight@0: } truelight@0: } truelight@0: Darkvater@1500: #undef DIFF_INGAME_DISABLED_BUTTONS Darkvater@1500: truelight@0: static const Widget _game_difficulty_widgets[] = { rubidium@4344: { WWT_CLOSEBOX, RESIZE_NONE, 10, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, rubidium@4344: { WWT_CAPTION, RESIZE_NONE, 10, 11, 369, 0, 13, STR_6800_DIFFICULTY_LEVEL, STR_018C_WINDOW_TITLE_DRAG_THIS}, rubidium@4344: { WWT_PANEL, RESIZE_NONE, 10, 0, 369, 14, 29, 0x0, STR_NULL}, rubidium@4344: { WWT_PUSHTXTBTN, RESIZE_NONE, 3, 10, 96, 16, 27, STR_6801_EASY, STR_NULL}, rubidium@4344: { WWT_PUSHTXTBTN, RESIZE_NONE, 3, 97, 183, 16, 27, STR_6802_MEDIUM, STR_NULL}, rubidium@4344: { WWT_PUSHTXTBTN, RESIZE_NONE, 3, 184, 270, 16, 27, STR_6803_HARD, STR_NULL}, rubidium@4344: { WWT_PUSHTXTBTN, RESIZE_NONE, 3, 271, 357, 16, 27, STR_6804_CUSTOM, STR_NULL}, rubidium@4344: { WWT_TEXTBTN, RESIZE_NONE, 10, 0, 369, 30, 41, STR_6838_SHOW_HI_SCORE_CHART, STR_NULL}, rubidium@4344: { WWT_PANEL, RESIZE_NONE, 10, 0, 369, 42, 262, 0x0, STR_NULL}, rubidium@4344: { WWT_PANEL, RESIZE_NONE, 10, 0, 369, 263, 278, 0x0, STR_NULL}, rubidium@4344: { WWT_PUSHTXTBTN, RESIZE_NONE, 3, 105, 185, 265, 276, STR_OPTIONS_SAVE_CHANGES, STR_NULL}, rubidium@4344: { WWT_PUSHTXTBTN, RESIZE_NONE, 3, 186, 266, 265, 276, STR_012E_CANCEL, STR_NULL}, darkvater@176: { WIDGETS_END}, truelight@0: }; truelight@0: truelight@0: static const WindowDesc _game_difficulty_desc = { truelight@0: WDP_CENTER, WDP_CENTER, 370, 279, truelight@0: WC_GAME_OPTIONS,0, truelight@0: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, truelight@0: _game_difficulty_widgets, truelight@0: GameDifficultyWndProc truelight@0: }; truelight@0: tron@1093: void ShowGameDifficulty(void) truelight@0: { truelight@0: DeleteWindowById(WC_GAME_OPTIONS, 0); Darkvater@1500: /* Copy current settings (ingame or in intro) to temporary holding place Darkvater@1500: * change that when setting stuff, copy back on clicking 'OK' */ tron@5024: _opt_mod_temp = *_opt_ptr; truelight@0: AllocateWindowDesc(&_game_difficulty_desc); truelight@193: } truelight@0: Darkvater@3247: static const char *_patches_ui[] = { Darkvater@3247: "vehicle_speed", Darkvater@3247: "status_long_date", Darkvater@3247: "show_finances", Darkvater@3247: "autoscroll", Darkvater@3247: "reverse_scroll", Darkvater@3247: "errmsg_duration", Darkvater@3247: "toolbar_pos", Darkvater@4834: "measure_tooltip", Darkvater@3247: "window_snap_radius", Darkvater@3247: "invisible_trees", Darkvater@3247: "population_in_label", Darkvater@3247: "link_terraform_toolbar", peter1138@4616: "liveries", Darkvater@5107: "prefer_teamchat", truelight@21: }; truelight@21: Darkvater@3247: static const char *_patches_construction[] = { Darkvater@3247: "build_on_slopes", Darkvater@3247: "extra_dynamite", Darkvater@3247: "longbridges", Darkvater@3247: "signal_side", Darkvater@3247: "always_small_airport", Darkvater@3247: "drag_signals_density", truelight@4300: "oil_refinery_limit", Darkvater@3247: }; Darkvater@3247: Darkvater@3247: static const char *_patches_stations[] = { Darkvater@3247: "join_stations", Darkvater@3247: "full_load_any", Darkvater@3247: "improved_load", Darkvater@3247: "selectgoods", Darkvater@3247: "new_nonstop", Darkvater@3247: "nonuniform_stations", Darkvater@3247: "station_spread", Darkvater@3247: "serviceathelipad", Darkvater@3247: "modified_catchment", peter1138@5211: "gradual_loading", Darkvater@3247: }; Darkvater@3247: Darkvater@3247: static const char *_patches_economy[] = { Darkvater@3247: "inflation", Darkvater@3247: "build_rawmaterial_ind", Darkvater@3247: "multiple_industry_per_town", Darkvater@3247: "same_industry_close", Darkvater@3247: "bribe", rubidium@4285: "colored_news_year", rubidium@4285: "ending_year", Darkvater@3247: "smooth_economy", Darkvater@3247: "allow_shares", Darkvater@3247: }; Darkvater@3247: Darkvater@3247: static const char *_patches_ai[] = { Darkvater@3247: "ainew_active", Darkvater@3247: "ai_in_multiplayer", Darkvater@3247: "ai_disable_veh_train", Darkvater@3247: "ai_disable_veh_roadveh", Darkvater@3247: "ai_disable_veh_aircraft", Darkvater@3247: "ai_disable_veh_ship", Darkvater@3247: }; Darkvater@3247: Darkvater@3247: static const char *_patches_vehicles[] = { Darkvater@3247: "realistic_acceleration", Darkvater@3247: "forbid_90_deg", Darkvater@3247: "mammoth_trains", Darkvater@3247: "gotodepot", Darkvater@3247: "roadveh_queue", Darkvater@3247: "new_pathfinding_all", KUDr@3900: "yapf.ship_use_yapf", KUDr@3900: "yapf.road_use_yapf", KUDr@3900: "yapf.rail_use_yapf", Darkvater@3247: "train_income_warn", Darkvater@3247: "order_review_system", Darkvater@3247: "never_expire_vehicles", KUDr@4870: "lost_train_warn", Darkvater@3247: "autorenew", Darkvater@3247: "autorenew_months", Darkvater@3247: "autorenew_money", Darkvater@3247: "max_trains", Darkvater@3247: "max_roadveh", Darkvater@3247: "max_aircraft", Darkvater@3247: "max_ships", Darkvater@3247: "servint_ispercent", Darkvater@3247: "servint_trains", Darkvater@3247: "servint_roadveh", Darkvater@3247: "servint_ships", Darkvater@3247: "servint_aircraft", Darkvater@3247: "no_servicing_if_no_breakdowns", Darkvater@3247: "wagon_speed_limits", KUDr@5116: "disable_elrails", peter1138@5163: "freight_trains", Darkvater@3247: }; Darkvater@3247: Darkvater@3247: typedef struct PatchEntry { Darkvater@3247: const SettingDesc *setting; Darkvater@3247: uint index; Darkvater@3247: } PatchEntry; Darkvater@3247: truelight@0: typedef struct PatchPage { Darkvater@3247: const char **names; Darkvater@3247: PatchEntry *entries; Darkvater@3118: byte num; truelight@0: } PatchPage; truelight@0: Darkvater@3247: /* PatchPage holds the categories, the number of elements in each category Darkvater@3247: * and (in NULL) a dynamic array of settings based on the string-representations Darkvater@3247: * of the settings. This way there is no worry about indeces, and such */ Darkvater@3247: static PatchPage _patches_page[] = { Darkvater@3247: {_patches_ui, NULL, lengthof(_patches_ui)}, Darkvater@3247: {_patches_construction, NULL, lengthof(_patches_construction)}, Darkvater@3247: {_patches_vehicles, NULL, lengthof(_patches_vehicles)}, Darkvater@3247: {_patches_stations, NULL, lengthof(_patches_stations)}, Darkvater@3247: {_patches_economy, NULL, lengthof(_patches_economy)}, Darkvater@3247: {_patches_ai, NULL, lengthof(_patches_ai)}, truelight@0: }; truelight@0: Darkvater@3118: /** The main patches window. Shows a number of categories on top and Darkvater@3118: * a selection of patches in that category. Darkvater@3118: * Uses WP(w, def_d) macro - data_1, data_2, data_3 */ truelight@0: static void PatchesSelectionWndProc(Window *w, WindowEvent *e) truelight@0: { Darkvater@3118: static Patches *patches_ptr; Darkvater@3118: Darkvater@1741: switch (e->event) { Darkvater@3206: case WE_CREATE: { Darkvater@3247: static bool first_time = true; Darkvater@3247: Darkvater@3121: patches_ptr = (_game_mode == GM_MENU) ? &_patches_newgame : &_patches; Darkvater@3247: Darkvater@3247: /* Build up the dynamic settings-array only once per OpenTTD session */ Darkvater@3247: if (first_time) { Darkvater@3247: PatchPage *page; Darkvater@3247: for (page = &_patches_page[0]; page != endof(_patches_page); page++) { Darkvater@3247: uint i; Darkvater@3247: Darkvater@3247: page->entries = malloc(page->num * sizeof(*page->entries)); Darkvater@3247: for (i = 0; i != page->num; i++) { Darkvater@3247: uint index; Darkvater@3247: const SettingDesc *sd = GetPatchFromName(page->names[i], &index); Darkvater@3247: assert(sd != NULL); Darkvater@3247: Darkvater@3247: page->entries[i].setting = sd; Darkvater@3247: page->entries[i].index = index; Darkvater@3247: } Darkvater@3247: } Darkvater@3247: first_time = false; Darkvater@3247: } belugas@4719: LowerWindowWidget(w, 4); Darkvater@3206: } break; Darkvater@3118: truelight@0: case WE_PAINT: { Darkvater@3118: int x, y; Darkvater@3118: const PatchPage *page = &_patches_page[WP(w,def_d).data_1]; tron@2639: uint i; truelight@0: Darkvater@3118: /* Set up selected category */ truelight@0: DrawWindowWidgets(w); truelight@0: Darkvater@3118: x = 5; Darkvater@3118: y = 47; Darkvater@3247: for (i = 0; i != page->num; i++) { Darkvater@3247: const SettingDesc *sd = page->entries[i].setting; Darkvater@3118: const SettingDescBase *sdb = &sd->desc; Darkvater@5141: const void *var = GetVariableAddress(patches_ptr, &sd->save); truelight@543: bool editable = true; Darkvater@3118: bool disabled = false; darkvater@998: truelight@543: // We do not allow changes of some items when we are a client in a networkgame Darkvater@3118: if (!(sd->save.conv & SLF_NETWORK_NO) && _networking && !_network_server) editable = false; Darkvater@3118: if ((sdb->flags & SGF_NETWORK_ONLY) && !_networking) editable = false; Darkvater@3118: Darkvater@3118: if (sdb->cmd == SDT_BOOLX) { Darkvater@3124: static const int _bool_ctabs[2][2] = {{9, 4}, {7, 6}}; Darkvater@3118: /* Draw checkbox for boolean-value either on/off */ Darkvater@3118: bool on = (*(bool*)var); Darkvater@3118: Darkvater@3124: DrawFrameRect(x, y, x + 19, y + 8, _bool_ctabs[!!on][!!editable], on ? FR_LOWERED : 0); Darkvater@3118: SetDParam(0, on ? STR_CONFIG_PATCHES_ON : STR_CONFIG_PATCHES_OFF); truelight@0: } else { Darkvater@3118: int32 value; truelight@0: miham@4211: value = (int32)ReadValue(var, sd->save.conv); miham@4211: Darkvater@3118: /* Draw [<][>] boxes for settings of an integer-type */ miham@4211: DrawArrowButtons(x, y, 3, WP(w,def_d).data_2 - (i * 2), (editable && value != sdb->min), (editable && value != sdb->max)); Darkvater@3118: Darkvater@3118: disabled = (value == 0) && (sdb->flags & SGF_0ISDISABLED); dominik@11: if (disabled) { tron@534: SetDParam(0, STR_CONFIG_PATCHES_DISABLED); truelight@0: } else { Darkvater@3118: if (sdb->flags & SGF_CURRENCY) { tron@534: SetDParam(0, STR_CONFIG_PATCHES_CURRENCY); Darkvater@3118: } else if (sdb->flags & SGF_MULTISTRING) { Darkvater@3118: SetDParam(0, sdb->str + value + 1); Darkvater@3118: } else { Darkvater@3118: SetDParam(0, (sdb->flags & SGF_NOCOMMA) ? STR_CONFIG_PATCHES_INT32 : STR_7024); truelight@53: } Darkvater@3118: SetDParam(1, value); truelight@0: } truelight@0: } Darkvater@3118: DrawString(30, y, (sdb->str) + disabled, 0); truelight@0: y += 11; truelight@0: } truelight@0: break; truelight@0: } truelight@0: truelight@0: case WE_CLICK: belugas@4634: switch (e->we.click.widget) { truelight@0: case 3: { Darkvater@3118: const PatchPage *page = &_patches_page[WP(w,def_d).data_1]; Darkvater@3118: const SettingDesc *sd; Darkvater@3118: void *var; Darkvater@3118: int32 value; Darkvater@3118: int x, y; Darkvater@3118: byte btn; truelight@0: belugas@4634: y = e->we.click.pt.y - 46 - 1; truelight@0: if (y < 0) return; truelight@193: belugas@4634: x = e->we.click.pt.x - 5; truelight@0: if (x < 0) return; truelight@0: Darkvater@3118: btn = y / 11; Darkvater@3118: if (y % 11 > 9) return; Darkvater@3118: if (btn >= page->num) return; truelight@0: Darkvater@3247: sd = page->entries[btn].setting; Darkvater@3118: Darkvater@3118: /* return if action is only active in network, or only settable by server */ Darkvater@3118: if ((sd->desc.flags & SGF_NETWORK_ONLY) && !_networking) return; Darkvater@3118: if (!(sd->save.conv & SLF_NETWORK_NO) && _networking && !_network_server) return; Darkvater@3118: Darkvater@5141: var = GetVariableAddress(patches_ptr, &sd->save); Darkvater@3118: value = (int32)ReadValue(var, sd->save.conv); Darkvater@3118: Darkvater@3118: /* clicked on the icon on the left side. Either scroller or bool on/off */ Darkvater@3118: if (x < 21) { Darkvater@3118: const SettingDescBase *sdb = &sd->desc; Darkvater@3118: int32 oldvalue = value; Darkvater@3118: Darkvater@3118: switch (sdb->cmd) { Darkvater@3118: case SDT_BOOLX: value ^= 1; break; Darkvater@3118: case SDT_NUMX: { Darkvater@3118: /* Add a dynamic step-size to the scroller. In a maximum of rubidium@4431: * 50-steps you should be able to get from min to max, rubidium@4431: * unless specified otherwise in the 'interval' variable rubidium@4431: * of the current patch. */ rubidium@4431: uint32 step = (sdb->interval == 0) ? ((sdb->max - sdb->min) / 50) : sdb->interval; Darkvater@3118: if (step == 0) step = 1; Darkvater@3118: truelight@0: // don't allow too fast scrolling truelight@0: if ((w->flags4 & WF_TIMEOUT_MASK) > 2 << WF_TIMEOUT_SHL) { truelight@0: _left_button_clicked = false; truelight@0: return; truelight@0: } truelight@0: Darkvater@3118: /* Increase or decrease the value and clamp it to extremes */ truelight@0: if (x >= 10) { Darkvater@3118: value += step; Darkvater@3118: if (value > sdb->max) value = sdb->max; truelight@0: } else { Darkvater@3118: value -= step; Darkvater@3118: if (value < sdb->min) value = (sdb->flags & SGF_0ISDISABLED) ? 0 : sdb->min; truelight@0: } truelight@193: Darkvater@3118: /* Set up scroller timeout */ Darkvater@3118: if (value != oldvalue) { Darkvater@3118: WP(w,def_d).data_2 = btn * 2 + 1 + ((x >= 10) ? 1 : 0); truelight@0: w->flags4 |= 5 << WF_TIMEOUT_SHL; truelight@0: _left_button_clicked = false; truelight@0: } Darkvater@3118: } break; Darkvater@3118: default: NOT_REACHED(); truelight@0: } Darkvater@3118: Darkvater@3118: if (value != oldvalue) { Darkvater@3247: SetPatchValue(page->entries[btn].index, patches_ptr, value); truelight@0: SetWindowDirty(w); truelight@0: } truelight@0: } else { Darkvater@3118: /* only open editbox for types that its sensible for */ Darkvater@3118: if (sd->desc.cmd != SDT_BOOLX && !(sd->desc.flags & SGF_MULTISTRING)) { Darkvater@3118: /* Show the correct currency-translated value */ Darkvater@3118: if (sd->desc.flags & SGF_CURRENCY) value *= _currency->rate; Darkvater@3118: truelight@0: WP(w,def_d).data_3 = btn; Darkvater@3118: SetDParam(0, value); truelight@4299: ShowQueryString(STR_CONFIG_PATCHES_INT32, STR_CONFIG_PATCHES_QUERY_CAPT, 10, 100, WC_GAME_OPTIONS, 0, CS_NUMERAL); truelight@0: } truelight@0: } truelight@193: truelight@0: break; truelight@0: } truelight@21: case 4: case 5: case 6: case 7: case 8: case 9: belugas@4719: RaiseWindowWidget(w, WP(w, def_d).data_1 + 4); belugas@4719: WP(w, def_d).data_1 = e->we.click.widget - 4; belugas@4719: LowerWindowWidget(w, WP(w, def_d).data_1 + 4); truelight@0: DeleteWindowById(WC_QUERY_STRING, 0); truelight@0: SetWindowDirty(w); truelight@0: break; truelight@0: } truelight@0: break; truelight@0: truelight@0: case WE_TIMEOUT: truelight@0: WP(w,def_d).data_2 = 0; truelight@0: SetWindowDirty(w); truelight@0: break; truelight@0: truelight@0: case WE_ON_EDIT_TEXT: { belugas@4634: if (e->we.edittext.str != NULL) { Darkvater@3247: const PatchEntry *pe = &_patches_page[WP(w,def_d).data_1].entries[WP(w,def_d).data_3]; Darkvater@3247: const SettingDesc *sd = pe->setting; belugas@4634: int32 value = atoi(e->we.edittext.str); Darkvater@3118: Darkvater@3118: /* Save the correct currency-translated value */ Darkvater@3118: if (sd->desc.flags & SGF_CURRENCY) value /= _currency->rate; Darkvater@3118: Darkvater@3247: SetPatchValue(pe->index, patches_ptr, value); truelight@0: SetWindowDirty(w); truelight@0: } truelight@0: break; truelight@0: } truelight@0: truelight@0: case WE_DESTROY: truelight@0: DeleteWindowById(WC_QUERY_STRING, 0); truelight@0: break; truelight@0: } truelight@0: } truelight@0: truelight@0: static const Widget _patches_selection_widgets[] = { rubidium@4344: { WWT_CLOSEBOX, RESIZE_NONE, 10, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, rubidium@4344: { WWT_CAPTION, RESIZE_NONE, 10, 11, 369, 0, 13, STR_CONFIG_PATCHES_CAPTION, STR_018C_WINDOW_TITLE_DRAG_THIS}, rubidium@4344: { WWT_PANEL, RESIZE_NONE, 10, 0, 369, 14, 41, 0x0, STR_NULL}, peter1138@5163: { WWT_PANEL, RESIZE_NONE, 10, 0, 369, 42, 370, 0x0, STR_NULL}, truelight@0: rubidium@4344: { WWT_TEXTBTN, RESIZE_NONE, 3, 10, 96, 16, 27, STR_CONFIG_PATCHES_GUI, STR_NULL}, rubidium@4344: { WWT_TEXTBTN, RESIZE_NONE, 3, 97, 183, 16, 27, STR_CONFIG_PATCHES_CONSTRUCTION, STR_NULL}, rubidium@4344: { WWT_TEXTBTN, RESIZE_NONE, 3, 184, 270, 16, 27, STR_CONFIG_PATCHES_VEHICLES, STR_NULL}, rubidium@4344: { WWT_TEXTBTN, RESIZE_NONE, 3, 271, 357, 16, 27, STR_CONFIG_PATCHES_STATIONS, STR_NULL}, rubidium@4344: { WWT_TEXTBTN, RESIZE_NONE, 3, 10, 96, 28, 39, STR_CONFIG_PATCHES_ECONOMY, STR_NULL}, rubidium@4344: { WWT_TEXTBTN, RESIZE_NONE, 3, 97, 183, 28, 39, STR_CONFIG_PATCHES_AI, STR_NULL}, darkvater@176: { WIDGETS_END}, truelight@0: }; truelight@0: truelight@0: static const WindowDesc _patches_selection_desc = { peter1138@5163: WDP_CENTER, WDP_CENTER, 370, 371, truelight@0: WC_GAME_OPTIONS,0, truelight@0: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, truelight@0: _patches_selection_widgets, truelight@0: PatchesSelectionWndProc, truelight@0: }; truelight@0: tron@1093: void ShowPatchesSelection(void) truelight@0: { truelight@0: DeleteWindowById(WC_GAME_OPTIONS, 0); truelight@0: AllocateWindowDesc(&_patches_selection_desc); truelight@0: } dominik@478: dominik@478: miham@4211: /** miham@4211: * Draw [<][>] boxes. miham@4211: * @param x the x position to draw miham@4211: * @param y the y position to draw miham@4211: * @param ctab the color of the buttons miham@4211: * @param state 0 = none clicked, 1 = first clicked, 2 = second clicked miham@4211: * @param clickable_left is the left button clickable? miham@4211: * @param clickable_right is the right button clickable? miham@4211: */ miham@4211: void DrawArrowButtons(int x, int y, int ctab, byte state, bool clickable_left, bool clickable_right) dominik@759: { tron@4444: int color = PALETTE_MODIFIER_GREYOUT | _colour_gradient[COLOUR_YELLOW][2]; Darkvater@3107: miham@4211: DrawFrameRect(x, y + 1, x + 9, y + 9, ctab, (state == 1) ? FR_LOWERED : 0); miham@4211: DrawFrameRect(x + 10, y + 1, x + 19, y + 9, ctab, (state == 2) ? FR_LOWERED : 0); miham@4211: DrawStringCentered(x + 5, y + 1, STR_6819, 0); // [<] miham@4211: DrawStringCentered(x + 15, y + 1, STR_681A, 0); // [>] miham@4211: miham@4211: /* Grey out the buttons that aren't clickable */ miham@4211: if (!clickable_left) miham@4211: GfxFillRect(x + 1, y + 1, x + 1 + 8, y + 8, color); miham@4211: if (!clickable_right) miham@4211: GfxFillRect(x + 11, y + 1, x + 11 + 8, y + 8, color); dominik@759: } dominik@759: tron@2307: static char _str_separator[2]; dominik@759: dominik@759: static void CustCurrencyWndProc(Window *w, WindowEvent *e) dominik@759: { dominik@759: switch (e->event) { tron@4488: case WE_PAINT: { tron@4488: int x; tron@4488: int y = 20; tron@4488: int clk = WP(w,def_d).data_1; tron@4488: DrawWindowWidgets(w); dominik@759: tron@4488: // exchange rate tron@4488: DrawArrowButtons(10, y, 3, GB(clk, 0, 2), true, true); tron@4488: SetDParam(0, 1); tron@4488: SetDParam(1, 1); tron@4488: DrawString(35, y + 1, STR_CURRENCY_EXCHANGE_RATE, 0); tron@4488: y += 12; dominik@759: tron@4488: // separator tron@4488: DrawFrameRect(10, y + 1, 29, y + 9, 0, GB(clk, 2, 2) ? FR_LOWERED : 0); tron@4488: x = DrawString(35, y + 1, STR_CURRENCY_SEPARATOR, 0); tron@4488: DoDrawString(_str_separator, x + 4, y + 1, 6); tron@4488: y += 12; tron@4488: tron@4488: // prefix tron@4488: DrawFrameRect(10, y + 1, 29, y + 9, 0, GB(clk, 4, 2) ? FR_LOWERED : 0); tron@4488: x = DrawString(35, y + 1, STR_CURRENCY_PREFIX, 0); tron@4488: DoDrawString(_custom_currency.prefix, x + 4, y + 1, 6); tron@4488: y += 12; tron@4488: tron@4488: // suffix tron@4488: DrawFrameRect(10, y + 1, 29, y + 9, 0, GB(clk, 6, 2) ? FR_LOWERED : 0); tron@4488: x = DrawString(35, y + 1, STR_CURRENCY_SUFFIX, 0); tron@4488: DoDrawString(_custom_currency.suffix, x + 4, y + 1, 6); tron@4488: y += 12; tron@4488: tron@4488: // switch to euro tron@4488: DrawArrowButtons(10, y, 3, GB(clk, 8, 2), true, true); tron@4488: SetDParam(0, _custom_currency.to_euro); tron@4488: DrawString(35, y + 1, (_custom_currency.to_euro != CF_NOEURO) ? STR_CURRENCY_SWITCH_TO_EURO : STR_CURRENCY_SWITCH_TO_EURO_NEVER, 0); tron@4488: y += 12; tron@4488: tron@4488: // Preview tron@4488: y += 12; tron@4488: SetDParam(0, 10000); tron@4488: DrawString(35, y + 1, STR_CURRENCY_PREVIEW, 0); dominik@759: break; dominik@759: } truelight@812: tron@4488: case WE_CLICK: { belugas@4634: int line = (e->we.click.pt.y - 20) / 12; tron@4488: int len = 0; belugas@4634: int x = e->we.click.pt.x; tron@4488: StringID str = 0; tron@4488: CharSetFilter afilter = CS_ALPHANUMERAL; truelight@812: tron@4488: switch (line) { tron@4488: case 0: // rate tron@4488: if (IS_INT_INSIDE(x, 10, 30)) { // clicked buttons tron@4488: if (x < 20) { tron@4488: if (_custom_currency.rate > 1) _custom_currency.rate--; tron@4488: WP(w,def_d).data_1 = 1 << (line * 2 + 0); tron@4488: } else { tron@4488: if (_custom_currency.rate < 5000) _custom_currency.rate++; tron@4488: WP(w,def_d).data_1 = 1 << (line * 2 + 1); tron@4488: } tron@4488: } else { // enter text tron@4488: SetDParam(0, _custom_currency.rate); tron@4488: str = STR_CONFIG_PATCHES_INT32; tron@4488: len = 4; tron@4488: afilter = CS_NUMERAL; tron@4488: } tron@2639: break; tron@2639: tron@4488: case 1: // separator tron@4488: if (IS_INT_INSIDE(x, 10, 30)) { // clicked button tron@4488: WP(w,def_d).data_1 = 1 << (line * 2 + 1); tron@4488: } tron@4488: str = BindCString(_str_separator); tron@4488: len = 1; tron@2639: break; tron@2639: tron@4488: case 2: // prefix tron@4488: if (IS_INT_INSIDE(x, 10, 30)) { // clicked button tron@4488: WP(w,def_d).data_1 = 1 << (line * 2 + 1); tron@4488: } tron@4488: str = BindCString(_custom_currency.prefix); tron@4488: len = 12; tron@4488: break; tron@4488: tron@4488: case 3: // suffix tron@4488: if (IS_INT_INSIDE(x, 10, 30)) { // clicked button tron@4488: WP(w,def_d).data_1 = 1 << (line * 2 + 1); tron@4488: } tron@4488: str = BindCString(_custom_currency.suffix); tron@4488: len = 12; tron@4488: break; tron@4488: tron@4488: case 4: // to euro tron@4488: if (IS_INT_INSIDE(x, 10, 30)) { // clicked buttons tron@4488: if (x < 20) { tron@4488: _custom_currency.to_euro = (_custom_currency.to_euro <= 2000) ? tron@4488: CF_NOEURO : _custom_currency.to_euro - 1; tron@4488: WP(w,def_d).data_1 = 1 << (line * 2 + 0); tron@4488: } else { tron@4488: _custom_currency.to_euro = tron@4488: clamp(_custom_currency.to_euro + 1, 2000, MAX_YEAR); tron@4488: WP(w,def_d).data_1 = 1 << (line * 2 + 1); tron@4488: } tron@4488: } else { // enter text tron@4488: SetDParam(0, _custom_currency.to_euro); tron@4488: str = STR_CONFIG_PATCHES_INT32; tron@4488: len = 4; tron@4488: afilter = CS_NUMERAL; tron@4488: } tron@2639: break; dominik@759: } dominik@759: tron@4488: if (len != 0) { tron@4488: WP(w,def_d).data_2 = line; tron@4488: ShowQueryString( tron@4488: str, tron@4488: STR_CURRENCY_CHANGE_PARAMETER, tron@4488: len + 1, // maximum number of characters OR tron@4488: 250, // characters up to this width pixels, whichever is satisfied first tron@4488: w->window_class, tron@4488: w->window_number, afilter); tron@4488: } dominik@759: tron@4488: w->flags4 |= 5 << WF_TIMEOUT_SHL; tron@4488: SetWindowDirty(w); tron@4488: break; tron@4488: } tron@4488: tron@4488: case WE_ON_EDIT_TEXT: { belugas@4634: const char *b = e->we.edittext.str; tron@4488: tron@4488: switch (WP(w,def_d).data_2) { tron@4488: case 0: /* Exchange rate */ tron@4488: _custom_currency.rate = clamp(atoi(b), 1, 5000); tron@4488: break; tron@4488: tron@4488: case 1: /* Thousands seperator */ tron@4488: _custom_currency.separator = (b[0] == '\0') ? ' ' : b[0]; tron@4488: ttd_strlcpy(_str_separator, b, lengthof(_str_separator)); tron@4488: break; tron@4488: tron@4488: case 2: /* Currency prefix */ tron@4488: ttd_strlcpy(_custom_currency.prefix, b, lengthof(_custom_currency.prefix)); tron@4488: break; tron@4488: tron@4488: case 3: /* Currency suffix */ tron@4488: ttd_strlcpy(_custom_currency.suffix, b, lengthof(_custom_currency.suffix)); tron@4488: break; tron@4488: tron@4488: case 4: { /* Year to switch to euro */ tron@4488: int val = atoi(b); tron@4488: tron@4488: _custom_currency.to_euro = tron@4488: (val < 2000 ? CF_NOEURO : min(val, MAX_YEAR)); tron@4488: break; tron@4488: } tron@4488: } tron@4488: MarkWholeScreenDirty(); tron@4488: break; tron@4488: } tron@4488: tron@4488: case WE_TIMEOUT: tron@4488: WP(w,def_d).data_1 = 0; tron@4488: SetWindowDirty(w); tron@4488: break; tron@4488: tron@4488: case WE_DESTROY: tron@4488: DeleteWindowById(WC_QUERY_STRING, 0); tron@4488: MarkWholeScreenDirty(); tron@4488: break; dominik@759: } dominik@759: } dominik@759: dominik@759: static const Widget _cust_currency_widgets[] = { rubidium@4344: { WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, rubidium@4344: { WWT_CAPTION, RESIZE_NONE, 14, 11, 229, 0, 13, STR_CURRENCY_WINDOW, STR_018C_WINDOW_TITLE_DRAG_THIS}, rubidium@4344: { WWT_PANEL, RESIZE_NONE, 14, 0, 229, 14, 119, 0x0, STR_NULL}, dominik@759: { WIDGETS_END}, dominik@759: }; dominik@759: dominik@759: static const WindowDesc _cust_currency_desc = { dominik@759: WDP_CENTER, WDP_CENTER, 230, 120, dominik@759: WC_CUSTOM_CURRENCY, 0, dominik@759: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, dominik@759: _cust_currency_widgets, dominik@759: CustCurrencyWndProc, dominik@759: }; dominik@759: tron@2817: static void ShowCustCurrency(void) dominik@759: { tron@2306: _str_separator[0] = _custom_currency.separator; Darkvater@1759: _str_separator[1] = '\0'; dominik@759: dominik@759: DeleteWindowById(WC_CUSTOM_CURRENCY, 0); tron@2639: AllocateWindowDesc(&_cust_currency_desc); dominik@759: }