2010-02-08 21:19:41 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
|
|
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2010-02-08 23:46:35 +00:00
|
|
|
/** @file smallmap_gui.h Smallmap GUI functions. */
|
2010-02-08 21:19:41 +00:00
|
|
|
|
|
|
|
#ifndef SMALLMAP_GUI_H
|
|
|
|
#define SMALLMAP_GUI_H
|
|
|
|
|
2013-02-17 20:38:35 +00:00
|
|
|
#include "industry_type.h"
|
2014-01-19 09:26:56 +00:00
|
|
|
#include "company_base.h"
|
2013-02-17 20:38:35 +00:00
|
|
|
#include "window_gui.h"
|
|
|
|
#include "strings_func.h"
|
|
|
|
#include "blitter/factory.hpp"
|
2013-05-19 14:36:35 +00:00
|
|
|
#include "linkgraph/linkgraph_gui.h"
|
2013-02-17 20:38:35 +00:00
|
|
|
#include "widgets/smallmap_widget.h"
|
2018-05-20 08:58:36 +00:00
|
|
|
#include "guitimer_func.h"
|
2013-02-17 20:38:35 +00:00
|
|
|
|
2015-08-02 18:37:42 +00:00
|
|
|
static const int NUM_NO_COMPANY_ENTRIES = 4; ///< Number of entries in the owner legend that are not companies.
|
|
|
|
|
|
|
|
/** Mapping of tile type to importance of the tile (higher number means more interesting to show). */
|
|
|
|
static const byte _tiletype_importance[] = {
|
|
|
|
2, // MP_CLEAR
|
|
|
|
8, // MP_RAILWAY
|
|
|
|
7, // MP_ROAD
|
|
|
|
5, // MP_HOUSE
|
|
|
|
2, // MP_TREES
|
|
|
|
9, // MP_STATION
|
|
|
|
2, // MP_WATER
|
|
|
|
1, // MP_VOID
|
|
|
|
6, // MP_INDUSTRY
|
|
|
|
8, // MP_TUNNELBRIDGE
|
|
|
|
2, // MP_OBJECT
|
|
|
|
0,
|
|
|
|
};
|
|
|
|
|
2013-05-19 14:36:35 +00:00
|
|
|
/* set up the cargos to be displayed in the smallmap's route legend */
|
|
|
|
void BuildLinkStatsLegend();
|
|
|
|
|
2015-08-02 18:37:42 +00:00
|
|
|
struct TunnelBridgeToMap {
|
|
|
|
TileIndex from_tile;
|
|
|
|
TileIndex to_tile;
|
|
|
|
};
|
2019-03-27 18:12:04 +00:00
|
|
|
typedef std::vector<TunnelBridgeToMap> TunnelBridgeToMapVector;
|
2015-08-02 18:37:42 +00:00
|
|
|
|
2010-02-08 21:19:41 +00:00
|
|
|
void BuildIndustriesLegend();
|
|
|
|
void ShowSmallMap();
|
2010-02-08 23:46:35 +00:00
|
|
|
void BuildLandLegend();
|
2011-01-04 20:53:57 +00:00
|
|
|
void BuildOwnerLegend();
|
2010-02-08 21:19:41 +00:00
|
|
|
|
2013-02-17 20:38:35 +00:00
|
|
|
/** Structure for holding relevant data for legends in small map */
|
|
|
|
struct LegendAndColour {
|
|
|
|
uint8 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 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,
|
2013-05-19 14:36:35 +00:00
|
|
|
SMT_LINKSTATS,
|
2013-02-17 20:38:35 +00:00
|
|
|
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.
|
2014-09-27 11:17:54 +00:00
|
|
|
static int max_heightlevel; ///< Currently used/cached maximum heightlevel.
|
2013-02-17 20:38:35 +00:00
|
|
|
|
|
|
|
static const uint LEGEND_BLOB_WIDTH = 8; ///< Width of the coloured blob in front of a line text in the #WID_SM_LEGEND widget.
|
|
|
|
static const uint INDUSTRY_MIN_NUMBER_OF_COLUMNS = 2; ///< Minimal number of columns in the #WID_SM_LEGEND widget for the #SMT_INDUSTRY legend.
|
2019-01-14 00:01:44 +00:00
|
|
|
static const uint FORCE_REFRESH_PERIOD = 2850; ///< map is redrawn after that many milliseconds.
|
2018-05-04 20:29:22 +00:00
|
|
|
static const uint BLINK_PERIOD = 450; ///< highlight blinking interval in milliseconds.
|
2013-02-17 20:38:35 +00:00
|
|
|
|
2013-02-17 20:55:26 +00:00
|
|
|
uint min_number_of_columns; ///< Minimal number of columns in legends.
|
2013-02-17 20:38:35 +00:00
|
|
|
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.
|
|
|
|
|
|
|
|
int32 scroll_x; ///< Horizontal world coordinate of the base tile left of the top-left corner of the smallmap display.
|
|
|
|
int32 scroll_y; ///< Vertical world coordinate of the base tile left of the top-left corner of the smallmap display.
|
|
|
|
int32 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).
|
|
|
|
|
2018-05-20 08:58:36 +00:00
|
|
|
GUITimer refresh; ///< Refresh timer.
|
2013-05-19 14:36:35 +00:00
|
|
|
LinkGraphOverlay *overlay;
|
2013-02-17 20:38:35 +00:00
|
|
|
|
2017-08-31 06:48:55 +00:00
|
|
|
static void BreakIndustryChainLink();
|
2013-02-17 20:38:35 +00:00
|
|
|
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 WD_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;
|
|
|
|
}
|
|
|
|
|
2013-02-17 20:51:55 +00:00
|
|
|
/**
|
|
|
|
* 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 WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM +
|
|
|
|
this->GetNumberRowsLegend(num_columns) * FONT_HEIGHT_SMALL;
|
|
|
|
}
|
2013-02-17 20:38:35 +00:00
|
|
|
|
2014-01-19 09:26:56 +00:00
|
|
|
/**
|
|
|
|
* 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 uint32 GetOverlayCompanyMask() const
|
|
|
|
{
|
|
|
|
return Company::IsValidID(_local_company) ? 1U << _local_company : 0xffffffff;
|
|
|
|
}
|
|
|
|
|
2013-02-17 20:51:55 +00:00
|
|
|
uint GetNumberRowsLegend(uint columns) const;
|
|
|
|
void SelectLegendItem(int click_pos, LegendAndColour *legend, int end_legend_item, int begin_legend_item = 0);
|
2013-02-17 20:38:35 +00:00
|
|
|
void SwitchMapType(SmallMapType map_type);
|
|
|
|
void SetNewScroll(int sx, int sy, int sub);
|
2013-02-17 20:55:26 +00:00
|
|
|
|
|
|
|
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;
|
2015-08-04 00:26:32 +00:00
|
|
|
void DrawSmallMap(DrawPixelInfo *dpi, bool draw_indicators = true) const;
|
2013-02-17 20:55:26 +00:00
|
|
|
|
|
|
|
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);
|
2013-05-19 14:36:35 +00:00
|
|
|
void SetOverlayCargoMask();
|
2013-02-17 20:55:26 +00:00
|
|
|
void SetupWidgetData();
|
|
|
|
uint32 GetTileColours(const TileArea &ta) const;
|
|
|
|
|
|
|
|
int GetPositionOnLegend(Point pt);
|
|
|
|
|
|
|
|
public:
|
|
|
|
friend class NWidgetSmallmapDisplay;
|
|
|
|
|
2013-05-26 19:23:42 +00:00
|
|
|
SmallMapWindow(WindowDesc *desc, int window_number);
|
2017-08-31 06:48:55 +00:00
|
|
|
virtual ~SmallMapWindow();
|
2013-05-19 14:36:35 +00:00
|
|
|
|
2015-08-02 18:37:42 +00:00
|
|
|
static void RebuildColourIndexIfNecessary();
|
|
|
|
|
2013-02-17 20:38:35 +00:00
|
|
|
void SmallMapCenterOnCurrentPos();
|
2013-05-19 14:36:35 +00:00
|
|
|
Point GetStationMiddle(const Station *st) const;
|
2013-02-17 20:38:35 +00:00
|
|
|
|
2019-03-24 16:49:26 +00:00
|
|
|
void SetStringParameters(int widget) const override;
|
|
|
|
void OnInit() override;
|
|
|
|
void OnPaint() override;
|
|
|
|
void DrawWidget(const Rect &r, int widget) const override;
|
|
|
|
void OnClick(Point pt, int widget, 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 OnRealtimeTick(uint delta_ms) override;
|
|
|
|
void OnScroll(Point delta) override;
|
|
|
|
void OnMouseOver(Point pt, int widget) override;
|
2015-08-04 00:26:32 +00:00
|
|
|
|
|
|
|
void TakeScreenshot();
|
|
|
|
void ScreenshotCallbackHandler(void *buf, uint y, uint pitch, uint n);
|
2013-02-17 20:38:35 +00:00
|
|
|
};
|
|
|
|
|
2010-02-08 21:19:41 +00:00
|
|
|
#endif /* SMALLMAP_GUI_H */
|