Credits tally123
Thread discussion
http://www.uc-forum.com/forum/showthread.php?t=56065
The basic "method" for this menu came from my second attempt at making a menu, I was pokin around and seen this source and thought I would clean it up a bit and post it.
Intro/Info and global vars:
Read here
Code:
////////////////////////////////////////////////
/*
PAY ATTENTION
Drawing functions:
void FillRectD3D(int x, int y, int iWidth, int iHeight, DWORD dwColor);
void DrawBox(int StartX, int StartY, int Width, int Height, DWORD dwColor);
void DrawTextD3D(int x, int y, DWORD dwColor, char* szText, DWORD format, bool bEspFont = false);
For your coding pleasure you will have to find your own way to draw d3d, however drawbox is just 4 fillrect's in a box shape.
Comments have been added accordingly, and dont hate on the codes :)
*/
///////////////////////////////////////////////
//Global variables
bool showMenu = false;
int iEntries = 0;
int MenuRectH = 0;
int MenuRectW = 120;
/*
You could do something like
#define iNameTags MenuVal[1]
*/
int MenuVal[100];
int MenuColor[100];
int MenuMin[100];
int MenuMax[100];
int MenuInc[100];
Now on with the menu class:
Code:
class cMenu
{
public:
void DrawBack(int x, int y, int width, int height, bool bordered, DWORD dwBackCol, DWORD dwBorderCol);
void Drawtitle(char * Title, DWORD dwtitleCol);
void AddMember(int x, int y, char * Name, int MinVal, int MaxVal, int Increment);
void CheckKeys();
int MenuXPos;
int MenuYPos;
private:
int MenuX, MenuY;
int MenuW, MenuH;
int MenuSelected;
void AssignColors();
void End();
};
Continuing with the functions:
Code:
void cMenu::DrawBack(int x, int y, int width, int height, bool bordered, DWORD dwBackCol, DWORD dwBorderCol)
{
MenuX = x;
MenuY = y;
MenuW = width;
MenuH = height;
Renderer.FillRectD3D(x, y, width, height, dwBackCol);
if(bordered == true)
Renderer.DrawBox(x, y, width, height, dwBorderCol);
}
//This will draw a title in the correct place without much hassle :>
void cMenu::Drawtitle(char * Title, DWORD dwtitleCol)
{
Renderer.DrawTextD3D(MenuX + (MenuW / 2), MenuY + 2, dwtitleCol, Title, DT_CENTER, 0);
}
//There's a lot going on past this point, i know
void cMenu::AddMember(int x, int y, char * Name, int MinVal, int MaxVal, int Increment)
{
iEntries++;
//X and Y are offsets from the menu origin
x = MenuX + x;
y = MenuY + y;
//Store this entry's parameters in an array
MenuMin[iEntries] = MinVal;
MenuMax[iEntries] = MaxVal;
MenuInc[iEntries] = Increment;
//MenuVal[iEntries] stores, well, this entry's value
char cVal[5];
sprintf(cVal, "%i", MenuVal[iEntries]);
//Box that goes around the menu val
Renderer.DrawBox(x - 4, y - 1, 16, 14, MenuColor[iEntries]);
//Draw the menu value
Renderer.DrawTextD3D(x + 4, y, MenuColor[iEntries], cVal, DT_CENTER, 0);
//Draw the entry name
Renderer.DrawTextD3D(x + 20, y - 1, MenuColor[iEntries], Name, 0, 0);
}
//As you can see here, move the menu selection and variables with the arrow keys
void cMenu::CheckKeys()
{
if(GetAsyncKeyState(VK_UP)&1)
if(MenuSelected > 1)
MenuSelected--;
if(GetAsyncKeyState(VK_DOWN)&1)
if(MenuSelected < iEntries)
MenuSelected++;
if(GetAsyncKeyState(VK_RIGHT)&1)
{
if(MenuVal[MenuSelected] < MenuMax[MenuSelected])
MenuVal[MenuSelected] += MenuInc[MenuSelected];
if(MenuVal[MenuSelected] > MenuMax[MenuSelected])
MenuVal[MenuSelected] = MenuMax[MenuSelected];
}
if(GetAsyncKeyState(VK_LEFT)&1)
{
if(MenuVal[MenuSelected] > 0)
MenuVal[MenuSelected] -= MenuInc[MenuSelected];
if(MenuVal[MenuSelected] < 0)
MenuVal[MenuSelected] = 0;
}
if(MenuSelected < 1)
MenuSelected = 1;
//Keep the code sort-of organized
cMenu::AssignColors();
cMenu::End();
}
//Loop through all the menu entries and color them accordingly
void cMenu::AssignColors()
{
for(int mc = 0; mc < (iEntries + 1); mc++)
{
if(MenuSelected == mc)
MenuColor[mc] = 0xFF00FF00;
else
MenuColor[mc] = 0xFFFF0000;
}
}
//Set the height for the menu background and reset the entry number for the next frame
void cMenu::End()
{
MenuRectH = iEntries * 25;
iEntries = 0;
}
I wouldn't forget to show you how its used
Code:
//Example usage
cMenu CMenu;
void DoMenu()
{
if(GetAsyncKeyState(VK_DELETE)&1) showMenu = !showMenu;
if(showMenu == true)
{
CMenu.DrawBack(50, 200, 160, MenuRectH, true, D3DCOLOR_ARGB(220, 50, 50, 50), 0xFFFF0000);
CMenu.AddMember(25, 20, "ESP Name", 0, 1, 1);
CMenu.AddMember(25, 35, "ESP Health", 0, 1, 1);
CMenu.AddMember(25, 50, "Chams", 0, 1, 1);
CMenu.AddMember(25, 65, "Uc-Forum", 0, 1, 1);
CMenu.CheckKeys();
}
}
RESULT:
(the gray background is from a test app)
If you use it I would appreciate thanking me