mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-03-22 15:05:03 +01:00
launcher: vehicle skin filter, texture metadata parsing
This commit is contained in:
@@ -28,11 +28,11 @@ void ui::vehicles_bank::scan_textures()
|
||||
void ui::vehicles_bank::parse_entry(const std::string &line)
|
||||
{
|
||||
std::string content;
|
||||
std::string comments;
|
||||
std::shared_ptr<skin_meta> meta;
|
||||
|
||||
size_t pos = line.find("//");
|
||||
if (pos != -1)
|
||||
comments = line.substr(pos);
|
||||
meta = parse_meta(line.substr(pos));
|
||||
content = line.substr(0, pos);
|
||||
|
||||
std::istringstream stream(content);
|
||||
@@ -54,7 +54,7 @@ void ui::vehicles_bank::parse_entry(const std::string &line)
|
||||
else if (line[0] == '@')
|
||||
parse_controllable_entry(target.substr(1), param);
|
||||
else
|
||||
parse_texture_info(target, param, comments);
|
||||
parse_texture_info(target, param, meta);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ void ui::vehicles_bank::parse_controllable_entry(const std::string &target, cons
|
||||
(param.size() >= 1 && param[0] == '1');
|
||||
}
|
||||
|
||||
void ui::vehicles_bank::parse_texture_info(const std::string &target, const std::string ¶m, const std::string &comment)
|
||||
void ui::vehicles_bank::parse_texture_info(const std::string &target, const std::string ¶m, std::shared_ptr<skin_meta> meta)
|
||||
{
|
||||
std::istringstream stream(param);
|
||||
|
||||
@@ -119,6 +119,7 @@ void ui::vehicles_bank::parse_texture_info(const std::string &target, const std:
|
||||
skin_set set;
|
||||
set.vehicle = vehicle;
|
||||
set.group = mini;
|
||||
set.meta = meta;
|
||||
|
||||
if (!mini.empty())
|
||||
group_icons.emplace(mini, std::move(deferred_image("textures/mini/" + ToLower(mini))));
|
||||
@@ -142,6 +143,43 @@ void ui::vehicles_bank::parse_texture_info(const std::string &target, const std:
|
||||
vehicle->matching_skinsets.push_back(std::make_shared<skin_set>(std::move(set)));
|
||||
}
|
||||
|
||||
std::shared_ptr<ui::skin_meta> ui::vehicles_bank::parse_meta(const std::string &str)
|
||||
{
|
||||
std::istringstream stream(str);
|
||||
|
||||
auto meta = std::make_shared<skin_meta>();
|
||||
|
||||
std::string version;
|
||||
std::getline(stream, version, ',');
|
||||
std::getline(stream, meta->name, ',');
|
||||
std::getline(stream, meta->short_id, ',');
|
||||
std::getline(stream, meta->location, ',');
|
||||
std::getline(stream, meta->rev_date, ',');
|
||||
std::getline(stream, meta->rev_company, ',');
|
||||
std::getline(stream, meta->texture_author, ',');
|
||||
std::getline(stream, meta->photo_author, ',');
|
||||
|
||||
meta->name = win1250_to_utf8(meta->name);
|
||||
meta->short_id = win1250_to_utf8(meta->short_id);
|
||||
meta->location = win1250_to_utf8(meta->location);
|
||||
meta->rev_date = win1250_to_utf8(meta->rev_date);
|
||||
meta->rev_company = win1250_to_utf8(meta->rev_company);
|
||||
meta->texture_author = win1250_to_utf8(meta->texture_author);
|
||||
meta->photo_author = win1250_to_utf8(meta->photo_author);
|
||||
|
||||
if (!meta->rev_date.empty() && meta->rev_date != "?") {
|
||||
std::istringstream stream(meta->rev_date);
|
||||
std::string day, month;
|
||||
|
||||
std::getline(stream, day, '.');
|
||||
std::getline(stream, month, '.');
|
||||
|
||||
stream >> meta->rev_year;
|
||||
}
|
||||
|
||||
return meta;
|
||||
}
|
||||
|
||||
void ui::vehicles_bank::parse_coupling_rule(const std::string &target, const std::string ¶m)
|
||||
{
|
||||
auto target_vehicle = get_vehicle(target);
|
||||
|
||||
@@ -24,9 +24,23 @@ enum class vehicle_type {
|
||||
|
||||
struct vehicle_desc;
|
||||
|
||||
struct skin_meta {
|
||||
std::string name;
|
||||
std::string short_id;
|
||||
std::string location;
|
||||
|
||||
std::string rev_date;
|
||||
int rev_year = -1;
|
||||
|
||||
std::string rev_company;
|
||||
std::string texture_author;
|
||||
std::string photo_author;
|
||||
};
|
||||
|
||||
struct skin_set {
|
||||
std::weak_ptr<vehicle_desc> vehicle;
|
||||
|
||||
std::shared_ptr<skin_meta> meta;
|
||||
std::string skin;
|
||||
//std::vector<std::filesystem::path> skins;
|
||||
deferred_image mini;
|
||||
@@ -69,8 +83,9 @@ private:
|
||||
void parse_controllable_entry(const std::string &target, const std::string ¶m);
|
||||
void parse_coupling_rule(const std::string &target, const std::string ¶m);
|
||||
void parse_texture_rule(const std::string &target, const std::string ¶m);
|
||||
void parse_texture_info(const std::string &target, const std::string ¶m, const std::string &comment);
|
||||
void parse_texture_info(const std::string &target, const std::string ¶m, std::shared_ptr<skin_meta> meta);
|
||||
|
||||
std::shared_ptr<skin_meta> parse_meta(const std::string &str);
|
||||
std::shared_ptr<vehicle_desc> get_vehicle(const std::string &name);
|
||||
|
||||
vehicle_type ctx_type = vehicle_type::unknown;
|
||||
|
||||
@@ -154,6 +154,16 @@ void ui::vehiclepicker_panel::render()
|
||||
ImGui::EndChild();
|
||||
ImGui::NextColumn();
|
||||
|
||||
ImGui::SetNextItemWidth(-1);
|
||||
ImGui::InputText("##search", search_query.data(), search_query.size());
|
||||
skinset_list.erase(std::remove_if(skinset_list.begin(), skinset_list.end(), [this](const skin_set* skin)
|
||||
{
|
||||
std::string query_str(search_query.data());
|
||||
if (query_str.empty())
|
||||
return false;
|
||||
return skin->skin.find(query_str) == -1;
|
||||
}), skinset_list.end());
|
||||
|
||||
if (ImGui::BeginChild("box3")) {
|
||||
ImGuiListClipper clipper(skinset_list.size());
|
||||
while (clipper.Step())
|
||||
@@ -161,10 +171,26 @@ void ui::vehiclepicker_panel::render()
|
||||
auto skin = skinset_list[i];
|
||||
|
||||
//std::string label = skin->skins[0].stem().string();
|
||||
std::string label = skin->skin;
|
||||
std::string label = skin->meta->name;
|
||||
if (label.empty() || label == "?")
|
||||
label = skin->skin;
|
||||
|
||||
auto mini = skin->mini ? &skin->mini : &placeholder_mini;
|
||||
if (selectable_image(label.c_str(), skin == selected_skinset, mini, skin))
|
||||
selected_skinset = skin;
|
||||
|
||||
if (ImGui::IsItemHovered()) {
|
||||
ImGui::BeginTooltip();
|
||||
ImGui::TextUnformatted(skin->skin.c_str());
|
||||
ImGui::TextUnformatted(skin->vehicle.lock()->path.string().c_str());
|
||||
ImGui::TextUnformatted(skin->meta->short_id.c_str());
|
||||
ImGui::TextUnformatted(skin->meta->location.c_str());
|
||||
ImGui::TextUnformatted(skin->meta->rev_date.c_str());
|
||||
ImGui::TextUnformatted(skin->meta->rev_company.c_str());
|
||||
ImGui::TextUnformatted(skin->meta->texture_author.c_str());
|
||||
ImGui::TextUnformatted(skin->meta->photo_author.c_str());
|
||||
ImGui::EndTooltip();
|
||||
}
|
||||
}
|
||||
}
|
||||
ImGui::EndChild();
|
||||
@@ -176,6 +202,8 @@ void ui::vehiclepicker_panel::render()
|
||||
|
||||
bool ui::vehiclepicker_panel::selectable_image(const char *desc, bool selected, const deferred_image* image, const skin_set *pickable)
|
||||
{
|
||||
ImGui::PushID(pickable);
|
||||
|
||||
bool ret = ImGui::Selectable(desc, selected, 0, ImVec2(0, 30));
|
||||
if (pickable)
|
||||
ImGui::SetItemAllowOverlap();
|
||||
@@ -206,5 +234,7 @@ bool ui::vehiclepicker_panel::selectable_image(const char *desc, bool selected,
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::PopID();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ private:
|
||||
const skin_set *selected_skinset = nullptr;
|
||||
bool display_by_groups = false;
|
||||
deferred_image placeholder_mini;
|
||||
std::array<char, 128> search_query = { 0 };
|
||||
|
||||
vehicles_bank bank;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user