Changeset - r15693:10940496c385
[Not reviewed]
master
0 4 0
yexo - 14 years ago 2010-08-05 12:03:34
yexo@openttd.org
(svn r20369) -Feature: preview sprites for airports
4 files changed with 60 insertions and 10 deletions:
0 comments (0 inline, 0 general)
src/airport_gui.cpp
Show inline comments
 
@@ -34,12 +34,13 @@
 
static AirportClassID _selected_airport_class; ///< the currently visible airport class
 
static int _selected_airport_index;            ///< the index of the selected airport in the current class or -1
 
static byte _selected_airport_layout;          ///< selected airport layout number.
 

	
 
static void ShowBuildAirportPicker(Window *parent);
 

	
 
SpriteID GetCustomAirportSprite(const AirportSpec *as, byte layout);
 

	
 
void CcBuildAirport(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
 
{
 
	if (result.Failed()) return;
 

	
 
	SndPlayTileFx(SND_1F_SPLAT, tile);
 
@@ -199,19 +200,21 @@ enum AirportPickerWidgets {
 
	BAIRW_CLASS_DROPDOWN,
 
	BAIRW_AIRPORT_LIST,
 
	BAIRW_SCROLLBAR,
 
	BAIRW_LAYOUT_NUM,
 
	BAIRW_LAYOUT_DECREASE,
 
	BAIRW_LAYOUT_INCREASE,
 
	BAIRW_AIRPORT_SPRITE,
 
	BAIRW_BOTTOMPANEL,
 
	BAIRW_COVERAGE_LABEL,
 
	BAIRW_BTN_DONTHILIGHT,
 
	BAIRW_BTN_DOHILIGHT,
 
};
 

	
 
class BuildAirportWindow : public PickerWindowBase {
 
	SpriteID preview_sprite; ///< Cached airport preview sprite.
 
	int line_height;
 

	
 
	/** Build a dropdown list of available airport classes */
 
	static DropDownList *BuildAirportClassDropDown()
 
	{
 
		DropDownList *list = new DropDownList();
 
@@ -284,28 +287,54 @@ public:
 

	
 
				this->line_height = FONT_HEIGHT_NORMAL + WD_MATRIX_TOP + WD_MATRIX_BOTTOM;
 
				size->height = this->vscroll.GetCapacity() * this->line_height;
 
				break;
 
			}
 

	
 
			case BAIRW_AIRPORT_SPRITE:
 
				for (int i = 0; i < NUM_AIRPORTS; i++) {
 
					const AirportSpec *as = AirportSpec::Get(i);
 
					if (!as->enabled) continue;
 
					for (byte layout = 0; layout < as->num_table; layout++) {
 
						SpriteID sprite = GetCustomAirportSprite(as, layout);
 
						if (sprite != 0) {
 
							Dimension d = GetSpriteSize(sprite);
 
							d.width += WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT;
 
							d.height += WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
 
							*size = maxdim(d, *size);
 
						}
 
					}
 
				}
 
				break;
 

	
 
			default: break;
 
		}
 
	}
 

	
 
	virtual void DrawWidget(const Rect &r, int widget) const
 
	{
 
		if (widget != BAIRW_AIRPORT_LIST) return;
 
		switch (widget) {
 
			case BAIRW_AIRPORT_LIST: {
 
				int y = r.top;
 
				for (uint i = this->vscroll.GetPosition(); this->vscroll.IsVisible(i) && i < GetNumAirportsInClass(_selected_airport_class); i++) {
 
					const AirportSpec *as = GetAirportSpecFromClass(_selected_airport_class, i);
 
					if (!as->IsAvailable()) {
 
						GfxFillRect(r.left + 1, y + 1, r.right - 1, y + this->line_height - 2, 0, FILLRECT_CHECKER);
 
					}
 
					DrawString(r.left + WD_MATRIX_LEFT, r.right + WD_MATRIX_RIGHT, y + WD_MATRIX_TOP, as->name, ((int)i == _selected_airport_index) ? TC_WHITE : TC_BLACK);
 
					y += this->line_height;
 
				}
 
				break;
 
			}
 

	
 
		int y = r.top;
 
		for (uint i = this->vscroll.GetPosition(); this->vscroll.IsVisible(i) && i < GetNumAirportsInClass(_selected_airport_class); i++) {
 
			const AirportSpec *as = GetAirportSpecFromClass(_selected_airport_class, i);
 
			if (!as->IsAvailable()) {
 
				GfxFillRect(r.left + 1, y + 1, r.right - 1, y + this->line_height - 2, 0, FILLRECT_CHECKER);
 
			}
 
			DrawString(r.left + WD_MATRIX_LEFT, r.right + WD_MATRIX_RIGHT, y + WD_MATRIX_TOP, as->name, ((int)i == _selected_airport_index) ? TC_WHITE : TC_BLACK);
 
			y += this->line_height;
 
			case BAIRW_AIRPORT_SPRITE:
 
				if (this->preview_sprite != 0) {
 
					Dimension d = GetSpriteSize(this->preview_sprite);
 
					DrawSprite(this->preview_sprite, PAL_NONE, (r.left + r.right - d.width) / 2, (r.top + r.bottom - d.height) / 2);
 
				}
 
				break;
 
		}
 
	}
 

	
 
	virtual void OnPaint()
 
	{
 
		this->DrawWidgets();
 
@@ -341,12 +370,17 @@ public:
 

	
 
	void SelectOtherAirport(int airport_index)
 
	{
 
		_selected_airport_index = airport_index;
 
		_selected_airport_layout = 0;
 

	
 
		if (_selected_airport_index != -1) {
 
			const AirportSpec *as = GetAirportSpecFromClass(_selected_airport_class, _selected_airport_index);
 
			this->preview_sprite = GetCustomAirportSprite(as, _selected_airport_layout);
 
		}
 

	
 
		this->UpdateSelectSize();
 
		this->SetDirty();
 
	}
 

	
 
	void UpdateSelectSize()
 
	{
 
@@ -469,12 +503,13 @@ static const NWidgetPart _nested_build_a
 
		EndContainer(),
 
		NWidget(NWID_HORIZONTAL),
 
			NWidget(NWID_BUTTON_ARROW, COLOUR_GREY, BAIRW_LAYOUT_DECREASE), SetMinimalSize(12, 0),SetDataTip(AWV_DECREASE, STR_NULL),
 
			NWidget(WWT_LABEL, COLOUR_GREY, BAIRW_LAYOUT_NUM), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_BLACK_STRING, STR_NULL),
 
			NWidget(NWID_BUTTON_ARROW, COLOUR_GREY, BAIRW_LAYOUT_INCREASE), SetMinimalSize(12, 0), SetDataTip(AWV_INCREASE, STR_NULL),
 
		EndContainer(),
 
		NWidget(WWT_EMPTY, COLOUR_DARK_GREEN, BAIRW_AIRPORT_SPRITE), SetFill(1, 0),
 
	EndContainer(),
 
	/* Bottom panel. */
 
	NWidget(WWT_PANEL, COLOUR_DARK_GREEN, BAIRW_BOTTOMPANEL), SetPIP(2, 2, 2),
 
		NWidget(WWT_LABEL, COLOUR_DARK_GREEN), SetDataTip(STR_STATION_BUILD_COVERAGE_AREA_TITLE, STR_NULL), SetFill(1, 0),
 
		NWidget(NWID_HORIZONTAL),
 
			NWidget(NWID_SPACER), SetMinimalSize(14, 0), SetFill(1, 0),
src/newgrf_airport.cpp
Show inline comments
 
@@ -319,12 +319,25 @@ static void NewAirportResolver(ResolverO
 
	res->count           = 0;
 

	
 
	const AirportSpec *as = AirportSpec::Get(airport_id);
 
	res->grffile = (as != NULL ? as->grf_prop.grffile : NULL);
 
}
 

	
 
SpriteID GetCustomAirportSprite(const AirportSpec *as, byte layout)
 
{
 
	const SpriteGroup *group;
 
	ResolverObject object;
 

	
 
	NewAirportResolver(&object, INVALID_TILE, NULL, as->GetIndex(), layout);
 

	
 
	group = SpriteGroup::Resolve(as->grf_prop.spritegroup, &object);
 
	if (group == NULL) return as->preview_sprite;
 

	
 
	return group->GetResult();
 
}
 

	
 
uint16 GetAirportCallback(CallbackID callback, uint32 param1, uint32 param2, Station *st, TileIndex tile)
 
{
 
	ResolverObject object;
 

	
 
	NewAirportResolver(&object, tile, st, st->airport.type, st->airport.layout);
 
	object.callback = callback;
src/newgrf_airport.h
Show inline comments
 
@@ -13,12 +13,13 @@
 
#define NEWGRF_AIRPORT_H
 

	
 
#include "date_type.h"
 
#include "map_type.h"
 
#include "strings_type.h"
 
#include "newgrf_commons.h"
 
#include "gfx_type.h"
 

	
 
/* Copy from station_map.h */
 
typedef byte StationGfx;
 

	
 
/** Tile-offset / AirportTileID pair. */
 
struct AirportTileTable {
 
@@ -69,12 +70,13 @@ struct AirportSpec {
 
	byte catchment;                        ///< catchment area of this airport
 
	Year min_year;                         ///< first year the airport is available
 
	Year max_year;                         ///< last year the airport is available
 
	StringID name;                         ///< name of this airport
 
	TTDPAirportType ttd_airport_type;      ///< ttdpatch airport type (Small/Large/Helipad/Oilrig)
 
	AirportClassID aclass;                 ///< the class to which this airport type belongs
 
	SpriteID preview_sprite;               ///< preview sprite for this airport
 
	/* Newgrf data */
 
	bool enabled;                          ///< entity still avaible (by default true).newgrf can disable it, though
 
	GRFFileProps grf_prop;                 ///< properties related the the grf file
 

	
 
	static const AirportSpec *Get(byte type);
 
	static AirportSpec *GetWithoutOverride(byte type);
src/table/airport_defaults.h
Show inline comments
 
@@ -379,13 +379,13 @@ static Direction _default_airports_rotat
 

	
 
#undef MK
 
#undef MKEND
 

	
 
/** General AirportSpec definition. */
 
#define AS_GENERIC(fsm, att, rot, att_len, depot_tbl, num_depots, size_x, size_y, noise, catchment, min_year, max_year, ttdpatch_type, class_id, name, enabled) \
 
	{fsm, att, rot, att_len, depot_tbl, num_depots, size_x, size_y, noise, catchment, min_year, max_year, name, ttdpatch_type, class_id, enabled, {AT_INVALID, 0, NULL, NULL, AT_INVALID}}
 
	{fsm, att, rot, att_len, depot_tbl, num_depots, size_x, size_y, noise, catchment, min_year, max_year, name, ttdpatch_type, class_id, 0, enabled, {AT_INVALID, 0, NULL, NULL, AT_INVALID}}
 

	
 
/** AirportSpec definition for airports without any depot. */
 
#define AS_ND(ap_name, size_x, size_y, min_year, max_year, catchment, noise, ttdpatch_type, class_id, name) \
 
	AS_GENERIC(&_airportfta_##ap_name, _tile_table_##ap_name, _default_airports_rotation, lengthof(_tile_table_##ap_name), NULL, 0, \
 
		size_x, size_y, noise, catchment, min_year, max_year, ttdpatch_type, class_id, name, true)
 

	
0 comments (0 inline, 0 general)