Changeset - r6475:29c739f4059e
[Not reviewed]
master
0 1 0
belugas - 18 years ago 2007-04-16 19:44:22
belugas@openttd.org
(svn r9651) -Codechange: make legend system of smallmap a little bit less magic with the help of a struct and not an array of bytes
1 file changed with 35 insertions and 21 deletions:
0 comments (0 inline, 0 general)
src/smallmap_gui.cpp
Show inline comments
 
@@ -46,18 +46,30 @@ static const Widget _smallmap_widgets[] 
 
{  WIDGETS_END},
 
};
 

	
 
static int _smallmap_type;
 
static bool _smallmap_show_towns = true;
 

	
 
#define MK(a,b) a, b
 
#define MKEND() 0xFFFF
 
#define MS(a,b) (a | 0x100), b
 
/** Macro for ordinary entry of LegendAndColor */
 
#define MK(a,b) {a, b, false, false}
 
/** Macro for end of list marker in arrays of LegendAndColor */
 
#define MKEND() {0, STR_NULL, false, true}
 
/** Macro for break marker in arrays of LegendAndColor.
 
 * It will have valid data, though */
 
#define MS(a,b) {a, b, true, false}
 

	
 
/* Legend text giving the colours to look for on the minimap */
 
static const uint16 _legend_land_contours[] = {
 
/** Structure for holding relevant data for legends in small map */
 
struct LegendAndColour {
 
	uint16 colour;     ///< color of the item on the map
 
	StringID legend;   ///< string corresponding to the colored item
 
	bool end;         ///< this is the end of the list
 
	bool col_break;   ///< perform a break and go one collumn further
 
};
 

	
 
/** Legend text giving the colours to look for on the minimap */
 
static const LegendAndColour _legend_land_contours[] = {
 
	MK(0x5A, STR_00F0_100M),
 
	MK(0x5C, STR_00F1_200M),
 
	MK(0x5E, STR_00F2_300M),
 
	MK(0x1F, STR_00F3_400M),
 
	MK(0x27, STR_00F4_500M),
 

	
 
@@ -66,23 +78,23 @@ static const uint16 _legend_land_contour
 
	MK(0x98, STR_00ED_STATIONS_AIRPORTS_DOCKS),
 
	MK(0xB5, STR_00EE_BUILDINGS_INDUSTRIES),
 
	MK(0x0F, STR_00EF_VEHICLES),
 
	MKEND()
 
};
 

	
 
static const uint16 _legend_vehicles[] = {
 
static const LegendAndColour _legend_vehicles[] = {
 
	MK(0xB8, STR_00F5_TRAINS),
 
	MK(0xBF, STR_00F6_ROAD_VEHICLES),
 
	MK(0x98, STR_00F7_SHIPS),
 
	MK(0x0F, STR_00F8_AIRCRAFT),
 
	MS(0xD7, STR_00F9_TRANSPORT_ROUTES),
 
	MK(0xB5, STR_00EE_BUILDINGS_INDUSTRIES),
 
	MKEND()
 
};
 

	
 
static const uint16 _legend_industries_normal[] = {
 
static const LegendAndColour _legend_industries_normal[] = {
 
	MK(0xD7, STR_00FA_COAL_MINE),
 
	MK(0xB8, STR_00FB_POWER_STATION),
 
	MK(0x56, STR_00FC_FOREST),
 
	MK(0xC2, STR_00FD_SAWMILL),
 
	MK(0xBF, STR_00FE_OIL_REFINERY),
 
	MK(0x0F, STR_0105_BANK),
 
@@ -92,13 +104,13 @@ static const uint16 _legend_industries_n
 
	MK(0x98, STR_0102_OIL_WELLS),
 
	MK(0x37, STR_0103_IRON_ORE_MINE),
 
	MK(0x0A, STR_0104_STEEL_MILL),
 
	MKEND()
 
};
 

	
 
static const uint16 _legend_industries_hilly[] = {
 
static const LegendAndColour _legend_industries_hilly[] = {
 
	MK(0xD7, STR_00FA_COAL_MINE),
 
	MK(0xB8, STR_00FB_POWER_STATION),
 
	MK(0x56, STR_00FC_FOREST),
 
	MK(0x0A, STR_0106_PAPER_MILL),
 
	MK(0xBF, STR_00FE_OIL_REFINERY),
 
	MK(0x37, STR_0108_FOOD_PROCESSING_PLANT),
 
@@ -108,13 +120,13 @@ static const uint16 _legend_industries_h
 
	MK(0x98, STR_0102_OIL_WELLS),
 
	MK(0xC2, STR_0107_GOLD_MINE),
 
	MK(0x0F, STR_0105_BANK),
 
	MKEND()
 
};
 

	
 
static const uint16 _legend_industries_desert[] = {
 
static const LegendAndColour _legend_industries_desert[] = {
 
	MK(0xBF, STR_00FE_OIL_REFINERY),
 
	MK(0x98, STR_0102_OIL_WELLS),
 
	MK(0x0F, STR_0105_BANK),
 
	MK(0xB8, STR_0109_DIAMOND_MINE),
 
	MK(0x37, STR_0108_FOOD_PROCESSING_PLANT),
 
	MK(0x0A, STR_010A_COPPER_ORE_MINE),
 
@@ -126,13 +138,13 @@ static const uint16 _legend_industries_d
 
	MK(0xD0, STR_010E_WATER_TOWER),
 
	MK(0xAE, STR_0100_FACTORY),
 
	MK(0xC2, STR_010F_LUMBER_MILL),
 
	MKEND()
 
};
 

	
 
static const uint16 _legend_industries_candy[] = {
 
static const LegendAndColour _legend_industries_candy[] = {
 
	MK(0x30, STR_0110_COTTON_CANDY_FOREST),
 
	MK(0xAE, STR_0111_CANDY_FACTORY),
 
	MK(0x27, STR_0112_BATTERY_FARM),
 
	MK(0x37, STR_0113_COLA_WELLS),
 
	MK(0xD0, STR_0114_TOY_SHOP),
 
	MK(0x0A, STR_0115_TOY_FACTORY),
 
@@ -142,26 +154,26 @@ static const uint16 _legend_industries_c
 
	MK(0x98, STR_0118_BUBBLE_GENERATOR),
 
	MK(0xC2, STR_0119_TOFFEE_QUARRY),
 
	MK(0x0F, STR_011A_SUGAR_MINE),
 
	MKEND()
 
};
 

	
 
static const uint16 _legend_routes[] = {
 
static const LegendAndColour _legend_routes[] = {
 
	MK(0xD7, STR_00EB_ROADS),
 
	MK(0x0A, STR_00EC_RAILROADS),
 
	MK(0xB5, STR_00EE_BUILDINGS_INDUSTRIES),
 
	MS(0x56, STR_011B_RAILROAD_STATION),
 

	
 
	MK(0xC2, STR_011C_TRUCK_LOADING_BAY),
 
	MK(0xBF, STR_011D_BUS_STATION),
 
	MK(0xB8, STR_011E_AIRPORT_HELIPORT),
 
	MK(0x98, STR_011F_DOCK),
 
	MKEND()
 
};
 

	
 
static const uint16 _legend_vegetation[] = {
 
static const LegendAndColour _legend_vegetation[] = {
 
	MK(0x52, STR_0120_ROUGH_LAND),
 
	MK(0x54, STR_0121_GRASS_LAND),
 
	MK(0x37, STR_0122_BARE_LAND),
 
	MK(0x25, STR_0123_FIELDS),
 
	MK(0x57, STR_0124_TREES),
 
	MK(0xD0, STR_00FC_FOREST),
 
@@ -171,26 +183,27 @@ static const uint16 _legend_vegetation[]
 
	MK(0x98, STR_012B_SNOW),
 
	MK(0xD7, STR_00F9_TRANSPORT_ROUTES),
 
	MK(0xB5, STR_00EE_BUILDINGS_INDUSTRIES),
 
	MKEND()
 
};
 

	
 
static const uint16 _legend_land_owners[] = {
 
static const LegendAndColour _legend_land_owners[] = {
 
	MK(0xCA, STR_0126_WATER),
 
	MK(0x54, STR_0127_NO_OWNER),
 
	MK(0xB4, STR_0128_TOWNS),
 
	MK(0x20, STR_0129_INDUSTRIES),
 
	MKEND()
 
};
 
#undef MK
 
#undef MS
 
#undef MKEND
 

	
 

	
 
enum { IND_OFFS = 6 };
 
static const uint16 * const _legend_table[] = {
 
enum { IND_OFFS = 6 };  ///< allow to "jump" to the industries corresponding to the landscape
 

	
 
static const LegendAndColour * const _legend_table[] = {
 
	_legend_land_contours,
 
	_legend_vehicles,
 
	NULL,
 
	_legend_routes,
 
	_legend_vegetation,
 
	_legend_land_owners,
 
@@ -776,13 +789,13 @@ void SmallMapCenterOnCurrentPos(Window *
 
}
 

	
 
static void SmallMapWindowProc(Window *w, WindowEvent *e)
 
{
 
	switch (e->event) {
 
		case WE_PAINT: {
 
			const uint16 *tbl;
 
			LegendAndColour *tbl;
 
			int x, y, y_org;
 
			DrawPixelInfo new_dpi;
 

	
 
			/* draw the window */
 
			SetDParam(0, STR_00E5_CONTOURS + _smallmap_type);
 
			DrawWindowWidgets(w);
 
@@ -791,21 +804,22 @@ static void SmallMapWindowProc(Window *w
 
			tbl = _legend_table[(_smallmap_type != 2) ? _smallmap_type : (_opt.landscape + IND_OFFS)];
 
			x = 4;
 
			y_org = w->height - 44 - 11;
 
			y = y_org;
 
			for (;;) {
 
				GfxFillRect(x,     y + 1, x + 8, y + 5, 0);
 
				GfxFillRect(x + 1, y + 2, x + 7, y + 4, (byte)tbl[0]);
 
				DrawString(x + 11, y, tbl[1], 0);
 
				GfxFillRect(x + 1, y + 2, x + 7, y + 4, tbl->colour);
 
				DrawString(x + 11, y, tbl->legend, 0);
 

	
 
				tbl += 2;
 
				tbl += 1;
 
				y += 6;
 

	
 
				if (tbl[0] == 0xFFFF) {
 
				if (tbl->end) { // end of the list
 
					break;
 
				} else if (tbl[0] & 0x100) {
 
				} else if (tbl->col_break) {
 
					/*  break asked, continue at top, 123 pixels (one "row") to the right */
 
					x += 123;
 
					y = y_org;
 
				}
 
			}
 

	
 
			if (!FillDrawPixelInfo(&new_dpi, 3, 17, w->width - 28 + 22, w->height - 64 - 11))
0 comments (0 inline, 0 general)