diff options
author | michi_cc <michi_cc@openttd.org> | 2012-04-17 19:44:41 +0000 |
---|---|---|
committer | michi_cc <michi_cc@openttd.org> | 2012-04-17 19:44:41 +0000 |
commit | a2b2bc36205868f836fb2599c401cdfd4dfa7c1e (patch) | |
tree | e6d9f2e8c1613a932e4390aaf7b136e92ccb5187 /src | |
parent | 8b65e041ebd4104bba8b21fc0f9a2b8ff99c3414 (diff) | |
download | openttd-a2b2bc36205868f836fb2599c401cdfd4dfa7c1e.tar.xz |
(svn r24141) -Feature: Display rating in the town directory window. (Inspired by patch from MagicBuzz)
Diffstat (limited to 'src')
-rw-r--r-- | src/table/sprites.h | 7 | ||||
-rw-r--r-- | src/town_gui.cpp | 23 |
2 files changed, 27 insertions, 3 deletions
diff --git a/src/table/sprites.h b/src/table/sprites.h index 8320e2c52..db78222b2 100644 --- a/src/table/sprites.h +++ b/src/table/sprites.h @@ -56,7 +56,7 @@ static const SpriteID SPR_LARGE_SMALL_WINDOW = 682; /** Extra graphic spritenumbers */ static const SpriteID SPR_OPENTTD_BASE = 4896; -static const uint16 OPENTTD_SPRITE_COUNT = 162; +static const uint16 OPENTTD_SPRITE_COUNT = 166; /* Halftile-selection sprites */ static const SpriteID SPR_HALFTILE_SELECTION_FLAT = SPR_OPENTTD_BASE; @@ -147,6 +147,11 @@ static const SpriteID SPR_GROUP_REPLACE_OFF_ROADVEH = SPR_OPENTTD_BASE + 131; static const SpriteID SPR_GROUP_REPLACE_OFF_SHIP = SPR_OPENTTD_BASE + 132; static const SpriteID SPR_GROUP_REPLACE_OFF_AIRCRAFT = SPR_OPENTTD_BASE + 133; +static const SpriteID SPR_TOWN_RATING_NA = SPR_OPENTTD_BASE + 162; +static const SpriteID SPR_TOWN_RATING_APALLING = SPR_OPENTTD_BASE + 163; +static const SpriteID SPR_TOWN_RATING_MEDIOCRE = SPR_OPENTTD_BASE + 164; +static const SpriteID SPR_TOWN_RATING_GOOD = SPR_OPENTTD_BASE + 165; + static const SpriteID SPR_IMG_SWITCH_TOOLBAR = SPR_OPENTTD_BASE + 144; static const SpriteID SPR_SIGNALS_BASE = SPR_OPENTTD_BASE + OPENTTD_SPRITE_COUNT; diff --git a/src/town_gui.cpp b/src/town_gui.cpp index 0f7f4e399..36b74a52b 100644 --- a/src/town_gui.cpp +++ b/src/town_gui.cpp @@ -727,15 +727,31 @@ public: DrawString(r.left + WD_FRAMERECT_LEFT, r.right, y, STR_TOWN_DIRECTORY_NONE); break; } + /* At least one town available. */ + bool rtl = _current_text_dir == TD_RTL; + Dimension icon_size = GetSpriteSize(SPR_TOWN_RATING_GOOD); + int text_left = r.left + WD_FRAMERECT_LEFT + (rtl ? 0 : icon_size.width + 2); + int text_right = r.right - WD_FRAMERECT_RIGHT - (rtl ? icon_size.width + 2 : 0); + int icon_x = rtl ? r.right - WD_FRAMERECT_RIGHT - icon_size.width : r.left + WD_FRAMERECT_LEFT; + for (uint i = this->vscroll->GetPosition(); i < this->towns.Length(); i++) { const Town *t = this->towns[i]; - assert(t->xy != INVALID_TILE); + /* Draw rating icon. */ + if (_game_mode == GM_EDITOR || !HasBit(t->have_ratings, _local_company)) { + DrawSprite(SPR_TOWN_RATING_NA, PAL_NONE, icon_x, y + (this->resize.step_height - icon_size.height) / 2); + } else { + SpriteID icon = SPR_TOWN_RATING_APALLING; + if (t->ratings[_local_company] > RATING_VERYPOOR) icon = SPR_TOWN_RATING_MEDIOCRE; + if (t->ratings[_local_company] > RATING_GOOD) icon = SPR_TOWN_RATING_GOOD; + DrawSprite(icon, PAL_NONE, icon_x, y + (this->resize.step_height - icon_size.height) / 2); + } + SetDParam(0, t->index); SetDParam(1, t->population); - DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_TOWN_DIRECTORY_TOWN); + DrawString(text_left, text_right, y + (this->resize.step_height - FONT_HEIGHT_NORMAL) / 2, STR_TOWN_DIRECTORY_TOWN); y += this->resize.step_height; if (++n == this->vscroll->GetCapacity()) break; // max number of towns in 1 window @@ -767,6 +783,9 @@ public: SetDParam(1, 10000000); // 10^7 d = maxdim(d, GetStringBoundingBox(STR_TOWN_DIRECTORY_TOWN)); } + Dimension icon_size = GetSpriteSize(SPR_TOWN_RATING_GOOD); + d.width += icon_size.width + 2; + d.height = max(d.height, icon_size.height); resize->height = d.height; d.height *= 5; d.width += padding.width + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT; |