From: FruitieX Date: Thu, 1 Jul 2010 13:13:42 +0000 (+0300) Subject: fix most of moving/resizing X-Git-Tag: xonotic-v0.1.0preview~457^2~41 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=a6b0996560275c0cd5cfe8a0314c97ff0346df75;p=xonotic%2Fxonotic-data.pk3dir.git fix most of moving/resizing --- diff --git a/qcsrc/client/autocvars.qh b/qcsrc/client/autocvars.qh index d7d0e9145..2f4408eda 100644 --- a/qcsrc/client/autocvars.qh +++ b/qcsrc/client/autocvars.qh @@ -21,7 +21,7 @@ var string autocvar_hud_dock; var float autocvar_hud_dock_alpha; var string autocvar_hud_bg; -var string autocvar_hud_bg_color; +var vector autocvar_hud_bg_color; var float autocvar_hud_bg_color_team; var float autocvar_hud_bg_alpha; var float autocvar_hud_bg_border; diff --git a/qcsrc/client/hud.qc b/qcsrc/client/hud.qc index a7f6ad29d..f39fb4bf2 100644 --- a/qcsrc/client/hud.qc +++ b/qcsrc/client/hud.qc @@ -544,8 +544,8 @@ void HUD_Panel_ExportCfg(string cfgname) float i; for (i = 0; i < HUD_PANEL_NUM; ++i) { -// HUD_Panel_GetName(i) -// HUD_Panel_UpdateCvarsForId(i) + HUD_Panel_GetName(i) + HUD_Panel_UpdateCvarsForId(i) fputs(fh, strcat("seta hud_", panel_name, " ", ftos(cvar(strcat("hud_", panel_name))), "\n")); fputs(fh, strcat("seta hud_", panel_name, "_pos \"", cvar_string(strcat("hud_", panel_name, "_pos")), "\"", "\n")); @@ -597,7 +597,7 @@ void HUD_Panel_ExportCfg(string cfgname) vector HUD_Panel_GetMenuSize(float id) { vector mySize; - mySize = stov(cvar_string(strcat("hud_", panel_name, "_size"))); + mySize = panel_size; mySize = eX * mySize_x * vid_conwidth + eY * mySize_y * vid_conheight; @@ -633,7 +633,7 @@ vector HUD_Panel_GetMenuSize(float id) vector HUD_Panel_GetMenuPos(float id) { vector pos; - pos = stov(cvar_string(strcat("hud_", panel_name, "_pos"))); + pos = panel_pos; pos = eX * pos_x * vid_conwidth + eY * pos_y * vid_conheight; @@ -682,7 +682,7 @@ void HUD_Panel_DrawProgressBar(vector pos, float vertical, vector mySize, vector stov(cvar_string(strcat("hud_progressbar_", item, "_color"))) // check if move will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector -vector HUD_Panel_CheckMove(float id, vector myPos, vector mySize) +vector HUD_Panel_CheckMove(vector myPos, vector mySize) { float i; @@ -699,7 +699,7 @@ vector HUD_Panel_CheckMove(float id, vector myPos, vector mySize) for (i = 0; i < HUD_PANEL_NUM; ++i) { HUD_Panel_UpdateCvarsForId(i) - if(i == id || !panel_enabled) + if(i == highlightedPanel || !panel_enabled) continue; targPos = panel_pos; @@ -756,16 +756,13 @@ vector HUD_Panel_CheckMove(float id, vector myPos, vector mySize) return myTarget; } -void HUD_Panel_SetPos(float id, vector pos) +void HUD_Panel_SetPos(vector pos) { - vector oldPos; - oldPos = panel_pos; - vector mySize; mySize = panel_size; if(autocvar_hud_configure_checkcollisions) - pos = HUD_Panel_CheckMove(id, pos, mySize); + pos = HUD_Panel_CheckMove(pos, mySize); pos_x = bound(0, pos_x, vid_conwidth - mySize_x); pos_y = bound(0, pos_y, vid_conheight - mySize_y); @@ -779,11 +776,12 @@ void HUD_Panel_SetPos(float id, 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_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 -vector HUD_Panel_CheckResize(float id, vector mySize, vector resizeorigin) { +vector HUD_Panel_CheckResize(vector mySize, vector resizeorigin) { float i; float targBorder; @@ -796,7 +794,9 @@ vector HUD_Panel_CheckResize(float id, vector mySize, vector resizeorigin) { ratio = mySize_x/mySize_y; for (i = 0; i < HUD_PANEL_NUM; ++i) { - if(i == id || !panel_enabled) + HUD_Panel_UpdateCvarsForId(i); + + if(i == highlightedPanel || !panel_enabled) continue; targPos = panel_pos; @@ -893,8 +893,9 @@ vector HUD_Panel_CheckResize(float id, vector mySize, vector resizeorigin) { return mySize; } -void HUD_Panel_SetPosSize(float id, vector mySize) +void HUD_Panel_SetPosSize(vector mySize) { + HUD_Panel_UpdatePosSizeForId(highlightedPanel) vector resizeorigin; resizeorigin = panel_click_resizeorigin; vector myPos; @@ -903,7 +904,7 @@ void HUD_Panel_SetPosSize(float id, vector mySize) mySize_x = max(0.025 * vid_conwidth, mySize_x); mySize_y = max(0.025 * vid_conheight, mySize_y); - if(id == HUD_PANEL_CHAT) // some panels have their own restrictions, like the chat panel (which actually only moves the engine chat print around). Looks bad if it's too small. + if(highlightedPanel == HUD_PANEL_CHAT) // some panels have their own restrictions, like the chat panel (which actually only moves the engine chat print around). Looks bad if it's too small. { mySize_x = max(17 * cvar("con_chatsize"), mySize_x); mySize_y = max(2 * cvar("con_chatsize") + 2 * panel_bg_padding, mySize_y); @@ -950,7 +951,7 @@ void HUD_Panel_SetPosSize(float id, vector mySize) } if(autocvar_hud_configure_checkcollisions) - mySize = HUD_Panel_CheckResize(id, mySize, resizeorigin); + mySize = HUD_Panel_CheckResize(mySize, resizeorigin); // minimum panel size cap, do this once more so we NEVER EVER EVER have a panel smaller than this, JUST IN CASE above code still makes the panel eg negative (impossible to resize back without changing cvars manually then) mySize_x = max(0.025 * vid_conwidth, mySize_x); @@ -974,6 +975,7 @@ void HUD_Panel_SetPosSize(float id, vector mySize) if(cvar("hud_configure_checkcollisions_debug")) drawfill(myPos, mySize, '0 1 0', .3, DRAWFLAG_NORMAL); + HUD_Panel_GetName(highlightedPanel); string s; s = strcat(ftos(mySize_x/vid_conwidth), " ", ftos(mySize_y/vid_conheight)); cvar_set(strcat("hud_", panel_name, "_size"), s); @@ -1066,7 +1068,7 @@ void HUD_Panel_Arrow_Action(float nPrimary) } else { // resizeCorner == 4 mySize_y += step; } - HUD_Panel_SetPosSize(highlightedPanel, mySize); + HUD_Panel_SetPosSize(mySize); } else // move { @@ -1082,7 +1084,7 @@ void HUD_Panel_Arrow_Action(float nPrimary) else // if(nPrimary == K_RIGHTARROW) pos_x += step; - HUD_Panel_SetPos(highlightedPanel, pos); + HUD_Panel_SetPos(pos); } } @@ -1202,6 +1204,8 @@ void HUD_Panel_Highlight() for(i = 0; i < HUD_PANEL_NUM; ++i) { + HUD_Panel_UpdateCvarsForId(i); + panelPos = panel_pos; panelSize = panel_size; border = 10; // FORCED border so a small border size doesn't mean you can't resize @@ -1293,7 +1297,7 @@ void HUD_Panel_Mouse() hud_configure_checkcollisions = (!(hudShiftState & S_CTRL) && cvar("hud_configure_checkcollisions")); if(highlightedAction == 1) - HUD_Panel_SetPos(highlightedPanel, mousepos - panel_click_distance); + HUD_Panel_SetPos(mousepos - panel_click_distance); else if(highlightedAction == 2) { vector mySize; @@ -1310,7 +1314,7 @@ void HUD_Panel_Mouse() mySize_x = mousepos_x - (panel_click_resizeorigin_x - panel_click_distance_x); mySize_y = mousepos_y - (panel_click_resizeorigin_y - panel_click_distance_y); } - HUD_Panel_SetPosSize(highlightedPanel, mySize); + HUD_Panel_SetPosSize(mySize); } // doubleclick check @@ -1712,6 +1716,7 @@ void DrawNumIcon(float id, vector myPos, vector mySize, float x, string icon, fl newPos_x = myPos_x; } + HUD_Panel_GetName(id); vector picpos, numpos; float iconalign; iconalign = cvar(strcat("hud_", panel_name, "_iconalign")); diff --git a/qcsrc/client/hud.qh b/qcsrc/client/hud.qh index 04f7f652b..e81704004 100644 --- a/qcsrc/client/hud.qh +++ b/qcsrc/client/hud.qh @@ -94,7 +94,7 @@ if(!autocvar__hud_configure && panel_bg_str == "0") {\ // Get value for panel_bg_color: if "" fetch default, else use panel_bg_color. Convert pants, shirt or teamcolor into a vector. #define HUD_Panel_GetColor()\ if(panel_bg_color_str == "") {\ - panel_bg_color_str = autocvar_hud_bg_color;\ + panel_bg_color = autocvar_hud_bg_color;\ } if(teamplay && panel_bg_color_team) {\ panel_bg_color = colormapPaletteColor(mod(stof(getplayerkey(player_localentnum - 1, "colors")), 16), 1) * panel_bg_color_team;\ } else {\ @@ -209,6 +209,30 @@ switch(id) { \ case HUD_PANEL_ENGINEINFO: HUD_Panel_UpdateCvars(engineinfo) break; \ } +#define HUD_Panel_UpdatePosSize(name) \ +panel_pos = autocvar_hud_##name##_pos; \ +panel_size = autocvar_hud_##name##_size; \ +HUD_Panel_GetScaledVectors() + +// Update pos and size of given panel id +#define HUD_Panel_UpdatePosSizeForId(id) \ +switch(id) { \ + case HUD_PANEL_WEAPONICONS: HUD_Panel_UpdatePosSize(weaponicons) break; \ + case HUD_PANEL_INVENTORY: HUD_Panel_UpdatePosSize(inventory) 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; \ +} + /* These cvars have to be placed separately wherever they are needed. panel_accuracy_yellow = autocvar_hud_##name##_accuracy_yellow; \ panel_onlycurrent = autocvar_hud_##name##_onlycurrent; \ diff --git a/qcsrc/common/util.qc b/qcsrc/common/util.qc index a622c320f..9875529d3 100644 --- a/qcsrc/common/util.qc +++ b/qcsrc/common/util.qc @@ -1948,23 +1948,3 @@ float get_model_parameters(string m, float sk) return 1; } - -// we probably want to get rid of GetName in the most places in hud.qc, TODO! -// Get name of specified panel id -#define HUD_Panel_GetName(id) \ -switch(id) { \ - case HUD_PANEL_WEAPONICONS: panel_name = HUD_PANELNAME_WEAPONICONS; break; \ - case HUD_PANEL_INVENTORY: panel_name = HUD_PANELNAME_INVENTORY; 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; \ - case HUD_PANEL_ENGINEINFO: panel_name = HUD_PANELNAME_ENGINEINFO; break; \ -} diff --git a/qcsrc/common/util.qh b/qcsrc/common/util.qh index 2a57be012..56659d038 100644 --- a/qcsrc/common/util.qh +++ b/qcsrc/common/util.qh @@ -211,4 +211,22 @@ float get_model_parameters_age; 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 -string HUD_Panel_GetName(float id) + +// Get name of specified panel id +#define HUD_Panel_GetName(id) \ +switch(id) { \ + case HUD_PANEL_WEAPONICONS: panel_name = HUD_PANELNAME_WEAPONICONS; break; \ + case HUD_PANEL_INVENTORY: panel_name = HUD_PANELNAME_INVENTORY; 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; \ + case HUD_PANEL_ENGINEINFO: panel_name = HUD_PANELNAME_ENGINEINFO; break; \ +}