43 return std::string(trainers->getListIndexUnchecked(2 * i).getString());
50 std::optional<std::string> newGame;
51 std::optional<int> toggleItem;
55 ImGui::SetNextWindowSize(
gl::vec2{28, 26} * ImGui::GetFontSize(), ImGuiCond_FirstUseEver);
56 im::Window(
"Trainer Selector", &
show, ImGuiWindowFlags_HorizontalScrollbar, [&]{
59 if (displayName.
empty()) displayName =
"none";
61 ImGui::InputText(ICON_IGFD_FILTER, &filterString);
62 HelpMarker(
"A list of substrings that must be part of the game name.\n"
64 "For example: enter 'vamp' to search for 'Akumajyo Drakyula - Vampire Killer'.");
66 auto drawGameNames = [&](
size_t num,
auto getName) {
68 if (ImGui::IsWindowAppearing()) {
69 for (
auto i :
xrange(num)) {
70 if (getName(i) == displayName) {
71 selectedIdx = narrow<int>(i) + 1;
77 if (ImGui::Selectable(
"none", displayName ==
"none")) {
78 newGame =
"deactivate";
81 auto name = getName(
size_t(i - 1));
82 if (ImGui::Selectable(name.c_str(), name == displayName)) {
85 if (i == selectedIdx) {
86 ImGui::SetItemDefaultFocus();
91 auto getGameName = [&](
size_t i) {
return gameNames[i]; };
96 drawGameNames(indices.size(), [&](
size_t i) { return gameNames[indices[i]]; });
99 ImGui::SetNextItemWidth(-FLT_MIN);
101 drawGameNames(gameNames.size(), getGameName);
107 ImGui::AlignTextToFramePadding();
108 ImGui::TextUnformatted(
"Select Cheats:"sv);
110 all = ImGui::Button(
"All");
112 none = ImGui::Button(
"None");
114 TclObject items = trainers->getOptionalDictValue(activeGame).value_or(TclObject{})
116 auto numItems = std::min(activeList.size(), items.size() / 2);
117 for (
auto i :
xrange(numItems)) {
118 bool active = activeList.getListIndexUnchecked(i).getOptionalBool().value_or(
false);
119 auto name = items.getListIndexUnchecked(2 * i + 0).getString();
120 if (ImGui::Checkbox(name.c_str(), &active)) {
129 }
else if (toggleItem) {
130 manager.execute(
makeTclList(
"trainer", activeGame, *toggleItem + 1));
131 }
else if (all || none) {
134 if (activeList.getListIndexUnchecked(i).getOptionalBool().value_or(
false) == none) {
135 cmd.addListElement(i + 1);
138 manager.execute(cmd);