Changeset - r13314:bcf1763c5012
[Not reviewed]
master
0 1 0
alberth - 15 years ago 2009-10-20 21:41:44
alberth@openttd.org
(svn r17833) -Codechange: Depot gui should use relative widget coordinates for clicking.
1 file changed with 16 insertions and 11 deletions:
0 comments (0 inline, 0 general)
src/depot_gui.cpp
Show inline comments
 
@@ -364,16 +364,16 @@ struct DepotWindow : Window {
 
			x -= 23;
 
		} else {
 
			xt = x / this->resize.step_width;
 
			xm = x % this->resize.step_width;
 
			if (xt >= this->hscroll.GetCapacity()) return MODE_ERROR;
 

	
 
			ym = (y - 14) % this->resize.step_height;
 
			ym = y % this->resize.step_height;
 
		}
 

	
 
		uint row = (y - 14) / this->resize.step_height;
 
		uint row = y / this->resize.step_height;
 
		if (row >= this->vscroll.GetCapacity()) return MODE_ERROR;
 

	
 
		uint16 boxes_in_each_row = GB(this->GetWidget<NWidgetCore>(DEPOT_WIDGET_MATRIX)->widget_data, MAT_COL_START, MAT_COL_BITS);
 
		int pos = ((row + this->vscroll.GetPosition()) * boxes_in_each_row) + xt;
 

	
 
		if ((int)(this->vehicle_list.Length() + this->wagon_list.Length()) <= pos) {
 
@@ -436,12 +436,16 @@ struct DepotWindow : Window {
 

	
 
			default: NOT_REACHED();
 
		}
 
		return MODE_START_STOP;
 
	}
 

	
 
	/** Handle click in the depot matrix.
 
	 * @param x Horizontal position in the matrix widget in pixels.
 
	 * @param y Vertical position in the matrix widget in pixels.
 
	 */
 
	void DepotClick(int x, int y)
 
	{
 
		GetDepotVehiclePtData gdvp = { NULL, NULL };
 
		const Vehicle *v = NULL;
 
		DepotGUIAction mode = this->GetVehicleFromDepotWndPt(x, y, &v, &gdvp);
 

	
 
@@ -674,15 +678,17 @@ struct DepotWindow : Window {
 
		this->DrawWidgets();
 
	}
 

	
 
	virtual void OnClick(Point pt, int widget)
 
	{
 
		switch (widget) {
 
			case DEPOT_WIDGET_MATRIX: // List
 
				this->DepotClick(pt.x, pt.y);
 
			case DEPOT_WIDGET_MATRIX: { // List
 
				NWidgetBase *nwi = this->GetWidget<NWidgetBase>(DEPOT_WIDGET_MATRIX);
 
				this->DepotClick(pt.x - nwi->pos_x, pt.y - nwi->pos_y);
 
				break;
 
			}
 

	
 
			case DEPOT_WIDGET_BUILD: // Build vehicle
 
				ResetObjectToPlace();
 
				ShowBuildVehicleWindow(this->window_number, this->type);
 
				break;
 

	
 
@@ -746,13 +752,14 @@ struct DepotWindow : Window {
 
	virtual void OnRightClick(Point pt, int widget)
 
	{
 
		if (widget != DEPOT_WIDGET_MATRIX) return;
 

	
 
		GetDepotVehiclePtData gdvp = { NULL, NULL };
 
		const Vehicle *v = NULL;
 
		DepotGUIAction mode = this->GetVehicleFromDepotWndPt(pt.x, pt.y, &v, &gdvp);
 
		NWidgetBase *nwi = this->GetWidget<NWidgetBase>(DEPOT_WIDGET_MATRIX);
 
		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 (v != NULL && mode == MODE_DRAG_VEHICLE) {
 
			CargoArray capacity, loaded;
 

	
 
@@ -837,29 +844,27 @@ struct DepotWindow : Window {
 
				const Vehicle *v = NULL;
 
				VehicleID sel = this->sel;
 

	
 
				this->sel = INVALID_VEHICLE;
 
				this->SetDirty();
 

	
 
				NWidgetBase *nwi = this->GetWidget<NWidgetBase>(DEPOT_WIDGET_MATRIX);
 
				if (this->type == VEH_TRAIN) {
 
					GetDepotVehiclePtData gdvp = { NULL, NULL };
 

	
 
					if (this->GetVehicleFromDepotWndPt(pt.x, pt.y, &v, &gdvp) == MODE_DRAG_VEHICLE &&
 
						sel != INVALID_VEHICLE) {
 
					if (this->GetVehicleFromDepotWndPt(pt.x - nwi->pos_x, pt.y - nwi->pos_y, &v, &gdvp) == MODE_DRAG_VEHICLE && sel != INVALID_VEHICLE) {
 
						if (gdvp.wagon != NULL && gdvp.wagon->index == sel && _ctrl_pressed) {
 
							DoCommandP(Vehicle::Get(sel)->tile, Vehicle::Get(sel)->index, true,
 
													CMD_REVERSE_TRAIN_DIRECTION | CMD_MSG(STR_ERROR_CAN_T_REVERSE_DIRECTION_RAIL_VEHICLE));
 
									CMD_REVERSE_TRAIN_DIRECTION | CMD_MSG(STR_ERROR_CAN_T_REVERSE_DIRECTION_RAIL_VEHICLE));
 
						} else if (gdvp.wagon == NULL || gdvp.wagon->index != sel) {
 
							TrainDepotMoveVehicle(gdvp.wagon, sel, gdvp.head);
 
						} else if (gdvp.head != NULL && Train::From(gdvp.head)->IsFrontEngine()) {
 
							ShowVehicleViewWindow(gdvp.head);
 
						}
 
					}
 
				} else if (this->GetVehicleFromDepotWndPt(pt.x, pt.y, &v, NULL) == MODE_DRAG_VEHICLE &&
 
					v != NULL &&
 
					sel == v->index) {
 
				} else if (this->GetVehicleFromDepotWndPt(pt.x - nwi->pos_x, pt.y - nwi->pos_y, &v, NULL) == MODE_DRAG_VEHICLE && v != NULL && sel == v->index) {
 
					ShowVehicleViewWindow(v);
 
				}
 
			} break;
 

	
 
			case DEPOT_WIDGET_SELL: case DEPOT_WIDGET_SELL_CHAIN: {
 
				if (this->IsWidgetDisabled(widget)) return;
0 comments (0 inline, 0 general)