16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-22 16:19:19 +02:00

launcher changes

This commit is contained in:
milek7
2019-09-21 23:25:48 +02:00
parent fbfafc4267
commit d0d7fa6738
4 changed files with 247 additions and 202 deletions

View File

@@ -13,11 +13,8 @@ ui::scenerylist_panel::scenerylist_panel(scenery_scanner &scanner)
{ {
} }
void ui::scenerylist_panel::render_contents() void ui::scenerylist_panel::draw_scenery_list()
{ {
ImGui::Columns(3);
if (ImGui::BeginChild("child1", ImVec2(0, -200))) {
std::string prev_prefix; std::string prev_prefix;
bool collapse_open = false; bool collapse_open = false;
@@ -46,11 +43,10 @@ void ui::scenerylist_panel::render_contents()
ImGui::Unindent(10.0f); ImGui::Unindent(10.0f);
} }
} }
} ImGui::EndChild(); }
ImGui::NextColumn(); void ui::scenerylist_panel::draw_scenery_info()
{
if (ImGui::BeginChild("child2", ImVec2(0, -200))) {
if (selected_scenery) { if (selected_scenery) {
ImGui::TextWrapped("%s", selected_scenery->name.c_str()); ImGui::TextWrapped("%s", selected_scenery->name.c_str());
ImGui::TextWrapped("%s", selected_scenery->description.c_str()); ImGui::TextWrapped("%s", selected_scenery->description.c_str());
@@ -58,8 +54,15 @@ void ui::scenerylist_panel::render_contents()
ImGui::Separator(); ImGui::Separator();
for (auto const &link : selected_scenery->links) { for (auto const &link : selected_scenery->links) {
if (ImGui::Button(link.second.c_str(), ImVec2(-1, 0))) { if (ImGui::Button(link.second.c_str(), ImVec2(-1, 0)))
std::string file = ToLower(link.first); open_link(link.first);
}
}
}
void ui::scenerylist_panel::open_link(const std::string &link)
{
std::string file = ToLower(link);
#ifdef _WIN32 #ifdef _WIN32
system(("start \"eu07_link\" \"" + file + "\"").c_str()); system(("start \"eu07_link\" \"" + file + "\"").c_str());
#elif __linux__ #elif __linux__
@@ -68,14 +71,9 @@ void ui::scenerylist_panel::render_contents()
system(("open \"" + file + "\"").c_str()); system(("open \"" + file + "\"").c_str());
#endif #endif
} }
}
}
} ImGui::EndChild();
ImGui::NextColumn(); void ui::scenerylist_panel::draw_scenery_image()
{
if (selected_scenery) {
if (ImGui::BeginChild("child3", ImVec2(0, -200), false, ImGuiWindowFlags_NoScrollbar)) {
if (!selected_scenery->image_path.empty()) { if (!selected_scenery->image_path.empty()) {
scenery_desc *desc = const_cast<scenery_desc*>(selected_scenery); scenery_desc *desc = const_cast<scenery_desc*>(selected_scenery);
desc->image = GfxRenderer.Fetch_Texture(selected_scenery->image_path, true); desc->image = GfxRenderer.Fetch_Texture(selected_scenery->image_path, true);
@@ -93,49 +91,60 @@ void ui::scenerylist_panel::render_contents()
ImGui::Image(reinterpret_cast<void *>(tex.id), ImVec2(avail_width, height), ImVec2(0, 1), ImVec2(1, 0)); ImGui::Image(reinterpret_cast<void *>(tex.id), ImVec2(avail_width, height), ImVec2(0, 1), ImVec2(1, 0));
} }
} }
} ImGui::EndChild();
} }
ImGui::Columns();
ImGui::Separator();
if (ImGui::BeginChild("child4")) { void ui::scenerylist_panel::draw_launch_box()
if (selected_scenery) { {
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 (selected_trainset) {
ImGui::NextColumn(); ImGui::NextColumn();
ImGui::TextWrapped(selected_trainset->description.c_str()); ImGui::TextWrapped(selected_trainset->description.c_str());
if (ImGui::Button(STR_C("Launch"), ImVec2(-1, 0))) { 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; bool found = false;
for (auto &veh : selected_trainset->vehicles) { for (auto &veh : selected_trainset->vehicles) {
if (veh.drivertype.size() > 0 && veh.drivertype != "nobody") { if (veh.drivertype.size() > 0 && veh.drivertype != "nobody") {
Global.local_start_vehicle = ToLower(veh.name); Global.local_start_vehicle = ToLower(veh.name);
Global.SceneryFile = selected_scenery->path.generic_string(); 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 "; std::string set = "trainset ";
set += selected_trainset->name + " "; set += trainset.name + " ";
set += selected_trainset->track + " "; set += trainset.track + " ";
set += std::to_string(selected_trainset->offset) + " "; set += std::to_string(trainset.offset) + " ";
set += std::to_string(selected_trainset->velocity) + "\n"; set += std::to_string(trainset.velocity) + "\n";
for (const auto &veh : selected_trainset->vehicles) { for (const auto &veh : trainset.vehicles) {
set += "node -1 0 " + veh.name + " dynamic "; set += "node -1 0 " + veh.name + " dynamic ";
set += veh.vehicle->path.parent_path().generic_string() + " "; set += veh.vehicle->path.parent_path().generic_string() + " ";
set += veh.skin->skin + " "; set += veh.skin->skin + " ";
@@ -151,47 +160,92 @@ void ui::scenerylist_panel::render_contents()
} }
set += "endtrainset\n"; set += "endtrainset\n";
Global.trainset_overrides.emplace(selected_trainset->file_bounds.first, set); Global.trainset_overrides.emplace(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")) { void ui::scenerylist_panel::draw_trainset_box()
ImGui::TextUnformatted(STR_C("Trainset not occupied")); {
if (ImGui::Button(STR_C("OK"), ImVec2(-1, 0))) ImGuiListClipper clipper(selected_scenery->trainsets.size());
ImGui::CloseCurrentPopup(); while (clipper.Step()) for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++)
ImGui::EndPopup(); draw_trainset(selected_scenery->trainsets[i]);
} }
void ui::scenerylist_panel::render_contents()
{
ImGui::Columns(3);
if (ImGui::BeginChild("child1", ImVec2(0, -200)))
draw_scenery_list();
ImGui::EndChild();
ImGui::NextColumn();
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))
draw_scenery_image();
ImGui::EndChild();
} }
ImGui::Columns();
ImGui::Separator();
if (ImGui::BeginChild("child4")) {
if (selected_scenery) {
if (selected_trainset)
ImGui::Columns(2);
if (ImGui::BeginChild("child5", ImVec2(0, 0), false, ImGuiWindowFlags_HorizontalScrollbar))
draw_trainset_box();
ImGui::EndChild();
if (selected_trainset)
draw_launch_box();
} }
} ImGui::EndChild(); } 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) 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 = ImGui::SetItemAllowOverlap();
{
{ 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") }
};
int position = 0; int position = 0;
@@ -234,37 +288,7 @@ void ui::scenerylist_panel::draw_trainset(trainset_desc &trainset)
} }
else if (ImGui::IsItemHovered()) { else if (ImGui::IsItemHovered()) {
ImGui::BeginTooltip(); ImGui::BeginTooltip();
std::string name = (dyn_desc.vehicle->path.parent_path() / dyn_desc.vehicle->path.stem()).string(); draw_summary_tooltip(dyn_desc);
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);
}
}
ImGui::EndTooltip(); ImGui::EndTooltip();
} }
@@ -277,6 +301,9 @@ void ui::scenerylist_panel::draw_trainset(trainset_desc &trainset)
ImGui::PopID(); ImGui::PopID();
} }
ImGui::NewLine();
ImGui::PopID();
} }
void ui::scenerylist_panel::draw_droptarget(trainset_desc &trainset, int position) 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.name = skin->skin + "_" + std::to_string((int)LocalRandom(0.0, 10000000.0));
desc.vehicle = skin->vehicle.lock(); desc.vehicle = skin->vehicle.lock();
desc.skin = skin; desc.skin = skin;
} }
payload = ImGui::AcceptDragDropPayload("vehicle_set"); 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() 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 = { static std::vector<std::string> occupancy_names = {
STRN("headdriver"), STRN("headdriver"),
STRN("reardriver"), STRN("reardriver"),
@@ -406,11 +418,7 @@ void ui::dynamic_edit_popup::render_content()
for (int i = 1; i <= 0x100; i <<= 1) { for (int i = 1; i <= 0x100; i <<= 1) {
bool selected = dynamic.coupling & i; bool selected = dynamic.coupling & i;
std::string label = STRN("unknown"); if (ImGui::Checkbox(Translations.coupling_name(i).c_str(), &selected))
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))
dynamic.coupling ^= i; dynamic.coupling ^= i;
} }
} }

View File

@@ -51,6 +51,16 @@ private:
trainset_desc *selected_trainset = nullptr; trainset_desc *selected_trainset = nullptr;
deferred_image placeholder_mini; 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_trainset(trainset_desc &trainset);
void draw_droptarget(trainset_desc &trainset, int position); void draw_droptarget(trainset_desc &trainset, int position);
}; };

View File

@@ -15,6 +15,7 @@ http://mozilla.org/MPL/2.0/.
#include "translation.h" #include "translation.h"
#include "Logs.h" #include "Logs.h"
#include "Globals.h" #include "Globals.h"
#include "MOVER.h"
void locale::init() void locale::init()
{ {
@@ -285,4 +286,29 @@ std::string locale::label_cab_control(std::string const &Label)
"" ); "" );
} }
const std::string& locale::coupling_name(int c)
{
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::string unknown(STRN("unknown"));
auto it = coupling_names.find(static_cast<coupling>(c));
if (it != coupling_names.end())
return lookup_s(it->second);
else
return lookup_s(unknown);
}
locale Translations; locale Translations;

View File

@@ -16,6 +16,7 @@ class locale {
public: public:
void init(); void init();
std::string label_cab_control(const std::string &Label); std::string label_cab_control(const std::string &Label);
const std::string &coupling_name(int c);
const char* lookup_c(const char *msg, bool constant = false); const char* lookup_c(const char *msg, bool constant = false);
const std::string& lookup_s(const std::string &msg, bool constant = false); const std::string& lookup_s(const std::string &msg, bool constant = false);