mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-03-22 15:05:03 +01:00
further WIP on launcher
This commit is contained in:
@@ -4,10 +4,12 @@
|
||||
#include "utilities.h"
|
||||
#include "renderer.h"
|
||||
#include "McZapkie/MOVER.h"
|
||||
#include "application.h"
|
||||
#include "Logs.h"
|
||||
#include <filesystem>
|
||||
|
||||
ui::scenerylist_panel::scenerylist_panel(scenery_scanner &scanner)
|
||||
: ui_panel(STR("Scenario list"), false), scanner(scanner)
|
||||
: ui_panel(STR("Scenario list"), false), scanner(scanner), placeholder_mini("textures/mini/other")
|
||||
{
|
||||
}
|
||||
|
||||
@@ -25,7 +27,7 @@ void ui::scenerylist_panel::render()
|
||||
std::string prev_prefix;
|
||||
bool collapse_open = false;
|
||||
|
||||
for (auto const &desc : scanner.scenarios) {
|
||||
for (auto &desc : scanner.scenarios) {
|
||||
std::string name = desc.path.stem().string();
|
||||
std::string prefix = name.substr(0, name.find_first_of("-_"));
|
||||
if (prefix.empty())
|
||||
@@ -110,7 +112,7 @@ void ui::scenerylist_panel::render()
|
||||
if (ImGui::BeginChild("child5", ImVec2(0, 0), false, ImGuiWindowFlags_HorizontalScrollbar)) {
|
||||
ImGuiListClipper clipper(selected_scenery->trainsets.size());
|
||||
while (clipper.Step()) for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) {
|
||||
auto const &trainset = selected_scenery->trainsets[i];
|
||||
auto &trainset = selected_scenery->trainsets[i];
|
||||
ImGui::PushID(i);
|
||||
if (ImGui::Selectable("##set", selected_trainset == &trainset, 0, ImVec2(0, 30)))
|
||||
selected_trainset = &trainset;
|
||||
@@ -124,8 +126,57 @@ void ui::scenerylist_panel::render()
|
||||
|
||||
if (selected_trainset) {
|
||||
ImGui::NextColumn();
|
||||
|
||||
ImGui::TextWrapped(selected_trainset->description.c_str());
|
||||
ImGui::Button(STR_C("Launch"), ImVec2(-1, 0));
|
||||
|
||||
if (ImGui::Button(STR_C("Launch"), ImVec2(-1, 0))) {
|
||||
bool found = false;
|
||||
for (auto &veh : selected_trainset->vehicles) {
|
||||
if (veh.drivertype.size() > 0 && veh.drivertype != "nobody") {
|
||||
Global.local_start_vehicle = ToLower(veh.name);
|
||||
Global.SceneryFile = selected_scenery->path;
|
||||
|
||||
std::string set = "trainset ";
|
||||
set += selected_trainset->name + " ";
|
||||
set += selected_trainset->track + " ";
|
||||
set += std::to_string(selected_trainset->offset) + " ";
|
||||
set += std::to_string(selected_trainset->velocity) + " ";
|
||||
for (const auto &veh : selected_trainset->vehicles) {
|
||||
set += "node -1 0 " + veh.name + " dynamic ";
|
||||
set += veh.vehicle->path.parent_path().generic_string() + " ";
|
||||
set += veh.skin->skin + " ";
|
||||
set += veh.vehicle->path.stem().generic_string() + " ";
|
||||
set += std::to_string(veh.offset) + " " + veh.drivertype + " ";
|
||||
set += std::to_string(veh.coupling);
|
||||
if (veh.params.size() > 0)
|
||||
set += "." + veh.params;
|
||||
set += " " + std::to_string(veh.loadcount) + " ";
|
||||
if (veh.loadcount > 0)
|
||||
set += veh.loadtype + " ";
|
||||
set += "enddynamic ";
|
||||
}
|
||||
set += "endtrainset";
|
||||
WriteLog(set);
|
||||
|
||||
Global.trainset_overrides.push_back(std::make_pair(selected_trainset->file_bounds.first, set));
|
||||
|
||||
Application.pop_mode();
|
||||
Application.push_mode(eu07_application::mode::scenarioloader);
|
||||
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
ImGui::OpenPopup("missing_driver");
|
||||
}
|
||||
|
||||
if (ImGui::BeginPopup("missing_driver")) {
|
||||
ImGui::TextUnformatted(STR_C("Trainset not occupied"));
|
||||
if (ImGui::Button(STR_C("OK"), ImVec2(-1, 0)))
|
||||
ImGui::CloseCurrentPopup();
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
}
|
||||
}
|
||||
} ImGui::EndChild();
|
||||
@@ -134,7 +185,7 @@ void ui::scenerylist_panel::render()
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
void ui::scenerylist_panel::draw_trainset(const trainset_desc &trainset)
|
||||
void ui::scenerylist_panel::draw_trainset(trainset_desc &trainset)
|
||||
{
|
||||
static std::unordered_map<coupling, std::string> coupling_names =
|
||||
{
|
||||
@@ -150,70 +201,93 @@ void ui::scenerylist_panel::draw_trainset(const trainset_desc &trainset)
|
||||
{ coupling::uic, STRN("uic") }
|
||||
};
|
||||
|
||||
draw_droptarget();
|
||||
int position = 0;
|
||||
|
||||
draw_droptarget(trainset, position++);
|
||||
ImGui::SameLine(15.0f);
|
||||
|
||||
for (auto const &dyn_desc : trainset.vehicles) {
|
||||
if (dyn_desc.skin && dyn_desc.skin->mini.get() != -1) {
|
||||
ImGui::PushID(static_cast<const void*>(&dyn_desc));
|
||||
deferred_image *mini = nullptr;
|
||||
|
||||
glm::ivec2 size = dyn_desc.skin->mini.size();
|
||||
float width = 30.0f / size.y * size.x;
|
||||
ImGui::Image(reinterpret_cast<void*>(dyn_desc.skin->mini.get()), ImVec2(width, 30), ImVec2(0, 1), ImVec2(1, 0));
|
||||
if (dyn_desc.skin && dyn_desc.skin->mini.get() != -1)
|
||||
mini = &dyn_desc.skin->mini;
|
||||
else
|
||||
mini = &placeholder_mini;
|
||||
|
||||
if (ImGui::IsItemHovered()) {
|
||||
ImGui::BeginTooltip();
|
||||
std::string name = (dyn_desc.vehicle->path.parent_path() / dyn_desc.vehicle->path.stem()).string();
|
||||
std::string skin = dyn_desc.skin->skin;
|
||||
ImGui::Text(STR_C("ID: %s"), dyn_desc.name.c_str());
|
||||
ImGui::NewLine();
|
||||
ImGui::PushID(static_cast<const void*>(&dyn_desc));
|
||||
|
||||
ImGui::Text(STR_C("Type: %s"), name.c_str());
|
||||
ImGui::Text(STR_C("Skin: %s"), skin.c_str());
|
||||
ImGui::NewLine();
|
||||
glm::ivec2 size = mini->size();
|
||||
float width = 30.0f / size.y * size.x;
|
||||
ImGui::Image(reinterpret_cast<void*>(mini->get()), ImVec2(width, 30), ImVec2(0, 1), ImVec2(1, 0));
|
||||
|
||||
if (dyn_desc.drivertype != "nobody")
|
||||
ImGui::Text(STR_C("Occupied: %s"), dyn_desc.drivertype.c_str());
|
||||
if (dyn_desc.loadcount > 0)
|
||||
ImGui::Text(STR_C("Load: %s: %d"), dyn_desc.loadtype.c_str(), dyn_desc.loadcount);
|
||||
if (!dyn_desc.params.empty())
|
||||
ImGui::Text(STR_C("Parameters: %s"), dyn_desc.params.c_str());
|
||||
ImGui::NewLine();
|
||||
if (ImGui::IsItemHovered()) {
|
||||
ImGui::BeginTooltip();
|
||||
std::string name = (dyn_desc.vehicle->path.parent_path() / dyn_desc.vehicle->path.stem()).string();
|
||||
std::string skin = dyn_desc.skin->skin;
|
||||
ImGui::Text(STR_C("ID: %s"), dyn_desc.name.c_str());
|
||||
ImGui::NewLine();
|
||||
|
||||
ImGui::TextUnformatted(STR_C("Coupling:"));
|
||||
ImGui::Text(STR_C("Type: %s"), name.c_str());
|
||||
ImGui::Text(STR_C("Skin: %s"), skin.c_str());
|
||||
ImGui::NewLine();
|
||||
|
||||
for (int i = 1; i <= 0x100; i <<= 1) {
|
||||
bool dummy = true;
|
||||
if (dyn_desc.drivertype != "nobody")
|
||||
ImGui::Text(STR_C("Occupied: %s"), dyn_desc.drivertype.c_str());
|
||||
if (dyn_desc.loadcount > 0)
|
||||
ImGui::Text(STR_C("Load: %s: %d"), dyn_desc.loadtype.c_str(), dyn_desc.loadcount);
|
||||
if (!dyn_desc.params.empty())
|
||||
ImGui::Text(STR_C("Parameters: %s"), dyn_desc.params.c_str());
|
||||
ImGui::NewLine();
|
||||
|
||||
if (dyn_desc.coupling & i) {
|
||||
std::string label = STRN("unknown");
|
||||
auto it = coupling_names.find(static_cast<coupling>(i));
|
||||
if (it != coupling_names.end())
|
||||
label = it->second;
|
||||
ImGui::Checkbox(Translations.lookup_c(label.c_str()), &dummy);
|
||||
}
|
||||
ImGui::TextUnformatted(STR_C("Coupling:"));
|
||||
|
||||
for (int i = 1; i <= 0x100; i <<= 1) {
|
||||
bool dummy = true;
|
||||
|
||||
if (dyn_desc.coupling & i) {
|
||||
std::string label = STRN("unknown");
|
||||
auto it = coupling_names.find(static_cast<coupling>(i));
|
||||
if (it != coupling_names.end())
|
||||
label = it->second;
|
||||
ImGui::Checkbox(Translations.lookup_c(label.c_str()), &dummy);
|
||||
}
|
||||
|
||||
ImGui::EndTooltip();
|
||||
}
|
||||
|
||||
ImGui::SameLine(0, 0);
|
||||
float originX = ImGui::GetCursorPosX();
|
||||
|
||||
ImGui::SameLine(originX - 7.5f);
|
||||
draw_droptarget();
|
||||
ImGui::SameLine(originX);
|
||||
|
||||
ImGui::PopID();
|
||||
ImGui::EndTooltip();
|
||||
}
|
||||
|
||||
ImGui::SameLine(0, 0);
|
||||
float originX = ImGui::GetCursorPosX();
|
||||
|
||||
ImGui::SameLine(originX - 7.5f);
|
||||
draw_droptarget(trainset, position++);
|
||||
ImGui::SameLine(originX);
|
||||
|
||||
ImGui::PopID();
|
||||
}
|
||||
}
|
||||
|
||||
void ui::scenerylist_panel::draw_droptarget()
|
||||
#include "Logs.h"
|
||||
void ui::scenerylist_panel::draw_droptarget(trainset_desc &trainset, int position)
|
||||
{
|
||||
ImGui::Dummy(ImVec2(15, 30));
|
||||
if (ImGui::BeginDragDropTarget()) {
|
||||
ImGui::AcceptDragDropPayload("skin");
|
||||
const ImGuiPayload *payload = ImGui::AcceptDragDropPayload("vehicle_pure");
|
||||
if (payload) {
|
||||
skin_set *ptr = *(reinterpret_cast<skin_set**>(payload->Data));
|
||||
std::shared_ptr<skin_set> skin;
|
||||
for (auto &s : ptr->vehicle.lock()->matching_skinsets)
|
||||
if (s.get() == ptr)
|
||||
skin = s;
|
||||
|
||||
trainset.vehicles.emplace(trainset.vehicles.begin() + position);
|
||||
dynamic_desc &desc = trainset.vehicles[position];
|
||||
|
||||
desc.name = skin->skin + "_" + std::to_string((int)LocalRandom(0.0, 10000000.0));
|
||||
desc.vehicle = skin->vehicle.lock();
|
||||
desc.skin = skin;
|
||||
|
||||
}
|
||||
ImGui::EndDragDropTarget();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user