Initial commit
This commit is contained in:
@@ -0,0 +1,126 @@
|
||||
#include <include.h>
|
||||
|
||||
using namespace window;
|
||||
|
||||
void get_map_position_from_origin(
|
||||
const math::position_t<float>& m_position, float m_radius, float m_range,
|
||||
math::Vector3 start_origin, math::Vector3 end_origin, math::Angle3 view_angle,
|
||||
math::Vector3& out
|
||||
)
|
||||
{
|
||||
const float x_center = (m_position.x);
|
||||
const float y_center = (m_position.y);
|
||||
|
||||
auto delta = (start_origin - end_origin);
|
||||
|
||||
float radians = (view_angle.y - 180.f) * (static_cast<float>(M_PI) / 180.f);
|
||||
float view_sin = math::sinf(radians), view_cos = math::cosf(radians);
|
||||
|
||||
out.x = static_cast<float>(x_center) + (delta.y * (-view_cos) + delta.x * view_sin) / m_range;
|
||||
out.y = static_cast<float>(y_center) + (delta.x * (-view_cos) - delta.y * view_sin) / m_range;
|
||||
out.z = 0.0f;
|
||||
|
||||
auto center_screen = math::Vector3{ x_center, y_center, 0.0f };
|
||||
auto center_delta = (out - center_screen);
|
||||
|
||||
float distance = center_delta.Length2d();
|
||||
|
||||
if (distance > m_radius)
|
||||
{
|
||||
center_delta *= m_radius / center_delta.Length2d();
|
||||
|
||||
out = center_screen + center_delta;
|
||||
}
|
||||
}
|
||||
|
||||
void c_radar::draw_base()
|
||||
{
|
||||
const auto Position = m_position;
|
||||
const auto Dimension = m_dimension;
|
||||
|
||||
const auto Radius = cfg::radar_radius;
|
||||
|
||||
m_radius = Radius;
|
||||
m_range = cfg::radar_range;
|
||||
|
||||
g::p::render.draw_rect_filled({ 5, 5, 5 }, Position.x - Radius, Position.y - Radius, Position.x + Radius, Position.y + Radius, cfg::radar_opacity);
|
||||
g::p::render.draw_rect_bordered(respawn::colors::blue, Position.x - Radius, Position.y - Radius, Position.x + Radius, Position.y + Radius);
|
||||
|
||||
g::p::render.draw_line(respawn::colors::blue, Position.x, Position.y - Radius, Position.x, Position.y + Radius);
|
||||
g::p::render.draw_line(respawn::colors::blue, Position.x - Radius, Position.y, Position.x + Radius, Position.y);
|
||||
}
|
||||
|
||||
void c_radar::draw_objects()
|
||||
{
|
||||
if (!g::is_in_game)
|
||||
return;
|
||||
|
||||
const auto& my_origin = g::p::cache.local_player.origin;
|
||||
const auto& my_angle = g::p::cache.local_player.eye_angle;
|
||||
const auto& my_team_num = g::p::cache.local_player.team_number;
|
||||
|
||||
auto position = math::position_t<float>( m_position.x, m_position.y );
|
||||
|
||||
for (auto i = 0ull; i < g::p::ent_cache.count(); i++)
|
||||
{
|
||||
auto data = g::p::ent_cache.get_neutral(i);
|
||||
|
||||
if (!data.valid)
|
||||
continue;
|
||||
|
||||
respawn::color_t color = respawn::colors::white;
|
||||
|
||||
switch (data.type)
|
||||
{
|
||||
case cache::types::player:
|
||||
case cache::types::dummie:
|
||||
|
||||
if (data.type_specific.plr.m_life_state != LIFE_ALIVE)
|
||||
continue;
|
||||
|
||||
if (data.type_specific.plr.m_teammate)
|
||||
color = respawn::colors::cyan;
|
||||
else
|
||||
color = respawn::colors::red;
|
||||
|
||||
if (data.type_specific.plr.m_bleedout_state != NULL &&
|
||||
!data.type_specific.plr.m_teammate)
|
||||
color = respawn::colors::red;
|
||||
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
|
||||
auto size = 4.0f;
|
||||
auto draw_pos = math::Vector3{};
|
||||
|
||||
get_map_position_from_origin(
|
||||
position, m_radius, m_range, my_origin,
|
||||
data.type_specific.plr.m_origin, my_angle, draw_pos
|
||||
);
|
||||
|
||||
g::p::render.draw_rect_filled(
|
||||
color, draw_pos.x - size,
|
||||
draw_pos.y - size, draw_pos.x + size,
|
||||
draw_pos.y + size, 255
|
||||
);
|
||||
|
||||
g::p::render.draw_rect(
|
||||
respawn::colors::black, draw_pos.x - size,
|
||||
draw_pos.y - size, draw_pos.x + size,
|
||||
draw_pos.y + size, 255
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void c_radar::paint()
|
||||
{
|
||||
if (!cfg::radar_enabled)
|
||||
return;
|
||||
|
||||
set_flag(fl::draggable, true);
|
||||
|
||||
draw_base();
|
||||
draw_objects();
|
||||
}
|
||||
+199
@@ -0,0 +1,199 @@
|
||||
#include <include.h>
|
||||
|
||||
bool ui::in_range(const math::position_t<float>& _position, const math::dimension_t<float>& _dimension)
|
||||
{
|
||||
const auto cursor_position = g::p::input_mgr.get_cursor_pos();
|
||||
|
||||
if (cursor_position.x < _position.x ||
|
||||
cursor_position.x > _position.x + _dimension.w)
|
||||
return false;
|
||||
|
||||
if (cursor_position.y < _position.y ||
|
||||
cursor_position.y > _position.y + _dimension.h)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ui::section(const math::position_t<float>& _position, const math::dimension_t<float>& _dimension, respawn::color_t color, const char* name)
|
||||
{
|
||||
const float name_offset = (12.0f + g::p::render.get_text_width(name, 14) + 2.0f);
|
||||
|
||||
g::p::render.draw_rect_filled({ 25, 25, 25 }, _position.x, _position.y, _position.x + _dimension.w, _position.y + _dimension.h);
|
||||
|
||||
// top left - bottom left.
|
||||
g::p::render.draw_line(color, _position.x, _position.y, _position.x, _position.y + _dimension.h);
|
||||
|
||||
// bottom left - bottom right.
|
||||
g::p::render.draw_line(color, _position.x, _position.y + _dimension.h, _position.x + _dimension.w, _position.y + _dimension.h);
|
||||
|
||||
// bottom right - top right.
|
||||
g::p::render.draw_line(color, _position.x + _dimension.w, _position.y, _position.x + _dimension.w, _position.y + _dimension.h);
|
||||
|
||||
// top left - top right.
|
||||
g::p::render.draw_line(color, _position.x + name_offset, _position.y, _position.x + _dimension.w, _position.y);
|
||||
|
||||
g::p::render.draw_text(color, 2, 14, _position.x + 4.0f, _position.y - 5.0f, name);
|
||||
}
|
||||
|
||||
void ui::checkbox(const math::position_t<float> _position, const char* text, bool* variable)
|
||||
{
|
||||
if (variable == nullptr)
|
||||
return;
|
||||
|
||||
const float text_width = static_cast<float>(g::p::render.get_text_width(text, 14)) + 15.0f;
|
||||
const auto box_color = *variable ? respawn::color_t( 0, 245, 233 ) : respawn::colors::black;
|
||||
const float checkbox_center_x = (math::roundf(_position.x) + (10.0f / 2.0f)), checkbox_center_y = (math::roundf(_position.y) + (10.0f / 2.0f));
|
||||
|
||||
g::p::render.draw_rect_filled(box_color, checkbox_center_x - 3.0f, checkbox_center_y - 3.0f, checkbox_center_x + 3.0f, checkbox_center_y + 3.0f);
|
||||
g::p::render.draw_rect({ 46, 158, 153 }, checkbox_center_x - 5.0f, checkbox_center_y - 5.0f, checkbox_center_x + 5.0f, checkbox_center_y + 5.0f);
|
||||
|
||||
g::p::render.draw_text({ 0, 245, 233 }, 2, 14, _position.x + 15.0f, _position.y - 2.0f, text);
|
||||
|
||||
if (!in_range(_position, { text_width, 15.0f }))
|
||||
return;
|
||||
|
||||
if (si::paint.was_button_down(VK_LBUTTON))
|
||||
*variable = !*variable;
|
||||
}
|
||||
|
||||
void ui::checkbox_triple(const math::position_t<float> _position, const char* text, int* variable)
|
||||
{
|
||||
if (variable == nullptr)
|
||||
return;
|
||||
|
||||
const float text_width = static_cast<float>(g::p::render.get_text_width(text, 14)) + 15.0f;
|
||||
const auto box_color = *variable ? respawn::color_t(0, 245, 233) : respawn::colors::black;
|
||||
const float checkbox_center_x = (math::roundf(_position.x) + (10.0f / 2.0f)), checkbox_center_y = (math::roundf(_position.y) + (10.0f / 2.0f));
|
||||
|
||||
switch (*variable)
|
||||
{
|
||||
case 1:
|
||||
g::p::render.draw_rect_filled(box_color, checkbox_center_x, checkbox_center_y, checkbox_center_x + 3.0f, checkbox_center_y + 3.0f);
|
||||
break;
|
||||
case 2:
|
||||
g::p::render.draw_rect_filled(box_color, checkbox_center_x - 3.0f, checkbox_center_y - 3.0f, checkbox_center_x + 3.0f, checkbox_center_y + 3.0f);
|
||||
break;
|
||||
}
|
||||
|
||||
g::p::render.draw_rect({ 46, 158, 153 }, checkbox_center_x - 5.0f, checkbox_center_y - 5.0f, checkbox_center_x + 5.0f, checkbox_center_y + 5.0f);
|
||||
|
||||
g::p::render.draw_text_ex({ 0, 245, 233 }, 2, 14, _position.x + 15.0f, _position.y - 2.0f, _XS("%s (%i)"), text, *variable);
|
||||
|
||||
if (!in_range(_position, { text_width, 15.0f }))
|
||||
return;
|
||||
|
||||
if (si::paint.was_button_down(VK_LBUTTON))
|
||||
{
|
||||
if (*variable < 2)
|
||||
++(*variable);
|
||||
else
|
||||
*variable = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void ui::slider(math::position_t<float> _position, math::dimension_t<float> _dimension, const char* text, int* variable, int min, int max)
|
||||
{
|
||||
if (variable == nullptr)
|
||||
return;
|
||||
|
||||
const auto cursor_position = g::p::input_mgr.get_cursor_pos();
|
||||
const auto bar_color = static_cast<int>(*variable) ? respawn::colors::green : respawn::colors::black;
|
||||
const float delta = _dimension.w / static_cast<float>(max) * static_cast<float>(*variable);
|
||||
|
||||
char label[72];
|
||||
util::format_string(label, sizeof(label), _XS("%s %i/%i"), text, static_cast<int>(*variable), static_cast<int>(max));
|
||||
|
||||
g::p::render.draw_text(respawn::colors::white, 2, 14, _position.x + 2.0f, _position.y, label);
|
||||
|
||||
_position.y += 15.0f;
|
||||
|
||||
g::p::render.draw_rect_filled({ 50, 50, 50 }, _position.x, _position.y, _position.x + _dimension.w, _position.y + _dimension.h);
|
||||
g::p::render.draw_rect_filled(bar_color, _position.x, _position.y, _position.x + delta, _position.y + _dimension.h);
|
||||
g::p::render.draw_rect(respawn::colors::black, _position.x, _position.y, _position.x + _dimension.w, _position.y + _dimension.h);
|
||||
|
||||
g::p::render.draw_rect_filled({ 45, 45, 45 }, _position.x + delta - 5, _position.y - 2.0f, _position.x + delta, _position.y + _dimension.h + 2.0f);
|
||||
g::p::render.draw_rect({ 25, 25, 45 }, _position.x + delta - 5.0f, _position.y - 2.0f, _position.x + delta, _position.y + _dimension.h + 2.0f);
|
||||
|
||||
if (!in_range({ _position.x, _position.y - 2.0f }, { _dimension.w, _dimension.h + 2.0f }))
|
||||
return;
|
||||
|
||||
if (si::paint.is_button_down(VK_LBUTTON))
|
||||
{
|
||||
const float scale = (max - min) / _dimension.w;
|
||||
const float value = min + (cursor_position.x - _position.x) * scale;
|
||||
|
||||
auto value_to_set = static_cast<int>(value);
|
||||
|
||||
if (value_to_set < min)
|
||||
value_to_set = min;
|
||||
else if (value_to_set > max)
|
||||
value_to_set = max;
|
||||
|
||||
*variable = value_to_set;
|
||||
}
|
||||
}
|
||||
|
||||
void ui::slider_float(math::position_t<float> _position, math::dimension_t<float> _dimension, const char* text, float* variable, float min, float max)
|
||||
{
|
||||
if (variable == nullptr)
|
||||
return;
|
||||
|
||||
const auto cursor_position = g::p::input_mgr.get_cursor_pos();
|
||||
const auto bar_color = static_cast<int>(*variable) ? respawn::colors::green : respawn::colors::black;
|
||||
const float delta = _dimension.w / static_cast<float>(max) * static_cast<float>(*variable);
|
||||
|
||||
char label[72];
|
||||
util::format_string(label, sizeof(label), _XS("%s %i/%i"), text, static_cast<int>(*variable), static_cast<int>(max));
|
||||
|
||||
g::p::render.draw_text(respawn::colors::white, 2, 14, _position.x + 2.0f, _position.y, label);
|
||||
|
||||
_position.y += 15.0f;
|
||||
|
||||
g::p::render.draw_rect_filled({ 50, 50, 50 }, _position.x, _position.y, _position.x + _dimension.w, _position.y + _dimension.h);
|
||||
g::p::render.draw_rect_filled(bar_color, _position.x, _position.y, _position.x + delta, _position.y + _dimension.h);
|
||||
g::p::render.draw_rect(respawn::colors::black, _position.x, _position.y, _position.x + _dimension.w, _position.y + _dimension.h);
|
||||
|
||||
g::p::render.draw_rect_filled({ 45, 45, 45 }, _position.x + delta - 5, _position.y - 2.0f, _position.x + delta, _position.y + _dimension.h + 2.0f);
|
||||
g::p::render.draw_rect({ 25, 25, 45 }, _position.x + delta - 5.0f, _position.y - 2.0f, _position.x + delta, _position.y + _dimension.h + 2.0f);
|
||||
|
||||
if (!in_range({ _position.x, _position.y - 2.0f }, { _dimension.w, _dimension.h + 2.0f }))
|
||||
return;
|
||||
|
||||
if (si::paint.is_button_down(VK_LBUTTON))
|
||||
{
|
||||
const float scale = (max - min) / _dimension.w;
|
||||
const float value = min + (cursor_position.x - _position.x) * scale;
|
||||
|
||||
auto value_to_set = value;
|
||||
|
||||
if (value_to_set < min)
|
||||
value_to_set = min;
|
||||
else if (value_to_set > max)
|
||||
value_to_set = max;
|
||||
|
||||
*variable = value_to_set;
|
||||
}
|
||||
}
|
||||
|
||||
bool ui::button(
|
||||
const math::position_t<float>& _position, const math::dimension_t<float>& _dimension,
|
||||
respawn::color_t background_color, respawn::color_t text_color, const char* text
|
||||
)
|
||||
{
|
||||
const auto text_width = g::p::render.get_text_width(text, 11);
|
||||
|
||||
g::p::render.draw_rect_filled(background_color, _position.x, _position.y, _position.x + _dimension.w, _position.y + _dimension.h);
|
||||
g::p::render.draw_rect(respawn::colors::black, _position.x, _position.y, _position.x + _dimension.w, _position.y + _dimension.h);
|
||||
g::p::render.draw_text(
|
||||
text_color, 2, 11, (_position.x + (_dimension.w / 2.f)) - (text_width / 2.f),
|
||||
_position.y + (_dimension.h / 4.f), text
|
||||
);
|
||||
|
||||
if (!in_range(_position, _dimension))
|
||||
return false;
|
||||
|
||||
const bool is_clicked = si::paint.was_button_down(VK_LBUTTON);
|
||||
|
||||
return is_clicked;
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
#include <include.h>
|
||||
|
||||
using namespace window;
|
||||
|
||||
void c_manager::paint()
|
||||
{
|
||||
const auto cursor_pos = g::p::input_mgr.get_cursor_pos();
|
||||
|
||||
const auto try_drag = [this](c_base* window, const math::position_t<int> new_position) -> bool
|
||||
{
|
||||
const auto screen_size = g::p::screen;
|
||||
|
||||
const auto my_position = window->_position();
|
||||
const auto my_dimension = window->_dimension();
|
||||
|
||||
const float min_x = 2.0f;
|
||||
const float max_x = (screen_size.w - 2.0f);
|
||||
|
||||
const float min_y = 2.0f;
|
||||
const float max_y = (screen_size.h - 2.0f);
|
||||
|
||||
auto my_new_position = math::position_t<int>{
|
||||
new_position.x - my_dimension.w / 2, new_position.y
|
||||
};
|
||||
|
||||
if (my_new_position.x < min_x)
|
||||
my_new_position.x = min_x;
|
||||
|
||||
if ((my_new_position.x + my_dimension.w) > max_x)
|
||||
my_new_position.x = (max_x - my_dimension.w);
|
||||
|
||||
if (my_new_position.y < min_y)
|
||||
my_new_position.y = min_y;
|
||||
|
||||
if ((my_new_position.y + my_dimension.h) > max_y)
|
||||
my_new_position.y = (max_y - my_dimension.h);
|
||||
|
||||
window->_position() = my_new_position;
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
for (auto i = 0; i < m_list.count(); i++)
|
||||
{
|
||||
auto* const wnd_ptr = m_list[i];
|
||||
|
||||
if (wnd_ptr == nullptr)
|
||||
continue;
|
||||
|
||||
auto* const wnd = *wnd_ptr;
|
||||
|
||||
if (wnd == nullptr)
|
||||
continue;
|
||||
|
||||
wnd->paint();
|
||||
|
||||
if (wnd->has_flag(fl::draggable))
|
||||
{
|
||||
const auto position = wnd->_position();
|
||||
const auto dimension = wnd->_dimension();
|
||||
|
||||
if (wnd->has_flag(fl::dragging) == false)
|
||||
{
|
||||
//
|
||||
// not being dragged currently.
|
||||
//
|
||||
|
||||
if (g::p::input_mgr.is_button_down(VK_LBUTTON))
|
||||
{
|
||||
if (in_range<int>(cursor_pos, std::make_pair(position, math::dimension_t<int>{dimension.w, 15})))
|
||||
wnd->set_flag(fl::dragging, true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// is being dragged.
|
||||
//
|
||||
|
||||
if (!g::p::input_mgr.is_button_down(VK_LBUTTON))
|
||||
wnd->set_flag(fl::dragging, false);
|
||||
else
|
||||
try_drag(wnd, cursor_pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user