mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Keep track of all open infrastructure windows in a vector highlight the infrastructure of the most recently opened company. Changed code style base on comments.
parent
452f25a5dd
commit
804557721c
|
@ -53,7 +53,7 @@
|
|||
/** Company GUI constants. */
|
||||
static void DoSelectCompanyManagerFace(Window *parent);
|
||||
static void ShowCompanyInfrastructure(CompanyID company);
|
||||
bool _infrastructure_window_open = false;
|
||||
std::vector<CompanyID> _viewport_infrastructure_window_order;
|
||||
|
||||
/** List of revenues. */
|
||||
static const std::initializer_list<ExpensesType> _expenses_list_revenue = {
|
||||
|
@ -1831,13 +1831,20 @@ 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;
|
||||
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);
|
||||
}
|
||||
|
||||
MarkWholeScreenDirty();
|
||||
this->Window::Close();
|
||||
}
|
||||
|
@ -2168,7 +2175,7 @@ static void ShowCompanyInfrastructure(CompanyID company)
|
|||
{
|
||||
if (!Company::IsValidID(company)) return;
|
||||
AllocateWindowDescFront<CompanyInfrastructureWindow>(&_company_infrastructure_desc, company);
|
||||
_infrastructure_window_open = true;
|
||||
_viewport_infrastructure_window_order.push_back(company);
|
||||
MarkWholeScreenDirty();
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,6 @@ void InvalidateCompanyWindows(const Company *c);
|
|||
void CloseCompanyWindows(CompanyID company);
|
||||
void DirtyCompanyInfrastructureWindows(CompanyID company);
|
||||
|
||||
extern bool _infrastructure_window_open;
|
||||
extern std::vector<CompanyID> _viewport_infrastructure_window_order;
|
||||
|
||||
#endif /* COMPANY_GUI_H */
|
||||
|
|
|
@ -1038,31 +1038,28 @@ 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;
|
||||
}
|
||||
}
|
||||
|
||||
/* Highlight infrastructure owned by the company with the most recently currently opened infrastructure window */
|
||||
if (!_viewport_infrastructure_window_order.empty()) {
|
||||
switch (GetTileType(t)) {
|
||||
case MP_ROAD:
|
||||
/* 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, _viewport_infrastructure_window_order.back())) {
|
||||
return THT_WHITE;
|
||||
}
|
||||
}
|
||||
[[fallthrough]];
|
||||
case MP_RAILWAY:
|
||||
case MP_TUNNELBRIDGE:
|
||||
case MP_WATER:
|
||||
{
|
||||
CommandCost ret = CheckTileOwnership(t);
|
||||
if (!ret.Failed()) {
|
||||
if (GetTileOwner(t) == _viewport_infrastructure_window_order.back()) {
|
||||
return THT_WHITE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
return THT_NONE;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return THT_NONE;
|
||||
|
|
Loading…
Reference in New Issue