X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fxonotic-data.pk3dir.git;a=blobdiff_plain;f=qcsrc%2Fmenu%2Fmenu.qc;h=d01f6f7d4d0d2f986a288f1de66b2948219ba777;hp=85aa3a640e319a055b56926f053ec58d72c12558;hb=08e6497842b33529d0c1b0caa431b49ca98d79da;hpb=bb450e879647c09efd145e95637ee17508d1d1cb diff --git a/qcsrc/menu/menu.qc b/qcsrc/menu/menu.qc index 85aa3a640e..d01f6f7d4d 100644 --- a/qcsrc/menu/menu.qc +++ b/qcsrc/menu/menu.qc @@ -1,3 +1,12 @@ +#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" +#include "../common/mutators/base.qh" + /////////////////////////////////////////////// // Menu Source File /////////////////////// @@ -7,7 +16,7 @@ float mouseButtonsPressed; vector menuMousePos; -float menuShiftState; +int menuShiftState; float menuPrevTime; float menuAlpha; float menuLogoAlpha; @@ -72,8 +81,7 @@ void m_init() } // needs to be done so early because of the constants they create - CALL_ACCUMULATED_FUNCTION(RegisterWeapons); - CALL_ACCUMULATED_FUNCTION(RegisterGametypes); + static_init(); RegisterSLCategories(); @@ -194,7 +202,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); @@ -206,8 +214,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); @@ -264,7 +272,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; @@ -314,13 +322,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: @@ -341,7 +346,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); } @@ -355,7 +360,7 @@ void drawBackground(string img, float a, string algn, float force1) string c; float scalemode; - v_z = 0; + v.z = 0; scalemode = SCALEMODE_CROP; @@ -370,17 +375,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); @@ -407,68 +412,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) { @@ -576,7 +581,7 @@ void m_tooltip(vector pos) menuTooltipState = 1; menuTooltipItem = it; - menuTooltipOrigin_x = -1; // unallocated + menuTooltipOrigin.x = -1; // unallocated if (menuTooltipText) strunzone(menuTooltipText); @@ -589,13 +594,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: @@ -648,25 +653,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; } } } @@ -759,7 +764,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) { @@ -774,7 +779,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(); } } @@ -828,8 +833,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 @@ -956,9 +961,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); } }