feat context_menu_service (#293)

- add box around selected entity
- add option to select entity types 
- show reticle in middle of screen
This commit is contained in:
Quentin E. / iDeath
2022-06-29 23:27:44 +02:00
committed by GitHub
parent 3f46bad9c1
commit 4d19585b20
7 changed files with 264 additions and 25 deletions

View File

@ -1,9 +1,41 @@
#include "views/view.hpp"
#include "services/context_menu_service.hpp"
namespace big
{
void view::context_menu_settings()
{
ImGui::Checkbox("Context Menu Enabled", &g->context_menu.enabled);
if (g->context_menu.enabled)
{
ImGui::Text("Allowed Entity Types:");
ImGui::CheckboxFlags("Object", reinterpret_cast<int*>(&g->context_menu.allowed_entity_types), static_cast<int>(ContextEntityType::OBJECT));
ImGui::SameLine();
ImGui::CheckboxFlags("Ped", reinterpret_cast<int*>(&g->context_menu.allowed_entity_types), static_cast<int>(ContextEntityType::PED));
ImGui::SameLine();
ImGui::CheckboxFlags("Player", reinterpret_cast<int*>(&g->context_menu.allowed_entity_types), static_cast<int>(ContextEntityType::PLAYER));
ImGui::SameLine();
ImGui::CheckboxFlags("Vehicle", reinterpret_cast<int*>(&g->context_menu.allowed_entity_types), static_cast<int>(ContextEntityType::VEHICLE));
static ImVec4 selected_option_color = ImGui::ColorConvertU32ToFloat4(g->context_menu.selected_option_color);
ImGui::Text("Selected Option Color:");
if (ImGui::ColorEdit4("###BSelected Option Color##cm_picker", (float*)&selected_option_color, ImGuiColorEditFlags_InputRGB | ImGuiColorEditFlags_NoSidePreview))
{
g->context_menu.selected_option_color = ImGui::ColorConvertFloat4ToU32(selected_option_color);
}
ImGui::Checkbox("Bounding Box Enabled", &g->context_menu.bounding_box_enabled);
if (g->context_menu.bounding_box_enabled)
{
static ImVec4 bounding_box_color = ImGui::ColorConvertU32ToFloat4(g->context_menu.bounding_box_color);
ImGui::Text("Bounding Box Color:");
if (ImGui::ColorEdit4("###Bounding Box Color##cm_picker", (float*)&bounding_box_color, ImGuiColorEditFlags_InputRGB | ImGuiColorEditFlags_NoSidePreview))
{
g->context_menu.bounding_box_color = ImGui::ColorConvertFloat4ToU32(bounding_box_color);
}
}
}
}
}

View File

@ -3,6 +3,27 @@
namespace big
{
static void draw_model_bounding_box(ImDrawList* draw_list, const model_bounding_box_screen_space& m_model_bounding_box_screen_space)
{
const auto& box = g_context_menu_service->m_model_bounding_box_screen_space;
const auto& color = g->context_menu.bounding_box_color;
draw_list->AddLine(box.edge1, box.edge2, color);
draw_list->AddLine(box.edge1, box.edge4, color);
draw_list->AddLine(box.edge2, box.edge3, color);
draw_list->AddLine(box.edge3, box.edge4, color);
draw_list->AddLine(box.edge5, box.edge6, color);
draw_list->AddLine(box.edge5, box.edge8, color);
draw_list->AddLine(box.edge6, box.edge7, color);
draw_list->AddLine(box.edge7, box.edge8, color);
draw_list->AddLine(box.edge1, box.edge7, color);
draw_list->AddLine(box.edge2, box.edge8, color);
draw_list->AddLine(box.edge3, box.edge5, color);
draw_list->AddLine(box.edge4, box.edge6, color);
}
void view::context_menu()
{
if (const auto draw_list = ImGui::GetBackgroundDrawList(); draw_list)
@ -35,10 +56,13 @@ namespace big
for (std::uint32_t i = 0; i < cm->options.size(); i++)
{
const auto co = cm->options.at(i);
draw_list->AddText({ cm_start_x + 7.f, cm_start_y + (20.f * static_cast<float>(i)) + 5.f }, cm->current_option == i ? ImGui::ColorConvertFloat4ToU32({ 0.f, 1.f, 0.f, 1.f }) : ImGui::ColorConvertFloat4ToU32({ 1.f, 1.f, 1.f, 1.f }), co.name.c_str());
draw_list->AddText({ cm_start_x + 7.f, cm_start_y + (20.f * static_cast<float>(i)) + 5.f }, cm->current_option == i ? g->context_menu.selected_option_color : ImGui::ColorConvertFloat4ToU32({ 1.f, 1.f, 1.f, 1.f }), co.name.c_str());
}
if (g->context_menu.bounding_box_enabled)
draw_model_bounding_box(draw_list, g_context_menu_service->m_model_bounding_box_screen_space);
}
}
}
}
}
}