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

@@ -22,6 +22,7 @@
#include "sound_func.h"
#include "company_func.h"
#include "dropdown_type.h"
#include "dropdown_func.h"
#include "tunnelbridge.h"
#include "tilehighlight_func.h"
#include "spritecache.h"
@@ -2385,7 +2386,7 @@ DropDownList GetRailTypeDropDownList(bool for_replacement, bool all_option)
DropDownList list;
if (all_option) {
list.push_back(std::make_unique<DropDownListStringItem>(STR_REPLACE_ALL_RAILTYPE, INVALID_RAILTYPE, false));
list.push_back(MakeDropDownListStringItem(STR_REPLACE_ALL_RAILTYPE, INVALID_RAILTYPE));
}
Dimension d = { 0, 0 };
@@ -2407,16 +2408,16 @@ DropDownList GetRailTypeDropDownList(bool for_replacement, bool all_option)
SetDParam(0, rti->strings.menu_text);
SetDParam(1, rti->max_speed);
if (for_replacement) {
list.push_back(std::make_unique<DropDownListStringItem>(rti->strings.replace_text, rt, !HasBit(avail_railtypes, rt)));
list.push_back(MakeDropDownListStringItem(rti->strings.replace_text, rt, !HasBit(avail_railtypes, 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_rail, PAL_NONE, str, rt, !HasBit(avail_railtypes, rt)));
list.push_back(MakeDropDownListIconItem(d, rti->gui_sprites.build_x_rail, PAL_NONE, str, rt, !HasBit(avail_railtypes, rt)));
}
}
if (list.empty()) {
/* Empty dropdowns are not allowed */
list.push_back(std::make_unique<DropDownListStringItem>(STR_NONE, INVALID_RAILTYPE, true));
list.push_back(MakeDropDownListStringItem(STR_NONE, INVALID_RAILTYPE, true));
}
return list;