order_gui.c
changeset 555 02df8a1b7f33
parent 536 03d80fecb999
child 558 1ae2a752501e
equal deleted inserted replaced
554:a4ba0fbbf018 555:02df8a1b7f33
    11 #include "viewport.h"
    11 #include "viewport.h"
    12 
    12 
    13 static int OrderGetSel(Window *w)
    13 static int OrderGetSel(Window *w)
    14 {
    14 {
    15 	Vehicle *v = &_vehicles[w->window_number];
    15 	Vehicle *v = &_vehicles[w->window_number];
    16 	uint16 *sched = v->schedule_ptr;
    16 	const Order *sched = v->schedule_ptr;
    17 	int num = WP(w,order_d).sel;
    17 	int num = WP(w,order_d).sel;
    18 	int count = 0;
    18 	int count = 0;
    19 
    19 
    20 	if (num == 0)
    20 	if (num == 0)
    21 		return 0;
    21 		return 0;
    22 
    22 
    23 	while (*sched != 0) {
    23 	while (sched->type != OT_NOTHING) {
    24 		sched++;
    24 		sched++;
    25 		count++;
    25 		count++;
    26 		if (--num == 0)
    26 		if (--num == 0)
    27 			break;
    27 			break;
    28 	}
    28 	}
    32 
    32 
    33 static void DrawOrdersWindow(Window *w)
    33 static void DrawOrdersWindow(Window *w)
    34 {
    34 {
    35 	Vehicle *v;
    35 	Vehicle *v;
    36 	int num, sel;
    36 	int num, sel;
    37 	uint16 *sched, ord;
    37 	const Order *sched;
       
    38 	Order ord;
    38 	int y, i;
    39 	int y, i;
    39 	StringID str;
    40 	StringID str;
    40 	bool shared_schedule;
    41 	bool shared_schedule;
    41 
    42 
    42 	v = &_vehicles[w->window_number];
    43 	v = &_vehicles[w->window_number];
    45 
    46 
    46 	shared_schedule = IsScheduleShared(v) != NULL;
    47 	shared_schedule = IsScheduleShared(v) != NULL;
    47 
    48 
    48 	sched = v->schedule_ptr;
    49 	sched = v->schedule_ptr;
    49 	num=0;
    50 	num=0;
    50 	while (*sched != 0)
    51 	while (sched->type != OT_NOTHING) {
    51 		sched++,num++;
    52 		sched++;
       
    53 		num++;
       
    54 	}
    52 
    55 
    53 	if ((uint)num + shared_schedule <= (uint)WP(w,order_d).sel)
    56 	if ((uint)num + shared_schedule <= (uint)WP(w,order_d).sel)
    54 		SETBIT(w->disabled_state, 5); /* delete */
    57 		SETBIT(w->disabled_state, 5); /* delete */
    55 
    58 
    56 	if (num == 0)
    59 	if (num == 0)
    59 	SetVScrollCount(w, num+1);
    62 	SetVScrollCount(w, num+1);
    60 
    63 
    61 	sel = OrderGetSel(w);
    64 	sel = OrderGetSel(w);
    62 
    65 
    63 	SetDParam(2,STR_8827_FULL_LOAD);
    66 	SetDParam(2,STR_8827_FULL_LOAD);
    64 	switch(v->schedule_ptr[sel] & 0x1F) {
    67 	switch (v->schedule_ptr[sel].type) {
    65 	case OT_GOTO_STATION:
    68 	case OT_GOTO_STATION:
    66 		break;
    69 		break;
    67 	case OT_GOTO_DEPOT:
    70 	case OT_GOTO_DEPOT:
    68 		SETBIT(w->disabled_state, 9);	/* unload */
    71 		SETBIT(w->disabled_state, 9);	/* unload */
    69 		SetDParam(2,STR_SERVICE);
    72 		SetDParam(2,STR_SERVICE);
    86 
    89 
    87 		ord = v->schedule_ptr[i];
    90 		ord = v->schedule_ptr[i];
    88 
    91 
    89 		if ( (uint)(i - w->vscroll.pos) < 6) {
    92 		if ( (uint)(i - w->vscroll.pos) < 6) {
    90 
    93 
    91 			if (ord == 0) {
    94 			if (ord.type == OT_NOTHING) {
    92 				str = shared_schedule ? STR_END_OF_SHARED_ORDERS : STR_882A_END_OF_ORDERS;
    95 				str = shared_schedule ? STR_END_OF_SHARED_ORDERS : STR_882A_END_OF_ORDERS;
    93 			} else {
    96 			} else {
    94 				SetDParam(1, 6);
    97 				SetDParam(1, 6);
    95 
    98 
    96 				if ( (ord & OT_MASK) == OT_GOTO_STATION) {
    99 				if (ord.type == OT_GOTO_STATION) {
    97 					SetDParam(1, STR_8806_GO_TO + ((ord >> 5) & 7));
   100 					SetDParam(1, STR_8806_GO_TO + (ord.flags >> 1));
    98 					SetDParam(2, ord >> 8);
   101 					SetDParam(2, ord.station);
    99 				} else if ((ord & OT_MASK) == OT_GOTO_DEPOT) {
   102 				} else if (ord.type == OT_GOTO_DEPOT) {
   100 					StringID s = STR_NULL;
   103 					StringID s = STR_NULL;
   101 					if (v->type == VEH_Aircraft) {
   104 					if (v->type == VEH_Aircraft) {
   102 						s = STR_GO_TO_AIRPORT_HANGAR;
   105 						s = STR_GO_TO_AIRPORT_HANGAR;
   103 					  SetDParam(2, ord>>8);
   106 					  SetDParam(2, ord.station);
   104 					} else {
   107 					} else {
   105 						SetDParam(2, _depots[ord >> 8].town_index);
   108 						SetDParam(2, _depots[ord.station].town_index);
   106 						switch (v->type) {
   109 						switch (v->type) {
   107 						case VEH_Train:	s = STR_880E_GO_TO_TRAIN_DEPOT; break;
   110 						case VEH_Train:	s = STR_880E_GO_TO_TRAIN_DEPOT; break;
   108 						case VEH_Road:	s = STR_9038_GO_TO_ROADVEH_DEPOT; break;
   111 						case VEH_Road:	s = STR_9038_GO_TO_ROADVEH_DEPOT; break;
   109 						case VEH_Ship:	s = STR_GO_TO_SHIP_DEPOT; break;
   112 						case VEH_Ship:	s = STR_GO_TO_SHIP_DEPOT; break;
   110 						}
   113 						}
   111 					}
   114 					}
   112 					if (v->type == VEH_Train)
   115 					if (v->type == VEH_Train && ord.flags & OF_NON_STOP) s += 2;
   113 						s += (ord>>6)&2;
   116 					if (ord.flags & OF_FULL_LOAD) ++s; /* XXX service */
   114 					SetDParam(1, s + ((ord>>6)&1) );
   117 					SetDParam(1, s);
   115 				} else if ((ord & OT_MASK) == OT_GOTO_WAYPOINT) {
   118 				} else if (ord.type == OT_GOTO_WAYPOINT) {
   116 					SetDParam(2, ord >> 8);
   119 					SetDParam(2, ord.station);
   117 					SetDParam(1, STR_GO_TO_WAYPOINT);
   120 					SetDParam(1, STR_GO_TO_WAYPOINT);
   118 				}
   121 				}
   119 			}
   122 			}
   120 			{
   123 			{
   121 				byte color = (i == WP(w,order_d).sel) ? 0xC : 0x10;
   124 				byte color = (i == WP(w,order_d).sel) ? 0xC : 0x10;
   122 				SetDParam(0, i+1);
   125 				SetDParam(0, i+1);
   123 				if ((ord & OT_MASK) != OT_DUMMY) {
   126 				if (ord.type != OT_DUMMY) {
   124 					DrawString(2, y, str, color);
   127 					DrawString(2, y, str, color);
   125 				} else {
   128 				} else {
   126 					SetDParam(1, STR_INVALID_ORDER);
   129 					SetDParam(1, STR_INVALID_ORDER);
   127 					SetDParam(2, ord >> 8);
   130 					SetDParam(2, ord.station);
   128 					DrawString(2, y, str, color);
   131 					DrawString(2, y, str, color);
   129 				}
   132 				}
   130 			}
   133 			}
   131 			y += 10;
   134 			y += 10;
   132 		}
   135 		}
   133 
   136 
   134 		i++;
   137 		i++;
   135 
   138 
   136 		if (ord == 0)
   139 		if (ord.type == OT_NOTHING)
   137 			break;
   140 			break;
   138 	}
   141 	}
   139 }
   142 }
   140 
   143 
   141 
   144 
   286 				return;
   289 				return;
   287 
   290 
   288 			sel += w->vscroll.pos;
   291 			sel += w->vscroll.pos;
   289 
   292 
   290 			if (_ctrl_pressed && sel < v->num_orders) { // watch out for schedule_ptr overflow
   293 			if (_ctrl_pressed && sel < v->num_orders) { // watch out for schedule_ptr overflow
   291 				int ord = v->schedule_ptr[sel];
   294 				Order ord = v->schedule_ptr[sel];
   292 				int xy = 0;
   295 				int xy = 0;
   293 				switch (ord & OT_MASK) {
   296 				switch (ord.type) {
   294 				case OT_GOTO_STATION:			/* station order */
   297 				case OT_GOTO_STATION:			/* station order */
   295 					xy = _stations[ord >> 8].xy ;
   298 					xy = _stations[ord.station].xy ;
   296 					break;
   299 					break;
   297 				case OT_GOTO_DEPOT:				/* goto depot order */
   300 				case OT_GOTO_DEPOT:				/* goto depot order */
   298 					xy = _depots[ord >> 8].xy;
   301 					xy = _depots[ord.station].xy;
   299 					break;
   302 					break;
   300 				case OT_GOTO_WAYPOINT:	/* goto waypoint order */
   303 				case OT_GOTO_WAYPOINT:	/* goto waypoint order */
   301 					xy = _waypoints[ord >> 8].xy;
   304 					xy = _waypoints[ord.station].xy;
   302 				}
   305 				}
   303 
   306 
   304 				if (xy)
   307 				if (xy)
   305 					ScrollMainWindowToTile(xy);
   308 					ScrollMainWindowToTile(xy);
   306 
   309 
   350 
   353 
   351 
   354 
   352 	case WE_RCLICK: {
   355 	case WE_RCLICK: {
   353 		Vehicle *v = &_vehicles[w->window_number];
   356 		Vehicle *v = &_vehicles[w->window_number];
   354 		if (e->click.widget != 8) break;
   357 		if (e->click.widget != 8) break;
   355 		if ((v->schedule_ptr[OrderGetSel(w)] & OT_MASK) == OT_GOTO_DEPOT)
   358 		if (v->schedule_ptr[OrderGetSel(w)].type == OT_GOTO_DEPOT)
   356 			GuiShowTooltips(STR_SERVICE_HINT);
   359 			GuiShowTooltips(STR_SERVICE_HINT);
   357 		else
   360 		else
   358 			GuiShowTooltips(STR_8857_MAKE_THE_HIGHLIGHTED_ORDER);
   361 			GuiShowTooltips(STR_8857_MAKE_THE_HIGHLIGHTED_ORDER);
   359 		} break;
   362 		} break;
   360 
   363