00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #include "stdafx.h"
00013 #include "clear_map.h"
00014 #include "industry.h"
00015 #include "station_map.h"
00016 #include "landscape.h"
00017 #include "tree_map.h"
00018 #include "viewport_func.h"
00019 #include "town.h"
00020 #include "tunnelbridge_map.h"
00021 #include "core/endian_func.hpp"
00022 #include "vehicle_base.h"
00023 #include "sound_func.h"
00024 #include "window_func.h"
00025 #include "company_base.h"
00026
00027 #include "smallmap_gui.h"
00028
00029 #include "table/strings.h"
00030
00031 static int _smallmap_industry_count;
00032 static int _smallmap_company_count;
00033 static int _smallmap_cargo_count;
00034
00036 static uint8 _linkstat_colours_in_legenda[] = {0, 1, 3, 5, 7, 9, 11};
00037
00038 static const int NUM_NO_COMPANY_ENTRIES = 4;
00039
00040 static const uint8 PC_ROUGH_LAND = 0x52;
00041 static const uint8 PC_GRASS_LAND = 0x54;
00042 static const uint8 PC_BARE_LAND = 0x37;
00043 static const uint8 PC_FIELDS = 0x25;
00044 static const uint8 PC_TREES = 0x57;
00045 static const uint8 PC_WATER = 0xCA;
00046
00048 #define MK(a, b) {a, b, INVALID_INDUSTRYTYPE, 0, INVALID_COMPANY, true, false, false}
00049
00051 #define MC(height) {0, STR_TINY_BLACK_HEIGHT, INVALID_INDUSTRYTYPE, height, INVALID_COMPANY, true, false, false}
00052
00054 #define MO(a, b) {a, b, INVALID_INDUSTRYTYPE, 0, INVALID_COMPANY, true, false, false}
00055
00057 #define MOEND() {0, 0, INVALID_INDUSTRYTYPE, 0, OWNER_NONE, true, true, false}
00058
00060 #define MKEND() {0, STR_NULL, INVALID_INDUSTRYTYPE, 0, INVALID_COMPANY, true, true, false}
00061
00066 #define MS(a, b) {a, b, INVALID_INDUSTRYTYPE, 0, INVALID_COMPANY, true, false, true}
00067
00069 static LegendAndColour _legend_land_contours[] = {
00070
00071 MC(0),
00072 MC(4),
00073 MC(8),
00074 MC(12),
00075 MC(14),
00076
00077 MS(PC_BLACK, STR_SMALLMAP_LEGENDA_ROADS),
00078 MK(PC_GREY, STR_SMALLMAP_LEGENDA_RAILROADS),
00079 MK(PC_LIGHT_BLUE, STR_SMALLMAP_LEGENDA_STATIONS_AIRPORTS_DOCKS),
00080 MK(PC_DARK_RED, STR_SMALLMAP_LEGENDA_BUILDINGS_INDUSTRIES),
00081 MK(PC_WHITE, STR_SMALLMAP_LEGENDA_VEHICLES),
00082 MKEND()
00083 };
00084
00085 static const LegendAndColour _legend_vehicles[] = {
00086 MK(PC_RED, STR_SMALLMAP_LEGENDA_TRAINS),
00087 MK(PC_YELLOW, STR_SMALLMAP_LEGENDA_ROAD_VEHICLES),
00088 MK(PC_LIGHT_BLUE, STR_SMALLMAP_LEGENDA_SHIPS),
00089 MK(PC_WHITE, STR_SMALLMAP_LEGENDA_AIRCRAFT),
00090
00091 MS(PC_BLACK, STR_SMALLMAP_LEGENDA_TRANSPORT_ROUTES),
00092 MK(PC_DARK_RED, STR_SMALLMAP_LEGENDA_BUILDINGS_INDUSTRIES),
00093 MKEND()
00094 };
00095
00096 static const LegendAndColour _legend_routes[] = {
00097 MK(PC_BLACK, STR_SMALLMAP_LEGENDA_ROADS),
00098 MK(PC_GREY, STR_SMALLMAP_LEGENDA_RAILROADS),
00099 MK(PC_DARK_RED, STR_SMALLMAP_LEGENDA_BUILDINGS_INDUSTRIES),
00100
00101 MS(PC_VERY_DARK_BROWN, STR_SMALLMAP_LEGENDA_RAILROAD_STATION),
00102 MK(PC_ORANGE, STR_SMALLMAP_LEGENDA_TRUCK_LOADING_BAY),
00103 MK(PC_YELLOW, STR_SMALLMAP_LEGENDA_BUS_STATION),
00104 MK(PC_RED, STR_SMALLMAP_LEGENDA_AIRPORT_HELIPORT),
00105 MK(PC_LIGHT_BLUE, STR_SMALLMAP_LEGENDA_DOCK),
00106 MKEND()
00107 };
00108
00109 static const LegendAndColour _legend_vegetation[] = {
00110 MK(PC_ROUGH_LAND, STR_SMALLMAP_LEGENDA_ROUGH_LAND),
00111 MK(PC_GRASS_LAND, STR_SMALLMAP_LEGENDA_GRASS_LAND),
00112 MK(PC_BARE_LAND, STR_SMALLMAP_LEGENDA_BARE_LAND),
00113 MK(PC_FIELDS, STR_SMALLMAP_LEGENDA_FIELDS),
00114 MK(PC_TREES, STR_SMALLMAP_LEGENDA_TREES),
00115 MK(PC_GREEN, STR_SMALLMAP_LEGENDA_FOREST),
00116
00117 MS(PC_GREY, STR_SMALLMAP_LEGENDA_ROCKS),
00118 MK(PC_ORANGE, STR_SMALLMAP_LEGENDA_DESERT),
00119 MK(PC_LIGHT_BLUE, STR_SMALLMAP_LEGENDA_SNOW),
00120 MK(PC_BLACK, STR_SMALLMAP_LEGENDA_TRANSPORT_ROUTES),
00121 MK(PC_DARK_RED, STR_SMALLMAP_LEGENDA_BUILDINGS_INDUSTRIES),
00122 MKEND()
00123 };
00124
00125 static LegendAndColour _legend_land_owners[NUM_NO_COMPANY_ENTRIES + MAX_COMPANIES + 1] = {
00126 MO(PC_WATER, STR_SMALLMAP_LEGENDA_WATER),
00127 MO(0x00, STR_SMALLMAP_LEGENDA_NO_OWNER),
00128 MO(PC_DARK_RED, STR_SMALLMAP_LEGENDA_TOWNS),
00129 MO(PC_DARK_GREY, STR_SMALLMAP_LEGENDA_INDUSTRIES),
00130
00131 MOEND(),
00132 };
00133
00134 #undef MK
00135 #undef MC
00136 #undef MS
00137 #undef MO
00138 #undef MOEND
00139 #undef MKEND
00140
00142 static LegendAndColour _legend_linkstats[NUM_CARGO + lengthof(_linkstat_colours_in_legenda) + 1];
00147 static LegendAndColour _legend_from_industries[NUM_INDUSTRYTYPES + 1];
00149 static uint _industry_to_list_pos[NUM_INDUSTRYTYPES];
00151 static bool _smallmap_show_heightmap = false;
00153 static IndustryType _smallmap_industry_highlight = INVALID_INDUSTRYTYPE;
00155 static bool _smallmap_industry_highlight_state;
00157 static uint _company_to_list_pos[MAX_COMPANIES];
00158
00162 void BuildIndustriesLegend()
00163 {
00164 uint j = 0;
00165
00166
00167 for (uint8 i = 0; i < NUM_INDUSTRYTYPES; i++) {
00168 IndustryType ind = _sorted_industry_types[i];
00169 const IndustrySpec *indsp = GetIndustrySpec(ind);
00170 if (indsp->enabled) {
00171 _legend_from_industries[j].legend = indsp->name;
00172 _legend_from_industries[j].colour = indsp->map_colour;
00173 _legend_from_industries[j].type = ind;
00174 _legend_from_industries[j].show_on_map = true;
00175 _legend_from_industries[j].col_break = false;
00176 _legend_from_industries[j].end = false;
00177
00178
00179 _industry_to_list_pos[ind] = j;
00180 j++;
00181 }
00182 }
00183
00184 _legend_from_industries[j].end = true;
00185
00186
00187 _smallmap_industry_count = j;
00188 }
00189
00193 void BuildLinkStatsLegend()
00194 {
00195
00196 memset(_legend_linkstats, 0, sizeof(_legend_linkstats));
00197
00198 uint i = 0;
00199 for (; i < _sorted_cargo_specs_size; ++i) {
00200 const CargoSpec *cs = _sorted_cargo_specs[i];
00201
00202 _legend_linkstats[i].legend = cs->name;
00203 _legend_linkstats[i].colour = cs->legend_colour;
00204 _legend_linkstats[i].type = cs->Index();
00205 _legend_linkstats[i].show_on_map = true;
00206 }
00207
00208 _legend_linkstats[i].col_break = true;
00209 _smallmap_cargo_count = i;
00210
00211 for (; i < _smallmap_cargo_count + lengthof(_linkstat_colours_in_legenda); ++i) {
00212 _legend_linkstats[i].legend = STR_EMPTY;
00213 _legend_linkstats[i].colour = LinkGraphOverlay::LINK_COLOURS[_linkstat_colours_in_legenda[i - _smallmap_cargo_count]];
00214 _legend_linkstats[i].show_on_map = true;
00215 }
00216
00217 _legend_linkstats[_smallmap_cargo_count].legend = STR_LINKGRAPH_LEGEND_UNUSED;
00218 _legend_linkstats[i - 1].legend = STR_LINKGRAPH_LEGEND_OVERLOADED;
00219 _legend_linkstats[(_smallmap_cargo_count + i - 1) / 2].legend = STR_LINKGRAPH_LEGEND_SATURATED;
00220 _legend_linkstats[i].end = true;
00221 }
00222
00223 static const LegendAndColour * const _legend_table[] = {
00224 _legend_land_contours,
00225 _legend_vehicles,
00226 _legend_from_industries,
00227 _legend_linkstats,
00228 _legend_routes,
00229 _legend_vegetation,
00230 _legend_land_owners,
00231 };
00232
00233 #define MKCOLOUR(x) TO_LE32X(x)
00234
00235 #define MKCOLOUR_XXXX(x) (MKCOLOUR(0x01010101) * (uint)(x))
00236 #define MKCOLOUR_X0X0(x) (MKCOLOUR(0x01000100) * (uint)(x))
00237 #define MKCOLOUR_0X0X(x) (MKCOLOUR(0x00010001) * (uint)(x))
00238 #define MKCOLOUR_0XX0(x) (MKCOLOUR(0x00010100) * (uint)(x))
00239 #define MKCOLOUR_X00X(x) (MKCOLOUR(0x01000001) * (uint)(x))
00240
00241 #define MKCOLOUR_XYXY(x, y) (MKCOLOUR_X0X0(x) | MKCOLOUR_0X0X(y))
00242 #define MKCOLOUR_XYYX(x, y) (MKCOLOUR_X00X(x) | MKCOLOUR_0XX0(y))
00243
00244 #define MKCOLOUR_0000 MKCOLOUR_XXXX(0x00)
00245 #define MKCOLOUR_0FF0 MKCOLOUR_0XX0(0xFF)
00246 #define MKCOLOUR_F00F MKCOLOUR_X00X(0xFF)
00247 #define MKCOLOUR_FFFF MKCOLOUR_XXXX(0xFF)
00248
00250 static const uint32 _green_map_heights[] = {
00251 MKCOLOUR_XXXX(0x5A),
00252 MKCOLOUR_XYXY(0x5A, 0x5B),
00253 MKCOLOUR_XXXX(0x5B),
00254 MKCOLOUR_XYXY(0x5B, 0x5C),
00255 MKCOLOUR_XXXX(0x5C),
00256 MKCOLOUR_XYXY(0x5C, 0x5D),
00257 MKCOLOUR_XXXX(0x5D),
00258 MKCOLOUR_XYXY(0x5D, 0x5E),
00259 MKCOLOUR_XXXX(0x5E),
00260 MKCOLOUR_XYXY(0x5E, 0x5F),
00261 MKCOLOUR_XXXX(0x5F),
00262 MKCOLOUR_XYXY(0x5F, 0x1F),
00263 MKCOLOUR_XXXX(0x1F),
00264 MKCOLOUR_XYXY(0x1F, 0x27),
00265 MKCOLOUR_XXXX(0x27),
00266 MKCOLOUR_XXXX(0x27),
00267 };
00268 assert_compile(lengthof(_green_map_heights) == MAX_TILE_HEIGHT + 1);
00269
00271 static const uint32 _dark_green_map_heights[] = {
00272 MKCOLOUR_XXXX(0x60),
00273 MKCOLOUR_XYXY(0x60, 0x61),
00274 MKCOLOUR_XXXX(0x61),
00275 MKCOLOUR_XYXY(0x61, 0x62),
00276 MKCOLOUR_XXXX(0x62),
00277 MKCOLOUR_XYXY(0x62, 0x63),
00278 MKCOLOUR_XXXX(0x63),
00279 MKCOLOUR_XYXY(0x63, 0x64),
00280 MKCOLOUR_XXXX(0x64),
00281 MKCOLOUR_XYXY(0x64, 0x65),
00282 MKCOLOUR_XXXX(0x65),
00283 MKCOLOUR_XYXY(0x65, 0x66),
00284 MKCOLOUR_XXXX(0x66),
00285 MKCOLOUR_XYXY(0x66, 0x67),
00286 MKCOLOUR_XXXX(0x67),
00287 MKCOLOUR_XXXX(0x67),
00288 };
00289 assert_compile(lengthof(_dark_green_map_heights) == MAX_TILE_HEIGHT + 1);
00290
00292 static const uint32 _violet_map_heights[] = {
00293 MKCOLOUR_XXXX(0x80),
00294 MKCOLOUR_XYXY(0x80, 0x81),
00295 MKCOLOUR_XXXX(0x81),
00296 MKCOLOUR_XYXY(0x81, 0x82),
00297 MKCOLOUR_XXXX(0x82),
00298 MKCOLOUR_XYXY(0x82, 0x83),
00299 MKCOLOUR_XXXX(0x83),
00300 MKCOLOUR_XYXY(0x83, 0x84),
00301 MKCOLOUR_XXXX(0x84),
00302 MKCOLOUR_XYXY(0x84, 0x85),
00303 MKCOLOUR_XXXX(0x85),
00304 MKCOLOUR_XYXY(0x85, 0x86),
00305 MKCOLOUR_XXXX(0x86),
00306 MKCOLOUR_XYXY(0x86, 0x87),
00307 MKCOLOUR_XXXX(0x87),
00308 MKCOLOUR_XXXX(0x87),
00309 };
00310 assert_compile(lengthof(_violet_map_heights) == MAX_TILE_HEIGHT + 1);
00311
00313 struct SmallMapColourScheme {
00314 const uint32 *height_colours;
00315 uint32 default_colour;
00316 };
00317
00319 static const SmallMapColourScheme _heightmap_schemes[] = {
00320 {_green_map_heights, MKCOLOUR_XXXX(0x54)},
00321 {_dark_green_map_heights, MKCOLOUR_XXXX(0x62)},
00322 {_violet_map_heights, MKCOLOUR_XXXX(0x82)},
00323 };
00324
00328 void BuildLandLegend()
00329 {
00330 for (LegendAndColour *lc = _legend_land_contours; lc->legend == STR_TINY_BLACK_HEIGHT; lc++) {
00331 lc->colour = _heightmap_schemes[_settings_client.gui.smallmap_land_colour].height_colours[lc->height];
00332 }
00333 }
00334
00338 void BuildOwnerLegend()
00339 {
00340 _legend_land_owners[1].colour = _heightmap_schemes[_settings_client.gui.smallmap_land_colour].default_colour;
00341
00342 int i = NUM_NO_COMPANY_ENTRIES;
00343 const Company *c;
00344 FOR_ALL_COMPANIES(c) {
00345 _legend_land_owners[i].colour = _colour_gradient[c->colour][5];
00346 _legend_land_owners[i].company = c->index;
00347 _legend_land_owners[i].show_on_map = true;
00348 _legend_land_owners[i].col_break = false;
00349 _legend_land_owners[i].end = false;
00350 _company_to_list_pos[c->index] = i;
00351 i++;
00352 }
00353
00354
00355 _legend_land_owners[i].end = true;
00356
00357
00358 _smallmap_company_count = i;
00359 }
00360
00361 struct AndOr {
00362 uint32 mor;
00363 uint32 mand;
00364 };
00365
00366 static inline uint32 ApplyMask(uint32 colour, const AndOr *mask)
00367 {
00368 return (colour & mask->mand) | mask->mor;
00369 }
00370
00371
00373 static const AndOr _smallmap_contours_andor[] = {
00374 {MKCOLOUR_0000 , MKCOLOUR_FFFF},
00375 {MKCOLOUR_0XX0(PC_GREY ), MKCOLOUR_F00F},
00376 {MKCOLOUR_0XX0(PC_BLACK ), MKCOLOUR_F00F},
00377 {MKCOLOUR_0XX0(PC_DARK_RED ), MKCOLOUR_F00F},
00378 {MKCOLOUR_0000 , MKCOLOUR_FFFF},
00379 {MKCOLOUR_XXXX(PC_LIGHT_BLUE), MKCOLOUR_0000},
00380 {MKCOLOUR_XXXX(PC_WATER ), MKCOLOUR_0000},
00381 {MKCOLOUR_0000 , MKCOLOUR_FFFF},
00382 {MKCOLOUR_XXXX(PC_DARK_RED ), MKCOLOUR_0000},
00383 {MKCOLOUR_0000 , MKCOLOUR_FFFF},
00384 {MKCOLOUR_0XX0(PC_DARK_RED ), MKCOLOUR_F00F},
00385 {MKCOLOUR_0XX0(PC_GREY ), MKCOLOUR_F00F},
00386 };
00387
00389 static const AndOr _smallmap_vehicles_andor[] = {
00390 {MKCOLOUR_0000 , MKCOLOUR_FFFF},
00391 {MKCOLOUR_0XX0(PC_BLACK ), MKCOLOUR_F00F},
00392 {MKCOLOUR_0XX0(PC_BLACK ), MKCOLOUR_F00F},
00393 {MKCOLOUR_0XX0(PC_DARK_RED ), MKCOLOUR_F00F},
00394 {MKCOLOUR_0000 , MKCOLOUR_FFFF},
00395 {MKCOLOUR_0XX0(PC_BLACK ), MKCOLOUR_F00F},
00396 {MKCOLOUR_XXXX(PC_WATER ), MKCOLOUR_0000},
00397 {MKCOLOUR_0000 , MKCOLOUR_FFFF},
00398 {MKCOLOUR_XXXX(PC_DARK_RED ), MKCOLOUR_0000},
00399 {MKCOLOUR_0000 , MKCOLOUR_FFFF},
00400 {MKCOLOUR_0XX0(PC_DARK_RED ), MKCOLOUR_F00F},
00401 {MKCOLOUR_0XX0(PC_BLACK ), MKCOLOUR_F00F},
00402 };
00403
00405 static const byte _tiletype_importance[] = {
00406 2,
00407 8,
00408 7,
00409 5,
00410 2,
00411 9,
00412 2,
00413 1,
00414 6,
00415 8,
00416 2,
00417 0,
00418 };
00419
00420
00421 static inline TileType GetEffectiveTileType(TileIndex tile)
00422 {
00423 TileType t = GetTileType(tile);
00424
00425 if (t == MP_TUNNELBRIDGE) {
00426 TransportType tt = GetTunnelBridgeTransportType(tile);
00427
00428 switch (tt) {
00429 case TRANSPORT_RAIL: t = MP_RAILWAY; break;
00430 case TRANSPORT_ROAD: t = MP_ROAD; break;
00431 default: t = MP_WATER; break;
00432 }
00433 }
00434 return t;
00435 }
00436
00443 static inline uint32 GetSmallMapContoursPixels(TileIndex tile, TileType t)
00444 {
00445 const SmallMapColourScheme *cs = &_heightmap_schemes[_settings_client.gui.smallmap_land_colour];
00446 return ApplyMask(cs->height_colours[TileHeight(tile)], &_smallmap_contours_andor[t]);
00447 }
00448
00456 static inline uint32 GetSmallMapVehiclesPixels(TileIndex tile, TileType t)
00457 {
00458 const SmallMapColourScheme *cs = &_heightmap_schemes[_settings_client.gui.smallmap_land_colour];
00459 return ApplyMask(cs->default_colour, &_smallmap_vehicles_andor[t]);
00460 }
00461
00469 static inline uint32 GetSmallMapIndustriesPixels(TileIndex tile, TileType t)
00470 {
00471 if (t == MP_INDUSTRY) {
00472
00473 IndustryType type = Industry::GetByTile(tile)->type;
00474 if (_legend_from_industries[_industry_to_list_pos[type]].show_on_map &&
00475 (_smallmap_industry_highlight_state || type != _smallmap_industry_highlight)) {
00476 return (type == _smallmap_industry_highlight ? PC_WHITE : GetIndustrySpec(Industry::GetByTile(tile)->type)->map_colour) * 0x01010101;
00477 } else {
00478
00479 t = (IsTileOnWater(tile) ? MP_WATER : MP_CLEAR);
00480 }
00481 }
00482
00483 const SmallMapColourScheme *cs = &_heightmap_schemes[_settings_client.gui.smallmap_land_colour];
00484 return ApplyMask(_smallmap_show_heightmap ? cs->height_colours[TileHeight(tile)] : cs->default_colour, &_smallmap_vehicles_andor[t]);
00485 }
00486
00494 static inline uint32 GetSmallMapRoutesPixels(TileIndex tile, TileType t)
00495 {
00496 if (t == MP_STATION) {
00497 switch (GetStationType(tile)) {
00498 case STATION_RAIL: return MKCOLOUR_XXXX(PC_VERY_DARK_BROWN);
00499 case STATION_AIRPORT: return MKCOLOUR_XXXX(PC_RED);
00500 case STATION_TRUCK: return MKCOLOUR_XXXX(PC_ORANGE);
00501 case STATION_BUS: return MKCOLOUR_XXXX(PC_YELLOW);
00502 case STATION_DOCK: return MKCOLOUR_XXXX(PC_LIGHT_BLUE);
00503 default: return MKCOLOUR_FFFF;
00504 }
00505 } else if (t == MP_RAILWAY) {
00506 AndOr andor = {
00507 MKCOLOUR_0XX0(GetRailTypeInfo(GetRailType(tile))->map_colour),
00508 _smallmap_contours_andor[t].mand
00509 };
00510
00511 const SmallMapColourScheme *cs = &_heightmap_schemes[_settings_client.gui.smallmap_land_colour];
00512 return ApplyMask(cs->default_colour, &andor);
00513 }
00514
00515
00516 const SmallMapColourScheme *cs = &_heightmap_schemes[_settings_client.gui.smallmap_land_colour];
00517 return ApplyMask(cs->default_colour, &_smallmap_contours_andor[t]);
00518 }
00519
00527 static inline uint32 GetSmallMapLinkStatsPixels(TileIndex tile, TileType t)
00528 {
00529 return _smallmap_show_heightmap ? GetSmallMapContoursPixels(tile, t) : GetSmallMapRoutesPixels(tile, t);
00530 }
00531
00532 static const uint32 _vegetation_clear_bits[] = {
00533 MKCOLOUR_XXXX(PC_GRASS_LAND),
00534 MKCOLOUR_XXXX(PC_ROUGH_LAND),
00535 MKCOLOUR_XXXX(PC_GREY),
00536 MKCOLOUR_XXXX(PC_FIELDS),
00537 MKCOLOUR_XXXX(PC_LIGHT_BLUE),
00538 MKCOLOUR_XXXX(PC_ORANGE),
00539 MKCOLOUR_XXXX(PC_GRASS_LAND),
00540 MKCOLOUR_XXXX(PC_GRASS_LAND),
00541 };
00542
00550 static inline uint32 GetSmallMapVegetationPixels(TileIndex tile, TileType t)
00551 {
00552 switch (t) {
00553 case MP_CLEAR:
00554 return (IsClearGround(tile, CLEAR_GRASS) && GetClearDensity(tile) < 3) ? MKCOLOUR_XXXX(PC_BARE_LAND) : _vegetation_clear_bits[GetClearGround(tile)];
00555
00556 case MP_INDUSTRY:
00557 return IsTileForestIndustry(tile) ? MKCOLOUR_XXXX(PC_GREEN) : MKCOLOUR_XXXX(PC_DARK_RED);
00558
00559 case MP_TREES:
00560 if (GetTreeGround(tile) == TREE_GROUND_SNOW_DESERT || GetTreeGround(tile) == TREE_GROUND_ROUGH_SNOW) {
00561 return (_settings_game.game_creation.landscape == LT_ARCTIC) ? MKCOLOUR_XYYX(PC_LIGHT_BLUE, PC_TREES) : MKCOLOUR_XYYX(PC_ORANGE, PC_TREES);
00562 }
00563 return MKCOLOUR_XYYX(PC_GRASS_LAND, PC_TREES);
00564
00565 default:
00566 return ApplyMask(MKCOLOUR_XXXX(PC_GRASS_LAND), &_smallmap_vehicles_andor[t]);
00567 }
00568 }
00569
00577 static inline uint32 GetSmallMapOwnerPixels(TileIndex tile, TileType t)
00578 {
00579 Owner o;
00580
00581 switch (t) {
00582 case MP_INDUSTRY: return MKCOLOUR_XXXX(PC_DARK_GREY);
00583 case MP_HOUSE: return MKCOLOUR_XXXX(PC_DARK_RED);
00584 default: o = GetTileOwner(tile); break;
00585
00586
00587
00588
00589 }
00590
00591 if ((o < MAX_COMPANIES && !_legend_land_owners[_company_to_list_pos[o]].show_on_map) || o == OWNER_NONE || o == OWNER_WATER) {
00592 if (t == MP_WATER) return MKCOLOUR_XXXX(PC_WATER);
00593 const SmallMapColourScheme *cs = &_heightmap_schemes[_settings_client.gui.smallmap_land_colour];
00594 return _smallmap_show_heightmap ? cs->height_colours[TileHeight(tile)] : cs->default_colour;
00595 } else if (o == OWNER_TOWN) {
00596 return MKCOLOUR_XXXX(PC_DARK_RED);
00597 }
00598
00599 return MKCOLOUR_XXXX(_legend_land_owners[_company_to_list_pos[o]].colour);
00600 }
00601
00603 static const byte _vehicle_type_colours[6] = {
00604 PC_RED, PC_YELLOW, PC_LIGHT_BLUE, PC_WHITE, PC_BLACK, PC_RED
00605 };
00606
00607
00608 inline Point SmallMapWindow::SmallmapRemapCoords(int x, int y) const
00609 {
00610 Point pt;
00611 pt.x = (y - x) * 2;
00612 pt.y = y + x;
00613 return pt;
00614 }
00615
00622 inline Point SmallMapWindow::RemapTile(int tile_x, int tile_y) const
00623 {
00624 int x_offset = tile_x - this->scroll_x / (int)TILE_SIZE;
00625 int y_offset = tile_y - this->scroll_y / (int)TILE_SIZE;
00626
00627 if (this->zoom == 1) return SmallmapRemapCoords(x_offset, y_offset);
00628
00629
00630 if (x_offset < 0) x_offset -= this->zoom - 1;
00631 if (y_offset < 0) y_offset -= this->zoom - 1;
00632
00633 return SmallmapRemapCoords(x_offset / this->zoom, y_offset / this->zoom);
00634 }
00635
00646 inline Point SmallMapWindow::PixelToTile(int px, int py, int *sub, bool add_sub) const
00647 {
00648 if (add_sub) px += this->subscroll;
00649
00650
00651
00652 Point pt = {((py >> 1) - (px >> 2)) * this->zoom, ((py >> 1) + (px >> 2)) * this->zoom};
00653 px &= 3;
00654
00655 if (py & 1) {
00656 if (px < 2) {
00657 pt.x += this->zoom;
00658 px += 2;
00659 } else {
00660 pt.y += this->zoom;
00661 px -= 2;
00662 }
00663 }
00664
00665 *sub = px;
00666 return pt;
00667 }
00668
00678 Point SmallMapWindow::ComputeScroll(int tx, int ty, int x, int y, int *sub)
00679 {
00680 assert(x >= 0 && y >= 0);
00681
00682 int new_sub;
00683 Point tile_xy = PixelToTile(x, y, &new_sub, false);
00684 tx -= tile_xy.x;
00685 ty -= tile_xy.y;
00686
00687 Point scroll;
00688 if (new_sub == 0) {
00689 *sub = 0;
00690 scroll.x = (tx + this->zoom) * TILE_SIZE;
00691 scroll.y = (ty - this->zoom) * TILE_SIZE;
00692 } else {
00693 *sub = 4 - new_sub;
00694 scroll.x = (tx + 2 * this->zoom) * TILE_SIZE;
00695 scroll.y = (ty - 2 * this->zoom) * TILE_SIZE;
00696 }
00697 return scroll;
00698 }
00699
00706 void SmallMapWindow::SetZoomLevel(ZoomLevelChange change, const Point *zoom_pt)
00707 {
00708 static const int zoomlevels[] = {1, 2, 4, 6, 8};
00709 static const int MIN_ZOOM_INDEX = 0;
00710 static const int MAX_ZOOM_INDEX = lengthof(zoomlevels) - 1;
00711
00712 int new_index, cur_index, sub;
00713 Point tile;
00714 switch (change) {
00715 case ZLC_INITIALIZE:
00716 cur_index = - 1;
00717 new_index = MIN_ZOOM_INDEX;
00718 tile.x = tile.y = 0;
00719 break;
00720
00721 case ZLC_ZOOM_IN:
00722 case ZLC_ZOOM_OUT:
00723 for (cur_index = MIN_ZOOM_INDEX; cur_index <= MAX_ZOOM_INDEX; cur_index++) {
00724 if (this->zoom == zoomlevels[cur_index]) break;
00725 }
00726 assert(cur_index <= MAX_ZOOM_INDEX);
00727
00728 tile = this->PixelToTile(zoom_pt->x, zoom_pt->y, &sub);
00729 new_index = Clamp(cur_index + ((change == ZLC_ZOOM_IN) ? -1 : 1), MIN_ZOOM_INDEX, MAX_ZOOM_INDEX);
00730 break;
00731
00732 default: NOT_REACHED();
00733 }
00734
00735 if (new_index != cur_index) {
00736 this->zoom = zoomlevels[new_index];
00737 if (cur_index >= 0) {
00738 Point new_tile = this->PixelToTile(zoom_pt->x, zoom_pt->y, &sub);
00739 this->SetNewScroll(this->scroll_x + (tile.x - new_tile.x) * TILE_SIZE,
00740 this->scroll_y + (tile.y - new_tile.y) * TILE_SIZE, sub);
00741 } else if (this->map_type == SMT_LINKSTATS) {
00742 this->overlay->RebuildCache();
00743 }
00744 this->SetWidgetDisabledState(WID_SM_ZOOM_IN, this->zoom == zoomlevels[MIN_ZOOM_INDEX]);
00745 this->SetWidgetDisabledState(WID_SM_ZOOM_OUT, this->zoom == zoomlevels[MAX_ZOOM_INDEX]);
00746 this->SetDirty();
00747 }
00748 }
00749
00755 inline uint32 SmallMapWindow::GetTileColours(const TileArea &ta) const
00756 {
00757 int importance = 0;
00758 TileIndex tile = INVALID_TILE;
00759 TileType et = MP_VOID;
00760
00761 TILE_AREA_LOOP(ti, ta) {
00762 TileType ttype = GetEffectiveTileType(ti);
00763 if (_tiletype_importance[ttype] > importance) {
00764 importance = _tiletype_importance[ttype];
00765 tile = ti;
00766 et = ttype;
00767 }
00768 }
00769
00770 switch (this->map_type) {
00771 case SMT_CONTOUR:
00772 return GetSmallMapContoursPixels(tile, et);
00773
00774 case SMT_VEHICLES:
00775 return GetSmallMapVehiclesPixels(tile, et);
00776
00777 case SMT_INDUSTRY:
00778 return GetSmallMapIndustriesPixels(tile, et);
00779
00780 case SMT_LINKSTATS:
00781 return GetSmallMapLinkStatsPixels(tile, et);
00782
00783 case SMT_ROUTES:
00784 return GetSmallMapRoutesPixels(tile, et);
00785
00786 case SMT_VEGETATION:
00787 return GetSmallMapVegetationPixels(tile, et);
00788
00789 case SMT_OWNER:
00790 return GetSmallMapOwnerPixels(tile, et);
00791
00792 default: NOT_REACHED();
00793 }
00794 }
00795
00809 void SmallMapWindow::DrawSmallMapColumn(void *dst, uint xc, uint yc, int pitch, int reps, int start_pos, int end_pos, Blitter *blitter) const
00810 {
00811 void *dst_ptr_abs_end = blitter->MoveTo(_screen.dst_ptr, 0, _screen.height);
00812 uint min_xy = _settings_game.construction.freeform_edges ? 1 : 0;
00813
00814 do {
00815
00816 if (xc >= MapMaxX() || yc >= MapMaxY()) continue;
00817
00818
00819 if (dst < _screen.dst_ptr) continue;
00820 if (dst >= dst_ptr_abs_end) continue;
00821
00822
00823 TileArea ta;
00824 if (min_xy == 1 && (xc == 0 || yc == 0)) {
00825 if (this->zoom == 1) continue;
00826
00827 ta = TileArea(TileXY(max(min_xy, xc), max(min_xy, yc)), this->zoom - (xc == 0), this->zoom - (yc == 0));
00828 } else {
00829 ta = TileArea(TileXY(xc, yc), this->zoom, this->zoom);
00830 }
00831 ta.ClampToMap();
00832
00833 uint32 val = this->GetTileColours(ta);
00834 uint8 *val8 = (uint8 *)&val;
00835 int idx = max(0, -start_pos);
00836 for (int pos = max(0, start_pos); pos < end_pos; pos++) {
00837 blitter->SetPixel(dst, idx, 0, val8[idx]);
00838 idx++;
00839 }
00840
00841 } while (xc += this->zoom, yc += this->zoom, dst = blitter->MoveTo(dst, pitch, 0), --reps != 0);
00842 }
00843
00849 void SmallMapWindow::DrawVehicles(const DrawPixelInfo *dpi, Blitter *blitter) const
00850 {
00851 const Vehicle *v;
00852 FOR_ALL_VEHICLES(v) {
00853 if (v->type == VEH_EFFECT) continue;
00854 if (v->vehstatus & (VS_HIDDEN | VS_UNCLICKABLE)) continue;
00855
00856
00857 Point pt = this->RemapTile(v->x_pos / TILE_SIZE, v->y_pos / TILE_SIZE);
00858
00859 int y = pt.y - dpi->top;
00860 if (!IsInsideMM(y, 0, dpi->height)) continue;
00861
00862 bool skip = false;
00863 int x = pt.x - this->subscroll - 3 - dpi->left;
00864 if (x < 0) {
00865
00866
00867 if (++x != 0) continue;
00868 skip = true;
00869 } else if (x >= dpi->width - 1) {
00870
00871 if (x != dpi->width - 1) continue;
00872 skip = true;
00873 }
00874
00875
00876 byte colour = (this->map_type == SMT_VEHICLES) ? _vehicle_type_colours[v->type] : PC_WHITE;
00877
00878
00879 blitter->SetPixel(dpi->dst_ptr, x, y, colour);
00880 if (!skip) blitter->SetPixel(dpi->dst_ptr, x + 1, y, colour);
00881 }
00882 }
00883
00888 void SmallMapWindow::DrawTowns(const DrawPixelInfo *dpi) const
00889 {
00890 const Town *t;
00891 FOR_ALL_TOWNS(t) {
00892
00893 Point pt = this->RemapTile(TileX(t->xy), TileY(t->xy));
00894 int x = pt.x - this->subscroll - (t->cache.sign.width_small >> 1);
00895 int y = pt.y;
00896
00897
00898 if (x + t->cache.sign.width_small > dpi->left &&
00899 x < dpi->left + dpi->width &&
00900 y + FONT_HEIGHT_SMALL > dpi->top &&
00901 y < dpi->top + dpi->height) {
00902
00903 SetDParam(0, t->index);
00904 DrawString(x, x + t->cache.sign.width_small, y, STR_SMALLMAP_TOWN);
00905 }
00906 }
00907 }
00908
00912 void SmallMapWindow::DrawMapIndicators() const
00913 {
00914
00915 const ViewPort *vp = FindWindowById(WC_MAIN_WINDOW, 0)->viewport;
00916
00917 Point tile = InverseRemapCoords(vp->virtual_left, vp->virtual_top);
00918 Point tl = this->RemapTile(tile.x >> 4, tile.y >> 4);
00919 tl.x -= this->subscroll;
00920
00921 tile = InverseRemapCoords(vp->virtual_left + vp->virtual_width, vp->virtual_top + vp->virtual_height);
00922 Point br = this->RemapTile(tile.x >> 4, tile.y >> 4);
00923 br.x -= this->subscroll;
00924
00925 SmallMapWindow::DrawVertMapIndicator(tl.x, tl.y, br.y);
00926 SmallMapWindow::DrawVertMapIndicator(br.x, tl.y, br.y);
00927
00928 SmallMapWindow::DrawHorizMapIndicator(tl.x, br.x, tl.y);
00929 SmallMapWindow::DrawHorizMapIndicator(tl.x, br.x, br.y);
00930 }
00931
00943 void SmallMapWindow::DrawSmallMap(DrawPixelInfo *dpi) const
00944 {
00945 Blitter *blitter = BlitterFactory::GetCurrentBlitter();
00946 DrawPixelInfo *old_dpi;
00947
00948 old_dpi = _cur_dpi;
00949 _cur_dpi = dpi;
00950
00951
00952 GfxFillRect(dpi->left, dpi->top, dpi->left + dpi->width - 1, dpi->top + dpi->height - 1, PC_BLACK);
00953
00954
00955 int dx;
00956 Point tile = this->PixelToTile(dpi->left, dpi->top, &dx);
00957 int tile_x = this->scroll_x / (int)TILE_SIZE + tile.x;
00958 int tile_y = this->scroll_y / (int)TILE_SIZE + tile.y;
00959
00960 void *ptr = blitter->MoveTo(dpi->dst_ptr, -dx - 4, 0);
00961 int x = - dx - 4;
00962 int y = 0;
00963
00964 for (;;) {
00965
00966 if (x >= -3) {
00967 if (x >= dpi->width) break;
00968
00969 int end_pos = min(dpi->width, x + 4);
00970 int reps = (dpi->height - y + 1) / 2;
00971 if (reps > 0) {
00972 this->DrawSmallMapColumn(ptr, tile_x, tile_y, dpi->pitch * 2, reps, x, end_pos, blitter);
00973 }
00974 }
00975
00976 if (y == 0) {
00977 tile_y += this->zoom;
00978 y++;
00979 ptr = blitter->MoveTo(ptr, 0, 1);
00980 } else {
00981 tile_x -= this->zoom;
00982 y--;
00983 ptr = blitter->MoveTo(ptr, 0, -1);
00984 }
00985 ptr = blitter->MoveTo(ptr, 2, 0);
00986 x += 2;
00987 }
00988
00989
00990 if (this->map_type == SMT_CONTOUR || this->map_type == SMT_VEHICLES) this->DrawVehicles(dpi, blitter);
00991
00992
00993 if (this->map_type == SMT_LINKSTATS) this->overlay->Draw(dpi);
00994
00995
00996 if (this->show_towns) this->DrawTowns(dpi);
00997
00998
00999 this->DrawMapIndicators();
01000
01001 _cur_dpi = old_dpi;
01002 }
01003
01007 void SmallMapWindow::SetupWidgetData()
01008 {
01009 StringID legend_tooltip;
01010 StringID enable_all_tooltip;
01011 StringID disable_all_tooltip;
01012 int plane;
01013 switch (this->map_type) {
01014 case SMT_INDUSTRY:
01015 legend_tooltip = STR_SMALLMAP_TOOLTIP_INDUSTRY_SELECTION;
01016 enable_all_tooltip = STR_SMALLMAP_TOOLTIP_ENABLE_ALL_INDUSTRIES;
01017 disable_all_tooltip = STR_SMALLMAP_TOOLTIP_DISABLE_ALL_INDUSTRIES;
01018 plane = 0;
01019 break;
01020
01021 case SMT_OWNER:
01022 legend_tooltip = STR_SMALLMAP_TOOLTIP_COMPANY_SELECTION;
01023 enable_all_tooltip = STR_SMALLMAP_TOOLTIP_ENABLE_ALL_COMPANIES;
01024 disable_all_tooltip = STR_SMALLMAP_TOOLTIP_DISABLE_ALL_COMPANIES;
01025 plane = 0;
01026 break;
01027
01028 case SMT_LINKSTATS:
01029 legend_tooltip = STR_SMALLMAP_TOOLTIP_CARGO_SELECTION;
01030 enable_all_tooltip = STR_SMALLMAP_TOOLTIP_ENABLE_ALL_CARGOS;
01031 disable_all_tooltip = STR_SMALLMAP_TOOLTIP_DISABLE_ALL_CARGOS;
01032 plane = 0;
01033 break;
01034
01035 default:
01036 legend_tooltip = STR_NULL;
01037 enable_all_tooltip = STR_NULL;
01038 disable_all_tooltip = STR_NULL;
01039 plane = 1;
01040 break;
01041 }
01042
01043 this->GetWidget<NWidgetCore>(WID_SM_LEGEND)->SetDataTip(STR_NULL, legend_tooltip);
01044 this->GetWidget<NWidgetCore>(WID_SM_ENABLE_ALL)->SetDataTip(STR_SMALLMAP_ENABLE_ALL, enable_all_tooltip);
01045 this->GetWidget<NWidgetCore>(WID_SM_DISABLE_ALL)->SetDataTip(STR_SMALLMAP_DISABLE_ALL, disable_all_tooltip);
01046 this->GetWidget<NWidgetStacked>(WID_SM_SELECT_BUTTONS)->SetDisplayedPlane(plane);
01047 }
01048
01049 SmallMapWindow::SmallMapWindow(WindowDesc *desc, int window_number) : Window(desc), refresh(FORCE_REFRESH_PERIOD)
01050 {
01051 _smallmap_industry_highlight = INVALID_INDUSTRYTYPE;
01052 this->overlay = new LinkGraphOverlay(this, WID_SM_MAP, 0, this->GetOverlayCompanyMask(), 1);
01053 this->InitNested(window_number);
01054 this->LowerWidget(this->map_type + WID_SM_CONTOUR);
01055
01056 BuildLandLegend();
01057 this->SetWidgetLoweredState(WID_SM_SHOW_HEIGHT, _smallmap_show_heightmap);
01058
01059 this->SetWidgetLoweredState(WID_SM_TOGGLETOWNNAME, this->show_towns);
01060
01061 this->SetupWidgetData();
01062
01063 this->SetZoomLevel(ZLC_INITIALIZE, NULL);
01064 this->SmallMapCenterOnCurrentPos();
01065 this->SetOverlayCargoMask();
01066 }
01067
01068 void SmallMapWindow::SetStringParameters(int widget) const
01069 {
01070 switch (widget) {
01071 case WID_SM_CAPTION:
01072 SetDParam(0, STR_SMALLMAP_TYPE_CONTOURS + this->map_type);
01073 break;
01074 }
01075 }
01076
01077 void SmallMapWindow::OnInit()
01078 {
01079 uint min_width = 0;
01080 this->min_number_of_columns = INDUSTRY_MIN_NUMBER_OF_COLUMNS;
01081 this->min_number_of_fixed_rows = lengthof(_linkstat_colours_in_legenda);
01082 for (uint i = 0; i < lengthof(_legend_table); i++) {
01083 uint height = 0;
01084 uint num_columns = 1;
01085 for (const LegendAndColour *tbl = _legend_table[i]; !tbl->end; ++tbl) {
01086 StringID str;
01087 if (i == SMT_INDUSTRY) {
01088 SetDParam(0, tbl->legend);
01089 SetDParam(1, IndustryPool::MAX_SIZE);
01090 str = STR_SMALLMAP_INDUSTRY;
01091 } else if (i == SMT_LINKSTATS) {
01092 SetDParam(0, tbl->legend);
01093 str = STR_SMALLMAP_LINKSTATS;
01094 } else if (i == SMT_OWNER) {
01095 if (tbl->company != INVALID_COMPANY) {
01096 if (!Company::IsValidID(tbl->company)) {
01097
01098 BuildOwnerLegend();
01099 this->OnInit();
01100 return;
01101 }
01102
01103 SetDParam(0, tbl->company);
01104 str = STR_SMALLMAP_COMPANY;
01105 } else {
01106 str = tbl->legend;
01107 }
01108 } else {
01109 if (tbl->col_break) {
01110 this->min_number_of_fixed_rows = max(this->min_number_of_fixed_rows, height);
01111 height = 0;
01112 num_columns++;
01113 }
01114 height++;
01115 str = tbl->legend;
01116 }
01117 min_width = max(GetStringBoundingBox(str).width, min_width);
01118 }
01119 this->min_number_of_fixed_rows = max(this->min_number_of_fixed_rows, height);
01120 this->min_number_of_columns = max(this->min_number_of_columns, num_columns);
01121 }
01122
01123
01124 this->column_width = min_width + LEGEND_BLOB_WIDTH + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT;
01125 }
01126
01127 void SmallMapWindow::OnPaint()
01128 {
01129 if (this->map_type == SMT_OWNER) {
01130 for (const LegendAndColour *tbl = _legend_table[this->map_type]; !tbl->end; ++tbl) {
01131 if (tbl->company != INVALID_COMPANY && !Company::IsValidID(tbl->company)) {
01132
01133 BuildOwnerLegend();
01134 this->InvalidateData(1);
01135 break;
01136 }
01137 }
01138 }
01139
01140 this->DrawWidgets();
01141 }
01142
01143 void SmallMapWindow::DrawWidget(const Rect &r, int widget) const
01144 {
01145 switch (widget) {
01146 case WID_SM_MAP: {
01147 DrawPixelInfo new_dpi;
01148 if (!FillDrawPixelInfo(&new_dpi, r.left + 1, r.top + 1, r.right - r.left - 1, r.bottom - r.top - 1)) return;
01149 this->DrawSmallMap(&new_dpi);
01150 break;
01151 }
01152
01153 case WID_SM_LEGEND: {
01154 uint columns = this->GetNumberColumnsLegend(r.right - r.left + 1);
01155 uint number_of_rows = this->GetNumberRowsLegend(columns);
01156 bool rtl = _current_text_dir == TD_RTL;
01157 uint y_org = r.top + WD_FRAMERECT_TOP;
01158 uint x = rtl ? r.right - this->column_width - WD_FRAMERECT_RIGHT : r.left + WD_FRAMERECT_LEFT;
01159 uint y = y_org;
01160 uint i = 0;
01161 uint row_height = FONT_HEIGHT_SMALL;
01162
01163 uint text_left = rtl ? 0 : LEGEND_BLOB_WIDTH + WD_FRAMERECT_LEFT;
01164 uint text_right = this->column_width - 1 - (rtl ? LEGEND_BLOB_WIDTH + WD_FRAMERECT_RIGHT : 0);
01165 uint blob_left = rtl ? this->column_width - 1 - LEGEND_BLOB_WIDTH : 0;
01166 uint blob_right = rtl ? this->column_width - 1 : LEGEND_BLOB_WIDTH;
01167
01168 StringID string = STR_NULL;
01169 switch (this->map_type) {
01170 case SMT_INDUSTRY:
01171 string = STR_SMALLMAP_INDUSTRY;
01172 break;
01173 case SMT_LINKSTATS:
01174 string = STR_SMALLMAP_LINKSTATS;
01175 break;
01176 case SMT_OWNER:
01177 string = STR_SMALLMAP_COMPANY;
01178 break;
01179 default:
01180 break;
01181 }
01182
01183 for (const LegendAndColour *tbl = _legend_table[this->map_type]; !tbl->end; ++tbl) {
01184 if (tbl->col_break || ((this->map_type == SMT_INDUSTRY || this->map_type == SMT_OWNER || this->map_type == SMT_LINKSTATS) && i++ >= number_of_rows)) {
01185
01186
01187 x += rtl ? -(int)this->column_width : this->column_width;
01188 y = y_org;
01189 i = 1;
01190 }
01191
01192 uint8 legend_colour = tbl->colour;
01193
01194 switch (this->map_type) {
01195 case SMT_INDUSTRY:
01196
01197
01198 SetDParam(0, tbl->legend);
01199 SetDParam(1, Industry::GetIndustryTypeCount(tbl->type));
01200 if (tbl->show_on_map && tbl->type == _smallmap_industry_highlight) {
01201 legend_colour = _smallmap_industry_highlight_state ? PC_WHITE : PC_BLACK;
01202 }
01203
01204 case SMT_LINKSTATS:
01205 SetDParam(0, tbl->legend);
01206
01207 case SMT_OWNER:
01208 if (this->map_type != SMT_OWNER || tbl->company != INVALID_COMPANY) {
01209 if (this->map_type == SMT_OWNER) SetDParam(0, tbl->company);
01210 if (!tbl->show_on_map) {
01211
01212
01213 DrawString(x + text_left, x + text_right, y, string, TC_GREY);
01214 } else {
01215 DrawString(x + text_left, x + text_right, y, string, TC_BLACK);
01216 GfxFillRect(x + blob_left, y + 1, x + blob_right, y + row_height - 1, PC_BLACK);
01217 }
01218 break;
01219 }
01220
01221 default:
01222 if (this->map_type == SMT_CONTOUR) SetDParam(0, tbl->height * TILE_HEIGHT_STEP);
01223
01224 GfxFillRect(x + blob_left, y + 1, x + blob_right, y + row_height - 1, PC_BLACK);
01225 DrawString(x + text_left, x + text_right, y, tbl->legend);
01226 break;
01227 }
01228 GfxFillRect(x + blob_left + 1, y + 2, x + blob_right - 1, y + row_height - 2, legend_colour);
01229
01230 y += row_height;
01231 }
01232 }
01233 }
01234 }
01235
01240 void SmallMapWindow::SwitchMapType(SmallMapType map_type)
01241 {
01242 this->RaiseWidget(this->map_type + WID_SM_CONTOUR);
01243 this->map_type = map_type;
01244 this->LowerWidget(this->map_type + WID_SM_CONTOUR);
01245
01246 this->SetupWidgetData();
01247
01248 if (map_type == SMT_LINKSTATS) this->overlay->RebuildCache();
01249 this->SetDirty();
01250 }
01251
01260 inline uint SmallMapWindow::GetNumberRowsLegend(uint columns) const
01261 {
01262
01263 uint num_rows_linkstats = CeilDiv(_smallmap_cargo_count, columns - 1);
01264 uint num_rows_others = CeilDiv(max(_smallmap_industry_count, _smallmap_company_count), columns);
01265 return max(this->min_number_of_fixed_rows, max(num_rows_linkstats, num_rows_others));
01266 }
01267
01279 void SmallMapWindow::SelectLegendItem(int click_pos, LegendAndColour *legend, int end_legend_item, int begin_legend_item)
01280 {
01281 if (_ctrl_pressed) {
01282
01283 bool changes = false;
01284 for (int i = begin_legend_item; i != end_legend_item; i++) {
01285 bool new_state = (i == click_pos);
01286 if (legend[i].show_on_map != new_state) {
01287 changes = true;
01288 legend[i].show_on_map = new_state;
01289 }
01290 }
01291 if (!changes) {
01292
01293 for (int i = begin_legend_item; i != end_legend_item; i++) {
01294 legend[i].show_on_map = true;
01295 }
01296 }
01297 } else {
01298 legend[click_pos].show_on_map = !legend[click_pos].show_on_map;
01299 }
01300 }
01301
01305 void SmallMapWindow::SetOverlayCargoMask()
01306 {
01307 uint32 cargo_mask = 0;
01308 for (int i = 0; i != _smallmap_cargo_count; ++i) {
01309 if (_legend_linkstats[i].show_on_map) SetBit(cargo_mask, _legend_linkstats[i].type);
01310 }
01311 this->overlay->SetCargoMask(cargo_mask);
01312 }
01313
01319 int SmallMapWindow::GetPositionOnLegend(Point pt)
01320 {
01321 const NWidgetBase *wi = this->GetWidget<NWidgetBase>(WID_SM_LEGEND);
01322 uint line = (pt.y - wi->pos_y - WD_FRAMERECT_TOP) / FONT_HEIGHT_SMALL;
01323 uint columns = this->GetNumberColumnsLegend(wi->current_x);
01324 uint number_of_rows = this->GetNumberRowsLegend(columns);
01325 if (line >= number_of_rows) return -1;
01326
01327 bool rtl = _current_text_dir == TD_RTL;
01328 int x = pt.x - wi->pos_x;
01329 if (rtl) x = wi->current_x - x;
01330 uint column = (x - WD_FRAMERECT_LEFT) / this->column_width;
01331
01332 return (column * number_of_rows) + line;
01333 }
01334
01335 void SmallMapWindow::OnMouseOver(Point pt, int widget)
01336 {
01337 IndustryType new_highlight = INVALID_INDUSTRYTYPE;
01338 if (widget == WID_SM_LEGEND && this->map_type == SMT_INDUSTRY) {
01339 int industry_pos = GetPositionOnLegend(pt);
01340 if (industry_pos >= 0 && industry_pos < _smallmap_industry_count) {
01341 new_highlight = _legend_from_industries[industry_pos].type;
01342 }
01343 }
01344 if (new_highlight != _smallmap_industry_highlight) {
01345 _smallmap_industry_highlight = new_highlight;
01346 this->refresh = _smallmap_industry_highlight != INVALID_INDUSTRYTYPE ? BLINK_PERIOD : FORCE_REFRESH_PERIOD;
01347 _smallmap_industry_highlight_state = true;
01348 this->SetDirty();
01349 }
01350 }
01351
01352 void SmallMapWindow::OnClick(Point pt, int widget, int click_count)
01353 {
01354
01355 InvalidateWindowClassesData(WC_INDUSTRY_CARGOES, NUM_INDUSTRYTYPES);
01356
01357 switch (widget) {
01358 case WID_SM_MAP: {
01359
01360
01361
01362
01363
01364
01365
01366
01367 _left_button_clicked = false;
01368
01369 const NWidgetBase *wid = this->GetWidget<NWidgetBase>(WID_SM_MAP);
01370 Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
01371 int sub;
01372 pt = this->PixelToTile(pt.x - wid->pos_x, pt.y - wid->pos_y, &sub);
01373 pt = RemapCoords(this->scroll_x + pt.x * TILE_SIZE + this->zoom * (TILE_SIZE - sub * TILE_SIZE / 4),
01374 this->scroll_y + pt.y * TILE_SIZE + sub * this->zoom * TILE_SIZE / 4, 0);
01375
01376 w->viewport->follow_vehicle = INVALID_VEHICLE;
01377 w->viewport->dest_scrollpos_x = pt.x - (w->viewport->virtual_width >> 1);
01378 w->viewport->dest_scrollpos_y = pt.y - (w->viewport->virtual_height >> 1);
01379
01380 this->SetDirty();
01381 break;
01382 }
01383
01384 case WID_SM_ZOOM_IN:
01385 case WID_SM_ZOOM_OUT: {
01386 const NWidgetBase *wid = this->GetWidget<NWidgetBase>(WID_SM_MAP);
01387 Point pt = {wid->current_x / 2, wid->current_y / 2};
01388 this->SetZoomLevel((widget == WID_SM_ZOOM_IN) ? ZLC_ZOOM_IN : ZLC_ZOOM_OUT, &pt);
01389 if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
01390 break;
01391 }
01392
01393 case WID_SM_CONTOUR:
01394 case WID_SM_VEHICLES:
01395 case WID_SM_INDUSTRIES:
01396 case WID_SM_LINKSTATS:
01397 case WID_SM_ROUTES:
01398 case WID_SM_VEGETATION:
01399 case WID_SM_OWNERS:
01400 this->SwitchMapType((SmallMapType)(widget - WID_SM_CONTOUR));
01401 if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
01402 break;
01403
01404 case WID_SM_CENTERMAP:
01405 this->SmallMapCenterOnCurrentPos();
01406 this->HandleButtonClick(WID_SM_CENTERMAP);
01407 if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
01408 break;
01409
01410 case WID_SM_TOGGLETOWNNAME:
01411 this->show_towns = !this->show_towns;
01412 this->SetWidgetLoweredState(WID_SM_TOGGLETOWNNAME, this->show_towns);
01413
01414 this->SetDirty();
01415 if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
01416 break;
01417
01418 case WID_SM_LEGEND:
01419 if (this->map_type == SMT_INDUSTRY || this->map_type == SMT_LINKSTATS || this->map_type == SMT_OWNER) {
01420 int click_pos = this->GetPositionOnLegend(pt);
01421 if (click_pos < 0) break;
01422
01423
01424 if (this->map_type == SMT_INDUSTRY) {
01425
01426 if (click_pos < _smallmap_industry_count) {
01427 this->SelectLegendItem(click_pos, _legend_from_industries, _smallmap_industry_count);
01428 }
01429 } else if (this->map_type == SMT_LINKSTATS) {
01430 if (click_pos < _smallmap_cargo_count) {
01431 this->SelectLegendItem(click_pos, _legend_linkstats, _smallmap_cargo_count);
01432 this->SetOverlayCargoMask();
01433 }
01434 } else if (this->map_type == SMT_OWNER) {
01435 if (click_pos < _smallmap_company_count) {
01436 this->SelectLegendItem(click_pos, _legend_land_owners, _smallmap_company_count, NUM_NO_COMPANY_ENTRIES);
01437 }
01438 }
01439 this->SetDirty();
01440 }
01441 break;
01442
01443 case WID_SM_ENABLE_ALL:
01444
01445 case WID_SM_DISABLE_ALL: {
01446 LegendAndColour *tbl = NULL;
01447 switch (this->map_type) {
01448 case SMT_INDUSTRY:
01449 tbl = _legend_from_industries;
01450 break;
01451 case SMT_OWNER:
01452 tbl = &(_legend_land_owners[NUM_NO_COMPANY_ENTRIES]);
01453 break;
01454 case SMT_LINKSTATS:
01455 tbl = _legend_linkstats;
01456 break;
01457 default:
01458 NOT_REACHED();
01459 }
01460 for (;!tbl->end && tbl->legend != STR_LINKGRAPH_LEGEND_UNUSED; ++tbl) {
01461 tbl->show_on_map = (widget == WID_SM_ENABLE_ALL);
01462 }
01463 if (this->map_type == SMT_LINKSTATS) this->SetOverlayCargoMask();
01464 this->SetDirty();
01465 break;
01466 }
01467
01468 case WID_SM_SHOW_HEIGHT:
01469 _smallmap_show_heightmap = !_smallmap_show_heightmap;
01470 this->SetWidgetLoweredState(WID_SM_SHOW_HEIGHT, _smallmap_show_heightmap);
01471 this->SetDirty();
01472 break;
01473 }
01474 }
01475
01483 void SmallMapWindow::OnInvalidateData(int data, bool gui_scope)
01484 {
01485 if (!gui_scope) return;
01486 switch (data) {
01487 case 1:
01488
01489 this->ReInit();
01490 break;
01491
01492 case 0: {
01493 extern uint64 _displayed_industries;
01494 if (this->map_type != SMT_INDUSTRY) this->SwitchMapType(SMT_INDUSTRY);
01495
01496 for (int i = 0; i != _smallmap_industry_count; i++) {
01497 _legend_from_industries[i].show_on_map = HasBit(_displayed_industries, _legend_from_industries[i].type);
01498 }
01499 break;
01500 }
01501
01502 default: NOT_REACHED();
01503 }
01504 this->SetDirty();
01505 }
01506
01507 bool SmallMapWindow::OnRightClick(Point pt, int widget)
01508 {
01509 if (widget != WID_SM_MAP || _scrolling_viewport) return false;
01510
01511 _scrolling_viewport = true;
01512 return true;
01513 }
01514
01515 void SmallMapWindow::OnMouseWheel(int wheel)
01516 {
01517 if (_settings_client.gui.scrollwheel_scrolling == 0) {
01518 const NWidgetBase *wid = this->GetWidget<NWidgetBase>(WID_SM_MAP);
01519 int cursor_x = _cursor.pos.x - this->left - wid->pos_x;
01520 int cursor_y = _cursor.pos.y - this->top - wid->pos_y;
01521 if (IsInsideMM(cursor_x, 0, wid->current_x) && IsInsideMM(cursor_y, 0, wid->current_y)) {
01522 Point pt = {cursor_x, cursor_y};
01523 this->SetZoomLevel((wheel < 0) ? ZLC_ZOOM_IN : ZLC_ZOOM_OUT, &pt);
01524 }
01525 }
01526 }
01527
01528 void SmallMapWindow::OnTick()
01529 {
01530
01531 if (--this->refresh != 0) return;
01532
01533 if (this->map_type == SMT_LINKSTATS) {
01534 uint32 company_mask = this->GetOverlayCompanyMask();
01535 if (this->overlay->GetCompanyMask() != company_mask) {
01536 this->overlay->SetCompanyMask(company_mask);
01537 } else {
01538 this->overlay->RebuildCache();
01539 }
01540 }
01541 _smallmap_industry_highlight_state = !_smallmap_industry_highlight_state;
01542
01543 this->refresh = _smallmap_industry_highlight != INVALID_INDUSTRYTYPE ? BLINK_PERIOD : FORCE_REFRESH_PERIOD;
01544 this->SetDirty();
01545 }
01546
01554 void SmallMapWindow::SetNewScroll(int sx, int sy, int sub)
01555 {
01556 const NWidgetBase *wi = this->GetWidget<NWidgetBase>(WID_SM_MAP);
01557 Point hv = InverseRemapCoords(wi->current_x * ZOOM_LVL_BASE * TILE_SIZE / 2, wi->current_y * ZOOM_LVL_BASE * TILE_SIZE / 2);
01558 hv.x *= this->zoom;
01559 hv.y *= this->zoom;
01560
01561 if (sx < -hv.x) {
01562 sx = -hv.x;
01563 sub = 0;
01564 }
01565 if (sx > (int)(MapMaxX() * TILE_SIZE) - hv.x) {
01566 sx = MapMaxX() * TILE_SIZE - hv.x;
01567 sub = 0;
01568 }
01569 if (sy < -hv.y) {
01570 sy = -hv.y;
01571 sub = 0;
01572 }
01573 if (sy > (int)(MapMaxY() * TILE_SIZE) - hv.y) {
01574 sy = MapMaxY() * TILE_SIZE - hv.y;
01575 sub = 0;
01576 }
01577
01578 this->scroll_x = sx;
01579 this->scroll_y = sy;
01580 this->subscroll = sub;
01581 if (this->map_type == SMT_LINKSTATS) this->overlay->RebuildCache();
01582 }
01583
01584 void SmallMapWindow::OnScroll(Point delta)
01585 {
01586 _cursor.fix_at = true;
01587
01588
01589 int sub;
01590 Point pt = this->PixelToTile(delta.x, delta.y, &sub);
01591 this->SetNewScroll(this->scroll_x + pt.x * TILE_SIZE, this->scroll_y + pt.y * TILE_SIZE, sub);
01592
01593 this->SetDirty();
01594 }
01595
01596 void SmallMapWindow::SmallMapCenterOnCurrentPos()
01597 {
01598 const ViewPort *vp = FindWindowById(WC_MAIN_WINDOW, 0)->viewport;
01599 Point pt = InverseRemapCoords(vp->virtual_left + vp->virtual_width / 2, vp->virtual_top + vp->virtual_height / 2);
01600
01601 int sub;
01602 const NWidgetBase *wid = this->GetWidget<NWidgetBase>(WID_SM_MAP);
01603 Point sxy = this->ComputeScroll(pt.x / TILE_SIZE, pt.y / TILE_SIZE, max(0, (int)wid->current_x / 2 - 2), wid->current_y / 2, &sub);
01604 this->SetNewScroll(sxy.x, sxy.y, sub);
01605 this->SetDirty();
01606 }
01607
01613 Point SmallMapWindow::GetStationMiddle(const Station *st) const
01614 {
01615 int x = (st->rect.right + st->rect.left + 1) / 2;
01616 int y = (st->rect.bottom + st->rect.top + 1) / 2;
01617 Point ret = this->RemapTile(x, y);
01618
01619
01620
01621
01622 ret.x -= 3 + this->subscroll;
01623 return ret;
01624 }
01625
01626 SmallMapWindow::SmallMapType SmallMapWindow::map_type = SMT_CONTOUR;
01627 bool SmallMapWindow::show_towns = true;
01628
01637 class NWidgetSmallmapDisplay : public NWidgetContainer {
01638 const SmallMapWindow *smallmap_window;
01639 public:
01640 NWidgetSmallmapDisplay() : NWidgetContainer(NWID_VERTICAL)
01641 {
01642 this->smallmap_window = NULL;
01643 }
01644
01645 virtual void SetupSmallestSize(Window *w, bool init_array)
01646 {
01647 NWidgetBase *display = this->head;
01648 NWidgetBase *bar = display->next;
01649
01650 display->SetupSmallestSize(w, init_array);
01651 bar->SetupSmallestSize(w, init_array);
01652
01653 this->smallmap_window = dynamic_cast<SmallMapWindow *>(w);
01654 assert(this->smallmap_window != NULL);
01655 this->smallest_x = max(display->smallest_x, bar->smallest_x + smallmap_window->GetMinLegendWidth());
01656 this->smallest_y = display->smallest_y + max(bar->smallest_y, smallmap_window->GetLegendHeight(smallmap_window->min_number_of_columns));
01657 this->fill_x = max(display->fill_x, bar->fill_x);
01658 this->fill_y = (display->fill_y == 0 && bar->fill_y == 0) ? 0 : min(display->fill_y, bar->fill_y);
01659 this->resize_x = max(display->resize_x, bar->resize_x);
01660 this->resize_y = min(display->resize_y, bar->resize_y);
01661 }
01662
01663 virtual void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl)
01664 {
01665 this->pos_x = x;
01666 this->pos_y = y;
01667 this->current_x = given_width;
01668 this->current_y = given_height;
01669
01670 NWidgetBase *display = this->head;
01671 NWidgetBase *bar = display->next;
01672
01673 if (sizing == ST_SMALLEST) {
01674 this->smallest_x = given_width;
01675 this->smallest_y = given_height;
01676
01677 display->AssignSizePosition(ST_SMALLEST, x, y, display->smallest_x, display->smallest_y, rtl);
01678 bar->AssignSizePosition(ST_SMALLEST, x, y + display->smallest_y, bar->smallest_x, bar->smallest_y, rtl);
01679 }
01680
01681 uint bar_height = max(bar->smallest_y, this->smallmap_window->GetLegendHeight(this->smallmap_window->GetNumberColumnsLegend(given_width - bar->smallest_x)));
01682 uint display_height = given_height - bar_height;
01683 display->AssignSizePosition(ST_RESIZE, x, y, given_width, display_height, rtl);
01684 bar->AssignSizePosition(ST_RESIZE, x, y + display_height, given_width, bar_height, rtl);
01685 }
01686
01687 virtual NWidgetCore *GetWidgetFromPos(int x, int y)
01688 {
01689 if (!IsInsideBS(x, this->pos_x, this->current_x) || !IsInsideBS(y, this->pos_y, this->current_y)) return NULL;
01690 for (NWidgetBase *child_wid = this->head; child_wid != NULL; child_wid = child_wid->next) {
01691 NWidgetCore *widget = child_wid->GetWidgetFromPos(x, y);
01692 if (widget != NULL) return widget;
01693 }
01694 return NULL;
01695 }
01696
01697 virtual void Draw(const Window *w)
01698 {
01699 for (NWidgetBase *child_wid = this->head; child_wid != NULL; child_wid = child_wid->next) child_wid->Draw(w);
01700 }
01701 };
01702
01704 static const NWidgetPart _nested_smallmap_display[] = {
01705 NWidget(WWT_PANEL, COLOUR_BROWN, WID_SM_MAP_BORDER),
01706 NWidget(WWT_INSET, COLOUR_BROWN, WID_SM_MAP), SetMinimalSize(346, 140), SetResize(1, 1), SetPadding(2, 2, 2, 2), EndContainer(),
01707 EndContainer(),
01708 };
01709
01711 static const NWidgetPart _nested_smallmap_bar[] = {
01712 NWidget(WWT_PANEL, COLOUR_BROWN),
01713 NWidget(NWID_HORIZONTAL),
01714 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_SM_LEGEND), SetResize(1, 1),
01715 NWidget(NWID_VERTICAL),
01716
01717 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
01718 NWidget(WWT_PUSHIMGBTN, COLOUR_BROWN, WID_SM_ZOOM_IN),
01719 SetDataTip(SPR_IMG_ZOOMIN, STR_TOOLBAR_TOOLTIP_ZOOM_THE_VIEW_IN), SetFill(1, 1),
01720 NWidget(WWT_PUSHIMGBTN, COLOUR_BROWN, WID_SM_CENTERMAP),
01721 SetDataTip(SPR_IMG_SMALLMAP, STR_SMALLMAP_CENTER), SetFill(1, 1),
01722 NWidget(WWT_IMGBTN, COLOUR_BROWN, WID_SM_BLANK),
01723 SetDataTip(SPR_DOT_SMALL, STR_NULL), SetFill(1, 1),
01724 NWidget(WWT_IMGBTN, COLOUR_BROWN, WID_SM_CONTOUR),
01725 SetDataTip(SPR_IMG_SHOW_COUNTOURS, STR_SMALLMAP_TOOLTIP_SHOW_LAND_CONTOURS_ON_MAP), SetFill(1, 1),
01726 NWidget(WWT_IMGBTN, COLOUR_BROWN, WID_SM_VEHICLES),
01727 SetDataTip(SPR_IMG_SHOW_VEHICLES, STR_SMALLMAP_TOOLTIP_SHOW_VEHICLES_ON_MAP), SetFill(1, 1),
01728 NWidget(WWT_IMGBTN, COLOUR_BROWN, WID_SM_INDUSTRIES),
01729 SetDataTip(SPR_IMG_INDUSTRY, STR_SMALLMAP_TOOLTIP_SHOW_INDUSTRIES_ON_MAP), SetFill(1, 1),
01730 EndContainer(),
01731
01732 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
01733 NWidget(WWT_PUSHIMGBTN, COLOUR_BROWN, WID_SM_ZOOM_OUT),
01734 SetDataTip(SPR_IMG_ZOOMOUT, STR_TOOLBAR_TOOLTIP_ZOOM_THE_VIEW_OUT), SetFill(1, 1),
01735 NWidget(WWT_IMGBTN, COLOUR_BROWN, WID_SM_TOGGLETOWNNAME),
01736 SetDataTip(SPR_IMG_TOWN, STR_SMALLMAP_TOOLTIP_TOGGLE_TOWN_NAMES_ON_OFF), SetFill(1, 1),
01737 NWidget(WWT_IMGBTN, COLOUR_BROWN, WID_SM_LINKSTATS),
01738 SetDataTip(SPR_IMG_CARGOFLOW, STR_SMALLMAP_TOOLTIP_SHOW_LINK_STATS_ON_MAP), SetFill(1, 1),
01739 NWidget(WWT_IMGBTN, COLOUR_BROWN, WID_SM_ROUTES),
01740 SetDataTip(SPR_IMG_SHOW_ROUTES, STR_SMALLMAP_TOOLTIP_SHOW_TRANSPORT_ROUTES_ON), SetFill(1, 1),
01741 NWidget(WWT_IMGBTN, COLOUR_BROWN, WID_SM_VEGETATION),
01742 SetDataTip(SPR_IMG_PLANTTREES, STR_SMALLMAP_TOOLTIP_SHOW_VEGETATION_ON_MAP), SetFill(1, 1),
01743 NWidget(WWT_IMGBTN, COLOUR_BROWN, WID_SM_OWNERS),
01744 SetDataTip(SPR_IMG_COMPANY_GENERAL, STR_SMALLMAP_TOOLTIP_SHOW_LAND_OWNERS_ON_MAP), SetFill(1, 1),
01745 EndContainer(),
01746 NWidget(NWID_SPACER), SetResize(0, 1),
01747 EndContainer(),
01748 EndContainer(),
01749 EndContainer(),
01750 };
01751
01752 static NWidgetBase *SmallMapDisplay(int *biggest_index)
01753 {
01754 NWidgetContainer *map_display = new NWidgetSmallmapDisplay;
01755
01756 MakeNWidgets(_nested_smallmap_display, lengthof(_nested_smallmap_display), biggest_index, map_display);
01757 MakeNWidgets(_nested_smallmap_bar, lengthof(_nested_smallmap_bar), biggest_index, map_display);
01758 return map_display;
01759 }
01760
01761
01762 static const NWidgetPart _nested_smallmap_widgets[] = {
01763 NWidget(NWID_HORIZONTAL),
01764 NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
01765 NWidget(WWT_CAPTION, COLOUR_BROWN, WID_SM_CAPTION), SetDataTip(STR_SMALLMAP_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
01766 NWidget(WWT_SHADEBOX, COLOUR_BROWN),
01767 NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
01768 NWidget(WWT_STICKYBOX, COLOUR_BROWN),
01769 EndContainer(),
01770 NWidgetFunction(SmallMapDisplay),
01771
01772 NWidget(NWID_HORIZONTAL),
01773 NWidget(WWT_PANEL, COLOUR_BROWN),
01774 NWidget(NWID_HORIZONTAL),
01775 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_SM_SELECT_BUTTONS),
01776 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
01777 NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, WID_SM_ENABLE_ALL), SetDataTip(STR_SMALLMAP_ENABLE_ALL, STR_NULL),
01778 NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, WID_SM_DISABLE_ALL), SetDataTip(STR_SMALLMAP_DISABLE_ALL, STR_NULL),
01779 NWidget(WWT_TEXTBTN, COLOUR_BROWN, WID_SM_SHOW_HEIGHT), SetDataTip(STR_SMALLMAP_SHOW_HEIGHT, STR_SMALLMAP_TOOLTIP_SHOW_HEIGHT),
01780 EndContainer(),
01781 NWidget(NWID_SPACER), SetFill(1, 1),
01782 EndContainer(),
01783 NWidget(NWID_SPACER), SetFill(1, 0), SetResize(1, 0),
01784 EndContainer(),
01785 EndContainer(),
01786 NWidget(WWT_RESIZEBOX, COLOUR_BROWN),
01787 EndContainer(),
01788 };
01789
01790 static WindowDesc _smallmap_desc(
01791 WDP_AUTO, "smallmap", 484, 314,
01792 WC_SMALLMAP, WC_NONE,
01793 0,
01794 _nested_smallmap_widgets, lengthof(_nested_smallmap_widgets)
01795 );
01796
01800 void ShowSmallMap()
01801 {
01802 AllocateWindowDescFront<SmallMapWindow>(&_smallmap_desc, 0);
01803 }
01804
01813 bool ScrollMainWindowTo(int x, int y, int z, bool instant)
01814 {
01815 bool res = ScrollWindowTo(x, y, z, FindWindowById(WC_MAIN_WINDOW, 0), instant);
01816
01817
01818
01819
01820
01821 if (res) return res;
01822
01823 SmallMapWindow *w = dynamic_cast<SmallMapWindow*>(FindWindowById(WC_SMALLMAP, 0));
01824 if (w != NULL) w->SmallMapCenterOnCurrentPos();
01825
01826 return res;
01827 }