This repository has been archived on 2024-10-22. You can view files and clone it, but cannot push or open issues or pull requests.
YimMenu/BigBaseV2/src/views/view_context_menu.cpp
Quentin E. / iDeath 4d19585b20
feat context_menu_service (#293)
- add box around selected entity
- add option to select entity types 
- show reticle in middle of screen
2022-06-29 23:27:44 +02:00

69 lines
2.8 KiB
C++

#include "view.hpp"
#include "services/context_menu_service.hpp"
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)
{
if (g_context_menu_service->enabled &&
g_context_menu_service->m_pointer &&
g_context_menu_service->m_pointer->m_navigation)
{
float context_screen_x;
float context_screen_y;
auto& context_target_pos = g_context_menu_service->m_pointer->m_navigation->m_position;
const auto context_target_distance = math::calculate_distance_from_game_cam(context_target_pos);
const auto context_target_multplr = context_target_distance > g->esp.global_render_distance[1] ? -1.f : 6.17757f / context_target_distance;
if (g_pointers->m_get_screen_coords_for_world_coords(context_target_pos.data, &context_screen_x, &context_screen_y))
{
const auto cm = g_context_menu_service->get_context_menu();
if (cm == nullptr)
return;
const auto cm_start_x = static_cast<float>(*g_pointers->m_resolution_x) * context_screen_x + (67.5f * context_target_multplr);
const auto cm_start_y = static_cast<float>(*g_pointers->m_resolution_y) * context_screen_y - (175.f * context_target_multplr);
const auto cm_col = ImGui::ColorConvertFloat4ToU32({ 0.549f, 0.639f, 0.710f, 0.3f });
draw_list->AddRectFilled({ cm_start_x - 2.f , cm_start_y }, { cm_start_x + 2.f + cm->menu_size.x, cm_start_y + cm->menu_size.y }, cm_col, 5.f);
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 ? 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);
}
}
}
}
}