16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-21 20:39:18 +02:00

Launcher improvements

Launcher windows are more Starter-like now:
- The scenery picker, vehicle list and keymapper buttons are now tied to the top portion of the screen.
- The current window is spanning the entire rest of the screen.
- Scenarios are now grouped into categories in the exact same way as Starter does.
- Some drawbacks include:
  - Currently you cannot edit the current trainset, as the vehicle picker window overwrites the scenario list window.
  - The GUI doesn't update when the screen resolution is changed.
This commit is contained in:
jakubg1
2025-09-09 16:40:04 +02:00
parent 22c0aed82d
commit c217081823
12 changed files with 335 additions and 334 deletions

View File

@@ -1,6 +1,7 @@
#include "stdafx.h"
#include "launcher/vehicle_picker.h"
#include "renderer.h"
#include "translation.h"
ui::vehiclepicker_panel::vehiclepicker_panel()
: ui_panel(STR("Select vehicle"), false), placeholder_mini("textures/mini/other")
@@ -8,195 +9,170 @@ ui::vehiclepicker_panel::vehiclepicker_panel()
bank.scan_textures();
}
void ui::vehiclepicker_panel::render()
void ui::vehiclepicker_panel::render_contents()
{
if (!is_open)
return;
ImGui::Columns(3);
static std::map<vehicle_type, std::string> type_names =
{
{ vehicle_type::electric_loco, STRN("Electric locos") },
{ vehicle_type::diesel_loco, STRN("Diesel locos") },
{ vehicle_type::steam_loco, STRN("Steam locos") },
{ vehicle_type::railcar, STRN("Railcars") },
{ vehicle_type::emu, STRN("EMU") },
{ vehicle_type::utility, STRN("Utility") },
{ vehicle_type::draisine, STRN("Draisines") },
{ vehicle_type::tram, STRN("Trams") },
{ vehicle_type::carriage, STRN("Carriages") },
{ vehicle_type::truck, STRN("Trucks") },
{ vehicle_type::bus, STRN("Buses") },
{ vehicle_type::car, STRN("Cars") },
{ vehicle_type::man, STRN("People") },
{ vehicle_type::animal, STRN("Animals") },
{ vehicle_type::unknown, STRN("Unknown") }
};
ImGui::PushStyleVar(ImGuiStyleVar_SelectableTextAlign, ImVec2(0.0f, 0.5f));
if (ImGui::Begin(m_name.c_str(), &is_open)) {
ImGui::Columns(3);
if (ImGui::BeginChild("box1")) {
for (auto const &e : type_names) {
deferred_image *image = nullptr;
auto it = bank.category_icons.find(e.first);
if (it != bank.category_icons.end())
image = &it->second;
ImGui::PushStyleVar(ImGuiStyleVar_SelectableTextAlign, ImVec2(0.0f, 0.5f));
if (selectable_image(Translations.lookup_s(e.second).c_str(), e.first == selected_type, image))
selected_type = e.first;
}
}
ImGui::EndChild();
ImGui::NextColumn();
if (ImGui::BeginChild("box1")) {
for (auto const &e : type_names) {
deferred_image *image = nullptr;
auto it = bank.category_icons.find(e.first);
if (it != bank.category_icons.end())
image = &it->second;
ImGui::TextUnformatted(STR_C("Group by: "));
ImGui::SameLine();
if (ImGui::RadioButton(STR_C("type"), !display_by_groups))
display_by_groups = false;
ImGui::SameLine();
if (ImGui::RadioButton(STR_C("texture group"), display_by_groups))
display_by_groups = true;
if (selectable_image(Translations.lookup_s(e.second).c_str(), e.first == selected_type, image))
selected_type = e.first;
std::vector<const skin_set*> skinset_list;
if (display_by_groups) {
std::vector<const std::string*> model_list;
for (auto const &kv : bank.group_map) {
const std::string &group = kv.first;
bool model_added = false;
bool can_break = false;
bool map_sel_eq = (selected_group && group == *selected_group);
for (auto const &vehicle : kv.second) {
if (vehicle->type != selected_type)
continue;
for (auto const &skinset : vehicle->matching_skinsets) {
bool map_group_eq = (skinset->group == group);
bool sel_group_eq = (selected_group && skinset->group == *selected_group);
if (!model_added && map_group_eq) {
model_list.push_back(&group);
model_added = true;
}
if (map_sel_eq) {
if (sel_group_eq)
skinset_list.push_back(skinset.get());
}
else if (model_added) {
can_break = true;
break;
}
}
if (can_break)
break;
}
}
ImGui::EndChild();
ImGui::NextColumn();
ImGui::TextUnformatted(STR_C("Group by: "));
ImGui::SameLine();
if (ImGui::RadioButton(STR_C("type"), !display_by_groups))
display_by_groups = false;
ImGui::SameLine();
if (ImGui::RadioButton(STR_C("texture group"), display_by_groups))
display_by_groups = true;
if (ImGui::BeginChild("box2")) {
ImGuiListClipper clipper(model_list.size());
while (clipper.Step())
for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) {
auto group = model_list[i];
std::vector<const skin_set*> skinset_list;
deferred_image *image = nullptr;
auto it = bank.group_icons.find(*group);
if (it != bank.group_icons.end())
image = &it->second;
if (display_by_groups) {
std::vector<const std::string*> model_list;
if (selectable_image(group->c_str(), group == selected_group, image))
selected_group = group;
}
}
}
else {
std::vector<std::shared_ptr<const vehicle_desc>> model_list;
for (auto const &kv : bank.group_map) {
const std::string &group = kv.first;
for (auto const &v : bank.vehicles) {
auto desc = v.second;
bool model_added = false;
bool can_break = false;
bool map_sel_eq = (selected_group && group == *selected_group);
if (selected_type == desc->type && desc->matching_skinsets.size() > 0)
model_list.push_back(desc);
for (auto const &vehicle : kv.second) {
if (vehicle->type != selected_type)
continue;
if (selected_vehicle == desc && selected_type == desc->type) {
for (auto &skin : desc->matching_skinsets)
skinset_list.push_back(skin.get());
}
}
for (auto const &skinset : vehicle->matching_skinsets) {
bool map_group_eq = (skinset->group == group);
bool sel_group_eq = (selected_group && skinset->group == *selected_group);
if (ImGui::BeginChild("box2")) {
ImGuiListClipper clipper(model_list.size());
while (clipper.Step())
for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) {
auto &desc = model_list[i];
if (!model_added && map_group_eq) {
model_list.push_back(&group);
model_added = true;
}
if (map_sel_eq) {
if (sel_group_eq)
skinset_list.push_back(skinset.get());
}
else if (model_added) {
can_break = true;
const deferred_image *image = nullptr;
for (auto const &skinset : desc->matching_skinsets) {
if (skinset->mini) {
image = &skinset->mini;
break;
}
}
if (can_break)
break;
}
}
if (ImGui::BeginChild("box2")) {
ImGuiListClipper clipper(model_list.size());
while (clipper.Step())
for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) {
auto group = model_list[i];
deferred_image *image = nullptr;
auto it = bank.group_icons.find(*group);
if (it != bank.group_icons.end())
image = &it->second;
if (selectable_image(group->c_str(), group == selected_group, image))
selected_group = group;
}
}
}
else {
std::vector<std::shared_ptr<const vehicle_desc>> model_list;
for (auto const &v : bank.vehicles) {
auto desc = v.second;
if (selected_type == desc->type && desc->matching_skinsets.size() > 0)
model_list.push_back(desc);
if (selected_vehicle == desc && selected_type == desc->type) {
for (auto &skin : desc->matching_skinsets)
skinset_list.push_back(skin.get());
}
}
if (ImGui::BeginChild("box2")) {
ImGuiListClipper clipper(model_list.size());
while (clipper.Step())
for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) {
auto &desc = model_list[i];
const deferred_image *image = nullptr;
for (auto const &skinset : desc->matching_skinsets) {
if (skinset->mini) {
image = &skinset->mini;
break;
}
}
std::string label = desc->path.stem().string();
if (selectable_image(label.c_str(), desc == selected_vehicle, image))
selected_vehicle = desc;
}
}
}
ImGui::EndChild();
ImGui::NextColumn();
ImGui::SetNextItemWidth(-1);
ImGui::InputText("##search", search_query.data(), search_query.size());
auto query_info = parse_search_query(search_query.data());
if (!query_info.empty())
skinset_list.erase(std::remove_if(skinset_list.begin(), skinset_list.end(),
std::bind(&vehiclepicker_panel::skin_filter, this, std::placeholders::_1, query_info)),
skinset_list.end());
if (ImGui::BeginChild("box3")) {
ImGuiListClipper clipper(skinset_list.size());
while (clipper.Step())
for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) {
auto skin = skinset_list[i];
//std::string label = skin->skins[0].stem().string();
std::string label = skin->skin;
if (skin->meta && !skin->meta->name.empty() && skin->meta->name != "?")
label = skin->meta->name;
auto mini = skin->mini ? &skin->mini : &placeholder_mini;
if (selectable_image(label.c_str(), skin == selected_skinset, mini, skin))
selected_skinset = skin;
if (skin->meta && ImGui::IsItemHovered()) {
ImGui::BeginTooltip();
ImGui::Text(STR_C("Skin: %s\nType: %s\nCarrier code: %s\nDepot: %s\nMaintenance: %s, by %s\nSkin author: %s\nPhoto author: %s"),
skin->skin.c_str(),
skin->vehicle.lock()->path.string().c_str(),
skin->meta->short_id.c_str(),
skin->meta->location.c_str(),
skin->meta->rev_date.c_str(),
skin->meta->rev_company.c_str(),
skin->meta->texture_author.c_str(),
skin->meta->photo_author.c_str());
ImGui::EndTooltip();
}
std::string label = desc->path.stem().string();
if (selectable_image(label.c_str(), desc == selected_vehicle, image))
selected_vehicle = desc;
}
}
ImGui::EndChild();
ImGui::PopStyleVar();
}
ImGui::End();
ImGui::EndChild();
ImGui::NextColumn();
ImGui::SetNextItemWidth(-1);
ImGui::InputText("##search", search_query.data(), search_query.size());
auto query_info = parse_search_query(search_query.data());
if (!query_info.empty())
skinset_list.erase(std::remove_if(skinset_list.begin(), skinset_list.end(),
std::bind(&vehiclepicker_panel::skin_filter, this, std::placeholders::_1, query_info)),
skinset_list.end());
if (ImGui::BeginChild("box3")) {
ImGuiListClipper clipper(skinset_list.size());
while (clipper.Step())
for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) {
auto skin = skinset_list[i];
//std::string label = skin->skins[0].stem().string();
std::string label = skin->skin;
if (skin->meta && !skin->meta->name.empty() && skin->meta->name != "?")
label = skin->meta->name;
auto mini = skin->mini ? &skin->mini : &placeholder_mini;
if (selectable_image(label.c_str(), skin == selected_skinset, mini, skin))
selected_skinset = skin;
if (skin->meta && ImGui::IsItemHovered()) {
ImGui::BeginTooltip();
ImGui::Text(STR_C("Skin: %s\nType: %s\nCarrier code: %s\nDepot: %s\nMaintenance: %s, by %s\nSkin author: %s\nPhoto author: %s"),
skin->skin.c_str(),
skin->vehicle.lock()->path.string().c_str(),
skin->meta->short_id.c_str(),
skin->meta->location.c_str(),
skin->meta->rev_date.c_str(),
skin->meta->rev_company.c_str(),
skin->meta->texture_author.c_str(),
skin->meta->photo_author.c_str());
ImGui::EndTooltip();
}
}
}
ImGui::EndChild();
ImGui::PopStyleVar();
}
std::vector<ui::vehiclepicker_panel::search_info> ui::vehiclepicker_panel::parse_search_query(const std::string &str)