reset_centerprint_messages();
if (time > hud_configure_cp_generation_time)
{
- if(HUD_PANEL(CENTERPRINT) == highlightedPanel)
+ if(highlightedPanel == HUD_PANEL(CENTERPRINT))
{
float r;
r = random();
// cache the panel order into the panel_order array
if(autocvar__hud_panelorder != hud_panelorder_prev) {
- for(i = 0; i < HUD_PANEL_NUM; ++i)
+ for(i = 0; i < hud_panels_COUNT; ++i)
panel_order[i] = -1;
string s = "";
int p_num;
bool warning = false;
int argc = tokenize_console(autocvar__hud_panelorder);
- if (argc > HUD_PANEL_NUM)
+ if (argc > hud_panels_COUNT)
warning = true;
//first detect wrong/missing panel numbers
- for(i = 0; i < HUD_PANEL_NUM; ++i) {
+ for(i = 0; i < hud_panels_COUNT; ++i) {
p_num = stoi(argv(i));
- if (p_num >= 0 && p_num < HUD_PANEL_NUM) { //correct panel number?
+ if (p_num >= 0 && p_num < hud_panels_COUNT) { //correct panel number?
if (panel_order[p_num] == -1) //found for the first time?
s = strcat(s, ftos(p_num), " ");
panel_order[p_num] = 1; //mark as found
else
warning = true;
}
- for(i = 0; i < HUD_PANEL_NUM; ++i) {
+ for(i = 0; i < hud_panels_COUNT; ++i) {
if (panel_order[i] == -1) {
warning = true;
s = strcat(s, ftos(i), " "); //add missing panel number
//now properly set panel_order
tokenize_console(s);
- for(i = 0; i < HUD_PANEL_NUM; ++i) {
+ for(i = 0; i < hud_panels_COUNT; ++i) {
panel_order[i] = stof(argv(i));
}
}
hud_draw_maximized = 0;
// draw panels in the order specified by panel_order array
- for(i = HUD_PANEL_NUM - 1; i >= 0; --i)
- HUD_Panel_Draw(hud_panel[panel_order[i]]);
+ for(i = hud_panels_COUNT - 1; i >= 0; --i)
+ HUD_Panel_Draw(hud_panels[panel_order[i]]);
hud_draw_maximized = 1; // panels that may be maximized must check this var
// draw maximized panels on top
#include "../common/weapons/all.qh"
-const int HUD_PANEL_MAX = 24;
-entity hud_panel[HUD_PANEL_MAX];
-const int HUD_PANEL_FIRST = 0;
-int HUD_PANEL_NUM;
-int HUD_PANEL_LAST;
+REGISTRY(hud_panels, 24)
+REGISTER_REGISTRY(Registerhud_panels)
-int panel_order[HUD_PANEL_MAX];
+#define REGISTER_HUD_PANEL(id, draw_func, name, showflags) \
+ void draw_func(); \
+ REGISTER(Registerhud_panels, HUD_PANEL, hud_panels, id, m_id, new(hud_panel)) { \
+ this.panel_id = this.m_id; \
+ this.panel_draw = draw_func; \
+ this.panel_name = #name; \
+ this.panel_showflags = showflags; \
+ }
+
+#define HUD_PANEL(NAME) HUD_PANEL_##NAME
+
+int panel_order[hud_panels_MAX];
string hud_panelorder_prev;
bool hud_draw_maximized;
void HUD_ItemsTime();
-#define HUD_PANELS(HUD_PANEL) \
- HUD_PANEL(WEAPONS , HUD_Weapons , weapons, PANEL_SHOW_MAINGAME ) \
- HUD_PANEL(AMMO , HUD_Ammo , ammo, PANEL_SHOW_MAINGAME ) \
- HUD_PANEL(POWERUPS , HUD_Powerups , powerups, PANEL_SHOW_MAINGAME ) \
- HUD_PANEL(HEALTHARMOR , HUD_HealthArmor , healtharmor, PANEL_SHOW_MAINGAME ) \
- HUD_PANEL(NOTIFY , HUD_Notify , notify, PANEL_SHOW_ALWAYS ) \
- HUD_PANEL(TIMER , HUD_Timer , timer, PANEL_SHOW_ALWAYS ) \
- HUD_PANEL(RADAR , HUD_Radar , radar, PANEL_SHOW_MAINGAME ) \
- HUD_PANEL(SCORE , HUD_Score , score, PANEL_SHOW_ALWAYS ) \
- HUD_PANEL(RACETIMER , HUD_RaceTimer , racetimer, PANEL_SHOW_MAINGAME ) \
- HUD_PANEL(VOTE , HUD_Vote , vote, PANEL_SHOW_ALWAYS ) \
- HUD_PANEL(MODICONS , HUD_ModIcons , modicons, PANEL_SHOW_MAINGAME ) \
- HUD_PANEL(PRESSEDKEYS , HUD_PressedKeys , pressedkeys, PANEL_SHOW_MAINGAME ) \
- HUD_PANEL(CHAT , HUD_Chat , chat, PANEL_SHOW_ALWAYS ) \
- HUD_PANEL(ENGINEINFO , HUD_EngineInfo , engineinfo, PANEL_SHOW_ALWAYS ) \
- HUD_PANEL(INFOMESSAGES , HUD_InfoMessages , infomessages, PANEL_SHOW_MAINGAME ) \
- HUD_PANEL(PHYSICS , HUD_Physics , physics, PANEL_SHOW_MAINGAME ) \
- HUD_PANEL(CENTERPRINT , HUD_CenterPrint , centerprint, PANEL_SHOW_MAINGAME ) \
- HUD_PANEL(MINIGAME_BOARD, HUD_MinigameBoard ,minigameboard, PANEL_SHOW_MINIGAME ) \
- HUD_PANEL(MINIGAME_STATUS,HUD_MinigameStatus,minigamestatus,PANEL_SHOW_MINIGAME ) \
- HUD_PANEL(MINIGAME_HELP, HUD_MinigameHelp ,minigamehelp, PANEL_SHOW_MINIGAME ) \
- HUD_PANEL(MINIGAME_MENU, HUD_MinigameMenu ,minigamemenu, PANEL_SHOW_ALWAYS ) \
- HUD_PANEL(MAPVOTE , MapVote_Draw ,mapvote, PANEL_SHOW_ALWAYS ) \
- HUD_PANEL(ITEMSTIME , HUD_ItemsTime ,itemstime, PANEL_SHOW_MAINGAME ) \
- HUD_PANEL(QUICKMENU , HUD_QuickMenu , quickmenu, PANEL_SHOW_MAINGAME ) \
- // always add new panels to the end of list
-
-
-#define HUD_PANEL(NAME, draw_func, name, showflags) \
- int 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.classname = "hud_panel"; \
- hud_panelent.panel_name = #name; \
- hud_panelent.panel_id = HUD_PANEL_##NAME; \
- hud_panelent.panel_draw = draw_func; \
- hud_panelent.panel_showflags = showflags; \
- HUD_PANEL_NUM++; \
- } \
- ACCUMULATE_FUNCTION(RegisterHUD_Panels, RegisterHUD_Panel_##NAME)
-
-HUD_PANELS(HUD_PANEL)
-#undef HUD_PANEL
-
-#define HUD_PANEL(NAME) hud_panel[HUD_PANEL_##NAME]
-
+REGISTER_HUD_PANEL(WEAPONS, HUD_Weapons, weapons, PANEL_SHOW_MAINGAME)
+REGISTER_HUD_PANEL(AMMO, HUD_Ammo, ammo, PANEL_SHOW_MAINGAME)
+REGISTER_HUD_PANEL(POWERUPS, HUD_Powerups, powerups, PANEL_SHOW_MAINGAME)
+REGISTER_HUD_PANEL(HEALTHARMOR, HUD_HealthArmor, healtharmor, PANEL_SHOW_MAINGAME)
+REGISTER_HUD_PANEL(NOTIFY, HUD_Notify, notify, PANEL_SHOW_ALWAYS )
+REGISTER_HUD_PANEL(TIMER, HUD_Timer, timer, PANEL_SHOW_ALWAYS )
+REGISTER_HUD_PANEL(RADAR, HUD_Radar, radar, PANEL_SHOW_MAINGAME)
+REGISTER_HUD_PANEL(SCORE, HUD_Score, score, PANEL_SHOW_ALWAYS )
+REGISTER_HUD_PANEL(RACETIMER, HUD_RaceTimer, racetimer, PANEL_SHOW_MAINGAME)
+REGISTER_HUD_PANEL(VOTE, HUD_Vote, vote, PANEL_SHOW_ALWAYS )
+REGISTER_HUD_PANEL(MODICONS, HUD_ModIcons, modicons, PANEL_SHOW_MAINGAME)
+REGISTER_HUD_PANEL(PRESSEDKEYS, HUD_PressedKeys, pressedkeys, PANEL_SHOW_MAINGAME)
+REGISTER_HUD_PANEL(CHAT, HUD_Chat, chat, PANEL_SHOW_ALWAYS )
+REGISTER_HUD_PANEL(ENGINEINFO, HUD_EngineInfo, engineinfo, PANEL_SHOW_ALWAYS )
+REGISTER_HUD_PANEL(INFOMESSAGES, HUD_InfoMessages, infomessages, PANEL_SHOW_MAINGAME)
+REGISTER_HUD_PANEL(PHYSICS, HUD_Physics, physics, PANEL_SHOW_MAINGAME)
+REGISTER_HUD_PANEL(CENTERPRINT, HUD_CenterPrint, centerprint, PANEL_SHOW_MAINGAME)
+REGISTER_HUD_PANEL(MINIGAME_BOARD, HUD_MinigameBoard, minigameboard, PANEL_SHOW_MINIGAME)
+REGISTER_HUD_PANEL(MINIGAME_STATUS, HUD_MinigameStatus, minigamestatus, PANEL_SHOW_MINIGAME)
+REGISTER_HUD_PANEL(MINIGAME_HELP, HUD_MinigameHelp, minigamehelp, PANEL_SHOW_MINIGAME)
+REGISTER_HUD_PANEL(MINIGAME_MENU, HUD_MinigameMenu, minigamemenu, PANEL_SHOW_ALWAYS )
+REGISTER_HUD_PANEL(MAPVOTE, MapVote_Draw, mapvote, PANEL_SHOW_ALWAYS )
+REGISTER_HUD_PANEL(ITEMSTIME, HUD_ItemsTime, itemstime, PANEL_SHOW_MAINGAME)
+REGISTER_HUD_PANEL(QUICKMENU, HUD_QuickMenu, quickmenu, PANEL_SHOW_MAINGAME)
+// always add new panels to the end of list
// Because calling lots of functions in QC apparently cuts fps in half on many machines:
// ----------------------
HUD_Write("\n");
// common cvars for all panels
- int i;
- for (i = 0; i < HUD_PANEL_NUM; ++i)
+ for (int i = 0; i < hud_panels_COUNT; ++i)
{
- panel = hud_panel[i];
+ panel = hud_panels[i];
HUD_Write_PanelCvar_n("");
HUD_Write_PanelCvar_q("_pos");
HUD_Write_PanelCvar_q("_bg_alpha");
HUD_Write_PanelCvar_q("_bg_border");
HUD_Write_PanelCvar_q("_bg_padding");
- switch(i) {
+ switch(panel) {
case HUD_PANEL_WEAPONS:
HUD_Write_PanelCvar_q("_accuracy");
HUD_Write_PanelCvar_q("_label");
vector myCenter, targCenter;
vector myTarget = myPos;
int i;
- for (i = 0; i < HUD_PANEL_NUM; ++i) {
- panel = hud_panel[i];
+ for (i = 0; i < hud_panels_COUNT; ++i) {
+ panel = hud_panels[i];
if(panel == HUD_PANEL(MAPVOTE)) continue;
if(panel == highlightedPanel) continue;
HUD_Panel_UpdatePosSize();
vector dist;
float ratio = mySize.x/mySize.y;
int i;
- for (i = 0; i < HUD_PANEL_NUM; ++i) {
- panel = hud_panel[i];
+ for (i = 0; i < hud_panels_COUNT; ++i) {
+ panel = hud_panels[i];
if(panel == HUD_PANEL(MAPVOTE)) continue;
if(panel == highlightedPanel) continue;
HUD_Panel_UpdatePosSize();
}
void HUD_Panel_EnableMenu();
-entity tab_panels[HUD_PANEL_MAX];
+entity tab_panels[hud_panels_MAX];
entity tab_panel;
vector tab_panel_pos;
float tab_backward;
void reset_tab_panels()
{
int i;
- for(i = 0; i < HUD_PANEL_NUM; ++i)
+ for(i = 0; i < hud_panels_COUNT; ++i)
tab_panels[i] = world;
}
float HUD_Panel_InputEvent(float bInputType, float nPrimary, float nSecondary)
k=0;
while(++k)
{
- for(i = 0; i < HUD_PANEL_NUM; ++i)
+ for(i = 0; i < hud_panels_COUNT; ++i)
{
- panel = hud_panel[i];
+ panel = hud_panels[i];
if(panel == HUD_PANEL(MAPVOTE))
continue;
if (panel == tab_panels[i] || panel == starting_panel)
float HUD_Panel_Check_Mouse_Pos(float allow_move)
{
int i, j = 0;
- while(j < HUD_PANEL_NUM)
+ while(j < hud_panels_COUNT)
{
i = panel_order[j];
j += 1;
- panel = hud_panel[i];
+ panel = hud_panels[i];
if(panel == HUD_PANEL(MAPVOTE)) continue;
HUD_Panel_UpdatePosSize();
int i;
int place = -1;
// find out where in the array our current id is, save into place
- for(i = 0; i < HUD_PANEL_NUM; ++i)
+ for(i = 0; i < hud_panels_COUNT; ++i)
{
if(panel_order[i] == id)
{
}
// place last if we didn't find a place for it yet (probably new panel, or screwed up cvar)
if(place == -1)
- place = HUD_PANEL_NUM - 1;
+ place = hud_panels_COUNT - 1;
// move all ids up by one step in the array until "place"
for(i = place; i > 0; --i)
// let's save them into the cvar by some strcat trickery
string s = "";
- for(i = 0; i < HUD_PANEL_NUM; ++i)
+ for(i = 0; i < hud_panels_COUNT; ++i)
{
s = strcat(s, ftos(panel_order[i]), " ");
}
{
int i, j = 0;
- while(j < HUD_PANEL_NUM)
+ while(j < hud_panels_COUNT)
{
i = panel_order[j];
j += 1;
- panel = hud_panel[i];
+ panel = hud_panels[i];
if(panel == HUD_PANEL(MAPVOTE))
continue;
HUD_Panel_UpdatePosSize();
// move
if(allow_move && mousepos.x > panel_pos.x && mousepos.y > panel_pos.y && mousepos.x < panel_pos.x + panel_size.x && mousepos.y < panel_pos.y + panel_size.y)
{
- highlightedPanel = hud_panel[i];
+ highlightedPanel = hud_panels[i];
HUD_Panel_FirstInDrawQ(i);
highlightedAction = 1;
panel_click_distance = mousepos - panel_pos;
// resize from topleft border
else if(mousepos.x >= panel_pos.x - border && mousepos.y >= panel_pos.y - border && mousepos.x <= panel_pos.x + 0.5 * panel_size.x && mousepos.y <= panel_pos.y + 0.5 * panel_size.y)
{
- highlightedPanel = hud_panel[i];
+ highlightedPanel = hud_panels[i];
HUD_Panel_FirstInDrawQ(i);
highlightedAction = 2;
resizeCorner = 1;
// resize from topright border
else if(mousepos.x >= panel_pos.x + 0.5 * panel_size.x && mousepos.y >= panel_pos.y - border && mousepos.x <= panel_pos.x + panel_size.x + border && mousepos.y <= panel_pos.y + 0.5 * panel_size.y)
{
- highlightedPanel = hud_panel[i];
+ highlightedPanel = hud_panels[i];
HUD_Panel_FirstInDrawQ(i);
highlightedAction = 2;
resizeCorner = 2;
// resize from bottomleft border
else if(mousepos.x >= panel_pos.x - border && mousepos.y >= panel_pos.y + 0.5 * panel_size.y && mousepos.x <= panel_pos.x + 0.5 * panel_size.x && mousepos.y <= panel_pos.y + panel_size.y + border)
{
- highlightedPanel = hud_panel[i];
+ highlightedPanel = hud_panels[i];
HUD_Panel_FirstInDrawQ(i);
highlightedAction = 2;
resizeCorner = 3;
// resize from bottomright border
else if(mousepos.x >= panel_pos.x + 0.5 * panel_size.x && mousepos.y >= panel_pos.y + 0.5 * panel_size.y && mousepos.x <= panel_pos.x + panel_size.x + border && mousepos.y <= panel_pos.y + panel_size.y + border)
{
- highlightedPanel = hud_panel[i];
+ highlightedPanel = hud_panels[i];
HUD_Panel_FirstInDrawQ(i);
highlightedAction = 2;
resizeCorner = 4;
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;
+ for(i = hud_panels_COUNT - 1; i >= 0; --i)
+ hud_panels[panel_order[i]].update_time = time;
}
// NOTE this check is necessary because _menu_alpha isn't updated the frame the menu gets enabled