-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelectionRenderSystem.cs
More file actions
54 lines (46 loc) · 2.34 KB
/
SelectionRenderSystem.cs
File metadata and controls
54 lines (46 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using Leopotam.EcsLite;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
public class SelectionRenderSystem : IEcsRunSystem
{
private EcsWorld _world;
private EcsFilter _selectionFilter;
private SpriteBatch _spriteBatch;
private Texture2D _pixelTexture; // 1x1 пиксель для рисования прямоугольника
private Camera _camera;
public SelectionRenderSystem(EcsWorld world, GraphicsDevice graphicsDevice, SpriteBatch spriteBatch, Camera camera)
{
_world = world;
_spriteBatch = spriteBatch;
_camera = camera;
_selectionFilter = _world.Filter<SelectionBox>().End();
// Создаём 1x1 текстуру для заливки
_pixelTexture = new Texture2D(graphicsDevice, 1, 1);
_pixelTexture.SetData(new[] { Color.White });
}
public void Run(IEcsSystems systems)
{
foreach (int entity in _selectionFilter)
{
ref SelectionBox selection = ref _world.GetPool<SelectionBox>().Get(entity);
if (!selection.IsActive) continue;
Rectangle bounds = selection.Bounds;
// Рисуем прозрачный прямоугольник (заливка)
_spriteBatch.Draw(
_pixelTexture,
bounds,
new Color(0, 0, 0, 100) // Полупрозрачный зелёный (можно настроить)
);
// Рисуем рамку (толщиной 2 пикселя)
int borderThickness = (int)MathHelper.Clamp((int)(2 / _camera.Zoom), 1, 5f);
// Верхняя линия
_spriteBatch.Draw(_pixelTexture, new Rectangle(bounds.X, bounds.Y, bounds.Width, borderThickness), Color.Green);
// Нижняя линия
_spriteBatch.Draw(_pixelTexture, new Rectangle(bounds.X, bounds.Y + bounds.Height - borderThickness, bounds.Width, borderThickness), Color.Green);
// Левая линия
_spriteBatch.Draw(_pixelTexture, new Rectangle(bounds.X, bounds.Y, borderThickness, bounds.Height), Color.Green);
// Правая линия
_spriteBatch.Draw(_pixelTexture, new Rectangle(bounds.X + bounds.Width - borderThickness, bounds.Y, borderThickness, bounds.Height), Color.Green);
}
}
}