1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2026-01-19 02:12:37 +01:00

Codechange: Use proper widget type and update widgets properly (#14870)

For vehicle window.
This commit is contained in:
Cyprian Klimaszewski
2026-01-08 23:31:00 +01:00
committed by GitHub
parent 52d6a579e5
commit d405e4cb09
5 changed files with 25 additions and 20 deletions

View File

@@ -133,6 +133,7 @@ void SetLocalCompany(CompanyID new_company)
if (switching_company) {
InvalidateWindowClassesData(WC_COMPANY);
InvalidateWindowClassesData(WC_VEHICLE_VIEW);
/* Delete any construction windows... */
CloseConstructionWindows();
}

View File

@@ -212,7 +212,7 @@ uint16_t Order::MapOldOrder() const
*/
void InvalidateVehicleOrder(const Vehicle *v, int data)
{
SetWindowDirty(WC_VEHICLE_VIEW, v->index);
InvalidateWindowData(WC_VEHICLE_VIEW, v->index);
if (data != 0) {
/* Calls SetDirty() too */
@@ -1761,7 +1761,7 @@ void RemoveOrderFromAllVehicles(OrderType type, DestinationID destination, bool
if ((v->type == VEH_AIRCRAFT && v->current_order.IsType(OT_GOTO_DEPOT) && !hangar ? OT_GOTO_STATION : v->current_order.GetType()) == type &&
(!hangar || v->type == VEH_AIRCRAFT) && v->current_order.GetDestination() == destination) {
v->current_order.MakeDummy();
SetWindowDirty(WC_VEHICLE_VIEW, v->index);
InvalidateWindowData(WC_VEHICLE_VIEW, v->index);
}
if (v->orders == nullptr) continue;

View File

@@ -2097,7 +2097,7 @@ CommandCost CmdReverseTrainDirection(DoCommandFlags flags, VehicleID veh_id, boo
front->ConsistChanged(CCF_ARRANGE);
SetWindowDirty(WC_VEHICLE_DEPOT, front->tile);
SetWindowDirty(WC_VEHICLE_DETAILS, front->index);
SetWindowDirty(WC_VEHICLE_VIEW, front->index);
InvalidateWindowData(WC_VEHICLE_VIEW, front->index);
SetWindowClassesDirty(WC_TRAINS_LIST);
}
} else {
@@ -2119,7 +2119,7 @@ CommandCost CmdReverseTrainDirection(DoCommandFlags flags, VehicleID veh_id, boo
/* We cancel any 'skip signal at dangers' here */
v->force_proceed = TFP_NONE;
SetWindowDirty(WC_VEHICLE_VIEW, v->index);
InvalidateWindowData(WC_VEHICLE_VIEW, v->index);
if (_settings_game.vehicle.train_acceleration_model != AM_ORIGINAL && v->cur_speed != 0) {
v->flags.Flip(VehicleRailFlag::Reversing);
@@ -2177,7 +2177,7 @@ CommandCost CmdForceTrainProceed(DoCommandFlags flags, VehicleID veh_id)
if (flags.Test(DoCommandFlag::Execute)) {
t->force_proceed = DetermineNextTrainForceProceeding(t);
SetWindowDirty(WC_VEHICLE_VIEW, t->index);
InvalidateWindowData(WC_VEHICLE_VIEW, t->index);
/* Unbunching data is no longer valid. */
t->ResetDepotUnbunching();
@@ -3049,7 +3049,7 @@ static void TrainEnterStation(Train *v, StationID station)
}
v->force_proceed = TFP_NONE;
SetWindowDirty(WC_VEHICLE_VIEW, v->index);
InvalidateWindowData(WC_VEHICLE_VIEW, v->index);
v->BeginLoading();
@@ -3363,7 +3363,7 @@ bool TrainController(Train *v, Vehicle *nomove, bool reverse)
/* However, we do not want to be stopped by PBS signals
* entered via the back. */
v->force_proceed = (v->force_proceed == TFP_SIGNAL) ? TFP_STUCK : TFP_NONE;
SetWindowDirty(WC_VEHICLE_VIEW, v->index);
InvalidateWindowData(WC_VEHICLE_VIEW, v->index);
}
}
@@ -4034,7 +4034,7 @@ static bool TrainLocoHandler(Train *v, bool mode)
if (v->cur_speed == 0 && v->vehstatus.Test(VehState::Stopped)) {
/* If we manually stopped, we're not force-proceeding anymore. */
v->force_proceed = TFP_NONE;
SetWindowDirty(WC_VEHICLE_VIEW, v->index);
InvalidateWindowData(WC_VEHICLE_VIEW, v->index);
}
int adv_spd = v->GetAdvanceDistance();

View File

@@ -1574,8 +1574,6 @@ void VehicleEnterDepot(Vehicle *v)
break;
default: NOT_REACHED();
}
SetWindowDirty(WC_VEHICLE_VIEW, v->index);
if (v->type != VEH_TRAIN) {
/* Trains update the vehicle list when the first unit enters the depot and calls VehicleEnterDepot() when the last unit enters.
* We only increase the number of vehicles when the first one enters, so we will not need to search for more vehicles in the depot */
@@ -1598,8 +1596,6 @@ void VehicleEnterDepot(Vehicle *v)
InvalidateWindowData(WC_VEHICLE_VIEW, v->index);
if (v->current_order.IsType(OT_GOTO_DEPOT)) {
SetWindowDirty(WC_VEHICLE_VIEW, v->index);
const Order *real_order = v->GetOrder(v->cur_real_order_index);
/* Test whether we are heading for this depot. If not, do nothing.
@@ -2538,7 +2534,7 @@ void Vehicle::LeaveUnbunchingDepot()
if (u->vehstatus.Any({VehState::Stopped, VehState::Crashed})) continue;
u->depot_unbunching_next_departure = next_departure;
SetWindowDirty(WC_VEHICLE_VIEW, u->index);
InvalidateWindowData(WC_VEHICLE_VIEW, u->index);
}
}

View File

@@ -2844,7 +2844,7 @@ static constexpr std::initializer_list<NWidgetPart> _nested_vehicle_view_widgets
EndContainer(),
/* For trains only, 'ignore signal' button. */
NWidget(NWID_SELECTION, INVALID_COLOUR, WID_VV_FORCE_PROCEED_SEL),
NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_VV_FORCE_PROCEED), SetMinimalSize(18, 18),
NWidget(WWT_IMGBTN, COLOUR_GREY, WID_VV_FORCE_PROCEED), SetMinimalSize(18, 18),
SetSpriteTip(SPR_IGNORE_SIGNALS, STR_VEHICLE_VIEW_TRAIN_IGNORE_SIGNAL_TOOLTIP),
EndContainer(),
NWidget(NWID_SELECTION, INVALID_COLOUR, WID_VV_SELECT_REFIT_TURN),
@@ -3047,7 +3047,8 @@ public:
this->GetWidget<NWidgetCore>(WID_VV_SHOW_DETAILS)->SetToolTip(STR_VEHICLE_VIEW_TRAIN_SHOW_DETAILS_TOOLTIP + v->type);
this->GetWidget<NWidgetCore>(WID_VV_CLONE)->SetToolTip(STR_VEHICLE_VIEW_CLONE_TRAIN_INFO + v->type);
this->UpdateButtonStatus();
this->UpdatePlanes();
this->UpdateButtons();
}
void Close([[maybe_unused]] int data = 0) override
@@ -3081,7 +3082,8 @@ public:
}
}
void OnPaint() override
/** Update buttons state to match shown vehicle. */
void UpdateButtons()
{
const Vehicle *v = Vehicle::Get(this->window_number);
bool is_localcompany = v->owner == _local_company;
@@ -3102,6 +3104,11 @@ public:
}
this->SetWidgetDisabledState(WID_VV_ORDER_LOCATION, v->current_order.GetLocation(v) == INVALID_TILE);
}
void OnPaint() override
{
const Vehicle *v = Vehicle::Get(this->window_number);
const Window *mainwindow = GetMainWindow();
if (mainwindow->viewport->follow_vehicle == v->index) {
@@ -3351,7 +3358,8 @@ public:
}
}
void UpdateButtonStatus()
/** Selects apropriate plane for current state of the shown vehicle. */
void UpdatePlanes()
{
const Vehicle *v = Vehicle::Get(this->window_number);
bool veh_stopped = v->IsStoppedInDepot();
@@ -3363,7 +3371,6 @@ public:
NWidgetStacked *nwi = this->GetWidget<NWidgetStacked>(WID_VV_SELECT_DEPOT_CLONE); // Selection widget 'send to depot' / 'clone'.
if (nwi->shown_plane + SEL_DC_BASEPLANE != plane) {
this->SelectPlane(plane);
this->SetWidgetDirty(WID_VV_SELECT_DEPOT_CLONE);
}
/* The same system applies to widget WID_VV_REFIT_VEH and VVW_WIDGET_TURN_AROUND.*/
if (v->IsGroundVehicle()) {
@@ -3371,7 +3378,6 @@ public:
nwi = this->GetWidget<NWidgetStacked>(WID_VV_SELECT_REFIT_TURN);
if (nwi->shown_plane + SEL_RT_BASEPLANE != plane) {
this->SelectPlane(plane);
this->SetWidgetDirty(WID_VV_SELECT_REFIT_TURN);
}
}
}
@@ -3389,7 +3395,9 @@ public:
return;
}
this->UpdateButtonStatus();
this->UpdatePlanes();
this->UpdateButtons();
this->SetDirty();
}
bool IsNewGRFInspectable() const override