X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fclient%2Fhud%2Fpanel%2Fweapons.qc;h=3f67787020693ad72e46cde40f0d824dbbdb6b2d;hb=a4d83c6badb407551c89dfdda9c0f048d0419a2b;hp=6e9f13dac10cada4c1b604fdf43821eab94a91a6;hpb=46a44942030ee6350c6847bf0efe75a1e0d54c6b;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/client/hud/panel/weapons.qc b/qcsrc/client/hud/panel/weapons.qc index 6e9f13dac..3f6778702 100644 --- a/qcsrc/client/hud/panel/weapons.qc +++ b/qcsrc/client/hud/panel/weapons.qc @@ -1,8 +1,17 @@ -// Weapon icons (#0) +#include "weapons.qh" + +#include +#include +#include +#include +#include + +// Weapons (#0) entity weaponorder[Weapons_MAX]; void weaponorder_swap(int i, int j, entity pass) { + TC(int, i); TC(int, j); entity h = weaponorder[i]; weaponorder[i] = weaponorder[j]; weaponorder[j] = h; @@ -11,14 +20,27 @@ void weaponorder_swap(int i, int j, entity pass) string weaponorder_cmp_str; int weaponorder_cmp(int i, int j, entity pass) { + TC(int, i); TC(int, j); int ai = strstrofs(weaponorder_cmp_str, sprintf(" %d ", weaponorder[i].m_id), 0); int aj = strstrofs(weaponorder_cmp_str, sprintf(" %d ", weaponorder[j].m_id), 0); return aj - ai; // the string is in REVERSE order (higher prio at the right is what we want, but higher prio first is the string) } +#define HUD_WEAPONS_GET_FULL_LAYOUT() MACRO_BEGIN \ + int nHidden = 0; \ + FOREACH(Weapons, it != WEP_Null, { \ + if (weapons_stat & WepSet_FromWeapon(it)) continue; \ + if ((it.spawnflags & WEP_FLAG_HIDDEN) || (it.spawnflags & WEP_FLAG_MUTATORBLOCKED)) nHidden += 1; \ + }); \ + vector table_size = HUD_GetTableSize_BestItemAR((Weapons_COUNT - 1) - nHidden, panel_size, aspect); \ + columns = table_size.x; \ + rows = table_size.y; \ + weapon_size.x = panel_size.x / columns; \ + weapon_size.y = panel_size.y / rows; \ +MACRO_END + void HUD_Weapons() { - SELFPARAM(); // declarations WepSet weapons_stat = WepSet_GetFromStat(); int i; @@ -41,9 +63,13 @@ void HUD_Weapons() float when = max(1, autocvar_hud_panel_weapons_complainbubble_time); float fadetime = max(0, autocvar_hud_panel_weapons_complainbubble_fadetime); + bool infinite_ammo = (STAT(ITEMS) & IT_UNLIMITED_WEAPON_AMMO); + vector weapon_pos, weapon_size = '0 0 0'; vector color; + entity panel_switchweapon = NULL; + // check to see if we want to continue if(hud != HUD_NORMAL) return; @@ -51,6 +77,8 @@ void HUD_Weapons() { if((!autocvar_hud_panel_weapons) || (spectatee_status == -1)) return; + if(STAT(HEALTH) <= 0 && autocvar_hud_panel_weapons_hide_ondeath) + return; if(timeout && time >= weapontime + timeout + timeout_effect_length) if(autocvar_hud_panel_weapons_timeout_effect == 3 || (autocvar_hud_panel_weapons_timeout_effect == 1 && !(autocvar_hud_panel_weapons_timeout_fadebgmin + autocvar_hud_panel_weapons_timeout_fadefgmin))) { @@ -60,19 +88,14 @@ void HUD_Weapons() } // update generic hud functions - HUD_Panel_UpdateCvars(); + HUD_Panel_LoadCvars(); // figure out weapon order (how the weapons are sorted) // TODO make this configurable if(weaponorder_bypriority != autocvar_cl_weaponpriority || !weaponorder[0]) { int weapon_cnt; - if(weaponorder_bypriority) - strunzone(weaponorder_bypriority); - if(weaponorder_byimpulse) - strunzone(weaponorder_byimpulse); - - weaponorder_bypriority = strzone(autocvar_cl_weaponpriority); - weaponorder_byimpulse = strzone(W_FixWeaponOrder_BuildImpulseList(W_FixWeaponOrder_ForceComplete(W_NumberWeaponOrder(weaponorder_bypriority)))); + strcpy(weaponorder_bypriority, autocvar_cl_weaponpriority); + strcpy(weaponorder_byimpulse, W_FixWeaponOrder_BuildImpulseList(W_FixWeaponOrder_ForceComplete(W_NumberWeaponOrder(weaponorder_bypriority)))); weaponorder_cmp_str = strcat(" ", weaponorder_byimpulse, " "); weapon_cnt = 0; @@ -85,22 +108,49 @@ void HUD_Weapons() } if(!autocvar_hud_panel_weapons_complainbubble || autocvar__hud_configure || time - complain_weapon_time >= when + fadetime) - complain_weapon = 0; + complain_weapon = NULL; + + entity wepent = viewmodels[0]; // TODO: unhardcode + + if (wepent.switchweapon == WEP_Null) + panel_switchweapon = NULL; + else if (!panel_switchweapon) + panel_switchweapon = wepent.switchweapon; if(autocvar__hud_configure) { if(!weapons_stat) - for(i = WEP_FIRST; i <= WEP_LAST; i += floor((WEP_LAST-WEP_FIRST)/5)) - weapons_stat |= WepSet_FromWeapon(Weapons_from(i)); + { + int j = 0; + FOREACH(Weapons, it != WEP_Null && it.impulse >= 0 && (it.impulse % 3 != 0) && j < 6, { + if(!(it.spawnflags & WEP_FLAG_MUTATORBLOCKED)) + { + if(!panel_switchweapon || j < 4) + panel_switchweapon = it; + weapons_stat |= it.m_wepset; + ++j; + } + }); + } #if 0 /// debug code if(cvar("wep_add")) { + int j; + int nHidden = 0; + FOREACH(Weapons, it != WEP_Null, { + if (it.spawnflags & WEP_FLAG_MUTATORBLOCKED) nHidden += 1; + }); weapons_stat = '0 0 0'; - float countw = 1 + floor((floor(time * cvar("wep_add"))) % (Weapons_COUNT - 1)); - for(i = WEP_FIRST; i <= countw; ++i) - weapons_stat |= WepSet_FromWeapon(Weapons_from(i)); + float countw = 1 + floor((floor(time * cvar("wep_add"))) % ((Weapons_COUNT - 1) - nHidden)); + for(i = 0, j = 0; i <= (Weapons_COUNT - 1) && j < countw; ++i) + { + if(weaponorder[i].spawnflags & WEP_FLAG_MUTATORBLOCKED) + continue; + weapons_stat |= weaponorder[i].m_wepset; + ++j; + } } #endif } @@ -110,56 +160,53 @@ void HUD_Weapons() { if(autocvar__hud_configure) { - if(menu_enabled != 2) - HUD_Panel_DrawBg(1); // also draw the bg of the entire panel + if(hud_configure_menu_open != 2) + HUD_Panel_DrawBg(); // also draw the bg of the entire panel } // do we own this weapon? weapon_count = 0; - for(i = 0; i <= WEP_LAST-WEP_FIRST; ++i) - if((weapons_stat & WepSet_FromWeapon(weaponorder[i])) || (weaponorder[i].m_id == complain_weapon)) - ++weapon_count; - + if (autocvar_hud_panel_weapons_onlyowned >= 2) // only current + { + for (i = 0; i <= WEP_LAST-WEP_FIRST; ++i) + if (weaponorder[i] == panel_switchweapon || weaponorder[i] == complain_weapon) + ++weapon_count; + } + else + { + for (i = 0; i <= WEP_LAST-WEP_FIRST; ++i) + if ((weapons_stat & WepSet_FromWeapon(weaponorder[i])) || weaponorder[i] == complain_weapon) + ++weapon_count; + } // might as well commit suicide now, no reason to live ;) if (weapon_count == 0) return; vector old_panel_size = panel_size; - vector padded_panel_size = panel_size - '2 2 0' * panel_bg_padding; - - // get the all-weapons layout - int nHidden = 0; - WepSet weapons_stat = WepSet_GetFromStat(); - FOREACH(Weapons, it != WEP_Null, { - if (weapons_stat & it.m_wepset) continue; - if (it.spawnflags & WEP_FLAG_MUTATORBLOCKED) nHidden += 1; - }); - vector table_size = HUD_GetTableSize_BestItemAR((Weapons_COUNT - 1) - nHidden, padded_panel_size, aspect); - columns = table_size.x; - rows = table_size.y; - weapon_size.x = padded_panel_size.x / columns; - weapon_size.y = padded_panel_size.y / rows; + panel_size -= '2 2 0' * panel_bg_padding; + + HUD_WEAPONS_GET_FULL_LAYOUT(); // NOTE: although weapons should aways look the same even if onlyowned is enabled, // we enlarge them a bit when possible to better match the desired aspect ratio - if(padded_panel_size.x / padded_panel_size.y < aspect) + if(panel_size.x / panel_size.y < aspect) { // maximum number of rows that allows to display items with the desired aspect ratio - int max_rows = floor(padded_panel_size.y / (weapon_size.x / aspect)); + int max_rows = floor(panel_size.y / (weapon_size.x / aspect)); columns = min(columns, ceil(weapon_count / max_rows)); rows = ceil(weapon_count / columns); - weapon_size.y = min(padded_panel_size.y / rows, weapon_size.x / aspect); - weapon_size.x = min(padded_panel_size.x / columns, aspect * weapon_size.y); + weapon_size.y = min(panel_size.y / rows, weapon_size.x / aspect); + weapon_size.x = min(panel_size.x / columns, aspect * weapon_size.y); vertical_order = false; } else { - int max_columns = floor(padded_panel_size.x / (weapon_size.y * aspect)); + int max_columns = floor(panel_size.x / (weapon_size.y * aspect)); rows = min(rows, ceil(weapon_count / max_columns)); columns = ceil(weapon_count / rows); - weapon_size.x = min(padded_panel_size.x / columns, aspect * weapon_size.y); - weapon_size.y = min(padded_panel_size.y / rows, weapon_size.x / aspect); + weapon_size.x = min(panel_size.x / columns, aspect * weapon_size.y); + weapon_size.y = min(panel_size.y / rows, weapon_size.x / aspect); vertical_order = true; } @@ -280,10 +327,14 @@ void HUD_Weapons() } // draw the background, then change the virtual size of it to better fit other items inside - HUD_Panel_DrawBg(1); + if (autocvar_hud_panel_weapons_dynamichud) + HUD_Scale_Enable(); + else + HUD_Scale_Disable(); + HUD_Panel_DrawBg(); if(center.x == -1) - return; + return; // panel has gone off screen if(panel_bg_padding) { @@ -295,16 +346,12 @@ void HUD_Weapons() if(!rows) // if rows is > 0 onlyowned code has already updated these vars { - vector table_size = HUD_GetTableSize_BestItemAR((Weapons_COUNT - 1), panel_size, aspect); - columns = table_size.x; - rows = table_size.y; - weapon_size.x = panel_size.x / columns; - weapon_size.y = panel_size.y / rows; + HUD_WEAPONS_GET_FULL_LAYOUT(); vertical_order = (panel_size.x / panel_size.y >= aspect); } // calculate position/size for visual bar displaying ammount of ammo status - if (autocvar_hud_panel_weapons_ammo) + if (!infinite_ammo && autocvar_hud_panel_weapons_ammo) { ammo_color = stov(autocvar_hud_panel_weapons_ammo_color); ammo_alpha = panel_fg_alpha * autocvar_hud_panel_weapons_ammo_alpha; @@ -328,34 +375,68 @@ void HUD_Weapons() // draw items row = column = 0; vector label_size = '1 1 0' * min(weapon_size.x, weapon_size.y) * bound(0, autocvar_hud_panel_weapons_label_scale, 1); - vector noncurrent_pos = '0 0 0'; - vector noncurrent_size = weapon_size * bound(0, autocvar_hud_panel_weapons_noncurrent_scale, 1); + vector noncurrent_size = weapon_size * bound(0.01, autocvar_hud_panel_weapons_noncurrent_scale, 1); float noncurrent_alpha = panel_fg_alpha * bound(0, autocvar_hud_panel_weapons_noncurrent_alpha, 1); - bool isCurrent; + static vector weapon_pos_current = '-1 0 0'; + if(weapon_pos_current.x == -1) + weapon_pos_current = panel_pos; + + float switch_speed; + if(autocvar_hud_panel_weapons_selection_speed <= 0 || autocvar__hud_configure) + switch_speed = 999; + else + switch_speed = frametime * autocvar_hud_panel_weapons_selection_speed; + vector radius_size = weapon_size * (autocvar_hud_panel_weapons_selection_radius + 1); + + // draw background behind currently selected weapon + // do it earlier to make sure bg is drawn behind every weapon icons while it's moving + if(panel_switchweapon) + drawpic_aspect_skin(weapon_pos_current, "weapon_current_bg", weapon_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL); for(i = 0; i <= WEP_LAST-WEP_FIRST; ++i) { // retrieve information about the current weapon to be drawn entity it = weaponorder[i]; weapon_id = it.impulse; - isCurrent = (it == switchweapon); // skip if this weapon doesn't exist if(!it || weapon_id < 0) { continue; } // skip this weapon if we don't own it (and onlyowned is enabled)-- or if weapons_complainbubble is showing for this weapon - if(autocvar_hud_panel_weapons_onlyowned) - if (!((weapons_stat & WepSet_FromWeapon(it)) || (it.m_id == complain_weapon))) - continue; + if (autocvar_hud_panel_weapons_onlyowned) + { + if (autocvar_hud_panel_weapons_onlyowned >= 2) // only current + { + if (!(it == panel_switchweapon || it == complain_weapon)) + continue; + } + else + { + if (!((weapons_stat & WepSet_FromWeapon(it)) || (it == complain_weapon))) + continue; + } + } + else + { + if (((it.spawnflags & WEP_FLAG_HIDDEN) || (it.spawnflags & WEP_FLAG_MUTATORBLOCKED)) && !(weapons_stat & WepSet_FromWeapon(it))) + continue; + } // figure out the drawing position of weapon - weapon_pos = (panel_pos + eX * column * weapon_size.x + eY * row * weapon_size.y); - noncurrent_pos.x = weapon_pos.x + (weapon_size.x - noncurrent_size.x) / 2; - noncurrent_pos.y = weapon_pos.y + (weapon_size.y - noncurrent_size.y) / 2; + weapon_pos = panel_pos + vec2(column * weapon_size.x, row * weapon_size.y); - // draw background behind currently selected weapon - if(isCurrent) - drawpic_aspect_skin(weapon_pos, "weapon_current_bg", weapon_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL); + // update position of the currently selected weapon + if(it == panel_switchweapon) + { + if(weapon_pos_current.y > weapon_pos.y) + weapon_pos_current.y = max(weapon_pos.y, weapon_pos_current.y - switch_speed * (weapon_pos_current.y - weapon_pos.y)); + else if(weapon_pos_current.y < weapon_pos.y) + weapon_pos_current.y = min(weapon_pos.y, weapon_pos_current.y + switch_speed * (weapon_pos.y - weapon_pos_current.y)); + if(weapon_pos_current.x > weapon_pos.x) + weapon_pos_current.x = max(weapon_pos.x, weapon_pos_current.x - switch_speed * (weapon_pos_current.x - weapon_pos.x)); + else if(weapon_pos_current.x < weapon_pos.x) + weapon_pos_current.x = min(weapon_pos.x, weapon_pos_current.x + switch_speed * (weapon_pos.x - weapon_pos_current.x)); + } // draw the weapon accuracy if(autocvar_hud_panel_weapons_accuracy) @@ -368,14 +449,26 @@ void HUD_Weapons() } } + vector weapon_size_real = noncurrent_size; + float weapon_alpha_real = noncurrent_alpha; + float radius_factor_x = 1 - bound(0, fabs(weapon_pos.x - weapon_pos_current.x) / radius_size.x, 1); + float radius_factor_y = 1 - bound(0, fabs(weapon_pos.y - weapon_pos_current.y) / radius_size.y, 1); + if(radius_factor_x || radius_factor_y) + { + weapon_size_real.x += (weapon_size.x - noncurrent_size.x) * radius_factor_x; + weapon_size_real.y += (weapon_size.y - noncurrent_size.y) * radius_factor_y; + weapon_alpha_real += (panel_fg_alpha - noncurrent_alpha) * min(radius_factor_x, radius_factor_y); + } + + vector weapon_pos_real = weapon_pos; + weapon_pos_real.x = weapon_pos.x + (weapon_size.x - weapon_size_real.x) / 2; + weapon_pos_real.y = weapon_pos.y + (weapon_size.y - weapon_size_real.y) / 2; + // drawing all the weapon items if(weapons_stat & WepSet_FromWeapon(it)) { // draw the weapon image - if(isCurrent) - drawpic_aspect_skin(weapon_pos, it.model2, weapon_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL); - else - drawpic_aspect_skin(noncurrent_pos, it.model2, noncurrent_size, '1 1 1', noncurrent_alpha, DRAWFLAG_NORMAL); + drawpic_aspect_skin(weapon_pos_real, it.model2, weapon_size_real, '1 1 1', weapon_alpha_real, DRAWFLAG_NORMAL); // draw weapon label string switch(autocvar_hud_panel_weapons_label) @@ -397,21 +490,21 @@ void HUD_Weapons() } // draw ammo status bar - if(autocvar_hud_panel_weapons_ammo && (it.ammo_field != ammo_none)) + if(!infinite_ammo && autocvar_hud_panel_weapons_ammo && (it.ammo_type != RES_NONE)) { float ammo_full; - a = getstati(GetAmmoStat(it.ammo_field)); // how much ammo do we have? + a = getstati(GetAmmoStat(it.ammo_type)); // how much ammo do we have? if(a > 0) { - switch(it.ammo_field) + switch (it.ammo_type) { - case ammo_shells: ammo_full = autocvar_hud_panel_weapons_ammo_full_shells; break; - case ammo_nails: ammo_full = autocvar_hud_panel_weapons_ammo_full_nails; break; - case ammo_rockets: ammo_full = autocvar_hud_panel_weapons_ammo_full_rockets; break; - case ammo_cells: ammo_full = autocvar_hud_panel_weapons_ammo_full_cells; break; - case ammo_plasma: ammo_full = autocvar_hud_panel_weapons_ammo_full_plasma; break; - case ammo_fuel: ammo_full = autocvar_hud_panel_weapons_ammo_full_fuel; break; + case RES_SHELLS: ammo_full = autocvar_hud_panel_weapons_ammo_full_shells; break; + case RES_BULLETS: ammo_full = autocvar_hud_panel_weapons_ammo_full_nails; break; + case RES_ROCKETS: ammo_full = autocvar_hud_panel_weapons_ammo_full_rockets; break; + case RES_CELLS: ammo_full = autocvar_hud_panel_weapons_ammo_full_cells; break; + case RES_PLASMA: ammo_full = autocvar_hud_panel_weapons_ammo_full_plasma; break; + case RES_FUEL: ammo_full = autocvar_hud_panel_weapons_ammo_full_fuel; break; default: ammo_full = 60; } @@ -437,11 +530,11 @@ void HUD_Weapons() } else // draw a "ghost weapon icon" if you don't have the weapon { - drawpic_aspect_skin(noncurrent_pos, it.model2, noncurrent_size, '0.2 0.2 0.2', panel_fg_alpha * 0.5, DRAWFLAG_NORMAL); + drawpic_aspect_skin(weapon_pos_real, it.model2, weapon_size_real, '0.2 0.2 0.2', weapon_alpha_real * 0.5, DRAWFLAG_NORMAL); } // draw the complain message - if(it.m_id == complain_weapon) + if(it == complain_weapon) { if(fadetime) a = ((complain_weapon_time + when > time) ? 1 : bound(0, (complain_weapon_time + when + fadetime - time) / fadetime, 1));