mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-18 00:49:19 +02:00
alerter fixes, removing obstacles, python config changes
This commit is contained in:
@@ -264,8 +264,9 @@ void ui::map_panel::render_contents()
|
||||
else
|
||||
{
|
||||
glm::vec3 nearest = simulation::Region->find_nearest_track_point(world_pos);
|
||||
if (!glm::isnan(nearest.x) && glm::distance(world_pos, nearest) < (0.03f / zoom))
|
||||
register_popup(std::make_unique<obstacle_window>(*this, std::move(nearest)));
|
||||
if (!glm::isnan(nearest.x)
|
||||
&& glm::distance(glm::vec2(world_pos.x, world_pos.z), glm::vec2(nearest.x, nearest.z)) < 60.0f)
|
||||
register_popup(std::make_unique<obstacle_insert_window>(*this, std::move(nearest)));
|
||||
}
|
||||
}
|
||||
else if (!objects.empty())
|
||||
@@ -288,6 +289,10 @@ void ui::handle_map_object_click(ui_panel &parent, std::shared_ptr<map::map_obje
|
||||
{
|
||||
parent.register_popup(std::make_unique<switch_window>(parent, std::move(track)));
|
||||
}
|
||||
else if (auto obstacle = std::dynamic_pointer_cast<map::obstacle>(obj))
|
||||
{
|
||||
parent.register_popup(std::make_unique<obstacle_remove_window>(parent, std::move(obstacle)));
|
||||
}
|
||||
}
|
||||
|
||||
void ui::handle_map_object_hover(std::shared_ptr<map::map_object> &obj)
|
||||
@@ -323,7 +328,7 @@ void ui::handle_map_object_hover(std::shared_ptr<map::map_object> &obj)
|
||||
ImGui::PopID();
|
||||
}
|
||||
}
|
||||
else if (auto sw = std::dynamic_pointer_cast<map::track_switch>(obj))
|
||||
else if (auto sw = std::dynamic_pointer_cast<map::map_object>(obj))
|
||||
{
|
||||
ImGui::TextUnformatted(sw->name.c_str());
|
||||
}
|
||||
@@ -426,11 +431,14 @@ void ui::switch_window::render_content()
|
||||
}
|
||||
}
|
||||
|
||||
ui::obstacle_window::obstacle_window(ui_panel &panel, glm::dvec3 const &pos) : popup(panel), m_position(pos)
|
||||
ui::obstacle_insert_window::obstacle_insert_window(ui_panel &panel, glm::dvec3 const &pos) : popup(panel), m_position(pos)
|
||||
{
|
||||
std::ifstream file;
|
||||
file.open("obstaclebank.txt", std::ios_base::in | std::ios_base::binary);
|
||||
|
||||
if (!file.is_open())
|
||||
return;
|
||||
|
||||
std::string line;
|
||||
while (std::getline(file, line))
|
||||
{
|
||||
@@ -445,16 +453,55 @@ ui::obstacle_window::obstacle_window(ui_panel &panel, glm::dvec3 const &pos) : p
|
||||
}
|
||||
}
|
||||
|
||||
void ui::obstacle_window::render_content()
|
||||
void ui::obstacle_insert_window::render_content()
|
||||
{
|
||||
if (m_obstacles.empty()) {
|
||||
ImGui::CloseCurrentPopup();
|
||||
return;
|
||||
}
|
||||
|
||||
ImGui::TextUnformatted(LOC_STR(map_obstacle_insert));
|
||||
for (auto const &entry : m_obstacles)
|
||||
{
|
||||
if (ImGui::Button(entry.first.c_str()))
|
||||
{
|
||||
std::string name("obstacle_" + std::to_string(LocalRandom(0.0, 100000.0)));
|
||||
|
||||
TAnimModel *cloned = simulation::State.create_model(entry.second, name, m_position);
|
||||
|
||||
auto obstacle = std::make_shared<map::obstacle>();
|
||||
obstacle->name = entry.first;
|
||||
obstacle->location = m_position;
|
||||
obstacle->model = cloned;
|
||||
map::Objects.entries.push_back(std::move(obstacle));
|
||||
|
||||
std::vector<gfx::basic_vertex> vertices;
|
||||
vertices.emplace_back((glm::vec3)m_position, glm::vec3(), glm::vec3());
|
||||
GfxRenderer.Append(vertices, simulation::Region->get_map_poi_geometry(), GL_POINTS);
|
||||
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ui::obstacle_remove_window::obstacle_remove_window(ui_panel &panel, std::shared_ptr<map::obstacle> &&obstacle)
|
||||
: popup(panel), m_obstacle(obstacle) { }
|
||||
|
||||
void ui::obstacle_remove_window::render_content()
|
||||
{
|
||||
if (ImGui::Button(LOC_STR(map_obstacle_remove))) {
|
||||
simulation::State.delete_model(m_obstacle->model);
|
||||
|
||||
auto &entries = map::Objects.entries;
|
||||
for (auto it = entries.rbegin(); it != entries.rend(); it++) {
|
||||
if (*it == m_obstacle) {
|
||||
entries.erase(std::next(it).base());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
simulation::Region->update_poi_geometry();
|
||||
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,13 +42,23 @@ class switch_window : public popup
|
||||
virtual void render_content() override;
|
||||
};
|
||||
|
||||
class obstacle_window : public popup
|
||||
class obstacle_insert_window : public popup
|
||||
{
|
||||
glm::dvec3 m_position;
|
||||
std::vector<std::pair<std::string, std::string>> m_obstacles;
|
||||
|
||||
public:
|
||||
obstacle_window(ui_panel &panel, glm::dvec3 const &pos);
|
||||
obstacle_insert_window(ui_panel &panel, glm::dvec3 const &pos);
|
||||
|
||||
virtual void render_content() override;
|
||||
};
|
||||
|
||||
class obstacle_remove_window : public popup
|
||||
{
|
||||
std::shared_ptr<map::obstacle> m_obstacle;
|
||||
|
||||
public:
|
||||
obstacle_remove_window(ui_panel &panel, std::shared_ptr<map::obstacle> &&obstacle);
|
||||
|
||||
virtual void render_content() override;
|
||||
};
|
||||
|
||||
@@ -33,6 +33,12 @@ struct track_switch : public map_object
|
||||
basic_event *divert_event = nullptr;
|
||||
};
|
||||
|
||||
// training obstacle description
|
||||
struct obstacle : public map_object
|
||||
{
|
||||
TAnimModel *model;
|
||||
};
|
||||
|
||||
struct objects
|
||||
{
|
||||
std::vector<std::shared_ptr<map_object>> entries;
|
||||
|
||||
Reference in New Issue
Block a user