109 lines
3.5 KiB
C#
109 lines
3.5 KiB
C#
using Raylib_cs;
|
|
using System.Numerics;
|
|
|
|
namespace Sand.App;
|
|
|
|
internal static partial class SandApp
|
|
{
|
|
private static void HandleSidebar(AppState state, Vector2 mouse)
|
|
{
|
|
if (mouse.X >= SidebarWidth)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var y = 60;
|
|
foreach (var category in state.Categories.Keys.Skip(state.CategoryScrollOffset).Take(GetVisibleCategoryRows()))
|
|
{
|
|
var rect = new Rectangle(12, y, 196, 32);
|
|
if (Raylib.CheckCollisionPointRec(mouse, rect))
|
|
{
|
|
state.CurrentCategory = category;
|
|
state.ParticleScrollOffset = 0;
|
|
if (state.Categories[state.CurrentCategory].Count > 0)
|
|
{
|
|
state.CurrentParticle = state.Categories[state.CurrentCategory][0].Id;
|
|
}
|
|
return;
|
|
}
|
|
|
|
y += 38;
|
|
}
|
|
|
|
y = 240;
|
|
var visibleRows = GetVisibleParticleRows();
|
|
foreach (var particle in state.Categories[state.CurrentCategory].Skip(state.ParticleScrollOffset).Take(visibleRows))
|
|
{
|
|
var rect = new Rectangle(12, y, 196, 24);
|
|
if (Raylib.CheckCollisionPointRec(mouse, rect))
|
|
{
|
|
state.CurrentParticle = particle.Id;
|
|
return;
|
|
}
|
|
|
|
y += 28;
|
|
}
|
|
|
|
var clearRect = new Rectangle(12, Raylib.GetScreenHeight() - 96, 196, 32);
|
|
if (Raylib.CheckCollisionPointRec(mouse, clearRect))
|
|
{
|
|
state.Simulation.Clear();
|
|
return;
|
|
}
|
|
|
|
var settingsRect = new Rectangle(12, Raylib.GetScreenHeight() - 54, 196, 32);
|
|
if (Raylib.CheckCollisionPointRec(mouse, settingsRect))
|
|
{
|
|
state.SettingsVisible = !state.SettingsVisible;
|
|
state.Settings.EnableDebug = state.SettingsVisible || state.Settings.EnableDebug;
|
|
}
|
|
}
|
|
|
|
private static void HandleSettingsPanel(AppState state, Rectangle panelRect, Vector2 mouse)
|
|
{
|
|
if (!Raylib.CheckCollisionPointRec(mouse, panelRect))
|
|
{
|
|
return;
|
|
}
|
|
|
|
var y = panelRect.Y + 18;
|
|
foreach (var item in state.SettingItems.Skip(state.SettingsScrollOffset).Take(GetVisibleSettingsRows(panelRect)))
|
|
{
|
|
var rowRect = new Rectangle(panelRect.X + 12, y, panelRect.Width - 24, 26);
|
|
if (Raylib.CheckCollisionPointRec(mouse, rowRect))
|
|
{
|
|
item.Toggle();
|
|
state.Simulation.RefreshSettingsState();
|
|
return;
|
|
}
|
|
|
|
y += 34;
|
|
}
|
|
|
|
var speedDownRect = new Rectangle(panelRect.X + 12, panelRect.Y + panelRect.Height - 36, 48, 24);
|
|
var speedUpRect = new Rectangle(panelRect.X + 72, panelRect.Y + panelRect.Height - 36, 48, 24);
|
|
if (Raylib.CheckCollisionPointRec(mouse, speedDownRect))
|
|
{
|
|
state.Simulation.Settings.TimeScale = MathF.Max(0.1f, state.Simulation.Settings.TimeScale - 0.1f);
|
|
state.SimulationAccumulator = 0f;
|
|
return;
|
|
}
|
|
|
|
if (Raylib.CheckCollisionPointRec(mouse, speedUpRect))
|
|
{
|
|
state.Simulation.Settings.TimeScale = MathF.Min(4f, state.Simulation.Settings.TimeScale + 0.1f);
|
|
state.SimulationAccumulator = 0f;
|
|
}
|
|
}
|
|
|
|
private static int GetVisibleParticleRows()
|
|
{
|
|
return Math.Max(1, (Raylib.GetScreenHeight() - 404) / 28);
|
|
}
|
|
|
|
private static int GetVisibleCategoryRows()
|
|
{
|
|
return Math.Max(1, (240 - 60) / 38);
|
|
}
|
|
}
|