From: terencehill Date: Sat, 23 Mar 2013 17:19:56 +0000 (+0100) Subject: Trying to restructure hud panel code making use of an entity for each panel X-Git-Tag: xonotic-v0.7.0~62^2~10 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=2814e7cda0098491e3e6624c6bd826e507b63d67;p=xonotic%2Fxonotic-data.pk3dir.git Trying to restructure hud panel code making use of an entity for each panel --- diff --git a/qcsrc/client/Main.qc b/qcsrc/client/Main.qc index f8b6e9cf0..3d286b31d 100644 --- a/qcsrc/client/Main.qc +++ b/qcsrc/client/Main.qc @@ -156,7 +156,8 @@ void CSQC_Init(void) CALL_ACCUMULATED_FUNCTION(RegisterGametypes); CALL_ACCUMULATED_FUNCTION(RegisterNotifications); CALL_ACCUMULATED_FUNCTION(RegisterDeathtypes); - + CALL_ACCUMULATED_FUNCTION(RegisterHUD_Panels); + WaypointSprite_Load(); // precaches diff --git a/qcsrc/client/hud.qc b/qcsrc/client/hud.qc index bec60a5e8..eb529c094 100644 --- a/qcsrc/client/hud.qc +++ b/qcsrc/client/hud.qc @@ -487,11 +487,9 @@ void HUD_Weapons(void) return; } } - else - hud_configure_active_panel = HUD_PANEL_WEAPONS; // update generic hud functions - HUD_Panel_UpdateCvars(weapons); + HUD_Panel_UpdateCvars(); HUD_Panel_ApplyFadeAlpha(); draw_beginBoldFont(); @@ -950,10 +948,8 @@ void HUD_Ammo(void) if(!autocvar_hud_panel_ammo) return; if(spectatee_status == -1) return; } - else - hud_configure_active_panel = HUD_PANEL_AMMO; - HUD_Panel_UpdateCvars(ammo); + HUD_Panel_UpdateCvars(); HUD_Panel_ApplyFadeAlpha(); draw_beginBoldFont(); @@ -1154,14 +1150,12 @@ void HUD_Powerups(void) } else { - hud_configure_active_panel = HUD_PANEL_POWERUPS; - strength_time = 15; shield_time = 27; superweapons_time = 13; } - HUD_Panel_UpdateCvars(powerups); + HUD_Panel_UpdateCvars(); HUD_Panel_ApplyFadeAlpha(); draw_beginBoldFont(); @@ -1397,14 +1391,12 @@ void HUD_HealthArmor(void) } else { - hud_configure_active_panel = HUD_PANEL_HEALTHARMOR; - health = 150; armor = 75; fuel = 20; } - HUD_Panel_UpdateCvars(healtharmor); + HUD_Panel_UpdateCvars(); HUD_Panel_ApplyFadeAlpha(); vector pos, mySize; pos = panel_pos; @@ -1656,10 +1648,8 @@ void HUD_Notify(void) { if(!autocvar_hud_panel_notify) return; } - else - hud_configure_active_panel = HUD_PANEL_NOTIFY; - HUD_Panel_UpdateCvars(notify); + HUD_Panel_UpdateCvars(); HUD_Panel_ApplyFadeAlpha(); vector pos, mySize; pos = panel_pos; @@ -1795,10 +1785,8 @@ void HUD_Timer(void) { if(!autocvar_hud_panel_timer) return; } - else - hud_configure_active_panel = HUD_PANEL_TIMER; - HUD_Panel_UpdateCvars(timer); + HUD_Panel_UpdateCvars(); HUD_Panel_ApplyFadeAlpha(); draw_beginBoldFont(); @@ -1865,12 +1853,10 @@ void HUD_Radar(void) if (autocvar_hud_panel_radar != 2 && !teamplay) return; } } - else - hud_configure_active_panel = HUD_PANEL_RADAR; - HUD_Panel_UpdateCvars(radar); + HUD_Panel_UpdateCvars(); HUD_Panel_ApplyFadeAlpha(); - + float f = 0; if (hud_panel_radar_maximized && !autocvar__hud_configure) @@ -2159,10 +2145,8 @@ void HUD_Score(void) if(!autocvar_hud_panel_score) return; if(spectatee_status == -1 && (gametype == MAPINFO_TYPE_RACE || gametype == MAPINFO_TYPE_CTS)) return; } - else - hud_configure_active_panel = HUD_PANEL_SCORE; - HUD_Panel_UpdateCvars(score); + HUD_Panel_UpdateCvars(); HUD_Panel_ApplyFadeAlpha(); vector pos, mySize; pos = panel_pos; @@ -2356,10 +2340,8 @@ void HUD_RaceTimer (void) if(!(gametype == MAPINFO_TYPE_RACE || gametype == MAPINFO_TYPE_CTS)) return; if(spectatee_status == -1) return; } - else - hud_configure_active_panel = HUD_PANEL_RACETIMER; - HUD_Panel_UpdateCvars(racetimer); + HUD_Panel_UpdateCvars(); HUD_Panel_ApplyFadeAlpha(); draw_beginBoldFont(); @@ -2508,7 +2490,7 @@ float vote_prev; // previous state of vote_active to check for a change float vote_alpha; float vote_change; // "time" when vote_active changed -void HUD_VoteWindow(void) +void HUD_Vote(void) { if(autocvar_cl_allow_uid2name == -1 && (gametype == MAPINFO_TYPE_CTS || gametype == MAPINFO_TYPE_RACE || (serverflags & SERVERFLAG_PLAYERSTATS))) { @@ -2540,8 +2522,6 @@ void HUD_VoteWindow(void) } else { - hud_configure_active_panel = HUD_PANEL_VOTE; - vote_yescount = 3; vote_nocount = 2; vote_needed = 4; @@ -2562,7 +2542,7 @@ void HUD_VoteWindow(void) if(!vote_alpha) return; - HUD_Panel_UpdateCvars(vote); + HUD_Panel_UpdateCvars(); HUD_Panel_ApplyFadeAlpha(); if(uid2name_dialog) @@ -3320,10 +3300,8 @@ void HUD_ModIcons(void) if(!autocvar_hud_panel_modicons) return; if (gametype != MAPINFO_TYPE_CTF && gametype != MAPINFO_TYPE_KEYHUNT && gametype != MAPINFO_TYPE_NEXBALL && gametype != MAPINFO_TYPE_CTS && gametype != MAPINFO_TYPE_RACE && gametype != MAPINFO_TYPE_CA && gametype != MAPINFO_TYPE_FREEZETAG && gametype != MAPINFO_TYPE_KEEPAWAY && gametype != MAPINFO_TYPE_DOMINATION) return; } - else - hud_configure_active_panel = HUD_PANEL_MODICONS; - HUD_Panel_UpdateCvars(modicons); + HUD_Panel_UpdateCvars(); HUD_Panel_ApplyFadeAlpha(); draw_beginBoldFont(); @@ -3372,18 +3350,15 @@ void HUD_ModIcons(void) // Draw pressed keys (#11) // -void HUD_DrawPressedKeys(void) +void HUD_PressedKeys(void) { if(!autocvar__hud_configure) { if(!autocvar_hud_panel_pressedkeys) return; if(spectatee_status <= 0 && autocvar_hud_panel_pressedkeys < 2) return; } - else - hud_configure_active_panel = HUD_PANEL_PRESSEDKEYS; - - HUD_Panel_UpdateCvars(pressedkeys); + HUD_Panel_UpdateCvars(); HUD_Panel_ApplyFadeAlpha(); vector pos, mySize; pos = panel_pos; @@ -3454,10 +3429,8 @@ void HUD_Chat(void) if(autocvar__con_chat_maximized) if(!hud_draw_maximized) return; } - else - hud_configure_active_panel = HUD_PANEL_CHAT; - HUD_Panel_UpdateCvars(chat); + HUD_Panel_UpdateCvars(); HUD_Panel_ApplyFadeAlpha(); if(autocvar__con_chat_maximized && !autocvar__hud_configure) // draw at full screen height if maximized @@ -3530,10 +3503,8 @@ void HUD_EngineInfo(void) { if(!autocvar_hud_panel_engineinfo) return; } - else - hud_configure_active_panel = HUD_PANEL_ENGINEINFO; - HUD_Panel_UpdateCvars(engineinfo); + HUD_Panel_UpdateCvars(); HUD_Panel_ApplyFadeAlpha(); vector pos, mySize; pos = panel_pos; @@ -3593,10 +3564,8 @@ void HUD_InfoMessages(void) { if(!autocvar_hud_panel_infomessages) return; } - else - hud_configure_active_panel = HUD_PANEL_INFOMESSAGES; - HUD_Panel_UpdateCvars(infomessages); + HUD_Panel_UpdateCvars(); HUD_Panel_ApplyFadeAlpha(); vector pos, mySize; pos = panel_pos; @@ -3784,10 +3753,8 @@ void HUD_Physics(void) if(spectatee_status == -1 && (autocvar_hud_panel_physics == 1 || autocvar_hud_panel_physics == 3)) return; if(autocvar_hud_panel_physics == 3 && !(gametype == MAPINFO_TYPE_RACE || gametype == MAPINFO_TYPE_CTS)) return; } - else - hud_configure_active_panel = HUD_PANEL_PHYSICS; - HUD_Panel_UpdateCvars(physics); + HUD_Panel_UpdateCvars(); HUD_Panel_ApplyFadeAlpha(); draw_beginBoldFont(); @@ -4167,8 +4134,6 @@ void HUD_CenterPrint (void) } else { - hud_configure_active_panel = HUD_PANEL_CENTERPRINT; - if (!hud_configure_prev) reset_centerprint_messages(); if (time > hud_configure_cp_generation_time) @@ -4185,7 +4150,7 @@ void HUD_CenterPrint (void) } } - HUD_Panel_UpdateCvars(centerprint); + HUD_Panel_UpdateCvars(); // this panel doesn't fade when showing the scoreboard if(autocvar__menu_alpha) @@ -4373,44 +4338,6 @@ void HUD_Reset (void) HUD_Mod_CTF_Reset(); } -#define HUD_DrawPanel(id)\ -switch (id) {\ - case (HUD_PANEL_RADAR):\ - HUD_Radar(); break;\ - case (HUD_PANEL_WEAPONS):\ - HUD_Weapons(); break;\ - case (HUD_PANEL_AMMO):\ - HUD_Ammo(); break;\ - case (HUD_PANEL_POWERUPS):\ - HUD_Powerups(); break;\ - case (HUD_PANEL_HEALTHARMOR):\ - HUD_HealthArmor(); break;\ - case (HUD_PANEL_NOTIFY):\ - HUD_Notify(); break;\ - case (HUD_PANEL_TIMER):\ - HUD_Timer(); break;\ - case (HUD_PANEL_SCORE):\ - HUD_Score(); break;\ - case (HUD_PANEL_RACETIMER):\ - HUD_RaceTimer(); break;\ - case (HUD_PANEL_VOTE):\ - HUD_VoteWindow(); break;\ - case (HUD_PANEL_MODICONS):\ - HUD_ModIcons(); break;\ - case (HUD_PANEL_PRESSEDKEYS):\ - HUD_DrawPressedKeys(); break;\ - case (HUD_PANEL_CHAT):\ - HUD_Chat(); break;\ - case (HUD_PANEL_ENGINEINFO):\ - HUD_EngineInfo(); break;\ - case (HUD_PANEL_INFOMESSAGES):\ - HUD_InfoMessages(); break;\ - case (HUD_PANEL_PHYSICS):\ - HUD_Physics(); break;\ - case (HUD_PANEL_CENTERPRINT):\ - HUD_CenterPrint(); break;\ -} ENDS_WITH_CURLY_BRACE - void HUD_Main (void) { float i; @@ -4440,7 +4367,7 @@ void HUD_Main (void) // they must call HUD_Panel_ApplyFadeAlpha(); only when showing the menu if(scoreboard_fade_alpha == 1) { - HUD_CenterPrint(); + (panel = HUD_PANEL(CENTERPRINT)).panel_draw(); return; } @@ -4565,31 +4492,35 @@ void HUD_Main (void) hud_draw_maximized = 0; // draw panels in order specified by panel_order array for(i = HUD_PANEL_NUM - 1; i >= 0; --i) - HUD_DrawPanel(panel_order[i]); + (panel = hud_panel[panel_order[i]]).panel_draw(); hud_draw_maximized = 1; // panels that may be maximized must check this var // draw maximized panels on top if(hud_panel_radar_maximized) - HUD_Radar(); + (panel = HUD_PANEL(RADAR)).panel_draw(); if(autocvar__con_chat_maximized) - HUD_Chat(); + (panel = HUD_PANEL(CHAT)).panel_draw(); if(autocvar__hud_configure) { if(tab_panel != -1) { - HUD_Panel_UpdatePosSizeForId(tab_panel) + panel = hud_panel[tab_panel]; + HUD_Panel_UpdatePosSize() drawfill(panel_pos - '1 1 0' * panel_bg_border, panel_size + '2 2 0' * panel_bg_border, '1 1 1', .2, DRAWFLAG_NORMAL); } if(highlightedPanel != -1) { - HUD_Panel_UpdatePosSizeForId(highlightedPanel); + panel = hud_panel[highlightedPanel]; + HUD_Panel_UpdatePosSize() HUD_Panel_HlBorder(panel_bg_border + 1.5 * hlBorderSize, '0 0.5 1', 0.25 * (1 - autocvar__menu_alpha)); } if(!hud_configure_prev || hud_configure_prev == -1) { if(autocvar_hud_cursormode) { setcursormode(1); } hudShiftState = 0; + for(i = HUD_PANEL_NUM - 1; i >= 0; --i) + hud_panel[panel_order[i]].update_time = time; } } else if (hud_configure_prev && autocvar_hud_cursormode) diff --git a/qcsrc/client/hud.qh b/qcsrc/client/hud.qh index 90ece36ac..9c8a9128c 100644 --- a/qcsrc/client/hud.qh +++ b/qcsrc/client/hud.qh @@ -1,4 +1,10 @@ -float panel_order[HUD_PANEL_NUM]; +#define HUD_PANEL_MAX 24 +entity hud_panel[HUD_PANEL_MAX]; +#define HUD_PANEL_FIRST 0 +float HUD_PANEL_NUM; +float HUD_PANEL_LAST; + +float panel_order[HUD_PANEL_MAX]; string hud_panelorder_prev; float hud_draw_maximized; @@ -57,8 +63,19 @@ var vector panel_size_backup; var float highlightedPanel_copied = -1; //this is good only to know if there is something copied var vector panel_size_copied; -var float hud_configure_active_panel; // this panel has recently referred the UpdateCvars macro -var string panel_name; +entity panel; +.string panel_name; +.float panel_id; +.vector current_panel_pos; +.vector current_panel_size; +.string current_panel_bg; +.float current_panel_bg_alpha; +.float current_panel_bg_border; +.vector current_panel_bg_color; +.float current_panel_bg_color_team; +.float current_panel_bg_padding; +.float current_panel_fg_alpha; +.float update_time; var float panel_enabled; var vector panel_pos; var vector panel_size; @@ -76,8 +93,52 @@ var string panel_bg_border_str; var float panel_bg_padding; var string panel_bg_padding_str; +.string panel_cvar; +.void() panel_draw; + float current_player; + +#define HUD_PANELS \ + HUD_PANEL(WEAPONS , HUD_Weapons , weapons) \ + HUD_PANEL(AMMO , HUD_Ammo , ammo) \ + HUD_PANEL(POWERUPS , HUD_Powerups , powerups) \ + HUD_PANEL(HEALTHARMOR , HUD_HealthArmor , healtharmor) \ + HUD_PANEL(NOTIFY , HUD_Notify , notify) \ + HUD_PANEL(TIMER , HUD_Timer , timer) \ + HUD_PANEL(RADAR , HUD_Radar , radar) \ + HUD_PANEL(SCORE , HUD_Score , score) \ + HUD_PANEL(RACETIMER , HUD_RaceTimer , racetimer) \ + HUD_PANEL(VOTE , HUD_Vote , vote) \ + HUD_PANEL(MODICONS , HUD_ModIcons , modicons) \ + HUD_PANEL(PRESSEDKEYS , HUD_PressedKeys , pressedkeys) \ + HUD_PANEL(CHAT , HUD_Chat , chat) \ + HUD_PANEL(ENGINEINFO , HUD_EngineInfo , engineinfo) \ + HUD_PANEL(INFOMESSAGES , HUD_InfoMessages , infomessages) \ + HUD_PANEL(PHYSICS , HUD_Physics , physics) \ + HUD_PANEL(CENTERPRINT , HUD_CenterPrint , centerprint) + +#define HUD_PANEL(NAME,draw_func,name) \ + float HUD_PANEL_##NAME; \ + void ##draw_func(void); \ + void RegisterHUD_Panel_##NAME() \ + { \ + HUD_PANEL_LAST = HUD_PANEL_##NAME = HUD_PANEL_NUM; \ + entity hud_panelent = spawn(); \ + hud_panel[HUD_PANEL_##NAME] = hud_panelent; \ + hud_panelent.panel_name = #name; \ + hud_panelent.panel_id = HUD_PANEL_##NAME; \ + hud_panelent.panel_draw = ##draw_func; \ + ++HUD_PANEL_NUM; \ + } \ + ACCUMULATE_FUNCTION(RegisterHUD_Panels, RegisterHUD_Panel_##NAME) + +HUD_PANELS +#undef HUD_PANEL + +#define HUD_PANEL(NAME) hud_panel[HUD_PANEL_##NAME] + + // Because calling lots of functions in QC apparently cuts fps in half on many machines: // ---------------------- // MACRO HELL STARTS HERE @@ -153,7 +214,7 @@ if(panel_bg_color_team_str == "") {\ // the check doesn't allow to fade this panel when showing the panel-specific menu dialog #define HUD_Panel_ApplyFadeAlpha()\ -if(!(menu_enabled == 2 && highlightedPanel == hud_configure_active_panel))\ +if(!(menu_enabled == 2 && panel.panel_id == highlightedPanel))\ {\ panel_bg_alpha *= hud_fade_alpha;\ panel_fg_alpha *= hud_fade_alpha;\ @@ -169,7 +230,7 @@ panel_bg_alpha = stof(panel_bg_alpha_str);\ if(autocvar__hud_configure) {\ if(!panel_enabled)\ panel_bg_alpha = 0.25;\ - else if(menu_enabled == 2 && highlightedPanel == hud_configure_active_panel)\ + else if(menu_enabled == 2 && panel.panel_id == highlightedPanel)\ panel_bg_alpha = (1 - autocvar__menu_alpha) * max(cvar("hud_configure_bg_minalpha"), panel_bg_alpha) + autocvar__menu_alpha * panel_bg_alpha;\ else\ panel_bg_alpha = max(cvar("hud_configure_bg_minalpha"), panel_bg_alpha);\ @@ -256,90 +317,58 @@ else\ }\ } -// Update all common cvars of given panel name -#define HUD_Panel_UpdateCvars(name) \ -panel_enabled = autocvar_hud_panel_##name; \ -panel_pos = stov(cvar_string("hud_panel_" #name "_pos")); \ -panel_size = stov(cvar_string("hud_panel_" #name "_size")); \ -panel_bg_str = cvar_string("hud_panel_" #name "_bg"); \ -panel_bg_color_str = cvar_string("hud_panel_" #name "_bg_color"); \ -panel_bg_color_team_str = cvar_string("hud_panel_" #name "_bg_color_team"); \ -panel_bg_alpha_str = cvar_string("hud_panel_" #name "_bg_alpha"); \ -panel_bg_border_str = cvar_string("hud_panel_" #name "_bg_border"); \ -panel_bg_padding_str = cvar_string("hud_panel_" #name "_bg_padding"); \ -HUD_Panel_GetStringVars()\ -if(menu_enabled == 2 && hud_configure_active_panel == highlightedPanel) {\ - HUD_Panel_GetMenuSize()\ - HUD_Panel_GetMenuPos()\ +#define HUD_Panel_UpdateCvars() \ +panel_enabled = cvar(strcat("hud_panel_", panel.panel_name)); \ +if(panel.update_time < time) { \ + panel_pos = stov(cvar_string(strcat("hud_panel_", panel.panel_name, "_pos"))); \ + panel_size = stov(cvar_string(strcat("hud_panel_", panel.panel_name, "_size"))); \ + panel_bg_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg")); \ + panel_bg_color_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_color")); \ + panel_bg_color_team_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_color_team")); \ + panel_bg_alpha_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_alpha")); \ + panel_bg_border_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_border")); \ + panel_bg_padding_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_padding")); \ + HUD_Panel_GetStringVars()\ + if(menu_enabled == 2 && panel.panel_id == highlightedPanel) {\ + HUD_Panel_GetMenuSize()\ + HUD_Panel_GetMenuPos()\ + } \ + panel.current_panel_pos = panel_pos; \ + panel.current_panel_size = panel_size; \ + if(panel.current_panel_bg != "") \ + strunzone(panel.current_panel_bg); \ + panel.current_panel_bg = strzone(panel_bg); \ + panel.current_panel_bg_alpha = panel_bg_alpha; \ + panel.current_panel_bg_border = panel_bg_border; \ + panel.current_panel_bg_color = panel_bg_color; \ + panel.current_panel_bg_color_team = panel_bg_color_team; \ + panel.current_panel_bg_padding = panel_bg_padding; \ + panel.current_panel_fg_alpha = panel_fg_alpha; \ + panel.update_time = (autocvar__hud_configure) ? time : time + 2; \ +} else { \ + panel_pos = panel.current_panel_pos; \ + panel_size = panel.current_panel_size; \ + panel_bg = panel.current_panel_bg; \ + panel_bg_alpha = panel.current_panel_bg_alpha; \ + panel_bg_border = panel.current_panel_bg_border; \ + panel_bg_color = panel.current_panel_bg_color; \ + panel_bg_color_team = panel.current_panel_bg_color_team; \ + panel_bg_padding = panel.current_panel_bg_padding; \ + panel_fg_alpha = panel.current_panel_fg_alpha; \ } ENDS_WITH_CURLY_BRACE -// FTEQCC I HATE YOU WHY DO YOU MAKE ME DO THIS??? :( -// max macro length is 1024 characters, I must split it up :( - -// Update all common cvars of given panel id -#define HUD_Panel_UpdateCvarsForId_Part2(id) \ -switch(id) { \ - case HUD_PANEL_INFOMESSAGES: HUD_Panel_UpdateCvars(infomessages) break; \ - case HUD_PANEL_PHYSICS: HUD_Panel_UpdateCvars(physics); break;\ - case HUD_PANEL_CENTERPRINT: HUD_Panel_UpdateCvars(centerprint); break;\ -} - -#define HUD_Panel_UpdateCvarsForId(id) \ -switch(id) { \ - case HUD_PANEL_WEAPONS: HUD_Panel_UpdateCvars(weapons) break; \ - case HUD_PANEL_AMMO: HUD_Panel_UpdateCvars(ammo) break; \ - case HUD_PANEL_POWERUPS: HUD_Panel_UpdateCvars(powerups) break; \ - case HUD_PANEL_HEALTHARMOR: HUD_Panel_UpdateCvars(healtharmor) break; \ - case HUD_PANEL_NOTIFY: HUD_Panel_UpdateCvars(notify) break; \ - case HUD_PANEL_TIMER: HUD_Panel_UpdateCvars(timer) break; \ - case HUD_PANEL_RADAR: HUD_Panel_UpdateCvars(radar) break; \ - case HUD_PANEL_SCORE: HUD_Panel_UpdateCvars(score) break; \ - case HUD_PANEL_RACETIMER: HUD_Panel_UpdateCvars(racetimer) break; \ - case HUD_PANEL_VOTE: HUD_Panel_UpdateCvars(vote) break; \ - case HUD_PANEL_MODICONS: HUD_Panel_UpdateCvars(modicons) break; \ - case HUD_PANEL_PRESSEDKEYS: HUD_Panel_UpdateCvars(pressedkeys) break; \ - case HUD_PANEL_CHAT: HUD_Panel_UpdateCvars(chat) break; \ - case HUD_PANEL_ENGINEINFO: HUD_Panel_UpdateCvars(engineinfo) break; \ - default: HUD_Panel_UpdateCvarsForId_Part2(id)\ -} - -#define HUD_Panel_UpdatePosSize(name) \ -panel_pos = stov(cvar_string("hud_panel_" #name "_pos")); \ -panel_size = stov(cvar_string("hud_panel_" #name "_size")); \ +#define HUD_Panel_UpdatePosSize() {\ +panel_pos = stov(cvar_string(strcat("hud_panel_", panel.panel_name, "_pos"))); \ +panel_size = stov(cvar_string(strcat("hud_panel_", panel.panel_name, "_size"))); \ HUD_Panel_GetScaledVectors()\ -if(menu_enabled == 2 && hud_configure_active_panel == highlightedPanel) {\ +if(menu_enabled == 2 && panel.panel_id == highlightedPanel) {\ HUD_Panel_GetMenuSize()\ HUD_Panel_GetMenuPos()\ }\ -panel_bg_border_str = cvar_string("hud_panel_" #name "_bg_border"); \ -HUD_Panel_GetBorder() - -// Update pos and size of given panel id -#define HUD_Panel_UpdatePosSizeForId_Part2(id) \ -switch(id) { \ - case HUD_PANEL_INFOMESSAGES: HUD_Panel_UpdatePosSize(infomessages) break;\ - case HUD_PANEL_PHYSICS: HUD_Panel_UpdatePosSize(physics); break;\ - case HUD_PANEL_CENTERPRINT: HUD_Panel_UpdatePosSize(centerprint); break;\ -} +panel_bg_border_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_border")); \ +HUD_Panel_GetBorder() \ +} ENDS_WITH_CURLY_BRACE -#define HUD_Panel_UpdatePosSizeForId(id) \ -switch(id) { \ - case HUD_PANEL_WEAPONS: HUD_Panel_UpdatePosSize(weapons) break;\ - case HUD_PANEL_AMMO: HUD_Panel_UpdatePosSize(ammo) break;\ - case HUD_PANEL_POWERUPS: HUD_Panel_UpdatePosSize(powerups) break;\ - case HUD_PANEL_HEALTHARMOR: HUD_Panel_UpdatePosSize(healtharmor) break;\ - case HUD_PANEL_NOTIFY: HUD_Panel_UpdatePosSize(notify) break;\ - case HUD_PANEL_TIMER: HUD_Panel_UpdatePosSize(timer) break;\ - case HUD_PANEL_RADAR: HUD_Panel_UpdatePosSize(radar) break;\ - case HUD_PANEL_SCORE: HUD_Panel_UpdatePosSize(score) break;\ - case HUD_PANEL_RACETIMER: HUD_Panel_UpdatePosSize(racetimer) break;\ - case HUD_PANEL_VOTE: HUD_Panel_UpdatePosSize(vote) break;\ - case HUD_PANEL_MODICONS: HUD_Panel_UpdatePosSize(modicons) break;\ - case HUD_PANEL_PRESSEDKEYS: HUD_Panel_UpdatePosSize(pressedkeys) break;\ - case HUD_PANEL_CHAT: HUD_Panel_UpdatePosSize(chat) break;\ - case HUD_PANEL_ENGINEINFO: HUD_Panel_UpdatePosSize(engineinfo) break;\ - default: HUD_Panel_UpdatePosSizeForId_Part2(id)\ -} #define KN_MAX_ENTRIES 10 diff --git a/qcsrc/client/hud_config.qc b/qcsrc/client/hud_config.qc index 21ab08fa7..0cba08567 100644 --- a/qcsrc/client/hud_config.qc +++ b/qcsrc/client/hud_config.qc @@ -2,8 +2,8 @@ // q: quoted, n: not quoted #define HUD_Write_Cvar_n(cvar) HUD_Write(strcat("seta ", cvar, " ", cvar_string(cvar), "\n")) #define HUD_Write_Cvar_q(cvar) HUD_Write(strcat("seta ", cvar, " \"", cvar_string(cvar), "\"\n")) -#define HUD_Write_PanelCvar_n(cvar_suf) HUD_Write_Cvar_n(strcat("hud_panel_", panel_name, cvar_suf)) -#define HUD_Write_PanelCvar_q(cvar_suf) HUD_Write_Cvar_q(strcat("hud_panel_", panel_name, cvar_suf)) +#define HUD_Write_PanelCvar_n(cvar_suf) HUD_Write_Cvar_n(strcat("hud_panel_", panel.panel_name, cvar_suf)) +#define HUD_Write_PanelCvar_q(cvar_suf) HUD_Write_Cvar_q(strcat("hud_panel_", panel.panel_name, cvar_suf)) // Save the config void HUD_Panel_ExportCfg(string cfgname) { @@ -52,7 +52,7 @@ void HUD_Panel_ExportCfg(string cfgname) float i; for (i = 0; i < HUD_PANEL_NUM; ++i) { - HUD_Panel_GetName(i); + panel = hud_panel[i]; HUD_Write_PanelCvar_n(""); HUD_Write_PanelCvar_q("_pos"); @@ -220,7 +220,8 @@ vector HUD_Panel_CheckMove(vector myPos, vector mySize) if(i == highlightedPanel || !panel_enabled) continue; - HUD_Panel_UpdatePosSizeForId(i); + panel = hud_panel[i]; + HUD_Panel_UpdatePosSize() panel_pos -= '1 1 0' * panel_bg_border; panel_size += '2 2 0' * panel_bg_border; @@ -280,7 +281,8 @@ vector HUD_Panel_CheckMove(vector myPos, vector mySize) void HUD_Panel_SetPos(vector pos) { - HUD_Panel_UpdatePosSizeForId(highlightedPanel); + panel = hud_panel[highlightedPanel]; + HUD_Panel_UpdatePosSize() vector mySize; mySize = panel_size; @@ -302,8 +304,7 @@ void HUD_Panel_SetPos(vector pos) string s; s = strcat(ftos(pos_x/vid_conwidth), " ", ftos(pos_y/vid_conheight)); - HUD_Panel_GetName(highlightedPanel); - cvar_set(strcat("hud_panel_", panel_name, "_pos"), s); + cvar_set(strcat("hud_panel_", hud_panel[highlightedPanel].panel_name, "_pos"), s); } // check if resize will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector @@ -320,7 +321,8 @@ vector HUD_Panel_CheckResize(vector mySize, vector resizeorigin) { if(i == highlightedPanel || !panel_enabled) continue; - HUD_Panel_UpdatePosSizeForId(i); + panel = hud_panel[i]; + HUD_Panel_UpdatePosSize() panel_pos -= '1 1 0' * panel_bg_border; panel_size += '2 2 0' * panel_bg_border; @@ -419,7 +421,8 @@ vector HUD_Panel_CheckResize(vector mySize, vector resizeorigin) { void HUD_Panel_SetPosSize(vector mySize) { - HUD_Panel_UpdatePosSizeForId(highlightedPanel); + panel = hud_panel[highlightedPanel]; + HUD_Panel_UpdatePosSize() vector resizeorigin; resizeorigin = panel_click_resizeorigin; local noref vector myPos; // fteqcc sucks @@ -499,13 +502,13 @@ void HUD_Panel_SetPosSize(vector mySize) //if(cvar("hud_configure_checkcollisions_debug")) //drawfill(myPos, mySize, '0 1 0', .3, DRAWFLAG_NORMAL); - HUD_Panel_GetName(highlightedPanel); + entity e = hud_panel[highlightedPanel]; string s; s = strcat(ftos(mySize_x/vid_conwidth), " ", ftos(mySize_y/vid_conheight)); - cvar_set(strcat("hud_panel_", panel_name, "_size"), s); + cvar_set(strcat("hud_panel_", e.panel_name, "_size"), s); s = strcat(ftos(myPos_x/vid_conwidth), " ", ftos(myPos_y/vid_conheight)); - cvar_set(strcat("hud_panel_", panel_name, "_pos"), s); + cvar_set(strcat("hud_panel_", e.panel_name, "_pos"), s); } float pressed_key_time; @@ -547,7 +550,8 @@ void HUD_Panel_Arrow_Action(float nPrimary) step = (step / 64) * (1 + 2 * (time - pressed_key_time)); } - HUD_Panel_UpdatePosSizeForId(highlightedPanel); + panel = hud_panel[highlightedPanel]; + HUD_Panel_UpdatePosSize() highlightedPanel_initial_pos = panel_pos; highlightedPanel_initial_size = panel_size; @@ -606,7 +610,8 @@ void HUD_Panel_Arrow_Action(float nPrimary) HUD_Panel_SetPos(pos); } - HUD_Panel_UpdatePosSizeForId(highlightedPanel); + panel = hud_panel[highlightedPanel]; + HUD_Panel_UpdatePosSize() if (highlightedPanel_initial_pos != panel_pos || highlightedPanel_initial_size != panel_size) { @@ -626,7 +631,7 @@ float prevMouseClickedTime; // time during previous left mouse click, to check f vector prevMouseClickedPos; // pos during previous left mouse click, to check for doubleclicks void HUD_Panel_EnableMenu(); -float tab_panels[HUD_PANEL_NUM]; +float tab_panels[HUD_PANEL_MAX]; float tab_panel, tab_backward; vector tab_panel_pos; void HUD_Panel_FirstInDrawQ(float id); @@ -741,7 +746,11 @@ float HUD_Panel_InputEvent(float bInputType, float nPrimary, float nSecondary) if (tab_panel == -1) //first press of TAB { if (highlightedPanel != -1) - HUD_Panel_UpdatePosSizeForId(highlightedPanel) + if (highlightedPanel) + { + panel = hud_panel[highlightedPanel]; + HUD_Panel_UpdatePosSize() + } else panel_pos = '0 0 0'; starting_panel = highlightedPanel; //can be -1, it means no starting panel @@ -771,7 +780,8 @@ float HUD_Panel_InputEvent(float bInputType, float nPrimary, float nSecondary) { if (i == tab_panels[i] || i == starting_panel) continue; - HUD_Panel_UpdatePosSizeForId(i) + panel = hud_panel[i]; + HUD_Panel_UpdatePosSize() if (panel_pos_y >= level && (panel_pos_y - level) < level_height) if ( ( !tab_backward && panel_pos_x >= start_pos_x && (panel_pos_x < candidate_pos_x || (panel_pos_x == candidate_pos_x && panel_pos_y <= candidate_pos_y)) ) || ( tab_backward && panel_pos_x <= start_pos_x && (panel_pos_x > candidate_pos_x || (panel_pos_x == candidate_pos_x && panel_pos_y >= candidate_pos_y)) ) ) @@ -817,8 +827,8 @@ float HUD_Panel_InputEvent(float bInputType, float nPrimary, float nSecondary) if (highlightedPanel != -1) { - HUD_Panel_GetName(highlightedPanel); - cvar_set(strcat("hud_panel_", panel_name), ftos(!(panel_enabled))); + entity e = hud_panel[highlightedPanel]; + cvar_set(strcat("hud_panel_", e.panel_name), ftos(!(panel_enabled))); } else cvar_set(strcat("hud_dock"), (autocvar_hud_dock == "") ? "dock" : ""); @@ -830,7 +840,8 @@ float HUD_Panel_InputEvent(float bInputType, float nPrimary, float nSecondary) if (highlightedPanel != -1) { - HUD_Panel_UpdatePosSizeForId(highlightedPanel); + panel = hud_panel[highlightedPanel]; + HUD_Panel_UpdatePosSize() panel_size_copied = panel_size; highlightedPanel_copied = highlightedPanel; } @@ -843,7 +854,8 @@ float HUD_Panel_InputEvent(float bInputType, float nPrimary, float nSecondary) if (highlightedPanel_copied == -1 || highlightedPanel == -1) return true; - HUD_Panel_UpdatePosSizeForId(highlightedPanel); + panel = hud_panel[highlightedPanel]; + HUD_Panel_UpdatePosSize() // reduce size if it'd go beyond screen boundaries vector tmp_size = panel_size_copied; @@ -861,8 +873,8 @@ float HUD_Panel_InputEvent(float bInputType, float nPrimary, float nSecondary) highlightedPanel_backup = highlightedPanel; s = strcat(ftos(tmp_size_x/vid_conwidth), " ", ftos(tmp_size_y/vid_conheight)); - HUD_Panel_GetName(highlightedPanel); - cvar_set(strcat("hud_panel_", panel_name, "_size"), s); + entity e = hud_panel[highlightedPanel]; + cvar_set(strcat("hud_panel_", e.panel_name, "_size"), s); } else if(nPrimary == 'z' && hudShiftState & S_CTRL) // undo last action { @@ -871,11 +883,11 @@ float HUD_Panel_InputEvent(float bInputType, float nPrimary, float nSecondary) //restore previous values if (highlightedPanel_backup != -1) { - HUD_Panel_GetName(highlightedPanel_backup); + entity e = hud_panel[highlightedPanel_backup]; s = strcat(ftos(panel_pos_backup_x/vid_conwidth), " ", ftos(panel_pos_backup_y/vid_conheight)); - cvar_set(strcat("hud_panel_", panel_name, "_pos"), s); + cvar_set(strcat("hud_panel_", e.panel_name, "_pos"), s); s = strcat(ftos(panel_size_backup_x/vid_conwidth), " ", ftos(panel_size_backup_y/vid_conheight)); - cvar_set(strcat("hud_panel_", panel_name, "_size"), s); + cvar_set(strcat("hud_panel_", e.panel_name, "_size"), s); highlightedPanel_backup = -1; } } @@ -914,7 +926,8 @@ float HUD_Panel_Check_Mouse_Pos(float allow_move) i = panel_order[j]; j += 1; - HUD_Panel_UpdatePosSizeForId(i); + panel = hud_panel[i]; + HUD_Panel_UpdatePosSize() border = max(8, panel_bg_border); // FORCED border so a small border size doesn't mean you can't resize @@ -994,7 +1007,8 @@ void HUD_Panel_Highlight(float allow_move) i = panel_order[j]; j += 1; - HUD_Panel_UpdatePosSizeForId(i); + panel = hud_panel[i]; + HUD_Panel_UpdatePosSize() border = max(8, panel_bg_border); // FORCED border so a small border size doesn't mean you can't resize @@ -1062,8 +1076,7 @@ void HUD_Panel_EnableMenu() { menu_enabled = 2; menu_enabled_time = time; - HUD_Panel_GetName(highlightedPanel); - localcmd("menu_showhudoptions ", panel_name, "\n"); + localcmd("menu_showhudoptions ", hud_panel[highlightedPanel].panel_name, "\n"); } float mouse_over_panel; void HUD_Panel_Mouse() @@ -1100,7 +1113,7 @@ void HUD_Panel_Mouse() reset_tab_panels(); } HUD_Panel_Highlight(mouseClicked & S_MOUSE1); // sets highlightedPanel, highlightedAction, panel_click_distance, panel_click_resizeorigin - // and calls HUD_Panel_UpdatePosSizeForId() for the highlighted panel + // and calls HUD_Panel_UpdatePosSize() for the highlighted panel if (highlightedPanel != -1) { highlightedPanel_initial_pos = panel_pos; @@ -1123,7 +1136,10 @@ void HUD_Panel_Mouse() } } else - HUD_Panel_UpdatePosSizeForId(highlightedPanel); + { + panel = hud_panel[highlightedPanel]; + HUD_Panel_UpdatePosSize() + } if (highlightedPanel != -1) { diff --git a/qcsrc/common/constants.qh b/qcsrc/common/constants.qh index c25fb059f..3ba59479d 100644 --- a/qcsrc/common/constants.qh +++ b/qcsrc/common/constants.qh @@ -392,6 +392,7 @@ float WR_SWITCHABLE = 12; // (CSQC) impact effect float WR_PLAYERDEATH = 13; // (SVQC) does not need to do anything float WR_GONETHINK = 14; // (SVQC) logic to run every frame, also if no longer having the weapon as long as the switch away has not been performed +#ifdef MENUQC float HUD_PANEL_WEAPONS = 0; float HUD_PANEL_AMMO = 1; float HUD_PANEL_POWERUPS = 2; @@ -410,24 +411,7 @@ float HUD_PANEL_INFOMESSAGES = 14; float HUD_PANEL_PHYSICS = 15; float HUD_PANEL_CENTERPRINT = 16; float HUD_PANEL_NUM = 17; // always last panel id + 1, please increment when adding a new panel - -string HUD_PANELNAME_WEAPONS = "weapons"; -string HUD_PANELNAME_AMMO = "ammo"; -string HUD_PANELNAME_POWERUPS = "powerups"; -string HUD_PANELNAME_HEALTHARMOR = "healtharmor"; -string HUD_PANELNAME_NOTIFY = "notify"; -string HUD_PANELNAME_TIMER = "timer"; -string HUD_PANELNAME_RADAR = "radar"; -string HUD_PANELNAME_SCORE = "score"; -string HUD_PANELNAME_RACETIMER = "racetimer"; -string HUD_PANELNAME_VOTE = "vote"; -string HUD_PANELNAME_MODICONS = "modicons"; -string HUD_PANELNAME_PRESSEDKEYS = "pressedkeys"; -string HUD_PANELNAME_CHAT = "chat"; -string HUD_PANELNAME_ENGINEINFO = "engineinfo"; -string HUD_PANELNAME_INFOMESSAGES = "infomessages"; -string HUD_PANELNAME_PHYSICS = "physics"; -string HUD_PANELNAME_CENTERPRINT = "centerprint"; +#endif #define SERVERFLAG_ALLOW_FULLBRIGHT 1 #define SERVERFLAG_TEAMPLAY 2 diff --git a/qcsrc/common/util.qh b/qcsrc/common/util.qh index bd603b74c..421f6126b 100644 --- a/qcsrc/common/util.qh +++ b/qcsrc/common/util.qh @@ -264,34 +264,6 @@ float get_model_parameters_fixbone; string get_model_parameters_desc; float get_model_parameters(string mod, float skn); // call with string_null to clear; skin -1 means mod is the filename of the txt file and is to be split -// stupid stupid stupid FTEQCC has a max limit on macro sizes, let's work around by splitting the macro into two macros! :( -#define HUD_Panel_GetName_Part2(id) \ -switch(id) {\ - case HUD_PANEL_ENGINEINFO: panel_name = HUD_PANELNAME_ENGINEINFO; break; \ - case HUD_PANEL_INFOMESSAGES: panel_name = HUD_PANELNAME_INFOMESSAGES; break; \ - case HUD_PANEL_PHYSICS: panel_name = HUD_PANELNAME_PHYSICS; break; \ - case HUD_PANEL_CENTERPRINT: panel_name = HUD_PANELNAME_CENTERPRINT; break; \ -} ENDS_WITH_CURLY_BRACE - -// Get name of specified panel id -#define HUD_Panel_GetName(id) \ -switch(id) { \ - case HUD_PANEL_WEAPONS: panel_name = HUD_PANELNAME_WEAPONS; break; \ - case HUD_PANEL_AMMO: panel_name = HUD_PANELNAME_AMMO; break; \ - case HUD_PANEL_POWERUPS: panel_name = HUD_PANELNAME_POWERUPS; break; \ - case HUD_PANEL_HEALTHARMOR: panel_name = HUD_PANELNAME_HEALTHARMOR; break; \ - case HUD_PANEL_NOTIFY: panel_name = HUD_PANELNAME_NOTIFY; break; \ - case HUD_PANEL_TIMER: panel_name = HUD_PANELNAME_TIMER; break; \ - case HUD_PANEL_RADAR: panel_name = HUD_PANELNAME_RADAR; break; \ - case HUD_PANEL_SCORE: panel_name = HUD_PANELNAME_SCORE; break; \ - case HUD_PANEL_RACETIMER: panel_name = HUD_PANELNAME_RACETIMER; break; \ - case HUD_PANEL_VOTE: panel_name = HUD_PANELNAME_VOTE; break; \ - case HUD_PANEL_MODICONS: panel_name = HUD_PANELNAME_MODICONS; break; \ - case HUD_PANEL_PRESSEDKEYS: panel_name = HUD_PANELNAME_PRESSEDKEYS; break; \ - case HUD_PANEL_CHAT: panel_name = HUD_PANELNAME_CHAT; break; \ - default: HUD_Panel_GetName_Part2(id)\ -} - vector vec2(vector v); #ifndef MENUQC