designer1337 / csgo-cheat-base

simple csgo internal base.
MIT License
245 stars 48 forks source link

Combobox #108

Open GLadiator279 opened 3 years ago

GLadiator279 commented 3 years ago

I saw a post here that a person cannot make a combobox. I decided to try to do it, and I succeeded. I am far from being a pro, so yes, semi-pasted from xy0.

I have put the code on pastebin as at the moment the code paste on github is broken.

framework.cpp https://pastebin.com/ucsgxWxC

framework.hpp https://pastebin.com/79evBbjS

How to use

Create a string array and an integer variable in variables.hpp inline std::vector<std::string> box_type_name { "Custom color", "White color" }; inline int box_type = 0; Add the item to menu.cpp. menu_framework::combo_box(x + 120, y + 150, x + 260, watermark_font, "Box type", variables::visuals::esp::box_type_name, &variables::visuals::esp::box_type);

Don't swear if the code isn't very good, thanks.

GLadiator279 commented 3 years ago

You do not need to create a string variable, you can write the names in the element call, for example, like this: menu_framework::combo_box(x + 120, y + 165, x + 260, watermark_font, "Box type", { "1", "2", "3" }, &variables::visuals::esp::box_type);

judahmane commented 3 years ago

penis fart

st3ph4nnn commented 3 years ago

Sorry for being late. If u atleast paste it try to optimize it. Your whole code can be shortened to 20 lines and have it work the same way.

bool open = false;
static bool selected_opened = false;
static bool rest;
static std::string name_selected;

if ((cursor.x > position) && (cursor.x < position + w) && (cursor.y > y) && (cursor.y < y + h) && GetAsyncKeyState(VK_LBUTTON) & 1) {
    name_selected = string;
    if (!rest)
        selected_opened = !selected_opened;
    rest = true;
}
else
    rest = false;

if (name_selected == string)
    open = selected_opened;

this can be 3 lines and work the same, literally. ` static bool open = false;

if (get_pos(x, y, w, h))
    open = !open;`

only my preference but this can be out of this if statement if (open) { render::draw_filled_rect(position + 2, y - 1, w, 15 + (size * 15), color(36, 36, 36, 255));

This can also be shortened to 1 line and much optimized. if (i == *values) { render::text(position + 7, (y - 1) + 15 + (i * 15), font, elements[i].c_str(), false, color::white()); } else { render::text(position + 7, (y - 1) + 15 + (i * 15), font, elements[i].c_str(), false, color::white(100)); }

render::text(x + ( w / 2 ), y + 15 + (i * 15), font, elements[i], true, i == *current ? active : idle);

Look, i just made it better for you all

    static bool open = false;

if (get_pos(x, y, w, h))
    open = !open;

std::size_t size = elements.size();

render::draw_filled_rect(x + 2, y - 1, w, open ? 15 + (size * 15) : h, groupbox_background_alt);
render::draw_outline(x + 2, y - 1, w, open ? 15 + (size * 15) : h, outline_color);
render::text(x + ( w / 2 ), y + 2, font, elements[*current], true, text_color);
render::text(x + w + 10, y + 1, font, text, false, text_color);

if (open) {
    for (int i = 0; i < size; i++) {
        if (get_pos(x, y, w, h + 15 + (i * 15))) {
            *current = i;
            return;
        }

        render::text(x + ( w / 2 ), y + 15 + (i * 15), font, elements[i], true, i == *current ? active : idle);
    }
}
GLadiator279 commented 3 years ago

Sorry for being late. If u atleast paste it try to optimize it. Your whole code can be shortened to 20 lines and have it work the same way.

bool open = false;
static bool selected_opened = false;
static bool rest;
static std::string name_selected;

if ((cursor.x > position) && (cursor.x < position + w) && (cursor.y > y) && (cursor.y < y + h) && GetAsyncKeyState(VK_LBUTTON) & 1) {
  name_selected = string;
  if (!rest)
      selected_opened = !selected_opened;
  rest = true;
}
else
  rest = false;

if (name_selected == string)
  open = selected_opened;

this can be 3 lines and work the same, literally. ` static bool open = false;

if (get_pos(x, y, w, h))
  open = !open;`

only my preference but this can be out of this if statement if (open) { render::draw_filled_rect(position + 2, y - 1, w, 15 + (size * 15), color(36, 36, 36, 255));

This can also be shortened to 1 line and much optimized. if (i == *values) { render::text(position + 7, (y - 1) + 15 + (i * 15), font, elements[i].c_str(), false, color::white()); } else { render::text(position + 7, (y - 1) + 15 + (i * 15), font, elements[i].c_str(), false, color::white(100)); }

render::text(x + ( w / 2 ), y + 15 + (i * 15), font, elements[i], true, i == *current ? active : idle);

Look, i just made it better for you all

    static bool open = false;

if (get_pos(x, y, w, h))
  open = !open;

std::size_t size = elements.size();

render::draw_filled_rect(x + 2, y - 1, w, open ? 15 + (size * 15) : h, groupbox_background_alt);
render::draw_outline(x + 2, y - 1, w, open ? 15 + (size * 15) : h, outline_color);
render::text(x + ( w / 2 ), y + 2, font, elements[*current], true, text_color);
render::text(x + w + 10, y + 1, font, text, false, text_color);

if (open) {
  for (int i = 0; i < size; i++) {
      if (get_pos(x, y, w, h + 15 + (i * 15))) {
          *current = i;
          return;
      }

      render::text(x + ( w / 2 ), y + 15 + (i * 15), font, elements[i], true, i == *current ? active : idle);
  }
}

Good job, thanks for the explanation.