From 5912b08890df4b5fd7cb9c532542da275fd9736d Mon Sep 17 00:00:00 2001 From: belugas Date: Thu, 26 Apr 2007 20:20:12 +0000 Subject: [PATCH] (svn r9721) -Codechange: -Codechange: Cleanup of industry_cmd (Step-12). Dynamically build the legends (name and color) for industries in the smallmap_gui. All the tiny fonts industry names should be removed from language files soon. --- src/industry.h | 3 ++ src/newgrf.cpp | 4 ++ src/smallmap_gui.cpp | 113 ++++++++++++++----------------------------- 3 files changed, 44 insertions(+), 76 deletions(-) diff --git a/src/industry.h b/src/industry.h index b0082d164d..aa6321fbb1 100644 --- a/src/industry.h +++ b/src/industry.h @@ -140,6 +140,9 @@ struct IndustryTileSpec { const IndustrySpec *GetIndustrySpec(IndustryType thistype); ///< Array of industries default data const IndustryTileSpec *GetIndustryTileSpec(IndustryGfx gfx); ///< Array of industry tiles default data +/* smallmap_gui.cpp */ +void BuildIndustriesLegend(); + DECLARE_OLD_POOL(Industry, Industry, 3, 8000) /** diff --git a/src/newgrf.cpp b/src/newgrf.cpp index 4954285360..6ee9be4acd 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -38,6 +38,7 @@ #include "helpers.hpp" #include "table/town_land.h" #include "cargotype.h" +#include "industry.h" /* TTDPatch extended GRF format codec * (c) Petr Baudis 2004 (GPL'd) @@ -4769,6 +4770,9 @@ static void AfterLoadGRFs() /* Add all new houses to the house array. */ FinaliseHouseArray(); + /* Create dynamic list of industry legends for smallmap_gui.cpp */ + BuildIndustriesLegend(); + /* Map cargo strings. This is a separate step because cargos are * loaded before strings... */ MapNewCargoStrings(); diff --git a/src/smallmap_gui.cpp b/src/smallmap_gui.cpp index 02a8f5f7cc..7687c9ea4a 100644 --- a/src/smallmap_gui.cpp +++ b/src/smallmap_gui.cpp @@ -91,72 +91,6 @@ static const LegendAndColour _legend_vehicles[] = { MKEND() }; -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), - - MS(0x30, STR_00FF_FARM), - MK(0xAE, STR_0100_FACTORY), - MK(0x98, STR_0102_OIL_WELLS), - MK(0x37, STR_0103_IRON_ORE_MINE), - MK(0x0A, STR_0104_STEEL_MILL), - MKEND() -}; - -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), - MS(0x30, STR_00FF_FARM), - - MK(0xAE, STR_0101_PRINTING_WORKS), - MK(0x98, STR_0102_OIL_WELLS), - MK(0xC2, STR_0107_GOLD_MINE), - MK(0x0F, STR_0105_BANK), - MKEND() -}; - -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), - MK(0x30, STR_00FF_FARM), - MS(0x56, STR_010B_FRUIT_PLANTATION), - - MK(0x27, STR_010C_RUBBER_PLANTATION), - MK(0x25, STR_010D_WATER_SUPPLY), - MK(0xD0, STR_010E_WATER_TOWER), - MK(0xAE, STR_0100_FACTORY), - MK(0xC2, STR_010F_LUMBER_MILL), - MKEND() -}; - -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), - MS(0x25, STR_0116_PLASTIC_FOUNTAINS), - - MK(0xB8, STR_0117_FIZZY_DRINK_FACTORY), - MK(0x98, STR_0118_BUBBLE_GENERATOR), - MK(0xC2, STR_0119_TOFFEE_QUARRY), - MK(0x0F, STR_011A_SUGAR_MINE), - MKEND() -}; - static const LegendAndColour _legend_routes[] = { MK(0xD7, STR_00EB_ROADS), MK(0x0A, STR_00EC_RAILROADS), @@ -197,21 +131,40 @@ static const LegendAndColour _legend_land_owners[] = { #undef MS #undef MKEND +/** Allow room for all industries, plus a terminator entry + * This is required in order to have the indutry slots all filled up */ +static LegendAndColour _legend_from_industries[NUM_INDUSTRYTYPES+1]; -enum { IND_OFFS = 6 }; ///< allow to "jump" to the industries corresponding to the landscape +/** + * Fills an array for the industries legends. + */ +void BuildIndustriesLegend() +{ + const IndustrySpec *indsp; + uint j = 0; + + /* Add each name */ + for (IndustryType i = 0; i < NUM_INDUSTRYTYPES; i++) { + indsp = GetIndustrySpec(i); + if (HASBIT(indsp->climate_availability, _opt.landscape)) { + _legend_from_industries[j].legend = indsp->name; + _legend_from_industries[j].colour = indsp->map_colour; + _legend_from_industries[j].col_break = (j % 6) == 0; // break is performed on the 7th item + _legend_from_industries[j].end = false; + j++; + } + } + /* Terminate the list */ + _legend_from_industries[j].end = true; +} static const LegendAndColour * const _legend_table[] = { _legend_land_contours, _legend_vehicles, - NULL, + _legend_from_industries, _legend_routes, _legend_vegetation, _legend_land_owners, - - _legend_industries_normal, - _legend_industries_hilly, - _legend_industries_desert, - _legend_industries_candy, }; #if defined(OTTD_ALIGNMENT) @@ -800,15 +753,23 @@ static void SmallMapWindowProc(Window *w, WindowEvent *e) SetDParam(0, STR_00E5_CONTOURS + _smallmap_type); DrawWindowWidgets(w); - /* draw the legend */ - tbl = _legend_table[(_smallmap_type != 2) ? _smallmap_type : (_opt.landscape + IND_OFFS)]; + tbl = _legend_table[_smallmap_type]; + 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, tbl->colour); - DrawString(x + 11, y, tbl->legend, 0); + + if (_smallmap_type == 2) { + /* Industry name must be formated, since it's not in tiny font in the specs. + * So, draw with a parameter and use the STR_7065 string, which is tiny, black */ + SetDParam(0, tbl->legend); + DrawString(x + 11, y, STR_7065, 0); + } else { + DrawString(x + 11, y, tbl->legend, 0); + } tbl += 1; y += 6;