2005-07-24 15:12:37 +01:00
|
|
|
/* $Id$ */
|
|
|
|
|
2008-05-06 16:11:33 +01:00
|
|
|
/** @file smallmap_gui.cpp GUI that shows a small map of the world with metadata like owner or height. */
|
2007-04-04 02:35:16 +01:00
|
|
|
|
2004-08-09 18:04:08 +01:00
|
|
|
#include "stdafx.h"
|
2006-03-05 10:19:33 +00:00
|
|
|
#include "clear_map.h"
|
2006-03-31 11:44:32 +01:00
|
|
|
#include "industry_map.h"
|
2006-03-26 20:20:15 +01:00
|
|
|
#include "station_map.h"
|
2007-04-12 14:07:15 +01:00
|
|
|
#include "landscape.h"
|
2007-12-19 20:45:46 +00:00
|
|
|
#include "window_gui.h"
|
2006-03-05 10:19:33 +00:00
|
|
|
#include "tree_map.h"
|
2008-01-09 09:45:45 +00:00
|
|
|
#include "viewport_func.h"
|
|
|
|
#include "gfx_func.h"
|
2004-08-09 18:04:08 +01:00
|
|
|
#include "town.h"
|
2007-06-17 21:30:28 +01:00
|
|
|
#include "blitter/factory.hpp"
|
2007-12-16 15:38:51 +00:00
|
|
|
#include "tunnelbridge_map.h"
|
2007-12-21 19:49:27 +00:00
|
|
|
#include "strings_func.h"
|
2007-12-23 10:56:02 +00:00
|
|
|
#include "zoom_func.h"
|
2007-12-25 13:28:09 +00:00
|
|
|
#include "core/endian_func.hpp"
|
2007-12-27 13:35:39 +00:00
|
|
|
#include "vehicle_base.h"
|
2007-12-29 09:24:26 +00:00
|
|
|
#include "sound_func.h"
|
2008-05-06 23:17:12 +01:00
|
|
|
#include "window_func.h"
|
2007-12-16 15:38:51 +00:00
|
|
|
|
2008-01-13 01:21:35 +00:00
|
|
|
#include "table/strings.h"
|
|
|
|
#include "table/sprites.h"
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2005-01-03 19:45:18 +00:00
|
|
|
static const Widget _smallmap_widgets[] = {
|
2009-03-14 18:16:29 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, COLOUR_BROWN, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
|
|
{ WWT_CAPTION, RESIZE_RIGHT, COLOUR_BROWN, 11, 337, 0, 13, STR_00B0_MAP, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
|
|
{ WWT_STICKYBOX, RESIZE_LR, COLOUR_BROWN, 338, 349, 0, 13, 0x0, STR_STICKY_BUTTON},
|
|
|
|
{ WWT_PANEL, RESIZE_RB, COLOUR_BROWN, 0, 349, 14, 157, 0x0, STR_NULL},
|
|
|
|
{ WWT_INSET, RESIZE_RB, COLOUR_BROWN, 2, 347, 16, 155, 0x0, STR_NULL},
|
|
|
|
{ WWT_PANEL, RESIZE_RTB, COLOUR_BROWN, 0, 261, 158, 201, 0x0, STR_NULL},
|
|
|
|
{ WWT_PANEL, RESIZE_LRTB, COLOUR_BROWN, 262, 349, 158, 158, 0x0, STR_NULL},
|
|
|
|
{ WWT_IMGBTN, RESIZE_LRTB, COLOUR_BROWN, 284, 305, 158, 179, SPR_IMG_SHOW_COUNTOURS, STR_0191_SHOW_LAND_CONTOURS_ON_MAP},
|
|
|
|
{ WWT_IMGBTN, RESIZE_LRTB, COLOUR_BROWN, 306, 327, 158, 179, SPR_IMG_SHOW_VEHICLES, STR_0192_SHOW_VEHICLES_ON_MAP},
|
|
|
|
{ WWT_IMGBTN, RESIZE_LRTB, COLOUR_BROWN, 328, 349, 158, 179, SPR_IMG_INDUSTRY, STR_0193_SHOW_INDUSTRIES_ON_MAP},
|
|
|
|
{ WWT_IMGBTN, RESIZE_LRTB, COLOUR_BROWN, 284, 305, 180, 201, SPR_IMG_SHOW_ROUTES, STR_0194_SHOW_TRANSPORT_ROUTES_ON},
|
|
|
|
{ WWT_IMGBTN, RESIZE_LRTB, COLOUR_BROWN, 306, 327, 180, 201, SPR_IMG_PLANTTREES, STR_0195_SHOW_VEGETATION_ON_MAP},
|
|
|
|
{ WWT_IMGBTN, RESIZE_LRTB, COLOUR_BROWN, 328, 349, 180, 201, SPR_IMG_COMPANY_GENERAL, STR_0196_SHOW_LAND_OWNERS_ON_MAP},
|
|
|
|
{ WWT_IMGBTN, RESIZE_LRTB, COLOUR_BROWN, 262, 283, 158, 179, SPR_IMG_SMALLMAP, STR_SMALLMAP_CENTER},
|
|
|
|
{ WWT_IMGBTN, RESIZE_LRTB, COLOUR_BROWN, 262, 283, 180, 201, SPR_IMG_TOWN, STR_0197_TOGGLE_TOWN_NAMES_ON_OFF},
|
|
|
|
{ WWT_PANEL, RESIZE_RTB, COLOUR_BROWN, 0, 337, 202, 213, 0x0, STR_NULL},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_TB, COLOUR_BROWN, 0, 99, 202, 213, STR_MESSAGES_ENABLE_ALL, STR_NULL},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_TB, COLOUR_BROWN, 100, 201, 202, 213, STR_MESSAGES_DISABLE_ALL, STR_NULL},
|
|
|
|
{ WWT_RESIZEBOX, RESIZE_LRTB, COLOUR_BROWN, 338, 349, 202, 213, 0x0, STR_RESIZE_BUTTON},
|
2005-06-06 16:58:58 +01:00
|
|
|
{ WIDGETS_END},
|
2004-08-09 18:04:08 +01:00
|
|
|
};
|
|
|
|
|
2007-11-19 04:34:40 +00:00
|
|
|
/* number of used industries */
|
|
|
|
static int _smallmap_industry_count;
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2009-02-09 02:57:15 +00:00
|
|
|
/** Macro for ordinary entry of LegendAndColour */
|
2009-01-09 22:56:28 +00:00
|
|
|
#define MK(a, b) {a, b, INVALID_INDUSTRYTYPE, true, false, false}
|
2009-02-09 02:57:15 +00:00
|
|
|
/** Macro for end of list marker in arrays of LegendAndColour */
|
2007-11-21 13:46:29 +00:00
|
|
|
#define MKEND() {0, STR_NULL, INVALID_INDUSTRYTYPE, true, true, false}
|
2009-02-09 02:57:15 +00:00
|
|
|
/** Macro for break marker in arrays of LegendAndColour.
|
2007-04-16 20:44:22 +01:00
|
|
|
* It will have valid data, though */
|
2009-01-09 22:56:28 +00:00
|
|
|
#define MS(a, b) {a, b, INVALID_INDUSTRYTYPE, true, false, true}
|
2007-04-16 20:44:22 +01:00
|
|
|
|
|
|
|
/** Structure for holding relevant data for legends in small map */
|
|
|
|
struct LegendAndColour {
|
2009-02-09 02:57:15 +00:00
|
|
|
uint16 colour; ///< colour of the item on the map
|
|
|
|
StringID legend; ///< string corresponding to the coloured item
|
2007-11-21 13:46:29 +00:00
|
|
|
IndustryType type; ///< type of industry
|
2009-02-09 02:57:15 +00:00
|
|
|
bool show_on_map; ///< for filtering industries, if true is shown on map in colour
|
2007-11-19 04:34:40 +00:00
|
|
|
bool end; ///< this is the end of the list
|
|
|
|
bool col_break; ///< perform a break and go one collumn further
|
2007-04-16 20:44:22 +01:00
|
|
|
};
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2007-04-16 20:44:22 +01:00
|
|
|
/** Legend text giving the colours to look for on the minimap */
|
|
|
|
static const LegendAndColour _legend_land_contours[] = {
|
2006-08-22 15:38:37 +01:00
|
|
|
MK(0x5A, STR_00F0_100M),
|
|
|
|
MK(0x5C, STR_00F1_200M),
|
|
|
|
MK(0x5E, STR_00F2_300M),
|
|
|
|
MK(0x1F, STR_00F3_400M),
|
|
|
|
MK(0x27, STR_00F4_500M),
|
|
|
|
|
|
|
|
MS(0xD7, STR_00EB_ROADS),
|
|
|
|
MK(0x0A, STR_00EC_RAILROADS),
|
|
|
|
MK(0x98, STR_00ED_STATIONS_AIRPORTS_DOCKS),
|
|
|
|
MK(0xB5, STR_00EE_BUILDINGS_INDUSTRIES),
|
|
|
|
MK(0x0F, STR_00EF_VEHICLES),
|
2004-08-09 18:04:08 +01:00
|
|
|
MKEND()
|
|
|
|
};
|
|
|
|
|
2007-04-16 20:44:22 +01:00
|
|
|
static const LegendAndColour _legend_vehicles[] = {
|
2006-08-22 15:38:37 +01:00
|
|
|
MK(0xB8, STR_00F5_TRAINS),
|
|
|
|
MK(0xBF, STR_00F6_ROAD_VEHICLES),
|
|
|
|
MK(0x98, STR_00F7_SHIPS),
|
|
|
|
MK(0x0F, STR_00F8_AIRCRAFT),
|
|
|
|
MS(0xD7, STR_00F9_TRANSPORT_ROUTES),
|
|
|
|
MK(0xB5, STR_00EE_BUILDINGS_INDUSTRIES),
|
2004-08-09 18:04:08 +01:00
|
|
|
MKEND()
|
|
|
|
};
|
|
|
|
|
2007-04-16 20:44:22 +01:00
|
|
|
static const LegendAndColour _legend_routes[] = {
|
2006-08-22 15:38:37 +01:00
|
|
|
MK(0xD7, STR_00EB_ROADS),
|
|
|
|
MK(0x0A, STR_00EC_RAILROADS),
|
|
|
|
MK(0xB5, STR_00EE_BUILDINGS_INDUSTRIES),
|
|
|
|
MS(0x56, STR_011B_RAILROAD_STATION),
|
|
|
|
|
|
|
|
MK(0xC2, STR_011C_TRUCK_LOADING_BAY),
|
|
|
|
MK(0xBF, STR_011D_BUS_STATION),
|
|
|
|
MK(0xB8, STR_011E_AIRPORT_HELIPORT),
|
|
|
|
MK(0x98, STR_011F_DOCK),
|
2004-08-09 18:04:08 +01:00
|
|
|
MKEND()
|
|
|
|
};
|
|
|
|
|
2007-04-16 20:44:22 +01:00
|
|
|
static const LegendAndColour _legend_vegetation[] = {
|
2006-08-22 15:38:37 +01:00
|
|
|
MK(0x52, STR_0120_ROUGH_LAND),
|
|
|
|
MK(0x54, STR_0121_GRASS_LAND),
|
|
|
|
MK(0x37, STR_0122_BARE_LAND),
|
|
|
|
MK(0x25, STR_0123_FIELDS),
|
|
|
|
MK(0x57, STR_0124_TREES),
|
|
|
|
MK(0xD0, STR_00FC_FOREST),
|
|
|
|
MS(0x0A, STR_0125_ROCKS),
|
|
|
|
|
|
|
|
MK(0xC2, STR_012A_DESERT),
|
|
|
|
MK(0x98, STR_012B_SNOW),
|
|
|
|
MK(0xD7, STR_00F9_TRANSPORT_ROUTES),
|
|
|
|
MK(0xB5, STR_00EE_BUILDINGS_INDUSTRIES),
|
2004-08-09 18:04:08 +01:00
|
|
|
MKEND()
|
|
|
|
};
|
|
|
|
|
2007-04-16 20:44:22 +01:00
|
|
|
static const LegendAndColour _legend_land_owners[] = {
|
2006-08-22 15:38:37 +01:00
|
|
|
MK(0xCA, STR_0126_WATER),
|
|
|
|
MK(0x54, STR_0127_NO_OWNER),
|
|
|
|
MK(0xB4, STR_0128_TOWNS),
|
|
|
|
MK(0x20, STR_0129_INDUSTRIES),
|
2004-08-09 18:04:08 +01:00
|
|
|
MKEND()
|
|
|
|
};
|
|
|
|
#undef MK
|
|
|
|
#undef MS
|
|
|
|
#undef MKEND
|
|
|
|
|
2007-04-26 21:20:12 +01:00
|
|
|
/** Allow room for all industries, plus a terminator entry
|
|
|
|
* This is required in order to have the indutry slots all filled up */
|
2009-01-09 22:56:28 +00:00
|
|
|
static LegendAndColour _legend_from_industries[NUM_INDUSTRYTYPES + 1];
|
2007-11-19 04:34:40 +00:00
|
|
|
/* For connecting industry type to position in industries list(small map legend) */
|
|
|
|
static uint _industry_to_list_pos[NUM_INDUSTRYTYPES];
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2007-04-26 21:20:12 +01:00
|
|
|
/**
|
|
|
|
* Fills an array for the industries legends.
|
|
|
|
*/
|
|
|
|
void BuildIndustriesLegend()
|
|
|
|
{
|
|
|
|
const IndustrySpec *indsp;
|
|
|
|
uint j = 0;
|
|
|
|
|
|
|
|
/* Add each name */
|
|
|
|
for (IndustryType i = 0; i < NUM_INDUSTRYTYPES; i++) {
|
|
|
|
indsp = GetIndustrySpec(i);
|
2007-05-30 02:55:11 +01:00
|
|
|
if (indsp->enabled) {
|
2007-04-26 21:20:12 +01:00
|
|
|
_legend_from_industries[j].legend = indsp->name;
|
|
|
|
_legend_from_industries[j].colour = indsp->map_colour;
|
2007-11-21 13:46:29 +00:00
|
|
|
_legend_from_industries[j].type = i;
|
2007-11-19 04:34:40 +00:00
|
|
|
_legend_from_industries[j].show_on_map = true;
|
|
|
|
_legend_from_industries[j].col_break = false;
|
2007-04-26 21:20:12 +01:00
|
|
|
_legend_from_industries[j].end = false;
|
2007-11-19 04:34:40 +00:00
|
|
|
|
|
|
|
/* Store widget number for this industry type */
|
|
|
|
_industry_to_list_pos[i] = j;
|
2007-04-26 21:20:12 +01:00
|
|
|
j++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Terminate the list */
|
|
|
|
_legend_from_industries[j].end = true;
|
2007-11-19 04:34:40 +00:00
|
|
|
|
|
|
|
/* Store number of enabled industries */
|
|
|
|
_smallmap_industry_count = j;
|
2007-04-26 21:20:12 +01:00
|
|
|
}
|
2007-04-16 20:44:22 +01:00
|
|
|
|
|
|
|
static const LegendAndColour * const _legend_table[] = {
|
2004-08-09 18:04:08 +01:00
|
|
|
_legend_land_contours,
|
|
|
|
_legend_vehicles,
|
2007-04-26 21:20:12 +01:00
|
|
|
_legend_from_industries,
|
2004-08-09 18:04:08 +01:00
|
|
|
_legend_routes,
|
|
|
|
_legend_vegetation,
|
|
|
|
_legend_land_owners,
|
|
|
|
};
|
|
|
|
|
2009-02-09 02:57:15 +00:00
|
|
|
#define MKCOLOUR(x) TO_LE32X(x)
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2007-07-23 20:30:36 +01:00
|
|
|
/**
|
|
|
|
* Height encodings; MAX_TILE_HEIGHT + 1 levels, from 0 to MAX_TILE_HEIGHT
|
|
|
|
*/
|
|
|
|
static const uint32 _map_height_bits[] = {
|
2009-02-09 02:57:15 +00:00
|
|
|
MKCOLOUR(0x5A5A5A5A),
|
|
|
|
MKCOLOUR(0x5A5B5A5B),
|
|
|
|
MKCOLOUR(0x5B5B5B5B),
|
|
|
|
MKCOLOUR(0x5B5C5B5C),
|
|
|
|
MKCOLOUR(0x5C5C5C5C),
|
|
|
|
MKCOLOUR(0x5C5D5C5D),
|
|
|
|
MKCOLOUR(0x5D5D5D5D),
|
|
|
|
MKCOLOUR(0x5D5E5D5E),
|
|
|
|
MKCOLOUR(0x5E5E5E5E),
|
|
|
|
MKCOLOUR(0x5E5F5E5F),
|
|
|
|
MKCOLOUR(0x5F5F5F5F),
|
|
|
|
MKCOLOUR(0x5F1F5F1F),
|
|
|
|
MKCOLOUR(0x1F1F1F1F),
|
|
|
|
MKCOLOUR(0x1F271F27),
|
|
|
|
MKCOLOUR(0x27272727),
|
|
|
|
MKCOLOUR(0x27272727),
|
2004-08-09 18:04:08 +01:00
|
|
|
};
|
2007-07-23 20:30:36 +01:00
|
|
|
assert_compile(lengthof(_map_height_bits) == MAX_TILE_HEIGHT + 1);
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2007-03-07 12:11:48 +00:00
|
|
|
struct AndOr {
|
2005-03-15 18:31:38 +00:00
|
|
|
uint32 mor;
|
|
|
|
uint32 mand;
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2005-03-15 18:31:38 +00:00
|
|
|
|
2006-07-26 04:33:12 +01:00
|
|
|
static inline uint32 ApplyMask(uint32 colour, const AndOr *mask)
|
2005-03-15 18:31:38 +00:00
|
|
|
{
|
|
|
|
return (colour & mask->mand) | mask->mor;
|
|
|
|
}
|
|
|
|
|
2005-06-06 16:58:58 +01:00
|
|
|
|
2005-03-15 18:31:38 +00:00
|
|
|
static const AndOr _smallmap_contours_andor[] = {
|
2009-02-09 02:57:15 +00:00
|
|
|
{MKCOLOUR(0x00000000), MKCOLOUR(0xFFFFFFFF)},
|
|
|
|
{MKCOLOUR(0x000A0A00), MKCOLOUR(0xFF0000FF)},
|
|
|
|
{MKCOLOUR(0x00D7D700), MKCOLOUR(0xFF0000FF)},
|
|
|
|
{MKCOLOUR(0x00B5B500), MKCOLOUR(0xFF0000FF)},
|
|
|
|
{MKCOLOUR(0x00000000), MKCOLOUR(0xFFFFFFFF)},
|
|
|
|
{MKCOLOUR(0x98989898), MKCOLOUR(0x00000000)},
|
|
|
|
{MKCOLOUR(0xCACACACA), MKCOLOUR(0x00000000)},
|
|
|
|
{MKCOLOUR(0x00000000), MKCOLOUR(0xFFFFFFFF)},
|
|
|
|
{MKCOLOUR(0xB5B5B5B5), MKCOLOUR(0x00000000)},
|
|
|
|
{MKCOLOUR(0x00000000), MKCOLOUR(0xFFFFFFFF)},
|
|
|
|
{MKCOLOUR(0x00B5B500), MKCOLOUR(0xFF0000FF)},
|
|
|
|
{MKCOLOUR(0x000A0A00), MKCOLOUR(0xFF0000FF)},
|
2004-08-09 18:04:08 +01:00
|
|
|
};
|
|
|
|
|
2005-03-15 18:31:38 +00:00
|
|
|
static const AndOr _smallmap_vehicles_andor[] = {
|
2009-02-09 02:57:15 +00:00
|
|
|
{MKCOLOUR(0x00000000), MKCOLOUR(0xFFFFFFFF)},
|
|
|
|
{MKCOLOUR(0x00D7D700), MKCOLOUR(0xFF0000FF)},
|
|
|
|
{MKCOLOUR(0x00D7D700), MKCOLOUR(0xFF0000FF)},
|
|
|
|
{MKCOLOUR(0x00B5B500), MKCOLOUR(0xFF0000FF)},
|
|
|
|
{MKCOLOUR(0x00000000), MKCOLOUR(0xFFFFFFFF)},
|
|
|
|
{MKCOLOUR(0x00D7D700), MKCOLOUR(0xFF0000FF)},
|
|
|
|
{MKCOLOUR(0xCACACACA), MKCOLOUR(0x00000000)},
|
|
|
|
{MKCOLOUR(0x00000000), MKCOLOUR(0xFFFFFFFF)},
|
|
|
|
{MKCOLOUR(0xB5B5B5B5), MKCOLOUR(0x00000000)},
|
|
|
|
{MKCOLOUR(0x00000000), MKCOLOUR(0xFFFFFFFF)},
|
|
|
|
{MKCOLOUR(0x00B5B500), MKCOLOUR(0xFF0000FF)},
|
|
|
|
{MKCOLOUR(0x00D7D700), MKCOLOUR(0xFF0000FF)},
|
2004-08-09 18:04:08 +01:00
|
|
|
};
|
|
|
|
|
2005-03-15 18:31:38 +00:00
|
|
|
static const AndOr _smallmap_vegetation_andor[] = {
|
2009-02-09 02:57:15 +00:00
|
|
|
{MKCOLOUR(0x00000000), MKCOLOUR(0xFFFFFFFF)},
|
|
|
|
{MKCOLOUR(0x00D7D700), MKCOLOUR(0xFF0000FF)},
|
|
|
|
{MKCOLOUR(0x00D7D700), MKCOLOUR(0xFF0000FF)},
|
|
|
|
{MKCOLOUR(0x00B5B500), MKCOLOUR(0xFF0000FF)},
|
|
|
|
{MKCOLOUR(0x00575700), MKCOLOUR(0xFF0000FF)},
|
|
|
|
{MKCOLOUR(0x00D7D700), MKCOLOUR(0xFF0000FF)},
|
|
|
|
{MKCOLOUR(0xCACACACA), MKCOLOUR(0x00000000)},
|
|
|
|
{MKCOLOUR(0x00000000), MKCOLOUR(0xFFFFFFFF)},
|
|
|
|
{MKCOLOUR(0xB5B5B5B5), MKCOLOUR(0x00000000)},
|
|
|
|
{MKCOLOUR(0x00000000), MKCOLOUR(0xFFFFFFFF)},
|
|
|
|
{MKCOLOUR(0x00B5B500), MKCOLOUR(0xFF0000FF)},
|
|
|
|
{MKCOLOUR(0x00D7D700), MKCOLOUR(0xFF0000FF)},
|
2004-08-09 18:04:08 +01:00
|
|
|
};
|
|
|
|
|
2005-06-06 16:58:58 +01:00
|
|
|
typedef uint32 GetSmallMapPixels(TileIndex tile); // typedef callthrough function
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Draws one column of the small map in a certain mode onto the screen buffer. This
|
|
|
|
* function looks exactly the same for all types
|
|
|
|
*
|
|
|
|
* @param dst Pointer to a part of the screen buffer to write to.
|
|
|
|
* @param xc The X coordinate of the first tile in the column.
|
|
|
|
* @param yc The Y coordinate of the first tile in the column
|
|
|
|
* @param pitch Number of pixels to advance in the screen buffer each time a pixel is written.
|
|
|
|
* @param reps Number of lines to draw
|
|
|
|
* @param mask ?
|
|
|
|
* @param proc Pointer to the colour function
|
|
|
|
* @see GetSmallMapPixels(TileIndex)
|
|
|
|
*/
|
2007-06-12 21:24:12 +01:00
|
|
|
static void DrawSmallMapStuff(void *dst, uint xc, uint yc, int pitch, int reps, uint32 mask, GetSmallMapPixels *proc)
|
2005-06-06 16:58:58 +01:00
|
|
|
{
|
2007-06-17 21:30:28 +01:00
|
|
|
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
|
2007-08-29 22:30:03 +01:00
|
|
|
void *dst_ptr_abs_end = blitter->MoveTo(_screen.dst_ptr, 0, _screen.height);
|
|
|
|
void *dst_ptr_end = blitter->MoveTo(dst_ptr_abs_end, -4, 0);
|
2005-06-06 16:58:58 +01:00
|
|
|
|
|
|
|
do {
|
2007-04-04 02:35:16 +01:00
|
|
|
/* check if the tile (xc,yc) is within the map range */
|
2009-01-21 23:49:59 +00:00
|
|
|
uint min_xy = _settings_game.construction.freeform_edges ? 1 : 0;
|
|
|
|
if (IsInsideMM(xc, min_xy, MapMaxX()) && IsInsideMM(yc, min_xy, MapMaxY())) {
|
2007-04-04 02:35:16 +01:00
|
|
|
/* check if the dst pointer points to a pixel inside the screen buffer */
|
2007-08-29 22:30:03 +01:00
|
|
|
if (dst < _screen.dst_ptr) continue;
|
|
|
|
if (dst >= dst_ptr_abs_end) continue;
|
|
|
|
|
|
|
|
uint32 val = proc(TileXY(xc, yc)) & mask;
|
|
|
|
uint8 *val8 = (uint8 *)&val;
|
|
|
|
|
|
|
|
if (dst <= dst_ptr_end) {
|
|
|
|
blitter->SetPixelIfEmpty(dst, 0, 0, val8[0]);
|
|
|
|
blitter->SetPixelIfEmpty(dst, 1, 0, val8[1]);
|
|
|
|
blitter->SetPixelIfEmpty(dst, 2, 0, val8[2]);
|
|
|
|
blitter->SetPixelIfEmpty(dst, 3, 0, val8[3]);
|
|
|
|
} else {
|
|
|
|
/* It happens that there are only 1, 2 or 3 pixels left to fill, so in that special case, write till the end of the video-buffer */
|
|
|
|
int i = 0;
|
|
|
|
do {
|
|
|
|
blitter->SetPixelIfEmpty(dst, 0, 0, val8[i]);
|
|
|
|
} while (i++, dst = blitter->MoveTo(dst, 1, 0), dst < dst_ptr_abs_end);
|
|
|
|
}
|
2005-06-06 16:58:58 +01:00
|
|
|
}
|
2007-04-04 02:35:16 +01:00
|
|
|
/* switch to next tile in the column */
|
2007-06-17 21:30:28 +01:00
|
|
|
} while (xc++, yc++, dst = blitter->MoveTo(dst, pitch, 0), --reps != 0);
|
2005-06-06 16:58:58 +01:00
|
|
|
}
|
|
|
|
|
2005-03-17 16:31:18 +00:00
|
|
|
|
|
|
|
static inline TileType GetEffectiveTileType(TileIndex tile)
|
2004-08-09 18:04:08 +01:00
|
|
|
{
|
2005-03-17 16:31:18 +00:00
|
|
|
TileType t = GetTileType(tile);
|
2004-08-09 18:04:08 +01:00
|
|
|
|
|
|
|
if (t == MP_TUNNELBRIDGE) {
|
2007-12-16 19:30:42 +00:00
|
|
|
TransportType tt = GetTunnelBridgeTransportType(tile);
|
2006-03-11 17:06:16 +00:00
|
|
|
|
|
|
|
switch (tt) {
|
|
|
|
case TRANSPORT_RAIL: t = MP_RAILWAY; break;
|
2007-07-30 00:42:59 +01:00
|
|
|
case TRANSPORT_ROAD: t = MP_ROAD; break;
|
2006-03-11 17:06:16 +00:00
|
|
|
default: t = MP_WATER; break;
|
2004-08-09 18:04:08 +01:00
|
|
|
}
|
|
|
|
}
|
2005-03-17 16:31:18 +00:00
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
2005-06-06 16:58:58 +01:00
|
|
|
/**
|
2009-02-09 02:57:15 +00:00
|
|
|
* Return the colour a tile would be displayed with in the small map in mode "Contour".
|
|
|
|
* @param tile The tile of which we would like to get the colour.
|
|
|
|
* @return The colour of tile in the small map in mode "Contour"
|
2005-06-06 16:58:58 +01:00
|
|
|
*/
|
2005-03-17 16:31:18 +00:00
|
|
|
static inline uint32 GetSmallMapContoursPixels(TileIndex tile)
|
|
|
|
{
|
|
|
|
TileType t = GetEffectiveTileType(tile);
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2005-03-15 18:31:38 +00:00
|
|
|
return
|
|
|
|
ApplyMask(_map_height_bits[TileHeight(tile)], &_smallmap_contours_andor[t]);
|
2004-08-09 18:04:08 +01:00
|
|
|
}
|
|
|
|
|
2005-06-06 16:58:58 +01:00
|
|
|
/**
|
2009-02-09 02:57:15 +00:00
|
|
|
* Return the colour a tile would be displayed with in the small map in mode "Vehicles".
|
2005-06-06 16:58:58 +01:00
|
|
|
*
|
2009-02-09 02:57:15 +00:00
|
|
|
* @param tile The tile of which we would like to get the colour.
|
|
|
|
* @return The colour of tile in the small map in mode "Vehicles"
|
2005-06-06 16:58:58 +01:00
|
|
|
*/
|
2005-03-17 09:59:52 +00:00
|
|
|
static inline uint32 GetSmallMapVehiclesPixels(TileIndex tile)
|
2004-08-09 18:04:08 +01:00
|
|
|
{
|
2005-03-17 16:31:18 +00:00
|
|
|
TileType t = GetEffectiveTileType(tile);
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2009-02-09 02:57:15 +00:00
|
|
|
return ApplyMask(MKCOLOUR(0x54545454), &_smallmap_vehicles_andor[t]);
|
2004-08-09 18:04:08 +01:00
|
|
|
}
|
|
|
|
|
2005-06-06 16:58:58 +01:00
|
|
|
/**
|
2009-02-09 02:57:15 +00:00
|
|
|
* Return the colour a tile would be displayed with in the small map in mode "Industries".
|
2005-06-06 16:58:58 +01:00
|
|
|
*
|
2009-02-09 02:57:15 +00:00
|
|
|
* @param tile The tile of which we would like to get the colour.
|
|
|
|
* @return The colour of tile in the small map in mode "Industries"
|
2005-06-06 16:58:58 +01:00
|
|
|
*/
|
2005-03-17 09:59:52 +00:00
|
|
|
static inline uint32 GetSmallMapIndustriesPixels(TileIndex tile)
|
2004-08-09 18:04:08 +01:00
|
|
|
{
|
2005-03-17 16:31:18 +00:00
|
|
|
TileType t = GetEffectiveTileType(tile);
|
2004-08-09 18:04:08 +01:00
|
|
|
|
|
|
|
if (t == MP_INDUSTRY) {
|
2009-02-09 02:57:15 +00:00
|
|
|
/* If industry is allowed to be seen, use its colour on the map */
|
2007-11-19 04:34:40 +00:00
|
|
|
if (_legend_from_industries[_industry_to_list_pos[GetIndustryByTile(tile)->type]].show_on_map) {
|
|
|
|
return GetIndustrySpec(GetIndustryByTile(tile)->type)->map_colour * 0x01010101;
|
|
|
|
} else {
|
2009-02-09 02:57:15 +00:00
|
|
|
/* otherwise, return the colour of the clear tiles, which will make it disappear */
|
|
|
|
return ApplyMask(MKCOLOUR(0x54545454), &_smallmap_vehicles_andor[MP_CLEAR]);
|
2007-11-19 04:34:40 +00:00
|
|
|
}
|
2004-08-09 18:04:08 +01:00
|
|
|
}
|
|
|
|
|
2009-02-09 02:57:15 +00:00
|
|
|
return ApplyMask(MKCOLOUR(0x54545454), &_smallmap_vehicles_andor[t]);
|
2004-08-09 18:04:08 +01:00
|
|
|
}
|
|
|
|
|
2005-06-06 16:58:58 +01:00
|
|
|
/**
|
2009-02-09 02:57:15 +00:00
|
|
|
* Return the colour a tile would be displayed with in the small map in mode "Routes".
|
2005-06-06 16:58:58 +01:00
|
|
|
*
|
2009-02-09 02:57:15 +00:00
|
|
|
* @param tile The tile of which we would like to get the colour.
|
|
|
|
* @return The colour of tile in the small map in mode "Routes"
|
2005-06-06 16:58:58 +01:00
|
|
|
*/
|
2005-03-17 09:59:52 +00:00
|
|
|
static inline uint32 GetSmallMapRoutesPixels(TileIndex tile)
|
2004-08-09 18:04:08 +01:00
|
|
|
{
|
2005-03-17 16:31:18 +00:00
|
|
|
TileType t = GetEffectiveTileType(tile);
|
2004-08-09 18:04:08 +01:00
|
|
|
uint32 bits;
|
|
|
|
|
|
|
|
if (t == MP_STATION) {
|
2006-03-26 20:20:15 +01:00
|
|
|
switch (GetStationType(tile)) {
|
2009-02-09 02:57:15 +00:00
|
|
|
case STATION_RAIL: bits = MKCOLOUR(0x56565656); break;
|
|
|
|
case STATION_AIRPORT: bits = MKCOLOUR(0xB8B8B8B8); break;
|
|
|
|
case STATION_TRUCK: bits = MKCOLOUR(0xC2C2C2C2); break;
|
|
|
|
case STATION_BUS: bits = MKCOLOUR(0xBFBFBFBF); break;
|
|
|
|
case STATION_DOCK: bits = MKCOLOUR(0x98989898); break;
|
|
|
|
default: bits = MKCOLOUR(0xFFFFFFFF); break;
|
2006-03-26 20:20:15 +01:00
|
|
|
}
|
2004-08-09 18:04:08 +01:00
|
|
|
} else {
|
2009-02-09 02:57:15 +00:00
|
|
|
/* ground colour */
|
|
|
|
bits = ApplyMask(MKCOLOUR(0x54545454), &_smallmap_contours_andor[t]);
|
2004-08-09 18:04:08 +01:00
|
|
|
}
|
|
|
|
return bits;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-02-01 15:31:21 +00:00
|
|
|
static const uint32 _vegetation_clear_bits[] = {
|
2009-02-09 02:57:15 +00:00
|
|
|
MKCOLOUR(0x54545454), ///< full grass
|
|
|
|
MKCOLOUR(0x52525252), ///< rough land
|
|
|
|
MKCOLOUR(0x0A0A0A0A), ///< rocks
|
|
|
|
MKCOLOUR(0x25252525), ///< fields
|
|
|
|
MKCOLOUR(0x98989898), ///< snow
|
|
|
|
MKCOLOUR(0xC2C2C2C2), ///< desert
|
|
|
|
MKCOLOUR(0x54545454), ///< unused
|
|
|
|
MKCOLOUR(0x54545454), ///< unused
|
2004-08-09 18:04:08 +01:00
|
|
|
};
|
|
|
|
|
2005-03-17 09:59:52 +00:00
|
|
|
static inline uint32 GetSmallMapVegetationPixels(TileIndex tile)
|
2004-08-09 18:04:08 +01:00
|
|
|
{
|
2005-03-17 16:31:18 +00:00
|
|
|
TileType t = GetEffectiveTileType(tile);
|
2004-08-09 18:04:08 +01:00
|
|
|
uint32 bits;
|
|
|
|
|
2005-03-17 09:59:52 +00:00
|
|
|
switch (t) {
|
|
|
|
case MP_CLEAR:
|
2006-04-04 22:35:13 +01:00
|
|
|
if (IsClearGround(tile, CLEAR_GRASS) && GetClearDensity(tile) < 3) {
|
2009-02-09 02:57:15 +00:00
|
|
|
bits = MKCOLOUR(0x37373737);
|
2006-02-01 15:31:21 +00:00
|
|
|
} else {
|
|
|
|
bits = _vegetation_clear_bits[GetClearGround(tile)];
|
|
|
|
}
|
2005-03-17 09:59:52 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MP_INDUSTRY:
|
2009-02-09 02:57:15 +00:00
|
|
|
bits = GetIndustrySpec(GetIndustryByTile(tile)->type)->check_proc == CHECK_FOREST ? MKCOLOUR(0xD0D0D0D0) : MKCOLOUR(0xB5B5B5B5);
|
2005-03-17 09:59:52 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MP_TREES:
|
2006-04-04 07:25:05 +01:00
|
|
|
if (GetTreeGround(tile) == TREE_GROUND_SNOW_DESERT) {
|
2009-02-09 02:57:15 +00:00
|
|
|
bits = (_settings_game.game_creation.landscape == LT_ARCTIC) ? MKCOLOUR(0x98575798) : MKCOLOUR(0xC25757C2);
|
2006-02-01 06:32:03 +00:00
|
|
|
} else {
|
2009-02-09 02:57:15 +00:00
|
|
|
bits = MKCOLOUR(0x54575754);
|
2006-02-01 06:32:03 +00:00
|
|
|
}
|
2005-03-17 09:59:52 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2009-02-09 02:57:15 +00:00
|
|
|
bits = ApplyMask(MKCOLOUR(0x54545454), &_smallmap_vehicles_andor[t]);
|
2005-03-17 09:59:52 +00:00
|
|
|
break;
|
2004-08-09 18:04:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return bits;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-09 02:57:15 +00:00
|
|
|
static uint32 _owner_colours[OWNER_END + 1];
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2005-06-06 16:58:58 +01:00
|
|
|
/**
|
2009-02-09 02:57:15 +00:00
|
|
|
* Return the colour a tile would be displayed with in the small map in mode "Owner".
|
2005-06-06 16:58:58 +01:00
|
|
|
*
|
2009-02-09 02:57:15 +00:00
|
|
|
* @param tile The tile of which we would like to get the colour.
|
|
|
|
* @return The colour of tile in the small map in mode "Owner"
|
2005-06-06 16:58:58 +01:00
|
|
|
*/
|
2005-03-17 09:59:52 +00:00
|
|
|
static inline uint32 GetSmallMapOwnerPixels(TileIndex tile)
|
2004-08-09 18:04:08 +01:00
|
|
|
{
|
2005-08-27 14:04:15 +01:00
|
|
|
Owner o;
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2005-08-27 14:04:15 +01:00
|
|
|
switch (GetTileType(tile)) {
|
2006-10-14 16:43:37 +01:00
|
|
|
case MP_INDUSTRY: o = OWNER_END; break;
|
2005-08-27 14:04:15 +01:00
|
|
|
case MP_HOUSE: o = OWNER_TOWN; break;
|
|
|
|
default: o = GetTileOwner(tile); break;
|
2008-05-24 20:36:20 +01:00
|
|
|
/* FIXME: For MP_ROAD there are multiple owners.
|
|
|
|
* GetTileOwner returns the rail owner (level crossing) resp. the owner of ROADTYPE_ROAD (normal road),
|
|
|
|
* even if there are no ROADTYPE_ROAD bits on the tile.
|
|
|
|
*/
|
2004-08-09 18:04:08 +01:00
|
|
|
}
|
|
|
|
|
2009-02-09 02:57:15 +00:00
|
|
|
return _owner_colours[o];
|
2004-08-09 18:04:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static const uint32 _smallmap_mask_left[3] = {
|
2009-02-09 02:57:15 +00:00
|
|
|
MKCOLOUR(0xFF000000),
|
|
|
|
MKCOLOUR(0xFFFF0000),
|
|
|
|
MKCOLOUR(0xFFFFFF00),
|
2004-08-09 18:04:08 +01:00
|
|
|
};
|
|
|
|
|
2005-03-17 09:59:52 +00:00
|
|
|
static const uint32 _smallmap_mask_right[] = {
|
2009-02-09 02:57:15 +00:00
|
|
|
MKCOLOUR(0x000000FF),
|
|
|
|
MKCOLOUR(0x0000FFFF),
|
|
|
|
MKCOLOUR(0x00FFFFFF),
|
2004-08-09 18:04:08 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/* each tile has 4 x pixels and 1 y pixel */
|
|
|
|
|
2005-06-06 16:58:58 +01:00
|
|
|
static GetSmallMapPixels *_smallmap_draw_procs[] = {
|
|
|
|
GetSmallMapContoursPixels,
|
|
|
|
GetSmallMapVehiclesPixels,
|
|
|
|
GetSmallMapIndustriesPixels,
|
|
|
|
GetSmallMapRoutesPixels,
|
|
|
|
GetSmallMapVegetationPixels,
|
|
|
|
GetSmallMapOwnerPixels,
|
2004-08-09 18:04:08 +01:00
|
|
|
};
|
|
|
|
|
2009-02-09 02:57:15 +00:00
|
|
|
static const byte _vehicle_type_colours[6] = {
|
2004-08-09 18:04:08 +01:00
|
|
|
184, 191, 152, 15, 215, 184
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static void DrawVertMapIndicator(int x, int y, int x2, int y2)
|
|
|
|
{
|
2006-02-01 06:32:03 +00:00
|
|
|
GfxFillRect(x, y, x2, y + 3, 69);
|
|
|
|
GfxFillRect(x, y2 - 3, x2, y2, 69);
|
2004-08-09 18:04:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void DrawHorizMapIndicator(int x, int y, int x2, int y2)
|
|
|
|
{
|
2006-02-01 06:32:03 +00:00
|
|
|
GfxFillRect(x, y, x + 3, y2, 69);
|
|
|
|
GfxFillRect(x2 - 3, y, x2, y2, 69);
|
2004-08-09 18:04:08 +01:00
|
|
|
}
|
|
|
|
|
2007-11-19 00:57:56 +00:00
|
|
|
enum SmallMapWindowWidgets {
|
2008-08-04 06:59:28 +01:00
|
|
|
SM_WIDGET_MAP_BORDER = 3,
|
|
|
|
SM_WIDGET_MAP,
|
|
|
|
SM_WIDGET_LEGEND,
|
|
|
|
SM_WIDGET_BUTTONSPANEL,
|
2007-11-19 00:57:56 +00:00
|
|
|
SM_WIDGET_CONTOUR,
|
|
|
|
SM_WIDGET_VEHICLES,
|
|
|
|
SM_WIDGET_INDUSTRIES,
|
|
|
|
SM_WIDGET_ROUTES,
|
|
|
|
SM_WIDGET_VEGETATION,
|
|
|
|
SM_WIDGET_OWNERS,
|
|
|
|
SM_WIDGET_CENTERMAP,
|
|
|
|
SM_WIDGET_TOGGLETOWNNAME,
|
2007-11-19 04:34:40 +00:00
|
|
|
SM_WIDGET_BOTTOMPANEL,
|
|
|
|
SM_WIDGET_ENABLEINDUSTRIES,
|
|
|
|
SM_WIDGET_DISABLEINDUSTRIES,
|
|
|
|
SM_WIDGET_RESIZEBOX,
|
2007-11-19 00:57:56 +00:00
|
|
|
};
|
|
|
|
|
2008-05-11 20:47:10 +01:00
|
|
|
class SmallMapWindow : public Window
|
2004-08-09 18:04:08 +01:00
|
|
|
{
|
2008-05-11 20:47:10 +01:00
|
|
|
enum SmallMapType {
|
|
|
|
SMT_CONTOUR,
|
|
|
|
SMT_VEHICLES,
|
|
|
|
SMT_INDUSTRY,
|
2008-08-05 01:17:56 +01:00
|
|
|
SMT_ROUTES,
|
|
|
|
SMT_VEGETATION,
|
|
|
|
SMT_OWNER,
|
2008-05-11 20:47:10 +01:00
|
|
|
};
|
|
|
|
|
2008-08-03 15:58:26 +01:00
|
|
|
static SmallMapType map_type;
|
|
|
|
static bool show_towns;
|
|
|
|
|
2008-05-11 20:47:10 +01:00
|
|
|
int32 scroll_x;
|
|
|
|
int32 scroll_y;
|
|
|
|
int32 subscroll;
|
2008-05-29 12:47:56 +01:00
|
|
|
uint8 refresh;
|
2008-05-11 20:47:10 +01:00
|
|
|
|
2008-08-04 06:59:28 +01:00
|
|
|
static const int COLUMN_WIDTH = 119;
|
|
|
|
static const int MIN_LEGEND_HEIGHT = 6 * 7;
|
|
|
|
|
2008-05-11 20:47:10 +01:00
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Draws the small map.
|
|
|
|
*
|
|
|
|
* Basically, the small map is draw column of pixels by column of pixels. The pixels
|
|
|
|
* are drawn directly into the screen buffer. The final map is drawn in multiple passes.
|
|
|
|
* The passes are:
|
2009-02-09 02:57:15 +00:00
|
|
|
* <ol><li>The colours of tiles in the different modes.</li>
|
2008-05-11 20:47:10 +01:00
|
|
|
* <li>Town names (optional)</li></ol>
|
|
|
|
*
|
|
|
|
* @param dpi pointer to pixel to write onto
|
|
|
|
* @param w pointer to Window struct
|
|
|
|
* @param type type of map requested (vegetation, owners, routes, etc)
|
|
|
|
* @param show_towns true if the town names should be displayed, false if not.
|
|
|
|
*/
|
2008-08-03 15:58:26 +01:00
|
|
|
void DrawSmallMap(DrawPixelInfo *dpi)
|
2008-05-11 20:47:10 +01:00
|
|
|
{
|
|
|
|
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
|
|
|
|
DrawPixelInfo *old_dpi;
|
2009-01-09 22:56:28 +00:00
|
|
|
int dx, dy, x, y, x2, y2;
|
2008-05-11 20:47:10 +01:00
|
|
|
void *ptr;
|
|
|
|
int tile_x;
|
|
|
|
int tile_y;
|
|
|
|
ViewPort *vp;
|
|
|
|
|
|
|
|
old_dpi = _cur_dpi;
|
|
|
|
_cur_dpi = dpi;
|
|
|
|
|
|
|
|
/* clear it */
|
|
|
|
GfxFillRect(dpi->left, dpi->top, dpi->left + dpi->width - 1, dpi->top + dpi->height - 1, 0);
|
|
|
|
|
|
|
|
/* setup owner table */
|
2008-08-03 15:58:26 +01:00
|
|
|
if (this->map_type == SMT_OWNER) {
|
2008-09-30 21:39:50 +01:00
|
|
|
const Company *c;
|
2008-05-11 20:47:10 +01:00
|
|
|
|
2009-02-09 02:57:15 +00:00
|
|
|
/* fill with some special colours */
|
|
|
|
_owner_colours[OWNER_TOWN] = MKCOLOUR(0xB4B4B4B4);
|
|
|
|
_owner_colours[OWNER_NONE] = MKCOLOUR(0x54545454);
|
|
|
|
_owner_colours[OWNER_WATER] = MKCOLOUR(0xCACACACA);
|
2009-03-15 00:32:18 +00:00
|
|
|
_owner_colours[OWNER_END] = MKCOLOUR(0x20202020); // industry
|
2008-05-11 20:47:10 +01:00
|
|
|
|
2008-09-30 21:39:50 +01:00
|
|
|
/* now fill with the company colours */
|
|
|
|
FOR_ALL_COMPANIES(c) {
|
2009-02-09 02:57:15 +00:00
|
|
|
_owner_colours[c->index] =
|
2008-09-30 21:39:50 +01:00
|
|
|
_colour_gradient[c->colour][5] * 0x01010101;
|
2006-02-01 06:32:03 +00:00
|
|
|
}
|
2004-09-10 20:02:27 +01:00
|
|
|
}
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2008-05-11 20:47:10 +01:00
|
|
|
tile_x = this->scroll_x / TILE_SIZE;
|
|
|
|
tile_y = this->scroll_y / TILE_SIZE;
|
|
|
|
|
|
|
|
dx = dpi->left + this->subscroll;
|
|
|
|
tile_x -= dx / 4;
|
|
|
|
tile_y += dx / 4;
|
|
|
|
dx &= 3;
|
|
|
|
|
|
|
|
dy = dpi->top;
|
|
|
|
tile_x += dy / 2;
|
|
|
|
tile_y += dy / 2;
|
|
|
|
|
|
|
|
if (dy & 1) {
|
|
|
|
tile_x++;
|
|
|
|
dx += 2;
|
|
|
|
if (dx > 3) {
|
|
|
|
dx -= 4;
|
|
|
|
tile_x--;
|
|
|
|
tile_y++;
|
|
|
|
}
|
2004-08-09 18:04:08 +01:00
|
|
|
}
|
|
|
|
|
2008-05-11 20:47:10 +01:00
|
|
|
ptr = blitter->MoveTo(dpi->dst_ptr, -dx - 4, 0);
|
|
|
|
x = - dx - 4;
|
|
|
|
y = 0;
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2008-05-11 20:47:10 +01:00
|
|
|
for (;;) {
|
|
|
|
uint32 mask = 0xFFFFFFFF;
|
|
|
|
int reps;
|
|
|
|
int t;
|
2005-03-17 09:59:52 +00:00
|
|
|
|
2008-05-11 20:47:10 +01:00
|
|
|
/* distance from left edge */
|
|
|
|
if (x < 0) {
|
|
|
|
if (x < -3) goto skip_column;
|
|
|
|
/* mask to use at the left edge */
|
|
|
|
mask = _smallmap_mask_left[x + 3];
|
|
|
|
}
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2008-05-11 20:47:10 +01:00
|
|
|
/* distance from right edge */
|
|
|
|
t = dpi->width - x;
|
|
|
|
if (t < 4) {
|
2009-03-15 00:32:18 +00:00
|
|
|
if (t <= 0) break; // exit loop
|
2008-05-11 20:47:10 +01:00
|
|
|
/* mask to use at the right edge */
|
|
|
|
mask &= _smallmap_mask_right[t - 1];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* number of lines */
|
|
|
|
reps = (dpi->height - y + 1) / 2;
|
|
|
|
if (reps > 0) {
|
2008-08-03 15:58:26 +01:00
|
|
|
DrawSmallMapStuff(ptr, tile_x, tile_y, dpi->pitch * 2, reps, mask, _smallmap_draw_procs[this->map_type]);
|
2008-05-11 20:47:10 +01:00
|
|
|
}
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2008-05-11 20:47:10 +01:00
|
|
|
skip_column:
|
|
|
|
if (y == 0) {
|
|
|
|
tile_y++;
|
|
|
|
y++;
|
|
|
|
ptr = blitter->MoveTo(ptr, 0, 1);
|
|
|
|
} else {
|
|
|
|
tile_x--;
|
|
|
|
y--;
|
|
|
|
ptr = blitter->MoveTo(ptr, 0, -1);
|
|
|
|
}
|
|
|
|
ptr = blitter->MoveTo(ptr, 2, 0);
|
|
|
|
x += 2;
|
2004-08-09 18:04:08 +01:00
|
|
|
}
|
|
|
|
|
2008-05-11 20:47:10 +01:00
|
|
|
/* draw vehicles? */
|
2008-08-03 15:58:26 +01:00
|
|
|
if (this->map_type == SMT_CONTOUR || this->map_type == SMT_VEHICLES) {
|
2008-05-11 20:47:10 +01:00
|
|
|
Vehicle *v;
|
|
|
|
bool skip;
|
2009-02-09 02:57:15 +00:00
|
|
|
byte colour;
|
2008-05-11 20:47:10 +01:00
|
|
|
|
|
|
|
FOR_ALL_VEHICLES(v) {
|
|
|
|
if (v->type != VEH_EFFECT &&
|
|
|
|
(v->vehstatus & (VS_HIDDEN | VS_UNCLICKABLE)) == 0) {
|
|
|
|
/* Remap into flat coordinates. */
|
|
|
|
Point pt = RemapCoords(
|
|
|
|
v->x_pos / TILE_SIZE - this->scroll_x / TILE_SIZE, // divide each one separately because (a-b)/c != a/c-b/c in integer world
|
|
|
|
v->y_pos / TILE_SIZE - this->scroll_y / TILE_SIZE, // dtto
|
|
|
|
0);
|
|
|
|
x = pt.x;
|
|
|
|
y = pt.y;
|
|
|
|
|
|
|
|
/* Check if y is out of bounds? */
|
|
|
|
y -= dpi->top;
|
|
|
|
if (!IsInsideMM(y, 0, dpi->height)) continue;
|
|
|
|
|
|
|
|
/* Default is to draw both pixels. */
|
|
|
|
skip = false;
|
|
|
|
|
|
|
|
/* Offset X coordinate */
|
|
|
|
x -= this->subscroll + 3 + dpi->left;
|
|
|
|
|
|
|
|
if (x < 0) {
|
|
|
|
/* if x+1 is 0, that means we're on the very left edge,
|
|
|
|
* and should thus only draw a single pixel */
|
|
|
|
if (++x != 0) continue;
|
|
|
|
skip = true;
|
|
|
|
} else if (x >= dpi->width - 1) {
|
|
|
|
/* Check if we're at the very right edge, and if so draw only a single pixel */
|
|
|
|
if (x != dpi->width - 1) continue;
|
|
|
|
skip = true;
|
|
|
|
}
|
|
|
|
|
2009-02-09 02:57:15 +00:00
|
|
|
/* Calculate pointer to pixel and the colour */
|
|
|
|
colour = (this->map_type == SMT_VEHICLES) ? _vehicle_type_colours[v->type] : 0xF;
|
2008-05-11 20:47:10 +01:00
|
|
|
|
|
|
|
/* And draw either one or two pixels depending on clipping */
|
2009-02-09 02:57:15 +00:00
|
|
|
blitter->SetPixel(dpi->dst_ptr, x, y, colour);
|
|
|
|
if (!skip) blitter->SetPixel(dpi->dst_ptr, x + 1, y, colour);
|
2008-05-11 20:47:10 +01:00
|
|
|
}
|
|
|
|
}
|
2004-08-09 18:04:08 +01:00
|
|
|
}
|
|
|
|
|
2008-08-03 15:58:26 +01:00
|
|
|
if (this->show_towns) {
|
2008-05-11 20:47:10 +01:00
|
|
|
const Town *t;
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2008-05-11 20:47:10 +01:00
|
|
|
FOR_ALL_TOWNS(t) {
|
|
|
|
/* Remap the town coordinate */
|
2004-08-09 18:04:08 +01:00
|
|
|
Point pt = RemapCoords(
|
2008-05-11 20:47:10 +01:00
|
|
|
(int)(TileX(t->xy) * TILE_SIZE - this->scroll_x) / TILE_SIZE,
|
|
|
|
(int)(TileY(t->xy) * TILE_SIZE - this->scroll_y) / TILE_SIZE,
|
2004-08-09 18:04:08 +01:00
|
|
|
0);
|
2008-05-11 20:47:10 +01:00
|
|
|
x = pt.x - this->subscroll + 3 - (t->sign.width_2 >> 1);
|
2004-08-09 18:04:08 +01:00
|
|
|
y = pt.y;
|
|
|
|
|
2008-05-11 20:47:10 +01:00
|
|
|
/* Check if the town sign is within bounds */
|
|
|
|
if (x + t->sign.width_2 > dpi->left &&
|
|
|
|
x < dpi->left + dpi->width &&
|
|
|
|
y + 6 > dpi->top &&
|
|
|
|
y < dpi->top + dpi->height) {
|
|
|
|
/* And draw it. */
|
|
|
|
SetDParam(0, t->index);
|
2009-03-22 14:55:49 +00:00
|
|
|
DrawString(x, x + t->sign.width_2, y, STR_2056, TC_WHITE);
|
2004-08-09 18:04:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-11 20:47:10 +01:00
|
|
|
/* Draw map indicators */
|
|
|
|
{
|
|
|
|
Point pt;
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2008-05-11 20:47:10 +01:00
|
|
|
/* Find main viewport. */
|
2009-01-09 22:56:28 +00:00
|
|
|
vp = FindWindowById(WC_MAIN_WINDOW, 0)->viewport;
|
2004-09-10 20:02:27 +01:00
|
|
|
|
2008-05-11 20:47:10 +01:00
|
|
|
pt = RemapCoords(this->scroll_x, this->scroll_y, 0);
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2008-05-11 20:47:10 +01:00
|
|
|
x = vp->virtual_left - pt.x;
|
|
|
|
y = vp->virtual_top - pt.y;
|
|
|
|
x2 = (x + vp->virtual_width) / TILE_SIZE;
|
|
|
|
y2 = (y + vp->virtual_height) / TILE_SIZE;
|
|
|
|
x /= TILE_SIZE;
|
|
|
|
y /= TILE_SIZE;
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2008-05-11 20:47:10 +01:00
|
|
|
x -= this->subscroll;
|
|
|
|
x2 -= this->subscroll;
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2008-05-11 20:47:10 +01:00
|
|
|
DrawVertMapIndicator(x, y, x, y2);
|
|
|
|
DrawVertMapIndicator(x2, y, x2, y2);
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2008-05-11 20:47:10 +01:00
|
|
|
DrawHorizMapIndicator(x, y, x2, y);
|
|
|
|
DrawHorizMapIndicator(x, y2, x2, y2);
|
|
|
|
}
|
|
|
|
_cur_dpi = old_dpi;
|
2004-08-09 18:04:08 +01:00
|
|
|
}
|
|
|
|
|
2008-05-11 20:47:10 +01:00
|
|
|
void SmallMapCenterOnCurrentPos()
|
|
|
|
{
|
|
|
|
int x, y;
|
|
|
|
ViewPort *vp;
|
|
|
|
vp = FindWindowById(WC_MAIN_WINDOW, 0)->viewport;
|
|
|
|
|
|
|
|
x = ((vp->virtual_width - (this->widget[SM_WIDGET_MAP].right - this->widget[SM_WIDGET_MAP].left) * TILE_SIZE) / 2 + vp->virtual_left) / 4;
|
|
|
|
y = ((vp->virtual_height - (this->widget[SM_WIDGET_MAP].bottom - this->widget[SM_WIDGET_MAP].top ) * TILE_SIZE) / 2 + vp->virtual_top ) / 2 - TILE_SIZE * 2;
|
|
|
|
this->scroll_x = (y - x) & ~0xF;
|
|
|
|
this->scroll_y = (x + y) & ~0xF;
|
|
|
|
this->SetDirty();
|
|
|
|
}
|
2006-08-21 18:41:04 +01:00
|
|
|
|
2008-08-04 06:59:28 +01:00
|
|
|
void ResizeLegend()
|
2008-05-11 20:47:10 +01:00
|
|
|
{
|
2008-08-03 21:09:35 +01:00
|
|
|
Widget *legend = &this->widget[SM_WIDGET_LEGEND];
|
2008-08-04 06:59:28 +01:00
|
|
|
int rows = (legend->bottom - legend->top) - 1;
|
|
|
|
int columns = (legend->right - legend->left) / COLUMN_WIDTH;
|
|
|
|
int new_rows = (this->map_type == SMT_INDUSTRY) ? ((_smallmap_industry_count + columns - 1) / columns) * 6 : MIN_LEGEND_HEIGHT;
|
|
|
|
|
|
|
|
new_rows = max(new_rows, MIN_LEGEND_HEIGHT);
|
|
|
|
|
|
|
|
if (new_rows != rows) {
|
|
|
|
this->SetDirty();
|
2008-08-03 21:09:35 +01:00
|
|
|
|
2008-08-04 06:59:28 +01:00
|
|
|
/* The legend widget needs manual adjustment as by default
|
|
|
|
* it lays outside the filler widget's bounds. */
|
|
|
|
legend->top--;
|
2008-08-03 21:09:35 +01:00
|
|
|
/* Resize the filler widget, and move widgets below it. */
|
2008-08-04 06:59:28 +01:00
|
|
|
ResizeWindowForWidget(this, SM_WIDGET_BUTTONSPANEL, 0, new_rows - rows);
|
|
|
|
legend->top++;
|
|
|
|
|
|
|
|
/* Resize map border widget so the window stays the same size */
|
|
|
|
ResizeWindowForWidget(this, SM_WIDGET_MAP_BORDER, 0, rows - new_rows);
|
|
|
|
/* Manually adjust the map widget as it lies completely within
|
|
|
|
* the map border widget */
|
|
|
|
this->widget[SM_WIDGET_MAP].bottom += rows - new_rows;
|
|
|
|
|
|
|
|
this->SetDirty();
|
2008-05-11 20:47:10 +01:00
|
|
|
}
|
2008-08-04 06:59:28 +01:00
|
|
|
}
|
2007-11-19 04:34:40 +00:00
|
|
|
|
2008-08-04 06:59:28 +01:00
|
|
|
SmallMapWindow(const WindowDesc *desc, int window_number) : Window(desc, window_number)
|
|
|
|
{
|
2008-08-03 15:58:26 +01:00
|
|
|
this->LowerWidget(this->map_type + SM_WIDGET_CONTOUR);
|
|
|
|
this->SetWidgetLoweredState(SM_WIDGET_TOGGLETOWNNAME, this->show_towns);
|
2006-08-29 01:17:47 +01:00
|
|
|
|
2008-05-11 20:47:10 +01:00
|
|
|
this->SmallMapCenterOnCurrentPos();
|
|
|
|
this->FindWindowPlacementAndResize(desc);
|
|
|
|
}
|
2007-11-19 04:34:40 +00:00
|
|
|
|
2008-05-11 20:47:10 +01:00
|
|
|
virtual void OnPaint()
|
|
|
|
{
|
|
|
|
DrawPixelInfo new_dpi;
|
|
|
|
|
|
|
|
/* Hide Enable all/Disable all buttons if is not industry type small map*/
|
2008-08-03 15:58:26 +01:00
|
|
|
this->SetWidgetHiddenState(SM_WIDGET_ENABLEINDUSTRIES, this->map_type != SMT_INDUSTRY);
|
|
|
|
this->SetWidgetHiddenState(SM_WIDGET_DISABLEINDUSTRIES, this->map_type != SMT_INDUSTRY);
|
2008-05-11 20:47:10 +01:00
|
|
|
|
|
|
|
/* draw the window */
|
2008-08-03 15:58:26 +01:00
|
|
|
SetDParam(0, STR_00E5_CONTOURS + this->map_type);
|
2008-05-17 13:48:06 +01:00
|
|
|
this->DrawWidgets();
|
2008-05-11 20:47:10 +01:00
|
|
|
|
2008-08-03 21:09:35 +01:00
|
|
|
const Widget *legend = &this->widget[SM_WIDGET_LEGEND];
|
2008-05-11 20:47:10 +01:00
|
|
|
|
2008-08-03 21:09:35 +01:00
|
|
|
int y_org = legend->top + 1;
|
|
|
|
int x = 4;
|
|
|
|
int y = y_org;
|
2008-05-11 20:47:10 +01:00
|
|
|
|
2008-08-03 19:18:36 +01:00
|
|
|
for (const LegendAndColour *tbl = _legend_table[this->map_type]; !tbl->end; ++tbl) {
|
2008-08-03 21:09:35 +01:00
|
|
|
if (tbl->col_break || y >= legend->bottom) {
|
2008-08-04 06:59:28 +01:00
|
|
|
/* Column break needed, continue at top, COLUMN_WIDTH pixels
|
|
|
|
* (one "row") to the right. */
|
|
|
|
x += COLUMN_WIDTH;
|
2008-08-03 19:18:36 +01:00
|
|
|
y = y_org;
|
|
|
|
}
|
|
|
|
|
2008-08-03 15:58:26 +01:00
|
|
|
if (this->map_type == SMT_INDUSTRY) {
|
2008-05-11 20:47:10 +01:00
|
|
|
/* Industry name must be formated, since it's not in tiny font in the specs.
|
|
|
|
* So, draw with a parameter and use the STR_SMALLMAP_INDUSTRY string, which is tiny font.*/
|
|
|
|
SetDParam(0, tbl->legend);
|
|
|
|
assert(tbl->type < NUM_INDUSTRYTYPES);
|
|
|
|
SetDParam(1, _industry_counts[tbl->type]);
|
|
|
|
if (!tbl->show_on_map) {
|
2009-02-09 02:57:15 +00:00
|
|
|
/* Simply draw the string, not the black border of the legend colour.
|
2008-05-11 20:47:10 +01:00
|
|
|
* This will enforce the idea of the disabled item */
|
2009-03-22 14:55:49 +00:00
|
|
|
DrawString(x + 11, x + COLUMN_WIDTH - 1, y, STR_SMALLMAP_INDUSTRY, TC_GREY);
|
2008-05-11 20:47:10 +01:00
|
|
|
} else {
|
2009-03-22 14:55:49 +00:00
|
|
|
DrawString(x + 11, x + COLUMN_WIDTH - 1, y, STR_SMALLMAP_INDUSTRY, TC_BLACK);
|
2009-02-09 02:57:15 +00:00
|
|
|
GfxFillRect(x, y + 1, x + 8, y + 5, 0); // outer border of the legend colour
|
2008-05-11 20:47:10 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Anything that is not an industry is using normal process */
|
|
|
|
GfxFillRect(x, y + 1, x + 8, y + 5, 0);
|
2009-03-22 14:55:49 +00:00
|
|
|
DrawString(x + 11, x + COLUMN_WIDTH - 1, y, tbl->legend, TC_FROMSTRING);
|
2008-05-11 20:47:10 +01:00
|
|
|
}
|
2009-02-09 02:57:15 +00:00
|
|
|
GfxFillRect(x + 1, y + 2, x + 7, y + 4, tbl->colour); // legend colour
|
2006-08-29 01:17:47 +01:00
|
|
|
|
2008-05-11 20:47:10 +01:00
|
|
|
y += 6;
|
|
|
|
}
|
2007-11-19 04:34:40 +00:00
|
|
|
|
2008-08-03 19:00:28 +01:00
|
|
|
const Widget *wi = &this->widget[SM_WIDGET_MAP];
|
|
|
|
if (!FillDrawPixelInfo(&new_dpi, wi->left + 1, wi->top + 1, wi->right - wi->left - 1, wi->bottom - wi->top - 1)) return;
|
2007-11-19 04:34:40 +00:00
|
|
|
|
2008-08-03 15:58:26 +01:00
|
|
|
this->DrawSmallMap(&new_dpi);
|
2008-05-11 20:47:10 +01:00
|
|
|
}
|
2007-04-26 21:20:12 +01:00
|
|
|
|
2008-05-11 20:47:10 +01:00
|
|
|
virtual void OnClick(Point pt, int widget)
|
|
|
|
{
|
|
|
|
switch (widget) {
|
|
|
|
case SM_WIDGET_MAP: { // Map window
|
|
|
|
/*
|
|
|
|
* XXX: scrolling with the left mouse button is done by subsequently
|
|
|
|
* clicking with the left mouse button; clicking once centers the
|
|
|
|
* large map at the selected point. So by unclicking the left mouse
|
|
|
|
* button here, it gets reclicked during the next inputloop, which
|
|
|
|
* would make it look like the mouse is being dragged, while it is
|
|
|
|
* actually being (virtually) clicked every inputloop.
|
|
|
|
*/
|
|
|
|
_left_button_clicked = false;
|
|
|
|
|
|
|
|
Point pt = RemapCoords(this->scroll_x, this->scroll_y, 0);
|
|
|
|
Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
|
2008-09-04 20:09:31 +01:00
|
|
|
w->viewport->follow_vehicle = INVALID_VEHICLE;
|
2008-05-11 20:47:10 +01:00
|
|
|
w->viewport->dest_scrollpos_x = pt.x + ((_cursor.pos.x - this->left + 2) << 4) - (w->viewport->virtual_width >> 1);
|
|
|
|
w->viewport->dest_scrollpos_y = pt.y + ((_cursor.pos.y - this->top - 16) << 4) - (w->viewport->virtual_height >> 1);
|
|
|
|
|
|
|
|
this->SetDirty();
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case SM_WIDGET_CONTOUR: // Show land contours
|
|
|
|
case SM_WIDGET_VEHICLES: // Show vehicles
|
|
|
|
case SM_WIDGET_INDUSTRIES: // Show industries
|
|
|
|
case SM_WIDGET_ROUTES: // Show transport routes
|
|
|
|
case SM_WIDGET_VEGETATION: // Show vegetation
|
|
|
|
case SM_WIDGET_OWNERS: // Show land owners
|
2008-08-03 15:58:26 +01:00
|
|
|
this->RaiseWidget(this->map_type + SM_WIDGET_CONTOUR);
|
|
|
|
this->map_type = (SmallMapType)(widget - SM_WIDGET_CONTOUR);
|
|
|
|
this->LowerWidget(this->map_type + SM_WIDGET_CONTOUR);
|
2008-05-11 20:47:10 +01:00
|
|
|
|
2008-08-04 06:59:28 +01:00
|
|
|
this->ResizeLegend();
|
|
|
|
|
2008-05-11 20:47:10 +01:00
|
|
|
this->SetDirty();
|
|
|
|
SndPlayFx(SND_15_BEEP);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SM_WIDGET_CENTERMAP: // Center the smallmap again
|
|
|
|
this->SmallMapCenterOnCurrentPos();
|
|
|
|
|
|
|
|
this->SetDirty();
|
|
|
|
SndPlayFx(SND_15_BEEP);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SM_WIDGET_TOGGLETOWNNAME: // Toggle town names
|
2008-08-03 15:58:26 +01:00
|
|
|
this->show_towns = !this->show_towns;
|
|
|
|
this->SetWidgetLoweredState(SM_WIDGET_TOGGLETOWNNAME, this->show_towns);
|
2008-05-11 20:47:10 +01:00
|
|
|
|
|
|
|
this->SetDirty();
|
|
|
|
SndPlayFx(SND_15_BEEP);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SM_WIDGET_LEGEND: // Legend
|
|
|
|
/* if industry type small map*/
|
2008-08-03 15:58:26 +01:00
|
|
|
if (this->map_type == SMT_INDUSTRY) {
|
2008-05-11 20:47:10 +01:00
|
|
|
/* if click on industries label, find right industry type and enable/disable it */
|
|
|
|
Widget *wi = &this->widget[SM_WIDGET_LEGEND]; // label panel
|
2008-08-04 06:59:28 +01:00
|
|
|
uint column = (pt.x - 4) / COLUMN_WIDTH;
|
2008-05-11 20:47:10 +01:00
|
|
|
uint line = (pt.y - wi->top - 2) / 6;
|
2008-08-03 21:09:35 +01:00
|
|
|
int rows_per_column = (wi->bottom - wi->top) / 6;
|
|
|
|
|
|
|
|
/* check if click is on industry label*/
|
|
|
|
int industry_pos = (column * rows_per_column) + line;
|
|
|
|
if (industry_pos < _smallmap_industry_count) {
|
|
|
|
_legend_from_industries[industry_pos].show_on_map = !_legend_from_industries[industry_pos].show_on_map;
|
2007-11-19 04:34:40 +00:00
|
|
|
}
|
2008-08-03 21:09:35 +01:00
|
|
|
|
2008-05-11 20:47:10 +01:00
|
|
|
/* Raise the two buttons "all", as we have done a specific choice */
|
|
|
|
this->RaiseWidget(SM_WIDGET_ENABLEINDUSTRIES);
|
|
|
|
this->RaiseWidget(SM_WIDGET_DISABLEINDUSTRIES);
|
|
|
|
this->SetDirty();
|
2007-04-26 21:20:12 +01:00
|
|
|
}
|
2008-05-11 20:47:10 +01:00
|
|
|
break;
|
2006-08-29 01:17:47 +01:00
|
|
|
|
2008-05-11 20:47:10 +01:00
|
|
|
case SM_WIDGET_ENABLEINDUSTRIES: // Enable all industries
|
|
|
|
for (int i = 0; i != _smallmap_industry_count; i++) {
|
|
|
|
_legend_from_industries[i].show_on_map = true;
|
2006-08-29 01:17:47 +01:00
|
|
|
}
|
2008-05-11 20:47:10 +01:00
|
|
|
/* toggle appeareance indicating the choice */
|
|
|
|
this->LowerWidget(SM_WIDGET_ENABLEINDUSTRIES);
|
|
|
|
this->RaiseWidget(SM_WIDGET_DISABLEINDUSTRIES);
|
|
|
|
this->SetDirty();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SM_WIDGET_DISABLEINDUSTRIES: // disable all industries
|
|
|
|
for (int i = 0; i != _smallmap_industry_count; i++) {
|
|
|
|
_legend_from_industries[i].show_on_map = false;
|
|
|
|
}
|
|
|
|
/* toggle appeareance indicating the choice */
|
|
|
|
this->RaiseWidget(SM_WIDGET_ENABLEINDUSTRIES);
|
|
|
|
this->LowerWidget(SM_WIDGET_DISABLEINDUSTRIES);
|
|
|
|
this->SetDirty();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2008-05-11 20:47:10 +01:00
|
|
|
virtual void OnRightClick(Point pt, int widget)
|
|
|
|
{
|
|
|
|
if (widget == SM_WIDGET_MAP) {
|
|
|
|
if (_scrolling_viewport) return;
|
|
|
|
_scrolling_viewport = true;
|
|
|
|
_cursor.delta.x = 0;
|
|
|
|
_cursor.delta.y = 0;
|
|
|
|
}
|
|
|
|
}
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2008-05-11 20:47:10 +01:00
|
|
|
virtual void OnTick()
|
|
|
|
{
|
|
|
|
/* update the window every now and then */
|
2008-05-29 12:47:56 +01:00
|
|
|
if ((++this->refresh & 0x1F) == 0) this->SetDirty();
|
2008-05-11 20:47:10 +01:00
|
|
|
}
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2008-05-11 20:47:10 +01:00
|
|
|
virtual void OnScroll(Point delta)
|
|
|
|
{
|
|
|
|
_cursor.fix_at = true;
|
2007-11-19 04:34:40 +00:00
|
|
|
|
2008-05-11 20:47:10 +01:00
|
|
|
int x = this->scroll_x;
|
|
|
|
int y = this->scroll_y;
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2008-05-11 20:47:10 +01:00
|
|
|
int sub = this->subscroll + delta.x;
|
2006-08-21 18:41:04 +01:00
|
|
|
|
2008-05-11 20:47:10 +01:00
|
|
|
x -= (sub >> 2) << 4;
|
|
|
|
y += (sub >> 2) << 4;
|
|
|
|
sub &= 3;
|
2006-08-21 15:34:59 +01:00
|
|
|
|
2008-05-11 20:47:10 +01:00
|
|
|
x += (delta.y >> 1) << 4;
|
|
|
|
y += (delta.y >> 1) << 4;
|
2006-08-21 15:34:59 +01:00
|
|
|
|
2008-05-11 20:47:10 +01:00
|
|
|
if (delta.y & 1) {
|
|
|
|
x += TILE_SIZE;
|
|
|
|
sub += 2;
|
|
|
|
if (sub > 3) {
|
|
|
|
sub -= 4;
|
|
|
|
x -= TILE_SIZE;
|
|
|
|
y += TILE_SIZE;
|
2006-08-21 15:34:59 +01:00
|
|
|
}
|
2008-05-11 20:47:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int hx = (this->widget[SM_WIDGET_MAP].right - this->widget[SM_WIDGET_MAP].left) / 2;
|
|
|
|
int hy = (this->widget[SM_WIDGET_MAP].bottom - this->widget[SM_WIDGET_MAP].top ) / 2;
|
|
|
|
int hvx = hx * -4 + hy * 8;
|
|
|
|
int hvy = hx * 4 + hy * 8;
|
|
|
|
if (x < -hvx) {
|
|
|
|
x = -hvx;
|
|
|
|
sub = 0;
|
|
|
|
}
|
|
|
|
if (x > (int)MapMaxX() * TILE_SIZE - hvx) {
|
|
|
|
x = MapMaxX() * TILE_SIZE - hvx;
|
|
|
|
sub = 0;
|
|
|
|
}
|
|
|
|
if (y < -hvy) {
|
|
|
|
y = -hvy;
|
|
|
|
sub = 0;
|
|
|
|
}
|
|
|
|
if (y > (int)MapMaxY() * TILE_SIZE - hvy) {
|
|
|
|
y = MapMaxY() * TILE_SIZE - hvy;
|
|
|
|
sub = 0;
|
|
|
|
}
|
2006-08-21 15:34:59 +01:00
|
|
|
|
2008-05-11 20:47:10 +01:00
|
|
|
this->scroll_x = x;
|
|
|
|
this->scroll_y = y;
|
|
|
|
this->subscroll = sub;
|
2006-08-21 15:34:59 +01:00
|
|
|
|
2008-05-11 20:47:10 +01:00
|
|
|
this->SetDirty();
|
2004-08-09 18:04:08 +01:00
|
|
|
}
|
2008-08-04 06:59:28 +01:00
|
|
|
|
2009-03-29 10:49:11 +01:00
|
|
|
virtual void OnResize(Point delta)
|
2008-08-04 06:59:28 +01:00
|
|
|
{
|
|
|
|
if (delta.x != 0 && this->map_type == SMT_INDUSTRY) this->ResizeLegend();
|
|
|
|
}
|
2008-05-11 20:47:10 +01:00
|
|
|
};
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2008-08-03 15:58:26 +01:00
|
|
|
SmallMapWindow::SmallMapType SmallMapWindow::map_type = SMT_CONTOUR;
|
|
|
|
bool SmallMapWindow::show_towns = true;
|
|
|
|
|
2009-03-15 15:12:06 +00:00
|
|
|
static const WindowDesc _smallmap_desc(
|
2007-07-27 23:10:21 +01:00
|
|
|
WDP_AUTO, WDP_AUTO, 350, 214, 446, 314,
|
2007-02-01 15:49:12 +00:00
|
|
|
WC_SMALLMAP, WC_NONE,
|
2005-01-03 19:45:18 +00:00
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON | WDF_RESIZABLE,
|
2009-03-15 15:12:06 +00:00
|
|
|
_smallmap_widgets
|
|
|
|
);
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void ShowSmallMap()
|
2004-08-09 18:04:08 +01:00
|
|
|
{
|
2008-05-11 20:47:10 +01:00
|
|
|
AllocateWindowDescFront<SmallMapWindow>(&_smallmap_desc, 0);
|
2004-08-09 18:04:08 +01:00
|
|
|
}
|
|
|
|
|
2004-09-03 20:59:05 +01:00
|
|
|
/* Extra ViewPort Window Stuff */
|
2005-01-03 19:45:18 +00:00
|
|
|
static const Widget _extra_view_port_widgets[] = {
|
2008-07-31 18:45:52 +01:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, COLOUR_GREY, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
|
|
{ WWT_CAPTION, RESIZE_RIGHT, COLOUR_GREY, 11, 287, 0, 13, STR_EXTRA_VIEW_PORT_TITLE, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
|
|
{ WWT_STICKYBOX, RESIZE_LR, COLOUR_GREY, 288, 299, 0, 13, 0x0, STR_STICKY_BUTTON},
|
|
|
|
{ WWT_PANEL, RESIZE_RB, COLOUR_GREY, 0, 299, 14, 33, 0x0, STR_NULL},
|
|
|
|
{ WWT_INSET, RESIZE_RB, COLOUR_GREY, 2, 297, 16, 31, 0x0, STR_NULL},
|
|
|
|
{ WWT_PUSHIMGBTN, RESIZE_TB, COLOUR_GREY, 0, 21, 34, 55, SPR_IMG_ZOOMIN, STR_017F_ZOOM_THE_VIEW_IN},
|
|
|
|
{ WWT_PUSHIMGBTN, RESIZE_TB, COLOUR_GREY, 22, 43, 34, 55, SPR_IMG_ZOOMOUT, STR_0180_ZOOM_THE_VIEW_OUT},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_TB, COLOUR_GREY, 44, 171, 34, 55, STR_EXTRA_VIEW_MOVE_MAIN_TO_VIEW, STR_EXTRA_VIEW_MOVE_MAIN_TO_VIEW_TT},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_TB, COLOUR_GREY, 172, 298, 34, 55, STR_EXTRA_VIEW_MOVE_VIEW_TO_MAIN, STR_EXTRA_VIEW_MOVE_VIEW_TO_MAIN_TT},
|
|
|
|
{ WWT_PANEL, RESIZE_RTB, COLOUR_GREY, 299, 299, 34, 55, 0x0, STR_NULL},
|
|
|
|
{ WWT_PANEL, RESIZE_RTB, COLOUR_GREY, 0, 287, 56, 67, 0x0, STR_NULL},
|
|
|
|
{ WWT_RESIZEBOX, RESIZE_LRTB, COLOUR_GREY, 288, 299, 56, 67, 0x0, STR_RESIZE_BUTTON},
|
2004-09-07 22:48:09 +01:00
|
|
|
{ WIDGETS_END},
|
2004-09-03 20:59:05 +01:00
|
|
|
};
|
|
|
|
|
2008-05-12 01:26:44 +01:00
|
|
|
class ExtraViewportWindow : public Window
|
2004-09-03 20:59:05 +01:00
|
|
|
{
|
2008-05-12 01:26:44 +01:00
|
|
|
enum ExtraViewportWindowWidgets {
|
|
|
|
EVW_CLOSE,
|
|
|
|
EVW_CAPTION,
|
|
|
|
EVW_STICKY,
|
|
|
|
EVW_BACKGROUND,
|
|
|
|
EVW_VIEWPORT,
|
|
|
|
EVW_ZOOMIN,
|
|
|
|
EVW_ZOOMOUT,
|
|
|
|
EVW_MAIN_TO_VIEW,
|
|
|
|
EVW_VIEW_TO_MAIN,
|
|
|
|
EVW_SPACER1,
|
|
|
|
EVW_SPACER2,
|
|
|
|
EVW_RESIZE,
|
|
|
|
};
|
|
|
|
|
|
|
|
public:
|
2008-05-13 15:43:33 +01:00
|
|
|
ExtraViewportWindow(const WindowDesc *desc, int window_number, TileIndex tile) : Window(desc, window_number)
|
2008-05-12 01:26:44 +01:00
|
|
|
{
|
2007-07-30 00:25:17 +01:00
|
|
|
/* New viewport start at (zero,zero) */
|
2008-05-12 01:26:44 +01:00
|
|
|
InitializeWindowViewport(this, 3, 17, this->widget[EVW_VIEWPORT].right - this->widget[EVW_VIEWPORT].left - 1, this->widget[EVW_VIEWPORT].bottom - this->widget[EVW_VIEWPORT].top - 1, 0, ZOOM_LVL_VIEWPORT);
|
|
|
|
|
|
|
|
this->DisableWidget(EVW_ZOOMIN);
|
|
|
|
this->FindWindowPlacementAndResize(desc);
|
|
|
|
|
|
|
|
Point pt;
|
|
|
|
if (tile == INVALID_TILE) {
|
|
|
|
/* the main window with the main view */
|
|
|
|
const Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
|
|
|
|
|
|
|
|
/* center on same place as main window (zoom is maximum, no adjustment needed) */
|
|
|
|
pt.x = w->viewport->scrollpos_x + w->viewport->virtual_height / 2;
|
|
|
|
pt.y = w->viewport->scrollpos_y + w->viewport->virtual_height / 2;
|
|
|
|
} else {
|
|
|
|
pt = RemapCoords(TileX(tile) * TILE_SIZE + TILE_SIZE / 2, TileY(tile) * TILE_SIZE + TILE_SIZE / 2, TileHeight(tile));
|
|
|
|
}
|
2007-07-30 00:25:17 +01:00
|
|
|
|
2008-05-12 01:26:44 +01:00
|
|
|
this->viewport->scrollpos_x = pt.x - ((this->widget[EVW_VIEWPORT].right - this->widget[EVW_VIEWPORT].left) - 1) / 2;
|
|
|
|
this->viewport->scrollpos_y = pt.y - ((this->widget[EVW_VIEWPORT].bottom - this->widget[EVW_VIEWPORT].top) - 1) / 2;
|
|
|
|
this->viewport->dest_scrollpos_x = this->viewport->scrollpos_x;
|
|
|
|
this->viewport->dest_scrollpos_y = this->viewport->scrollpos_y;
|
2006-06-10 09:37:41 +01:00
|
|
|
|
2008-05-12 01:26:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void OnPaint()
|
|
|
|
{
|
2008-04-19 14:05:05 +01:00
|
|
|
/* set the number in the title bar */
|
2008-05-12 01:26:44 +01:00
|
|
|
SetDParam(0, this->window_number + 1);
|
|
|
|
|
2008-05-17 13:48:06 +01:00
|
|
|
this->DrawWidgets();
|
|
|
|
this->DrawViewport();
|
2008-05-12 01:26:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void OnClick(Point pt, int widget)
|
|
|
|
{
|
|
|
|
switch (widget) {
|
|
|
|
case EVW_ZOOMIN: DoZoomInOutWindow(ZOOM_IN, this); break;
|
|
|
|
case EVW_ZOOMOUT: DoZoomInOutWindow(ZOOM_OUT, this); break;
|
|
|
|
|
|
|
|
case EVW_MAIN_TO_VIEW: { // location button (move main view to same spot as this view) 'Paste Location'
|
|
|
|
Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
|
|
|
|
int x = this->viewport->scrollpos_x; // Where is the main looking at
|
|
|
|
int y = this->viewport->scrollpos_y;
|
|
|
|
|
|
|
|
/* set this view to same location. Based on the center, adjusting for zoom */
|
|
|
|
w->viewport->dest_scrollpos_x = x - (w->viewport->virtual_width - this->viewport->virtual_width) / 2;
|
|
|
|
w->viewport->dest_scrollpos_y = y - (w->viewport->virtual_height - this->viewport->virtual_height) / 2;
|
2009-01-09 23:28:28 +00:00
|
|
|
w->viewport->follow_vehicle = INVALID_VEHICLE;
|
2008-05-12 01:26:44 +01:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case EVW_VIEW_TO_MAIN: { // inverse location button (move this view to same spot as main view) 'Copy Location'
|
|
|
|
const Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
|
|
|
|
int x = w->viewport->scrollpos_x;
|
|
|
|
int y = w->viewport->scrollpos_y;
|
|
|
|
|
|
|
|
this->viewport->dest_scrollpos_x = x + (w->viewport->virtual_width - this->viewport->virtual_width) / 2;
|
|
|
|
this->viewport->dest_scrollpos_y = y + (w->viewport->virtual_height - this->viewport->virtual_height) / 2;
|
|
|
|
} break;
|
2004-09-10 20:02:27 +01:00
|
|
|
}
|
2008-05-12 01:26:44 +01:00
|
|
|
}
|
2005-05-15 12:20:38 +01:00
|
|
|
|
2009-03-29 10:49:11 +01:00
|
|
|
virtual void OnResize(Point delta)
|
2008-05-12 01:26:44 +01:00
|
|
|
{
|
|
|
|
this->viewport->width += delta.x;
|
|
|
|
this->viewport->height += delta.y;
|
|
|
|
this->viewport->virtual_width += delta.x;
|
|
|
|
this->viewport->virtual_height += delta.y;
|
|
|
|
}
|
2006-08-21 15:34:59 +01:00
|
|
|
|
2008-05-12 01:26:44 +01:00
|
|
|
virtual void OnScroll(Point delta)
|
|
|
|
{
|
2009-03-02 18:01:33 +00:00
|
|
|
const ViewPort *vp = IsPtInWindowViewport(this, _cursor.pos.x, _cursor.pos.y);
|
|
|
|
if (vp == NULL) return;
|
2006-08-21 15:34:59 +01:00
|
|
|
|
2008-05-12 01:26:44 +01:00
|
|
|
this->viewport->scrollpos_x += ScaleByZoom(delta.x, vp->zoom);
|
|
|
|
this->viewport->scrollpos_y += ScaleByZoom(delta.y, vp->zoom);
|
|
|
|
this->viewport->dest_scrollpos_x = this->viewport->scrollpos_x;
|
|
|
|
this->viewport->dest_scrollpos_y = this->viewport->scrollpos_y;
|
|
|
|
}
|
2006-08-21 15:59:58 +01:00
|
|
|
|
2008-05-12 01:26:44 +01:00
|
|
|
virtual void OnMouseWheel(int wheel)
|
|
|
|
{
|
|
|
|
ZoomInOrOutToCursorWindow(wheel < 0, this);
|
|
|
|
}
|
2006-11-07 13:06:02 +00:00
|
|
|
|
2008-05-12 01:26:44 +01:00
|
|
|
virtual void OnInvalidateData(int data = 0)
|
|
|
|
{
|
|
|
|
/* Only handle zoom message if intended for us (msg ZOOM_IN/ZOOM_OUT) */
|
|
|
|
HandleZoomMessage(this, this->viewport, EVW_ZOOMIN, EVW_ZOOMOUT);
|
2004-09-03 20:59:05 +01:00
|
|
|
}
|
2008-05-12 01:26:44 +01:00
|
|
|
};
|
2004-09-03 20:59:05 +01:00
|
|
|
|
2009-03-15 15:12:06 +00:00
|
|
|
static const WindowDesc _extra_view_port_desc(
|
2007-07-30 00:25:17 +01:00
|
|
|
WDP_AUTO, WDP_AUTO, 300, 68, 300, 268,
|
2007-02-01 15:49:12 +00:00
|
|
|
WC_EXTRA_VIEW_PORT, WC_NONE,
|
2005-01-03 19:45:18 +00:00
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
|
2009-03-15 15:12:06 +00:00
|
|
|
_extra_view_port_widgets
|
|
|
|
);
|
2004-09-03 20:59:05 +01:00
|
|
|
|
2008-05-05 12:36:43 +01:00
|
|
|
void ShowExtraViewPortWindow(TileIndex tile)
|
2004-09-03 20:59:05 +01:00
|
|
|
{
|
|
|
|
int i = 0;
|
2004-09-10 20:02:27 +01:00
|
|
|
|
2007-04-04 02:35:16 +01:00
|
|
|
/* find next free window number for extra viewport */
|
2006-02-06 09:18:04 +00:00
|
|
|
while (FindWindowById(WC_EXTRA_VIEW_PORT, i) != NULL) i++;
|
2004-09-03 20:59:05 +01:00
|
|
|
|
2008-05-13 15:43:33 +01:00
|
|
|
new ExtraViewportWindow(&_extra_view_port_desc, i, tile);
|
2004-09-03 20:59:05 +01:00
|
|
|
}
|
2008-05-11 20:47:10 +01:00
|
|
|
|
2009-03-15 15:25:18 +00:00
|
|
|
/**
|
|
|
|
* Scrolls the main window to given coordinates.
|
|
|
|
* @param x x coordinate
|
|
|
|
* @param y y coordinate
|
|
|
|
* @param z z coordinate; -1 to scroll to terrain height
|
|
|
|
* @param instant scroll instantly (meaningful only when smooth_scrolling is active)
|
|
|
|
* @return did the viewport position change?
|
|
|
|
*/
|
|
|
|
bool ScrollMainWindowTo(int x, int y, int z, bool instant)
|
2008-05-11 20:47:10 +01:00
|
|
|
{
|
2009-03-15 15:25:18 +00:00
|
|
|
bool res = ScrollWindowTo(x, y, z, FindWindowById(WC_MAIN_WINDOW, 0), instant);
|
2008-05-11 20:47:10 +01:00
|
|
|
|
|
|
|
/* If a user scrolls to a tile (via what way what so ever) and already is on
|
|
|
|
* that tile (e.g.: pressed twice), move the smallmap to that location,
|
|
|
|
* so you directly see where you are on the smallmap. */
|
|
|
|
|
|
|
|
if (res) return res;
|
|
|
|
|
|
|
|
SmallMapWindow *w = dynamic_cast<SmallMapWindow*>(FindWindowById(WC_SMALLMAP, 0));
|
|
|
|
if (w != NULL) w->SmallMapCenterOnCurrentPos();
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|