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