mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-03-22 15:05:03 +01:00
Add scenery category detection, launcher category list parity with Starter
This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
#include "imgui/imgui.h"
|
||||
#include "utilities.h"
|
||||
#include "renderer.h"
|
||||
#include "McZapkie/MOVER.h"
|
||||
#include "application.h"
|
||||
#include "Logs.h"
|
||||
#include <filesystem>
|
||||
@@ -15,32 +14,36 @@ ui::scenerylist_panel::scenerylist_panel(scenery_scanner &scanner)
|
||||
|
||||
void ui::scenerylist_panel::draw_scenery_list()
|
||||
{
|
||||
std::string prev_prefix;
|
||||
bool collapse_open = false;
|
||||
|
||||
// Draw all the scenarios which are not assigned to any category.
|
||||
for (auto &desc : scanner.scenarios) {
|
||||
std::string name = desc.path.stem().string();
|
||||
std::string prefix = name.substr(0, name.find_first_of("-_"));
|
||||
std::string prefix = desc.category;
|
||||
if (prefix.empty())
|
||||
prefix = name;
|
||||
|
||||
bool just_opened = false;
|
||||
if (prefix != prev_prefix) {
|
||||
collapse_open = ImGui::CollapsingHeader(prefix.c_str());
|
||||
just_opened = ImGui::IsItemDeactivated();
|
||||
prev_prefix = prefix;
|
||||
}
|
||||
|
||||
if (collapse_open) {
|
||||
if (just_opened)
|
||||
selected_scenery = &desc;
|
||||
|
||||
ImGui::Indent(10.0f);
|
||||
{
|
||||
if (ImGui::Selectable(name.c_str(), &desc == selected_scenery)) {
|
||||
selected_scenery = &desc;
|
||||
selected_trainset = nullptr;
|
||||
}
|
||||
ImGui::Unindent(10.0f);
|
||||
}
|
||||
}
|
||||
|
||||
// Render all aggregated scenarios inside categories.
|
||||
bool collapse_open = false;
|
||||
for (auto category : scanner.categories)
|
||||
{
|
||||
collapse_open = ImGui::CollapsingHeader(category.first.c_str());
|
||||
if (collapse_open) {
|
||||
for (auto desc : category.second)
|
||||
{
|
||||
std::string name = desc->path.stem().string();
|
||||
|
||||
ImGui::Indent(10.0f);
|
||||
if (ImGui::Selectable(name.c_str(), desc == selected_scenery)) {
|
||||
selected_scenery = desc;
|
||||
selected_trainset = nullptr;
|
||||
}
|
||||
ImGui::Unindent(10.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,8 @@ void scenery_scanner::scan()
|
||||
|
||||
std::sort(scenarios.begin(), scenarios.end(),
|
||||
[](const scenery_desc &a, const scenery_desc &b) { return a.path < b.path; });
|
||||
|
||||
build_categories();
|
||||
}
|
||||
|
||||
void scenery_scanner::scan_scn(std::filesystem::path path)
|
||||
@@ -57,6 +59,8 @@ void scenery_scanner::scan_scn(std::filesystem::path path)
|
||||
desc.name = win1250_to_utf8(line.substr(5));
|
||||
else if (line[3] == 'd')
|
||||
desc.description += win1250_to_utf8(line.substr(5)) + '\n';
|
||||
else if (line[3] == 'l')
|
||||
desc.category = win1250_to_utf8(line.substr(5));
|
||||
else if (line[3] == 'f') {
|
||||
std::string lang;
|
||||
std::string file;
|
||||
@@ -154,3 +158,14 @@ void scenery_scanner::parse_trainset(cParser &parser)
|
||||
|
||||
trainset.file_bounds.second = parser.Line();
|
||||
}
|
||||
|
||||
void scenery_scanner::build_categories()
|
||||
{
|
||||
for (auto &desc : scenarios) {
|
||||
std::string name = desc.path.stem().string();
|
||||
std::string prefix = desc.category;
|
||||
// If the scenario does have a category, add it to the list so we can render it later in a group.
|
||||
if (!prefix.empty())
|
||||
categories[prefix].push_back(&desc);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@ struct scenery_desc {
|
||||
std::filesystem::path path;
|
||||
std::string name;
|
||||
std::string description;
|
||||
std::string category;
|
||||
std::string image_path;
|
||||
texture_handle image = 0;
|
||||
|
||||
@@ -58,12 +59,14 @@ public:
|
||||
scenery_scanner(ui::vehicles_bank &bank);
|
||||
|
||||
std::vector<scenery_desc> scenarios;
|
||||
std::map<std::string, std::vector<scenery_desc*>> categories;
|
||||
|
||||
void scan();
|
||||
|
||||
private:
|
||||
void scan_scn(std::filesystem::path path);
|
||||
void parse_trainset(cParser &parser);
|
||||
void build_categories();
|
||||
|
||||
ui::vehicles_bank &bank;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user