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
 
@@ -37,6 +37,7 @@ static byte _selected_airport_layout;   
 

	
 
static void ShowBuildAirportPicker(Window *parent);
 

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

	
 
void CcBuildAirport(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
 
{
 
@@ -202,6 +203,7 @@ enum AirportPickerWidgets {
 
	BAIRW_LAYOUT_NUM,
 
	BAIRW_LAYOUT_DECREASE,
 
	BAIRW_LAYOUT_INCREASE,
 
	BAIRW_AIRPORT_SPRITE,
 
	BAIRW_BOTTOMPANEL,
 
	BAIRW_COVERAGE_LABEL,
 
	BAIRW_BTN_DONTHILIGHT,
 
@@ -209,6 +211,7 @@ enum AirportPickerWidgets {
 
};
 

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

	
 
	/** Build a dropdown list of available airport classes */
 
@@ -287,22 +290,48 @@ public:
 
				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;
 
		}
 
	}
 

	
 
@@ -344,6 +373,11 @@ public:
 
		_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();
 
	}
 
@@ -472,6 +506,7 @@ static const NWidgetPart _nested_build_a
 
			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),
src/newgrf_airport.cpp
Show inline comments
 
@@ -322,6 +322,19 @@ static void NewAirportResolver(ResolverO
 
	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;
src/newgrf_airport.h
Show inline comments
 
@@ -16,6 +16,7 @@
 
#include "map_type.h"
 
#include "strings_type.h"
 
#include "newgrf_commons.h"
 
#include "gfx_type.h"
 

	
 
/* Copy from station_map.h */
 
typedef byte StationGfx;
 
@@ -72,6 +73,7 @@ struct AirportSpec {
 
	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
src/table/airport_defaults.h
Show inline comments
 
@@ -382,7 +382,7 @@ static Direction _default_airports_rotat
 

	
 
/** 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) \
0 comments (0 inline, 0 general)