truelight@0: #include "stdafx.h" truelight@0: #include "ttd.h" tron@507: #include "table/strings.h" tron@679: #include "map.h" darkvater@152: #include "gui.h" truelight@0: #include "window.h" truelight@0: #include "gfx.h" truelight@0: #include "viewport.h" truelight@0: #include "player.h" truelight@0: #include "vehicle.h" truelight@0: #include "town.h" tron@337: #include "sound.h" truelight@0: truelight@0: static const Widget _smallmap_megabig_widgets[] = { darkvater@176: { WWT_TEXTBTN, 13, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, truelight@0: { WWT_CAPTION, 13, 11, 592, 0, 13, STR_00B0_MAP,STR_018C_WINDOW_TITLE_DRAG_THIS}, darkvater@176: { WWT_IMGBTN, 13, 593, 606, 0, 13, 0x2AA, STR_01CC_TOGGLE_LARGE_SMALL_MAP}, darkvater@176: { WWT_IMGBTN, 13, 0, 606, 14, 407, 0x0, STR_NULL}, darkvater@176: { WWT_6, 13, 2, 604, 16, 405, 0x0, STR_NULL}, darkvater@176: { WWT_IMGBTN, 13, 541, 562, 408, 429, 0x2E2, STR_0191_SHOW_LAND_CONTOURS_ON_MAP}, darkvater@176: { WWT_IMGBTN, 13, 563, 584, 408, 429, 0x2E3, STR_0192_SHOW_VEHICLES_ON_MAP}, darkvater@176: { WWT_IMGBTN, 13, 585, 606, 408, 429, 0x2E5, STR_0193_SHOW_INDUSTRIES_ON_MAP}, darkvater@176: { WWT_IMGBTN, 13, 519, 540, 430, 451, 0x2E4, STR_0194_SHOW_TRANSPORT_ROUTES_ON}, darkvater@176: { WWT_IMGBTN, 13, 541, 562, 430, 451, 0x2E6, STR_0195_SHOW_VEGETATION_ON_MAP}, darkvater@176: { WWT_IMGBTN, 13, 563, 584, 430, 451, 0x2E7, STR_0196_SHOW_LAND_OWNERS_ON_MAP}, darkvater@176: { WWT_IMGBTN, 13, 585, 606, 430, 451, 0xFED, STR_0197_TOGGLE_TOWN_NAMES_ON_OFF}, darkvater@176: { WWT_IMGBTN, 13, 0, 518, 408, 451, 0x0, STR_0197_TOGGLE_TOWN_NAMES_ON_OFF}, darkvater@176: { WWT_IMGBTN, 13, 519, 540, 408, 429, 0x0, STR_NULL}, darkvater@176: { WIDGETS_END}, truelight@0: }; truelight@0: truelight@0: static const Widget _smallmap_big_widgets[] = { darkvater@176: { WWT_TEXTBTN, 13, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, truelight@0: { WWT_CAPTION, 13, 11, 431, 0, 13, STR_00B0_MAP,STR_018C_WINDOW_TITLE_DRAG_THIS}, darkvater@176: { WWT_IMGBTN, 13, 432, 445, 0, 13, 0x2AA, STR_01CC_TOGGLE_LARGE_SMALL_MAP}, darkvater@176: { WWT_IMGBTN, 13, 0, 445, 14, 257, 0x0, STR_NULL}, darkvater@176: { WWT_6, 13, 2, 443, 16, 255, 0x0, STR_NULL}, darkvater@176: { WWT_IMGBTN, 13, 380, 401, 258, 279, 0x2E2, STR_0191_SHOW_LAND_CONTOURS_ON_MAP}, darkvater@176: { WWT_IMGBTN, 13, 402, 423, 258, 279, 0x2E3, STR_0192_SHOW_VEHICLES_ON_MAP}, darkvater@176: { WWT_IMGBTN, 13, 424, 445, 258, 279, 0x2E5, STR_0193_SHOW_INDUSTRIES_ON_MAP}, darkvater@176: { WWT_IMGBTN, 13, 380, 401, 280, 301, 0x2E4, STR_0194_SHOW_TRANSPORT_ROUTES_ON}, darkvater@176: { WWT_IMGBTN, 13, 402, 423, 280, 301, 0x2E6, STR_0195_SHOW_VEGETATION_ON_MAP}, darkvater@176: { WWT_IMGBTN, 13, 424, 445, 280, 301, 0x2E7, STR_0196_SHOW_LAND_OWNERS_ON_MAP}, darkvater@176: { WWT_IMGBTN, 13, 358, 379, 280, 301, 0xFED, STR_0197_TOGGLE_TOWN_NAMES_ON_OFF}, darkvater@176: { WWT_IMGBTN, 13, 0, 357, 258, 301, 0x0, STR_0197_TOGGLE_TOWN_NAMES_ON_OFF}, darkvater@176: { WWT_IMGBTN, 13, 358, 379, 258, 279, 0x0, STR_NULL}, darkvater@176: { WIDGETS_END}, truelight@0: }; truelight@0: truelight@0: truelight@0: static const Widget _smallmap_small_widgets[] = { darkvater@176: { WWT_TEXTBTN, 13, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, truelight@0: { WWT_CAPTION, 13, 11, 233, 0, 13, STR_00B0_MAP,STR_018C_WINDOW_TITLE_DRAG_THIS}, darkvater@176: { WWT_IMGBTN, 13, 234, 247, 0, 13, 0x2AA, STR_01CC_TOGGLE_LARGE_SMALL_MAP}, darkvater@176: { WWT_IMGBTN, 13, 0, 225, 14, 167, 0x0, STR_NULL}, darkvater@176: { WWT_6, 13, 2, 223, 16, 165, 0x0, STR_NULL}, darkvater@176: { WWT_IMGBTN, 13, 226, 247, 14, 35, 0x2E2, STR_0191_SHOW_LAND_CONTOURS_ON_MAP}, darkvater@176: { WWT_IMGBTN, 13, 226, 247, 36, 57, 0x2E3, STR_0192_SHOW_VEHICLES_ON_MAP}, darkvater@176: { WWT_IMGBTN, 13, 226, 247, 58, 79, 0x2E5, STR_0193_SHOW_INDUSTRIES_ON_MAP}, darkvater@176: { WWT_IMGBTN, 13, 226, 247, 80, 101, 0x2E4, STR_0194_SHOW_TRANSPORT_ROUTES_ON}, darkvater@176: { WWT_IMGBTN, 13, 226, 247, 102, 123, 0x2E6, STR_0195_SHOW_VEGETATION_ON_MAP}, darkvater@176: { WWT_IMGBTN, 13, 226, 247, 124, 145, 0x2E7, STR_0196_SHOW_LAND_OWNERS_ON_MAP}, darkvater@176: { WWT_IMGBTN, 13, 226, 247, 146, 167, 0xFED, STR_0197_TOGGLE_TOWN_NAMES_ON_OFF}, darkvater@176: { WWT_IMGBTN, 13, 0, 247, 168, 211, 0x0, STR_NULL}, darkvater@176: { WIDGETS_END}, truelight@0: }; truelight@0: truelight@0: static int _smallmap_type; truelight@0: static byte _smallmap_size; truelight@0: static bool _smallmap_show_towns = true; truelight@0: truelight@0: static void DoShowSmallMap(int big); truelight@0: truelight@0: #define MK(a,b) a,b truelight@0: #define MKEND() 0xffff truelight@0: #define MS(a,b) (a|0x100),b truelight@0: truelight@0: static const uint16 _legend_land_contours[] = { truelight@0: MK(0x5A,STR_00F0_100M), truelight@0: MK(0x5C,STR_00F1_200M), truelight@0: MK(0x5E,STR_00F2_300M), truelight@0: MK(0x1F,STR_00F3_400M), truelight@0: MK(0x27,STR_00F4_500M), truelight@193: truelight@0: MS(0xD7,STR_00EB_ROADS), truelight@0: MK(0x0A,STR_00EC_RAILROADS), truelight@0: MK(0x98,STR_00ED_STATIONS_AIRPORTS_DOCKS), truelight@0: MK(0xB5,STR_00EE_BUILDINGS_INDUSTRIES), truelight@0: MK(0x0F,STR_00EF_VEHICLES), truelight@0: MKEND() truelight@0: }; truelight@0: truelight@0: static const uint16 _legend_vehicles[] = { truelight@0: MK(0xB8,STR_00F5_TRAINS), truelight@0: MK(0xBF,STR_00F6_ROAD_VEHICLES), truelight@0: MK(0x98,STR_00F7_SHIPS), truelight@0: MK(0x0F,STR_00F8_AIRCRAFT), truelight@0: MS(0xD7,STR_00F9_TRANSPORT_ROUTES), truelight@0: MK(0xB5,STR_00EE_BUILDINGS_INDUSTRIES), truelight@0: MKEND() truelight@0: }; truelight@0: truelight@0: static const uint16 _legend_industries_normal[] = { truelight@0: MK(0xD7,STR_00FA_COAL_MINE), truelight@0: MK(0xB8,STR_00FB_POWER_STATION), truelight@0: MK(0x56,STR_00FC_FOREST), truelight@0: MK(0xC2,STR_00FD_SAWMILL), truelight@0: MK(0xBF,STR_00FE_OIL_REFINERY), truelight@0: MK(0x0F,STR_0105_BANK), truelight@0: truelight@0: MS(0x30,STR_00FF_FARM), truelight@0: MK(0xAE,STR_0100_FACTORY), truelight@0: MK(0x98,STR_0102_OIL_WELLS), truelight@0: MK(0x37,STR_0103_IRON_ORE_MINE), truelight@0: MK(0x0A,STR_0104_STEEL_MILL), truelight@0: MKEND() truelight@0: }; truelight@0: truelight@0: static const uint16 _legend_industries_hilly[] = { truelight@0: MK(0xD7,STR_00FA_COAL_MINE), truelight@0: MK(0xB8,STR_00FB_POWER_STATION), truelight@0: MK(0x56,STR_00FC_FOREST), truelight@0: MK(0x0A,STR_0106_PAPER_MILL), truelight@0: MK(0xBF,STR_00FE_OIL_REFINERY), truelight@0: MK(0x37,STR_0108_FOOD_PROCESSING_PLANT), truelight@0: MS(0x30,STR_00FF_FARM), truelight@0: truelight@0: MK(0xAE,STR_0101_PRINTING_WORKS), truelight@0: MK(0x98,STR_0102_OIL_WELLS), truelight@0: MK(0xC2,STR_0107_GOLD_MINE), truelight@0: MK(0x0F,STR_0105_BANK), truelight@0: MKEND() truelight@0: }; truelight@0: truelight@0: static const uint16 _legend_industries_desert[] = { truelight@0: MK(0xBF,STR_00FE_OIL_REFINERY), truelight@0: MK(0x98,STR_0102_OIL_WELLS), truelight@0: MK(0x0F,STR_0105_BANK), truelight@0: MK(0xB8,STR_0109_DIAMOND_MINE), truelight@0: MK(0x37,STR_0108_FOOD_PROCESSING_PLANT), truelight@0: MK(0x0A,STR_010A_COPPER_ORE_MINE), truelight@0: MK(0x30,STR_00FF_FARM), truelight@0: MS(0x56,STR_010B_FRUIT_PLANTATION), truelight@0: truelight@0: MK(0x27,STR_010C_RUBBER_PLANTATION), truelight@0: MK(0x25,STR_010D_WATER_SUPPLY), truelight@0: MK(0xD0,STR_010E_WATER_TOWER), truelight@0: MK(0xAE,STR_0100_FACTORY), truelight@0: MK(0xC2,STR_010F_LUMBER_MILL), truelight@0: MKEND() truelight@0: }; truelight@0: truelight@0: static const uint16 _legend_industries_candy[] = { truelight@0: MK(0x30,STR_0110_COTTON_CANDY_FOREST), truelight@0: MK(0xAE,STR_0111_CANDY_FACTORY), truelight@0: MK(0x27,STR_0112_BATTERY_FARM), truelight@0: MK(0x37,STR_0113_COLA_WELLS), truelight@0: MK(0xD0,STR_0114_TOY_SHOP), truelight@0: MK(0x0A,STR_0115_TOY_FACTORY), truelight@0: MS(0x25,STR_0116_PLASTIC_FOUNTAINS), truelight@0: truelight@0: MK(0xB8,STR_0117_FIZZY_DRINK_FACTORY), truelight@0: MK(0x98,STR_0118_BUBBLE_GENERATOR), truelight@0: MK(0xC2,STR_0119_TOFFEE_QUARRY), truelight@0: MK(0x0F,STR_011A_SUGAR_MINE), truelight@0: MKEND() truelight@0: }; truelight@0: truelight@0: static const uint16 _legend_routes[] = { truelight@0: MK(0xD7,STR_00EB_ROADS), truelight@0: MK(0x0A,STR_00EC_RAILROADS), truelight@0: MK(0xB5,STR_00EE_BUILDINGS_INDUSTRIES), truelight@0: MS(0x56,STR_011B_RAILROAD_STATION), truelight@0: truelight@0: MK(0xC2,STR_011C_TRUCK_LOADING_BAY), truelight@0: MK(0xBF,STR_011D_BUS_STATION), truelight@0: MK(0xB8,STR_011E_AIRPORT_HELIPORT), truelight@0: MK(0x98,STR_011F_DOCK), truelight@0: MKEND() truelight@0: }; truelight@0: truelight@0: static const uint16 _legend_vegetation[] = { truelight@0: MK(0x52,STR_0120_ROUGH_LAND), truelight@0: MK(0x54,STR_0121_GRASS_LAND), truelight@0: MK(0x37,STR_0122_BARE_LAND), truelight@0: MK(0x25,STR_0123_FIELDS), truelight@0: MK(0x57,STR_0124_TREES), truelight@0: MK(0xD0,STR_00FC_FOREST), truelight@0: MS(0x0A,STR_0125_ROCKS), truelight@0: truelight@0: MK(0xC2,STR_012A_DESERT), truelight@0: MK(0x98,STR_012B_SNOW), truelight@0: MK(0xD7,STR_00F9_TRANSPORT_ROUTES), truelight@0: MK(0xB5,STR_00EE_BUILDINGS_INDUSTRIES), truelight@0: MKEND() truelight@0: }; truelight@0: truelight@0: static const uint16 _legend_land_owners[] = { truelight@0: MK(0xCA,STR_0126_WATER), truelight@0: MK(0x54,STR_0127_NO_OWNER), truelight@0: MK(0xB4,STR_0128_TOWNS), truelight@0: MK(0x20,STR_0129_INDUSTRIES), truelight@0: MKEND() truelight@0: }; truelight@0: #undef MK truelight@0: #undef MS truelight@0: #undef MKEND truelight@0: truelight@0: truelight@0: enum { IND_OFFS = 6 }; truelight@0: static const uint16 * const _legend_table[] = { truelight@0: _legend_land_contours, truelight@0: _legend_vehicles, truelight@0: NULL, truelight@0: _legend_routes, truelight@0: _legend_vegetation, truelight@0: _legend_land_owners, truelight@0: truelight@0: _legend_industries_normal, truelight@0: _legend_industries_hilly, truelight@0: _legend_industries_desert, truelight@0: _legend_industries_candy, truelight@0: }; truelight@0: truelight@0: #if defined(TTD_ALIGNMENT_4) tron@500: static inline void WRITE_PIXELS(void *dst, uint32 val) truelight@0: { truelight@0: byte *d = (byte*)dst; truelight@0: # if defined(TTD_BIG_ENDIAN) truelight@0: d[0] = (byte)(val >> 24); truelight@0: d[1] = (byte)(val >> 16); truelight@0: d[2] = (byte)(val >> 8); truelight@0: d[3] = (byte)(val >> 0); truelight@0: # elif defined(TTD_LITTLE_ENDIAN) truelight@0: d[0] = (byte)(val >> 0); truelight@0: d[1] = (byte)(val >> 8); truelight@0: d[2] = (byte)(val >> 16); truelight@0: d[3] = (byte)(val >> 24); truelight@0: # endif truelight@0: } truelight@0: truelight@0: /* need to use OR, otherwise we will overwrite the wrong pixels at the edges :( */ tron@500: static inline void WRITE_PIXELS_OR(void *dst, uint32 val) truelight@0: { truelight@0: byte *d = (byte*)dst; truelight@0: # if defined(TTD_BIG_ENDIAN) truelight@0: d[0] |= (byte)(val >> 24); truelight@0: d[1] |= (byte)(val >> 16); truelight@0: d[2] |= (byte)(val >> 8); truelight@0: d[3] |= (byte)(val >> 0); truelight@0: # elif defined(TTD_LITTLE_ENDIAN) truelight@0: d[0] |= (byte)(val >> 0); truelight@0: d[1] |= (byte)(val >> 8); truelight@0: d[2] |= (byte)(val >> 16); truelight@0: d[3] |= (byte)(val >> 24); truelight@0: # endif truelight@0: } truelight@0: #else truelight@0: # define WRITE_PIXELS(dst, val) *(uint32*)(dst) = (val); truelight@0: # define WRITE_PIXELS_OR(dst,val) *(uint32*)(dst) |= (val); truelight@0: #endif truelight@0: truelight@0: #if defined(TTD_BIG_ENDIAN) truelight@0: # define MKCOLOR(x) BSWAP32(x) truelight@0: #elif defined(TTD_LITTLE_ENDIAN) truelight@0: # define MKCOLOR(x) (x) truelight@0: #endif truelight@0: truelight@0: static const uint32 _map_height_bits[16] = { 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@0: truelight@0: static const uint32 _smallmap_contours_andor[12][2] = { truelight@0: {MKCOLOR(0x00000000),MKCOLOR(0xFFFFFFFF)}, truelight@0: {MKCOLOR(0x000A0A00),MKCOLOR(0xFF0000FF)}, truelight@0: {MKCOLOR(0x00D7D700),MKCOLOR(0xFF0000FF)}, truelight@0: {MKCOLOR(0x00B5B500),MKCOLOR(0xFF0000FF)}, truelight@0: {MKCOLOR(0x00000000),MKCOLOR(0xFFFFFFFF)}, truelight@0: {MKCOLOR(0x98989898),MKCOLOR(0x00000000)}, truelight@0: {MKCOLOR(0xCACACACA),MKCOLOR(0x00000000)}, truelight@0: {MKCOLOR(0x00000000),MKCOLOR(0xFFFFFFFF)}, truelight@0: {MKCOLOR(0xB5B5B5B5),MKCOLOR(0x00000000)}, truelight@0: {MKCOLOR(0x00000000),MKCOLOR(0xFFFFFFFF)}, truelight@0: {MKCOLOR(0x00B5B500),MKCOLOR(0xFF0000FF)}, truelight@0: {MKCOLOR(0x000A0A00),MKCOLOR(0xFF0000FF)}, truelight@0: }; truelight@0: truelight@0: static const uint32 _smallmap_vehicles_andor[12][2] = { truelight@0: {MKCOLOR(0x00000000),MKCOLOR(0xFFFFFFFF)}, truelight@0: {MKCOLOR(0x00D7D700),MKCOLOR(0xFF0000FF)}, truelight@0: {MKCOLOR(0x00D7D700),MKCOLOR(0xFF0000FF)}, truelight@0: {MKCOLOR(0x00B5B500),MKCOLOR(0xFF0000FF)}, truelight@0: {MKCOLOR(0x00000000),MKCOLOR(0xFFFFFFFF)}, truelight@0: {MKCOLOR(0x00D7D700),MKCOLOR(0xFF0000FF)}, truelight@0: {MKCOLOR(0xCACACACA),MKCOLOR(0x00000000)}, truelight@0: {MKCOLOR(0x00000000),MKCOLOR(0xFFFFFFFF)}, truelight@0: {MKCOLOR(0xB5B5B5B5),MKCOLOR(0x00000000)}, truelight@0: {MKCOLOR(0x00000000),MKCOLOR(0xFFFFFFFF)}, truelight@0: {MKCOLOR(0x00B5B500),MKCOLOR(0xFF0000FF)}, truelight@0: {MKCOLOR(0x00D7D700),MKCOLOR(0xFF0000FF)}, truelight@0: }; truelight@0: truelight@0: static const uint32 _smallmap_vegetation_andor[12][2] = { truelight@0: {MKCOLOR(0x00000000),MKCOLOR(0xFFFFFFFF)}, truelight@0: {MKCOLOR(0x00D7D700),MKCOLOR(0xFF0000FF)}, truelight@0: {MKCOLOR(0x00D7D700),MKCOLOR(0xFF0000FF)}, truelight@0: {MKCOLOR(0x00B5B500),MKCOLOR(0xFF0000FF)}, truelight@0: {MKCOLOR(0x00575700),MKCOLOR(0xFF0000FF)}, truelight@0: {MKCOLOR(0x00D7D700),MKCOLOR(0xFF0000FF)}, truelight@0: {MKCOLOR(0xCACACACA),MKCOLOR(0x00000000)}, truelight@0: {MKCOLOR(0x00000000),MKCOLOR(0xFFFFFFFF)}, truelight@0: {MKCOLOR(0xB5B5B5B5),MKCOLOR(0x00000000)}, truelight@0: {MKCOLOR(0x00000000),MKCOLOR(0xFFFFFFFF)}, truelight@0: {MKCOLOR(0x00B5B500),MKCOLOR(0xFF0000FF)}, truelight@0: {MKCOLOR(0x00D7D700),MKCOLOR(0xFF0000FF)}, truelight@0: }; truelight@0: tron@500: static inline uint32 GetSmallMapCountoursPixels(uint tile) truelight@0: { truelight@0: uint t; truelight@0: truelight@0: t = GET_TILETYPE(tile); truelight@0: if (t == MP_TUNNELBRIDGE) { truelight@0: t = _map5[tile]; truelight@0: if ((t & 0x80) == 0) t>>=1; truelight@0: if ((t & 6) == 0) { truelight@0: t = MP_RAILWAY; truelight@0: } else if ((t & 6) == 2) { truelight@0: t = MP_STREET; truelight@0: } else { truelight@0: t = MP_WATER; truelight@0: } truelight@0: } truelight@0: truelight@0: return (_map_height_bits[_map_type_and_height[tile] & 0xF] & _smallmap_contours_andor[t][1]) | _smallmap_contours_andor[t][0]; truelight@0: } truelight@0: truelight@0: static void DrawSmallMapContours(byte *dst, uint xc, uint yc, int pitch, int reps, uint32 mask) truelight@0: { truelight@0: do { truelight@0: if (xc < TILE_X_MAX && yc < TILE_Y_MAX) truelight@12: if (dst > _screen.dst_ptr && dst < (_screen.dst_ptr + _screen.width * _screen.height - _screen.width) ) truelight@12: WRITE_PIXELS_OR( dst, GetSmallMapCountoursPixels(TILE_XY(xc,yc)) & mask ); truelight@0: } while (xc++,yc++,dst+=pitch,--reps != 0); truelight@0: } truelight@0: truelight@0: tron@500: static inline uint32 GetSmallMapVehiclesPixels(uint tile) truelight@0: { truelight@0: uint t; truelight@0: truelight@0: t = GET_TILETYPE(tile); truelight@0: if (t == MP_TUNNELBRIDGE) { truelight@0: t = _map5[tile]; truelight@0: if ((t & 0x80) == 0) t>>=1; truelight@0: if ((t & 6) == 0) { truelight@0: t = MP_RAILWAY; truelight@0: } else if ((t & 6) == 2) { truelight@0: t = MP_STREET; truelight@0: } else { truelight@0: t = MP_WATER; truelight@0: } truelight@0: } truelight@0: return (MKCOLOR(0x54545454) & _smallmap_vehicles_andor[t][1]) | _smallmap_vehicles_andor[t][0]; truelight@0: } truelight@0: truelight@0: truelight@0: static void DrawSmallMapVehicles(byte *dst, uint xc, uint yc, int pitch, int reps, uint32 mask) truelight@0: { truelight@0: do { truelight@0: if (xc < TILE_X_MAX && yc < TILE_Y_MAX) truelight@0: WRITE_PIXELS_OR( dst, GetSmallMapVehiclesPixels(TILE_XY(xc,yc)) & mask ); truelight@0: } while (xc++,yc++,dst+=pitch,--reps != 0); truelight@0: } truelight@0: truelight@0: static const byte _industry_smallmap_colors[175] = { truelight@0: 215,215,215,215,215,215,215,184, truelight@0: 184,184,184,194,194,194,194,194, truelight@0: 86, 86,191,191,191,191,191,191, truelight@0: 152,152,152,152,152,152,152,152, truelight@0: 152, 48, 48, 48, 48, 48, 48,174, truelight@0: 174,174,174,174,174,174,174, 10, truelight@0: 10, 10, 10, 10, 10, 10, 10, 10, truelight@0: 10, 10, 15, 15, 55, 55, 55, 55, truelight@0: 10, 10, 10, 10, 10, 10, 10, 10, truelight@0: 194,194,194,194,194,194,194,194, truelight@0: 194,194,194,194,194,194,194,194, truelight@0: 194, 15, 15,184,184,184,184,184, truelight@0: 184,184,184,184, 55, 55, 55, 55, truelight@0: 55, 55, 55, 55, 55, 55, 55, 55, truelight@0: 55, 55, 55, 55, 86, 39, 37, 37, truelight@0: 208,174,174,174,174,194,194,194, truelight@0: 194, 48, 48,174,174,174,174, 39, truelight@0: 39, 55,208,208,208,208, 10, 10, truelight@0: 10, 10, 10, 10, 37, 37, 37, 37, truelight@0: 37, 37, 37, 37,184,184,184,184, truelight@0: 152,152,152,152,194,194,194, 15, truelight@0: 15, 15, 15, 15, 15, 15, 15, truelight@0: }; truelight@0: tron@500: static inline uint32 GetSmallMapIndustriesPixels(uint tile) truelight@0: { truelight@0: int t; truelight@0: truelight@0: t = GET_TILETYPE(tile); truelight@0: if (t == MP_INDUSTRY) { truelight@0: byte color = _industry_smallmap_colors[_map5[tile]]; truelight@0: return color + (color << 8) + (color << 16) + (color << 24); truelight@0: } else { truelight@0: if (t == MP_TUNNELBRIDGE) { truelight@0: t = _map5[tile]; truelight@0: if ((t & 0x80) == 0) t>>=1; truelight@0: if ((t & 6) == 0) { truelight@0: t = MP_RAILWAY; truelight@0: } else if ((t & 6) == 2) { truelight@0: t = MP_STREET; truelight@0: } else { truelight@0: t = MP_WATER; truelight@0: } truelight@0: } truelight@0: return ((MKCOLOR(0x54545454) & _smallmap_vehicles_andor[t][1]) | _smallmap_vehicles_andor[t][0]); truelight@0: } truelight@0: } truelight@0: truelight@0: static void DrawSmallMapIndustries(byte *dst, uint xc, uint yc, int pitch, int reps, uint32 mask) truelight@0: { truelight@0: do { truelight@0: if (xc < TILE_X_MAX && yc < TILE_Y_MAX) truelight@0: WRITE_PIXELS_OR(dst, GetSmallMapIndustriesPixels(TILE_XY(xc,yc)) & mask); truelight@0: } while (xc++,yc++,dst+=pitch,--reps != 0); truelight@0: } truelight@0: tron@500: static inline uint32 GetSmallMapRoutesPixels(uint tile) truelight@0: { truelight@0: int t; truelight@0: uint32 bits; truelight@0: truelight@0: t = GET_TILETYPE(tile); truelight@0: if (t == MP_STATION) { truelight@0: byte m5 = _map5[tile]; truelight@0: (bits = MKCOLOR(0x56565656), m5 < 8) || // 8 - railroad station (green) truelight@0: (bits = MKCOLOR(0xB8B8B8B8), m5 < 0x43) || // 67 - airport (red) truelight@0: (bits = MKCOLOR(0xC2C2C2C2), m5 < 0x47) || // 71 - truck loading bay (orange) truelight@0: (bits = MKCOLOR(0xBFBFBFBF), m5 < 0x4B) || // 75 - bus station (yellow) truelight@0: (bits = MKCOLOR(0x98989898), m5 < 0x53) || // 83 - docks (blue) truelight@0: (bits = MKCOLOR(0xB8B8B8B8), m5 < 0x73) || // 115 - airport (red) (new airports) truelight@0: (bits = MKCOLOR(0xFFFFFFFF), true); // all others truelight@0: } else { truelight@0: if (t == MP_TUNNELBRIDGE) { truelight@0: t = _map5[tile]; truelight@0: if ((t & 0x80) == 0) t>>=1; truelight@0: if ((t & 6) == 0) { truelight@0: t = MP_RAILWAY; truelight@0: } else if ((t & 6) == 2) { truelight@0: t = MP_STREET; truelight@0: } else { truelight@0: t = MP_WATER; truelight@0: } truelight@0: } truelight@0: // ground color truelight@0: bits = ((MKCOLOR(0x54545454) & _smallmap_contours_andor[t][1]) | _smallmap_contours_andor[t][0]); truelight@0: } truelight@0: return bits; truelight@0: } truelight@0: truelight@0: static void DrawSmallMapRoutes(byte *dst, uint xc, uint yc, int pitch, int reps, uint32 mask) truelight@0: { truelight@0: do { truelight@0: if (xc < TILE_X_MAX && yc < TILE_Y_MAX) truelight@0: WRITE_PIXELS_OR(dst, GetSmallMapRoutesPixels(TILE_XY(xc,yc)) & mask); truelight@0: } while (xc++,yc++,dst+=pitch,--reps != 0); truelight@0: } truelight@0: truelight@0: static const uint32 _vegetation_clear_bits[4 + 7] = { truelight@0: MKCOLOR(0x37373737), truelight@0: MKCOLOR(0x37373737), truelight@0: MKCOLOR(0x37373737), truelight@0: MKCOLOR(0x54545454), truelight@0: truelight@0: MKCOLOR(0x52525252), truelight@0: MKCOLOR(0x0A0A0A0A), truelight@0: MKCOLOR(0x25252525), truelight@0: MKCOLOR(0x98989898), truelight@0: MKCOLOR(0xC2C2C2C2), truelight@0: MKCOLOR(0x54545454), truelight@0: MKCOLOR(0x54545454), truelight@0: }; truelight@0: tron@500: static inline uint32 GetSmallMapVegetationPixels(uint tile) truelight@0: { truelight@0: int i,t; truelight@0: uint32 bits; truelight@0: truelight@0: t = GET_TILETYPE(tile); truelight@0: if (t == MP_CLEAR) { truelight@0: i = (_map5[tile] & 0x1F) - 4; truelight@0: if (i >= 0) i = (i >> 2); truelight@0: bits = _vegetation_clear_bits[i + 4]; truelight@0: } else if (t == MP_INDUSTRY) { truelight@193: bits = IS_BYTE_INSIDE(_map5[tile], 0x10, 0x12) ? MKCOLOR(0xD0D0D0D0) : MKCOLOR(0xB5B5B5B5); truelight@0: } else if (t == MP_TREES) { truelight@0: bits = MKCOLOR(0x54575754); truelight@0: if ((_map2[tile] & 0x30) == 0x20) truelight@0: bits = (_opt.landscape == LT_HILLY) ? MKCOLOR(0x98575798) : MKCOLOR(0xC25757C2); truelight@0: } else { truelight@0: if (t == MP_TUNNELBRIDGE) { truelight@0: t = _map5[tile]; truelight@0: if ((t & 0x80) == 0) t>>=1; truelight@0: if ((t & 6) == 0) { truelight@0: t = MP_RAILWAY; truelight@0: } else if ((t & 6) == 2) { truelight@0: t = MP_STREET; truelight@0: } else { truelight@0: t = MP_WATER; truelight@0: } truelight@0: } truelight@0: bits = ((MKCOLOR(0x54545454) & _smallmap_vehicles_andor[t][1]) | _smallmap_vehicles_andor[t][0]); truelight@0: } truelight@0: truelight@0: return bits; truelight@0: } truelight@0: truelight@0: truelight@0: static void DrawSmallMapVegetation(byte *dst, uint xc, uint yc, int pitch, int reps, uint32 mask) truelight@0: { truelight@0: do { truelight@0: if (xc < TILE_X_MAX && yc < TILE_Y_MAX) truelight@0: WRITE_PIXELS_OR(dst, GetSmallMapVegetationPixels(TILE_XY(xc,yc)) & mask); truelight@0: } while (xc++,yc++,dst+=pitch,--reps != 0); truelight@0: } truelight@0: truelight@0: truelight@0: static uint32 *_owner_colors; truelight@0: tron@500: static inline uint32 GetSmallMapOwnerPixels(uint tile) truelight@0: { truelight@0: int t; truelight@0: truelight@0: t = GET_TILETYPE(tile); truelight@0: if (t == MP_HOUSE || _map_owner[tile] == OWNER_TOWN) { truelight@193: t = 0x80; truelight@0: } else if (t == MP_INDUSTRY) { truelight@0: t = 0xff; truelight@0: } else { truelight@0: t = _map_owner[tile]; truelight@0: } truelight@0: truelight@0: return _owner_colors[t]; truelight@0: } truelight@0: truelight@0: truelight@0: static void DrawSmallMapOwners(byte *dst, uint xc, uint yc, int pitch, int reps, uint32 mask) truelight@0: { truelight@0: do { truelight@0: if (xc < TILE_X_MAX && yc < TILE_Y_MAX) truelight@0: WRITE_PIXELS_OR(dst, GetSmallMapOwnerPixels(TILE_XY(xc,yc)) & mask); truelight@0: } while (xc++,yc++,dst+=pitch,--reps != 0); 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: truelight@0: static const uint32 _smallmap_mask_right[4] = { truelight@0: MKCOLOR(0x00000000), 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: truelight@0: typedef void SmallmapDrawProc(byte *dst, uint xc, uint yc, int pitch, int reps, uint32 mask); truelight@0: truelight@0: static SmallmapDrawProc *_smallmap_draw_procs[] = { truelight@0: DrawSmallMapContours, truelight@0: DrawSmallMapVehicles, truelight@0: DrawSmallMapIndustries, truelight@0: DrawSmallMapRoutes, truelight@0: DrawSmallMapVegetation, truelight@0: DrawSmallMapOwners, 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: tron@500: static inline uint32 dup_byte32(byte b) { truelight@0: return b + (b << 8) + (b << 16) + (b << 24); truelight@0: } truelight@0: truelight@0: static void DrawVertMapIndicator(int x, int y, int x2, int y2) truelight@0: { truelight@0: GfxFillRect(x, y, x2, y + 3, 69); truelight@0: 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: { truelight@0: GfxFillRect(x, y, x + 3, y2, 69); truelight@0: GfxFillRect(x2 - 3, y, x2, y2, 69); truelight@0: } truelight@0: truelight@0: static void DrawSmallMap(DrawPixelInfo *dpi, Window *w, int type, bool show_towns) truelight@0: { truelight@0: DrawPixelInfo *old_dpi; truelight@0: int dx,dy, x, y, x2, y2; truelight@0: byte *ptr; truelight@0: uint tile_x, tile_y; truelight@0: uint32 mask; truelight@0: int t; truelight@0: int reps; truelight@0: SmallmapDrawProc *proc; truelight@0: ViewPort *vp; truelight@0: truelight@0: old_dpi = _cur_dpi; truelight@0: _cur_dpi = dpi; truelight@0: truelight@0: /* clear it */ truelight@0: GfxFillRect(dpi->left, dpi->top, dpi->left + dpi->width - 1, dpi->top + dpi->height - 1, 0); truelight@0: truelight@0: /* setup owner table */ truelight@0: if (type == 5) { truelight@0: Player *p; truelight@0: uint32 *tbl; truelight@0: truelight@0: /* setup owners ptr */ truelight@0: _owner_colors = tbl = alloca(256 * sizeof(*_owner_colors)); truelight@193: truelight@0: /* clear the town colors */ truelight@0: memset(tbl + 128, 0xB4, 128 * sizeof(*_owner_colors)); truelight@193: truelight@0: /* fill with some special colors */ truelight@0: tbl[0x10] = MKCOLOR(0x54545454); truelight@0: tbl[0x11] = MKCOLOR(0xCACACACA); truelight@0: tbl[0xff] = MKCOLOR(0x20202020); /* industry */ truelight@0: truelight@0: /* now fill with the player colors */ truelight@0: FOR_ALL_PLAYERS(p) { truelight@0: if (p->is_active) { truelight@0: tbl[p->index] = dup_byte32(GetSpritePtr(0x307 + p->player_color)[0xCB]); truelight@0: } truelight@193: } truelight@0: } truelight@0: truelight@0: tile_x = (int)WP(w,smallmap_d).scroll_x >> 4; truelight@0: tile_y = (int)WP(w,smallmap_d).scroll_y >> 4; truelight@0: truelight@0: dx = dpi->left + WP(w,smallmap_d).subscroll; truelight@0: tile_x -= (dx >> 2); truelight@0: tile_y += (dx >> 2); truelight@0: dx &= 3; truelight@0: truelight@0: dy = dpi->top; truelight@0: tile_x += (dy >> 1); truelight@0: tile_y += (dy >> 1); truelight@0: truelight@0: if (dy & 1) { truelight@0: tile_x++; truelight@0: dx += 2; truelight@0: if (dx > 3) { truelight@0: dx -= 4; truelight@0: tile_x--; truelight@0: tile_y++; truelight@0: } truelight@0: } truelight@0: truelight@0: proc = _smallmap_draw_procs[type]; truelight@0: truelight@0: ptr = dpi->dst_ptr - dx - 4; truelight@0: x = - dx - 4; truelight@0: y = 0; truelight@0: truelight@0: for(;;) { truelight@0: mask = (uint32)-1; truelight@0: truelight@0: /* distance from left edge */ truelight@0: if (x < 0) { truelight@0: if (x < -3) goto skip_column; truelight@0: /* mask to use at the left edge */ truelight@0: mask = _smallmap_mask_left[x + 3]; truelight@0: } truelight@0: truelight@0: /* distance from right edge */ truelight@0: t = dpi->width - x; truelight@0: if (t < 4) { truelight@0: if (t < 0) truelight@0: break; /* exit loop */ truelight@0: /* mask to use at the right edge */ truelight@0: mask &= _smallmap_mask_right[t]; truelight@0: } truelight@0: truelight@0: /* number of lines */ truelight@0: reps = ((dpi->height - y + 1) >> 1); truelight@0: if (reps > 0) { truelight@0: // assert(ptr >= dpi->dst_ptr); truelight@0: proc(ptr, tile_x, tile_y, dpi->pitch*2, reps, mask); truelight@0: } truelight@0: truelight@193: skip_column: truelight@0: if (y == 0) { truelight@0: tile_y++; truelight@0: y++; truelight@0: ptr += dpi->pitch; truelight@0: } else { truelight@0: tile_x--; truelight@0: y--; truelight@0: ptr -= dpi->pitch; truelight@0: } truelight@0: ptr += 2; truelight@0: x += 2; truelight@0: } truelight@0: truelight@0: /* draw vehicles? */ truelight@0: if (type == 0 || type == 1) { truelight@0: Vehicle *v; truelight@0: bool skip; truelight@0: byte color; truelight@0: truelight@0: FOR_ALL_VEHICLES(v) { truelight@0: if (v->type != 0 && v->type != 0x14 && (v->vehstatus & (VS_HIDDEN|VS_UNCLICKABLE)) == 0) { truelight@0: // Remap into flat coordinates. truelight@0: Point pt = RemapCoords( truelight@193: (int)(v->x_pos - WP(w,smallmap_d).scroll_x) >> 4, truelight@0: (int)(v->y_pos - WP(w,smallmap_d).scroll_y) >> 4, truelight@0: 0); truelight@0: x = pt.x; truelight@0: y = pt.y; truelight@0: truelight@0: // Check if y is out of bounds? truelight@0: y -= dpi->top; truelight@0: if ((uint)y >= (uint)dpi->height) truelight@0: continue; truelight@0: truelight@0: // Default is to draw both pixels. truelight@0: skip = false; truelight@0: truelight@0: // Offset X coordinate truelight@0: x -= WP(w,smallmap_d).subscroll + 3 + dpi->left; truelight@0: truelight@0: if (x < 0) { truelight@0: // if x+1 is 0, that means we're on the very left edge, truelight@0: // and should thus only draw a single pixel truelight@0: if (++x != 0) truelight@0: continue; truelight@0: skip = true; truelight@0: } else if (x >= dpi->width - 1) { truelight@0: // Check if we're at the very right edge, and if so draw only a single pixel truelight@0: if (x != dpi->width - 1) truelight@0: continue; truelight@0: skip = true; truelight@0: } truelight@193: truelight@0: // Calculate pointer to pixel and the color truelight@0: ptr = dpi->dst_ptr + y * dpi->pitch + x; truelight@0: color = (type == 1) ? _vehicle_type_colors[v->type-0x10] : 0xF; truelight@193: truelight@0: // And draw either one or two pixels depending on clipping truelight@0: ptr[0] = color; truelight@0: if (!skip) truelight@0: ptr[1] = color; truelight@0: } truelight@0: } truelight@0: } truelight@0: truelight@0: if (show_towns) { truelight@0: Town *t; truelight@0: FOR_ALL_TOWNS(t) { truelight@0: if (t->xy != 0) { truelight@0: // Remap the town coordinate truelight@0: Point pt = RemapCoords( truelight@0: (int)(GET_TILE_X(t->xy)*16 - WP(w,smallmap_d).scroll_x) >> 4, truelight@0: (int)(GET_TILE_Y(t->xy)*16 - WP(w,smallmap_d).scroll_y) >> 4, truelight@0: 0); truelight@0: x = pt.x - WP(w,smallmap_d).subscroll + 3 - (t->sign.width_2 >> 1); truelight@0: y = pt.y; truelight@193: truelight@0: // Check if the town sign is within bounds truelight@0: if (x + t->sign.width_2 > dpi->left && truelight@0: x < dpi->left + dpi->width && truelight@193: y + 6 > dpi->top && truelight@0: y < dpi->top + dpi->height) { truelight@0: // And draw it. tron@534: SetDParam(0, t->index); truelight@0: DrawString(x, y, STR_2056, 12); truelight@0: } truelight@0: } truelight@0: } truelight@193: } truelight@0: truelight@0: // Draw map indicators truelight@0: { truelight@0: Point pt; truelight@0: truelight@0: // Find main viewport. truelight@0: vp = FindWindowById(WC_MAIN_WINDOW,0)->viewport; truelight@193: truelight@0: pt = RemapCoords( truelight@0: WP(w,smallmap_d).scroll_x, truelight@0: WP(w,smallmap_d).scroll_y, truelight@0: 0); truelight@0: truelight@0: x = vp->virtual_left - pt.x; truelight@0: y = vp->virtual_top - pt.y; truelight@0: x2 = (x + vp->virtual_width) >> 4; truelight@0: y2 = (y + vp->virtual_height) >> 4; truelight@0: x >>= 4; truelight@0: y >>= 4; truelight@0: truelight@0: x -= WP(w,smallmap_d).subscroll; truelight@0: x2 -= WP(w,smallmap_d).subscroll; truelight@0: truelight@0: DrawVertMapIndicator(x, y, x, y2); truelight@0: DrawVertMapIndicator(x2, y, x2, y2); truelight@0: truelight@0: DrawHorizMapIndicator(x, y, x2, y); truelight@0: DrawHorizMapIndicator(x, y2, x2, y2); truelight@0: } truelight@0: _cur_dpi = old_dpi; truelight@0: } truelight@0: truelight@0: static void SmallMapWindowProc(Window *w, WindowEvent *e) truelight@0: { truelight@0: switch(e->event) { truelight@0: case WE_PAINT: { truelight@0: const uint16 *tbl; truelight@0: int x,y,y_org; truelight@0: DrawPixelInfo new_dpi; truelight@0: truelight@0: truelight@0: /* draw the window */ tron@534: SetDParam(0, STR_00E5_CONTOURS + _smallmap_type); truelight@0: DrawWindowWidgets(w); truelight@193: truelight@0: /* draw the legend */ truelight@0: tbl = _legend_table[(_smallmap_type != 2) ? _smallmap_type : (_opt.landscape + IND_OFFS)]; truelight@0: x = 4; truelight@0: y_org = w->height - 43; truelight@0: y = y_org; truelight@0: while(1) { truelight@0: GfxFillRect(x, y+1, x+8, y + 5, 0); truelight@0: GfxFillRect(x+1, y+2, x+7, y + 4, (byte)tbl[0]); truelight@0: DrawString(x+11, y, tbl[1], 0); truelight@0: truelight@0: tbl += 2; truelight@0: y += 6; truelight@0: truelight@0: if (tbl[0] == 0xFFFF) { truelight@0: break; truelight@0: } else if (tbl[0] & 0x100) { truelight@0: x += 123; truelight@0: y = y_org; truelight@0: } truelight@0: } truelight@0: truelight@0: if (!FillDrawPixelInfo(&new_dpi, NULL, 3, 17, w->width - 28 + (w->widget == _smallmap_small_widgets ? 0 : 22), w->height - 64)) truelight@0: return; truelight@0: truelight@0: DrawSmallMap(&new_dpi, w, _smallmap_type, _smallmap_show_towns); truelight@0: } break; truelight@0: truelight@0: case WE_CLICK: truelight@0: switch(e->click.widget) { truelight@0: case 2: {/* big/small size */ truelight@193: // const Widget *wi = w->widget; truelight@0: DeleteWindow(w); tron@541: SndPlayFx(SND_15_BEEP); truelight@0: { truelight@0: int i = _smallmap_size + 1; truelight@0: if (i == 3) i = 0; truelight@0: DoShowSmallMap(i); truelight@0: } truelight@0: } break; truelight@0: truelight@0: case 4: {/* main wnd */ truelight@0: Window *w2; truelight@0: Point pt; truelight@0: truelight@0: _left_button_clicked = false; truelight@0: truelight@0: w2 = FindWindowById(WC_MAIN_WINDOW, 0); truelight@0: truelight@0: pt = RemapCoords(WP(w,smallmap_d).scroll_x, WP(w,smallmap_d).scroll_y, 0); truelight@0: WP(w2,vp_d).scrollpos_x = pt.x + ((_cursor.pos.x - w->left + 2) << 4) - (w2->viewport->virtual_width >> 1); truelight@0: WP(w2,vp_d).scrollpos_y = pt.y + ((_cursor.pos.y - w->top - 16) << 4) - (w2->viewport->virtual_height >> 1); truelight@0: } break; truelight@0: truelight@0: case 5: /* show land contours */ truelight@0: case 6: /* show vehicles */ truelight@0: case 7: /* show industries */ truelight@193: case 8: /* show transport routes */ truelight@0: case 9: /* show vegetation */ truelight@0: case 10: /* show land owners */ truelight@0: w->click_state &= ~(1<<5|1<<6|1<<7|1<<8|1<<9|1<<10); truelight@0: w->click_state |= 1 << e->click.widget; truelight@0: _smallmap_type = e->click.widget - 5; truelight@0: truelight@0: SetWindowDirty(w); tron@541: SndPlayFx(SND_15_BEEP); truelight@0: break; truelight@0: truelight@0: case 11: /* toggle town names */ truelight@0: w->click_state ^= (1 << 11); truelight@0: _smallmap_show_towns = (w->click_state >> 11) & 1; truelight@0: SetWindowDirty(w); tron@541: SndPlayFx(SND_15_BEEP); truelight@0: break; truelight@0: } truelight@0: break; truelight@0: truelight@0: case WE_RCLICK: truelight@0: if (e->click.widget == 4) { truelight@0: if (_scrolling_viewport) truelight@0: return; truelight@0: _scrolling_viewport = true; truelight@0: _cursor.delta.x = 0; truelight@0: _cursor.delta.y = 0; truelight@0: } truelight@0: break; truelight@0: truelight@0: case WE_MOUSELOOP: truelight@0: /* update the window every now and then */ truelight@0: if ((++w->vscroll.pos & 0x1F) == 0) truelight@0: SetWindowDirty(w); truelight@0: break; truelight@0: } truelight@0: } truelight@0: truelight@0: static const WindowDesc _smallmap_small_desc = { truelight@0: -1,-1, 248, 212, truelight@0: WC_SMALLMAP,0, truelight@0: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, truelight@0: _smallmap_small_widgets, truelight@0: SmallMapWindowProc truelight@0: }; truelight@0: truelight@0: static const WindowDesc _smallmap_big_desc = { truelight@0: -1,-1, 446, 302, truelight@0: WC_SMALLMAP,0, truelight@0: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, truelight@0: _smallmap_big_widgets, truelight@0: SmallMapWindowProc truelight@0: }; truelight@0: truelight@0: static const WindowDesc _smallmap_megabig_desc = { truelight@0: -1,-1, 607, 452, truelight@0: WC_SMALLMAP,0, truelight@0: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, truelight@0: _smallmap_megabig_widgets, truelight@0: SmallMapWindowProc truelight@0: }; truelight@0: truelight@0: static const WindowDesc * const _smallmap_descs[3] = { truelight@0: &_smallmap_small_desc, truelight@0: &_smallmap_big_desc, truelight@0: &_smallmap_megabig_desc truelight@0: }; truelight@0: truelight@0: static void DoShowSmallMap(int big) truelight@0: { truelight@0: Window *w; truelight@0: ViewPort *vp; truelight@0: int x,y; truelight@0: truelight@0: _smallmap_size = big; truelight@193: truelight@0: w = AllocateWindowDescFront(_smallmap_descs[big], 0); truelight@0: if (w) { truelight@0: w->click_state = (1<<5) << _smallmap_type | _smallmap_show_towns << 11; truelight@0: vp = FindWindowById(WC_MAIN_WINDOW, 0)->viewport; truelight@0: truelight@0: x = (((vp->virtual_width - (big?220*32:110*32)) >> 1) + vp->virtual_left) >> 2; truelight@0: y = ((((vp->virtual_height- (big?120*32:75*32)) >> 1) + vp->virtual_top) >> 1) - 32; truelight@0: WP(w,smallmap_d).scroll_x = (y-x) & ~0xF; truelight@0: WP(w,smallmap_d).scroll_y = (x+y) & ~0xF; truelight@0: WP(w,smallmap_d).subscroll = 0; truelight@0: } truelight@0: } truelight@0: truelight@0: void ShowSmallMap() truelight@0: { truelight@0: DoShowSmallMap(_smallmap_size); truelight@0: } darkvater@152: darkvater@152: /* Extra ViewPort Window Stuff */ darkvater@152: static Widget _extra_view_port_widgets[] = { darkvater@176: { WWT_CLOSEBOX, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, darkvater@682: { WWT_CAPTION, 14, 11, 287, 0, 13, STR_EXTRA_VIEW_PORT_TITLE, STR_018C_WINDOW_TITLE_DRAG_THIS}, darkvater@682: { WWT_STICKYBOX, 14, 288, 299, 0, 13, 0x0, STR_STICKY_BUTTON}, darkvater@176: { WWT_PANEL, 14, 0, 299, 14, 233, 0x0, STR_NULL}, darkvater@176: { WWT_6, 14, 2, 297, 16, 231, 0x0, STR_NULL}, darkvater@176: { WWT_PANEL, 14, 0, 21, 234, 255, 0x2DF, STR_017F_ZOOM_THE_VIEW_IN}, darkvater@176: { WWT_PANEL, 14, 22, 43, 234, 255, 0x2E0, STR_0180_ZOOM_THE_VIEW_OUT}, darkvater@176: { WWT_PUSHTXTBTN, 14, 44, 171, 234, 255, STR_EXTRA_VIEW_MOVE_MAIN_TO_VIEW,STR_EXTRA_VIEW_MOVE_MAIN_TO_VIEW_TT}, darkvater@176: { WWT_PUSHTXTBTN, 14, 172, 299, 234, 255, STR_EXTRA_VIEW_MOVE_VIEW_TO_MAIN,STR_EXTRA_VIEW_MOVE_VIEW_TO_MAIN_TT}, darkvater@176: { WIDGETS_END}, darkvater@152: }; darkvater@152: darkvater@152: static void ExtraViewPortWndProc(Window *w, WindowEvent *e) darkvater@152: { darkvater@152: ViewPort *vp = w->viewport; darkvater@152: darkvater@152: switch(e->event) { darkvater@152: case WE_PAINT: { darkvater@152: // set the number in the title bar tron@534: SetDParam(0, (w->window_number+1)); darkvater@152: darkvater@152: DrawWindowWidgets(w); darkvater@152: DrawWindowViewport(w); darkvater@152: } break; darkvater@152: case WE_CLICK: { darkvater@152: switch(e->click.widget) { darkvater@682: case 5: { /* zoom in */ darkvater@152: DoZoomInOutWindow(ZOOM_IN,w); darkvater@152: } break; darkvater@152: darkvater@682: case 6: { /* zoom out */ darkvater@152: DoZoomInOutWindow(ZOOM_OUT,w); darkvater@152: } break; darkvater@152: darkvater@682: case 7: { /* location button (move main view to same spot as this view) */ darkvater@152: Window * w2 = FindWindowById(WC_MAIN_WINDOW, 0); darkvater@152: int x = WP(w,vp_d).scrollpos_x; // Where is the main looking at darkvater@152: int y = WP(w,vp_d).scrollpos_y; darkvater@152: darkvater@152: // set this view to same location. Based on the center, adjusting for zoom darkvater@152: WP(w2,vp_d).scrollpos_x = x - (w2->viewport->virtual_width - (294 <zoom) )/2; truelight@193: WP(w2,vp_d).scrollpos_y = y - (w2->viewport->virtual_height - (214 << vp->zoom) )/2; darkvater@152: } break; darkvater@682: case 8: { /* inverse location button (move this view to same spot as main view) */ darkvater@152: Window * w2 = FindWindowById(WC_MAIN_WINDOW, 0); darkvater@152: int x = WP(w2,vp_d).scrollpos_x; darkvater@152: int y = WP(w2,vp_d).scrollpos_y; darkvater@152: darkvater@152: WP(w,vp_d).scrollpos_x = x + (w2->viewport->virtual_width - (294 <zoom) )/2; truelight@193: WP(w,vp_d).scrollpos_y = y + (w2->viewport->virtual_height - (214 << vp->zoom) )/2; darkvater@152: } break; truelight@193: } darkvater@152: } break; darkvater@152: } darkvater@152: } darkvater@152: darkvater@152: static const WindowDesc _extra_view_port_desc = { darkvater@152: -1,-1, 300, 256, darkvater@152: WC_EXTRA_VIEW_PORT,0, darkvater@682: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON, darkvater@152: _extra_view_port_widgets, darkvater@152: ExtraViewPortWndProc darkvater@152: }; darkvater@152: darkvater@152: void ShowExtraViewPortWindow() darkvater@152: { darkvater@152: Window *w, *v; darkvater@152: int i = 0; truelight@193: darkvater@152: // find next free window number for extra viewport darkvater@152: while (FindWindowById(WC_EXTRA_VIEW_PORT,i) ) { darkvater@152: i++; darkvater@152: } darkvater@152: darkvater@152: w = AllocateWindowDescFront(&_extra_view_port_desc,i); darkvater@152: if (w) { darkvater@152: int x,y; darkvater@152: // disable zoom in button darkvater@152: w->disabled_state = 1 << 4; darkvater@152: // the main window with the main view truelight@193: v = FindWindowById(WC_MAIN_WINDOW, 0); truelight@193: // New viewport start ats (zero,zero) darkvater@152: AssignWindowViewport(w, 3, 17, 294, 214, 0 , 0); darkvater@152: darkvater@152: // center on same place as main window (zoom is maximum, no adjustment needed) darkvater@152: x = WP(v,vp_d).scrollpos_x; darkvater@152: y = WP(v,vp_d).scrollpos_y; darkvater@152: WP(w,vp_d).scrollpos_x = x + (v->viewport->virtual_width - (294) )/2; darkvater@152: WP(w,vp_d).scrollpos_y = y + (v->viewport->virtual_height - (214) )/2; darkvater@152: } darkvater@152: }