diff --git a/src/company_gui.cpp b/src/company_gui.cpp index f15e66ce7c..3c7aa4a67f 100644 --- a/src/company_gui.cpp +++ b/src/company_gui.cpp @@ -53,6 +53,7 @@ /** Company GUI constants. */ static void DoSelectCompanyManagerFace(Window *parent); static void ShowCompanyInfrastructure(CompanyID company); +bool _infrastructure_window_open = false; /** List of revenues. */ static const std::initializer_list _expenses_list_revenue = { @@ -1830,6 +1831,16 @@ struct CompanyInfrastructureWindow : Window RoadTypes roadtypes; ///< Valid roadtypes. uint total_width; ///< String width of the total cost line. + /** + * 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 + { + _infrastructure_window_open = false; + MarkWholeScreenDirty(); + this->Window::Close(); + } CompanyInfrastructureWindow(WindowDesc *desc, WindowNumber window_number) : Window(desc) { @@ -2150,12 +2161,15 @@ static WindowDesc _company_infrastructure_desc(__FILE__, __LINE__, /** * Open the infrastructure window of a company. + * Signal to the viewport to highlight company owned infrastructure * @param company Company to show infrastructure of. */ static void ShowCompanyInfrastructure(CompanyID company) { if (!Company::IsValidID(company)) return; AllocateWindowDescFront(&_company_infrastructure_desc, company); + _infrastructure_window_open = true; + MarkWholeScreenDirty(); } static constexpr NWidgetPart _nested_company_widgets[] = { diff --git a/src/company_gui.h b/src/company_gui.h index f6149b05fb..d2633d74d3 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 bool _infrastructure_window_open; + #endif /* COMPANY_GUI_H */ diff --git a/src/viewport.cpp b/src/viewport.cpp index 0c40926e81..9cb465756e 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 @@ -1036,6 +1038,33 @@ static TileHighlightType GetTileHighlightType(TileIndex t) } } + if (_current_company < MAX_COMPANIES && _infrastructure_window_open) { + /* Edge case of company owned tramway on non-company owned tile */ + if (IsTileType(t, MP_ROAD) && !IsRoadDepot(t) && HasTileRoadType(t, RTT_TRAM)) { + if (IsRoadOwner(t, RTT_TRAM, _current_company)) { + return THT_WHITE; + } + } + + switch (GetTileType(t)) { + case MP_ROAD: + case MP_RAILWAY: + case MP_TUNNELBRIDGE: + case MP_WATER: + { + CommandCost ret = CheckTileOwnership(t); + if (!ret.Failed()) { + return THT_WHITE; + } + break; + } + default: + { + return THT_NONE; + break; + } + } + } return THT_NONE; }