Changeset - r9949:5ac3bf61abad
[Not reviewed]
master
0 12 1
belugas - 16 years ago 2008-08-20 01:29:05
belugas@openttd.org
(svn r14104) -Feature: Add a window for waypoints, allowing to view all the trains having the selected waypoint in their orders.
Changing its name is also supported from the same new window.
Gui based on work done by Satyap, on FS#2025.
13 files changed with 165 insertions and 27 deletions:
0 comments (0 inline, 0 general)
projects/openttd_vs80.vcproj
Show inline comments
 
@@ -1867,6 +1867,10 @@
 
				RelativePath=".\..\src\vehicle_gui.cpp"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\waypoints_gui.cpp"
 
				>
 
			</File>
 
		</Filter>
 
		<Filter
 
			Name="Command handlers"
projects/openttd_vs90.vcproj
Show inline comments
 
@@ -1864,6 +1864,10 @@
 
				RelativePath=".\..\src\vehicle_gui.cpp"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\waypoints_gui.cpp"
 
				>
 
			</File>
 
		</Filter>
 
		<Filter
 
			Name="Command handlers"
source.list
Show inline comments
 
@@ -410,6 +410,7 @@ train_gui.cpp
 
transparency_gui.cpp
 
tree_gui.cpp
 
vehicle_gui.cpp
 
waypoints_gui.cpp
 

	
 
# Command handlers
 
aircraft_cmd.cpp
src/lang/english.txt
Show inline comments
 
@@ -2902,6 +2902,9 @@ STR_886A_RENAME_TRAIN_VEHICLE_TYPE      
 
STR_886B_CAN_T_RENAME_TRAIN_VEHICLE                             :{WHITE}Can't rename train vehicle type...
 
STR_CLEAR_TIME                                                  :{BLACK}Clear Time
 
STR_RESET_LATENESS                                              :{BLACK}Reset Late Counter
 
STR_CHANGE_WAYPOINT_NAME                                        :{BLACK}Change waypoint name
 
STR_SHOW_TRAINS_ON_WAYPOINT                                     :{BLACK}Show Trains
 
STR_WAYPOINT_NAME                                               :{WHITE}{WAYPOINT}
 

	
 
STR_TRAIN_STOPPING                                              :{RED}Stopping
 
STR_TRAIN_STOPPING_VEL                                          :{RED}Stopping, {VELOCITY}
src/main_gui.cpp
Show inline comments
 
@@ -66,10 +66,6 @@ void HandleOnEditText(const char *str)
 
	_cmd_text = str;
 

	
 
	switch (_rename_what) {
 
	case 1: // Rename a waypoint
 
		if (*str == '\0') return;
 
		DoCommandP(0, id, 0, NULL, CMD_RENAME_WAYPOINT | CMD_MSG(STR_CANT_CHANGE_WAYPOINT_NAME));
 
		break;
 
#ifdef ENABLE_NETWORK
 
	case 3: { // Give money, you can only give money in excess of loan
 
		const Player *p = GetPlayer(_current_player);
 
@@ -131,23 +127,6 @@ void ShowNetworkGiveMoneyWindow(PlayerID
 
}
 
#endif /* ENABLE_NETWORK */
 

	
 
void ShowRenameWaypointWindow(const Waypoint *wp)
 
{
 
	int id = wp->index;
 

	
 
	/* Are we allowed to change the name of the waypoint? */
 
	if (!CheckTileOwnership(wp->xy)) {
 
		ShowErrorMessage(_error_message, STR_CANT_CHANGE_WAYPOINT_NAME,
 
			TileX(wp->xy) * TILE_SIZE, TileY(wp->xy) * TILE_SIZE);
 
		return;
 
	}
 

	
 
	_rename_id = id;
 
	_rename_what = 1;
 
	SetDParam(0, id);
 
	ShowQueryString(STR_WAYPOINT_RAW, STR_EDIT_WAYPOINT_NAME, MAX_LENGTH_WAYPOINT_NAME_BYTES, MAX_LENGTH_WAYPOINT_NAME_PIXELS, NULL, CS_ALPHANUMERAL);
 
}
 

	
 

	
 
/* Zooms a viewport in a window in or out */
 
/* No button handling or what so ever */
src/rail_cmd.cpp
Show inline comments
 
@@ -2307,8 +2307,8 @@ static TrackStatus GetTileTrackStatus_Tr
 
static void ClickTile_Track(TileIndex tile)
 
{
 
	switch (GetRailTileType(tile)) {
 
		case RAIL_TILE_DEPOT:    ShowDepotWindow(tile, VEH_TRAIN);                  break;
 
		case RAIL_TILE_WAYPOINT: ShowRenameWaypointWindow(GetWaypointByTile(tile)); break;
 
		case RAIL_TILE_DEPOT:    ShowDepotWindow(tile, VEH_TRAIN);            break;
 
		case RAIL_TILE_WAYPOINT: ShowWaypointWindow(GetWaypointByTile(tile)); break;
 
		default: break;
 
	}
 
}
src/vehicle_gui.cpp
Show inline comments
 
@@ -789,6 +789,7 @@ struct VehicleListWindow : public Window
 
			case VLW_SHARED_ORDERS:
 
				this->widget[VLW_WIDGET_CAPTION].data  = STR_VEH_WITH_SHARED_ORDERS_LIST;
 
				break;
 

	
 
			case VLW_STANDARD: /* Company Name - standard widget setup */
 
				switch (this->vehicle_type) {
 
					case VEH_TRAIN:    this->widget[VLW_WIDGET_CAPTION].data = STR_881B_TRAINS;        break;
 
@@ -798,6 +799,11 @@ struct VehicleListWindow : public Window
 
					default: NOT_REACHED(); break;
 
				}
 
				break;
 

	
 
			case VLM_WAYPOINT_LIST:
 
				this->widget[VLW_WIDGET_CAPTION].data = STR_WAYPOINT_VIEWPORT;
 
				break;
 

	
 
			case VLW_STATION_LIST: /* Station Name */
 
				switch (this->vehicle_type) {
 
					case VEH_TRAIN:    this->widget[VLW_WIDGET_CAPTION].data = STR_SCHEDULED_TRAINS;        break;
 
@@ -893,6 +899,10 @@ struct VehicleListWindow : public Window
 
				SetDParam(1, this->vscroll.count);
 
				break;
 

	
 
			case VLM_WAYPOINT_LIST:
 
				SetDParam(0, index);
 
				break;
 

	
 
			case VLW_STATION_LIST: /* Station Name */
 
				SetDParam(0, index);
 
				SetDParam(1, this->vscroll.count);
 
@@ -1167,6 +1177,12 @@ void ShowVehicleListWindow(PlayerID play
 
	}
 
}
 

	
 
void ShowVehicleListWindow(const Waypoint *wp)
 
{
 
	if (wp == NULL) return;
 
	ShowVehicleListWindowLocal(GetTileOwner(wp->xy), VLM_WAYPOINT_LIST, VEH_TRAIN, wp->index);
 
}
 

	
 
void ShowVehicleListWindow(const Vehicle *v)
 
{
 
	ShowVehicleListWindowLocal(v->owner, VLW_SHARED_ORDERS, v->type, v->FirstShared()->index);
src/vehicle_gui.h
Show inline comments
 
@@ -11,6 +11,7 @@
 
#include "order_type.h"
 
#include "station_type.h"
 
#include "engine_type.h"
 
#include "waypoint.h"
 

	
 
void DrawVehicleProfitButton(const Vehicle *v, int x, int y);
 
void ShowVehicleRefitWindow(const Vehicle *v, VehicleOrderID order);
 
@@ -51,6 +52,7 @@ enum {
 
	VLW_STATION_LIST  = 2 << 8,
 
	VLW_DEPOT_LIST    = 3 << 8,
 
	VLW_GROUP_LIST    = 4 << 8,
 
	VLM_WAYPOINT_LIST = 5 << 8,
 
	VLW_MASK          = 0x700,
 
};
 

	
 
@@ -72,6 +74,7 @@ uint ShowAdditionalText(int x, int y, ui
 
uint ShowRefitOptionsList(int x, int y, uint w, EngineID engine);
 

	
 
void ShowVehicleListWindow(const Vehicle *v);
 
void ShowVehicleListWindow(const Waypoint *wp);
 
void ShowVehicleListWindow(PlayerID player, VehicleType vehicle_type);
 
void ShowVehicleListWindow(PlayerID player, VehicleType vehicle_type, StationID station);
 
void ShowVehicleListWindow(PlayerID player, VehicleType vehicle_type, TileIndex depot_tile);
src/vehiclelist.cpp
Show inline comments
 
@@ -67,6 +67,7 @@ void BuildDepotVehicleList(VehicleType t
 
 *      <li>VLW_STANDARD: not used<li>
 
 *      <li>VLW_DEPOT_LIST: TileIndex of the depot/hangar to make the list for</li>
 
 *      <li>VLW_GROUP_LIST: index of group to generate a list for</li>
 
 *      <li>VLM_WAYPOINT_LIST: index of waypoint to generate a list for</li>
 
 *    </ul>
 
 * @param window_type The type of window the list is for, using the VLW_ flags in vehicle_gui.h
 
 */
 
@@ -122,6 +123,21 @@ void GenerateVehicleSortList(VehicleList
 
			}
 
			break;
 

	
 
		case VLM_WAYPOINT_LIST:
 
			FOR_ALL_VEHICLES(v) {
 
				if (v->type == type && v->IsPrimaryVehicle()) {
 
					const Order *order;
 

	
 
					FOR_VEHICLE_ORDERS(v, order) {
 
						if (order->IsType(OT_GOTO_WAYPOINT) && order->GetDestination() == index) {
 
							*list->Append() = v;
 
							break;
 
						}
 
					}
 
				}
 
			}
 
			break;
 

	
 
		case VLW_GROUP_LIST:
 
			FOR_ALL_VEHICLES(v) {
 
				if (v->type == type && v->IsPrimaryVehicle() &&
src/viewport.cpp
Show inline comments
 
@@ -1934,7 +1934,7 @@ static bool CheckClickOnWaypoint(const V
 
						y < wp->sign.top + 12 &&
 
						x >= wp->sign.left &&
 
						x < wp->sign.left + wp->sign.width_1) {
 
					ShowRenameWaypointWindow(wp);
 
					ShowWaypointWindow(wp);
 
					return true;
 
				}
 
			}
 
@@ -1948,7 +1948,7 @@ static bool CheckClickOnWaypoint(const V
 
						y < wp->sign.top + 24 &&
 
						x >= wp->sign.left &&
 
						x < wp->sign.left + wp->sign.width_1 * 2) {
 
					ShowRenameWaypointWindow(wp);
 
					ShowWaypointWindow(wp);
 
					return true;
 
				}
 
			}
 
@@ -1964,7 +1964,7 @@ static bool CheckClickOnWaypoint(const V
 
						y < wp->sign.top + ScaleByZoom(12, vp->zoom) &&
 
						x >= wp->sign.left &&
 
						x < wp->sign.left + ScaleByZoom(wp->sign.width_2, vp->zoom)) {
 
					ShowRenameWaypointWindow(wp);
 
					ShowWaypointWindow(wp);
 
					return true;
 
				}
 
			}
src/waypoint.h
Show inline comments
 
@@ -65,7 +65,7 @@ static inline Waypoint *GetWaypointByTil
 

	
 
CommandCost RemoveTrainWaypoint(TileIndex tile, uint32 flags, bool justremove);
 
Station *ComposeWaypointStation(TileIndex tile);
 
void ShowRenameWaypointWindow(const Waypoint *cp);
 
void ShowWaypointWindow(const Waypoint *wp);
 
void DrawWaypointSprite(int x, int y, int stat_id, RailType railtype);
 
void FixOldWaypoints();
 
void UpdateAllWaypointSigns();
src/waypoints_gui.cpp
Show inline comments
 
new file 100644
 
/* $Id$ */
 

	
 
/** @file waypoint_gui.cpp Handling of waypoints gui. */
 

	
 
#include "stdafx.h"
 
#include "openttd.h"
 
#include "window_gui.h"
 
#include "gui.h"
 
#include "textbuf_gui.h"
 
#include "vehicle_gui.h"
 
#include "waypoint.h"
 
#include "viewport_func.h"
 
#include "string_func.h"
 
#include "strings_func.h"
 
#include "gfx_func.h"
 
#include "command_func.h"
 
#include "functions.h"
 

	
 
#include "table/strings.h"
 

	
 
struct WaypointWindow : Window {
 
private:
 
	Waypoint *wp;
 

	
 
	enum WaypointViewWidget {
 
		WAYPVW_CLOSEBOX = 0,
 
		WAYPVW_CAPTION,
 
		WAYPVW_STICKY,
 
		WAYPVW_VIEWPORTPANEL,
 
		WAYPVW_SPACER,
 
		WAYPVW_CENTERVIEW,
 
		WAYPVW_RENAME,
 
		WAYPVW_SHOW_TRAINS,
 
	};
 

	
 
public:
 
	WaypointWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number)
 
	{
 
		this->wp = GetWaypoint(this->window_number);
 

	
 
		this->flags4 |= WF_DISABLE_VP_SCROLL;
 
		InitializeWindowViewport(this, 3, 17, 254, 86, this->wp->xy, ZOOM_LVL_MIN);
 

	
 
		this->FindWindowPlacementAndResize(desc);
 
	}
 

	
 
	virtual void OnPaint()
 
	{
 
		/* You can only change your own waypoints */
 
		this->SetWidgetDisabledState(WAYPVW_RENAME, !CheckTileOwnership(this->wp->xy));
 
		SetDParam(0, this->wp->index);
 
		this->DrawWidgets();
 

	
 
		this->DrawViewport();
 
	}
 

	
 
	virtual void OnClick(Point pt, int widget)
 
	{
 
		switch (widget) {
 
			case WAYPVW_CENTERVIEW: /* scroll to location */
 
				if (_ctrl_pressed) {
 
					ShowExtraViewPortWindow(this->wp->xy);
 
				} else {
 
					ScrollMainWindowToTile(this->wp->xy);
 
				}
 
				break;
 

	
 
			case WAYPVW_RENAME: /* rename */
 
				SetDParam(0, this->wp->index);
 
				ShowQueryString(STR_WAYPOINT_RAW, STR_EDIT_WAYPOINT_NAME, MAX_LENGTH_WAYPOINT_NAME_BYTES, MAX_LENGTH_WAYPOINT_NAME_PIXELS, this, CS_ALPHANUMERAL);
 
				break;
 

	
 
			case WAYPVW_SHOW_TRAINS: /* show list of trains having this waypoint in their orders*/
 
				ShowVehicleListWindow(this->wp);
 
				break;
 
		}
 
	}
 

	
 
	virtual void OnQueryTextFinished(char *str)
 
	{
 
		if (!StrEmpty(str)) {
 
			_cmd_text = str;
 
			DoCommandP(0, this->window_number, 0, NULL, CMD_RENAME_WAYPOINT | CMD_MSG(STR_CANT_CHANGE_WAYPOINT_NAME));
 
		}
 
	}
 

	
 
};
 

	
 
static const Widget _waypoint_view_widgets[] = {
 
{   WWT_CLOSEBOX,   RESIZE_NONE,  COLOUR_GREY,     0,    10,     0,    13, STR_00C5,              STR_018B_CLOSE_WINDOW},                 // WAYPVW_CLOSEBOX
 
{    WWT_CAPTION,   RESIZE_NONE,  COLOUR_GREY,    11,   247,     0,    13, STR_WAYPOINT_VIEWPORT, STR_018C_WINDOW_TITLE_DRAG_THIS},       // WAYPVW_CAPTION
 
{  WWT_STICKYBOX,   RESIZE_NONE,  COLOUR_GREY,   248,   259,     0,    13, 0x0,                   STR_STICKY_BUTTON},                     // WAYPVW_STICKY
 
{      WWT_PANEL,   RESIZE_NONE,  COLOUR_GREY,     0,   259,    14,   105, 0x0,                   STR_NULL},                              // WAYPVW_VIEWPORTPANEL
 
{      WWT_INSET,   RESIZE_NONE,  COLOUR_GREY,     2,   257,    16,   103, 0x0,                   STR_NULL},                              // WAYPVW_SPACER
 
{ WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_GREY,     0,   121,   106,   117, STR_00E4_LOCATION,     STR_3053_CENTER_MAIN_VIEW_ON_STATION},  // WAYPVW_CENTERVIEW
 
{ WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_GREY,   122,   244,   106,   117, STR_0130_RENAME,       STR_CHANGE_WAYPOINT_NAME},              // WAYPVW_RENAME
 
{ WWT_PUSHTXTBTN,   RESIZE_NONE,  COLOUR_GREY,   245,   259,   106,   117, STR_TRAIN,             STR_SCHEDULED_TRAINS_TIP },             // WAYPVW_SHOW_TRAINS
 
{   WIDGETS_END},
 
};
 

	
 
static const WindowDesc _waypoint_view_desc = {
 
	WDP_AUTO, WDP_AUTO, 260, 118, 260, 118,
 
	WC_WAYPOINT_VIEW, WC_NONE,
 
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON,
 
	_waypoint_view_widgets,
 
};
 

	
 
void ShowWaypointWindow(const Waypoint *wp)
 
{
 
	AllocateWindowDescFront<WaypointWindow>(&_waypoint_view_desc, wp->index);
 
}
src/window_type.h
Show inline comments
 
@@ -94,6 +94,7 @@ enum WindowClass {
 
	WC_BUILD_SIGNAL,
 
	WC_COMPANY_PASSWORD_WINDOW,
 
	WC_OSK,
 
	WC_WAYPOINT_VIEW,
 

	
 
	WC_INVALID = 0xFFFF
 
};
0 comments (0 inline, 0 general)