Codechange: Use functions to create common drop down list items.

This commit is contained in:
Peter Nelson
2024-03-31 17:31:47 +01:00
committed by Peter Nelson
parent 11aa3694fa
commit 56cac21086
22 changed files with 190 additions and 136 deletions

View File

@@ -27,6 +27,8 @@
#include "hotkeys.h"
#include "road_gui.h"
#include "zoom_func.h"
#include "dropdown_type.h"
#include "dropdown_func.h"
#include "engine_base.h"
#include "strings_func.h"
#include "core/geometry_func.hpp"
@@ -1830,7 +1832,7 @@ DropDownList GetRoadTypeDropDownList(RoadTramTypes rtts, bool for_replacement, b
DropDownList list;
if (all_option) {
list.push_back(std::make_unique<DropDownListStringItem>(STR_REPLACE_ALL_ROADTYPE, INVALID_ROADTYPE, false));
list.push_back(MakeDropDownListStringItem(STR_REPLACE_ALL_ROADTYPE, INVALID_ROADTYPE));
}
Dimension d = { 0, 0 };
@@ -1852,16 +1854,16 @@ DropDownList GetRoadTypeDropDownList(RoadTramTypes rtts, bool for_replacement, b
SetDParam(0, rti->strings.menu_text);
SetDParam(1, rti->max_speed / 2);
if (for_replacement) {
list.push_back(std::make_unique<DropDownListStringItem>(rti->strings.replace_text, rt, !HasBit(avail_roadtypes, rt)));
list.push_back(MakeDropDownListStringItem(rti->strings.replace_text, rt, !HasBit(avail_roadtypes, rt)));
} else {
StringID str = rti->max_speed > 0 ? STR_TOOLBAR_RAILTYPE_VELOCITY : STR_JUST_STRING;
list.push_back(std::make_unique<DropDownListIconItem>(d, rti->gui_sprites.build_x_road, PAL_NONE, str, rt, !HasBit(avail_roadtypes, rt)));
list.push_back(MakeDropDownListIconItem(d, rti->gui_sprites.build_x_road, PAL_NONE, str, rt, !HasBit(avail_roadtypes, rt)));
}
}
if (list.empty()) {
/* Empty dropdowns are not allowed */
list.push_back(std::make_unique<DropDownListStringItem>(STR_NONE, INVALID_ROADTYPE, true));
list.push_back(MakeDropDownListStringItem(STR_NONE, INVALID_ROADTYPE, true));
}
return list;
@@ -1894,12 +1896,12 @@ DropDownList GetScenRoadTypeDropDownList(RoadTramTypes rtts)
SetDParam(0, rti->strings.menu_text);
SetDParam(1, rti->max_speed / 2);
StringID str = rti->max_speed > 0 ? STR_TOOLBAR_RAILTYPE_VELOCITY : STR_JUST_STRING;
list.push_back(std::make_unique<DropDownListIconItem>(d, rti->gui_sprites.build_x_road, PAL_NONE, str, rt, !HasBit(avail_roadtypes, rt)));
list.push_back(MakeDropDownListIconItem(d, rti->gui_sprites.build_x_road, PAL_NONE, str, rt, !HasBit(avail_roadtypes, rt)));
}
if (list.empty()) {
/* Empty dropdowns are not allowed */
list.push_back(std::make_unique<DropDownListStringItem>(STR_NONE, -1, true));
list.push_back(MakeDropDownListStringItem(STR_NONE, -1, true));
}
return list;