Grid Inventory (#21931)

* Grid Inventory

* oh boy we keep cracking on

* auto insertion is kinda working? gross, too!

* pieces and proper layouts

* fix the sprites

* mousing over grid pieces... finally

* dragging deez nuts all over the screen

* eek!

* dragging is 90% less horrendous

* auto-rotating

* flatten

* Rotation at last

* fix rotation and change keybind for removing items.

* rebinding and keybinding

* wow! look at that! configurable with a button! cool!

* dragging is a bit cooler, eh?

* hover insert, my beloved

* add some grids for storage, fix 1x1 storages, fix multiple inputs at once

* el navigation

* oh yeah some stuff i forgor

* more fixes and QOL stuff

* the griddening

* the last of it (yippee)

* sloth review :)
This commit is contained in:
Nemanja
2023-12-04 18:04:39 -05:00
committed by GitHub
parent 4221ed2d4b
commit cc8984d096
99 changed files with 2014 additions and 619 deletions

View File

@@ -0,0 +1,76 @@
namespace Content.Shared.Storage;
public static class StorageHelper
{
public static Box2i GetBoundingBox(this IReadOnlyList<Box2i> boxes)
{
if (boxes.Count == 0)
return new Box2i();
var firstBox = boxes[0];
if (boxes.Count == 1)
return firstBox;
var bottom = firstBox.Bottom;
var left = firstBox.Left;
var top = firstBox.Top;
var right = firstBox.Right;
for (var i = 1; i < boxes.Count; i++)
{
var box = boxes[i];
if (bottom > box.Bottom)
bottom = box.Bottom;
if (left > box.Left)
left = box.Left;
if (top < box.Top)
top = box.Top;
if (right < box.Right)
right = box.Right;
}
return new Box2i(left, bottom, right, top);
}
public static int GetArea(this IReadOnlyList<Box2i> boxes)
{
var area = 0;
var bounding = boxes.GetBoundingBox();
for (var y = bounding.Bottom; y <= bounding.Top; y++)
{
for (var x = bounding.Left; x <= bounding.Right; x++)
{
if (boxes.Contains(x, y))
area++;
}
}
return area;
}
public static bool Contains(this IReadOnlyList<Box2i> boxes, int x, int y)
{
foreach (var box in boxes)
{
if (box.Contains(x, y))
return true;
}
return false;
}
public static bool Contains(this IReadOnlyList<Box2i> boxes, Vector2i point)
{
foreach (var box in boxes)
{
if (box.Contains(point))
return true;
}
return false;
}
}