diff --git a/src/company_gui.cpp b/src/company_gui.cpp index 3e7aecfac0..19739bf922 100644 --- a/src/company_gui.cpp +++ b/src/company_gui.cpp @@ -58,6 +58,7 @@ /** Company GUI constants. */ static void DoSelectCompanyManagerFace(Window *parent); static void ShowCompanyInfrastructure(CompanyID company); +CompanyID _viewport_company_to_highlight_infrastructure = INVALID_OWNER; /** List of revenues. */ static const std::initializer_list _expenses_list_revenue = { @@ -1758,6 +1759,7 @@ static constexpr NWidgetPart _nested_company_infrastructure_widgets[] = { NWidget(WWT_EMPTY, INVALID_COLOUR, WID_CI_TOTAL), SetFill(0, 1), EndContainer(), EndContainer(), + NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_CI_HIGHLIGHT_INFRASTRUCTURE), SetFill(1, 0), SetDataTip(STR_COMPANY_INFRASTRUCTURE_VIEW_HIGHLIGHT_INFRASTRUCTURE, STR_COMPANY_INFRASTRUCTURE_VIEW_HIGHLIGHT_INFRASTRUCTURE_TOOLTIP), EndContainer(), }; @@ -1771,7 +1773,21 @@ struct CompanyInfrastructureWindow : Window uint total_width = 0; ///< String width of the total cost line. - CompanyInfrastructureWindow(WindowDesc &desc, WindowNumber window_number) : Window(desc) + /** + * Hide the window and all its child windows, and mark them for a later deletion. + * Stop white highlight of company owned infrastructure + */ + void Close([[maybe_unused]] int data) override + { + /* Clear highlights if the infrastructure window is closed */ + if (_viewport_company_to_highlight_infrastructure == (CompanyID)this->window_number) { + _viewport_company_to_highlight_infrastructure = INVALID_OWNER; + MarkWholeScreenDirty(); + } + this->Window::Close(); + } + + CompanyInfrastructureWindow(WindowDesc *desc, WindowNumber window_number) : Window(desc) { this->UpdateRailRoadTypes(); @@ -1969,6 +1985,12 @@ struct CompanyInfrastructureWindow : Window } } + void OnPaint() override + { + this->SetWidgetLoweredState(WID_CI_HIGHLIGHT_INFRASTRUCTURE, _viewport_company_to_highlight_infrastructure == (CompanyID)this->window_number); + this->DrawWidgets(); + } + void DrawWidget(const Rect &r, WidgetID widget) const override { const Company *c = Company::Get(this->window_number); @@ -2067,6 +2089,23 @@ struct CompanyInfrastructureWindow : Window } } + void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override + { + if (widget != WID_CI_HIGHLIGHT_INFRASTRUCTURE) return; + + /* Toggle between highlight and clear */ + CompanyID window_company_id = (CompanyID)this->window_number; + if(_viewport_company_to_highlight_infrastructure != window_company_id) { + /* highlight tiles of this company */ + _viewport_company_to_highlight_infrastructure = window_company_id; + MarkWholeScreenDirty(); + } else { + /* Clear tile highlights */ + _viewport_company_to_highlight_infrastructure = INVALID_OWNER; + MarkWholeScreenDirty(); + } + } + /** * Some data on this window has become invalid. * @param data Information about the changed data. diff --git a/src/company_gui.h b/src/company_gui.h index f6149b05fb..94e59c5fb0 100644 --- a/src/company_gui.h +++ b/src/company_gui.h @@ -26,4 +26,6 @@ void InvalidateCompanyWindows(const Company *c); void CloseCompanyWindows(CompanyID company); void DirtyCompanyInfrastructureWindows(CompanyID company); + extern CompanyID _viewport_company_to_highlight_infrastructure; + #endif /* COMPANY_GUI_H */ diff --git a/src/lang/english.txt b/src/lang/english.txt index 811c38810f..9e04eb0264 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -4005,6 +4005,8 @@ STR_COMPANY_INFRASTRUCTURE_VIEW_STATIONS :{WHITE}Station STR_COMPANY_INFRASTRUCTURE_VIEW_AIRPORTS :{WHITE}Airports STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL_YEAR :{WHITE}{CURRENCY_LONG}/year STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL_PERIOD :{WHITE}{CURRENCY_LONG}/period +STR_COMPANY_INFRASTRUCTURE_VIEW_HIGHLIGHT_INFRASTRUCTURE :{BLACK}Highlight infrastructure +STR_COMPANY_INFRASTRUCTURE_VIEW_HIGHLIGHT_INFRASTRUCTURE_TOOLTIP:{BLACK}Highlight all infrastructure tiles owned by this company # Industry directory STR_INDUSTRY_DIRECTORY_CAPTION :{WHITE}Industries ({COMMA} of {COMMA}) diff --git a/src/viewport.cpp b/src/viewport.cpp index 7950b7d4a2..abf46f5c67 100644 --- a/src/viewport.cpp +++ b/src/viewport.cpp @@ -90,6 +90,8 @@ #include "network/network_func.h" #include "framerate_type.h" #include "viewport_cmd.h" +#include "company_gui.h" +#include "road_map.h" #include #include @@ -1040,6 +1042,39 @@ static TileHighlightType GetTileHighlightType(TileIndex t) } } + /* Highlight infrastructure of selected company */ + if (_viewport_company_to_highlight_infrastructure != INVALID_OWNER) { + switch (GetTileType(t)) { + case MP_ROAD: + /* Edge case of company owned tramway on non-company owned road/rail tile */ + if (!IsRoadDepot(t) && HasTileRoadType(t, RTT_TRAM)) { + if (IsRoadOwner(t, RTT_TRAM, _viewport_company_to_highlight_infrastructure)) { + return THT_WHITE; + } + } + + /* Edge case of company owned road on non-company owned rail tile */ + if (!IsRoadDepot(t) && HasTileRoadType(t, RTT_ROAD)) { + if (IsRoadOwner(t, RTT_ROAD, _viewport_company_to_highlight_infrastructure)){ + return THT_WHITE; + } + } + [[fallthrough]]; + case MP_RAILWAY: + case MP_TUNNELBRIDGE: + case MP_WATER: + case MP_STATION: + case MP_OBJECT: + if (GetTileOwner(t) == _viewport_company_to_highlight_infrastructure) { + return THT_WHITE; + } + break; + default: + return THT_NONE; + break; + + } + } return THT_NONE; } diff --git a/src/widgets/company_widget.h b/src/widgets/company_widget.h index 452632dccb..ab072950c7 100644 --- a/src/widgets/company_widget.h +++ b/src/widgets/company_widget.h @@ -182,6 +182,7 @@ enum CompanyInfrastructureWidgets : WidgetID { WID_CI_STATION_COUNT, ///< Count of station. WID_CI_TOTAL_DESC, ///< Description of total. WID_CI_TOTAL, ///< Count of total. + WID_CI_HIGHLIGHT_INFRASTRUCTURE, ///< Button to highlight infrastructure of this company. }; /** Widgets of the #BuyCompanyWindow class. */