(svn r5336) - NewGRF: draw custom helicopter rotor sprites in vehicle info window, ensuring the correct direction is used (inspiration from mart3p)
--- a/aircraft_cmd.c Thu Jun 22 21:03:19 2006 +0000
+++ b/aircraft_cmd.c Thu Jun 22 21:15:27 2006 +0000
@@ -123,7 +123,7 @@
w = v->next->next;
if (is_custom_sprite(v->spritenum)) {
- SpriteID spritenum = GetCustomRotorSprite(v);
+ SpriteID spritenum = GetCustomRotorSprite(v, false);
if (spritenum != 0) return spritenum;
}
--- a/aircraft_gui.c Thu Jun 22 21:03:19 2006 +0000
+++ b/aircraft_gui.c Thu Jun 22 21:15:27 2006 +0000
@@ -79,7 +79,11 @@
{
PalSpriteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v);
DrawSprite(GetAircraftImage(v, DIR_W) | pal, x + 25, y + 10);
- if (v->subtype == 0) DrawSprite(SPR_ROTOR_STOPPED, x + 25, y + 5);
+ if (v->subtype == 0) {
+ SpriteID rotor_sprite = GetCustomRotorSprite(v, true);
+ if (rotor_sprite == 0) rotor_sprite = SPR_ROTOR_STOPPED;
+ DrawSprite(rotor_sprite, x + 25, y + 5);
+ }
if (v->index == selection) {
DrawFrameRect(x - 1, y - 1, x + 58, y + 21, 0xF, FR_BORDERONLY);
}
--- a/newgrf_engine.c Thu Jun 22 21:03:19 2006 +0000
+++ b/newgrf_engine.c Thu Jun 22 21:15:27 2006 +0000
@@ -660,7 +660,7 @@
case 0x1C: return v->y_pos;
case 0x1D: return v->y_pos & 0xFF;
case 0x1E: return v->z_pos;
- case 0x1F: return v->direction;
+ case 0x1F: return object->info_view ? DIR_W : v->direction;
case 0x28: return v->cur_image;
case 0x29: return v->cur_image & 0xFF;
case 0x32: return v->vehstatus;
@@ -799,6 +799,8 @@
res->u.vehicle.self = v;
res->u.vehicle.parent = (v != NULL && v->type == VEH_Train) ? GetFirstVehicleInChain(v) : v;
+ res->info_view = false;
+
res->callback = 0;
res->callback_param1 = 0;
res->callback_param2 = 0;
@@ -842,7 +844,7 @@
}
-SpriteID GetRotorOverrideSprite(EngineID engine, const Vehicle *v)
+SpriteID GetRotorOverrideSprite(EngineID engine, const Vehicle *v, bool info_view)
{
const SpriteGroup *group;
ResolverObject object;
@@ -855,6 +857,8 @@
NewVehicleResolver(&object, v);
+ object.info_view = info_view;
+
group = heli_rotor_custom_sprites[engine - AIRCRAFT_ENGINES_INDEX];
group = Resolve(group, &object);
@@ -862,7 +866,7 @@
if (v == NULL) return group->g.result.sprite;
- return group->g.result.sprite + (v->next->next->u.air.state % group->g.result.num_sprites);
+ return group->g.result.sprite + (info_view ? 0 : (v->next->next->u.air.state % group->g.result.num_sprites));
}
--- a/newgrf_engine.h Thu Jun 22 21:03:19 2006 +0000
+++ b/newgrf_engine.h Thu Jun 22 21:15:27 2006 +0000
@@ -22,9 +22,9 @@
void SetCustomEngineSprites(EngineID engine, byte cargo, const struct SpriteGroup *group);
void SetRotorOverrideSprites(EngineID engine, const struct SpriteGroup *group);
SpriteID GetCustomEngineSprite(EngineID engine, const Vehicle* v, Direction direction);
-SpriteID GetRotorOverrideSprite(EngineID engine, const Vehicle* v);
-#define GetCustomRotorSprite(v) GetRotorOverrideSprite(v->engine_type, v)
-#define GetCustomRotorIcon(et) GetRotorOverrideSprite(et, NULL)
+SpriteID GetRotorOverrideSprite(EngineID engine, const Vehicle* v, bool info_view);
+#define GetCustomRotorSprite(v, i) GetRotorOverrideSprite(v->engine_type, v, i)
+#define GetCustomRotorIcon(et) GetRotorOverrideSprite(et, NULL, true)
/* Forward declaration of GRFFile, to avoid unnecessary inclusion of newgrf.h
* elsewhere... */
--- a/newgrf_spritegroup.h Thu Jun 22 21:03:19 2006 +0000
+++ b/newgrf_spritegroup.h Thu Jun 22 21:15:27 2006 +0000
@@ -165,6 +165,8 @@
uint32 reseed;
VarSpriteGroupScope scope;
+ bool info_view; ///< Indicates if the item is being drawn in an info window
+
union {
struct {
const struct Vehicle *self;