Skip to content

Instantly share code, notes, and snippets.

@dotxnc
Created January 14, 2017 04:56
Show Gist options
  • Save dotxnc/d4fb52a39aa6723b26486124415a68fc to your computer and use it in GitHub Desktop.
Save dotxnc/d4fb52a39aa6723b26486124415a68fc to your computer and use it in GitHub Desktop.
rip old drop menu code
template <typename TYPE>
struct DropMenu {
std::vector<TYPE>* skins;
const wchar_t* name;
int index = 0;
bool thisdrop = false;
int x, y;
SourceEngine::EItemDefinitionIndex skinid;
bool needsupdate=true;
KeyToggle drop_click;
std::function<void(DropMenu*)> funct;
DropMenu(std::vector<TYPE>* _skins, const wchar_t* _name, std::function<void(DropMenu*)> _funct, SourceEngine::EItemDefinitionIndex _skinid, int _x, int _y) :
drop_click(ButtonCode_t::MOUSE_LEFT),
skinid(_skinid)
{
skins = _skins;
name = _name;
x = _x;
y = _y;
funct = _funct;
}
void Draw() {
Surface->DrawSetTextColor(255, 255, 255, 255);
Surface->DrawSetColor(0, 0, 120, 180);
DrawFillRect(x, y, 150, 20);
Surface->DrawSetColor(0, 0, 0, 255);
DrawRect(x, y, 150, 20);
DText(name, x + 5, y - 16);
std::string z((*skins)[index].name);
DText(std::wstring(z.begin(), z.end()).c_str(), x, y);
if (thisdrop)
{
for (int i = 0; i < skins->size(); i++) {
TYPE skin = (*skins)[i];
if (Cur.x > x && Cur.x < x + 150 && Cur.y > y + 20 + i * 20 && Cur.y < y + 20 + i * 20 + 20) {
Surface->DrawSetColor(0, 120, 0, 180);
if (drop_click) {
index = i;
needsupdate = true;
thisdrop = false;
drop = false;
}
}
else
Surface->DrawSetColor(0, 120, 120, 180);
DrawFillRect(x, y + 20 + i * 20, 150, 20);
Surface->DrawSetColor(0, 0, 0, 255);
DrawRect(x, y + 20 + i * 20, 150, 20);
Surface->DrawSetTextColor(255, 255, 255, 255);
std::string h(skin.name);
DText(std::wstring(h.begin(), h.end()).c_str(), x, y + 20 + i * 20);
}
}
if (drop_click) {
if (drop)
if (!thisdrop)
return;
if (Cur.x > this->x && Cur.x < this->x + 150 && Cur.y > this->y && Cur.y < this->y + 20) {
if (!drop && !thisdrop) {
this->thisdrop = true;
drop = true;
}
}
else {
drop = false;
this->thisdrop = false;
}
}
if (needsupdate) {
//set_skins(skinid, (*skins)[index].id);
funct(this);
needsupdate = false;
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment