summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoryexo <yexo@openttd.org>2010-08-05 12:03:34 +0000
committeryexo <yexo@openttd.org>2010-08-05 12:03:34 +0000
commit3e6f8165d47b0b414c98ffae3487c7bb9f557eae (patch)
tree25cdabbcebbdf6f2665597f4a51df08f19c74c06 /src
parent7e4bdbbc9dd9c7a4bb8f6c0af569aafece9d1443 (diff)
downloadopenttd-3e6f8165d47b0b414c98ffae3487c7bb9f557eae.tar.xz
(svn r20369) -Feature: preview sprites for airports
Diffstat (limited to 'src')
-rw-r--r--src/airport_gui.cpp53
-rw-r--r--src/newgrf_airport.cpp13
-rw-r--r--src/newgrf_airport.h2
-rw-r--r--src/table/airport_defaults.h2
4 files changed, 60 insertions, 10 deletions
diff --git a/src/airport_gui.cpp b/src/airport_gui.cpp
index 00297d62a..2b2730f6d 100644
--- a/src/airport_gui.cpp
+++ b/src/airport_gui.cpp
@@ -37,6 +37,7 @@ static byte _selected_airport_layout; ///< selected airport layout numb
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;
-
- 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);
+ 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;
}
- 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_airport_widgets[] = {
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),
diff --git a/src/newgrf_airport.cpp b/src/newgrf_airport.cpp
index 3355603a4..20533bc67 100644
--- a/src/newgrf_airport.cpp
+++ b/src/newgrf_airport.cpp
@@ -322,6 +322,19 @@ static void NewAirportResolver(ResolverObject *res, TileIndex tile, Station *st,
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;
diff --git a/src/newgrf_airport.h b/src/newgrf_airport.h
index 5895a00cb..20c6aa046 100644
--- a/src/newgrf_airport.h
+++ b/src/newgrf_airport.h
@@ -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
diff --git a/src/table/airport_defaults.h b/src/table/airport_defaults.h
index 5e2d82b72..c9cb88c16 100644
--- a/src/table/airport_defaults.h
+++ b/src/table/airport_defaults.h
@@ -382,7 +382,7 @@ static Direction _default_airports_rotation[] = {
/** 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) \