rendered paste bodyvoid drawMenu() {
// Get item height
int itemHeight = sizeTextHeight(MENU_TEXT_SIZE, ð.fontVariable) + (2 * 2);
// Get max menu text width size
int maxItemWidth = 0;
int count;
for (count = 0; count < VARS_TOTAL; count++) {
int size = sizeTextWidth(MENU_TEXT_SIZE, seth.vars[count].menuText, ð.fontVariable);
if (size > maxItemWidth)
maxItemWidth = size;
}
maxItemWidth += itemHeight;
// Get max choice text width size
int maxValueWidth = 0;
for (count = 0; count < VARS_TOTAL; count++) {
int i = 0;
for (; i < MAX_CHOICES; i++) {
int size = sizeTextWidth(MENU_TEXT_SIZE, seth.vars[count].choices[i].name, ð.fontVariable);
if (size > maxValueWidth)
maxValueWidth = size;
}
}
maxValueWidth += itemHeight;
static int openCategory = -1;
int nextOpenCategory = openCategory;
int y = MENU_SCREEN_BORDER;
if (eth.mod->type == MOD_TCE)
y += 40;
int catCount = 0;
for (; catCount < CATS_MAX; catCount++) {
qboolean isMouseOn = ((eth.mouseX > MENU_SCREEN_BORDER)
&& (eth.mouseX < (MENU_SCREEN_BORDER + maxItemWidth))
&& (eth.mouseY > y)
&& (eth.mouseY < (y + itemHeight)));
// Sanity check
if (!menuCats[catCount].name)
fatalError("Can't find text for a menu category.");
// Draw category
if ( seth.value[ VAR_STYLEDMENU ] ) {
drawFillRoundRect(MENU_SCREEN_BORDER, y, maxItemWidth, itemHeight, isMouseOn ? colorBlack : gameBackColor);
drawRoundRect(MENU_SCREEN_BORDER, y, maxItemWidth, itemHeight, isMouseOn ? gameBackColor : gameBorderColor);
drawPic( MENU_SCREEN_BORDER + (itemHeight / 2), y - 5, itemHeight + 5, itemHeight + 5, eth.menuShader[ menuCats[ catCount ].id ] );
drawText(MENU_SCREEN_BORDER + (itemHeight / 2) + itemHeight + 5, y + 2, MENU_TEXT_SIZE, menuCats[catCount].name, isMouseOn ? gameFontColor : colorWhite, qfalse, qfalse, ð.fontVariable);
} else {
drawFillRect(MENU_SCREEN_BORDER, y, maxItemWidth, itemHeight, isMouseOn ? colorBlack : gameBackColor);
drawRect(MENU_SCREEN_BORDER, y, maxItemWidth, itemHeight, isMouseOn ? gameBackColor : gameBorderColor, 1);
drawText(MENU_SCREEN_BORDER + (itemHeight / 2) + itemHeight, y + 2, MENU_TEXT_SIZE, menuCats[catCount].name, isMouseOn ? gameFontColor : colorWhite, qfalse, qfalse, ð.fontVariable);
}
y += itemHeight + MENU_ITEM_SPACE ;
// Category click
if (((eth.mouseButton == Button1) || (eth.mouseButton == Button3)) && isMouseOn) {
eth.mouseButton = 0;
if (nextOpenCategory != catCount)
syscall_CG_S_StartLocalSound(eth.cgs_media_sndLimboSelect, CHAN_LOCAL_SOUND);
// open & close
if ( catCount != nextOpenCategory ) {
nextOpenCategory = catCount;
} else {
nextOpenCategory = -1;
}
}
// Draw vars only for this category
if (openCategory != catCount) {
if ( seth.value[ VAR_STYLEDMENU ] ) y += 5;
continue;
}
// Search vars in this category
int varCount = 0;
for (; varCount < VARS_TOTAL; varCount++) {
if (menuCats[catCount].id != seth.vars[varCount].menuCategory)
continue;
ethVars_t *var = &seth.vars[varCount];
isMouseOn = ((eth.mouseX > MENU_SCREEN_BORDER + MENU_ENTRY_SPACE)
&& (eth.mouseX < (MENU_SCREEN_BORDER + MENU_ENTRY_SPACE + maxItemWidth + MENU_ITEM_SPACE + maxValueWidth))
&& (eth.mouseY > y)
&& (eth.mouseY < (y + itemHeight)));
// Draw var
if ( seth.value[ VAR_STYLEDMENU ] ) {
drawFillRoundRect(MENU_SCREEN_BORDER + MENU_ENTRY_SPACE, y, maxItemWidth, itemHeight, isMouseOn ? colorBlack : gameBackColor);
drawRoundRect(MENU_SCREEN_BORDER + MENU_ENTRY_SPACE, y, maxItemWidth, itemHeight, isMouseOn ? gameBackColor : gameBorderColor);
drawText(MENU_SCREEN_BORDER + MENU_ENTRY_SPACE + (itemHeight / 2) + sizeTextWidth(MENU_TEXT_SIZE, " ", ð.fontVariable), y + 2, MENU_TEXT_SIZE, var->menuText, colorLtGrey, qfalse, qfalse, ð.fontVariable);
} else {
drawFillRect(MENU_SCREEN_BORDER, y, maxItemWidth, itemHeight, isMouseOn ? colorBlack : gameBackColor);
drawRect(MENU_SCREEN_BORDER, y, maxItemWidth, itemHeight, isMouseOn ? gameBackColor : gameBorderColor, 1);
drawText(MENU_SCREEN_BORDER + (itemHeight / 2) + sizeTextWidth(MENU_TEXT_SIZE, " ", ð.fontVariable), y + 2, MENU_TEXT_SIZE, var->menuText, colorLtGrey, qfalse, qfalse, ð.fontVariable);
}
// Search position of the current value
int pos = 0;
while ((var->choices[pos].name != NULL) // Check for valid choice
&& (var->choices[pos].value != seth.value[varCount])
&& (pos < MAX_CHOICES)) {
pos++;
}
// Get name of this value
char value[32];
memset(value, 0, sizeof(value));
if ((pos == MAX_CHOICES) || (var->choices[pos].name == NULL))
sprintf(value, "%.2f", seth.value[varCount]);
else
strncpy(value, var->choices[pos].name, sizeof(value));
// Draw value of this var
if ( seth.value[ VAR_STYLEDMENU ] ) {
drawFillRoundRect(MENU_SCREEN_BORDER + MENU_ENTRY_SPACE + MENU_ITEM_SPACE + maxItemWidth, y, maxValueWidth, itemHeight, isMouseOn ? colorBlack : gameBackColor);
drawRoundRect(MENU_SCREEN_BORDER + MENU_ENTRY_SPACE + MENU_ITEM_SPACE + maxItemWidth, y, maxValueWidth, itemHeight, isMouseOn ? gameBackColor : gameBorderColor);
int w = sizeTextWidth(MENU_TEXT_SIZE, value, ð.fontVariable);
drawText(MENU_SCREEN_BORDER + MENU_ENTRY_SPACE + MENU_ITEM_SPACE + maxItemWidth + (maxValueWidth / 2) - (w / 2), y + 2, MENU_TEXT_SIZE, value, colorLtGrey, qfalse, qfalse, ð.fontVariable);
} else {
drawFillRect(MENU_SCREEN_BORDER + MENU_ITEM_SPACE + maxItemWidth, y, maxValueWidth, itemHeight, isMouseOn ? colorBlack : gameBackColor);
drawRect(MENU_SCREEN_BORDER + MENU_ITEM_SPACE + maxItemWidth, y, maxValueWidth, itemHeight, isMouseOn ? gameBackColor : gameBorderColor, 1);
int w = sizeTextWidth(MENU_TEXT_SIZE, value, ð.fontVariable);
drawText(MENU_SCREEN_BORDER + MENU_ITEM_SPACE + maxItemWidth + (maxValueWidth / 2) - (w / 2), y + 2, MENU_TEXT_SIZE, value, colorLtGrey, qfalse, qfalse, ð.fontVariable);
}
y += itemHeight + MENU_ITEM_SPACE;
// If not a value click
if (((eth.mouseButton != Button1) && (eth.mouseButton != Button3)) || !isMouseOn)
continue;
// Get max choices
int max = 0;
while (var->choices[max].name != NULL)
max++;
// Pre-define values
if (max) {
// If current value no found take 0
if ((pos < 0) || (pos == MAX_CHOICES))
pos = 0;
// Set new position
if (eth.mouseButton == Button1)
pos++;
else
pos--;
// Check bounds
if (pos >= max)
pos = 0;
else if (pos < 0)
pos = max - 1;
seth.value[varCount] = var->choices[pos].value;
// Automatically disable draw2d when we turn on custom hud
// and enable it when we turn it off
if (varCount == VAR_CHUD) {
if (seth.value[varCount] == HUD_OFF)
orig_Cvar_Set2("cg_draw2d", "1", qtrue);
else
orig_Cvar_Set2("cg_draw2d", "0", qtrue);
}
// Manual value
} else {
// Set new value
if (eth.mouseButton == Button1) {
seth.value[varCount] += seth.value[VAR_STEP];
if ((varCount == VAR_AIMFOV) && (seth.value[varCount] > 360.0f))
seth.value[varCount] -= 360.0f;
if ((varCount == VAR_HUMANVALUE) && (seth.value[varCount] > 1.0f))
seth.value[varCount] -= seth.value[VAR_STEP];
}
else {
seth.value[varCount] -= seth.value[VAR_STEP];
if ((varCount == VAR_AIMFOV) && (seth.value[varCount] < 0.01f)) // 0.01 to make it 360.0 instead of 0.0 when decreasing
seth.value[varCount] += 360.0f;
if ((varCount == VAR_HUMANVALUE) && (seth.value[varCount] < 0.0f))
seth.value[varCount] += seth.value[VAR_STEP];
}
}
// Set cvar
/* char cmd[50];
sprintf(cmd, "%s%s %i\n", ETH_CVAR_PREFIX, menuItems[pos].cvarName, menuItems[count].choices[pos].value);
orig_syscall(CG_SENDCONSOLECOMMAND, cmd);*/
syscall_CG_S_StartLocalSound(eth.cgs_media_sndLimboSelect, CHAN_LOCAL_SOUND);
eth.mouseButton = 0;
}
if ( seth.value[ VAR_STYLEDMENU ] ) y += 5;
}
openCategory = nextOpenCategory;
eth.mouseButton = 0;
}