Changeset - r17083:ef30d4b1de6b
[Not reviewed]
master
0 1 0
terkhen - 14 years ago 2011-01-17 19:40:06
terkhen@openttd.org
(svn r21830) -Fix: Deunionize a union which was not initialized correctly.
1 file changed with 21 insertions and 23 deletions:
0 comments (0 inline, 0 general)
src/smallmap_gui.cpp
Show inline comments
 
@@ -54,41 +54,39 @@ enum SmallMapWindowWidgets {
 
static int _smallmap_industry_count; ///< Number of used industries
 
static int _smallmap_company_count;  ///< Number of entries in the owner legend.
 

	
 
static const int NUM_NO_COMPANY_ENTRIES = 4; ///< Number of entries in the owner legend that are not companies.
 

	
 
/** Macro for ordinary entry of LegendAndColour */
 
#define MK(a, b) {a, b, {INVALID_INDUSTRYTYPE}, true, false, false}
 
#define MK(a, b) {a, b, INVALID_INDUSTRYTYPE, 0, INVALID_COMPANY, true, false, false}
 

	
 
/** Macro for a height legend entry with configurable colour. */
 
#define MC(height)  {0, STR_TINY_BLACK_HEIGHT, {height}, true, false, false}
 
#define MC(height)  {0, STR_TINY_BLACK_HEIGHT, INVALID_INDUSTRYTYPE, height, INVALID_COMPANY, true, false, false}
 

	
 
/** Macro for non-company owned property entry of LegendAndColour */
 
#define MO(a, b) {a, b, {INVALID_COMPANY}, true, false, false}
 
#define MO(a, b) {a, b, INVALID_INDUSTRYTYPE, 0, INVALID_COMPANY, true, false, false}
 

	
 
/** Macro used for forcing a rebuild of the owner legend the first time it is used. */
 
#define MOEND() {0, 0, {OWNER_NONE}, true, true, false}
 
#define MOEND() {0, 0, INVALID_INDUSTRYTYPE, 0, OWNER_NONE, true, true, false}
 

	
 
/** Macro for end of list marker in arrays of LegendAndColour */
 
#define MKEND() {0, STR_NULL, {INVALID_INDUSTRYTYPE}, true, true, false}
 
#define MKEND() {0, STR_NULL, INVALID_INDUSTRYTYPE, 0, INVALID_COMPANY, true, true, false}
 

	
 
/**
 
 * Macro for break marker in arrays of LegendAndColour.
 
 * It will have valid data, though
 
 */
 
#define MS(a, b) {a, b, {INVALID_INDUSTRYTYPE}, true, false, true}
 
#define MS(a, b) {a, b, INVALID_INDUSTRYTYPE, 0, INVALID_COMPANY, true, false, true}
 

	
 
/** Structure for holding relevant data for legends in small map */
 
struct LegendAndColour {
 
	uint8 colour;              ///< Colour of the item on the map.
 
	StringID legend;           ///< String corresponding to the coloured item.
 
	union {
 
		IndustryType type;     ///< Type of industry.
 
		uint8 height;          ///< Height in tiles.
 
		CompanyID company;     ///< Company to display.
 
	} u;
 
	IndustryType type;         ///< Type of industry. Only valid for industry entries.
 
	uint8 height;              ///< Height in tiles. Only valid for height legend entries.
 
	CompanyID company;         ///< Company to display. Only valid for company entries of the owner legend.
 
	bool show_on_map;          ///< For filtering industries, if \c true, industry is shown on the map in colour.
 
	bool end;                  ///< This is the end of the list.
 
	bool col_break;            ///< Perform a column break and go further at the next column.
 
};
 

	
 
/** Legend text giving the colours to look for on the minimap */
 
@@ -187,13 +185,13 @@ void BuildIndustriesLegend()
 
	for (uint8 i = 0; i < NUM_INDUSTRYTYPES; i++) {
 
		IndustryType ind = _sorted_industry_types[i];
 
		const IndustrySpec *indsp = GetIndustrySpec(ind);
 
		if (indsp->enabled) {
 
			_legend_from_industries[j].legend = indsp->name;
 
			_legend_from_industries[j].colour = indsp->map_colour;
 
			_legend_from_industries[j].u.type = ind;
 
			_legend_from_industries[j].type = ind;
 
			_legend_from_industries[j].show_on_map = true;
 
			_legend_from_industries[j].col_break = false;
 
			_legend_from_industries[j].end = false;
 

	
 
			/* Store widget number for this industry type. */
 
			_industry_to_list_pos[ind] = j;
 
@@ -294,13 +292,13 @@ static const SmallMapColourScheme _heigh
 
	{_violet_map_heights,     MKCOLOUR(0x82828282)}, ///< Violet colour scheme.
 
};
 

	
 
void BuildLandLegend()
 
{
 
	for (LegendAndColour *lc = _legend_land_contours; lc->legend == STR_TINY_BLACK_HEIGHT; lc++) {
 
		lc->colour = _heightmap_schemes[_settings_client.gui.smallmap_land_colour].height_colours[lc->u.height];
 
		lc->colour = _heightmap_schemes[_settings_client.gui.smallmap_land_colour].height_colours[lc->height];
 
	}
 
}
 

	
 
/**
 
 * Completes the array for the owned property legend.
 
 */
 
@@ -309,13 +307,13 @@ void BuildOwnerLegend()
 
	_legend_land_owners[1].colour = _heightmap_schemes[_settings_client.gui.smallmap_land_colour].default_colour;
 

	
 
	int i = NUM_NO_COMPANY_ENTRIES;
 
	const Company *c;
 
	FOR_ALL_COMPANIES(c) {
 
		_legend_land_owners[i].colour = _colour_gradient[c->colour][5];
 
		_legend_land_owners[i].u.company = c->index;
 
		_legend_land_owners[i].company = c->index;
 
		_legend_land_owners[i].show_on_map = true;
 
		_legend_land_owners[i].col_break = false;
 
		_legend_land_owners[i].end = false;
 
		_company_to_list_pos[c->index] = i;
 
		i++;
 
	}
 
@@ -1108,21 +1106,21 @@ public:
 
				StringID str;
 
				if (i == SMT_INDUSTRY) {
 
					SetDParam(0, tbl->legend);
 
					SetDParam(1, IndustryPool::MAX_SIZE);
 
					str = STR_SMALLMAP_INDUSTRY;
 
				} else if (i == SMT_OWNER) {
 
					if (tbl->u.company != INVALID_COMPANY) {
 
						if (!Company::IsValidID(tbl->u.company)) {
 
					if (tbl->company != INVALID_COMPANY) {
 
						if (!Company::IsValidID(tbl->company)) {
 
							/* Rebuild the owner legend. */
 
							BuildOwnerLegend();
 
							this->OnInit();
 
							return;
 
						}
 
						/* Non-fixed legend entries for the owner view. */
 
						SetDParam(0, tbl->u.company);
 
						SetDParam(0, tbl->company);
 
						str = STR_SMALLMAP_COMPANY;
 
					} else {
 
						str = tbl->legend;
 
					}
 
				} else {
 
					if (tbl->col_break) {
 
@@ -1144,13 +1142,13 @@ public:
 
	}
 

	
 
	virtual void OnPaint()
 
	{
 
		if (this->map_type == SMT_OWNER) {
 
			for (const LegendAndColour *tbl = _legend_table[this->map_type]; !tbl->end; ++tbl) {
 
				if (tbl->u.company != INVALID_COMPANY && !Company::IsValidID(tbl->u.company)) {
 
				if (tbl->company != INVALID_COMPANY && !Company::IsValidID(tbl->company)) {
 
					/* Rebuild the owner legend. */
 
					BuildOwnerLegend();
 
					this->InvalidateData(1);
 
					break;
 
				}
 
			}
 
@@ -1194,33 +1192,33 @@ public:
 
					}
 

	
 
					if (this->map_type == SMT_INDUSTRY) {
 
						/* Industry name must be formatted, since it's not in tiny font in the specs.
 
						 * So, draw with a parameter and use the STR_SMALLMAP_INDUSTRY string, which is tiny font */
 
						SetDParam(0, tbl->legend);
 
						SetDParam(1, Industry::GetIndustryTypeCount(tbl->u.type));
 
						SetDParam(1, Industry::GetIndustryTypeCount(tbl->type));
 
						if (!tbl->show_on_map) {
 
							/* Simply draw the string, not the black border of the legend colour.
 
							 * This will enforce the idea of the disabled item */
 
							DrawString(x + text_left, x + text_right, y, STR_SMALLMAP_INDUSTRY, TC_GREY);
 
						} else {
 
							DrawString(x + text_left, x + text_right, y, STR_SMALLMAP_INDUSTRY, TC_BLACK);
 
							GfxFillRect(x + blob_left, y + 1, x + blob_right, y + row_height - 1, 0); // Outer border of the legend colour
 
						}
 
					} else if (this->map_type == SMT_OWNER && tbl->u.company != INVALID_COMPANY) {
 
						SetDParam(0, tbl->u.company);
 
					} else if (this->map_type == SMT_OWNER && tbl->company != INVALID_COMPANY) {
 
						SetDParam(0, tbl->company);
 
						if (!tbl->show_on_map) {
 
							/* Simply draw the string, not the black border of the legend colour.
 
							 * This will enforce the idea of the disabled item */
 
							DrawString(x + text_left, x + text_right, y, STR_SMALLMAP_COMPANY, TC_GREY);
 
						} else {
 
							DrawString(x + text_left, x + text_right, y, STR_SMALLMAP_COMPANY, TC_BLACK);
 
							GfxFillRect(x + blob_left, y + 1, x + blob_right, y + row_height - 1, 0); // Outer border of the legend colour
 
						}
 
					} else {
 
						if (this->map_type == SMT_CONTOUR) SetDParam(0, tbl->u.height * TILE_HEIGHT_STEP);
 
						if (this->map_type == SMT_CONTOUR) SetDParam(0, tbl->height * TILE_HEIGHT_STEP);
 

	
 
						/* Anything that is not an industry or a company is using normal process */
 
						GfxFillRect(x + blob_left, y + 1, x + blob_right, y + row_height - 1, 0);
 
						DrawString(x + text_left, x + text_right, y, tbl->legend);
 
					}
 
					GfxFillRect(x + blob_left + 1, y + 2, x + blob_right - 1, y + row_height - 2, tbl->colour); // Legend colour
 
@@ -1440,13 +1438,13 @@ public:
 

	
 
			case 0: {
 
				extern uint64 _displayed_industries;
 
				if (this->map_type != SMT_INDUSTRY) this->SwitchMapType(SMT_INDUSTRY);
 

	
 
				for (int i = 0; i != _smallmap_industry_count; i++) {
 
					_legend_from_industries[i].show_on_map = HasBit(_displayed_industries, _legend_from_industries[i].u.type);
 
					_legend_from_industries[i].show_on_map = HasBit(_displayed_industries, _legend_from_industries[i].type);
 
				}
 
				break;
 
			}
 

	
 
			default: NOT_REACHED();
 
		}
0 comments (0 inline, 0 general)