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

move vehicle param window to vehicle list, add radiostop button

This commit is contained in:
milek7
2019-03-16 20:51:51 +01:00
parent 20652829b1
commit 16570f8d23
21 changed files with 130 additions and 81 deletions

View File

@@ -129,7 +129,6 @@ set(SOURCES
"widgets/popup.cpp" "widgets/popup.cpp"
"widgets/time.cpp" "widgets/time.cpp"
"widgets/vehicleparams.cpp" "widgets/vehicleparams.cpp"
"widgets/trainingcontrol.cpp"
"ref/glad/src/glad.c" "ref/glad/src/glad.c"

View File

@@ -479,10 +479,8 @@ private:
int GetPneumatic(bool front, bool red); int GetPneumatic(bool front, bool red);
void SetPneumatic(bool front, bool red); void SetPneumatic(bool front, bool red);
std::string asName; std::string asName;
std::string name() const { const std::string &name() const {
return this ? return asName; }
asName :
std::string(); };
std::string asBaseDir; std::string asBaseDir;
// std::ofstream PneuLogFile; //zapis parametrow pneumatycznych // std::ofstream PneuLogFile; //zapis parametrow pneumatycznych

View File

@@ -5013,7 +5013,7 @@ void TTrain::vehiclemove(float distance) {
while( d ) { while( d ) {
d->Move( distance * d->DirectionGet() ); d->Move( distance * d->DirectionGet() );
d = d->Next(); // pozostałe też d = d->Next(); // pozostałe też
} }
d = DynamicObject->Prev(); d = DynamicObject->Prev();
while( d ) { while( d ) {
d->Move( distance * d->DirectionGet() ); d->Move( distance * d->DirectionGet() );

View File

@@ -229,6 +229,7 @@ commanddescription_sequence Commands_descriptions = {
{ "motorblowersdisableall", command_target::vehicle, command_mode::oneoff }, { "motorblowersdisableall", command_target::vehicle, command_mode::oneoff },
{ "coolingfanstoggle", command_target::vehicle, command_mode::oneoff }, { "coolingfanstoggle", command_target::vehicle, command_mode::oneoff },
{ "tempomattoggle", command_target::vehicle, command_mode::oneoff }, { "tempomattoggle", command_target::vehicle, command_mode::oneoff },
{ "globalradiostop", command_target::simulation, command_mode::oneoff },
{ "timejump", command_target::simulation, command_mode::oneoff }, { "timejump", command_target::simulation, command_mode::oneoff },
{ "timejumplarge", command_target::simulation, command_mode::oneoff }, { "timejumplarge", command_target::simulation, command_mode::oneoff },
{ "timejumpsmall", command_target::simulation, command_mode::oneoff }, { "timejumpsmall", command_target::simulation, command_mode::oneoff },
@@ -243,6 +244,7 @@ commanddescription_sequence Commands_descriptions = {
{ "focuspauseset", command_target::simulation, command_mode::oneoff }, { "focuspauseset", command_target::simulation, command_mode::oneoff },
{ "pausetoggle", command_target::simulation, command_mode::oneoff }, { "pausetoggle", command_target::simulation, command_mode::oneoff },
{ "entervehicle", command_target::simulation, command_mode::oneoff }, { "entervehicle", command_target::simulation, command_mode::oneoff },
{ "resettrainset", command_target::simulation, command_mode::oneoff },
{ "queueevent", command_target::simulation, command_mode::oneoff }, { "queueevent", command_target::simulation, command_mode::oneoff },
{ "setlight", command_target::simulation, command_mode::oneoff }, { "setlight", command_target::simulation, command_mode::oneoff },
{ "insertmodel", command_target::simulation, command_mode::oneoff }, { "insertmodel", command_target::simulation, command_mode::oneoff },

View File

@@ -223,6 +223,7 @@ enum class user_command {
coolingfanstoggle, coolingfanstoggle,
tempomattoggle, tempomattoggle,
radiostop,
timejump, timejump,
timejumplarge, timejumplarge,
timejumpsmall, timejumpsmall,
@@ -237,6 +238,7 @@ enum class user_command {
focuspauseset, focuspauseset,
pausetoggle, pausetoggle,
entervehicle, entervehicle,
resettrainset,
queueevent, queueevent,
setlight, setlight,
insertmodel, insertmodel,

View File

@@ -22,17 +22,16 @@ driver_ui::driver_ui() {
clear_panels(); clear_panels();
// bind the panels with ui object. maybe not the best place for this but, eh // bind the panels with ui object. maybe not the best place for this but, eh
push_back( &m_aidpanel ); add_external_panel( &m_aidpanel );
push_back( &m_scenariopanel ); add_external_panel( &m_scenariopanel );
push_back( &m_timetablepanel ); add_external_panel( &m_timetablepanel );
push_back( &m_debugpanel ); add_external_panel( &m_debugpanel );
push_back( &m_transcriptspanel ); add_external_panel( &m_transcriptspanel );
//push_back( &m_vehiclelist ); add_external_panel( &m_vehiclelist );
push_back( &m_vehicleparams ); add_external_panel( &m_timepanel );
push_back( &m_timepanel ); add_external_panel( &m_mappanel );
push_back( &m_mappanel ); add_external_panel( &m_logpanel );
push_back( &m_logpanel );
m_logpanel.is_open = false; m_logpanel.is_open = false;
m_aidpanel.title = locale::strings[ locale::string::driver_aid_header ]; m_aidpanel.title = locale::strings[ locale::string::driver_aid_header ];
@@ -57,14 +56,13 @@ void driver_ui::render_menu_contents() {
{ {
ImGui::MenuItem(m_aidpanel.title.c_str(), "F1", &m_aidpanel.is_open); ImGui::MenuItem(m_aidpanel.title.c_str(), "F1", &m_aidpanel.is_open);
ImGui::MenuItem(locale::strings[locale::string::driver_timetable_name].c_str(), "F2", &m_timetablepanel.is_open); ImGui::MenuItem(locale::strings[locale::string::driver_timetable_name].c_str(), "F2", &m_timetablepanel.is_open);
ImGui::MenuItem(m_debugpanel.get_name().c_str(), "F12", &m_debugpanel.is_open); ImGui::MenuItem(m_debugpanel.name().c_str(), "F12", &m_debugpanel.is_open);
ImGui::MenuItem(m_mappanel.get_name().c_str(), "Tab", &m_mappanel.is_open); ImGui::MenuItem(m_mappanel.name().c_str(), "Tab", &m_mappanel.is_open);
ImGui::MenuItem(m_vehiclelist.name().c_str(), nullptr, &m_vehiclelist.is_open);
if (ImGui::MenuItem(m_timepanel.get_name().c_str())) if (ImGui::MenuItem(m_timepanel.name().c_str()))
m_timepanel.open(); m_timepanel.open();
ImGui::MenuItem(m_vehicleparams.get_name().c_str(), nullptr, &m_vehicleparams.is_open);
ImGui::EndMenu(); ImGui::EndMenu();
} }
} }

View File

@@ -59,8 +59,7 @@ private:
bool m_pause_modal_opened { false }; bool m_pause_modal_opened { false };
command_relay m_relay; command_relay m_relay;
ui::vehiclelist_panel m_vehiclelist; ui::vehiclelist_panel m_vehiclelist { ui::vehiclelist_panel(*this) };
ui::vehicleparams_panel m_vehicleparams;
ui::map_panel m_mappanel; ui::map_panel m_mappanel;
ui::time_panel m_timepanel; ui::time_panel m_timepanel;
}; };

View File

@@ -195,9 +195,9 @@ scenario_panel::render() {
} }
auto const panelname { ( auto const panelname { (
title.empty() ? title.empty() ?
name : m_name :
title ) title )
+ "###" + name }; + "###" + m_name };
if( true == ImGui::Begin( panelname.c_str(), &is_open, flags ) ) { if( true == ImGui::Begin( panelname.c_str(), &is_open, flags ) ) {
// potential assignment section // potential assignment section
auto const *owner { ( auto const *owner { (
@@ -442,9 +442,9 @@ debug_panel::render() {
} }
auto const panelname { ( auto const panelname { (
title.empty() ? title.empty() ?
name : m_name :
title ) title )
+ "###" + name }; + "###" + m_name };
if( true == ImGui::Begin( panelname.c_str(), &is_open, flags ) ) { if( true == ImGui::Begin( panelname.c_str(), &is_open, flags ) ) {
// header section // header section
for( auto const &line : text_lines ) { for( auto const &line : text_lines ) {
@@ -1028,9 +1028,9 @@ transcripts_panel::render() {
} }
auto const panelname { ( auto const panelname { (
title.empty() ? title.empty() ?
name : m_name :
title ) title )
+ "###" + name }; + "###" + m_name };
if( true == ImGui::Begin( panelname.c_str(), &is_open, flags ) ) { if( true == ImGui::Begin( panelname.c_str(), &is_open, flags ) ) {
// header section // header section
for( auto const &line : text_lines ) { for( auto const &line : text_lines ) {

View File

@@ -17,8 +17,8 @@ editor_ui::editor_ui() {
clear_panels(); clear_panels();
// bind the panels with ui object. maybe not the best place for this but, eh // bind the panels with ui object. maybe not the best place for this but, eh
push_back( &m_itempropertiespanel ); add_external_panel( &m_itempropertiespanel );
push_back( &m_nodebankpanel ); add_external_panel( &m_nodebankpanel );
} }
// potentially processes provided input key. returns: true if key was processed, false otherwise // potentially processes provided input key. returns: true if key was processed, false otherwise

View File

@@ -253,9 +253,9 @@ itemproperties_panel::render() {
} }
auto const panelname { ( auto const panelname { (
title.empty() ? title.empty() ?
name : m_name :
title ) title )
+ "###" + name }; + "###" + m_name };
if( true == ImGui::Begin( panelname.c_str(), nullptr, flags ) ) { if( true == ImGui::Begin( panelname.c_str(), nullptr, flags ) ) {
// header section // header section
for( auto const &line : text_lines ) { for( auto const &line : text_lines ) {

View File

@@ -177,6 +177,32 @@ void state_manager::process_commands() {
simulation::State.delete_model(simulation::Instances.find(commanddata.payload)); simulation::State.delete_model(simulation::Instances.find(commanddata.payload));
} }
if (commanddata.command == user_command::radiostop) {
simulation::Region->RadioStop( commanddata.location );
}
if (commanddata.command == user_command::resettrainset) {
TDynamicObject *found_vehicle = simulation::Vehicles.find(commanddata.payload);
TDynamicObject *vehicle = found_vehicle;
while (vehicle) {
vehicle->MoverParameters->DamageFlag = 0;
vehicle->MoverParameters->EngDmgFlag = 0;
vehicle->MoverParameters->V = 0.0;
vehicle->MoverParameters->DistCounter = 0.0;
vehicle = vehicle->Next();
}
vehicle = found_vehicle;
while (vehicle) {
vehicle->MoverParameters->DamageFlag = 0;
vehicle->MoverParameters->EngDmgFlag = 0;
vehicle->MoverParameters->V = 0.0;
vehicle->MoverParameters->DistCounter = 0.0;
vehicle = vehicle->Prev();
}
}
if (DebugModeFlag) { if (DebugModeFlag) {
if (commanddata.command == user_command::timejump) { if (commanddata.command == user_command::timejump) {
Time.update(commanddata.param1); Time.update(commanddata.param1);

View File

@@ -110,7 +110,11 @@ init() {
"Insert obstacle:", "Insert obstacle:",
"Delete obstacle", "Delete obstacle",
"Vehicle list",
"Vehicle parameters", "Vehicle parameters",
"Radiostop",
"Reset trainset",
"master controller", "master controller",
"master controller", "master controller",
@@ -307,7 +311,11 @@ init() {
u8"Wstaw przeszkodę:", u8"Wstaw przeszkodę:",
u8"Usuń przeszkodę", u8"Usuń przeszkodę",
u8"Lista pojazdów",
u8"Parametry pojazdu", u8"Parametry pojazdu",
u8"Radiostop",
u8"Zresetuj skład",
u8"nastawnik jazdy", u8"nastawnik jazdy",
u8"nastawnik jazdy", u8"nastawnik jazdy",

View File

@@ -99,7 +99,11 @@ enum string {
map_obstacle_insert, map_obstacle_insert,
map_obstacle_remove, map_obstacle_remove,
vehiclelist_window,
vehicleparams_window, vehicleparams_window,
vehicleparams_radiostop,
vehicleparams_reset,
cab_mainctrl, cab_mainctrl,
cab_jointctrl, cab_jointctrl,

View File

@@ -29,7 +29,7 @@ GLFWwindow *ui_layer::m_window{nullptr};
ImGuiIO *ui_layer::m_imguiio{nullptr}; ImGuiIO *ui_layer::m_imguiio{nullptr};
bool ui_layer::m_cursorvisible; bool ui_layer::m_cursorvisible;
ui_panel::ui_panel(std::string const &Identifier, bool const Isopen) : name(Identifier), is_open(Isopen) {} ui_panel::ui_panel(std::string const &Identifier, bool const Isopen) : m_name(Identifier), is_open(Isopen) {}
void ui_panel::render() void ui_panel::render()
{ {
@@ -49,7 +49,7 @@ void ui_panel::render()
if (size_min.x > 0) if (size_min.x > 0)
ImGui::SetNextWindowSizeConstraints(ImVec2(size_min.x, size_min.y), ImVec2(size_max.x, size_max.y)); ImGui::SetNextWindowSizeConstraints(ImVec2(size_min.x, size_min.y), ImVec2(size_max.x, size_max.y));
auto const panelname{(title.empty() ? name : title) + "###" + name}; auto const panelname{(title.empty() ? m_name : title) + "###" + m_name};
if (ImGui::Begin(panelname.c_str(), &is_open, flags)) { if (ImGui::Begin(panelname.c_str(), &is_open, flags)) {
render_contents(); render_contents();
@@ -118,7 +118,7 @@ bool ui_layer::mouse_button_callback(int button, int action, int mods)
ui_layer::ui_layer() ui_layer::ui_layer()
{ {
if (Global.loading_log) if (Global.loading_log)
push_back(&m_logpanel); add_external_panel(&m_logpanel);
m_logpanel.size = { 700, 400 }; m_logpanel.size = { 700, 400 };
} }
@@ -221,9 +221,13 @@ bool ui_layer::on_mouse_button(int const Button, int const Action)
void ui_layer::update() void ui_layer::update()
{ {
for (auto *panel : m_panels) for (auto *panel : m_panels)
{
panel->update(); panel->update();
}
for (auto it = m_ownedpanels.rbegin(); it != m_ownedpanels.rend(); it++) {
(*it)->update();
if (!(*it)->is_open)
m_ownedpanels.erase(std::next(it).base());
}
} }
void ui_layer::render() void ui_layer::render()
@@ -301,6 +305,19 @@ void ui_layer::set_background(std::string const &Filename)
void ui_layer::clear_panels() void ui_layer::clear_panels()
{ {
m_panels.clear(); m_panels.clear();
m_ownedpanels.clear();
}
void ui_layer::add_owned_panel(ui_panel *Panel)
{
for (auto &panel : m_ownedpanels)
if (panel->name() == Panel->name()) {
delete Panel;
return;
}
Panel->is_open = true;
m_ownedpanels.emplace_back( Panel );
} }
void ui_layer::render_progress() void ui_layer::render_progress()
@@ -322,9 +339,9 @@ void ui_layer::render_progress()
void ui_layer::render_panels() void ui_layer::render_panels()
{ {
for (auto *panel : m_panels) for (auto *panel : m_panels)
{
panel->render(); panel->render();
} for (auto &panel : m_ownedpanels)
panel->render();
} }
void ui_layer::render_tooltip() void ui_layer::render_tooltip()

View File

@@ -48,12 +48,12 @@ public:
std::deque<text_line> text_lines; std::deque<text_line> text_lines;
int window_flags = -1; int window_flags = -1;
const std::string& get_name() { return name; } const std::string& name() { return m_name; }
void register_popup(std::unique_ptr<ui::popup> &&popup); void register_popup(std::unique_ptr<ui::popup> &&popup);
protected: protected:
// members // members
std::string name; std::string m_name;
std::list<std::unique_ptr<ui::popup>> popups; std::list<std::unique_ptr<ui::popup>> popups;
}; };
@@ -128,7 +128,9 @@ public:
void void
clear_panels(); clear_panels();
void void
push_back( ui_panel *Panel ) { m_panels.emplace_back( Panel ); } add_external_panel( ui_panel *Panel ) { m_panels.emplace_back( Panel ); }
void
add_owned_panel( ui_panel *Panel );
// callback functions for imgui input // callback functions for imgui input
// returns true if input is consumed // returns true if input is consumed
@@ -180,6 +182,7 @@ private:
texture_handle m_background { null_handle }; // path to texture used as the background. size depends on mAspect. texture_handle m_background { null_handle }; // path to texture used as the background. size depends on mAspect.
std::vector<ui_panel *> m_panels; std::vector<ui_panel *> m_panels;
std::vector<std::unique_ptr<ui_panel>> m_ownedpanels;
std::string m_tooltip; std::string m_tooltip;
bool m_quit_active = false; bool m_quit_active = false;
}; };

View File

@@ -1,5 +0,0 @@
#include "widgets/trainingcontrol.h"
void ui::trainingcontrol_panel::render_contents() {
}

View File

@@ -1,10 +0,0 @@
#include "uilayer.h"
namespace ui
{
class trainingcontrol_panel : public ui_panel
{
public:
void render_contents() override;
};
} // namespace ui

View File

@@ -2,12 +2,19 @@
#include "widgets/vehiclelist.h" #include "widgets/vehiclelist.h"
#include "simulation.h" #include "simulation.h"
#include "Driver.h" #include "Driver.h"
#include "widgets/vehicleparams.h"
ui::vehiclelist_panel::vehiclelist_panel(ui_layer &parent)
: ui_panel(LOC_STR(vehiclelist_window), false), m_parent(parent)
{
}
void ui::vehiclelist_panel::render_contents() void ui::vehiclelist_panel::render_contents()
{ {
for (TDynamicObject *vehicle : simulation::Vehicles.sequence()) for (TDynamicObject *vehicle : simulation::Vehicles.sequence())
{ {
if (vehicle->Prev()) if (!vehicle->Mechanik)
continue; continue;
std::string name = vehicle->name(); std::string name = vehicle->name();
@@ -16,20 +23,13 @@ void ui::vehiclelist_panel::render_contents()
if (vehicle->Mechanik) if (vehicle->Mechanik)
timetable = vehicle->Mechanik->TrainName() + ", "; timetable = vehicle->Mechanik->TrainName() + ", ";
std::string label = std::string(name + ", " + timetable + std::to_string(speed) + " km/h"); std::string label = std::string(name + ", " + timetable + std::to_string(speed) + " km/h###");
if (!vehicle->Next())
ImGui::TextUnformatted(label.c_str());
else if (ImGui::TreeNode(vehicle, label.c_str()))
{
vehicle = vehicle->Next();
while (vehicle)
{
ImGui::TextUnformatted(vehicle->name().c_str());
vehicle = vehicle->Next();
}
ImGui::TreePop();
}
}
// ImGui::ShowDemoWindow(); ImGui::PushID(vehicle);
if (ImGui::Button(label.c_str())) {
ui_panel *panel = new vehicleparams_panel(vehicle->name());
m_parent.add_owned_panel(panel);
}
ImGui::PopID();
}
} }

View File

@@ -4,8 +4,10 @@ namespace ui
{ {
class vehiclelist_panel : public ui_panel class vehiclelist_panel : public ui_panel
{ {
ui_layer &m_parent;
public: public:
vehiclelist_panel() : ui_panel("Vehicle list", true) {} vehiclelist_panel(ui_layer &parent);
void render_contents() override; void render_contents() override;
}; };

View File

@@ -5,17 +5,14 @@
#include "Driver.h" #include "Driver.h"
#include "Train.h" #include "Train.h"
ui::vehicleparams_panel::vehicleparams_panel() ui::vehicleparams_panel::vehicleparams_panel(const std::string &vehicle)
: ui_panel(LOC_STR(vehicleparams_window), false) : ui_panel(std::string(LOC_STR(vehicleparams_window)) + ": " + vehicle, false), m_vehicle_name(vehicle)
{ {
} }
void ui::vehicleparams_panel::render_contents() void ui::vehicleparams_panel::render_contents()
{ {
if (m_vehicle_name.empty())
m_vehicle_name = simulation::Vehicles.sequence()[0]->name();
TDynamicObject *vehicle_ptr = simulation::Vehicles.find(m_vehicle_name); TDynamicObject *vehicle_ptr = simulation::Vehicles.find(m_vehicle_name);
if (!vehicle_ptr) { if (!vehicle_ptr) {
is_open = false; is_open = false;
@@ -186,4 +183,12 @@ void ui::vehicleparams_panel::render_contents()
vehicle.GetPosition().z ); vehicle.GetPosition().z );
ImGui::TextUnformatted(buffer.data()); ImGui::TextUnformatted(buffer.data());
if (ImGui::Button(LOC_STR(vehicleparams_radiostop)))
m_relay.post(user_command::radiostop, 0.0, 0.0, GLFW_PRESS, 0, vehicle_ptr->GetPosition());
ImGui::SameLine();
if (ImGui::Button(LOC_STR(vehicleparams_reset)))
m_relay.post(user_command::resettrainset, 0.0, 0.0, GLFW_PRESS, 0, glm::vec3(0.0f), &vehicle_ptr->name());
} }

View File

@@ -7,9 +7,10 @@ namespace ui
class vehicleparams_panel : public ui_panel class vehicleparams_panel : public ui_panel
{ {
std::string m_vehicle_name; std::string m_vehicle_name;
command_relay m_relay;
public: public:
vehicleparams_panel(); vehicleparams_panel(const std::string &vehicle);
void render_contents() override; void render_contents() override;
}; };