mirror of https://github.com/OpenTTD/OpenTTD.git
Fix #10819, Fix #10811: GetVehicleFromDepotWndPt used widget- instead of window-relative positions. (#10820)
Pass window-relative positions instead, and adjust for relative positions where needed within the function itself. This simplifies calling code.
This commit is contained in:
parent
07473bfd2e
commit
385b25df63
|
@ -445,6 +445,8 @@ struct DepotWindow : Window {
|
||||||
DepotGUIAction GetVehicleFromDepotWndPt(int x, int y, const Vehicle **veh, GetDepotVehiclePtData *d) const
|
DepotGUIAction GetVehicleFromDepotWndPt(int x, int y, const Vehicle **veh, GetDepotVehiclePtData *d) const
|
||||||
{
|
{
|
||||||
const NWidgetCore *matrix_widget = this->GetWidget<NWidgetCore>(WID_D_MATRIX);
|
const NWidgetCore *matrix_widget = this->GetWidget<NWidgetCore>(WID_D_MATRIX);
|
||||||
|
/* Make X relative to widget. Y is left alone for GetScrolledRowFromWidget(). */
|
||||||
|
x -= matrix_widget->pos_x;
|
||||||
/* In case of RTL the widgets are swapped as a whole */
|
/* In case of RTL the widgets are swapped as a whole */
|
||||||
if (_current_text_dir == TD_RTL) x = matrix_widget->current_x - x;
|
if (_current_text_dir == TD_RTL) x = matrix_widget->current_x - x;
|
||||||
|
|
||||||
|
@ -456,7 +458,7 @@ struct DepotWindow : Window {
|
||||||
xm = x % this->resize.step_width;
|
xm = x % this->resize.step_width;
|
||||||
if (xt >= this->num_columns) return MODE_ERROR;
|
if (xt >= this->num_columns) return MODE_ERROR;
|
||||||
}
|
}
|
||||||
ym = y % this->resize.step_height;
|
ym = (y - matrix_widget->pos_y) % this->resize.step_height;
|
||||||
|
|
||||||
int row = this->vscroll->GetScrolledRowFromWidget(y, this, WID_D_MATRIX);
|
int row = this->vscroll->GetScrolledRowFromWidget(y, this, WID_D_MATRIX);
|
||||||
if (row == INT_MAX) return MODE_ERROR;
|
if (row == INT_MAX) return MODE_ERROR;
|
||||||
|
@ -762,11 +764,9 @@ struct DepotWindow : Window {
|
||||||
void OnClick(Point pt, int widget, int click_count) override
|
void OnClick(Point pt, int widget, int click_count) override
|
||||||
{
|
{
|
||||||
switch (widget) {
|
switch (widget) {
|
||||||
case WID_D_MATRIX: { // List
|
case WID_D_MATRIX: // List
|
||||||
NWidgetBase *nwi = this->GetWidget<NWidgetBase>(WID_D_MATRIX);
|
this->DepotClick(pt.x, pt.y);
|
||||||
this->DepotClick(pt.x - nwi->pos_x, pt.y - nwi->pos_y);
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
case WID_D_BUILD: // Build vehicle
|
case WID_D_BUILD: // Build vehicle
|
||||||
ResetObjectToPlace();
|
ResetObjectToPlace();
|
||||||
|
@ -849,8 +849,7 @@ struct DepotWindow : Window {
|
||||||
|
|
||||||
GetDepotVehiclePtData gdvp = { nullptr, nullptr };
|
GetDepotVehiclePtData gdvp = { nullptr, nullptr };
|
||||||
const Vehicle *v = nullptr;
|
const Vehicle *v = nullptr;
|
||||||
NWidgetBase *nwi = this->GetWidget<NWidgetBase>(WID_D_MATRIX);
|
DepotGUIAction mode = this->GetVehicleFromDepotWndPt(pt.x, pt.y, &v, &gdvp);
|
||||||
DepotGUIAction mode = this->GetVehicleFromDepotWndPt(pt.x - nwi->pos_x, pt.y - nwi->pos_y, &v, &gdvp);
|
|
||||||
|
|
||||||
if (this->type == VEH_TRAIN) v = gdvp.wagon;
|
if (this->type == VEH_TRAIN) v = gdvp.wagon;
|
||||||
|
|
||||||
|
@ -1005,11 +1004,10 @@ struct DepotWindow : Window {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
NWidgetBase *matrix = this->GetWidget<NWidgetBase>(widget);
|
|
||||||
const Vehicle *v = nullptr;
|
const Vehicle *v = nullptr;
|
||||||
GetDepotVehiclePtData gdvp = {nullptr, nullptr};
|
GetDepotVehiclePtData gdvp = {nullptr, nullptr};
|
||||||
|
|
||||||
if (this->GetVehicleFromDepotWndPt(pt.x - matrix->pos_x, pt.y - matrix->pos_y, &v, &gdvp) != MODE_DRAG_VEHICLE) return;
|
if (this->GetVehicleFromDepotWndPt(pt.x, pt.y, &v, &gdvp) != MODE_DRAG_VEHICLE) return;
|
||||||
|
|
||||||
VehicleID new_vehicle_over = INVALID_VEHICLE;
|
VehicleID new_vehicle_over = INVALID_VEHICLE;
|
||||||
if (gdvp.head != nullptr) {
|
if (gdvp.head != nullptr) {
|
||||||
|
@ -1042,11 +1040,10 @@ struct DepotWindow : Window {
|
||||||
this->sel = INVALID_VEHICLE;
|
this->sel = INVALID_VEHICLE;
|
||||||
this->SetDirty();
|
this->SetDirty();
|
||||||
|
|
||||||
NWidgetBase *nwi = this->GetWidget<NWidgetBase>(WID_D_MATRIX);
|
|
||||||
if (this->type == VEH_TRAIN) {
|
if (this->type == VEH_TRAIN) {
|
||||||
GetDepotVehiclePtData gdvp = { nullptr, nullptr };
|
GetDepotVehiclePtData gdvp = { nullptr, nullptr };
|
||||||
|
|
||||||
if (this->GetVehicleFromDepotWndPt(pt.x - nwi->pos_x, pt.y - nwi->pos_y, &v, &gdvp) == MODE_DRAG_VEHICLE && sel != INVALID_VEHICLE) {
|
if (this->GetVehicleFromDepotWndPt(pt.x, pt.y, &v, &gdvp) == MODE_DRAG_VEHICLE && sel != INVALID_VEHICLE) {
|
||||||
if (gdvp.wagon != nullptr && gdvp.wagon->index == sel && _ctrl_pressed) {
|
if (gdvp.wagon != nullptr && gdvp.wagon->index == sel && _ctrl_pressed) {
|
||||||
Command<CMD_REVERSE_TRAIN_DIRECTION>::Post(STR_ERROR_CAN_T_REVERSE_DIRECTION_RAIL_VEHICLE, Vehicle::Get(sel)->tile, Vehicle::Get(sel)->index, true);
|
Command<CMD_REVERSE_TRAIN_DIRECTION>::Post(STR_ERROR_CAN_T_REVERSE_DIRECTION_RAIL_VEHICLE, Vehicle::Get(sel)->tile, Vehicle::Get(sel)->index, true);
|
||||||
} else if (gdvp.wagon == nullptr || gdvp.wagon->index != sel) {
|
} else if (gdvp.wagon == nullptr || gdvp.wagon->index != sel) {
|
||||||
|
@ -1056,7 +1053,7 @@ struct DepotWindow : Window {
|
||||||
ShowVehicleViewWindow(gdvp.head);
|
ShowVehicleViewWindow(gdvp.head);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (this->GetVehicleFromDepotWndPt(pt.x - nwi->pos_x, pt.y - nwi->pos_y, &v, nullptr) == MODE_DRAG_VEHICLE && v != nullptr && sel == v->index) {
|
} else if (this->GetVehicleFromDepotWndPt(pt.x, pt.y, &v, nullptr) == MODE_DRAG_VEHICLE && v != nullptr && sel == v->index) {
|
||||||
ShowVehicleViewWindow(v);
|
ShowVehicleViewWindow(v);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue