Changeset - r9314:0cd85d317c52
[Not reviewed]
master
0 4 0
rubidium - 16 years ago 2008-05-19 09:24:03
rubidium@openttd.org
(svn r13182) -Doc: add documentation to mostly rail_gui related functions. Patch by Alberth.
4 files changed with 147 insertions and 27 deletions:
0 comments (0 inline, 0 general)
src/misc_gui.cpp
Show inline comments
 
@@ -1078,16 +1078,16 @@ static const WindowDesc _query_string_de
 
};
 

	
 
/** Show a query popup window with a textbox in it.
 
 * @param str StringID for the text shown in the textbox
 
 * @param caption StringID of text shown in caption of querywindow
 
 * @param maxlen maximum length in characters allowed. If bit 12 is set we
 
 * will not check the resulting string against to original string to return success
 
 *               will not check the resulting string against to original string to return success
 
 * @param maxwidth maximum width in pixels allowed
 
 * @param parent pointer to a Window that will handle the events (ok/cancel) of this
 
 * window. If NULL, results are handled by global function HandleOnEditText
 
 *        window. If NULL, results are handled by global function HandleOnEditText
 
 * @param afilter filters out unwanted character input */
 
void ShowQueryString(StringID str, StringID caption, uint maxlen, uint maxwidth, Window *parent, CharSetFilter afilter)
 
{
 
	uint realmaxlen = maxlen & ~0x1000;
 

	
 
	DeleteWindowById(WC_QUERY_STRING, 0);
src/osk_gui.cpp
Show inline comments
 
@@ -343,13 +343,13 @@ void GetKeyboardLayout()
 
		ShowInfoF("Caps Lock:        %s", keyboard[1]);
 
		ShowInfoF("                  %s", errormark[1]);
 
	}
 
}
 

	
 
/**
 
 * Show the osk associated with a given textbox
 
 * Show the on-screen keyboard (osk) associated with a given textbox
 
 * @param parent pointer to the Window where this keyboard originated from
 
 * @param q      querystr_d pointer to the query string of the parent, which is
 
 *               shared for both windows
 
 * @param button widget number of parent's textbox
 
 * @param cancel widget number of parent's cancel button (0 if cancel events
 
 *               should not be passed)
src/rail_gui.cpp
Show inline comments
 
@@ -39,31 +39,31 @@
 
#include "tunnel_map.h"
 
#include "tunnelbridge_map.h"
 

	
 
#include "table/sprites.h"
 
#include "table/strings.h"
 

	
 
static RailType _cur_railtype;
 
static bool _remove_button_clicked;
 
static DiagDirection _build_depot_direction;
 
static byte _waypoint_count = 1;
 
static byte _cur_waypoint_type;
 
static bool _convert_signal_button;       ///< convert signal button in the signal GUI pressed
 
static SignalVariant _cur_signal_variant; ///< set the signal variant (for signal GUI)
 
static SignalType _cur_signal_type;       ///< set the signal type (for signal GUI)
 
static RailType _cur_railtype;               ///< Rail type of the current build-rail toolbar.
 
static bool _remove_button_clicked;          ///< Flag whether 'remove' toggle-button is currently enabled
 
static DiagDirection _build_depot_direction; ///< Currently selected depot direction
 
static byte _waypoint_count = 1;             ///< Number of waypoint types
 
static byte _cur_waypoint_type;              ///< Currently selected waypoint type
 
static bool _convert_signal_button;          ///< convert signal button in the signal GUI pressed
 
static SignalVariant _cur_signal_variant;    ///< set the signal variant (for signal GUI)
 
static SignalType _cur_signal_type;          ///< set the signal type (for signal GUI)
 

	
 
static struct {
 
	byte orientation;
 
	byte numtracks;
 
	byte platlength;
 
	bool dragdrop;
 
	byte orientation;                 ///< Currently selected rail station orientation
 
	byte numtracks;                   ///< Currently selected number of tracks in station (if not \c dragdrop )
 
	byte platlength;                  ///< Currently selected platform length of station (if not \c dragdrop )
 
	bool dragdrop;                    ///< Use drag & drop to place a station
 

	
 
	bool newstations;
 
	StationClassIDByte station_class;
 
	byte station_type;
 
	byte station_count;
 
	bool newstations;                 ///< Are custom station definitions available?
 
	StationClassIDByte station_class; ///< Currently selected custom station class (if newstations is \c true )
 
	byte station_type;                ///< Station type within the currently selected custom station class (if newstations is \c true )
 
	byte station_count;               ///< Number of custom stations (if newstations is \c true )
 
} _railstation;
 

	
 

	
 
static void HandleStationPlacement(TileIndex start, TileIndex end);
 
static void ShowBuildTrainDepotPicker();
 
static void ShowBuildWaypointPicker();
 
@@ -108,24 +108,31 @@ static void PlaceRail_NW(TileIndex tile)
 

	
 
static void PlaceRail_AutoRail(TileIndex tile)
 
{
 
	VpStartPlaceSizing(tile, VPM_RAILDIRS, DDSP_PLACE_AUTORAIL);
 
}
 

	
 
/**
 
 * Try to add an additional rail-track at the entrance of a depot
 
 * @param tile  Tile to use for adding the rail-track
 
 * @param extra Track to add
 
 * @see CcRailDepot()
 
 */
 
static void PlaceExtraDepotRail(TileIndex tile, uint16 extra)
 
{
 
	if (GetRailTileType(tile) != RAIL_TILE_NORMAL) return;
 
	if ((GetTrackBits(tile) & GB(extra, 8, 8)) == 0) return;
 

	
 
	DoCommandP(tile, _cur_railtype, extra & 0xFF, NULL, CMD_BUILD_SINGLE_RAIL | CMD_NO_WATER);
 
}
 

	
 
/** Additional pieces of track to add at the entrance of a depot. */
 
static const uint16 _place_depot_extra[12] = {
 
	0x0604, 0x2102, 0x1202, 0x0505,
 
	0x2400, 0x2801, 0x1800, 0x1401,
 
	0x2203, 0x0904, 0x0A05, 0x1103,
 
	0x0604, 0x2102, 0x1202, 0x0505,  // First additional track for directions 0..3
 
	0x2400, 0x2801, 0x1800, 0x1401,  // Second additional track
 
	0x2203, 0x0904, 0x0A05, 0x1103,  // Third additional track
 
};
 

	
 

	
 
void CcRailDepot(bool success, TileIndex tile, uint32 p1, uint32 p2)
 
{
 
	if (success) {
 
@@ -232,12 +239,13 @@ static void GenericPlaceSignals(TileInde
 

	
 
static void PlaceRail_Bridge(TileIndex tile)
 
{
 
	VpStartPlaceSizing(tile, VPM_X_OR_Y, DDSP_BUILD_BRIDGE);
 
}
 

	
 
/** Command callback for building a tunnel */
 
void CcBuildRailTunnel(bool success, TileIndex tile, uint32 p1, uint32 p2)
 
{
 
	if (success) {
 
		SndPlayTileFx(SND_20_SPLAT_2, tile);
 
		ResetObjectToPlace();
 
	} else {
 
@@ -282,13 +290,13 @@ enum RailToolbarWidgets {
 
	RTW_BUILD_TUNNEL,
 
	RTW_REMOVE,
 
	RTW_CONVERT_RAIL,
 
};
 

	
 

	
 
/** Toogles state of the Remove button of Build rail toolbar
 
/** Toggles state of the Remove button of Build rail toolbar
 
 * @param w window the button belongs to
 
 */
 
static void ToggleRailButton_Remove(Window *w)
 
{
 
	w->ToggleWidgetLoweredState(RTW_REMOVE);
 
	w->InvalidateWidget(RTW_REMOVE);
 
@@ -313,83 +321,149 @@ static bool RailToolbar_CtrlChanged(Wind
 
	}
 

	
 
	return false;
 
}
 

	
 

	
 
/**
 
 * The "rail N"-button click proc of the build-rail toolbar.
 
 * @param w Build-rail toolbar window
 
 * @see BuildRailToolbWndProc()
 
 */
 
static void BuildRailClick_N(Window *w)
 
{
 
	HandlePlacePushButton(w, RTW_BUILD_NS, GetRailTypeInfo(_cur_railtype)->cursor.rail_ns, VHM_RECT, PlaceRail_N);
 
}
 

	
 
/**
 
 * The "rail NE"-button click proc of the build-rail toolbar.
 
 * @param w Build-rail toolbar window
 
 * @see BuildRailToolbWndProc()
 
 */
 
static void BuildRailClick_NE(Window *w)
 
{
 
	HandlePlacePushButton(w, RTW_BUILD_X, GetRailTypeInfo(_cur_railtype)->cursor.rail_swne, VHM_RECT, PlaceRail_NE);
 
}
 

	
 
/**
 
 * The "rail E"-button click proc of the build-rail toolbar.
 
 * @param w Build-rail toolbar window
 
 * @see BuildRailToolbWndProc()
 
 */
 
static void BuildRailClick_E(Window *w)
 
{
 
	HandlePlacePushButton(w, RTW_BUILD_EW, GetRailTypeInfo(_cur_railtype)->cursor.rail_ew, VHM_RECT, PlaceRail_E);
 
}
 

	
 
/**
 
 * The "rail NW"-button click proc of the build-rail toolbar.
 
 * @param w Build-rail toolbar window
 
 * @see BuildRailToolbWndProc()
 
 */
 
static void BuildRailClick_NW(Window *w)
 
{
 
	HandlePlacePushButton(w, RTW_BUILD_Y, GetRailTypeInfo(_cur_railtype)->cursor.rail_nwse, VHM_RECT, PlaceRail_NW);
 
}
 

	
 
/**
 
 * The "auto-rail"-button click proc of the build-rail toolbar.
 
 * @param w Build-rail toolbar window
 
 * @see BuildRailToolbWndProc()
 
 */
 
static void BuildRailClick_AutoRail(Window *w)
 
{
 
	HandlePlacePushButton(w, RTW_AUTORAIL, GetRailTypeInfo(_cur_railtype)->cursor.autorail, VHM_RAIL, PlaceRail_AutoRail);
 
}
 

	
 
/**
 
 * The "demolish"-button click proc of the build-rail toolbar.
 
 * @param w Build-rail toolbar window
 
 * @see BuildRailToolbWndProc()
 
 */
 
static void BuildRailClick_Demolish(Window *w)
 
{
 
	HandlePlacePushButton(w, RTW_DEMOLISH, ANIMCURSOR_DEMOLISH, VHM_RECT, PlaceProc_DemolishArea);
 
}
 

	
 
/**
 
 * The "build depot"-button click proc of the build-rail toolbar.
 
 * @param w Build-rail toolbar window
 
 * @see BuildRailToolbWndProc()
 
 */
 
static void BuildRailClick_Depot(Window *w)
 
{
 
	if (HandlePlacePushButton(w, RTW_BUILD_DEPOT, GetRailTypeInfo(_cur_railtype)->cursor.depot, VHM_RECT, PlaceRail_Depot)) {
 
		ShowBuildTrainDepotPicker();
 
	}
 
}
 

	
 
/**
 
 * The "build waypoint"-button click proc of the build-rail toolbar.
 
 * If there are newGRF waypoints, also open a window to pick the waypoint type.
 
 * @param w Build-rail toolbar window
 
 * @see BuildRailToolbWndProc()
 
 */
 
static void BuildRailClick_Waypoint(Window *w)
 
{
 
	_waypoint_count = GetNumCustomStations(STAT_CLASS_WAYP);
 
	if (HandlePlacePushButton(w, RTW_BUILD_WAYPOINT, SPR_CURSOR_WAYPOINT, VHM_RECT, PlaceRail_Waypoint) &&
 
			_waypoint_count > 1) {
 
		ShowBuildWaypointPicker();
 
	}
 
}
 

	
 
/**
 
 * The "build station"-button click proc of the build-rail toolbar.
 
 * @param w Build-rail toolbar window
 
 * @see BuildRailToolbWndProc()
 
 */
 
static void BuildRailClick_Station(Window *w)
 
{
 
	if (HandlePlacePushButton(w, RTW_BUILD_STATION, SPR_CURSOR_RAIL_STATION, VHM_RECT, PlaceRail_Station)) ShowStationBuilder();
 
}
 

	
 
/** The "build signal"-button proc from BuildRailToolbWndProc() (start ShowSignalBuilder() and/or HandleAutoSignalPlacement()) */
 
/**
 
 * The "build signal"-button click proc of the build-rail toolbar.
 
 * Start ShowSignalBuilder() and/or HandleAutoSignalPlacement().
 
 * @param w Build-rail toolbar window
 
 * @see BuildRailToolbWndProc()
 
 */
 
static void BuildRailClick_AutoSignals(Window *w)
 
{
 
	if (_patches.enable_signal_gui != _ctrl_pressed) {
 
		if (HandlePlacePushButton(w, RTW_BUILD_SIGNALS, ANIMCURSOR_BUILDSIGNALS, VHM_RECT, PlaceRail_AutoSignals)) ShowSignalBuilder();
 
	} else {
 
		HandlePlacePushButton(w, RTW_BUILD_SIGNALS, ANIMCURSOR_BUILDSIGNALS, VHM_RECT, PlaceRail_AutoSignals);
 
	}
 
}
 

	
 
/**
 
 * The "build bridge"-button click proc of the build-rail toolbar.
 
 * @param w Build-rail toolbar window
 
 * @see BuildRailToolbWndProc()
 
 */
 
static void BuildRailClick_Bridge(Window *w)
 
{
 
	HandlePlacePushButton(w, RTW_BUILD_BRIDGE, SPR_CURSOR_BRIDGE, VHM_RECT, PlaceRail_Bridge);
 
}
 

	
 
/**
 
 * The "build tunnel"-button click proc of the build-rail toolbar.
 
 * @param w Build-rail toolbar window
 
 * @see BuildRailToolbWndProc()
 
 */
 
static void BuildRailClick_Tunnel(Window *w)
 
{
 
	HandlePlacePushButton(w, RTW_BUILD_TUNNEL, GetRailTypeInfo(_cur_railtype)->cursor.tunnel, VHM_SPECIAL, PlaceRail_Tunnel);
 
}
 

	
 
/**
 
 * The "remove"-button click proc of the build-rail toolbar.
 
 * @param w Build-rail toolbar window
 
 * @see BuildRailToolbWndProc()
 
 */
 
static void BuildRailClick_Remove(Window *w)
 
{
 
	if (w->IsWidgetDisabled(RTW_REMOVE)) return;
 
	ToggleRailButton_Remove(w);
 
	SndPlayFx(SND_15_BEEP);
 

	
 
@@ -413,12 +487,18 @@ static void BuildRailClick_Remove(Window
 
				VpSetPlaceSizingLimit(_patches.station_spread);
 
			}
 
		}
 
	}
 
}
 

	
 
/**
 
 * The "convert-rail"-button click proc of the build-rail toolbar.
 
 * Switches to 'convert-rail' mode
 
 * @param w Build-rail toolbar window
 
 * @see BuildRailToolbWndProc()
 
 */
 
static void BuildRailClick_Convert(Window *w)
 
{
 
	HandlePlacePushButton(w, RTW_CONVERT_RAIL, GetRailTypeInfo(_cur_railtype)->cursor.convert, VHM_RECT, PlaceRail_ConvertRail);
 
}
 

	
 

	
 
@@ -523,12 +603,17 @@ static const uint16 _rail_keycodes[] = {
 
	'T', // tunnel
 
	'R', // remove
 
	'C', // convert rail
 
};
 

	
 

	
 
/**
 
 * Based on the widget clicked, update the status of the 'remove' button.
 
 * @param w              Rail toolbar window
 
 * @param clicked_widget Widget clicked in the toolbar
 
 */
 
struct BuildRailToolbarWindow : Window {
 
	BuildRailToolbarWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number)
 
	{
 
		this->DisableWidget(RTW_REMOVE);
 

	
 
		this->FindWindowPlacementAndResize(desc);
 
@@ -737,12 +822,23 @@ static void SetupRailToolbar(RailType ra
 
	w->widget[RTW_AUTORAIL].data = rti->gui_sprites.auto_rail;
 
	w->widget[RTW_BUILD_DEPOT].data = rti->gui_sprites.build_depot;
 
	w->widget[RTW_CONVERT_RAIL].data = rti->gui_sprites.convert_rail;
 
	w->widget[RTW_BUILD_TUNNEL].data = rti->gui_sprites.build_tunnel;
 
}
 

	
 
/**
 
 * Open the build rail toolbar window for a specific rail type.
 
 * The window may be opened in the 'normal' way by clicking at the rail icon in
 
 * the main toolbar, or by means of selecting one of the functions of the
 
 * toolbar. In the latter case, the corresponding widget is also selected.
 
 *
 
 * If the terraform toolbar is linked to the toolbar, that window is also opened.
 
 *
 
 * @param railtype Rail type to open the window for
 
 * @param button   Widget clicked (\c -1 means no button clicked)
 
 */
 
void ShowBuildRailToolbar(RailType railtype, int button)
 
{
 
	BuildRailToolbarWindow *w;
 

	
 
	if (!IsValidPlayer(_current_player)) return;
 
	if (!ValParamRailtype(railtype)) return;
 
@@ -821,17 +917,22 @@ private:
 

	
 
		BRSW_NEWST_DROPDOWN,
 
		BRSW_NEWST_LIST,
 
		BRSW_NEWST_SCROLL
 
	};
 

	
 
	/* Check if the currently selected station size is allowed */
 
	/**
 
	 * Verify whether the currently selected station size is allowed after selecting a new station class/type.
 
	 * If not, change the station size variables ( _railstation.numtracks and _railstation.platlength ).
 
	 * @param statspec Specification of the new station class/type
 
	 */
 
	void CheckSelectedSize(const StationSpec *statspec)
 
	{
 
		if (statspec == NULL || _railstation.dragdrop) return;
 

	
 
		/* If current number of tracks is not allowed, make it as big as possible (which is always less than currently selected) */
 
		if (HasBit(statspec->disallowed_platforms, _railstation.numtracks - 1)) {
 
			this->RaiseWidget(_railstation.numtracks + BRSW_PLATFORM_NUM_BEGIN);
 
			_railstation.numtracks = 1;
 
			while (HasBit(statspec->disallowed_platforms, _railstation.numtracks - 1)) {
 
				_railstation.numtracks++;
 
			}
 
@@ -845,23 +946,29 @@ private:
 
				_railstation.platlength++;
 
			}
 
			this->LowerWidget(_railstation.platlength + BRSW_PLATFORM_LEN_BEGIN);
 
		}
 
	}
 

	
 
	/** Build a dropdown list of available station classes */
 
	static DropDownList *BuildStationClassDropDown()
 
	{
 
		DropDownList *list = new DropDownList();
 

	
 
		for (uint i = 0; i < GetNumStationClasses(); i++) {
 
			if (i == STAT_CLASS_WAYP) continue;
 
			list->push_back(new DropDownListStringItem(GetStationClassName((StationClassID)i), i, false));
 
		}
 

	
 
		return list;
 
	}
 
/**
 
 * Window event handler of station build window.
 
 * @param w Staion build window
 
 * @param e Window event to handle
 
 */
 

	
 
public:
 
	BuildRailStationWindow(const WindowDesc *desc, bool newstation) : PickerWindowBase(desc)
 
	{
 
		this->LowerWidget(_railstation.orientation + BRSW_PLATFORM_DIR_X);
 
		if (_railstation.dragdrop) {
 
@@ -1207,28 +1314,31 @@ static const Widget _newstation_builder_
 
{ WWT_DROPDOWNIN,   RESIZE_NONE,    14,     7,   140,    17,    28, STR_02BD,                        STR_SELECT_STATION_CLASS_TIP},        // BRSW_NEWST_DROPDOWN
 
{     WWT_MATRIX,   RESIZE_NONE,    14,     7,   128,    32,   102, 0x501,                           STR_SELECT_STATION_TYPE_TIP},         // BRSW_NEWST_LIST
 
{  WWT_SCROLLBAR,   RESIZE_NONE,    14,   129,   140,    32,   102, 0x0,                             STR_0190_SCROLL_BAR_SCROLLS_LIST},    // BRSW_NEWST_SCROLL
 
{   WIDGETS_END},
 
};
 

	
 
/** High level window description of the default station-build window */
 
static const WindowDesc _station_builder_desc = {
 
	WDP_AUTO, WDP_AUTO, 148, 200, 148, 200,
 
	WC_BUILD_STATION, WC_BUILD_TOOLBAR,
 
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
 
	_station_builder_widgets,
 
	NULL
 
};
 

	
 
/** High level window description of the newGRF station-build window */
 
static const WindowDesc _newstation_builder_desc = {
 
	WDP_AUTO, WDP_AUTO, 148, 290, 148, 290,
 
	WC_BUILD_STATION, WC_BUILD_TOOLBAR,
 
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
 
	_newstation_builder_widgets,
 
	NULL
 
};
 

	
 
/** Open station build window */
 
static void ShowStationBuilder()
 
{
 
	if (GetNumStationClasses() <= 2 && GetNumCustomStations(STAT_CLASS_DFLT) == 1) {
 
		new BuildRailStationWindow(&_station_builder_desc, false);
 
	} else {
 
		new BuildRailStationWindow(&_newstation_builder_desc, true);
 
@@ -1558,21 +1668,27 @@ static const WindowDesc _build_waypoint_
 

	
 
static void ShowBuildWaypointPicker()
 
{
 
	new BuildRailWaypointWindow(&_build_waypoint_desc);
 
}
 

	
 

	
 
/**
 
 * Initialize rail building GUI settings
 
 */
 
void InitializeRailGui()
 
{
 
	_build_depot_direction = DIAGDIR_NW;
 
	_railstation.numtracks = 1;
 
	_railstation.platlength = 1;
 
	_railstation.dragdrop = true;
 
}
 

	
 
/**
 
 * Re-initialize rail-build toolbar after toggling support for electric trains
 
 * @param disable Boolean whether electric trains are disabled (removed from the game)
 
 */
 
void ReinitGuiAfterToggleElrail(bool disable)
 
{
 
	extern RailType _last_built_railtype;
 
	if (disable && _last_built_railtype == RAILTYPE_ELECTRIC) {
 
		Window *w;
 
		_last_built_railtype = _cur_railtype = RAILTYPE_RAIL;
 
@@ -1582,12 +1698,13 @@ void ReinitGuiAfterToggleElrail(bool dis
 
			w->SetDirty();
 
		}
 
	}
 
	MarkWholeScreenDirty();
 
}
 

	
 
/** Set the initial (default) railtype to use */
 
static void SetDefaultRailGui()
 
{
 
	if (_local_player == PLAYER_SPECTATOR || !IsValidPlayer(_local_player)) return;
 

	
 
	extern RailType _last_built_railtype;
 
	RailType rt = (RailType)_patches.default_rail_type;
src/viewport.cpp
Show inline comments
 
@@ -2658,13 +2658,16 @@ calc_heightdiff_single_direction:;
 
	}
 

	
 
	_thd.selend.x = x;
 
	_thd.selend.y = y;
 
}
 

	
 
/** while dragging */
 
/**
 
 * Handle the mouse while dragging for placement/resizing.
 
 * @return Boolean whether search for a handler should continue
 
 */
 
bool VpHandlePlaceSizingDrag()
 
{
 
	if (_special_mouse_mode != WSM_SIZING) return true;
 

	
 
	/* stop drag mode if the window has been closed */
 
	Window *w = FindWindowById(_thd.window_class, _thd.window_number);
0 comments (0 inline, 0 general)