From 7530529653949a6f1888b162ed852137a8987799 Mon Sep 17 00:00:00 2001 From: Anthony Lazar Date: Mon, 1 Jul 2024 00:34:03 -0400 Subject: [PATCH] Codechange: Added Comments, fixed code style, added highlights to HQ and owned lands (MP_objects) and Airports and stations (MP_stations) --- src/company_gui.cpp | 36 ++++++++++++++++++------------------ src/lang/english.txt | 2 +- src/lang/english_US.txt | 2 -- src/viewport.cpp | 4 +++- src/widgets/company_widget.h | 2 +- 5 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/company_gui.cpp b/src/company_gui.cpp index 474d08c42d..6680c3a0b5 100644 --- a/src/company_gui.cpp +++ b/src/company_gui.cpp @@ -1818,8 +1818,8 @@ static constexpr NWidgetPart _nested_company_infrastructure_widgets[] = { NWidget(WWT_EMPTY, COLOUR_GREY, WID_CI_TOTAL_DESC), SetFill(1, 0), NWidget(WWT_EMPTY, COLOUR_GREY, WID_CI_TOTAL), SetFill(0, 1), 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(), + 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(), }; @@ -1839,8 +1839,8 @@ struct CompanyInfrastructureWindow : Window */ void Close([[maybe_unused]] int data) override { - - if(_viewport_company_to_highlight_infrastructure == (CompanyID)this->window_number){ + /* 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(); } @@ -2043,11 +2043,13 @@ struct CompanyInfrastructureWindow : Window TC_FROMSTRING, SA_RIGHT); } } + 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((CompanyID)this->window_number); @@ -2146,20 +2148,21 @@ struct CompanyInfrastructureWindow : Window break; } } + void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override { - switch (widget) { - case WID_CI_HIGHLIGHT_INFRASTRUCTURE: - CompanyID window_company_id = (CompanyID)this->window_number; - if(_viewport_company_to_highlight_infrastructure != window_company_id) { - _viewport_company_to_highlight_infrastructure = window_company_id; - MarkWholeScreenDirty(); - } - else { - _viewport_company_to_highlight_infrastructure = INVALID_OWNER; - MarkWholeScreenDirty(); - } - break; + 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(); } } @@ -2186,15 +2189,12 @@ 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); - - MarkWholeScreenDirty(); } static constexpr NWidgetPart _nested_company_widgets[] = { diff --git a/src/lang/english.txt b/src/lang/english.txt index 6333bd43a2..8ff92f7f97 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -3934,7 +3934,7 @@ 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 the company currently owns +STR_COMPANY_INFRASTRUCTURE_VIEW_HIGHLIGHT_INFRASTRUCTURE_TOOLTIP:{BLACK}Highlight all infrastructure tiles owned by this company # Industry directory STR_INDUSTRY_DIRECTORY_CAPTION :{WHITE}Industries diff --git a/src/lang/english_US.txt b/src/lang/english_US.txt index 9d314d0e20..73fac4bfc2 100644 --- a/src/lang/english_US.txt +++ b/src/lang/english_US.txt @@ -3930,8 +3930,6 @@ 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 the company currently owns # Industry directory STR_INDUSTRY_DIRECTORY_CAPTION :{WHITE}Industries diff --git a/src/viewport.cpp b/src/viewport.cpp index bd5d266666..01d4bcdfa5 100644 --- a/src/viewport.cpp +++ b/src/viewport.cpp @@ -1038,7 +1038,7 @@ static TileHighlightType GetTileHighlightType(TileIndex t) } } - /* Highlight infrastructure owned by the company with the most recently currently opened infrastructure window */ + /* Highlight infrastructure of selected company */ if (_viewport_company_to_highlight_infrastructure != INVALID_OWNER) { switch (GetTileType(t)) { case MP_ROAD: @@ -1059,6 +1059,8 @@ static TileHighlightType GetTileHighlightType(TileIndex t) 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; } diff --git a/src/widgets/company_widget.h b/src/widgets/company_widget.h index 9c92d53429..faed62f06c 100644 --- a/src/widgets/company_widget.h +++ b/src/widgets/company_widget.h @@ -184,7 +184,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, + WID_CI_HIGHLIGHT_INFRASTRUCTURE, ///< Button to highlight infrastructure of this company. }; /** Widgets of the #BuyCompanyWindow class. */