mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-17 23:39:18 +02:00
launcher changes
This commit is contained in:
@@ -13,87 +13,183 @@ ui::scenerylist_panel::scenerylist_panel(scenery_scanner &scanner)
|
||||
{
|
||||
}
|
||||
|
||||
void ui::scenerylist_panel::draw_scenery_list()
|
||||
{
|
||||
std::string prev_prefix;
|
||||
bool collapse_open = false;
|
||||
|
||||
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())
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ui::scenerylist_panel::draw_scenery_info()
|
||||
{
|
||||
if (selected_scenery) {
|
||||
ImGui::TextWrapped("%s", selected_scenery->name.c_str());
|
||||
ImGui::TextWrapped("%s", selected_scenery->description.c_str());
|
||||
|
||||
ImGui::Separator();
|
||||
|
||||
for (auto const &link : selected_scenery->links) {
|
||||
if (ImGui::Button(link.second.c_str(), ImVec2(-1, 0)))
|
||||
open_link(link.first);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ui::scenerylist_panel::open_link(const std::string &link)
|
||||
{
|
||||
std::string file = ToLower(link);
|
||||
#ifdef _WIN32
|
||||
system(("start \"eu07_link\" \"" + file + "\"").c_str());
|
||||
#elif __linux__
|
||||
system(("xdg-open \"" + file + "\"").c_str());
|
||||
#elif __APPLE__
|
||||
system(("open \"" + file + "\"").c_str());
|
||||
#endif
|
||||
}
|
||||
|
||||
void ui::scenerylist_panel::draw_scenery_image()
|
||||
{
|
||||
if (!selected_scenery->image_path.empty()) {
|
||||
scenery_desc *desc = const_cast<scenery_desc*>(selected_scenery);
|
||||
desc->image = GfxRenderer.Fetch_Texture(selected_scenery->image_path, true);
|
||||
desc->image_path.clear();
|
||||
}
|
||||
|
||||
if (selected_scenery->image != null_handle) {
|
||||
opengl_texture &tex = GfxRenderer.Texture(selected_scenery->image);
|
||||
tex.create();
|
||||
|
||||
if (tex.is_ready) {
|
||||
float avail_width = ImGui::GetContentRegionAvailWidth();
|
||||
float height = avail_width / tex.width() * tex.height();
|
||||
|
||||
ImGui::Image(reinterpret_cast<void *>(tex.id), ImVec2(avail_width, height), ImVec2(0, 1), ImVec2(1, 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ui::scenerylist_panel::draw_launch_box()
|
||||
{
|
||||
ImGui::NextColumn();
|
||||
|
||||
ImGui::TextWrapped(selected_trainset->description.c_str());
|
||||
|
||||
if (ImGui::Button(STR_C("Launch"), ImVec2(-1, 0))) {
|
||||
if (!launch_simulation())
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
bool ui::scenerylist_panel::launch_simulation()
|
||||
{
|
||||
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.generic_string();
|
||||
|
||||
Application.pop_mode();
|
||||
Application.push_mode(eu07_application::mode::scenarioloader);
|
||||
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found)
|
||||
return false;
|
||||
|
||||
for (auto &desc : selected_scenery->trainsets)
|
||||
add_replace_entry(desc);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ui::scenerylist_panel::add_replace_entry(const trainset_desc &trainset)
|
||||
{
|
||||
std::string set = "trainset ";
|
||||
set += trainset.name + " ";
|
||||
set += trainset.track + " ";
|
||||
set += std::to_string(trainset.offset) + " ";
|
||||
set += std::to_string(trainset.velocity) + "\n";
|
||||
for (const auto &veh : 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\n";
|
||||
}
|
||||
set += "endtrainset\n";
|
||||
|
||||
Global.trainset_overrides.emplace(trainset.file_bounds.first, set);
|
||||
}
|
||||
|
||||
void ui::scenerylist_panel::draw_trainset_box()
|
||||
{
|
||||
ImGuiListClipper clipper(selected_scenery->trainsets.size());
|
||||
while (clipper.Step()) for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++)
|
||||
draw_trainset(selected_scenery->trainsets[i]);
|
||||
}
|
||||
|
||||
void ui::scenerylist_panel::render_contents()
|
||||
{
|
||||
ImGui::Columns(3);
|
||||
|
||||
if (ImGui::BeginChild("child1", ImVec2(0, -200))) {
|
||||
std::string prev_prefix;
|
||||
bool collapse_open = false;
|
||||
|
||||
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())
|
||||
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);
|
||||
}
|
||||
}
|
||||
} ImGui::EndChild();
|
||||
if (ImGui::BeginChild("child1", ImVec2(0, -200)))
|
||||
draw_scenery_list();
|
||||
ImGui::EndChild();
|
||||
|
||||
ImGui::NextColumn();
|
||||
|
||||
if (ImGui::BeginChild("child2", ImVec2(0, -200))) {
|
||||
if (selected_scenery) {
|
||||
ImGui::TextWrapped("%s", selected_scenery->name.c_str());
|
||||
ImGui::TextWrapped("%s", selected_scenery->description.c_str());
|
||||
|
||||
ImGui::Separator();
|
||||
|
||||
for (auto const &link : selected_scenery->links) {
|
||||
if (ImGui::Button(link.second.c_str(), ImVec2(-1, 0))) {
|
||||
std::string file = ToLower(link.first);
|
||||
#ifdef _WIN32
|
||||
system(("start \"eu07_link\" \"" + file + "\"").c_str());
|
||||
#elif __linux__
|
||||
system(("xdg-open \"" + file + "\"").c_str());
|
||||
#elif __APPLE__
|
||||
system(("open \"" + file + "\"").c_str());
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
} ImGui::EndChild();
|
||||
if (ImGui::BeginChild("child2", ImVec2(0, -200)))
|
||||
draw_scenery_info();
|
||||
ImGui::EndChild();
|
||||
|
||||
ImGui::NextColumn();
|
||||
|
||||
if (selected_scenery) {
|
||||
if (ImGui::BeginChild("child3", ImVec2(0, -200), false, ImGuiWindowFlags_NoScrollbar)) {
|
||||
if (!selected_scenery->image_path.empty()) {
|
||||
scenery_desc *desc = const_cast<scenery_desc*>(selected_scenery);
|
||||
desc->image = GfxRenderer.Fetch_Texture(selected_scenery->image_path, true);
|
||||
desc->image_path.clear();
|
||||
}
|
||||
|
||||
if (selected_scenery->image != null_handle) {
|
||||
opengl_texture &tex = GfxRenderer.Texture(selected_scenery->image);
|
||||
tex.create();
|
||||
|
||||
if (tex.is_ready) {
|
||||
float avail_width = ImGui::GetContentRegionAvailWidth();
|
||||
float height = avail_width / tex.width() * tex.height();
|
||||
|
||||
ImGui::Image(reinterpret_cast<void *>(tex.id), ImVec2(avail_width, height), ImVec2(0, 1), ImVec2(1, 0));
|
||||
}
|
||||
}
|
||||
} ImGui::EndChild();
|
||||
if (ImGui::BeginChild("child3", ImVec2(0, -200), false, ImGuiWindowFlags_NoScrollbar))
|
||||
draw_scenery_image();
|
||||
ImGui::EndChild();
|
||||
}
|
||||
ImGui::Columns();
|
||||
ImGui::Separator();
|
||||
@@ -103,95 +199,53 @@ void ui::scenerylist_panel::render_contents()
|
||||
if (selected_trainset)
|
||||
ImGui::Columns(2);
|
||||
|
||||
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 &trainset = selected_scenery->trainsets[i];
|
||||
ImGui::PushID(i);
|
||||
if (ImGui::Selectable("##set", selected_trainset == &trainset, 0, ImVec2(0, 30)))
|
||||
selected_trainset = &trainset;
|
||||
ImGui::SameLine();
|
||||
draw_trainset(trainset);
|
||||
ImGui::NewLine();
|
||||
ImGui::PopID();
|
||||
//ImGui::Selectable(z.c_str(), false);
|
||||
}
|
||||
} ImGui::EndChild();
|
||||
if (ImGui::BeginChild("child5", ImVec2(0, 0), false, ImGuiWindowFlags_HorizontalScrollbar))
|
||||
draw_trainset_box();
|
||||
ImGui::EndChild();
|
||||
|
||||
if (selected_trainset) {
|
||||
ImGui::NextColumn();
|
||||
|
||||
ImGui::TextWrapped(selected_trainset->description.c_str());
|
||||
|
||||
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.generic_string();
|
||||
|
||||
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) + "\n";
|
||||
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\n";
|
||||
}
|
||||
set += "endtrainset\n";
|
||||
|
||||
Global.trainset_overrides.emplace(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();
|
||||
}
|
||||
}
|
||||
if (selected_trainset)
|
||||
draw_launch_box();
|
||||
}
|
||||
} ImGui::EndChild();
|
||||
}
|
||||
|
||||
void ui::scenerylist_panel::draw_summary_tooltip(const dynamic_desc &dyn_desc)
|
||||
{
|
||||
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::Text(STR_C("Type: %s"), name.c_str());
|
||||
ImGui::Text(STR_C("Skin: %s"), skin.c_str());
|
||||
ImGui::NewLine();
|
||||
|
||||
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();
|
||||
|
||||
ImGui::TextUnformatted(STR_C("Coupling:"));
|
||||
|
||||
for (int i = 1; i <= 0x100; i <<= 1) {
|
||||
bool dummy = true;
|
||||
|
||||
if (dyn_desc.coupling & i)
|
||||
ImGui::Text("+ %s", Translations.coupling_name(i).c_str(), &dummy);
|
||||
}
|
||||
}
|
||||
|
||||
void ui::scenerylist_panel::draw_trainset(trainset_desc &trainset)
|
||||
{
|
||||
ImGui::SetItemAllowOverlap();
|
||||
ImGui::PushID(&trainset);
|
||||
if (ImGui::Selectable("##set", selected_trainset == &trainset, 0, ImVec2(0, 30)))
|
||||
selected_trainset = &trainset;
|
||||
ImGui::SameLine();
|
||||
|
||||
static std::unordered_map<coupling, std::string> coupling_names =
|
||||
{
|
||||
{ coupling::faux, STRN("faux") },
|
||||
{ coupling::coupler, STRN("coupler") },
|
||||
{ coupling::brakehose, STRN("brake hose") },
|
||||
{ coupling::control, STRN("control") },
|
||||
{ coupling::highvoltage, STRN("high voltage") },
|
||||
{ coupling::gangway, STRN("gangway") },
|
||||
{ coupling::mainhose, STRN("main hose") },
|
||||
{ coupling::heating, STRN("heating") },
|
||||
{ coupling::permanent, STRN("permanent") },
|
||||
{ coupling::uic, STRN("uic") }
|
||||
};
|
||||
ImGui::SetItemAllowOverlap();
|
||||
|
||||
int position = 0;
|
||||
|
||||
@@ -234,37 +288,7 @@ void ui::scenerylist_panel::draw_trainset(trainset_desc &trainset)
|
||||
}
|
||||
else 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::Text(STR_C("Type: %s"), name.c_str());
|
||||
ImGui::Text(STR_C("Skin: %s"), skin.c_str());
|
||||
ImGui::NewLine();
|
||||
|
||||
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();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
draw_summary_tooltip(dyn_desc);
|
||||
ImGui::EndTooltip();
|
||||
}
|
||||
|
||||
@@ -277,6 +301,9 @@ void ui::scenerylist_panel::draw_trainset(trainset_desc &trainset)
|
||||
|
||||
ImGui::PopID();
|
||||
}
|
||||
|
||||
ImGui::NewLine();
|
||||
ImGui::PopID();
|
||||
}
|
||||
|
||||
void ui::scenerylist_panel::draw_droptarget(trainset_desc &trainset, int position)
|
||||
@@ -297,7 +324,6 @@ void ui::scenerylist_panel::draw_droptarget(trainset_desc &trainset, int positio
|
||||
desc.name = skin->skin + "_" + std::to_string((int)LocalRandom(0.0, 10000000.0));
|
||||
desc.vehicle = skin->vehicle.lock();
|
||||
desc.skin = skin;
|
||||
|
||||
}
|
||||
|
||||
payload = ImGui::AcceptDragDropPayload("vehicle_set");
|
||||
@@ -330,20 +356,6 @@ ui::dynamic_edit_popup::dynamic_edit_popup(ui_panel &panel, dynamic_desc &dynami
|
||||
|
||||
void ui::dynamic_edit_popup::render_content()
|
||||
{
|
||||
static std::unordered_map<coupling, std::string> coupling_names =
|
||||
{
|
||||
{ coupling::faux, STRN("faux") },
|
||||
{ coupling::coupler, STRN("coupler") },
|
||||
{ coupling::brakehose, STRN("brake hose") },
|
||||
{ coupling::control, STRN("control") },
|
||||
{ coupling::highvoltage, STRN("high voltage") },
|
||||
{ coupling::gangway, STRN("gangway") },
|
||||
{ coupling::mainhose, STRN("main hose") },
|
||||
{ coupling::heating, STRN("heating") },
|
||||
{ coupling::permanent, STRN("permanent") },
|
||||
{ coupling::uic, STRN("uic") }
|
||||
};
|
||||
|
||||
static std::vector<std::string> occupancy_names = {
|
||||
STRN("headdriver"),
|
||||
STRN("reardriver"),
|
||||
@@ -406,11 +418,7 @@ void ui::dynamic_edit_popup::render_content()
|
||||
for (int i = 1; i <= 0x100; i <<= 1) {
|
||||
bool selected = dynamic.coupling & i;
|
||||
|
||||
std::string label = STRN("unknown");
|
||||
auto it = coupling_names.find(static_cast<coupling>(i));
|
||||
if (it != coupling_names.end())
|
||||
label = it->second;
|
||||
if (ImGui::Checkbox(Translations.lookup_c(label.c_str()), &selected))
|
||||
if (ImGui::Checkbox(Translations.coupling_name(i).c_str(), &selected))
|
||||
dynamic.coupling ^= i;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,6 +51,16 @@ private:
|
||||
trainset_desc *selected_trainset = nullptr;
|
||||
deferred_image placeholder_mini;
|
||||
|
||||
void draw_scenery_list();
|
||||
void draw_scenery_info();
|
||||
void draw_scenery_image();
|
||||
void draw_launch_box();
|
||||
void draw_trainset_box();
|
||||
bool launch_simulation();
|
||||
void add_replace_entry(const trainset_desc &trainset);
|
||||
void draw_summary_tooltip(const dynamic_desc &dyn_desc);
|
||||
|
||||
void open_link(const std::string &link);
|
||||
void draw_trainset(trainset_desc &trainset);
|
||||
void draw_droptarget(trainset_desc &trainset, int position);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user