Add two more minimap zoom levels

This commit is contained in:
dP
2021-03-24 11:55:19 +03:00
parent a55227a48f
commit 6f8e0c144b
8 changed files with 2046 additions and 10 deletions

View File

@@ -2,8 +2,8 @@
#include "cm_main.hpp"
#include "cm_hotkeys.hpp"
#include "cm_minimap.hpp"
#include "../smallmap_gui.h"
#include "../window_func.h"
#include "../safeguards.h"
@@ -22,7 +22,7 @@ void SwitchToMode(SwitchMode new_mode) {
}
void ToggleSmallMap() {
SmallMapWindow *w = dynamic_cast<SmallMapWindow*>(FindWindowById(WC_SMALLMAP, 0));
SmallMapWindow *w = dynamic_cast<citymania::SmallMapWindow*>(FindWindowById(WC_SMALLMAP, 0));
if (w == nullptr) ShowSmallMap();
delete w;
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,8 +1,10 @@
#ifndef CM_MINIMAP_HPP
#define CM_MINIMAP_HPP
#include "../smallmap_gui.h"
#include "../core/endian_func.hpp"
namespace citymania {
#define MKCOLOUR(x) TO_LE32X(x)
@@ -35,6 +37,167 @@ static const uint32 _orange_map_heights[] = {
MKCOLOUR(0xC5C5C5C5),
};
void BuildLinkStatsLegend();
void BuildIndustriesLegend();
void ShowSmallMap();
void BuildLandLegend();
void BuildOwnerLegend();
/** 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,
CM_SMT_IMBA,
};
/** 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 max_heightlevel; ///< Currently used/cached maximum heightlevel.
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.
static const uint FORCE_REFRESH_PERIOD = 930; ///< map is redrawn after that many milliseconds.
static const uint BLINK_PERIOD = 450; ///< highlight blinking interval in milliseconds.
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.
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 tile_zoom; ///< Zoom level. Bigger number means more zoom-out (further away).
int ui_zoom; ///< Zoom level. Bigger number means more zoom-out (further away).
int zoom; ///< Zoom level. Bigger number means more zoom-out (further away).
GUITimer refresh; ///< Refresh timer.
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 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;
}
/**
* 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;
}
/**
* 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;
}
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, int y, int end_y, Blitter *blitter) const;
void DrawVehicles(const DrawPixelInfo *dpi, Blitter *blitter) const;
void DrawTowns(const DrawPixelInfo *dpi) const;
void DrawSmallMap(DrawPixelInfo *dpi) const;
Point TileToPixel(int tx, int ty) const;
Point PixelToTile(int tx, int ty) const;
void SetZoomLevel(ZoomLevelChange change, const Point *zoom_pt);
void SetOverlayCargoMask();
void SetupWidgetData();
uint32 GetTileColours(const TileArea &ta) const;
int GetPositionOnLegend(Point pt);
public:
friend class NWidgetSmallmapDisplay;
SmallMapWindow(WindowDesc *desc, int window_number);
virtual ~SmallMapWindow();
void SmallMapCenterOnCurrentPos();
Point GetStationMiddle(const Station *st) const;
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;
};
} // namespace citymania
#endif /* CITYMANIA_MINIMAP_HPP */

View File

@@ -45,6 +45,7 @@
#include "citymania/cm_hotkeys.hpp"
#include "citymania/cm_highlight.hpp"
#include "citymania/cm_minimap.hpp"
#include "safeguards.h"
@@ -2989,7 +2990,7 @@ struct IndustryCargoesWindow : public Window {
if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
if (this->IsWidgetLowered(WID_IC_NOTIFY)) {
if (FindWindowByClass(WC_SMALLMAP) == nullptr) ShowSmallMap();
if (FindWindowByClass(WC_SMALLMAP) == nullptr) citymania::ShowSmallMap();
this->NotifySmallmap();
}
break;

View File

@@ -14,12 +14,14 @@
#include "../company_gui.h"
#include "../date_func.h"
#include "../viewport_func.h"
#include "../smallmap_gui.h"
// #include "../smallmap_gui.h"
#include "../core/geometry_func.hpp"
#include "../widgets/link_graph_legend_widget.h"
#include "table/strings.h"
#include "../citymania/cm_minimap.hpp"
#include "../safeguards.h"
/**
@@ -346,7 +348,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 static_cast<const citymania::SmallMapWindow *>(this->window)->GetStationMiddle(st);
}
}

View File

@@ -169,6 +169,9 @@ static uint _company_to_list_pos[MAX_COMPANIES];
*/
void BuildIndustriesLegend()
{
citymania::BuildIndustriesLegend();
return;
uint j = 0;
/* Add each name */
@@ -199,6 +202,9 @@ void BuildIndustriesLegend()
*/
void BuildLinkStatsLegend()
{
citymania::BuildLinkStatsLegend();
return;
/* Clear the legend */
memset(_legend_linkstats, 0, sizeof(_legend_linkstats));
@@ -277,6 +283,9 @@ static SmallMapColourScheme _heightmap_schemes[] = {
*/
void BuildLandLegend()
{
citymania::BuildLandLegend();
return;
/* The smallmap window has never been initialized, so no need to change the legend. */
if (_heightmap_schemes[0].height_colours == nullptr) return;
@@ -328,6 +337,9 @@ void BuildLandLegend()
*/
void BuildOwnerLegend()
{
citymania::BuildOwnerLegend();
return;
_legend_land_owners[1].colour = _heightmap_schemes[_settings_client.gui.smallmap_land_colour].default_colour;
int i = NUM_NO_COMPANY_ENTRIES;
@@ -1885,6 +1897,9 @@ static const NWidgetPart _nested_smallmap_widgets[] = {
EndContainer(),
};
#if 0
CityMania has its own smallmap
static WindowDesc _smallmap_desc(
WDP_AUTO, "smallmap", 484, 314,
WC_SMALLMAP, WC_NONE,
@@ -1899,6 +1914,7 @@ void ShowSmallMap()
{
AllocateWindowDescFront<SmallMapWindow>(&_smallmap_desc, 0);
}
#endif
/**
* Scrolls the main window to given coordinates.
@@ -1918,8 +1934,9 @@ bool ScrollMainWindowTo(int x, int y, int z, bool instant)
if (res) return res;
SmallMapWindow *w = dynamic_cast<SmallMapWindow*>(FindWindowById(WC_SMALLMAP, 0));
citymania::SmallMapWindow *w = dynamic_cast<citymania::SmallMapWindow*>(FindWindowById(WC_SMALLMAP, 0));
if (w != nullptr) w->SmallMapCenterOnCurrentPos();
return res;
}

View File

@@ -23,7 +23,7 @@
void BuildLinkStatsLegend();
void BuildIndustriesLegend();
void ShowSmallMap();
// void ShowSmallMap(); CM
void BuildLandLegend();
void BuildOwnerLegend();

View File

@@ -62,6 +62,7 @@
#include "citymania/cm_locations.hpp"
#include "citymania/cm_main.hpp"
#include "citymania/cm_minimap.hpp"
#include "safeguards.h"
@@ -516,7 +517,7 @@ static CallBackFunction ToolbarScenMapTownDir(Window *w)
static CallBackFunction MenuClickMap(int index)
{
switch (index) {
case MME_SHOW_SMALLMAP: ShowSmallMap(); break;
case MME_SHOW_SMALLMAP: citymania::ShowSmallMap(); break;
case MME_SHOW_EXTRAVIEWPORTS: ShowExtraViewPortWindow(); break;
case MME_SHOW_LINKGRAPH: ShowLinkGraphLegend(); break;
case MME_SHOW_SIGNLISTS: ShowSignList(); break;
@@ -2179,7 +2180,7 @@ struct MainToolbarWindow : Window {
case MTHK_SETTINGS: ShowGameOptions(); break;
case MTHK_SAVEGAME: MenuClickSaveLoad(); break;
case MTHK_LOADGAME: ShowSaveLoadDialog(FT_SAVEGAME, SLO_LOAD); break;
case MTHK_SMALLMAP: ShowSmallMap(); break;
case MTHK_SMALLMAP: citymania::ShowSmallMap(); break;
case MTHK_TOWNDIRECTORY: ShowTownDirectory(); break;
case MTHK_SUBSIDIES: ShowSubsidiesList(); break;
case MTHK_STATIONS: ShowCompanyStations(_local_company); break;
@@ -2638,7 +2639,7 @@ struct ScenarioEditorToolbarWindow : Window {
case MTEHK_ZOOM_IN: ToolbarZoomInClick(this); break;
case MTEHK_ZOOM_OUT: ToolbarZoomOutClick(this); break;
case MTEHK_TERRAFORM: ShowEditorTerraformToolbar(); break;
case MTEHK_SMALLMAP: ShowSmallMap(); break;
case MTEHK_SMALLMAP: citymania::ShowSmallMap(); break;
case MTEHK_EXTRA_VIEWPORT: ShowExtraViewPortWindowForTileUnderCursor(); break;
case CM_MTEHK_SMALLMAP_TOGGLE: citymania::ToggleSmallMap(); break;
default: return ES_NOT_HANDLED;