]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Make the weapon panel snapping work with any padding value
authorSeverin Meyer <sev.ch@web.de>
Thu, 5 Feb 2015 20:43:33 +0000 (21:43 +0100)
committerSeverin Meyer <sev.ch@web.de>
Thu, 5 Feb 2015 20:43:33 +0000 (21:43 +0100)
qcsrc/client/hud.qc

index 1816d07552d7ad2c801e6138ffe7fa3745f41a55..86dfadbaf20b6c6c3d53e782bee9544f65d75040 100644 (file)
@@ -529,35 +529,37 @@ void HUD_Weapons(void)
                        return;
                }
 
-               vector old_panel_size = panel_size - '2 2 0' * panel_bg_padding;
+               vector old_panel_size = panel_size;
+               vector padded_panel_size = panel_size - '2 2 0' * panel_bg_padding;
 
                // 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;
+               rows = HUD_GetRowCount(WEP_COUNT, padded_panel_size, aspect);
+               columns = ceil(WEP_COUNT / rows);
+               weapon_size.x = padded_panel_size.x / columns;
+               weapon_size.y = padded_panel_size.y / rows;
 
                // reduce rows and columns as needed
                // 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(old_panel_size.y > old_panel_size.x)
+               if(padded_panel_size.y > padded_panel_size.x)
                {
                        columns = ceil(weapon_count / rows);
                        rows = ceil(weapon_count / columns);
-                       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(padded_panel_size.y / rows, weapon_size.x / aspect);
+                       weapon_size.x = min(padded_panel_size.x / columns, aspect * weapon_size.y);
                }
                else
                {
                        rows = ceil(weapon_count / columns);
                        columns = ceil(weapon_count / rows);
-                       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(padded_panel_size.x / columns, aspect * weapon_size.y);
+                       weapon_size.y = min(padded_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_size += '2 2 0' * panel_bg_padding;
 
                // center the resized panel, or snap it to the screen edge when close enough
                if(panel_pos.x > vid_conwidth * 0.001)
@@ -571,8 +573,6 @@ void HUD_Weapons(void)
                                panel_pos.y += old_panel_size.y - panel_size.y;
                        else
                                panel_pos.y += (old_panel_size.y - panel_size.y) / 2;
-
-               panel_size += '2 2 0' * panel_bg_padding;
        }
        else
                weapon_count = WEP_COUNT;