mirror of https://github.com/OpenTTD/OpenTTD
Compare commits
9 Commits
d3cb6e1e67
...
c6411168d8
Author | SHA1 | Date |
---|---|---|
|
c6411168d8 | |
|
c687b59efc | |
|
53845bc024 | |
|
ed8df72c49 | |
|
f91462f54b | |
|
ff5e8bb9a3 | |
|
278b42d078 | |
|
4f3adc038a | |
|
49d53c41ab |
|
@ -138,35 +138,60 @@ struct Industry : IndustryPool::PoolItem<&_industry_pool> {
|
|||
return IsTileType(tile, MP_INDUSTRY) && GetIndustryIndex(tile) == this->index;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get produced cargo slot for a specific cargo type.
|
||||
* @param cargo CargoID to find.
|
||||
* @return Iterator pointing to produced cargo slot if it exists, or the end iterator.
|
||||
*/
|
||||
inline ProducedCargoArray::iterator GetCargoProduced(CargoID cargo)
|
||||
{
|
||||
if (!IsValidCargoID(cargo)) return std::end(this->produced);
|
||||
return std::find_if(std::begin(this->produced), std::end(this->produced), [&cargo](const auto &p) { return p.cargo == cargo; });
|
||||
}
|
||||
|
||||
/**
|
||||
* Get produced cargo slot for a specific cargo type (const-variant).
|
||||
* @param cargo CargoID to find.
|
||||
* @return Iterator pointing to produced cargo slot if it exists, or the end iterator.
|
||||
*/
|
||||
inline ProducedCargoArray::const_iterator GetCargoProduced(CargoID cargo) const
|
||||
{
|
||||
if (!IsValidCargoID(cargo)) return std::end(this->produced);
|
||||
return std::find_if(std::begin(this->produced), std::end(this->produced), [&cargo](const auto &p) { return p.cargo == cargo; });
|
||||
}
|
||||
|
||||
/**
|
||||
* Get accepted cargo slot for a specific cargo type.
|
||||
* @param cargo CargoID to find.
|
||||
* @return Iterator pointing to accepted cargo slot if it exists, or the end iterator.
|
||||
*/
|
||||
inline AcceptedCargoArray::iterator GetCargoAccepted(CargoID cargo)
|
||||
{
|
||||
if (!IsValidCargoID(cargo)) return std::end(this->accepted);
|
||||
return std::find_if(std::begin(this->accepted), std::end(this->accepted), [&cargo](const auto &a) { return a.cargo == cargo; });
|
||||
}
|
||||
|
||||
/** Test if this industry accepts any cargo.
|
||||
/**
|
||||
* Test if this industry accepts any cargo.
|
||||
* @return true iff the industry accepts any cargo.
|
||||
*/
|
||||
bool IsCargoAccepted() const { return std::any_of(std::begin(this->accepted), std::end(this->accepted), [](const auto &a) { return IsValidCargoID(a.cargo); }); }
|
||||
|
||||
/** Test if this industry produces any cargo.
|
||||
/**
|
||||
* Test if this industry produces any cargo.
|
||||
* @return true iff the industry produces any cargo.
|
||||
*/
|
||||
bool IsCargoProduced() const { return std::any_of(std::begin(this->produced), std::end(this->produced), [](const auto &p) { return IsValidCargoID(p.cargo); }); }
|
||||
|
||||
/** Test if this industry accepts a specific cargo.
|
||||
/**
|
||||
* Test if this industry accepts a specific cargo.
|
||||
* @param cargo Cargo type to test.
|
||||
* @return true iff the industry accepts the given cargo type.
|
||||
*/
|
||||
bool IsCargoAccepted(CargoID cargo) const { return std::any_of(std::begin(this->accepted), std::end(this->accepted), [&cargo](const auto &a) { return a.cargo == cargo; }); }
|
||||
|
||||
/** Test if this industry produces a specific cargo.
|
||||
/**
|
||||
* Test if this industry produces a specific cargo.
|
||||
* @param cargo Cargo type to test.
|
||||
* @return true iff the industry produces the given cargo types.
|
||||
*/
|
||||
|
|
|
@ -1509,14 +1509,16 @@ protected:
|
|||
if (filter == CF_NONE) return IndustryTypeSorter(a, b);
|
||||
|
||||
uint prod_a = 0, prod_b = 0;
|
||||
for (auto ita = std::begin(a->produced), itb = std::begin(b->produced); ita != std::end(a->produced) && itb != std::end(b->produced); ++ita, ++itb) {
|
||||
if (filter == CF_ANY) {
|
||||
if (IsValidCargoID(ita->cargo)) prod_a += ita->history[LAST_MONTH].production;
|
||||
if (IsValidCargoID(itb->cargo)) prod_b += ita->history[LAST_MONTH].production;
|
||||
} else {
|
||||
if (ita->cargo == filter) prod_a += ita->history[LAST_MONTH].production;
|
||||
if (itb->cargo == filter) prod_b += itb->history[LAST_MONTH].production;
|
||||
for (const auto &pa : a->produced) {
|
||||
if (IsValidCargoID(pa.cargo)) prod_a += pa.history[LAST_MONTH].production;
|
||||
}
|
||||
for (const auto &pb : b->produced) {
|
||||
if (IsValidCargoID(pb.cargo)) prod_b += pb.history[LAST_MONTH].production;
|
||||
}
|
||||
} else {
|
||||
if (auto ita = a->GetCargoProduced(filter); ita != std::end(a->produced)) prod_a = ita->history[LAST_MONTH].production;
|
||||
if (auto itb = b->GetCargoProduced(filter); itb != std::end(b->produced)) prod_b = itb->history[LAST_MONTH].production;
|
||||
}
|
||||
int r = prod_a - prod_b;
|
||||
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
#include "../smallmap_gui.h"
|
||||
#include "../core/geometry_func.hpp"
|
||||
#include "../widgets/link_graph_legend_widget.h"
|
||||
#include "../strings_func.h"
|
||||
#include "linkgraph_gui.h"
|
||||
|
||||
#include "table/strings.h"
|
||||
|
||||
|
@ -425,7 +427,7 @@ Point LinkGraphOverlay::GetStationMiddle(const Station *st) const
|
|||
return GetViewportStationMiddle(this->window->viewport, st);
|
||||
} else {
|
||||
/* assume this is a smallmap */
|
||||
return static_cast<const SmallMapWindow *>(this->window)->GetStationMiddle(st);
|
||||
return GetSmallMapStationMiddle(this->window, st);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -294,7 +294,7 @@ void DrawRoadStopTile(int x, int y, RoadType roadtype, const RoadStopSpec *spec,
|
|||
}
|
||||
}
|
||||
} else {
|
||||
/* Drive-in stop */
|
||||
/* Bay stop */
|
||||
if ((spec->draw_mode & ROADSTOP_DRAW_MODE_ROAD) && rti->UsesOverlay()) {
|
||||
SpriteID ground = GetCustomRoadSprite(rti, INVALID_TILE, ROTSG_ROADSTOP);
|
||||
DrawSprite(ground + view, PAL_NONE, x, y);
|
||||
|
|
|
@ -64,7 +64,7 @@ enum RoadTypeSpriteGroup {
|
|||
ROTSG_reserved2, ///< Placeholder, if we need specific level crossing sprites.
|
||||
ROTSG_DEPOT, ///< Optional: Depot images
|
||||
ROTSG_reserved3, ///< Placeholder, if we add road fences (for highways).
|
||||
ROTSG_ROADSTOP, ///< Required: Drive-in stop surface
|
||||
ROTSG_ROADSTOP, ///< Required: Bay stop surface
|
||||
ROTSG_ONEWAY, ///< Optional: One-way indicator images
|
||||
ROTSG_END,
|
||||
};
|
||||
|
|
|
@ -46,6 +46,8 @@
|
|||
#include "vehicle_func.h"
|
||||
#include "viewport_func.h"
|
||||
#include "void_map.h"
|
||||
#include "station_func.h"
|
||||
#include "station_base.h"
|
||||
|
||||
#include "table/strings.h"
|
||||
#include "table/settings.h"
|
||||
|
|
1118
src/smallmap_gui.cpp
1118
src/smallmap_gui.cpp
File diff suppressed because it is too large
Load Diff
|
@ -10,15 +10,10 @@
|
|||
#ifndef SMALLMAP_GUI_H
|
||||
#define SMALLMAP_GUI_H
|
||||
|
||||
#include "industry_type.h"
|
||||
#include "company_base.h"
|
||||
#include "window_gui.h"
|
||||
#include "strings_func.h"
|
||||
#include "blitter/factory.hpp"
|
||||
#include "linkgraph/linkgraph_gui.h"
|
||||
#include "widgets/smallmap_widget.h"
|
||||
#include "timer/timer.h"
|
||||
#include "timer/timer_window.h"
|
||||
#include "core/geometry_type.hpp"
|
||||
#include "station_type.h"
|
||||
#include "tile_type.h"
|
||||
#include "window_type.h"
|
||||
|
||||
/* set up the cargos to be displayed in the smallmap's route legend */
|
||||
void BuildLinkStatsLegend();
|
||||
|
@ -37,179 +32,6 @@ enum class IncludeHeightmap {
|
|||
|
||||
uint32_t GetSmallMapOwnerPixels(TileIndex tile, TileType t, IncludeHeightmap include_heightmap);
|
||||
|
||||
/** Structure for holding relevant data for legends in small map */
|
||||
struct LegendAndColour {
|
||||
uint8_t colour; ///< Colour of the item on the map.
|
||||
StringID legend; ///< String corresponding to the coloured item.
|
||||
IndustryType type; ///< Type of industry. Only valid for industry entries.
|
||||
uint8_t height; ///< Height in tiles. Only valid for height legend entries.
|
||||
CompanyID company; ///< Company to display. Only valid for company entries of the owner legend.
|
||||
bool show_on_map; ///< For filtering industries, if \c true, industry is shown on the map in colour.
|
||||
bool end; ///< This is the end of the list.
|
||||
bool col_break; ///< Perform a column break and go further at the next column.
|
||||
};
|
||||
|
||||
/** Class managing the smallmap window. */
|
||||
class SmallMapWindow : public Window {
|
||||
protected:
|
||||
/** Types of legends in the #WID_SM_LEGEND widget. */
|
||||
enum SmallMapType {
|
||||
SMT_CONTOUR,
|
||||
SMT_VEHICLES,
|
||||
SMT_INDUSTRY,
|
||||
SMT_LINKSTATS,
|
||||
SMT_ROUTES,
|
||||
SMT_VEGETATION,
|
||||
SMT_OWNER,
|
||||
};
|
||||
|
||||
/** Available kinds of zoomlevel changes. */
|
||||
enum ZoomLevelChange {
|
||||
ZLC_INITIALIZE, ///< Initialize zoom level.
|
||||
ZLC_ZOOM_OUT, ///< Zoom out.
|
||||
ZLC_ZOOM_IN, ///< Zoom in.
|
||||
};
|
||||
|
||||
static SmallMapType map_type; ///< Currently displayed legends.
|
||||
static bool show_towns; ///< Display town names in the smallmap.
|
||||
static int map_height_limit; ///< Currently used/cached map height limit.
|
||||
|
||||
static const uint INDUSTRY_MIN_NUMBER_OF_COLUMNS = 2; ///< Minimal number of columns in the #WID_SM_LEGEND widget for the #SMT_INDUSTRY legend.
|
||||
|
||||
uint min_number_of_columns; ///< Minimal number of columns in legends.
|
||||
uint min_number_of_fixed_rows; ///< Minimal number of rows in the legends for the fixed layouts only (all except #SMT_INDUSTRY).
|
||||
uint column_width; ///< Width of a column in the #WID_SM_LEGEND widget.
|
||||
uint legend_width; ///< Width of legend 'blob'.
|
||||
|
||||
int32_t scroll_x; ///< Horizontal world coordinate of the base tile left of the top-left corner of the smallmap display.
|
||||
int32_t scroll_y; ///< Vertical world coordinate of the base tile left of the top-left corner of the smallmap display.
|
||||
int32_t subscroll; ///< Number of pixels (0..3) between the right end of the base tile and the pixel at the top-left corner of the smallmap display.
|
||||
int zoom; ///< Zoom level. Bigger number means more zoom-out (further away).
|
||||
|
||||
LinkGraphOverlay *overlay;
|
||||
|
||||
static void BreakIndustryChainLink();
|
||||
Point SmallmapRemapCoords(int x, int y) const;
|
||||
|
||||
/**
|
||||
* Draws vertical part of map indicator
|
||||
* @param x X coord of left/right border of main viewport
|
||||
* @param y Y coord of top border of main viewport
|
||||
* @param y2 Y coord of bottom border of main viewport
|
||||
*/
|
||||
static inline void DrawVertMapIndicator(int x, int y, int y2)
|
||||
{
|
||||
GfxFillRect(x, y, x, y + 3, PC_VERY_LIGHT_YELLOW);
|
||||
GfxFillRect(x, y2 - 3, x, y2, PC_VERY_LIGHT_YELLOW);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws horizontal part of map indicator
|
||||
* @param x X coord of left border of main viewport
|
||||
* @param x2 X coord of right border of main viewport
|
||||
* @param y Y coord of top/bottom border of main viewport
|
||||
*/
|
||||
static inline void DrawHorizMapIndicator(int x, int x2, int y)
|
||||
{
|
||||
GfxFillRect(x, y, x + 3, y, PC_VERY_LIGHT_YELLOW);
|
||||
GfxFillRect(x2 - 3, y, x2, y, PC_VERY_LIGHT_YELLOW);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute minimal required width of the legends.
|
||||
* @return Minimally needed width for displaying the smallmap legends in pixels.
|
||||
*/
|
||||
inline uint GetMinLegendWidth() const
|
||||
{
|
||||
return WidgetDimensions::scaled.framerect.left + this->min_number_of_columns * this->column_width;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return number of columns that can be displayed in \a width pixels.
|
||||
* @return Number of columns to display.
|
||||
*/
|
||||
inline uint GetNumberColumnsLegend(uint width) const
|
||||
{
|
||||
return width / this->column_width;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute height given a number of columns.
|
||||
* @param num_columns Number of columns.
|
||||
* @return Needed height for displaying the smallmap legends in pixels.
|
||||
*/
|
||||
inline uint GetLegendHeight(uint num_columns) const
|
||||
{
|
||||
return WidgetDimensions::scaled.framerect.Vertical() +
|
||||
this->GetNumberRowsLegend(num_columns) * FONT_HEIGHT_SMALL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a bitmask for company links to be displayed. Usually this will be
|
||||
* the _local_company. Spectators get to see all companies' links.
|
||||
* @return Company mask.
|
||||
*/
|
||||
inline CompanyMask GetOverlayCompanyMask() const
|
||||
{
|
||||
return Company::IsValidID(_local_company) ? 1U << _local_company : MAX_UVALUE(CompanyMask);
|
||||
}
|
||||
|
||||
/** Blink the industries (if selected) on a regular interval. */
|
||||
IntervalTimer<TimerWindow> blink_interval = {std::chrono::milliseconds(450), [this](auto) {
|
||||
Blink();
|
||||
}};
|
||||
|
||||
/** Update the whole map on a regular interval. */
|
||||
IntervalTimer<TimerWindow> refresh_interval = {std::chrono::milliseconds(930), [this](auto) {
|
||||
ForceRefresh();
|
||||
}};
|
||||
|
||||
void RebuildColourIndexIfNecessary();
|
||||
uint GetNumberRowsLegend(uint columns) const;
|
||||
void SelectLegendItem(int click_pos, LegendAndColour *legend, int end_legend_item, int begin_legend_item = 0);
|
||||
void SwitchMapType(SmallMapType map_type);
|
||||
void SetNewScroll(int sx, int sy, int sub);
|
||||
|
||||
void DrawMapIndicators() const;
|
||||
void DrawSmallMapColumn(void *dst, uint xc, uint yc, int pitch, int reps, int start_pos, int end_pos, Blitter *blitter) const;
|
||||
void DrawVehicles(const DrawPixelInfo *dpi, Blitter *blitter) const;
|
||||
void DrawTowns(const DrawPixelInfo *dpi) const;
|
||||
void DrawSmallMap(DrawPixelInfo *dpi) const;
|
||||
|
||||
Point RemapTile(int tile_x, int tile_y) const;
|
||||
Point PixelToTile(int px, int py, int *sub, bool add_sub = true) const;
|
||||
Point ComputeScroll(int tx, int ty, int x, int y, int *sub);
|
||||
void SetZoomLevel(ZoomLevelChange change, const Point *zoom_pt);
|
||||
void SetOverlayCargoMask();
|
||||
void SetupWidgetData();
|
||||
uint32_t GetTileColours(const TileArea &ta) const;
|
||||
|
||||
int GetPositionOnLegend(Point pt);
|
||||
|
||||
void UpdateLinks();
|
||||
void Blink();
|
||||
void ForceRefresh();
|
||||
|
||||
public:
|
||||
friend class NWidgetSmallmapDisplay;
|
||||
|
||||
SmallMapWindow(WindowDesc *desc, int window_number);
|
||||
virtual ~SmallMapWindow();
|
||||
|
||||
void SmallMapCenterOnCurrentPos();
|
||||
Point GetStationMiddle(const Station *st) const;
|
||||
|
||||
void Close([[maybe_unused]] int data = 0) override;
|
||||
void SetStringParameters(int widget) const override;
|
||||
void OnInit() override;
|
||||
void OnPaint() override;
|
||||
void DrawWidget(const Rect &r, int widget) const override;
|
||||
void OnClick([[maybe_unused]] Point pt, int widget, [[maybe_unused]] int click_count) override;
|
||||
void OnInvalidateData(int data = 0, bool gui_scope = true) override;
|
||||
bool OnRightClick(Point pt, int widget) override;
|
||||
void OnMouseWheel(int wheel) override;
|
||||
void OnScroll(Point delta) override;
|
||||
void OnMouseOver([[maybe_unused]] Point pt, int widget) override;
|
||||
};
|
||||
Point GetSmallMapStationMiddle(const Window *w, const Station *st);
|
||||
|
||||
#endif /* SMALLMAP_GUI_H */
|
||||
|
|
|
@ -3246,7 +3246,7 @@ void StationPickerDrawSprite(int x, int y, StationType st, RailType railtype, Ro
|
|||
DrawSprite(SPR_TRAMWAY_TRAM + sprite_offset, PAL_NONE, x, y);
|
||||
}
|
||||
} else {
|
||||
/* Drive-in stop */
|
||||
/* Bay stop */
|
||||
if (RoadTypeIsRoad(roadtype) && roadtype_info->UsesOverlay()) {
|
||||
SpriteID ground = GetCustomRoadSprite(roadtype_info, INVALID_TILE, ROTSG_ROADSTOP);
|
||||
DrawSprite(ground + image, PAL_NONE, x, y);
|
||||
|
|
Loading…
Reference in New Issue