summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2019-03-10 02:26:19 +0000
committerPeterN <peter@fuzzle.org>2019-03-10 10:31:37 +0000
commit9c8b7b5efc9ff3dd065d5f02577de39161e2bee2 (patch)
tree4418503cc6c997dee169e7a033ff3305ccda9ecc
parentb56ea5ca27440fd8023bfecf8299422c93eb05c3 (diff)
downloadopenttd-9c8b7b5efc9ff3dd065d5f02577de39161e2bee2.tar.xz
Feature: Add rail icon to rail construction drop down list.
-rw-r--r--src/rail_gui.cpp19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/rail_gui.cpp b/src/rail_gui.cpp
index 0bc29977c..d0789f337 100644
--- a/src/rail_gui.cpp
+++ b/src/rail_gui.cpp
@@ -2010,7 +2010,17 @@ DropDownList *GetRailTypeDropDownList(bool for_replacement, bool all_option)
*list->Append() = item;
}
+ Dimension d = { 0, 0 };
RailType rt;
+ /* Get largest icon size, to ensure text is aligned on each menu item. */
+ if (!for_replacement) {
+ FOR_ALL_SORTED_RAILTYPES(rt) {
+ if (!HasBit(used_railtypes, rt)) continue;
+ const RailtypeInfo *rti = GetRailTypeInfo(rt);
+ d = maxdim(d, GetSpriteSize(rti->gui_sprites.build_x_rail));
+ }
+ }
+
FOR_ALL_SORTED_RAILTYPES(rt) {
/* If it's not used ever, don't show it to the user. */
if (!HasBit(used_railtypes, rt)) continue;
@@ -2018,7 +2028,14 @@ DropDownList *GetRailTypeDropDownList(bool for_replacement, bool all_option)
const RailtypeInfo *rti = GetRailTypeInfo(rt);
StringID str = for_replacement ? rti->strings.replace_text : (rti->max_speed > 0 ? STR_TOOLBAR_RAILTYPE_VELOCITY : STR_JUST_STRING);
- DropDownListParamStringItem *item = new DropDownListParamStringItem(str, rt, !HasBit(c->avail_railtypes, rt));
+ DropDownListParamStringItem *item;
+ if (for_replacement) {
+ item = new DropDownListParamStringItem(str, rt, !HasBit(c->avail_railtypes, rt));
+ } else {
+ DropDownListIconItem *iconitem = new DropDownListIconItem(rti->gui_sprites.build_x_rail, PAL_NONE, str, rt, !HasBit(c->avail_railtypes, rt));
+ iconitem->SetDimension(d);
+ item = iconitem;
+ }
item->SetParam(0, rti->strings.menu_text);
item->SetParam(1, rti->max_speed);
*list->Append() = item;