From 5a07315405a5e09e1fc46aae3d132c72ab752e84 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Sun, 30 Aug 2015 17:09:43 +0100 Subject: [PATCH] Add train length and group name to vehicle details window. Add settings to control each, default on. Re-init window whenever presence of group name line changes. --- src/lang/english.txt | 8 ++++++ src/settings_gui.cpp | 2 ++ src/settings_type.h | 2 ++ src/table/settings.ini | 18 ++++++++++++++ src/vehicle_gui.cpp | 56 +++++++++++++++++++++++++++++++++++++----- 5 files changed, 80 insertions(+), 6 deletions(-) diff --git a/src/lang/english.txt b/src/lang/english.txt index ad29b3d596..f80f7faf17 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -1287,6 +1287,10 @@ STR_CONFIG_SETTING_POPULATION_IN_LABEL :Show town popul STR_CONFIG_SETTING_POPULATION_IN_LABEL_HELPTEXT :Display the population of towns in their label on the map STR_CONFIG_SETTING_GRAPH_LINE_THICKNESS :Thickness of lines in graphs: {STRING2} STR_CONFIG_SETTING_GRAPH_LINE_THICKNESS_HELPTEXT :Width of the line in the graphs. A thin line is more precisely readable, a thicker line is easier to see and colours are easier to distinguish +STR_CONFIG_SETTING_SHOW_TRAIN_LENGTH_IN_DETAILS :Show train length in details: {STRING2} +STR_CONFIG_SETTING_SHOW_TRAIN_LENGTH_IN_DETAILS_HELPTEXT :Show train length in the vehicle details window +STR_CONFIG_SETTING_SHOW_VEHICLE_GROUP_IN_DETAILS :Show vehicle group in details: {STRING2} +STR_CONFIG_SETTING_SHOW_VEHICLE_GROUP_IN_DETAILS_HELPTEXT :Show vehicle group name in the vehicle details window STR_CONFIG_SETTING_LANDSCAPE :Landscape: {STRING2} STR_CONFIG_SETTING_LANDSCAPE_HELPTEXT :Landscapes define basic gameplay scenarios with different cargos and town growth requirements. NewGRF and Game Scripts allow finer control though @@ -3657,9 +3661,13 @@ STR_VEHICLE_INFO_MAX_SPEED_RANGE :{BLACK}Max. spe STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED :{BLACK}Weight: {LTBLUE}{WEIGHT_SHORT} {BLACK}Power: {LTBLUE}{POWER}{BLACK} Max. speed: {LTBLUE}{VELOCITY} STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED_MAX_TE :{BLACK}Weight: {LTBLUE}{WEIGHT_SHORT} {BLACK}Power: {LTBLUE}{POWER}{BLACK} Max. speed: {LTBLUE}{VELOCITY} {BLACK}Max. T.E.: {LTBLUE}{FORCE} +STR_VEHICLE_INFO_TRAIN_LENGTH :{BLACK}Train length {LTBLUE}{DECIMAL} tile{P "" s} {STRING3} + STR_VEHICLE_INFO_PROFIT_THIS_YEAR_LAST_YEAR :{BLACK}Profit this year: {LTBLUE}{CURRENCY_LONG} (last year: {CURRENCY_LONG}) STR_VEHICLE_INFO_RELIABILITY_BREAKDOWNS :{BLACK}Reliability: {LTBLUE}{COMMA}% {BLACK}Breakdowns since last service: {LTBLUE}{COMMA} +STR_VEHICLE_INFO_GROUP :{BLACK}Group: {LTBLUE}{GROUP} + STR_VEHICLE_INFO_BUILT_VALUE :{LTBLUE}{ENGINE} {BLACK}Built: {LTBLUE}{NUM}{BLACK} Value: {LTBLUE}{CURRENCY_LONG} STR_VEHICLE_INFO_NO_CAPACITY :{BLACK}Capacity: {LTBLUE}None{STRING} STR_VEHICLE_INFO_CAPACITY :{BLACK}Capacity: {LTBLUE}{CARGO_LONG}{3:STRING} diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index 0652d1bd81..b9edf205bf 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -1544,6 +1544,8 @@ static SettingsContainer &GetSettingsTree() interface->Add(new SettingEntry("gui.timetable_in_ticks")); interface->Add(new SettingEntry("gui.timetable_arrival_departure")); interface->Add(new SettingEntry("gui.expenses_layout")); + interface->Add(new SettingEntry("gui.show_train_length_in_details")); + interface->Add(new SettingEntry("gui.show_vehicle_group_in_details")); } SettingsPage *advisors = main->Add(new SettingsPage(STR_CONFIG_SETTING_ADVISORS)); diff --git a/src/settings_type.h b/src/settings_type.h index 41366a7719..4a5df7aba6 100644 --- a/src/settings_type.h +++ b/src/settings_type.h @@ -135,6 +135,8 @@ struct GUISettings { uint32 last_newgrf_count; ///< the numbers of NewGRFs we found during the last scan byte missing_strings_threshold; ///< the number of missing strings before showing the warning uint8 graph_line_thickness; ///< the thickness of the lines in the various graph guis + bool show_train_length_in_details; ///< show train length in vehicle details window top widget + bool show_vehicle_group_in_details; ///< show vehicle group in vehicle details window top widget uint8 osk_activation; ///< Mouse gesture to trigger the OSK. uint16 console_backlog_timeout; ///< the minimum amount of time items should be in the console backlog before they will be removed in ~3 seconds granularity. diff --git a/src/table/settings.ini b/src/table/settings.ini index f314f21e92..43334ebebe 100644 --- a/src/table/settings.ini +++ b/src/table/settings.ini @@ -3133,6 +3133,24 @@ strhelp = STR_CONFIG_SETTING_GRAPH_LINE_THICKNESS_HELPTEXT strval = STR_JUST_COMMA proc = RedrawScreen +[SDTC_BOOL] +var = gui.show_train_length_in_details +flags = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC +def = true +str = STR_CONFIG_SETTING_SHOW_TRAIN_LENGTH_IN_DETAILS +strhelp = STR_CONFIG_SETTING_SHOW_TRAIN_LENGTH_IN_DETAILS_HELPTEXT +proc = RedrawScreen +cat = SC_BASIC + +[SDTC_BOOL] +var = gui.show_vehicle_group_in_details +flags = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC +def = true +str = STR_CONFIG_SETTING_SHOW_VEHICLE_GROUP_IN_DETAILS +strhelp = STR_CONFIG_SETTING_SHOW_VEHICLE_GROUP_IN_DETAILS_HELPTEXT +proc = RedrawScreen +cat = SC_BASIC + ; For the dedicated build we'll enable dates in logs by default. [SDTC_BOOL] ifdef = DEDICATED diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index 4ace090dda..7261a2badb 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -1859,6 +1859,7 @@ static StringID _service_interval_dropdown[] = { struct VehicleDetailsWindow : Window { TrainDetailsWindowTabs tab; ///< For train vehicles: which tab is displayed. Scrollbar *vscroll; + bool vehicle_group_line_shown; /** Initialize a newly created vehicle details window */ VehicleDetailsWindow(WindowDesc *desc, WindowNumber window_number) : Window(desc) @@ -1897,6 +1898,11 @@ struct VehicleDetailsWindow : Window { this->ReInit(); } } + + /* If the presence of the group line changes, the size of the top details widget must change */ + if (this->vehicle_group_line_shown != this->ShouldShowGroupLine(v)) { + this->ReInit(); + } } /** @@ -1920,24 +1926,42 @@ struct VehicleDetailsWindow : Window { return desired_height; } + bool ShouldShowGroupLine(const Vehicle *v) const + { + return (_settings_client.gui.show_vehicle_group_in_details && v->group_id != INVALID_GROUP && v->group_id != DEFAULT_GROUP); + } + virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) { switch (widget) { case WID_VD_TOP_DETAILS: { + const Vehicle *v = Vehicle::Get(this->window_number); Dimension dim = { 0, 0 }; - size->height = WD_FRAMERECT_TOP + 4 * FONT_HEIGHT_NORMAL + WD_FRAMERECT_BOTTOM; + this->vehicle_group_line_shown = ShouldShowGroupLine(v); + size->height = WD_FRAMERECT_TOP + (this->vehicle_group_line_shown ? 5 : 4) * FONT_HEIGHT_NORMAL + WD_FRAMERECT_BOTTOM; - for (uint i = 0; i < 4; i++) SetDParamMaxValue(i, INT16_MAX); + for (uint i = 0; i < 5; i++) SetDParamMaxValue(i, INT16_MAX); static const StringID info_strings[] = { STR_VEHICLE_INFO_MAX_SPEED, STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED, STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED_MAX_TE, - STR_VEHICLE_INFO_PROFIT_THIS_YEAR_LAST_YEAR, STR_VEHICLE_INFO_RELIABILITY_BREAKDOWNS }; for (uint i = 0; i < lengthof(info_strings); i++) { dim = maxdim(dim, GetStringBoundingBox(info_strings[i])); } + if (v->type == VEH_TRAIN && _settings_client.gui.show_train_length_in_details) { + SetDParamMaxValue(0, _settings_game.vehicle.max_train_length * 10); + SetDParam(1, 1); + SetDParam(2, STR_VEHICLE_INFO_PROFIT_THIS_YEAR_LAST_YEAR); + dim = maxdim(dim, GetStringBoundingBox(STR_VEHICLE_INFO_TRAIN_LENGTH)); + } else { + dim = maxdim(dim, GetStringBoundingBox(STR_VEHICLE_INFO_PROFIT_THIS_YEAR_LAST_YEAR)); + } + if (this->vehicle_group_line_shown) { + SetDParam(0, v->group_id); + dim = maxdim(dim, GetStringBoundingBox(STR_VEHICLE_INFO_GROUP)); + } SetDParam(0, STR_VEHICLE_INFO_AGE); dim = maxdim(dim, GetStringBoundingBox(STR_VEHICLE_INFO_AGE_RUNNING_COST_YR)); size->width = dim.width + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT; @@ -2073,15 +2097,35 @@ struct VehicleDetailsWindow : Window { y += FONT_HEIGHT_NORMAL; /* Draw profit */ - SetDParam(0, v->GetDisplayProfitThisYear()); - SetDParam(1, v->GetDisplayProfitLastYear()); - DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_VEHICLE_INFO_PROFIT_THIS_YEAR_LAST_YEAR); + if (v->type == VEH_TRAIN && _settings_client.gui.show_train_length_in_details) { + const GroundVehicleCache *gcache = v->GetGroundVehicleCache(); + SetDParam(0, CeilDiv(gcache->cached_total_length * 10, TILE_SIZE)); + SetDParam(1, 1); + SetDParam(2, STR_VEHICLE_INFO_PROFIT_THIS_YEAR_LAST_YEAR); + SetDParam(3, v->GetDisplayProfitThisYear()); + SetDParam(4, v->GetDisplayProfitLastYear()); + DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_VEHICLE_INFO_TRAIN_LENGTH); + } else { + SetDParam(0, v->GetDisplayProfitThisYear()); + SetDParam(1, v->GetDisplayProfitLastYear()); + DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_VEHICLE_INFO_PROFIT_THIS_YEAR_LAST_YEAR); + } y += FONT_HEIGHT_NORMAL; /* Draw breakdown & reliability */ SetDParam(0, ToPercent16(v->reliability)); SetDParam(1, v->breakdowns_since_last_service); DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_VEHICLE_INFO_RELIABILITY_BREAKDOWNS); + y += FONT_HEIGHT_NORMAL; + + bool should_show_group = this->ShouldShowGroupLine(v); + if (should_show_group) { + SetDParam(0, v->group_id); + DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_VEHICLE_INFO_GROUP); + } + if (this->vehicle_group_line_shown != should_show_group) { + const_cast(this)->ReInit(); + } break; }