From: terencehill Date: Mon, 2 Feb 2015 23:37:19 +0000 (+0100) Subject: Merge branch 'master' into terencehill/weapon_panel_fix X-Git-Tag: xonotic-v0.8.1~129^2 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=bb80a6aba067167c6ef8d5f3465f03bd34142fa2;p=xonotic%2Fxonotic-data.pk3dir.git Merge branch 'master' into terencehill/weapon_panel_fix Conflicts: qcsrc/client/hud.qc --- bb80a6aba067167c6ef8d5f3465f03bd34142fa2 diff --cc qcsrc/client/hud.qc index 89519d627,e33b9b020..024a0761e --- a/qcsrc/client/hud.qc +++ b/qcsrc/client/hud.qc @@@ -132,15 -140,9 +140,15 @@@ vector HUD_Get_Num_Color (float x, floa return color; } +float HUD_GetRowCount(float item_count, vector size, float item_aspect) +{ - float aspect = size_y/size_x; ++ float aspect = size_y / size_x; + return bound(1, floor((sqrt(4 * item_aspect * aspect * item_count + aspect * aspect) + aspect + 0.5) / 2), item_count); +} + float stringwidth_colors(string s, vector theSize) { - return stringwidth(s, TRUE, theSize); + return stringwidth(s, true, theSize); } float stringwidth_nocolors(string s, vector theSize) @@@ -419,16 -421,20 +427,17 @@@ void HUD_Weapons(void // declarations WepSet weapons_stat = WepSet_GetFromStat(); float i, f, a; - float screen_ar, center_x = 0, center_y; + float screen_ar; + vector center = '0 0 0'; float weapon_count, weapon_id; - float row, column, rows = 0, columns = 0; + float row, column, rows = 0, columns; float aspect = autocvar_hud_panel_weapons_aspect; - float panel_weapon_accuracy; - float timeout = autocvar_hud_panel_weapons_timeout; float timein_effect_length = autocvar_hud_panel_weapons_timeout_speed_in; //? 0.375 : 0); float timeout_effect_length = autocvar_hud_panel_weapons_timeout_speed_out; //? 0.75 : 0); - float barsize_x = 0, barsize_y = 0, baroffset_x = 0, baroffset_y = 0; - float ammo_full; + vector barsize = '0 0 0', baroffset = '0 0 0'; vector ammo_color = '1 0 1'; float ammo_alpha = 1; @@@ -520,36 -527,41 +529,36 @@@ return; } - vector max_panel_size = panel_size - '2 2 0' * panel_bg_padding; + vector old_panel_size = panel_size; + if(panel_bg_padding) + old_panel_size -= '2 2 0' * panel_bg_padding; - // calculate distribution and size of table cells - if(max_panel_size.x > max_panel_size.y) - { - while(weapon_count > columns * rows) - { - ++rows; - columns = ceil(max_panel_size.x / (max_panel_size.y / rows * aspect)); - } + // NOTE: the goal is to use the all-weapons layout and remove unneeded cells + // this way weapon icons always have the same size regardless of owned weapon count - weapon_size.x = max_panel_size.x / columns; - weapon_size.y = max_panel_size.y / rows; - columns = ceil(weapon_count / rows); - } - else - { - while(weapon_count > columns * rows) - { - ++columns; - rows = ceil(max_panel_size.y / (max_panel_size.x / columns / aspect)); - } + // get the all-weapons layout + rows = HUD_GetRowCount(WEP_COUNT, old_panel_size, aspect); + columns = ceil(WEP_COUNT/rows); - weapon_size_x = old_panel_size_x / columns; - weapon_size_y = old_panel_size_y / rows; ++ weapon_size.x = old_panel_size.x / columns; ++ weapon_size.y = old_panel_size.y / rows; - weapon_size.x = max_panel_size.x / columns; - weapon_size.y = max_panel_size.y / rows; - rows = ceil(weapon_count / columns); - } + // reduce rows and columns as needed + columns = ceil(weapon_count / rows); + rows = ceil(weapon_count / columns); + + // NOTE: although weapons should aways look the same even if onlyowned is disabled, + // we enlarge them a bit when possible to better match the desired aspect ratio + // as they look much better - weapon_size_x = min(old_panel_size_x / columns, aspect * weapon_size_y); - weapon_size_y = min(old_panel_size_y / rows, weapon_size_x / aspect); ++ weapon_size.x = min(old_panel_size.x / columns, aspect * weapon_size.y); ++ weapon_size.y = min(old_panel_size.y / rows, weapon_size.x / aspect); // reduce size of the panel - panel_size_x = columns * weapon_size_x; - panel_size_y = rows * weapon_size_y; - panel_pos_x += (old_panel_size_x - panel_size_x) / 2; - panel_pos_y += (old_panel_size_y - panel_size_y) / 2; + panel_size.x = columns * weapon_size.x; + panel_size.y = rows * weapon_size.y; - panel_pos.x += (max_panel_size.x - panel_size.x) / 2; - panel_pos.y += (max_panel_size.y - panel_size.y) / 2; - - panel_size += '2 2 0' * panel_bg_padding; ++ panel_pos.x += (old_panel_size.x - panel_size.x) / 2; ++ panel_pos.y += (old_panel_size.y - panel_size.y) / 2; + if(panel_bg_padding) + panel_size += '2 2 0' * panel_bg_padding; } else weapon_count = WEP_COUNT; @@@ -660,9 -672,10 +669,9 @@@ if(!rows) // if rows is > 0 onlyowned code has already updated these vars { - rows = panel_size.y/panel_size.x; - rows = bound(1, floor((sqrt(4 * aspect * rows * weapon_count + rows * rows) + rows + 0.5) / 2), weapon_count); + rows = HUD_GetRowCount(weapon_count, panel_size, aspect); columns = ceil(weapon_count/rows); - weapon_size = eX * panel_size_x*(1/columns) + eY * panel_size_y*(1/rows); + weapon_size = eX * panel_size.x*(1/columns) + eY * panel_size.y*(1/rows); } // calculate position/size for visual bar displaying ammount of ammo status @@@ -1003,18 -1015,23 +1012,18 @@@ void HUD_Ammo(void else nade_prevstatus = nade_prevframe = nade_statuschange_time = 0; - rows = mySize.y/mySize.x; - rows = bound(1, floor((sqrt(4 * (3/1) * rows * (total_ammo_count) + rows * rows) + rows + 0.5) / 2), (total_ammo_count)); - // ^^^ ammo item aspect goes here - + rows = HUD_GetRowCount(total_ammo_count, mySize, 3); columns = ceil((total_ammo_count)/rows); - ammo_size = eX * mySize_x*(1/columns) + eY * mySize_y*(1/rows); - + ammo_size = eX * mySize.x*(1/columns) + eY * mySize.y*(1/rows); - local vector offset = '0 0 0'; // fteqcc sucks - + vector offset = '0 0 0'; // fteqcc sucks float newSize; - if(ammo_size_x/ammo_size_y > 3) + if(ammo_size.x/ammo_size.y > 3) { - newSize = 3 * ammo_size_y; - offset_x = ammo_size_x - newSize; - pos_x += offset_x/2; - ammo_size_x = newSize; + newSize = 3 * ammo_size.y; + offset.x = ammo_size.x - newSize; + pos.x += offset.x/2; + ammo_size.x = newSize; } else { @@@ -2292,17 -2309,21 +2301,17 @@@ void HUD_Score(void } if(spectatee_status == -1) { - rows = mySize.y/mySize.x; - rows = bound(1, floor((sqrt(4 * (3/1) * rows * team_count + rows * rows) + rows + 0.5) / 2), team_count); - // ^^^ ammo item aspect goes here - + rows = HUD_GetRowCount(team_count, mySize, 3); columns = ceil(team_count/rows); - score_size = eX * mySize_x*(1/columns) + eY * mySize_y*(1/rows); - + score_size = eX * mySize.x*(1/columns) + eY * mySize.y*(1/rows); float newSize; - if(score_size_x/score_size_y > 3) + if(score_size.x/score_size.y > 3) { - newSize = 3 * score_size_y; - offset_x = score_size_x - newSize; - pos_x += offset_x/2; - score_size_x = newSize; + newSize = 3 * score_size.y; + offset.x = score_size.x - newSize; + pos.x += offset.x/2; + score_size.x = newSize; } else { @@@ -3324,10 -3336,11 +3323,10 @@@ void HUD_Mod_Dom(vector myPos, vector m { mod_active = 1; // required in each mod function that always shows something - float layout = autocvar_hud_panel_modicons_dom_layout; + int layout = autocvar_hud_panel_modicons_dom_layout; float rows, columns, aspect_ratio; - rows = mySize.y/mySize.x; aspect_ratio = (layout) ? 3 : 1; - rows = bound(1, floor((sqrt((4 * aspect_ratio * team_count + rows) * rows) + rows + 0.5) / 2), team_count); + rows = HUD_GetRowCount(team_count, mySize, aspect_ratio); columns = ceil(team_count/rows); int i;