rail_gui.c
changeset 395 4c990f33dab7
parent 393 82c2bf635cd9
child 409 98c586218b01
equal deleted inserted replaced
394:70651c0838a3 395:4c990f33dab7
    11 #include "station.h"
    11 #include "station.h"
    12 
    12 
    13 static uint _cur_railtype;
    13 static uint _cur_railtype;
    14 static bool _remove_button_clicked;
    14 static bool _remove_button_clicked;
    15 static byte _build_depot_direction;
    15 static byte _build_depot_direction;
    16 static byte _checkpoint_count;
    16 static byte _waypoint_count;
    17 static byte _cur_checkpoint_type;
    17 static byte _cur_waypoint_type;
    18 
    18 
    19 struct {
    19 struct {
    20 	byte orientation;
    20 	byte orientation;
    21 	byte numtracks;
    21 	byte numtracks;
    22 	byte platlength;
    22 	byte platlength;
    24 } _railstation;
    24 } _railstation;
    25 
    25 
    26 
    26 
    27 static void HandleStationPlacement(uint start, uint end);
    27 static void HandleStationPlacement(uint start, uint end);
    28 static void ShowBuildTrainDepotPicker();
    28 static void ShowBuildTrainDepotPicker();
    29 static void ShowBuildCheckpointPicker();
    29 static void ShowBuildWaypointPicker();
    30 static void ShowStationBuilder();
    30 static void ShowStationBuilder();
    31 
    31 
    32 typedef void OnButtonClick(Window *w);
    32 typedef void OnButtonClick(Window *w);
    33 
    33 
    34 static void CcPlaySound1E(bool success, uint tile, uint32 p1, uint32 p2)
    34 static void CcPlaySound1E(bool success, uint tile, uint32 p1, uint32 p2)
   113 {
   113 {
   114 	DoCommandP(tile, _cur_railtype, _build_depot_direction, CcDepot,
   114 	DoCommandP(tile, _cur_railtype, _build_depot_direction, CcDepot,
   115 		CMD_BUILD_TRAIN_DEPOT | CMD_AUTO | CMD_NO_WATER | CMD_MSG(STR_100E_CAN_T_BUILD_TRAIN_DEPOT));
   115 		CMD_BUILD_TRAIN_DEPOT | CMD_AUTO | CMD_NO_WATER | CMD_MSG(STR_100E_CAN_T_BUILD_TRAIN_DEPOT));
   116 }
   116 }
   117 
   117 
   118 static void PlaceRail_Checkpoint(uint tile)
   118 static void PlaceRail_Waypoint(uint tile)
   119 {
   119 {
   120 	if (!_remove_button_clicked) {
   120 	if (!_remove_button_clicked) {
   121 		DoCommandP(tile, _checkpoint_count > 0 ? (0x100 + _cur_checkpoint_type) : 0, 0, CcPlaySound1E, CMD_BUILD_TRAIN_CHECKPOINT | CMD_MSG(STR_CANT_BUILD_TRAIN_CHECKPOINT));
   121 		DoCommandP(tile, _waypoint_count > 0 ? (0x100 + _cur_waypoint_type) : 0, 0, CcPlaySound1E, CMD_BUILD_TRAIN_WAYPOINT | CMD_MSG(STR_CANT_BUILD_TRAIN_WAYPOINT));
   122 	} else {
   122 	} else {
   123 		DoCommandP(tile, 0, 0, CcPlaySound1E, CMD_REMOVE_TRAIN_CHECKPOINT | CMD_MSG(STR_CANT_REMOVE_TRAIN_CHECKPOINT));
   123 		DoCommandP(tile, 0, 0, CcPlaySound1E, CMD_REMOVE_TRAIN_WAYPOINT | CMD_MSG(STR_CANT_REMOVE_TRAIN_WAYPOINT));
   124 	}
   124 	}
   125 }
   125 }
   126 
   126 
   127 static void CcStation(bool success, uint tile, uint32 p1, uint32 p2)
   127 static void CcStation(bool success, uint tile, uint32 p1, uint32 p2)
   128 {
   128 {
   303 static void BuildRailClick_Sign(Window *w)
   303 static void BuildRailClick_Sign(Window *w)
   304 {
   304 {
   305 	HandlePlacePushButton(w, 17, 0x12B8, 1, PlaceProc_BuyLand);
   305 	HandlePlacePushButton(w, 17, 0x12B8, 1, PlaceProc_BuyLand);
   306 }
   306 }
   307 
   307 
   308 static void BuildRailClick_Checkpoint(Window *w)
   308 static void BuildRailClick_Waypoint(Window *w)
   309 {
   309 {
   310 	_checkpoint_count = GetCustomStationsCount('WAYP');
   310 	_waypoint_count = GetCustomStationsCount('WAYP');
   311 	if (HandlePlacePushButton(w, 18, SPR_OPENTTD_BASE + 7, 1, PlaceRail_Checkpoint)
   311 	if (HandlePlacePushButton(w, 18, SPR_OPENTTD_BASE + 7, 1, PlaceRail_Waypoint)
   312 	    && _checkpoint_count > 1)
   312 	    && _waypoint_count > 1)
   313 		ShowBuildCheckpointPicker();
   313 		ShowBuildWaypointPicker();
   314 }
   314 }
   315 
   315 
   316 static void BuildRailClick_Convert(Window *w)
   316 static void BuildRailClick_Convert(Window *w)
   317 {
   317 {
   318 	HandlePlacePushButton(w, 19, (SPR_OPENTTD_BASE + 26) + _cur_railtype * 2, 1, PlaceRail_ConvertRail);
   318 	HandlePlacePushButton(w, 19, (SPR_OPENTTD_BASE + 26) + _cur_railtype * 2, 1, PlaceRail_ConvertRail);
   573 	BuildRailClick_AutoSignals,
   573 	BuildRailClick_AutoSignals,
   574 	BuildRailClick_Bridge,
   574 	BuildRailClick_Bridge,
   575 	BuildRailClick_Tunnel,
   575 	BuildRailClick_Tunnel,
   576 	BuildRailClick_Remove,
   576 	BuildRailClick_Remove,
   577 	BuildRailClick_Sign,
   577 	BuildRailClick_Sign,
   578 	BuildRailClick_Checkpoint,
   578 	BuildRailClick_Waypoint,
   579 	BuildRailClick_Convert,
   579 	BuildRailClick_Convert,
   580 };
   580 };
   581 
   581 
   582 static const uint16 _rail_keycodes[] = {
   582 static const uint16 _rail_keycodes[] = {
   583 	'5',
   583 	'5',
   593 	'S',// signals
   593 	'S',// signals
   594 	'B',// bridge
   594 	'B',// bridge
   595 	'T',// tunnel
   595 	'T',// tunnel
   596 	'R',// remove
   596 	'R',// remove
   597 	0,	// sign
   597 	0,	// sign
   598 	'C',// checkpoint
   598 	'C',// waypoint
   599 };
   599 };
   600 
   600 
   601 
   601 
   602 
   602 
   603 
   603 
   710 {      WWT_PANEL,     7,   288,   329,    14,    35, 0xA22,		STR_101C_BUILD_RAILROAD_BRIDGE},
   710 {      WWT_PANEL,     7,   288,   329,    14,    35, 0xA22,		STR_101C_BUILD_RAILROAD_BRIDGE},
   711 {      WWT_PANEL,     7,   330,   351,    14,    35, 0x97E,		STR_101D_BUILD_RAILROAD_TUNNEL},
   711 {      WWT_PANEL,     7,   330,   351,    14,    35, 0x97E,		STR_101D_BUILD_RAILROAD_TUNNEL},
   712 {      WWT_PANEL,     7,   352,   373,    14,    35, 0x2CA,		STR_101E_TOGGLE_BUILD_REMOVE_FOR},
   712 {      WWT_PANEL,     7,   352,   373,    14,    35, 0x2CA,		STR_101E_TOGGLE_BUILD_REMOVE_FOR},
   713 {      WWT_PANEL,     7,   374,   395,    14,    35, 0x12B7,	STR_0329_PURCHASE_LAND_FOR_FUTURE},
   713 {      WWT_PANEL,     7,   374,   395,    14,    35, 0x12B7,	STR_0329_PURCHASE_LAND_FOR_FUTURE},
   714 
   714 
   715 {      WWT_PANEL,     7,   202,   223,    14,    35, SPR_OPENTTD_BASE + 3, STR_CONVERT_RAIL_TO_CHECKPOINT_TIP},
   715 {      WWT_PANEL,     7,   202,   223,    14,    35, SPR_OPENTTD_BASE + 3, STR_CONVERT_RAIL_TO_WAYPOINT_TIP},
   716 {      WWT_PANEL,     7,   396,   417,    14,    35, SPR_OPENTTD_BASE + 25, STR_CONVERT_RAIL_TIP},
   716 {      WWT_PANEL,     7,   396,   417,    14,    35, SPR_OPENTTD_BASE + 25, STR_CONVERT_RAIL_TIP},
   717 
   717 
   718 {   WIDGETS_END},
   718 {   WIDGETS_END},
   719 };
   719 };
   720 
   720 
   748 {      WWT_PANEL,     7,   288,   329,    14,    35, 0xA22,		STR_101C_BUILD_RAILROAD_BRIDGE},
   748 {      WWT_PANEL,     7,   288,   329,    14,    35, 0xA22,		STR_101C_BUILD_RAILROAD_BRIDGE},
   749 {      WWT_PANEL,     7,   330,   351,    14,    35, 0x97F,		STR_101D_BUILD_RAILROAD_TUNNEL},
   749 {      WWT_PANEL,     7,   330,   351,    14,    35, 0x97F,		STR_101D_BUILD_RAILROAD_TUNNEL},
   750 {      WWT_PANEL,     7,   352,   373,    14,    35, 0x2CA,		STR_101E_TOGGLE_BUILD_REMOVE_FOR},
   750 {      WWT_PANEL,     7,   352,   373,    14,    35, 0x2CA,		STR_101E_TOGGLE_BUILD_REMOVE_FOR},
   751 {      WWT_PANEL,     7,   374,   395,    14,    35, 0x12B7,	STR_0329_PURCHASE_LAND_FOR_FUTURE},
   751 {      WWT_PANEL,     7,   374,   395,    14,    35, 0x12B7,	STR_0329_PURCHASE_LAND_FOR_FUTURE},
   752 
   752 
   753 {      WWT_PANEL,     7,   202,   223,    14,    35, SPR_OPENTTD_BASE + 3, STR_CONVERT_RAIL_TO_CHECKPOINT_TIP},
   753 {      WWT_PANEL,     7,   202,   223,    14,    35, SPR_OPENTTD_BASE + 3, STR_CONVERT_RAIL_TO_WAYPOINT_TIP},
   754 {      WWT_PANEL,     7,   396,   417,    14,    35, SPR_OPENTTD_BASE + 27, STR_CONVERT_RAIL_TIP},
   754 {      WWT_PANEL,     7,   396,   417,    14,    35, SPR_OPENTTD_BASE + 27, STR_CONVERT_RAIL_TIP},
   755 {   WIDGETS_END},
   755 {   WIDGETS_END},
   756 };
   756 };
   757 
   757 
   758 static const WindowDesc _build_monorail_desc = {
   758 static const WindowDesc _build_monorail_desc = {
   785 {      WWT_PANEL,     7,   288,   329,    14,    35, 0xA22,		STR_101C_BUILD_RAILROAD_BRIDGE},
   785 {      WWT_PANEL,     7,   288,   329,    14,    35, 0xA22,		STR_101C_BUILD_RAILROAD_BRIDGE},
   786 {      WWT_PANEL,     7,   330,   351,    14,    35, 0x980,		STR_101D_BUILD_RAILROAD_TUNNEL},
   786 {      WWT_PANEL,     7,   330,   351,    14,    35, 0x980,		STR_101D_BUILD_RAILROAD_TUNNEL},
   787 {      WWT_PANEL,     7,   352,   373,    14,    35, 0x2CA,		STR_101E_TOGGLE_BUILD_REMOVE_FOR},
   787 {      WWT_PANEL,     7,   352,   373,    14,    35, 0x2CA,		STR_101E_TOGGLE_BUILD_REMOVE_FOR},
   788 {      WWT_PANEL,     7,   374,   395,    14,    35, 0x12B7,	STR_0329_PURCHASE_LAND_FOR_FUTURE},
   788 {      WWT_PANEL,     7,   374,   395,    14,    35, 0x12B7,	STR_0329_PURCHASE_LAND_FOR_FUTURE},
   789 
   789 
   790 {      WWT_PANEL,     7,   202,   223,    14,    35, SPR_OPENTTD_BASE + 3, STR_CONVERT_RAIL_TO_CHECKPOINT_TIP},
   790 {      WWT_PANEL,     7,   202,   223,    14,    35, SPR_OPENTTD_BASE + 3, STR_CONVERT_RAIL_TO_WAYPOINT_TIP},
   791 {      WWT_PANEL,     7,   396,   417,    14,    35, SPR_OPENTTD_BASE + 29, STR_CONVERT_RAIL_TIP},
   791 {      WWT_PANEL,     7,   396,   417,    14,    35, SPR_OPENTTD_BASE + 29, STR_CONVERT_RAIL_TIP},
   792 {   WIDGETS_END},
   792 {   WIDGETS_END},
   793 };
   793 };
   794 
   794 
   795 static const WindowDesc _build_maglev_desc = {
   795 static const WindowDesc _build_maglev_desc = {
  1053 {
  1053 {
  1054 	AllocateWindowDesc(&_build_depot_desc);
  1054 	AllocateWindowDesc(&_build_depot_desc);
  1055 }
  1055 }
  1056 
  1056 
  1057 
  1057 
  1058 static void BuildCheckpointWndProc(Window *w, WindowEvent *e)
  1058 static void BuildWaypointWndProc(Window *w, WindowEvent *e)
  1059 {
  1059 {
  1060 	switch(e->event) {
  1060 	switch(e->event) {
  1061 	case WE_PAINT: {
  1061 	case WE_PAINT: {
  1062 		int r;
  1062 		int r;
  1063 
  1063 
  1064 		w->click_state = (1 << 3) << _cur_checkpoint_type;
  1064 		w->click_state = (1 << 3) << _cur_waypoint_type;
  1065 		DrawWindowWidgets(w);
  1065 		DrawWindowWidgets(w);
  1066 
  1066 
  1067 		r = 4*w->hscroll.pos;
  1067 		r = 4*w->hscroll.pos;
  1068 		if(r+0<=_checkpoint_count) DrawCheckpointSprite(2,   25, r + 0);
  1068 		if(r+0<=_waypoint_count) DrawWaypointSprite(2,   25, r + 0);
  1069 		if(r+1<=_checkpoint_count) DrawCheckpointSprite(70,  25, r + 1);
  1069 		if(r+1<=_waypoint_count) DrawWaypointSprite(70,  25, r + 1);
  1070 		if(r+2<=_checkpoint_count) DrawCheckpointSprite(138, 25, r + 2);
  1070 		if(r+2<=_waypoint_count) DrawWaypointSprite(138, 25, r + 2);
  1071 		if(r+3<=_checkpoint_count) DrawCheckpointSprite(206, 25, r + 3);
  1071 		if(r+3<=_waypoint_count) DrawWaypointSprite(206, 25, r + 3);
  1072 		break;
  1072 		break;
  1073 		}
  1073 		}
  1074 	case WE_CLICK: {
  1074 	case WE_CLICK: {
  1075 		switch(e->click.widget) {
  1075 		switch(e->click.widget) {
  1076 		case 0:
  1076 		case 0:
  1078 			break;
  1078 			break;
  1079 		case 3:
  1079 		case 3:
  1080 		case 4:
  1080 		case 4:
  1081 		case 5:
  1081 		case 5:
  1082 		case 6:
  1082 		case 6:
  1083 			_cur_checkpoint_type = e->click.widget - 3;
  1083 			_cur_waypoint_type = e->click.widget - 3;
  1084 			SndPlayFx(0x13);
  1084 			SndPlayFx(0x13);
  1085 			SetWindowDirty(w);
  1085 			SetWindowDirty(w);
  1086 			break;
  1086 			break;
  1087 		}
  1087 		}
  1088 		break;
  1088 		break;
  1093 			DeleteWindow(w);
  1093 			DeleteWindow(w);
  1094 		return;
  1094 		return;
  1095 	}
  1095 	}
  1096 }
  1096 }
  1097 
  1097 
  1098 static const Widget _build_checkpoint_widgets[] = {
  1098 static const Widget _build_waypoint_widgets[] = {
  1099 {   WWT_CLOSEBOX,     7,     0,    10,     0,    13, STR_00C5, STR_018B_CLOSE_WINDOW},
  1099 {   WWT_CLOSEBOX,     7,     0,    10,     0,    13, STR_00C5, STR_018B_CLOSE_WINDOW},
  1100 {    WWT_CAPTION,     7,    11,   275,     0,    13, STR_CHECKPOINT,STR_018C_WINDOW_TITLE_DRAG_THIS},
  1100 {    WWT_CAPTION,     7,    11,   275,     0,    13, STR_WAYPOINT,STR_018C_WINDOW_TITLE_DRAG_THIS},
  1101 {      WWT_PANEL,     7,     0,   275,    14,    91, 0x0, 0},
  1101 {      WWT_PANEL,     7,     0,   275,    14,    91, 0x0, 0},
  1102 
  1102 
  1103 {      WWT_PANEL,     7,     3,    68,    17,    76, 0x0, STR_CHECKPOINT_GRAPHICS_TIP},
  1103 {      WWT_PANEL,     7,     3,    68,    17,    76, 0x0, STR_WAYPOINT_GRAPHICS_TIP},
  1104 {      WWT_PANEL,     7,    71,   136,    17,    76, 0x0, STR_CHECKPOINT_GRAPHICS_TIP},
  1104 {      WWT_PANEL,     7,    71,   136,    17,    76, 0x0, STR_WAYPOINT_GRAPHICS_TIP},
  1105 {      WWT_PANEL,     7,   139,   204,    17,    76, 0x0, STR_CHECKPOINT_GRAPHICS_TIP},
  1105 {      WWT_PANEL,     7,   139,   204,    17,    76, 0x0, STR_WAYPOINT_GRAPHICS_TIP},
  1106 {      WWT_PANEL,     7,   207,   272,    17,    76, 0x0, STR_CHECKPOINT_GRAPHICS_TIP},
  1106 {      WWT_PANEL,     7,   207,   272,    17,    76, 0x0, STR_WAYPOINT_GRAPHICS_TIP},
  1107 
  1107 
  1108 {  WWT_HSCROLLBAR,    7,     1,   275,    80,    91, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
  1108 {  WWT_HSCROLLBAR,    7,     1,   275,    80,    91, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
  1109 {      WWT_LAST},
  1109 {      WWT_LAST},
  1110 };
  1110 };
  1111 
  1111 
  1112 static const WindowDesc _build_checkpoint_desc = {
  1112 static const WindowDesc _build_waypoint_desc = {
  1113 	-1,-1, 276, 92,
  1113 	-1,-1, 276, 92,
  1114 	WC_BUILD_DEPOT,WC_BUILD_TOOLBAR,
  1114 	WC_BUILD_DEPOT,WC_BUILD_TOOLBAR,
  1115 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
  1115 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
  1116 	_build_checkpoint_widgets,
  1116 	_build_waypoint_widgets,
  1117 	BuildCheckpointWndProc
  1117 	BuildWaypointWndProc
  1118 };
  1118 };
  1119 
  1119 
  1120 static void ShowBuildCheckpointPicker()
  1120 static void ShowBuildWaypointPicker()
  1121 {
  1121 {
  1122 	Window *w = AllocateWindowDesc(&_build_checkpoint_desc);
  1122 	Window *w = AllocateWindowDesc(&_build_waypoint_desc);
  1123 	w->hscroll.cap = 1;
  1123 	w->hscroll.cap = 1;
  1124 	w->hscroll.count = (uint) (_checkpoint_count+3) / 4;
  1124 	w->hscroll.count = (uint) (_waypoint_count+3) / 4;
  1125 }
  1125 }
  1126 
  1126 
  1127 
  1127 
  1128 void InitializeRailGui()
  1128 void InitializeRailGui()
  1129 {
  1129 {