ship_gui.c
changeset 842 efc3546bc313
parent 767 27edbcad701c
child 867 dffd33233237
equal deleted inserted replaced
841:4874b9ce2765 842:efc3546bc313
    10 #include "station.h"
    10 #include "station.h"
    11 #include "command.h"
    11 #include "command.h"
    12 #include "player.h"
    12 #include "player.h"
    13 #include "engine.h"
    13 #include "engine.h"
    14 
    14 
       
    15 void Set_DPARAM_Ship_Build_Window(uint16 engine_number)
       
    16 {
       
    17 	YearMonthDay ymd;
       
    18 	const ShipVehicleInfo *svi = ShipVehInfo(engine_number);
       
    19 	Engine *e;
       
    20 
       
    21 	SetDParam(0, svi->base_cost * (_price.ship_base>>3)>>5);
       
    22 	SetDParam(1, svi->max_speed * 10 >> 5);
       
    23 	SetDParam(2, _cargoc.names_long_p[svi->cargo_type]);
       
    24 	SetDParam(3, svi->capacity);
       
    25 	SetDParam(4, svi->refittable ? STR_9842_REFITTABLE : STR_EMPTY);
       
    26 	SetDParam(5, svi->running_cost * _price.ship_running >> 8);
       
    27 
       
    28 	e = &_engines[engine_number];
       
    29 	SetDParam(7, e->lifelength);
       
    30 	SetDParam(8, e->reliability * 100 >> 16);
       
    31 	ConvertDayToYMD(&ymd, e->intro_date);
       
    32 	SetDParam(6, ymd.year + 1920);
       
    33 }
    15 
    34 
    16 static void DrawShipImage(Vehicle *v, int x, int y, VehicleID selection);
    35 static void DrawShipImage(Vehicle *v, int x, int y, VehicleID selection);
    17 
    36 
    18 
    37 
    19 const byte _ship_refit_types[4][16] = {
    38 const byte _ship_refit_types[4][16] = {
   315 	ShowShipViewWindow(v);
   334 	ShowShipViewWindow(v);
   316 }
   335 }
   317 
   336 
   318 static void NewShipWndProc(Window *w, WindowEvent *e)
   337 static void NewShipWndProc(Window *w, WindowEvent *e)
   319 {
   338 {
   320 	YearMonthDay ymd;
       
   321 	switch(e->event) {
   339 	switch(e->event) {
   322 	case WE_PAINT:
   340 	case WE_PAINT:
   323 		if (w->window_number == 0)
   341 		if (w->window_number == 0)
   324 			w->disabled_state = 1 << 5;
   342 			w->disabled_state = 1 << 5;
   325 
   343 
   360 			} while (++engine_id, ++e,--num);
   378 			} while (++engine_id, ++e,--num);
   361 
   379 
   362 			WP(w,buildtrain_d).sel_engine = selected_id;
   380 			WP(w,buildtrain_d).sel_engine = selected_id;
   363 
   381 
   364 			if (selected_id != -1) {
   382 			if (selected_id != -1) {
   365 				const ShipVehicleInfo *svi = ShipVehInfo(selected_id);
   383 				Set_DPARAM_Ship_Build_Window(selected_id);
   366 				Engine *e;
       
   367 
       
   368 				SetDParam(0, svi->base_cost * (_price.ship_base>>3)>>5);
       
   369 				SetDParam(1, svi->max_speed * 10 >> 5);
       
   370 				SetDParam(2, _cargoc.names_long_p[svi->cargo_type]);
       
   371 				SetDParam(3, svi->capacity);
       
   372 				SetDParam(4, svi->refittable ? STR_9842_REFITTABLE : STR_EMPTY);
       
   373 				SetDParam(5, svi->running_cost * _price.ship_running >> 8);
       
   374 
       
   375 				e = &_engines[selected_id];
       
   376 				SetDParam(7, e->lifelength);
       
   377 				SetDParam(8, e->reliability * 100 >> 16);
       
   378 				ConvertDayToYMD(&ymd, e->intro_date);
       
   379 				SetDParam(6, ymd.year + 1920);
       
   380 
   384 
   381 				DrawString(2, 111, STR_980A_COST_SPEED_CAPACITY_RUNNING, 0);
   385 				DrawString(2, 111, STR_980A_COST_SPEED_CAPACITY_RUNNING, 0);
   382 			}
   386 			}
   383 		}
   387 		}
   384 		break;
   388 		break;
   879 {   WWT_CLOSEBOX,    14,   238,   248,    14,    25, STR_0225,							STR_SORT_CRITERIA_TIP},
   883 {   WWT_CLOSEBOX,    14,   238,   248,    14,    25, STR_0225,							STR_SORT_CRITERIA_TIP},
   880 {      WWT_PANEL,    14,   249,   259,    14,    25, 0x0,										STR_NULL},
   884 {      WWT_PANEL,    14,   249,   259,    14,    25, 0x0,										STR_NULL},
   881 {     WWT_MATRIX,    14,     0,   248,    26,   169, 0x401,									STR_9823_SHIPS_CLICK_ON_SHIP_FOR},
   885 {     WWT_MATRIX,    14,     0,   248,    26,   169, 0x401,									STR_9823_SHIPS_CLICK_ON_SHIP_FOR},
   882 {  WWT_SCROLLBAR,    14,   249,   259,    26,   169, 0x0,										STR_0190_SCROLL_BAR_SCROLLS_LIST},
   886 {  WWT_SCROLLBAR,    14,   249,   259,    26,   169, 0x0,										STR_0190_SCROLL_BAR_SCROLLS_LIST},
   883 { WWT_PUSHTXTBTN,    14,     0,   129,   170,   181, STR_9804_NEW_SHIPS,		STR_9824_BUILD_NEW_SHIPS_REQUIRES},
   887 { WWT_PUSHTXTBTN,    14,     0,   129,   170,   181, STR_9804_NEW_SHIPS,		STR_9824_BUILD_NEW_SHIPS_REQUIRES},
   884 {      WWT_PANEL,    14,   130,   259,   170,   181, 0x0,										STR_NULL},
   888 { WWT_PUSHTXTBTN,    14,   130,   259,   170,   181, STR_REPLACE_VEHICLES,					STR_REPLACE_HELP},
   885 {   WIDGETS_END},
   889 {   WIDGETS_END},
   886 };
   890 };
   887 
   891 
   888 static Widget _other_player_ships_widgets[] = {
   892 static Widget _other_player_ships_widgets[] = {
   889 {   WWT_CLOSEBOX,    14,     0,    10,     0,    13, STR_00C5,							STR_018B_CLOSE_WINDOW},
   893 {   WWT_CLOSEBOX,    14,     0,    10,     0,    13, STR_00C5,							STR_018B_CLOSE_WINDOW},
   984 			vl->flags ^= VL_DESC;
   988 			vl->flags ^= VL_DESC;
   985 			vl->flags |= VL_RESORT;
   989 			vl->flags |= VL_RESORT;
   986 			SetWindowDirty(w);
   990 			SetWindowDirty(w);
   987 			break;
   991 			break;
   988 		case 4: case 5:/* Select sorting criteria dropdown menu */
   992 		case 4: case 5:/* Select sorting criteria dropdown menu */
   989 			ShowDropDownMenu(w, _vehicle_sort_listing, vl->sort_type, 5, 0);
   993 			ShowDropDownMenu(w, _vehicle_sort_listing, vl->sort_type, 5, 0, 0);
   990 			return;
   994 			return;
   991 		case 7: { /* Matrix to show vehicles */
   995 		case 7: { /* Matrix to show vehicles */
   992 			uint32 id_v = (e->click.pt.y - PLY_WND_PRC__OFFSET_TOP_WIDGET) / PLY_WND_PRC__SIZE_OF_ROW_BIG;
   996 			uint32 id_v = (e->click.pt.y - PLY_WND_PRC__OFFSET_TOP_WIDGET) / PLY_WND_PRC__SIZE_OF_ROW_BIG;
   993 
   997 
   994 			if (id_v >= w->vscroll.cap) { return;} // click out of bounds
   998 			if (id_v >= w->vscroll.cap) { return;} // click out of bounds
  1022 				tile = TILE_MASK(tile + 1);
  1026 				tile = TILE_MASK(tile + 1);
  1023 			} while(tile != _last_built_ship_depot_tile);
  1027 			} while(tile != _last_built_ship_depot_tile);
  1024 
  1028 
  1025 			ShowBuildShipWindow(0);
  1029 			ShowBuildShipWindow(0);
  1026 		} break;
  1030 		} break;
  1027 		}
  1031 		
       
  1032 		case 10: {
       
  1033 			ShowReplaceVehicleWindow(VEH_Ship);
       
  1034 			break;
       
  1035 		}
       
  1036 	}
  1028 	}	break;
  1037 	}	break;
  1029 
  1038 
  1030 	case WE_DROPDOWN_SELECT: /* we have selected a dropdown item in the list */
  1039 	case WE_DROPDOWN_SELECT: /* we have selected a dropdown item in the list */
  1031 		if (vl->sort_type != e->dropdown.index) {
  1040 		if (vl->sort_type != e->dropdown.index) {
  1032 			// value has changed -> resort
  1041 			// value has changed -> resort