152 lines
4.2 KiB
C#
152 lines
4.2 KiB
C#
using Voile;
|
|
using Voile.Resources;
|
|
using Voile.Input;
|
|
using Voile.Systems.Particles;
|
|
using System.Numerics;
|
|
using System.Diagnostics.CodeAnalysis;
|
|
using Voile.Rendering;
|
|
using Voile.OpenAL;
|
|
using Voile.UI;
|
|
using Voile.UI.Widgets;
|
|
using Voile.UI.Containers;
|
|
|
|
public class TestGame : Game
|
|
{
|
|
public override string Name => "Test Game";
|
|
public override string ResourceRoot => "Resources/";
|
|
|
|
public override void Initialize()
|
|
{
|
|
InitializeSystemsDefault();
|
|
|
|
_uiSystem = new UISystem(Input, ResourceRef<Style>.Empty());
|
|
_uiSystem.RenderDebugRects = true;
|
|
|
|
_particleSystem = new ParticleSystem();
|
|
|
|
AddSystemToUpdate(_uiSystem);
|
|
AddSystemToUpdate(_particleSystem);
|
|
}
|
|
|
|
public override void Shutdown()
|
|
{
|
|
ShutdownDefault();
|
|
}
|
|
|
|
protected override void LoadResources()
|
|
{
|
|
ResourceManager.AddResourceLoaderAssociation(new ParticleEmitterSettingsResourceLoader());
|
|
|
|
if (!ResourceManager.TryLoad("fonts/Inter-Regular.ttf", out _font))
|
|
{
|
|
|
|
}
|
|
|
|
if (!ResourceManager.TryLoad("fonts/NotoSansJP-Regular.ttf", out _jpFont))
|
|
{
|
|
|
|
}
|
|
|
|
ResourceManager.TryLoad("icon.png", out _icon);
|
|
ResourceManager.TryLoad("sounds/test_sound_mono.ogg", out _sound);
|
|
|
|
if (!ResourceManager.TryLoad("fire_effect.toml", out _fireEffect))
|
|
{
|
|
throw new Exception("Failed to load emitter settings!");
|
|
}
|
|
}
|
|
|
|
protected override void Ready()
|
|
{
|
|
Input.AddInputMapping("reload", new IInputAction[] { new KeyInputAction(KeyboardKey.R) });
|
|
_emitterId = _particleSystem.CreateEmitter(Renderer.WindowSize / 2, _fireEffect);
|
|
|
|
// _fillContainer.AddChild(_container);
|
|
// _marginContainer.AddChild(_container);
|
|
|
|
_uiSystem.AddElement(_container);
|
|
}
|
|
|
|
|
|
protected override void Update(double deltaTime)
|
|
{
|
|
if (Input.IsActionPressed("reload"))
|
|
{
|
|
ResourceManager.Reload();
|
|
_particleSystem!.RestartEmitter(_emitterId);
|
|
}
|
|
|
|
if (Input.IsActionPressed("accept"))
|
|
{
|
|
_container.AddChild(new Label("こんにちは世界!", _jpFont));
|
|
}
|
|
|
|
if (Input.IsActionPressed("cancel") && _container.Children.Count != 0)
|
|
{
|
|
var lastChild = _container.Children.Last();
|
|
_container.RemoveChild(lastChild);
|
|
}
|
|
}
|
|
|
|
protected override void Render(double deltaTime)
|
|
{
|
|
Renderer.ClearBackground(Color.Black);
|
|
|
|
// foreach (var emitter in _particleSystem!.Emitters)
|
|
// {
|
|
// DrawEmitter(emitter);
|
|
// }
|
|
|
|
Renderer.ResetTransform();
|
|
_uiSystem.Render(Renderer);
|
|
}
|
|
|
|
private void DrawEmitter(ParticleEmitter emitter)
|
|
{
|
|
Renderer.BeginBlended(BlendMode.BlendAlpha);
|
|
|
|
var maxParticles = emitter.Settings.MaxParticles;
|
|
var particleSize = new Vector2(16.0f, 16.0f);
|
|
var pivot = particleSize / 2;
|
|
|
|
for (int i = maxParticles - 1; i >= 0; i--)
|
|
{
|
|
var particle = emitter.GetParticle(i);
|
|
|
|
Renderer.SetTransform(particle.Position, pivot, particle.Rotation);
|
|
Renderer.DrawRectangle(particleSize * particle.Scale, particle.Color);
|
|
}
|
|
|
|
Renderer.EndBlended();
|
|
}
|
|
|
|
[NotNull] private ParticleSystem _particleSystem;
|
|
[NotNull] private UISystem _uiSystem;
|
|
private int _emitterId;
|
|
private ResourceRef<ParticleEmitterSettingsResource> _fireEffect;
|
|
private ResourceRef<Font> _font;
|
|
private ResourceRef<Font> _jpFont;
|
|
private ResourceRef<Sound> _sound;
|
|
private ResourceRef<Texture2d> _icon;
|
|
|
|
private FlexContainer _container = new(minimumSize: new Rect(256.0f, 256.0f), new())
|
|
{
|
|
Anchor = Anchor.Center,
|
|
Direction = FlexDirection.Column,
|
|
Justify = JustifyContent.Start,
|
|
Align = AlignItems.Center,
|
|
Wrap = true,
|
|
Gap = 8.0f
|
|
};
|
|
|
|
[NotNull] private Label _label;
|
|
|
|
private FillContainer _fillContainer = new();
|
|
private MarginContainer _marginContainer = new(new Margin(32.0f))
|
|
{
|
|
};
|
|
// private HorizontalContainer _container = new(new Rect(128.0f, 64.0f), new(), 16)
|
|
// {
|
|
// ConfineToContents = true,
|
|
// };
|
|
} |