+#include "menu.qh"
+#include "oo/classes.qc"
+#include "xonotic/util.qh"
+
+#include "../common/items/all.qh"
+#include "../common/weapons/all.qh"
+#include "../common/mapinfo.qh"
+
///////////////////////////////////////////////
// Menu Source File
///////////////////////
float mouseButtonsPressed;
vector menuMousePos;
-float menuShiftState;
+int menuShiftState;
float menuPrevTime;
float menuAlpha;
float menuLogoAlpha;
// needs to be done so early because of the constants they create
CALL_ACCUMULATED_FUNCTION(RegisterWeapons);
+ CALL_ACCUMULATED_FUNCTION(RegisterItems);
CALL_ACCUMULATED_FUNCTION(RegisterGametypes);
RegisterSLCategories();
}
fclose(fh);
- glob = search_begin(strcat(draw_currentSkin, "/*.tga"), TRUE, TRUE);
+ glob = search_begin(strcat(draw_currentSkin, "/*.tga"), true, true);
if(glob >= 0)
{
n = search_getsize(glob);
draw_setMousePointer(SKINGFX_CURSOR, SKINSIZE_CURSOR, SKINOFFSET_CURSOR);
loadTooltips();
- anim = spawnAnimHost();
- main = spawnMainWindow(); main.configureMainWindow(main);
+ anim = NEW(AnimHost);
+ main = NEW(MainWindow); main.configureMainWindow(main);
unloadTooltips();
main.resizeNotify(main, '0 0 0', eX * conwidth + eY * conheight, '0 0 0', eX * conwidth + eY * conheight);
{
// detect a click outside of the game window
vector p = getmousepos();
- if(p_x < 0 || p_x > realconwidth || p_y < 0 || p_y > realconheight)
+ if(p.x < 0 || p.x > realconwidth || p.y < 0 || p.y > realconheight)
{
++mouseButtonsPressed;
return;
float width_is_larger;
sz = draw_PictureSize(img);
- width_is_larger = (sz_x * draw_scale_y >= sz_y * draw_scale_x);
- isz_w = '1 0 0' + '0 1 0' * ((sz_y / sz_x) * (draw_scale_x / draw_scale_y));
- isz_h = '0 1 0' + '1 0 0' * ((sz_x / sz_y) * (draw_scale_y / draw_scale_x));
+ width_is_larger = (sz.x * draw_scale.y >= sz.y * draw_scale.x);
+ isz_w = '1 0 0' + '0 1 0' * ((sz.y / sz.x) * (draw_scale.x / draw_scale.y));
+ isz_h = '0 1 0' + '1 0 0' * ((sz.x / sz.y) * (draw_scale.y / draw_scale.x));
switch(scalemode)
{
break;
}
- org = eX * (algn_x * (1 - isz_x)) + eY * (algn_y * (1 - isz_y));
+ org = eX * (algn.x * (1 - isz.x)) + eY * (algn.y * (1 - isz.y));
draw_Picture(org, img, isz, '1 1 1', a);
}
string c;
float scalemode;
- v_z = 0;
+ v.z = 0;
scalemode = SCALEMODE_CROP;
case "h": scalemode = SCALEMODE_HEIGHT; goto nopic;
case "w": scalemode = SCALEMODE_WIDTH; goto nopic;
case "s": scalemode = SCALEMODE_STRETCH; goto nopic;
- case "1": case "4": case "7": v_x = 0.0; break;
- case "2": case "5": case "8": v_x = 0.5; break;
- case "3": case "6": case "9": v_x = 1.0; break;
- default: v_x = random(); break;
+ case "1": case "4": case "7": v.x = 0.0; break;
+ case "2": case "5": case "8": v.x = 0.5; break;
+ case "3": case "6": case "9": v.x = 1.0; break;
+ default: v.x = random(); break;
}
switch(c)
{
- case "7": case "8": case "9": v_y = 0.0; break;
- case "4": case "5": case "6": v_y = 0.5; break;
- case "1": case "2": case "3": v_y = 1.0; break;
- default: v_y = random(); break;
+ case "7": case "8": case "9": v.y = 0.0; break;
+ case "4": case "5": case "6": v.y = 0.5; break;
+ case "1": case "2": case "3": v.y = 1.0; break;
+ default: v.y = random(); break;
}
if(l == 0)
draw_Picture_Aligned(v, scalemode, img, a);
float menuTooltipState; // 0: static, 1: fading in, 2: fading out
float m_testmousetooltipbox(vector pos)
{
- if(pos_x >= menuTooltipOrigin_x && pos_x < menuTooltipOrigin_x + menuTooltipSize_x)
- if(pos_y >= menuTooltipOrigin_y && pos_y < menuTooltipOrigin_y + menuTooltipSize_y)
- return FALSE;
- return TRUE;
+ if(pos.x >= menuTooltipOrigin.x && pos.x < menuTooltipOrigin.x + menuTooltipSize.x)
+ if(pos.y >= menuTooltipOrigin.y && pos.y < menuTooltipOrigin.y + menuTooltipSize.y)
+ return false;
+ return true;
}
float m_testtooltipbox(vector tooltippos)
{
- if(tooltippos_x < 0)
- return FALSE;
- if(tooltippos_y < 0)
- return FALSE;
- if(tooltippos_x + menuTooltipSize_x > 1)
- return FALSE;
- if(tooltippos_y + menuTooltipSize_y > 1)
- return FALSE;
+ if(tooltippos.x < 0)
+ return false;
+ if(tooltippos.y < 0)
+ return false;
+ if(tooltippos.x + menuTooltipSize.x > 1)
+ return false;
+ if(tooltippos.y + menuTooltipSize.y > 1)
+ return false;
menuTooltipOrigin = tooltippos;
- return TRUE;
+ return true;
}
float m_allocatetooltipbox(vector pos)
{
vector avoidplus, avoidminus;
vector v;
- avoidplus_x = (SKINAVOID_TOOLTIP_x + SKINSIZE_CURSOR_x - SKINOFFSET_CURSOR_x * SKINSIZE_CURSOR_x) / conwidth;
- avoidplus_y = (SKINAVOID_TOOLTIP_y + SKINSIZE_CURSOR_y - SKINOFFSET_CURSOR_y * SKINSIZE_CURSOR_y) / conheight;
- avoidplus_z = 0;
+ avoidplus.x = (SKINAVOID_TOOLTIP_x + SKINSIZE_CURSOR_x - SKINOFFSET_CURSOR_x * SKINSIZE_CURSOR_x) / conwidth;
+ avoidplus.y = (SKINAVOID_TOOLTIP_y + SKINSIZE_CURSOR_y - SKINOFFSET_CURSOR_y * SKINSIZE_CURSOR_y) / conheight;
+ avoidplus.z = 0;
- avoidminus_x = (SKINAVOID_TOOLTIP_x + SKINOFFSET_CURSOR_x * SKINSIZE_CURSOR_x) / conwidth + menuTooltipSize_x;
- avoidminus_y = (SKINAVOID_TOOLTIP_y + SKINOFFSET_CURSOR_y * SKINSIZE_CURSOR_y) / conheight + menuTooltipSize_y;
- avoidminus_z = 0;
+ avoidminus.x = (SKINAVOID_TOOLTIP_x + SKINOFFSET_CURSOR_x * SKINSIZE_CURSOR_x) / conwidth + menuTooltipSize.x;
+ avoidminus.y = (SKINAVOID_TOOLTIP_y + SKINOFFSET_CURSOR_y * SKINSIZE_CURSOR_y) / conheight + menuTooltipSize.y;
+ avoidminus.z = 0;
// bottom right
v = pos + avoidplus;
if(m_testtooltipbox(v))
- return TRUE;
+ return true;
// bottom center
- v_x = pos_x - menuTooltipSize_x * 0.5;
+ v.x = pos.x - menuTooltipSize.x * 0.5;
if(m_testtooltipbox(v))
- return TRUE;
+ return true;
// bottom left
- v_x = pos_x - avoidminus_x;
+ v.x = pos.x - avoidminus.x;
if(m_testtooltipbox(v))
- return TRUE;
+ return true;
// top left
- v_y = pos_y - avoidminus_y;
+ v.y = pos.y - avoidminus.y;
if(m_testtooltipbox(v))
- return TRUE;
+ return true;
// top center
- v_x = pos_x - menuTooltipSize_x * 0.5;
+ v.x = pos.x - menuTooltipSize.x * 0.5;
if(m_testtooltipbox(v))
- return TRUE;
+ return true;
// top right
- v_x = pos_x + avoidplus_x;
+ v.x = pos.x + avoidplus.x;
if(m_testtooltipbox(v))
- return TRUE;
+ return true;
- return FALSE;
+ return false;
}
entity m_findtooltipitem(entity root, vector pos)
{
menuTooltipState = 1;
menuTooltipItem = it;
- menuTooltipOrigin_x = -1; // unallocated
+ menuTooltipOrigin.x = -1; // unallocated
if (menuTooltipText)
strunzone(menuTooltipText);
{
s = getWrappedLine(SKINWIDTH_TOOLTIP, fontsize, draw_TextWidth_WithoutColors);
++i;
- f = draw_TextWidth(s, FALSE, fontsize);
+ f = draw_TextWidth(s, false, fontsize);
if(f > w)
w = f;
}
- menuTooltipSize_x = w + 2 * (SKINMARGIN_TOOLTIP_x / conwidth);
- menuTooltipSize_y = i * fontsize_y + 2 * (SKINMARGIN_TOOLTIP_y / conheight);
- menuTooltipSize_z = 0;
+ menuTooltipSize.x = w + 2 * (SKINMARGIN_TOOLTIP_x / conwidth);
+ menuTooltipSize.y = i * fontsize.y + 2 * (SKINMARGIN_TOOLTIP_y / conheight);
+ menuTooltipSize.z = 0;
}
break;
case 1:
menuTooltipItem = world; // reload tooltip next frame
menu_tooltips_old = menu_tooltips;
}
- else if(menuTooltipOrigin_x < 0) // unallocated?
+ else if(menuTooltipOrigin.x < 0) // unallocated?
m_allocatetooltipbox(pos);
- if(menuTooltipOrigin_x >= 0)
+ if(menuTooltipOrigin.x >= 0)
{
// draw the tooltip!
p = SKINBORDER_TOOLTIP;
- p_x *= 1 / conwidth;
- p_y *= 1 / conheight;
+ p.x *= 1 / conwidth;
+ p.y *= 1 / conheight;
draw_BorderPicture(menuTooltipOrigin, SKINGFX_TOOLTIP, menuTooltipSize, '1 1 1', menuTooltipAlpha, p);
p = menuTooltipOrigin;
- p_x += SKINMARGIN_TOOLTIP_x / conwidth;
- p_y += SKINMARGIN_TOOLTIP_y / conheight;
+ p.x += SKINMARGIN_TOOLTIP_x / conwidth;
+ p.y += SKINMARGIN_TOOLTIP_y / conheight;
getWrappedLine_remaining = menuTooltipText;
while(getWrappedLine_remaining)
{
s = getWrappedLine(SKINWIDTH_TOOLTIP, fontsize, draw_TextWidth_WithoutColors);
- draw_Text(p, s, fontsize, SKINCOLOR_TOOLTIP, SKINALPHA_TOOLTIP * menuTooltipAlpha, FALSE);
- p_y += fontsize_y;
+ draw_Text(p, s, fontsize, SKINCOLOR_TOOLTIP, SKINALPHA_TOOLTIP * menuTooltipAlpha, false);
+ p.y += fontsize.y;
}
}
}
{
draw_reset_full();
draw_Fill('0 0 0', '1 1 0', SKINCOLOR_BACKGROUND, 1);
- drawBackground(SKINGFX_BACKGROUND, bound(0, menuLogoAlpha, 1), SKINALIGN_BACKGROUND, TRUE);
+ drawBackground(SKINGFX_BACKGROUND, bound(0, menuLogoAlpha, 1), SKINALIGN_BACKGROUND, true);
draw_reset_cropped();
if(menuAlpha <= 0 && SKINALPHA_CURSOR_INTRO > 0)
{
if(menuAlpha > 0)
{
draw_reset_full();
- drawBackground(SKINGFX_BACKGROUND_INGAME, menuAlpha * SKINALPHA_BACKGROUND_INGAME, SKINALIGN_BACKGROUND_INGAME, FALSE);
+ drawBackground(SKINGFX_BACKGROUND_INGAME, menuAlpha * SKINALPHA_BACKGROUND_INGAME, SKINALIGN_BACKGROUND_INGAME, false);
draw_reset_cropped();
}
}
maxpos = globalToBox(eX * (realconwidth - 1) + eY * (realconheight - 1), draw_shift, draw_scale);
dMouse = globalToBoxSize(dMouse, draw_scale);
menuMousePos += dMouse * cvar("menu_mouse_speed");
- menuMousePos_x = bound(minpos_x, menuMousePos_x, maxpos_x);
- menuMousePos_y = bound(minpos_y, menuMousePos_y, maxpos_y);
+ menuMousePos.x = bound(minpos.x, menuMousePos.x, maxpos.x);
+ menuMousePos.y = bound(minpos.y, menuMousePos.y, maxpos.y);
if(mouseButtonsPressed)
main.mouseDrag(main, menuMousePos);
else
if(focus)
{
menuMousePos = focus.origin + 0.5 * focus.size;
- menuMousePos_x *= 1 / conwidth;
- menuMousePos_y *= 1 / conheight;
- if(wnd.focused) // why does this never happen?
+ menuMousePos.x *= 1 / conwidth;
+ menuMousePos.y *= 1 / conheight;
+ entity par = wnd.parent;
+ if(par.focused)
+ par.setFocus(par, wnd);
+ if(wnd.focused)
m_focus_item_chain(wnd, focus);
}
}
}
}
}
+
+float menuLastFocusSoundTime;
+void m_play_focus_sound()
+{
+ if(cvar("menu_sounds") > 1)
+ if(time - menuLastFocusSoundTime > 0.25)
+ {
+ localsound(MENU_SOUND_FOCUS);
+ menuLastFocusSoundTime = time;
+ }
+}
+
+void m_play_click_sound(string soundfile)
+{
+ if(cvar("menu_sounds"))
+ localsound(soundfile);
+}