mirror of https://github.com/OpenTTD/OpenTTD.git
Codechange: Added UI, simplified functionality
This commit is contained in:
parent
fb44f5a074
commit
945561ada8
|
@ -53,7 +53,7 @@
|
||||||
/** Company GUI constants. */
|
/** Company GUI constants. */
|
||||||
static void DoSelectCompanyManagerFace(Window *parent);
|
static void DoSelectCompanyManagerFace(Window *parent);
|
||||||
static void ShowCompanyInfrastructure(CompanyID company);
|
static void ShowCompanyInfrastructure(CompanyID company);
|
||||||
std::vector<CompanyID> _viewport_infrastructure_window_order;
|
CompanyID _viewport_company_to_highlight_infrastructure = INVALID_OWNER;
|
||||||
|
|
||||||
/** List of revenues. */
|
/** List of revenues. */
|
||||||
static const std::initializer_list<ExpensesType> _expenses_list_revenue = {
|
static const std::initializer_list<ExpensesType> _expenses_list_revenue = {
|
||||||
|
@ -1818,6 +1818,7 @@ 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_DESC), SetFill(1, 0),
|
||||||
NWidget(WWT_EMPTY, COLOUR_GREY, WID_CI_TOTAL), SetFill(0, 1),
|
NWidget(WWT_EMPTY, COLOUR_GREY, 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(),
|
EndContainer(),
|
||||||
EndContainer(),
|
EndContainer(),
|
||||||
};
|
};
|
||||||
|
@ -1838,14 +1839,11 @@ struct CompanyInfrastructureWindow : Window
|
||||||
*/
|
*/
|
||||||
void Close([[maybe_unused]] int data) override
|
void Close([[maybe_unused]] int data) override
|
||||||
{
|
{
|
||||||
auto to_remove_from_order = std::find(_viewport_infrastructure_window_order.begin(), _viewport_infrastructure_window_order.end(), (CompanyID)this->window_number);
|
|
||||||
|
|
||||||
/* Cautious error checking */
|
|
||||||
if (to_remove_from_order != _viewport_infrastructure_window_order.end()) {
|
|
||||||
_viewport_infrastructure_window_order.erase(to_remove_from_order);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if(_viewport_company_to_highlight_infrastructure == (CompanyID)this->window_number){
|
||||||
|
_viewport_company_to_highlight_infrastructure = INVALID_OWNER;
|
||||||
MarkWholeScreenDirty();
|
MarkWholeScreenDirty();
|
||||||
|
}
|
||||||
this->Window::Close();
|
this->Window::Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2045,7 +2043,11 @@ struct CompanyInfrastructureWindow : Window
|
||||||
TC_FROMSTRING, SA_RIGHT);
|
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
|
void DrawWidget(const Rect &r, WidgetID widget) const override
|
||||||
{
|
{
|
||||||
const Company *c = Company::Get((CompanyID)this->window_number);
|
const Company *c = Company::Get((CompanyID)this->window_number);
|
||||||
|
@ -2144,6 +2146,22 @@ struct CompanyInfrastructureWindow : Window
|
||||||
break;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Some data on this window has become invalid.
|
* Some data on this window has become invalid.
|
||||||
|
@ -2176,15 +2194,6 @@ static void ShowCompanyInfrastructure(CompanyID company)
|
||||||
if (!Company::IsValidID(company)) return;
|
if (!Company::IsValidID(company)) return;
|
||||||
AllocateWindowDescFront<CompanyInfrastructureWindow>(&_company_infrastructure_desc, company);
|
AllocateWindowDescFront<CompanyInfrastructureWindow>(&_company_infrastructure_desc, company);
|
||||||
|
|
||||||
/* Check if already open then move up in the order */
|
|
||||||
auto to_moveup_in_order = std::find(_viewport_infrastructure_window_order.begin(), _viewport_infrastructure_window_order.end(), company);
|
|
||||||
|
|
||||||
/* Cautious error checking */
|
|
||||||
if (to_moveup_in_order != _viewport_infrastructure_window_order.end()) {
|
|
||||||
_viewport_infrastructure_window_order.erase(to_moveup_in_order);
|
|
||||||
}
|
|
||||||
|
|
||||||
_viewport_infrastructure_window_order.push_back(company);
|
|
||||||
MarkWholeScreenDirty();
|
MarkWholeScreenDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,6 @@ void InvalidateCompanyWindows(const Company *c);
|
||||||
void CloseCompanyWindows(CompanyID company);
|
void CloseCompanyWindows(CompanyID company);
|
||||||
void DirtyCompanyInfrastructureWindows(CompanyID company);
|
void DirtyCompanyInfrastructureWindows(CompanyID company);
|
||||||
|
|
||||||
extern std::vector<CompanyID> _viewport_infrastructure_window_order;
|
extern CompanyID _viewport_company_to_highlight_infrastructure;
|
||||||
|
|
||||||
#endif /* COMPANY_GUI_H */
|
#endif /* COMPANY_GUI_H */
|
||||||
|
|
|
@ -3933,6 +3933,8 @@ STR_COMPANY_INFRASTRUCTURE_VIEW_STATIONS :{WHITE}Station
|
||||||
STR_COMPANY_INFRASTRUCTURE_VIEW_AIRPORTS :{WHITE}Airports
|
STR_COMPANY_INFRASTRUCTURE_VIEW_AIRPORTS :{WHITE}Airports
|
||||||
STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL_YEAR :{WHITE}{CURRENCY_LONG}/year
|
STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL_YEAR :{WHITE}{CURRENCY_LONG}/year
|
||||||
STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL_PERIOD :{WHITE}{CURRENCY_LONG}/period
|
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
|
# Industry directory
|
||||||
STR_INDUSTRY_DIRECTORY_CAPTION :{WHITE}Industries
|
STR_INDUSTRY_DIRECTORY_CAPTION :{WHITE}Industries
|
||||||
|
|
|
@ -3930,6 +3930,8 @@ STR_COMPANY_INFRASTRUCTURE_VIEW_STATIONS :{WHITE}Station
|
||||||
STR_COMPANY_INFRASTRUCTURE_VIEW_AIRPORTS :{WHITE}Airports
|
STR_COMPANY_INFRASTRUCTURE_VIEW_AIRPORTS :{WHITE}Airports
|
||||||
STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL_YEAR :{WHITE}{CURRENCY_LONG}/year
|
STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL_YEAR :{WHITE}{CURRENCY_LONG}/year
|
||||||
STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL_PERIOD :{WHITE}{CURRENCY_LONG}/period
|
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
|
# Industry directory
|
||||||
STR_INDUSTRY_DIRECTORY_CAPTION :{WHITE}Industries
|
STR_INDUSTRY_DIRECTORY_CAPTION :{WHITE}Industries
|
||||||
|
|
|
@ -1039,19 +1039,19 @@ static TileHighlightType GetTileHighlightType(TileIndex t)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Highlight infrastructure owned by the company with the most recently currently opened infrastructure window */
|
/* Highlight infrastructure owned by the company with the most recently currently opened infrastructure window */
|
||||||
if (!_viewport_infrastructure_window_order.empty()) {
|
if (_viewport_company_to_highlight_infrastructure != INVALID_OWNER) {
|
||||||
switch (GetTileType(t)) {
|
switch (GetTileType(t)) {
|
||||||
case MP_ROAD:
|
case MP_ROAD:
|
||||||
/* Edge case of company owned tramway on non-company owned road/rail tile */
|
/* Edge case of company owned tramway on non-company owned road/rail tile */
|
||||||
if (!IsRoadDepot(t) && HasTileRoadType(t, RTT_TRAM)) {
|
if (!IsRoadDepot(t) && HasTileRoadType(t, RTT_TRAM)) {
|
||||||
if (IsRoadOwner(t, RTT_TRAM, _viewport_infrastructure_window_order.back())) {
|
if (IsRoadOwner(t, RTT_TRAM, _viewport_company_to_highlight_infrastructure)) {
|
||||||
return THT_WHITE;
|
return THT_WHITE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Edge case of company owned road on non-company owned rail tile */
|
/* Edge case of company owned road on non-company owned rail tile */
|
||||||
if (!IsRoadDepot(t) && HasTileRoadType(t, RTT_ROAD)) {
|
if (!IsRoadDepot(t) && HasTileRoadType(t, RTT_ROAD)) {
|
||||||
if (IsRoadOwner(t, RTT_ROAD, _viewport_infrastructure_window_order.back())) {
|
if (IsRoadOwner(t, RTT_ROAD, _viewport_company_to_highlight_infrastructure)){
|
||||||
return THT_WHITE;
|
return THT_WHITE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1059,7 +1059,7 @@ static TileHighlightType GetTileHighlightType(TileIndex t)
|
||||||
case MP_RAILWAY:
|
case MP_RAILWAY:
|
||||||
case MP_TUNNELBRIDGE:
|
case MP_TUNNELBRIDGE:
|
||||||
case MP_WATER:
|
case MP_WATER:
|
||||||
if (GetTileOwner(t) == _viewport_infrastructure_window_order.back()) {
|
if (GetTileOwner(t) == _viewport_company_to_highlight_infrastructure) {
|
||||||
return THT_WHITE;
|
return THT_WHITE;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -184,6 +184,7 @@ enum CompanyInfrastructureWidgets : WidgetID {
|
||||||
WID_CI_STATION_COUNT, ///< Count of station.
|
WID_CI_STATION_COUNT, ///< Count of station.
|
||||||
WID_CI_TOTAL_DESC, ///< Description of total.
|
WID_CI_TOTAL_DESC, ///< Description of total.
|
||||||
WID_CI_TOTAL, ///< Count of total.
|
WID_CI_TOTAL, ///< Count of total.
|
||||||
|
WID_CI_HIGHLIGHT_INFRASTRUCTURE,
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Widgets of the #BuyCompanyWindow class. */
|
/** Widgets of the #BuyCompanyWindow class. */
|
||||||
|
|
Loading…
Reference in New Issue