X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fxonotic-data.pk3dir.git;a=blobdiff_plain;f=qcsrc%2Fmenu%2Fmenu.qc;h=d8a3ede2e7d8988afd29865a409af7de2defe772;hp=0926458bf37989f3100460e788b12b50c95a0fbd;hb=2f239100c8b77275d69972f91ac4e7ff913f3d7c;hpb=e6eb6e7fc36a3a243c5171b8cc3db88e823514d4 diff --git a/qcsrc/menu/menu.qc b/qcsrc/menu/menu.qc index 0926458bf3..d8a3ede2e7 100644 --- a/qcsrc/menu/menu.qc +++ b/qcsrc/menu/menu.qc @@ -1,3 +1,11 @@ +#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 /////////////////////// @@ -7,7 +15,7 @@ float mouseButtonsPressed; vector menuMousePos; -float menuShiftState; +int menuShiftState; float menuPrevTime; float menuAlpha; float menuLogoAlpha; @@ -73,6 +81,7 @@ void m_init() // 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(); @@ -92,8 +101,6 @@ void m_init() cvar_set("_menu_initialized", "1"); } - //PlayerInfo_Details(); - PlayerStats_PlayerDetail_CheckUpdate(); } const float MENU_ASPECT = 1.25; // 1280x1024 @@ -196,7 +203,7 @@ void m_init_delayed() } 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); @@ -208,8 +215,8 @@ void m_init_delayed() 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); @@ -266,7 +273,7 @@ void m_keydown(float key, float ascii) { // 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; @@ -316,13 +323,10 @@ void draw_Picture_Aligned(vector algn, float scalemode, string img, float a) 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)); -#ifdef GMQCC - isz = '0 0 0'; -#endif switch(scalemode) { default: @@ -343,7 +347,7 @@ void draw_Picture_Aligned(vector algn, float scalemode, string img, float a) 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); } @@ -357,7 +361,7 @@ void drawBackground(string img, float a, string algn, float force1) string c; float scalemode; - v_z = 0; + v.z = 0; scalemode = SCALEMODE_CROP; @@ -372,17 +376,17 @@ void drawBackground(string img, float a, string algn, float force1) 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); @@ -409,68 +413,68 @@ string menuTooltipText; 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) { @@ -578,7 +582,7 @@ void m_tooltip(vector pos) menuTooltipState = 1; menuTooltipItem = it; - menuTooltipOrigin_x = -1; // unallocated + menuTooltipOrigin.x = -1; // unallocated if (menuTooltipText) strunzone(menuTooltipText); @@ -591,13 +595,13 @@ void m_tooltip(vector pos) { 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: @@ -650,25 +654,25 @@ void m_tooltip(vector pos) 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; } } } @@ -761,7 +765,7 @@ void m_draw(float width, float height) { 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) { @@ -776,7 +780,7 @@ void m_draw(float width, float height) 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(); } } @@ -830,8 +834,8 @@ void m_draw(float width, float height) 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 @@ -958,9 +962,12 @@ void m_setpointerfocus(entity wnd) 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); } } @@ -1003,3 +1010,20 @@ void m_goto(string itemname) } } } + +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); +}