diff --git a/TestGame/TestGame.cs b/TestGame/TestGame.cs index 0cc5832..b722f5e 100644 --- a/TestGame/TestGame.cs +++ b/TestGame/TestGame.cs @@ -92,10 +92,11 @@ public class TestGame : Game protected override void Render(double deltaTime) { Renderer.ClearBackground(Color.Black); - foreach (var emitter in _particleSystem!.Emitters) - { - DrawEmitter(emitter); - } + + // foreach (var emitter in _particleSystem!.Emitters) + // { + // DrawEmitter(emitter); + // } Renderer.ResetTransform(); _uiSystem.Render(Renderer); diff --git a/Voile/GridSet.cs b/Voile/GridSet.cs new file mode 100644 index 0000000..9c18362 --- /dev/null +++ b/Voile/GridSet.cs @@ -0,0 +1,37 @@ +using System.Collections; +using System.Collections.Generic; +using System.Numerics; +using Voile.Extensions; + +namespace Voile; + +public class GridSet +{ + public float GridSize { get; } + public GridSet(float gridSize = 32.0f) + { + GridSize = gridSize; + } + + public void Add(Vector2 position, T child) + { + var snap = Vector2.One * GridSize; + position = position.Snapped(snap); + + if (_values.TryGetValue(position, out var list)) + { + list.Add(child); + } + else + { + _values.Add(position, new List()); + } + } + + public void Remove(T child) + { + + } + + private Dictionary> _values = new(); +} \ No newline at end of file diff --git a/Voile/Source/Extensions/Vector2Extensions.cs b/Voile/Source/Extensions/Vector2Extensions.cs index 6c72e68..d3e75e7 100644 --- a/Voile/Source/Extensions/Vector2Extensions.cs +++ b/Voile/Source/Extensions/Vector2Extensions.cs @@ -8,5 +8,31 @@ namespace Voile.Extensions { return new Vector2((float)MathUtils.Lerp(a.X, b.X, t), (float)MathUtils.Lerp(a.Y, b.Y, t)); } + + public static Vector2 Snapped(this Vector2 a, Vector2 snap) + { + var x = a.X % snap.X; + var y = a.Y % snap.Y; + + if (x == 0) + { + x = a.X; + } + else + { + x = a.X - x; + } + + if (y == 0) + { + y = a.Y; + } + else + { + y = a.Y - y; + } + + return new Vector2(x, y); + } } } \ No newline at end of file diff --git a/Voile/Source/UI/UISystem.cs b/Voile/Source/UI/UISystem.cs index 875a3fc..5dfd6b5 100644 --- a/Voile/Source/UI/UISystem.cs +++ b/Voile/Source/UI/UISystem.cs @@ -31,7 +31,11 @@ public class UISystem : IUpdatableSystem, IRenderableSystem _elements = elements; } - public void AddElement(UIElement element) => _elements.Add(element); + public void AddElement(UIElement element) + { + _elements.Add(element); + _inputElementIndices.Add(element.GlobalPosition, _elements.Count - 1); + } public void RemoveElement(UIElement element) => _elements.Remove(element); public void Update(double deltaTime) @@ -167,5 +171,7 @@ public class UISystem : IUpdatableSystem, IRenderableSystem private List _elements = new(); private InputSystem _input; + private GridSet _inputElementIndices = new(); + private Vector2 _lastMousePosition = Vector2.Zero; } \ No newline at end of file