diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/roadveh.h | 1 | ||||
-rw-r--r-- | src/roadveh_cmd.cpp | 16 | ||||
-rw-r--r-- | src/roadveh_gui.cpp | 41 |
3 files changed, 28 insertions, 30 deletions
diff --git a/src/roadveh.h b/src/roadveh.h index 9945635aa..9f57d9ff3 100644 --- a/src/roadveh.h +++ b/src/roadveh.h @@ -117,6 +117,7 @@ struct RoadVehicle : public SpecializedVehicle<RoadVehicle, VEH_ROAD> { int GetDisplaySpeed() const { return this->cur_speed / 2; } int GetDisplayMaxSpeed() const { return this->max_speed / 2; } Money GetRunningCost() const { return RoadVehInfo(this->engine_type)->running_cost * GetPriceByIndex(RoadVehInfo(this->engine_type)->running_cost_class); } + int GetDisplayImageWidth(Point *offset = NULL) const; bool IsInDepot() const { return this->state == RVSB_IN_DEPOT; } bool IsStoppedInDepot() const; bool Tick(); diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp index 50a7d4e95..811a0e422 100644 --- a/src/roadveh_cmd.cpp +++ b/src/roadveh_cmd.cpp @@ -85,6 +85,22 @@ static const Trackdir _roadveh_depot_exit_trackdir[DIAGDIR_END] = { TRACKDIR_X_NE, TRACKDIR_Y_SE, TRACKDIR_X_SW, TRACKDIR_Y_NW }; +/** + * Get the width of a road vehicle image in the GUI. + * @param offset Additional offset for positioning the sprite; set to NULL if not needed + * @return Width in pixels + */ +int RoadVehicle::GetDisplayImageWidth(Point *offset) const +{ + int reference_width = ROADVEHINFO_DEFAULT_VEHICLE_WIDTH; + + if (offset != NULL) { + offset->x = reference_width / 2; + offset->y = 0; + } + return this->rcache.cached_veh_length * reference_width / 8; +} + static SpriteID GetRoadVehIcon(EngineID engine) { uint8 spritenum = RoadVehInfo(engine)->image_index; diff --git a/src/roadveh_gui.cpp b/src/roadveh_gui.cpp index a234c2a4c..49a608a06 100644 --- a/src/roadveh_gui.cpp +++ b/src/roadveh_gui.cpp @@ -6,7 +6,6 @@ #include "roadveh.h" #include "window_gui.h" #include "gfx_func.h" -#include "newgrf_engine.h" #include "vehicle_gui.h" #include "strings_func.h" #include "vehicle_func.h" @@ -115,12 +114,6 @@ void DrawRoadVehDetails(const Vehicle *v, int left, int right, int y) DrawString(left, right, y + 33 + y_offset, STR_FEEDER_CARGO_VALUE); } - -static inline int RoadVehLengthToPixels(int length) -{ - return (length * ROADVEHINFO_DEFAULT_VEHICLE_WIDTH) / 8; -} - /** * Draws an image of a road vehicle chain * @param v Front vehicle @@ -131,31 +124,19 @@ static inline int RoadVehLengthToPixels(int length) */ void DrawRoadVehImage(const Vehicle *v, int x, int y, VehicleID selection, int max_width) { - int max_length = max_width / ROADVEHINFO_DEFAULT_VEHICLE_WIDTH; - - /* Width of highlight box */ - int highlight_w = 0; - - for (int dx = 0; v != NULL && dx < max_length ; v = v->Next()) { - int width = RoadVehicle::From(v)->rcache.cached_veh_length; - - if (dx + width > 0 && dx <= max_length) { - SpriteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v); - DrawSprite(v->GetImage(DIR_W), pal, x + 14 + RoadVehLengthToPixels(dx), y + 6); - - if (v->index == selection) { - /* Set the highlight position */ - highlight_w = RoadVehLengthToPixels(width); - } else if (_cursor.vehchain && highlight_w != 0) { - highlight_w += RoadVehLengthToPixels(width); - } - } - - dx += width; + const RoadVehicle *u = RoadVehicle::From(v); + int x_pos = 0; + for (; u != NULL && x_pos < max_width; u = u->Next()) { + Point offset; + int width = u->GetDisplayImageWidth(&offset); + + SpriteID pal = (u->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(u); + DrawSprite(u->GetImage(DIR_W), pal, x + x_pos + offset.x, y + 6 + offset.y); + x_pos += width; } - if (highlight_w != 0) { - DrawFrameRect(x - 1, y - 1, x - 1 + highlight_w, y + 12, COLOUR_WHITE, FR_BORDERONLY); + if (v->index == selection) { + DrawFrameRect(x - 1, y - 1, x - 1 + x_pos, y + 12, COLOUR_WHITE, FR_BORDERONLY); } } |