X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fmenu%2Fmenu.qc;h=bccf5c8d61ea28fbf50e2191efe8482786382be6;hb=ee3543c1c14ffc6cd14b6dbd07d76d4cb65e3bd6;hp=594844117c1afc7ee50bc9e929276f67a9e00f40;hpb=efab64ab443b4182a8dda35f0fb517eb78897ea0;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/menu/menu.qc b/qcsrc/menu/menu.qc index 594844117..382a19d2d 100644 --- a/qcsrc/menu/menu.qc +++ b/qcsrc/menu/menu.qc @@ -16,25 +16,47 @@ float menuInitialized; float menuNotTheFirstFrame; float menuMouseMode; -void SUB_Null() { } +float conwidth_s, conheight_s, vidwidth_s, vidheight_s, vidpixelheight_s, + realconwidth, realconheight; void m_sync() { updateCompression(); - updateConwidths(); + vidwidth_s = vidheight_s = vidpixelheight_s = 0; // Force updateConwidths on next draw. loadAllCvars(main); } +void m_gamestatus() +{ + gamestatus = 0; + if(isserver()) + gamestatus = gamestatus | GAME_ISSERVER; + if(clientstate() == CS_CONNECTED || isdemo()) + gamestatus = gamestatus | GAME_CONNECTED; + if(cvar("developer")) + gamestatus = gamestatus | GAME_DEVELOPER; +} + void m_init() { + float restarting = 0; cvar_set("_menu_alpha", "0"); - prvm_language = strzone(cvar_string("prvm_language")); + prvm_language = cvar_string("prvm_language"); + if(prvm_language == "") + { + prvm_language = "en"; + cvar_set("prvm_language", prvm_language); + localcmd("\nmenu_restart\n"); + restarting = 1; + } + prvm_language = strzone(prvm_language); + cvar_set("_menu_prvm_language", prvm_language); check_unacceptable_compiler_bugs(); #ifdef WATERMARK - print(sprintf(_("^4MQC Build information: ^1%s\n"), WATERMARK())); + printf(_("^4MQC Build information: ^1%s\n"), WATERMARK); #endif // list all game dirs (TEST) @@ -45,26 +67,55 @@ void m_init() for(i = 0; ; ++i) { s = getgamedirinfo(i, GETGAMEDIRINFO_NAME); - if not(s) + if (!s) break; dprint(s, ": ", getgamedirinfo(i, GETGAMEDIRINFO_DESCRIPTION)); } } + + // needs to be done so early because of the constants they create + CALL_ACCUMULATED_FUNCTION(RegisterWeapons); + CALL_ACCUMULATED_FUNCTION(RegisterGametypes); + + RegisterSLCategories(); + + float ddsload = cvar("r_texture_dds_load"); + float texcomp = cvar("gl_texturecompression"); + updateCompression(); + if(ddsload != cvar("r_texture_dds_load") || texcomp != cvar("gl_texturecompression")) + localcmd("\nr_restart\n"); + + if(!restarting) + { + if(cvar("_menu_initialized")) // always show menu after menu_restart + m_display(); + else + m_hide(); + cvar_set("_menu_initialized", "1"); + } } -float MENU_ASPECT = 1.25; // 1280x1024 -float MENU_MINHEIGHT = 600; -float conwidth_s, conheight_s, realconwidth, realconheight, screenconwidth, screenconheight; +const float MENU_ASPECT = 1.25; // 1280x1024 + void draw_reset_cropped() { - draw_reset(screenconwidth, screenconheight, 0.5 * (realconwidth - screenconwidth), 0.5 * (realconheight - screenconheight)); + draw_reset(conwidth, conheight, 0.5 * (realconwidth - conwidth), 0.5 * (realconheight - conheight)); } void draw_reset_full() { draw_reset(realconwidth, realconheight, 0, 0); } -void UpdateConWidthHeight() + +void UpdateConWidthHeight(float w, float h, float p) { + if (w != vidwidth_s || h != vidheight_s || p != vidpixelheight_s) + { + if (updateConwidths(w, h, p)) + localcmd(sprintf("\nexec %s\n", cvar_string("menu_font_cfg"))); + vidwidth_s = w; + vidheight_s = h; + vidpixelheight_s = p; + } conwidth_s = conwidth; conheight_s = conheight; realconwidth = cvar("vid_conwidth"); @@ -81,18 +132,6 @@ void UpdateConWidthHeight() conwidth = realconwidth; conheight = realconwidth / MENU_ASPECT; } - screenconwidth = conwidth; - screenconheight = conheight; - if(conwidth < MENU_MINHEIGHT * MENU_ASPECT) - { - conheight *= MENU_MINHEIGHT * MENU_ASPECT / conwidth; - conwidth = MENU_MINHEIGHT * MENU_ASPECT; - } - if(conheight < MENU_MINHEIGHT) - { - conwidth *= MENU_MINHEIGHT / conheight; - conheight = MENU_MINHEIGHT; - } if(main) { if(conwidth_s != conwidth || conheight_s != conheight) @@ -101,15 +140,18 @@ void UpdateConWidthHeight() main.resizeNotify(main, '0 0 0', eX * conwidth + eY * conheight, '0 0 0', eX * conwidth + eY * conheight); } } + else + { + vidwidth_s = vidheight_s = vidpixelheight_s = 0; // retry next frame + } } +string m_goto_buffer; void m_init_delayed() { float fh, glob, n, i; string s; - conwidth = conheight = -1; - UpdateConWidthHeight(); draw_reset_cropped(); menuInitialized = 0; @@ -117,8 +159,6 @@ void m_init_delayed() return; menuInitialized = 1; - RegisterWeapons(); - fh = -1; if(cvar_string("menu_skin") != "") { @@ -178,6 +218,13 @@ void m_init_delayed() m_sync(); + if(m_goto_buffer) + { + m_goto(m_goto_buffer); + strunzone(m_goto_buffer); + m_goto_buffer = string_null; + } + if(Menu_Active) m_display(); // delayed menu display } @@ -212,6 +259,19 @@ void m_keydown(float key, float ascii) return; if(!Menu_Active) return; + + if(menuMouseMode) + if(key >= K_MOUSE1 && key <= K_MOUSE3) + { + // detect a click outside of the game window + vector p = getmousepos(); + if(p_x < 0 || p_x > realconwidth || p_y < 0 || p_y > realconheight) + { + ++mouseButtonsPressed; + return; + } + } + if(keyGrabber) { entity e; @@ -244,11 +304,11 @@ void m_keydown(float key, float ascii) if(key == K_SHIFT) menuShiftState |= S_SHIFT; } -float SCALEMODE_CROP = 0; -float SCALEMODE_LETTERBOX = 1; -float SCALEMODE_WIDTH = 2; -float SCALEMODE_HEIGHT = 3; -float SCALEMODE_STRETCH = 4; +const float SCALEMODE_CROP = 0; +const float SCALEMODE_LETTERBOX = 1; +const float SCALEMODE_WIDTH = 2; +const float SCALEMODE_HEIGHT = 3; +const float SCALEMODE_STRETCH = 4; void draw_Picture_Aligned(vector algn, float scalemode, string img, float a) { vector sz, org, isz, isz_w, isz_h; @@ -259,6 +319,9 @@ void draw_Picture_Aligned(vector algn, float scalemode, string img, float a) 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: @@ -297,6 +360,7 @@ void drawBackground(string img, float a, string algn, float force1) scalemode = SCALEMODE_CROP; + l = 0; for(i = 0; i < strlen(algn); ++i) { c = substring(algn, i, 1); @@ -379,7 +443,7 @@ float m_allocatetooltipbox(vector pos) v = pos + avoidplus; if(m_testtooltipbox(v)) return TRUE; - + // bottom center v_x = pos_x - menuTooltipSize_x * 0.5; if(m_testtooltipbox(v)) @@ -399,12 +463,12 @@ float m_allocatetooltipbox(vector pos) v_x = pos_x - menuTooltipSize_x * 0.5; if(m_testtooltipbox(v)) return TRUE; - + // top right v_x = pos_x + avoidplus_x; if(m_testtooltipbox(v)) return TRUE; - + return FALSE; } entity m_findtooltipitem(entity root, vector pos) @@ -609,18 +673,21 @@ void m_tooltip(vector pos) } } -void m_draw() +void m_draw(float width, float height) { float t; float realFrametime; + m_gamestatus(); + + execute_next_frame(); + menuMouseMode = cvar("menu_mouse_absolute"); if (anim) anim.tickAll(anim); - if(main) - UpdateConWidthHeight(); + UpdateConWidthHeight(width, height, cvar("vid_pixelheight")); if(!menuInitialized) { @@ -634,7 +701,7 @@ void m_draw() if(Menu_Active) if(!cvar("menu_video_played")) { - localcmd("cd loop $menu_cdtrack; play sound/announcer/default/welcome.ogg\n"); + localcmd("cd loop $menu_cdtrack; play sound/announcer/default/welcome.wav\n"); menuLogoAlpha = -0.8; // no idea why, but when I start this at zero, it jumps instead of fading FIXME } // ALWAYS set this cvar; if we start but menu is not active, this means we want no background music! @@ -666,14 +733,6 @@ void m_draw() if(cvar("cl_capturevideo")) frametime = t / cvar("cl_capturevideo_fps"); // make capturevideo work smoothly - gamestatus = 0; - if(isserver()) - gamestatus = gamestatus | GAME_ISSERVER; - if(clientstate() == CS_CONNECTED) - gamestatus = gamestatus | GAME_CONNECTED; - if(cvar("developer")) - gamestatus = gamestatus | GAME_DEVELOPER; - prevMenuAlpha = menuAlpha; if(Menu_Active) { @@ -739,7 +798,12 @@ void m_draw() draw_alpha *= menuAlpha; - if(menuMouseMode) + if(!Menu_Active) + { + // do not update mouse position + // it prevents mouse jumping to '0 0 0' when menu is fading out + } + else if(menuMouseMode) { vector newMouse; newMouse = globalToBox(getmousepos(), draw_shift, draw_scale); @@ -905,11 +969,18 @@ void m_goto(string itemname) { entity e; if(!menuInitialized) + { + if(m_goto_buffer) + strunzone(m_goto_buffer); + m_goto_buffer = strzone(itemname); return; + } if(itemname == "") // this can be called by GameCommand { if(gamestatus & (GAME_ISSERVER | GAME_CONNECTED)) + { m_hide(); + } else { m_activate_window(main.mainNexposee); @@ -921,7 +992,8 @@ void m_goto(string itemname) for(e = NULL; (e = find(e, name, itemname)); ) if(e.classname != "vtbl") break; - if(e) + + if((e) && (!e.requiresConnection || (gamestatus & (GAME_ISSERVER | GAME_CONNECTED)))) { m_hide(); m_activate_window(e); @@ -930,27 +1002,3 @@ void m_goto(string itemname) } } } - -void m_goto_skin_selector() -{ - if(!menuInitialized) - return; - // TODO add code to switch back to the skin selector (no idea how to do it now) - m_goto("skinselector"); -} - -void m_goto_language_selector() -{ - if(!menuInitialized) - return; - // TODO add code to switch back to the language selector (no idea how to do it now) - m_goto("languageselector"); -} - -void m_goto_video_settings() -{ - if(!menuInitialized) - return; - // TODO add code to switch back to the video settings (no idea how to do it now) - m_goto("videosettings"); -}