mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-19 09:59:18 +02:00
vehicle params window, aware system rewrite, sifa
This commit is contained in:
126
widgets/map.cpp
126
widgets/map.cpp
@@ -10,8 +10,8 @@
|
||||
|
||||
ui::map_panel::map_panel() : ui_panel(LOC_STR(ui_map), false)
|
||||
{
|
||||
size_min = { 200, 200 };
|
||||
size_max = { fb_size, fb_size };
|
||||
size_min = {200, 200};
|
||||
size_max = {fb_size, fb_size};
|
||||
window_flags = ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse;
|
||||
|
||||
gl::shader vert("map.vert");
|
||||
@@ -57,13 +57,14 @@ ui::map_panel::map_panel() : ui_panel(LOC_STR(ui_map), false)
|
||||
|
||||
float ui::map_panel::get_vehicle_rotation()
|
||||
{
|
||||
const TDynamicObject *vehicle = simulation::Train->Dynamic();
|
||||
glm::vec3 front = glm::dvec3(vehicle->VectorFront()) * (vehicle->DirectionGet() > 0 ? 1.0 : -1.0);
|
||||
glm::vec2 north_ptr(0.0f, 1.0f);
|
||||
const TDynamicObject *vehicle = simulation::Train->Dynamic();
|
||||
glm::vec3 front = glm::dvec3(vehicle->VectorFront()) * (vehicle->DirectionGet() > 0 ? 1.0 : -1.0);
|
||||
glm::vec2 north_ptr(0.0f, 1.0f);
|
||||
return glm::atan(front.z, front.x) - glm::atan(north_ptr.y, north_ptr.x);
|
||||
}
|
||||
|
||||
void ui::map_panel::render_map_texture(glm::mat4 transform, glm::vec2 surface_size) {
|
||||
void ui::map_panel::render_map_texture(glm::mat4 transform, glm::vec2 surface_size)
|
||||
{
|
||||
cFrustum frustum;
|
||||
frustum.calculate(transform, glm::mat4());
|
||||
|
||||
@@ -78,7 +79,8 @@ void ui::map_panel::render_map_texture(glm::mat4 transform, glm::vec2 surface_si
|
||||
if (section && frustum.sphere_inside(section->area().center, section->area().radius) > 0.f)
|
||||
{
|
||||
const gfx::geometrybank_handle handle = section->get_map_geometry();
|
||||
if (handle != null_handle) {
|
||||
if (handle != null_handle)
|
||||
{
|
||||
m_section_handles.push_back(handle);
|
||||
section->get_map_active_switches(m_switch_handles);
|
||||
}
|
||||
@@ -130,7 +132,8 @@ void ui::map_panel::render_map_texture(glm::mat4 transform, glm::vec2 surface_si
|
||||
void ui::map_panel::render_labels(glm::mat4 transform, ImVec2 origin, glm::vec2 surface_size)
|
||||
{
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0.7f, 1.0f, 0.7f, 1.0f));
|
||||
for (TDynamicObject *vehicle : simulation::Vehicles.sequence()) {
|
||||
for (TDynamicObject *vehicle : simulation::Vehicles.sequence())
|
||||
{
|
||||
if (vehicle->Prev() || !vehicle->Mechanik)
|
||||
continue;
|
||||
|
||||
@@ -147,14 +150,13 @@ void ui::map_panel::render_labels(glm::mat4 transform, ImVec2 origin, glm::vec2
|
||||
TDynamicObject *veh = vehicle;
|
||||
|
||||
ImVec2 textsize = ImGui::CalcTextSize(label.c_str());
|
||||
ImGui::SetCursorPos(ImVec2(origin.x + gui_pos.x - textsize.x / 2.0f,
|
||||
origin.y + gui_pos.y - textsize.y / 2.0f));
|
||||
ImGui::SetCursorPos(ImVec2(origin.x + gui_pos.x - textsize.x / 2.0f, origin.y + gui_pos.y - textsize.y / 2.0f));
|
||||
ImGui::TextUnformatted(label.c_str());
|
||||
}
|
||||
ImGui::PopStyleColor();
|
||||
|
||||
if (zoom > 0.005f) {
|
||||
|
||||
if (zoom > 0.005f)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -179,15 +181,13 @@ void ui::map_panel::render_contents()
|
||||
glm::mat4 transform;
|
||||
transform[0][0] = -1.0f;
|
||||
|
||||
static enum {
|
||||
MODE_MANUAL = 0,
|
||||
MODE_CAMERA,
|
||||
MODE_VEHICLE
|
||||
} mode = MODE_MANUAL;
|
||||
static enum { MODE_MANUAL = 0, MODE_CAMERA, MODE_VEHICLE } mode = MODE_MANUAL;
|
||||
|
||||
ImGui::RadioButton("manual", (int*)&mode, 0); ImGui::SameLine();
|
||||
ImGui::RadioButton("cam", (int*)&mode, 1); ImGui::SameLine();
|
||||
ImGui::RadioButton("vehicle", (int*)&mode, 2);
|
||||
ImGui::RadioButton("manual", (int *)&mode, 0);
|
||||
ImGui::SameLine();
|
||||
ImGui::RadioButton("cam", (int *)&mode, 1);
|
||||
ImGui::SameLine();
|
||||
ImGui::RadioButton("vehicle", (int *)&mode, 2);
|
||||
|
||||
ImVec2 surface_size_im = ImGui::GetContentRegionAvail();
|
||||
glm::vec2 surface_size(surface_size_im.x, surface_size_im.y);
|
||||
@@ -231,11 +231,12 @@ void ui::map_panel::render_contents()
|
||||
|
||||
ImVec2 window_origin = ImGui::GetCursorPos();
|
||||
ImVec2 screen_origin = ImGui::GetCursorScreenPos();
|
||||
ImGui::ImageButton(reinterpret_cast<void*>(m_tex->id), surface_size_im, ImVec2(0, surface_size.y / fb_size), ImVec2(surface_size.x / fb_size, 0), 0);
|
||||
ImGui::ImageButton(reinterpret_cast<void *>(m_tex->id), surface_size_im, ImVec2(0, surface_size.y / fb_size), ImVec2(surface_size.x / fb_size, 0), 0);
|
||||
|
||||
if (ImGui::IsItemHovered())
|
||||
{
|
||||
if (mode == 0 && ImGui::IsMouseDragging(0)) {
|
||||
if (mode == 0 && ImGui::IsMouseDragging(0))
|
||||
{
|
||||
ImVec2 delta_im = ImGui::GetMouseDragDelta();
|
||||
ImGui::ResetMouseDragDelta();
|
||||
|
||||
@@ -245,27 +246,30 @@ void ui::map_panel::render_contents()
|
||||
|
||||
translate -= delta * 2.0f;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
ImVec2 screen_pos = ImGui::GetMousePos();
|
||||
glm::vec2 surface_pos(screen_pos.x - screen_origin.x, screen_pos.y - screen_origin.y);
|
||||
glm::vec2 ndc_pos = surface_pos / surface_size * 2.0f - 1.0f;
|
||||
glm::vec3 world_pos = glm::inverse(transform) * glm::vec4(ndc_pos.x, 0.0f, -ndc_pos.y, 1.0f);
|
||||
|
||||
map::sorted_object_list objects =
|
||||
map::Objects.find_in_range(glm::vec3(world_pos.x, NAN, world_pos.z), 0.03f / zoom);
|
||||
map::sorted_object_list objects = map::Objects.find_in_range(glm::vec3(world_pos.x, NAN, world_pos.z), 0.03f / zoom);
|
||||
|
||||
if (ImGui::IsMouseClicked(1)) {
|
||||
if (ImGui::IsMouseClicked(1))
|
||||
{
|
||||
if (objects.size() > 1)
|
||||
register_popup(std::make_unique<ui::disambiguation_popup>(*this, std::move(objects)));
|
||||
else if (objects.size() == 1)
|
||||
handle_map_object_click(*this, objects.begin()->second);
|
||||
else {
|
||||
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)));
|
||||
}
|
||||
}
|
||||
else if (!objects.empty()) {
|
||||
else if (!objects.empty())
|
||||
{
|
||||
handle_map_object_hover(objects.begin()->second);
|
||||
}
|
||||
}
|
||||
@@ -276,10 +280,12 @@ void ui::map_panel::render_contents()
|
||||
|
||||
void ui::handle_map_object_click(ui_panel &parent, std::shared_ptr<map::map_object> &obj)
|
||||
{
|
||||
if (auto sem = std::dynamic_pointer_cast<map::semaphore>(obj)) {
|
||||
if (auto sem = std::dynamic_pointer_cast<map::semaphore>(obj))
|
||||
{
|
||||
parent.register_popup(std::make_unique<semaphore_window>(parent, std::move(sem)));
|
||||
}
|
||||
else if (auto track = std::dynamic_pointer_cast<map::track_switch>(obj)) {
|
||||
else if (auto track = std::dynamic_pointer_cast<map::track_switch>(obj))
|
||||
{
|
||||
parent.register_popup(std::make_unique<switch_window>(parent, std::move(track)));
|
||||
}
|
||||
}
|
||||
@@ -288,12 +294,15 @@ void ui::handle_map_object_hover(std::shared_ptr<map::map_object> &obj)
|
||||
{
|
||||
ImGui::BeginTooltip();
|
||||
|
||||
if (auto sem = std::dynamic_pointer_cast<map::semaphore>(obj)) {
|
||||
for (auto &model : sem->models) {
|
||||
if (auto sem = std::dynamic_pointer_cast<map::semaphore>(obj))
|
||||
{
|
||||
for (auto &model : sem->models)
|
||||
{
|
||||
ImGui::PushID(model);
|
||||
ImGui::TextUnformatted(model->name().c_str());
|
||||
|
||||
for (int i = 0; i < iMaxNumLights; i++) {
|
||||
for (int i = 0; i < iMaxNumLights; i++)
|
||||
{
|
||||
GfxRenderer.Update_AnimModel(model); // update lamp opacities
|
||||
auto state = model->LightGet(i);
|
||||
if (!state)
|
||||
@@ -314,20 +323,22 @@ 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::track_switch>(obj))
|
||||
{
|
||||
ImGui::TextUnformatted(sw->name.c_str());
|
||||
}
|
||||
|
||||
ImGui::EndTooltip();
|
||||
}
|
||||
|
||||
ui::disambiguation_popup::disambiguation_popup(ui_panel &panel, map::sorted_object_list &&list)
|
||||
: popup(panel), m_list(list) { }
|
||||
ui::disambiguation_popup::disambiguation_popup(ui_panel &panel, map::sorted_object_list &&list) : popup(panel), m_list(list) {}
|
||||
|
||||
void ui::disambiguation_popup::render_content()
|
||||
{
|
||||
for (auto &item : m_list) {
|
||||
if (ImGui::Button(item.second->name.c_str())) {
|
||||
for (auto &item : m_list)
|
||||
{
|
||||
if (ImGui::Button(item.second->name.c_str()))
|
||||
{
|
||||
ImGui::CloseCurrentPopup();
|
||||
|
||||
handle_map_object_click(m_parent, item.second);
|
||||
@@ -335,16 +346,17 @@ void ui::disambiguation_popup::render_content()
|
||||
}
|
||||
}
|
||||
|
||||
ui::semaphore_window::semaphore_window(ui_panel &panel, std::shared_ptr<map::semaphore> &&sem)
|
||||
: popup(panel), m_sem(sem) { }
|
||||
ui::semaphore_window::semaphore_window(ui_panel &panel, std::shared_ptr<map::semaphore> &&sem) : popup(panel), m_sem(sem) {}
|
||||
|
||||
void ui::semaphore_window::render_content()
|
||||
{
|
||||
for (auto &model : m_sem->models) {
|
||||
for (auto &model : m_sem->models)
|
||||
{
|
||||
ImGui::PushID(model);
|
||||
ImGui::TextUnformatted(model->name().c_str());
|
||||
|
||||
for (int i = 0; i < iMaxNumLights; i++) {
|
||||
for (int i = 0; i < iMaxNumLights; i++)
|
||||
{
|
||||
GfxRenderer.Update_AnimModel(model); // update lamp opacities
|
||||
auto state = model->LightGet(i);
|
||||
if (!state)
|
||||
@@ -361,7 +373,8 @@ void ui::semaphore_window::render_content()
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(current_color.x, current_color.y, current_color.z, 1.0f));
|
||||
|
||||
std::string res = " ##" + std::to_string(i);
|
||||
if (ImGui::Button(res.c_str())) {
|
||||
if (ImGui::Button(res.c_str()))
|
||||
{
|
||||
level += 1.0f;
|
||||
if (level >= 3.0f)
|
||||
level = 0.0f;
|
||||
@@ -378,7 +391,8 @@ void ui::semaphore_window::render_content()
|
||||
|
||||
ImGui::Separator();
|
||||
|
||||
for (auto &item : m_sem->events) {
|
||||
for (auto &item : m_sem->events)
|
||||
{
|
||||
std::string displayname = item->name().substr(m_sem->name.size());
|
||||
|
||||
if (displayname.size() < 2)
|
||||
@@ -386,38 +400,40 @@ void ui::semaphore_window::render_content()
|
||||
|
||||
displayname[1] = std::toupper(displayname[1]);
|
||||
|
||||
if (ImGui::Button(displayname.c_str())) {
|
||||
if (ImGui::Button(displayname.c_str()))
|
||||
{
|
||||
m_relay.post(user_command::queueevent, (double)simulation::Events.GetEventId(item), 0.0, GLFW_PRESS, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ui::switch_window::switch_window(ui_panel &panel, std::shared_ptr<map::track_switch> &&sw)
|
||||
: popup(panel), m_switch(sw) { }
|
||||
ui::switch_window::switch_window(ui_panel &panel, std::shared_ptr<map::track_switch> &&sw) : popup(panel), m_switch(sw) {}
|
||||
|
||||
void ui::switch_window::render_content()
|
||||
{
|
||||
ImGui::TextUnformatted(m_switch->name.c_str());
|
||||
|
||||
if (ImGui::Button(LOC_STR(map_straight))) {
|
||||
if (ImGui::Button(LOC_STR(map_straight)))
|
||||
{
|
||||
m_relay.post(user_command::queueevent, (double)simulation::Events.GetEventId(m_switch->straight_event), 0.0, GLFW_PRESS, 0);
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
|
||||
if (ImGui::Button(LOC_STR(map_divert))) {
|
||||
if (ImGui::Button(LOC_STR(map_divert)))
|
||||
{
|
||||
m_relay.post(user_command::queueevent, (double)simulation::Events.GetEventId(m_switch->divert_event), 0.0, GLFW_PRESS, 0);
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
}
|
||||
|
||||
ui::obstacle_window::obstacle_window(ui_panel &panel, glm::dvec3 const &pos)
|
||||
: popup(panel), m_position(pos)
|
||||
ui::obstacle_window::obstacle_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);
|
||||
|
||||
std::string line;
|
||||
while (std::getline(file, line)) {
|
||||
while (std::getline(file, line))
|
||||
{
|
||||
std::istringstream entry(line);
|
||||
|
||||
std::string name;
|
||||
@@ -432,8 +448,10 @@ ui::obstacle_window::obstacle_window(ui_panel &panel, glm::dvec3 const &pos)
|
||||
void ui::obstacle_window::render_content()
|
||||
{
|
||||
ImGui::TextUnformatted(LOC_STR(map_obstacle_insert));
|
||||
for (auto const &entry : m_obstacles) {
|
||||
if (ImGui::Button(entry.first.c_str())) {
|
||||
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);
|
||||
ImGui::CloseCurrentPopup();
|
||||
|
||||
Reference in New Issue
Block a user