truelight@0: #include "stdafx.h" truelight@0: #include "ttd.h" truelight@0: truelight@0: #include "window.h" truelight@0: #include "gui.h" truelight@0: #include "viewport.h" truelight@0: #include "gfx.h" truelight@0: #include "command.h" truelight@0: #include "engine.h" truelight@0: truelight@0: static uint32 _dropdown_disabled; truelight@0: static const StringID *_dropdown_items; truelight@0: static int _dropdown_selindex; truelight@0: static uint _dropdown_item_count; truelight@0: static byte _dropdown_button; truelight@0: static WindowClass _dropdown_windowclass; truelight@0: static WindowNumber _dropdown_windownum; truelight@0: static byte _dropdown_var1; truelight@0: static byte _dropdown_var2; truelight@0: truelight@0: static uint32 _difficulty_click_a; truelight@0: static uint32 _difficulty_click_b; truelight@0: static byte _difficulty_timeout; truelight@0: truelight@0: static Widget _dropdown_menu_widgets[] = { truelight@0: { WWT_IMGBTN, 0, 0, 0, 0, 0, 0x0}, truelight@0: { WWT_LAST}, truelight@0: }; truelight@0: truelight@0: static int GetDropdownItem(Window *w) truelight@0: { truelight@0: uint item; truelight@0: int y; truelight@0: truelight@0: if (GetWidgetFromPos(w, _cursor.pos.x - w->left, _cursor.pos.y - w->top) < 0) truelight@0: return -1; truelight@0: truelight@0: y = _cursor.pos.y - w->top - 2; truelight@0: truelight@0: if (y < 0) truelight@0: return - 1; truelight@0: truelight@0: item = y / 10; truelight@0: if (item >= _dropdown_item_count || HASBIT(_dropdown_disabled,item) || _dropdown_items[item] == 0) truelight@0: return - 1; truelight@0: truelight@0: return item; truelight@0: } truelight@0: truelight@0: void DropdownMenuWndProc(Window *w, WindowEvent *e) truelight@0: { truelight@0: int item; truelight@0: truelight@0: switch(e->event) { truelight@0: case WE_PAINT: { truelight@0: int x,y,i,sel; truelight@0: uint32 dis; truelight@0: truelight@0: DrawWindowWidgets(w); truelight@0: truelight@0: x = 1; truelight@0: y = 2; truelight@0: sel = _dropdown_selindex; truelight@0: dis = _dropdown_disabled; truelight@0: truelight@0: for(i=0; _dropdown_items[i] != INVALID_STRING_ID; i++) { truelight@0: if (_dropdown_items[i] != 0) { truelight@0: if (sel == 0) { truelight@0: GfxFillRect(x+1, y, x+w->width-4, y + 9, 0); truelight@0: } truelight@0: DrawString(x+2, y, _dropdown_items[i], sel==0 ? 12 : 16); truelight@0: truelight@0: if (dis & 1) { truelight@0: GfxFillRect(x, y, x+w->width-3, y + 9, 0x8000 + truelight@0: _color_list[_dropdown_menu_widgets[0].color].window_color_bga); truelight@0: } truelight@0: } else { truelight@0: int color_1 = _color_list[_dropdown_menu_widgets[0].color].window_color_1a; truelight@0: int color_2 = _color_list[_dropdown_menu_widgets[0].color].window_color_2; truelight@0: GfxFillRect(x+1, y+3, x+w->width-5, y+3, color_1); truelight@0: GfxFillRect(x+1, y+4, x+w->width-5, y+4, color_2); truelight@0: } truelight@0: y += 10; truelight@0: sel--; truelight@0: dis>>=1; truelight@0: } truelight@0: } break; truelight@0: truelight@0: case WE_CLICK: { truelight@0: item = GetDropdownItem(w); truelight@0: if (item >= 0) { truelight@0: _dropdown_var1 = 4; truelight@0: _dropdown_selindex = item; truelight@0: SetWindowDirty(w); truelight@0: } truelight@0: } break; truelight@0: truelight@0: case WE_MOUSELOOP: { truelight@0: Window *w2 = FindWindowById(_dropdown_windowclass, _dropdown_windownum); truelight@0: if (w2 == NULL) { truelight@0: DeleteWindow(w); truelight@0: return; truelight@0: } truelight@0: truelight@0: if (_dropdown_var1 != 0 && --_dropdown_var1 == 0) { truelight@0: WindowEvent e; truelight@0: e.event = WE_DROPDOWN_SELECT; truelight@0: e.dropdown.button = _dropdown_button; truelight@0: e.dropdown.index = _dropdown_selindex; truelight@0: w2->wndproc(w2, &e); truelight@0: DeleteWindow(w); truelight@0: return; truelight@0: } truelight@0: truelight@0: if (_dropdown_var2 != 0) { truelight@0: item = GetDropdownItem(w); truelight@0: truelight@0: if (!_left_button_clicked) { truelight@0: _dropdown_var2 = 0; truelight@0: if (item < 0) truelight@0: return; truelight@0: _dropdown_var1 = 2; truelight@0: } else { truelight@0: if (item < 0) truelight@0: return; truelight@0: } truelight@0: truelight@0: _dropdown_selindex = item; truelight@0: SetWindowDirty(w); truelight@0: } truelight@0: } break; truelight@0: truelight@0: case WE_DESTROY: { truelight@0: Window *w2 = FindWindowById(_dropdown_windowclass, _dropdown_windownum); truelight@0: if (w2 != NULL) { truelight@0: CLRBIT(w2->click_state, _dropdown_button); truelight@0: InvalidateWidget(w2, _dropdown_button); truelight@0: } truelight@0: } break; truelight@0: } truelight@0: } truelight@0: truelight@0: void ShowDropDownMenu(Window *w, const StringID *strings, int selected, int button, uint32 disabled_mask) truelight@0: { truelight@0: WindowNumber num; truelight@0: WindowClass cls; truelight@0: int i,t1,t2; truelight@0: const Widget *wi; truelight@0: Window *w2; truelight@0: uint32 old_click_state = w->click_state; truelight@0: truelight@0: _dropdown_disabled = disabled_mask; truelight@0: truelight@0: cls = w->window_class; truelight@0: num = w->window_number; truelight@0: DeleteWindowById(WC_DROPDOWN_MENU, 0); truelight@0: w = FindWindowById(cls, num); truelight@0: truelight@0: if (HASBIT(old_click_state, button)) truelight@0: return; truelight@0: truelight@0: SETBIT(w->click_state, button); truelight@0: truelight@0: InvalidateWidget(w, button); truelight@0: truelight@0: for(i=0;strings[i] != INVALID_STRING_ID;i++); truelight@0: if (i == 0) truelight@0: return; truelight@0: truelight@0: _dropdown_items = strings; truelight@0: _dropdown_item_count = i; truelight@0: _dropdown_selindex = selected; truelight@0: truelight@0: _dropdown_windowclass = w->window_class; truelight@0: _dropdown_windownum = w->window_number; truelight@0: _dropdown_button = button; truelight@0: truelight@0: _dropdown_var1 = 0; truelight@0: _dropdown_var2 = 1; truelight@0: truelight@0: wi = &w->widget[button]; truelight@0: truelight@0: _dropdown_menu_widgets[0].color = wi->color; truelight@0: truelight@0: w2 = AllocateWindow( truelight@0: w->left + wi[-1].left + 1, truelight@0: w->top + wi->bottom + 2, truelight@0: (_dropdown_menu_widgets[0].right=t1=wi->right - wi[-1].left, t1 + 1), truelight@0: (_dropdown_menu_widgets[0].bottom=t2=i*10+3, t2+1), truelight@0: DropdownMenuWndProc, truelight@0: 0x3F, truelight@0: _dropdown_menu_widgets); truelight@0: truelight@0: truelight@0: w2->flags4 &= ~WF_WHITE_BORDER_MASK; truelight@0: } truelight@0: truelight@0: extern const StringID _currency_string_list[]; truelight@0: extern uint GetMaskOfAllowedCurrencies(); truelight@0: truelight@0: static const StringID _distances_dropdown[] = { truelight@0: STR_0139_IMPERIAL_MILES, truelight@0: STR_013A_METRIC_KILOMETERS, 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: truelight@0: static int GetCurRes() truelight@0: { truelight@0: int i; truelight@0: for(i=0; i!=_num_resolutions; i++) truelight@0: if (_resolutions[i][0] == _cur_resolution[0] && _resolutions[i][1] == _cur_resolution[1]) truelight@0: break; truelight@0: return i; truelight@0: } truelight@0: truelight@0: static void GameOptionsWndProc(Window *w, WindowEvent *e) truelight@0: { truelight@0: int i; truelight@0: truelight@0: switch(e->event) { truelight@0: case WE_PAINT: { truelight@0: StringID str = STR_02BE_DEFAULT; truelight@0: w->disabled_state = (_vehicle_design_names & 1) ? (++str, 0) : (1 << 21); truelight@0: SET_DPARAM16(0, str); truelight@0: SET_DPARAM16(1, _currency_string_list[_opt_mod_ptr->currency]); truelight@0: SET_DPARAM16(2, _opt_mod_ptr->kilometers + STR_0139_IMPERIAL_MILES); truelight@0: SET_DPARAM16(3, STR_02E9_DRIVE_ON_LEFT + _opt_mod_ptr->road_side); truelight@0: SET_DPARAM16(4, STR_TOWNNAME_ENGLISH + _opt_mod_ptr->town_name); truelight@0: SET_DPARAM16(5, _autosave_dropdown[_opt_mod_ptr->autosave]); truelight@0: SET_DPARAM16(6, SPECSTR_LANGUAGE_START + _dynlang.curr); truelight@0: i = GetCurRes(); truelight@0: SET_DPARAM16(7, i == _num_resolutions ? STR_RES_OTHER : SPECSTR_RESOLUTION_START + i); truelight@0: SET_DPARAM16(8, SPECSTR_SCREENSHOT_START + _cur_screenshot_format); truelight@0: DrawWindowWidgets(w); truelight@0: } break; truelight@0: truelight@0: case WE_CLICK: truelight@0: switch(e->click.widget) { truelight@0: case 5: truelight@0: ShowDropDownMenu(w, _currency_string_list, _opt_mod_ptr->currency, e->click.widget, _game_mode == GM_MENU ? 0 : ~GetMaskOfAllowedCurrencies()); truelight@0: return; truelight@0: case 8: truelight@0: ShowDropDownMenu(w, _distances_dropdown, _opt_mod_ptr->kilometers, e->click.widget, 0); truelight@0: return; truelight@0: case 11: { truelight@0: int i = _opt_mod_ptr->road_side; truelight@0: ShowDropDownMenu(w, _driveside_dropdown, i, e->click.widget, (_game_mode == GM_MENU) ? 0 : (-1) ^ (1 << i)); truelight@0: return; truelight@0: } truelight@0: case 14: { truelight@0: int i = _opt_mod_ptr->town_name; truelight@0: ShowDropDownMenu(w, BuildDynamicDropdown(STR_TOWNNAME_ENGLISH, SPECSTR_TOWNNAME_LAST - SPECSTR_TOWNNAME_START + 1), i, e->click.widget, (_game_mode == GM_MENU) ? 0 : (-1) ^ (1 << i)); truelight@0: return; truelight@0: } truelight@0: case 17: truelight@0: ShowDropDownMenu(w, _autosave_dropdown, _opt_mod_ptr->autosave, e->click.widget, 0); truelight@0: return; truelight@0: case 20: truelight@0: ShowDropDownMenu(w, _designnames_dropdown, (_vehicle_design_names&1)?1:0, e->click.widget, (_vehicle_design_names&2)?0:2); truelight@0: return; truelight@0: case 21: truelight@0: return; truelight@0: case 24: truelight@0: ShowDropDownMenu(w, _dynlang.dropdown, _dynlang.curr, e->click.widget, 0); truelight@0: return; truelight@0: case 27: truelight@0: // setup resolution dropdown truelight@0: ShowDropDownMenu(w, BuildDynamicDropdown(SPECSTR_RESOLUTION_START, _num_resolutions), GetCurRes(), e->click.widget, 0); truelight@0: return; truelight@0: case 30: truelight@0: // setup screenshot format dropdown truelight@0: ShowDropDownMenu(w, BuildDynamicDropdown(SPECSTR_SCREENSHOT_START, _num_screenshot_formats), _cur_screenshot_format, e->click.widget, 0); truelight@0: return; truelight@0: truelight@0: } truelight@0: break; truelight@0: truelight@0: case WE_DROPDOWN_SELECT: truelight@0: switch(e->dropdown.button) { truelight@0: case 20: truelight@0: if (e->dropdown.index == 0) { truelight@0: DeleteCustomEngineNames(); truelight@0: MarkWholeScreenDirty(); truelight@0: } else if (!(_vehicle_design_names&1)) { truelight@0: LoadCustomEngineNames(); truelight@0: MarkWholeScreenDirty(); truelight@0: } truelight@0: break; truelight@0: case 5: truelight@0: _opt_mod_ptr->currency = _opt.currency = e->dropdown.index; truelight@0: MarkWholeScreenDirty(); truelight@0: break; truelight@0: case 8: truelight@0: _opt_mod_ptr->kilometers = e->dropdown.index; truelight@0: MarkWholeScreenDirty(); truelight@0: break; truelight@0: case 11: truelight@0: if (_game_mode == GM_MENU) truelight@0: DoCommandP(0, e->dropdown.index, 0, NULL, CMD_SET_ROAD_DRIVE_SIDE | CMD_MSG(STR_EMPTY)); truelight@0: break; truelight@0: case 14: truelight@0: if (_game_mode == GM_MENU) truelight@0: DoCommandP(0, e->dropdown.index, 0, NULL, CMD_SET_TOWN_NAME_TYPE | CMD_MSG(STR_EMPTY)); truelight@0: break; truelight@0: case 17: truelight@0: _opt_mod_ptr->autosave = e->dropdown.index; truelight@0: SetWindowDirty(w); truelight@0: break; truelight@0: truelight@0: // change interface language truelight@0: case 24: truelight@0: ReadLanguagePack(e->dropdown.index); truelight@0: MarkWholeScreenDirty(); truelight@0: break; truelight@0: truelight@0: // change resolution truelight@0: case 27: truelight@0: if (e->dropdown.index < _num_resolutions && ChangeResInGame(_resolutions[e->dropdown.index][0],_resolutions[e->dropdown.index][1])) truelight@0: SetWindowDirty(w); truelight@0: break; truelight@0: truelight@0: // change screenshot format truelight@0: case 30: truelight@0: SetScreenshotFormat(e->dropdown.index); truelight@0: SetWindowDirty(w); truelight@0: break; truelight@0: } truelight@0: break; truelight@0: } truelight@0: } truelight@0: truelight@0: int32 CmdSetRoadDriveSide(int x, int y, uint32 flags, uint32 p1, uint32 p2) truelight@0: { truelight@0: if (flags & DC_EXEC) { truelight@0: _opt_mod_ptr->road_side = p1; truelight@0: InvalidateWindow(WC_GAME_OPTIONS,0); truelight@0: } truelight@0: return 0; truelight@0: } truelight@0: truelight@0: int32 CmdSetTownNameType(int x, int y, uint32 flags, uint32 p1, uint32 p2) truelight@0: { truelight@0: if (flags & DC_EXEC) { truelight@0: _opt_mod_ptr->town_name = p1; truelight@0: InvalidateWindow(WC_GAME_OPTIONS,0); truelight@0: } truelight@0: return 0; truelight@0: } truelight@0: truelight@0: truelight@0: static const Widget _game_options_widgets[] = { truelight@0: { WWT_CLOSEBOX, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, truelight@0: { WWT_CAPTION, 14, 11, 369, 0, 13, STR_00B1_GAME_OPTIONS, STR_018C_WINDOW_TITLE_DRAG_THIS}, truelight@0: { WWT_PANEL, 14, 0, 369, 14, 233, 0x0}, truelight@0: { WWT_FRAME, 14, 10, 179, 20, 55, STR_02E0_CURRENCY_UNITS}, truelight@0: { WWT_6, 14, 20, 169, 34, 45, STR_02E1, STR_02E2_CURRENCY_UNITS_SELECTION}, truelight@0: { WWT_CLOSEBOX, 14, 158, 168, 35, 44, STR_0225, STR_02E2_CURRENCY_UNITS_SELECTION}, truelight@0: { WWT_FRAME, 14, 190, 359, 20, 55, STR_02E3_DISTANCE_UNITS}, truelight@0: { WWT_6, 14, 200, 349, 34, 45, STR_02E4, STR_02E5_DISTANCE_UNITS_SELECTION}, truelight@0: { WWT_CLOSEBOX, 14, 338, 348, 35, 44, STR_0225, STR_02E5_DISTANCE_UNITS_SELECTION}, truelight@0: { WWT_FRAME, 14, 10, 179, 62, 97, STR_02E6_ROAD_VEHICLES}, truelight@0: { WWT_6, 14, 20, 169, 76, 87, STR_02E7, STR_02E8_SELECT_SIDE_OF_ROAD_FOR}, truelight@0: { WWT_CLOSEBOX, 14, 158, 168, 77, 86, STR_0225, STR_02E8_SELECT_SIDE_OF_ROAD_FOR}, truelight@0: { WWT_FRAME, 14, 190, 359, 62, 97, STR_02EB_TOWN_NAMES}, truelight@0: { WWT_6, 14, 200, 349, 76, 87, STR_02EC, STR_02ED_SELECT_STYLE_OF_TOWN_NAMES}, truelight@0: { WWT_CLOSEBOX, 14, 338, 348, 77, 86, STR_0225, STR_02ED_SELECT_STYLE_OF_TOWN_NAMES}, truelight@0: { WWT_FRAME, 14, 10, 179, 104, 139, STR_02F4_AUTOSAVE}, truelight@0: { WWT_6, 14, 20, 169, 118, 129, STR_02F5, STR_02F6_SELECT_INTERVAL_BETWEEN}, truelight@0: { WWT_CLOSEBOX, 14, 158, 168, 119, 128, STR_0225, STR_02F6_SELECT_INTERVAL_BETWEEN}, truelight@0: truelight@0: { WWT_FRAME, 14, 10, 359, 188, 223, STR_02BC_VEHICLE_DESIGN_NAMES}, truelight@0: { WWT_6, 14, 20, 119, 202, 213, STR_02BD, STR_02C1_VEHICLE_DESIGN_NAMES_SELECTION}, truelight@0: { WWT_CLOSEBOX, 14, 108, 118, 203, 212, STR_0225, STR_02C1_VEHICLE_DESIGN_NAMES_SELECTION}, truelight@0: { WWT_CLOSEBOX, 14, 130, 349, 202, 213, STR_02C0_SAVE_CUSTOM_NAMES_TO_DISK, STR_02C2_SAVE_CUSTOMIZED_VEHICLE}, truelight@0: truelight@0: { WWT_FRAME, 14, 190, 359, 104, 139, STR_OPTIONS_LANG}, truelight@0: { WWT_6, 14, 200, 349, 118, 129, STR_OPTIONS_LANG_CBO, STR_OPTIONS_LANG_TIP}, truelight@0: { WWT_CLOSEBOX, 14, 338, 348, 119, 128, STR_0225, STR_OPTIONS_LANG_TIP}, truelight@0: { WWT_FRAME, 14, 10, 179, 146, 181, STR_OPTIONS_RES}, truelight@0: { WWT_6, 14, 20, 169, 160, 171, STR_OPTIONS_RES_CBO, STR_OPTIONS_RES_TIP}, truelight@0: { WWT_CLOSEBOX, 14, 158, 168, 161, 170, STR_0225, STR_OPTIONS_RES_TIP}, truelight@0: truelight@0: { WWT_FRAME, 14, 190, 359, 146, 181, STR_OPTIONS_SCREENSHOT_FORMAT}, truelight@0: { WWT_6, 14, 200, 349, 160, 171, STR_OPTIONS_SCREENSHOT_FORMAT_CBO, STR_OPTIONS_SCREENSHOT_FORMAT_TIP}, truelight@0: { WWT_CLOSEBOX, 14, 338, 348, 161, 170, STR_0225, STR_OPTIONS_SCREENSHOT_FORMAT_TIP}, truelight@0: truelight@0: { WWT_LAST}, truelight@0: }; truelight@0: truelight@0: static const WindowDesc _game_options_desc = { truelight@0: WDP_CENTER, WDP_CENTER, 370, 234, truelight@0: WC_GAME_OPTIONS,0, truelight@0: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_RESTORE_DPARAM | WDF_UNCLICK_BUTTONS, truelight@0: _game_options_widgets, truelight@0: GameOptionsWndProc truelight@0: }; truelight@0: truelight@0: truelight@0: void ShowGameOptions() 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[] = { truelight@0: {0,7,1,0}, truelight@0: {0,3,1,STR_6830_IMMEDIATE}, truelight@0: {0,2,1,STR_6816_LOW}, orudge@61: {0,3,1,STR_26816_NONE}, truelight@0: {100,500,50,0}, truelight@0: {2,4,1,0}, truelight@0: {0,2,1,STR_6820_LOW}, truelight@0: {0,4,1,STR_681B_VERY_SLOW}, truelight@0: {0,2,1,STR_6820_LOW}, truelight@0: {0,2,1,STR_6823_NONE}, truelight@0: {0,3,1,STR_6826_X1_5}, truelight@0: {0,2,1,STR_6820_LOW}, truelight@0: {0,3,1,STR_682A_VERY_FLAT}, truelight@0: {0,3,1,STR_VERY_LOW}, truelight@0: {0,1,1,STR_682E_STEADY}, truelight@0: {0,1,1,STR_6834_AT_END_OF_LINE_AND_AT_STATIONS}, truelight@0: {0,1,1,STR_6836_OFF}, truelight@0: {0,2,1,STR_6839_PERMISSIVE}, truelight@0: }; truelight@0: truelight@0: static bool FORCEINLINE GetBitAndShift(uint32 *b) truelight@0: { truelight@0: uint32 x = *b; truelight@0: *b >>= 1; truelight@0: return (x&1) != 0; truelight@0: } truelight@0: truelight@0: static GameOptions _opt_mod_temp; truelight@0: truelight@0: static const int16 _default_game_diff[3][GAME_DIFFICULTY_NUM] = { orudge@61: {2, 2, 1, 3, 300, 2, 0, 2, 0, 1, 2, 0, 1, 0, 0, 0, 0, 0}, orudge@61: {4, 1, 1, 2, 150, 3, 1, 3, 1, 2, 1, 1, 2, 1, 1, 1, 1, 1}, orudge@61: {7, 0, 2, 2, 100, 4, 1, 3, 2, 2, 0, 2, 3, 2, 1, 1, 1, 2}, 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 truelight@0: 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: darkvater@46: extern void StartupEconomy(); darkvater@46: truelight@0: static void GameDifficultyWndProc(Window *w, WindowEvent *e) truelight@0: { truelight@0: switch(e->event) { truelight@0: case WE_PAINT: { truelight@0: uint32 click_a, click_b, disabled; truelight@0: int i; truelight@0: int x,y,value; truelight@0: truelight@0: w->click_state = (1 << 4) << _opt_mod_temp.diff_level; truelight@0: w->disabled_state = (_game_mode != GM_NORMAL) ? 0 : (1 << 4) | (1 << 5) | (1 << 6) | (1 << 7); truelight@0: DrawWindowWidgets(w); truelight@0: truelight@0: click_a = _difficulty_click_a; truelight@0: click_b = _difficulty_click_b; truelight@0: truelight@0: disabled = _game_mode == GM_NORMAL ? 0x383E : 0; truelight@0: // XXX truelight@0: truelight@0: x = 0; truelight@0: y = 32; truelight@0: for (i = 0; i != GAME_DIFFICULTY_NUM; i++) { truelight@0: DrawFrameRect(x+5, y+1, x+5+9, y+9, 3, GetBitAndShift(&click_a)?0x20:0); truelight@0: DrawFrameRect(x+15, y+1, x+15+9, y+9, 3, GetBitAndShift(&click_b)?0x20:0); truelight@0: if (GetBitAndShift(&disabled)) { truelight@0: int color = 0x8000 | _color_list[3].unk2; truelight@0: GfxFillRect(x+6, y+2, x+6+8, y+9, color); truelight@0: GfxFillRect(x+16, y+2, x+16+8, y+9, color); truelight@0: } truelight@0: truelight@0: DrawStringCentered(x+10, y+1, STR_6819, 0); truelight@0: DrawStringCentered(x+20, y+1, STR_681A, 0); truelight@0: truelight@0: truelight@0: value = _game_setting_info[i].str + ((int*)&_opt_mod_temp.diff)[i]; truelight@0: if (i == 4) value *= 1000; // handle currency option truelight@0: SET_DPARAM32(0, value); truelight@0: DrawString(x+30, y+1, STR_6805_MAXIMUM_NO_COMPETITORS + i, 0); truelight@0: truelight@0: y += 11; truelight@0: } truelight@0: } break; truelight@0: truelight@0: case WE_CLICK: truelight@0: switch(e->click.widget) { truelight@0: case 3: { truelight@0: int x,y; truelight@0: uint btn, dis; truelight@0: int val; truelight@0: const GameSettingData *info; truelight@0: truelight@0: x = e->click.pt.x - 5; truelight@0: if (!IS_INT_INSIDE(x, 0, 21)) truelight@0: return; truelight@0: truelight@0: y = e->click.pt.y - 33; truelight@0: if (y < 0) truelight@0: return; truelight@0: truelight@0: // Get button from Y coord. truelight@0: btn = y / 11; truelight@0: if (btn >= GAME_DIFFICULTY_NUM || y % 11 > 9) truelight@0: return; truelight@0: truelight@0: // Clicked disabled button? truelight@0: dis = 0; truelight@0: if (_game_mode == GM_NORMAL) truelight@0: dis |= 0x383E; 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: truelight@0: info = &_game_setting_info[btn]; 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); truelight@0: break; truelight@0: } truelight@0: case 4: case 5: case 6: case 7: // easy/medium/hard/custom truelight@0: // temporarily change difficulty level truelight@0: SetDifficultyLevel(e->click.widget - 4, &_opt_mod_temp); truelight@0: SetWindowDirty(w); truelight@0: break; truelight@0: case 8: truelight@0: ShowHighscoreTable(_opt_mod_ptr->diff_level); truelight@0: break; truelight@0: 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 truelight@0: if (val != ((int*)&_opt_mod_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: } truelight@0: case 11: // Cancel button - close window truelight@0: DeleteWindow(w); truelight@0: break; truelight@0: } truelight@0: break; truelight@0: truelight@0: case WE_MOUSELOOP: 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: truelight@0: static const Widget _game_difficulty_widgets[] = { truelight@0: { WWT_CLOSEBOX, 10, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, truelight@0: { WWT_CAPTION, 10, 11, 369, 0, 13, STR_6800_DIFFICULTY_LEVEL, STR_018C_WINDOW_TITLE_DRAG_THIS}, truelight@0: { WWT_PANEL, 10, 0, 369, 14, 29, 0x0, 0}, truelight@0: { WWT_PANEL, 10, 0, 369, 30, 276, 0x0, 0}, truelight@0: { WWT_PUSHTXTBTN, 3, 10, 96, 16, 27, STR_6801_EASY, 0}, truelight@0: { WWT_PUSHTXTBTN, 3, 97, 183, 16, 27, STR_6802_MEDIUM, 0}, truelight@0: { WWT_PUSHTXTBTN, 3, 184, 270, 16, 27, STR_6803_HARD, 0}, truelight@0: { WWT_PUSHTXTBTN, 3, 271, 357, 16, 27, STR_6804_CUSTOM, 0}, truelight@0: { WWT_EMPTY, 10, 0, 369, 251, 262, 0x0, 0}, truelight@0: //{ WWT_CLOSEBOX, 10, 0, 369, 251, 262, STR_6838_SHOW_HI_SCORE_CHART, 0}, truelight@0: { WWT_PANEL, 10, 0, 369, 263, 278, 0x0, 0}, truelight@0: { WWT_PUSHTXTBTN, 3, 105, 185, 265, 276, STR_OPTIONS_SAVE_CHANGES, 0}, truelight@0: { WWT_PUSHTXTBTN, 3, 186, 266, 265, 276, STR_012E_CANCEL, 0}, truelight@0: { WWT_LAST}, 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: truelight@0: void ShowGameDifficulty() truelight@0: { truelight@0: DeleteWindowById(WC_GAME_OPTIONS, 0); truelight@0: /* copy current settings to temporary holding place truelight@0: * change that when setting stuff, copy back on clicking 'OK' truelight@0: */ truelight@0: memcpy(&_opt_mod_temp, _opt_mod_ptr, sizeof(GameOptions)); truelight@0: AllocateWindowDesc(&_game_difficulty_desc); truelight@0: } truelight@0: truelight@0: void ShowHighscoreTable(int tbl) truelight@0: { truelight@0: ShowInfoF("ShowHighscoreTable(%d) not implemented", tbl); truelight@0: } truelight@0: darkvater@68: // virtual PositionMainToolbar function, calls the right one. darkvater@68: int32 v_PositionMainToolbar(int32 p1) darkvater@68: { darkvater@68: if (_game_mode != GM_MENU) darkvater@68: PositionMainToolbar(NULL); darkvater@68: darkvater@68: return 0; darkvater@68: } darkvater@68: darkvater@68: typedef int32 PatchButtonClick(int32); darkvater@68: static PatchButtonClick * const _patch_button_proc[] = { darkvater@68: &v_PositionMainToolbar, darkvater@68: }; darkvater@68: truelight@0: typedef struct PatchEntry { darkvater@68: byte type; // type of selector darkvater@68: byte flags; // selector flags darkvater@68: StringID str; // string with descriptive text darkvater@68: void *variable; // pointer to the variable darkvater@68: int32 min,max; // range for spinbox setting darkvater@68: uint32 step; // step for spinbox darkvater@68: PatchButtonClick *click_proc; // callback procedure truelight@0: } PatchEntry; truelight@0: truelight@0: enum { truelight@0: PE_BOOL = 0, truelight@0: PE_UINT8 = 1, truelight@0: PE_INT16 = 2, truelight@0: PE_UINT16 = 3, truelight@0: PE_INT32 = 4, truelight@26: PE_CURRENCY = 5, truelight@0: truelight@0: PF_0ISDIS = 1, truelight@0: PF_NOCOMMA = 2, truelight@53: PF_MULTISTRING = 4, truelight@0: }; truelight@0: truelight@0: static const PatchEntry _patches_ui[] = { truelight@0: {PE_BOOL, 0, STR_CONFIG_PATCHES_VEHICLESPEED, &_patches.vehicle_speed}, truelight@0: {PE_BOOL, 0, STR_CONFIG_PATCHES_LONGDATE, &_patches.status_long_date}, truelight@0: {PE_BOOL, 0, STR_CONFIG_PATCHES_SHOWFINANCES, &_patches.show_finances}, truelight@0: {PE_BOOL, 0, STR_CONFIG_PATCHES_AUTOSCROLL, &_patches.autoscroll}, truelight@0: truelight@0: {PE_UINT8, 0, STR_CONFIG_PATCHES_ERRMSG_DURATION, &_patches.errmsg_duration, 0, 20, 1}, truelight@0: darkvater@68: {PE_UINT8, PF_MULTISTRING, STR_CONFIG_PATCHES_TOOLBAR_POS, &_patches.toolbar_pos, 0, 2, 1, &v_PositionMainToolbar}, truelight@0: }; truelight@0: truelight@0: static const PatchEntry _patches_construction[] = { truelight@0: {PE_BOOL, 0, STR_CONFIG_PATCHES_BUILDONSLOPES, &_patches.build_on_slopes}, truelight@0: {PE_BOOL, 0, STR_CONFIG_PATCHES_EXTRADYNAMITE, &_patches.extra_dynamite}, truelight@0: {PE_BOOL, 0, STR_CONFIG_PATCHES_LONGBRIDGES, &_patches.longbridges}, truelight@0: {PE_BOOL, 0, STR_CONFIG_PATCHES_SIGNALSIDE, &_patches.signal_side}, darkvater@67: truelight@0: {PE_BOOL, 0, STR_CONFIG_PATCHES_SMALL_AIRPORTS, &_patches.always_small_airport}, darkvater@58: {PE_UINT8,0, STR_CONFIG_PATCHES_DRAG_SIGNALS_DENSITY, &_patches.drag_signals_density, 1, 20, 1}, truelight@0: truelight@0: }; truelight@0: truelight@0: static const PatchEntry _patches_vehicles[] = { truelight@0: {PE_BOOL, 0, STR_CONFIG_PATCHES_REALISTICACCEL, &_patches.realistic_acceleration}, truelight@0: {PE_BOOL, 0, STR_CONFIG_PATCHES_MAMMOTHTRAINS, &_patches.mammoth_trains}, truelight@0: {PE_BOOL, 0, STR_CONFIG_PATCHES_GOTODEPOT, &_patches.gotodepot}, truelight@0: {PE_BOOL, 0, STR_CONFIG_PATCHES_ROADVEH_QUEUE, &_patches.roadveh_queue}, truelight@0: {PE_BOOL, 0, STR_CONFIG_PATCHES_NEW_DEPOT_FINDING, &_patches.new_depot_finding}, truelight@0: {PE_BOOL, 0, STR_CONFIG_PATCHES_NEW_TRAIN_PATHFIND, &_patches.new_pathfinding}, truelight@0: truelight@0: {PE_BOOL, 0, STR_CONFIG_PATCHES_WARN_INCOME_LESS, &_patches.train_income_warn}, dominik@55: {PE_UINT8, PF_MULTISTRING, STR_CONFIG_PATCHES_ORDER_REVIEW, &_patches.order_review_system,0,2,1}, truelight@0: {PE_BOOL, 0, STR_CONFIG_PATCHES_NEVER_EXPIRE_VEHICLES, &_patches.never_expire_vehicles}, truelight@0: truelight@0: {PE_UINT16, PF_0ISDIS, STR_CONFIG_PATCHES_LOST_TRAIN_DAYS, &_patches.lost_train_days, 180, 720, 60}, truelight@26: {PE_BOOL, 0, STR_CONFIG_PATCHES_AUTORENEW_VEHICLE, &_patches.autorenew}, truelight@26: {PE_INT16, 0, STR_CONFIG_PATCHES_AUTORENEW_MONTHS, &_patches.autorenew_months, -12, 12, 1}, truelight@26: {PE_CURRENCY, 0, STR_CONFIG_PATCHES_AUTORENEW_MONEY, &_patches.autorenew_money, 0, 2000000, 100000}, truelight@0: truelight@0: {PE_UINT8, 0, STR_CONFIG_PATCHES_MAX_TRAINS, &_patches.max_trains, 0, 240, 10}, truelight@0: {PE_UINT8, 0, STR_CONFIG_PATCHES_MAX_ROADVEH, &_patches.max_roadveh, 0, 240, 10}, truelight@0: {PE_UINT8, 0, STR_CONFIG_PATCHES_MAX_AIRCRAFT, &_patches.max_aircraft, 0, 240, 10}, truelight@0: {PE_UINT8, 0, STR_CONFIG_PATCHES_MAX_SHIPS, &_patches.max_ships, 0, 240, 10}, truelight@0: dominik@11: {PE_UINT16, PF_0ISDIS, STR_CONFIG_PATCHES_SERVINT_TRAINS, &_patches.servint_trains, 30, 1200, 10}, dominik@11: {PE_UINT16, PF_0ISDIS, STR_CONFIG_PATCHES_SERVINT_ROADVEH, &_patches.servint_roadveh, 30, 1200, 10}, dominik@11: {PE_UINT16, PF_0ISDIS, STR_CONFIG_PATCHES_SERVINT_AIRCRAFT, &_patches.servint_aircraft, 30, 1200, 10}, dominik@11: {PE_UINT16, PF_0ISDIS, STR_CONFIG_PATCHES_SERVINT_SHIPS, &_patches.servint_ships, 30, 1200, 10}, truelight@0: }; truelight@0: truelight@0: static const PatchEntry _patches_stations[] = { truelight@0: {PE_BOOL, 0, STR_CONFIG_PATCHES_JOINSTATIONS, &_patches.join_stations}, truelight@0: {PE_BOOL, 0, STR_CONFIG_PATCHES_FULLLOADANY, &_patches.full_load_any}, truelight@0: {PE_BOOL, 0, STR_CONFIG_PATCHES_SELECTGOODS, &_patches.selectgoods}, truelight@0: {PE_BOOL, 0, STR_CONFIG_PATCHES_NEW_NONSTOP, &_patches.new_nonstop}, truelight@0: {PE_BOOL, 0, STR_CONFIG_PATCHES_NONUNIFORM_STATIONS, &_patches.nonuniform_stations}, truelight@0: {PE_UINT8, 0, STR_CONFIG_PATCHES_STATION_SPREAD, &_patches.station_spread, 4, 64, 1}, truelight@0: {PE_BOOL, 0, STR_CONFIG_PATCHES_SERVICEATHELIPAD, &_patches.serviceathelipad}, truelight@0: }; truelight@0: truelight@0: static const PatchEntry _patches_economy[] = { truelight@0: {PE_BOOL, 0, STR_CONFIG_PATCHES_INFLATION, &_patches.inflation}, truelight@0: {PE_BOOL, 0, STR_CONFIG_PATCHES_BUILDXTRAIND, &_patches.build_rawmaterial_ind}, truelight@0: {PE_BOOL, 0, STR_CONFIG_PATCHES_MULTIPINDTOWN, &_patches.multiple_industry_per_town}, truelight@0: {PE_BOOL, 0, STR_CONFIG_PATCHES_SAMEINDCLOSE, &_patches.same_industry_close}, truelight@0: {PE_BOOL, 0, STR_CONFIG_PATCHES_BRIBE, &_patches.bribe}, truelight@0: {PE_UINT8, 0, STR_CONFIG_PATCHES_SNOWLINE_HEIGHT, &_patches.snow_line_height, 2, 13, 1}, truelight@0: truelight@0: {PE_INT32, PF_NOCOMMA, STR_CONFIG_PATCHES_COLORED_NEWS_DATE, &_patches.colored_news_date, 1900, 2200, 5}, truelight@0: {PE_INT32, PF_NOCOMMA, STR_CONFIG_PATCHES_STARTING_DATE, &_patches.starting_date, 1920, 2100, 1}, truelight@0: truelight@0: {PE_BOOL, 0, STR_CONFIG_PATCHES_SMOOTH_ECONOMY, &_patches.smooth_economy}, truelight@0: }; truelight@0: truelight@21: static const PatchEntry _patches_ai[] = { truelight@21: {PE_BOOL, 0, STR_CONFIG_PATCHES_AI_BUILDS_TRAINS, &_patches.ai_disable_veh_train}, truelight@21: {PE_BOOL, 0, STR_CONFIG_PATCHES_AI_BUILDS_ROADVEH, &_patches.ai_disable_veh_roadveh}, truelight@21: {PE_BOOL, 0, STR_CONFIG_PATCHES_AI_BUILDS_AIRCRAFT, &_patches.ai_disable_veh_aircraft}, truelight@21: {PE_BOOL, 0, STR_CONFIG_PATCHES_AI_BUILDS_SHIPS, &_patches.ai_disable_veh_ship}, truelight@21: }; truelight@21: truelight@0: typedef struct PatchPage { truelight@0: const PatchEntry *entries; truelight@0: uint num; truelight@0: } PatchPage; truelight@0: truelight@0: static const PatchPage _patches_page[] = { truelight@0: {_patches_ui, lengthof(_patches_ui) }, truelight@0: {_patches_construction, lengthof(_patches_construction) }, truelight@0: {_patches_vehicles, lengthof(_patches_vehicles) }, truelight@0: {_patches_stations, lengthof(_patches_stations) }, truelight@0: {_patches_economy, lengthof(_patches_economy) }, truelight@21: {_patches_ai, lengthof(_patches_ai) }, truelight@0: }; truelight@0: truelight@26: extern uint GetCurrentCurrencyRate(); truelight@26: truelight@0: static int32 ReadPE(const PatchEntry*pe) truelight@0: { truelight@0: switch(pe->type) { truelight@0: case PE_BOOL: return *(bool*)pe->variable; truelight@0: case PE_UINT8: return *(uint8*)pe->variable; truelight@0: case PE_INT16: return *(int16*)pe->variable; truelight@0: case PE_UINT16: return *(uint16*)pe->variable; truelight@0: case PE_INT32: return *(int32*)pe->variable; truelight@26: case PE_CURRENCY: return (*(int64*)pe->variable) * GetCurrentCurrencyRate(); truelight@0: default: truelight@0: NOT_REACHED(); truelight@0: } truelight@0: truelight@0: /* useless, but avoids compiler warning this way */ truelight@0: return 0; truelight@0: } truelight@0: truelight@20: static void WritePE(const PatchEntry *pe, int32 val) truelight@20: { darkvater@48: darkvater@48: if ((pe->flags & PF_0ISDIS) && val <= 0) { darkvater@48: *(bool*)pe->variable = 0; // "clamp" 'disabled' value to smallest type, PE_BOOL darkvater@48: return; darkvater@48: } darkvater@48: truelight@20: switch(pe->type) { truelight@20: case PE_BOOL: *(bool*)pe->variable = (bool)val; break; truelight@20: truelight@20: case PE_UINT8: if ((uint8)val > (uint8)pe->max) truelight@20: *(uint8*)pe->variable = (uint8)pe->max; truelight@20: else if ((uint8)val < (uint8)pe->min) truelight@20: *(uint8*)pe->variable = (uint8)pe->min; truelight@20: else truelight@20: *(uint8*)pe->variable = (uint8)val; truelight@20: break; truelight@20: truelight@20: case PE_INT16: if ((int16)val > (int16)pe->max) truelight@20: *(int16*)pe->variable = (int16)pe->max; truelight@20: else if ((int16)val < (int16)pe->min) truelight@20: *(int16*)pe->variable = (int16)pe->min; truelight@20: else truelight@20: *(int16*)pe->variable = (int16)val; truelight@20: break; truelight@20: truelight@20: case PE_UINT16: if ((uint16)val > (uint16)pe->max) truelight@20: *(uint16*)pe->variable = (uint16)pe->max; truelight@20: else if ((uint16)val < (uint16)pe->min) truelight@20: *(uint16*)pe->variable = (uint16)pe->min; truelight@20: else truelight@20: *(uint16*)pe->variable = (uint16)val; truelight@20: break; truelight@20: truelight@20: case PE_INT32: if ((int32)val > (int32)pe->max) truelight@20: *(int32*)pe->variable = (int32)pe->max; truelight@20: else if ((int32)val < (int32)pe->min) truelight@20: *(int32*)pe->variable = (int32)pe->min; truelight@20: else truelight@20: *(int32*)pe->variable = val; truelight@20: break; truelight@26: truelight@26: case PE_CURRENCY: val /= GetCurrentCurrencyRate(); truelight@26: if ((int64)val > (int64)pe->max) truelight@26: *(int64*)pe->variable = (int64)pe->max; truelight@26: else if ((int64)val < (int64)pe->min) truelight@26: *(int64*)pe->variable = (int64)pe->min; truelight@26: else truelight@26: *(int64*)pe->variable = val; truelight@26: break; truelight@20: default: truelight@20: NOT_REACHED(); truelight@20: } truelight@0: } truelight@0: truelight@0: static void PatchesSelectionWndProc(Window *w, WindowEvent *e) truelight@0: { truelight@0: uint i; truelight@0: switch(e->event) { truelight@0: case WE_PAINT: { truelight@0: int x,y; truelight@0: const PatchEntry *pe; truelight@0: const PatchPage *page; truelight@0: uint clk; truelight@0: int32 val; truelight@0: truelight@0: w->click_state = 1 << (WP(w,def_d).data_1 + 4); truelight@0: truelight@0: DrawWindowWidgets(w); truelight@0: truelight@0: x = 0; truelight@0: y = 46; truelight@0: clk = WP(w,def_d).data_2; truelight@0: page = &_patches_page[WP(w,def_d).data_1]; truelight@0: for(i=0,pe=page->entries; i!=page->num; i++,pe++) { dominik@11: bool disabled = false; truelight@0: if (pe->type == PE_BOOL) { truelight@0: DrawFrameRect(x+5, y+1, x+15+9, y+9, (*(bool*)pe->variable)?6:4, (*(bool*)pe->variable)?0x20:0); truelight@0: SET_DPARAM16(0, *(bool*)pe->variable ? STR_CONFIG_PATCHES_ON : STR_CONFIG_PATCHES_OFF); truelight@0: } else { truelight@0: DrawFrameRect(x+5, y+1, x+5+9, y+9, 3, clk == i*2+1 ? 0x20 : 0); truelight@0: DrawFrameRect(x+15, y+1, x+15+9, y+9, 3, clk == i*2+2 ? 0x20 : 0); truelight@0: DrawStringCentered(x+10, y+1, STR_6819, 0); truelight@0: DrawStringCentered(x+20, y+1, STR_681A, 0); truelight@0: truelight@0: val = ReadPE(pe); truelight@26: if (pe->type == PE_CURRENCY) truelight@26: val /= GetCurrentCurrencyRate(); dominik@11: disabled = ((val == 0) && (pe->flags & PF_0ISDIS)); dominik@11: if (disabled) { truelight@0: SET_DPARAM16(0, STR_CONFIG_PATCHES_DISABLED); truelight@0: } else { truelight@0: SET_DPARAM32(1, val); truelight@26: if (pe->type == PE_CURRENCY) truelight@26: SET_DPARAM16(0, STR_CONFIG_PATCHES_CURRENCY); truelight@53: else { truelight@53: if (pe->flags & PF_MULTISTRING) truelight@53: SET_DPARAM16(0, pe->str + val + 1); truelight@53: else truelight@53: SET_DPARAM16(0, pe->flags & PF_NOCOMMA ? STR_CONFIG_PATCHES_INT32 : STR_7024); truelight@53: } truelight@0: } truelight@0: } dominik@11: DrawString(30, y+1, (pe->str)+disabled, 0); truelight@0: y += 11; truelight@0: } truelight@0: break; truelight@0: } truelight@0: truelight@0: case WE_CLICK: truelight@0: switch(e->click.widget) { truelight@0: case 3: { truelight@0: int x,y; truelight@0: uint btn; truelight@0: const PatchPage *page; truelight@0: const PatchEntry *pe; truelight@0: truelight@0: y = e->click.pt.y - 46 - 1; truelight@0: if (y < 0) return; truelight@0: truelight@0: btn = y / 11; truelight@0: if (y % 11 > 9) return; truelight@0: truelight@0: page = &_patches_page[WP(w,def_d).data_1]; truelight@0: if (btn >= page->num) return; truelight@0: pe = &page->entries[btn]; truelight@0: truelight@0: x = e->click.pt.x - 5; truelight@0: if (x < 0) return; truelight@0: darkvater@68: if (x < 21) { // clicked on the icon on the left side. Either scroller or bool on/off truelight@0: int32 val = ReadPE(pe), oval = val; truelight@0: truelight@0: switch(pe->type) { truelight@0: case PE_BOOL: truelight@0: val ^= 1; truelight@0: break; truelight@0: case PE_UINT8: truelight@0: case PE_INT16: truelight@0: case PE_UINT16: truelight@0: case PE_INT32: truelight@26: case PE_CURRENCY: 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: truelight@0: if (x >= 10) { truelight@0: //increase truelight@0: if (pe->flags & PF_0ISDIS && val == 0) truelight@0: val = pe->min; truelight@0: else truelight@0: val += pe->step; truelight@0: if (val > pe->max) val = pe->max; truelight@0: } else { dominik@47: // decrease truelight@0: if (val <= pe->min && pe->flags & PF_0ISDIS) { truelight@0: val = 0; truelight@0: } else { truelight@0: val -= pe->step; truelight@0: if (val < pe->min) val = pe->min; truelight@0: } truelight@0: } truelight@0: truelight@0: if (val != oval) { truelight@0: 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: } truelight@0: break; truelight@0: } truelight@0: if (val != oval) { truelight@0: WritePE(pe, val); truelight@0: SetWindowDirty(w); darkvater@68: darkvater@68: if (pe->click_proc != NULL) // call callback function darkvater@68: pe->click_proc(val); truelight@0: } truelight@0: } else { darkvater@68: if (pe->type != PE_BOOL && !(pe->flags & PF_MULTISTRING)) { // do not open editbox truelight@0: WP(w,def_d).data_3 = btn; truelight@0: SET_DPARAM32(0, ReadPE(pe)); truelight@0: ShowQueryString(STR_CONFIG_PATCHES_INT32, STR_CONFIG_PATCHES_QUERY_CAPT, 10, 100, WC_GAME_OPTIONS, 0); truelight@0: } truelight@0: } truelight@0: truelight@0: break; truelight@0: } truelight@21: case 4: case 5: case 6: case 7: case 8: case 9: truelight@0: WP(w,def_d).data_1 = e->click.widget - 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: { truelight@0: if (*e->edittext.str) { truelight@0: const PatchPage *page = &_patches_page[WP(w,def_d).data_1]; darkvater@68: const PatchEntry *pe = &page->entries[WP(w,def_d).data_3]; darkvater@68: WritePE(pe, atoi(e->edittext.str)); truelight@0: SetWindowDirty(w); darkvater@68: darkvater@68: if (pe->click_proc != NULL) // call callback function darkvater@68: pe->click_proc(*(int32*)pe->variable); 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[] = { truelight@0: { WWT_CLOSEBOX, 10, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, truelight@0: { WWT_CAPTION, 10, 11, 369, 0, 13, STR_CONFIG_PATCHES_CAPTION, STR_018C_WINDOW_TITLE_DRAG_THIS}, truelight@0: { WWT_PANEL, 10, 0, 369, 14, 41, 0x0, 0}, truelight@0: { WWT_PANEL, 10, 0, 369, 42, 320, 0x0, 0}, truelight@0: truelight@0: { WWT_CLOSEBOX, 3, 10, 96, 16, 27, STR_CONFIG_PATCHES_GUI, 0}, truelight@0: { WWT_CLOSEBOX, 3, 97, 183, 16, 27, STR_CONFIG_PATCHES_CONSTRUCTION, 0}, truelight@0: { WWT_CLOSEBOX, 3, 184, 270, 16, 27, STR_CONFIG_PATCHES_VEHICLES, 0}, truelight@0: { WWT_CLOSEBOX, 3, 271, 357, 16, 27, STR_CONFIG_PATCHES_STATIONS, 0}, truelight@0: { WWT_CLOSEBOX, 3, 10, 96, 28, 39, STR_CONFIG_PATCHES_ECONOMY, 0}, truelight@21: { WWT_CLOSEBOX, 3, 97, 183, 28, 39, STR_CONFIG_PATCHES_AI, 0}, truelight@0: { WWT_LAST}, truelight@0: }; truelight@0: truelight@0: static const WindowDesc _patches_selection_desc = { truelight@0: WDP_CENTER, WDP_CENTER, 370, 321, 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: truelight@0: void ShowPatchesSelection() truelight@0: { truelight@0: DeleteWindowById(WC_GAME_OPTIONS, 0); truelight@0: AllocateWindowDesc(&_patches_selection_desc); truelight@0: }