1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-04 22:49:08 +01:00
MLEM/Sandbox/GameImpl.cs

74 lines
2.5 KiB
C#
Raw Normal View History

using System;
2019-11-02 14:21:42 +01:00
using System.Collections.Generic;
using Coroutine;
2019-09-19 20:23:18 +02:00
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
2019-11-02 14:21:42 +01:00
using Microsoft.Xna.Framework.Input;
2019-09-19 20:23:18 +02:00
using MLEM.Cameras;
using MLEM.Extended.Extensions;
using MLEM.Extended.Tiled;
using MLEM.Font;
using MLEM.Misc;
2019-09-19 20:23:18 +02:00
using MLEM.Startup;
using MLEM.Textures;
using MLEM.Ui;
using MLEM.Ui.Elements;
using MLEM.Ui.Style;
2019-09-19 20:23:18 +02:00
using MonoGame.Extended.Tiled;
namespace Sandbox {
public class GameImpl : MlemGame {
public GameImpl() {
this.IsMouseVisible = true;
}
protected override void LoadContent() {
base.LoadContent();
var tex = LoadContent<Texture2D>("Textures/Test");
this.UiSystem.Style = new UntexturedStyle(this.SpriteBatch) {
Font = new GenericSpriteFont(LoadContent<SpriteFont>("Fonts/TestFont")),
TextScale = 0.1F,
PanelTexture = new NinePatch(new TextureRegion(tex, 0, 8, 24, 24), 8),
ButtonTexture = new NinePatch(new TextureRegion(tex, 24, 8, 16, 16), 4)
};
this.UiSystem.AutoScaleReferenceSize = new Point(1280, 720);
this.UiSystem.AutoScaleWithScreen = true;
this.UiSystem.GlobalScale = 5;
2019-11-02 14:21:42 +01:00
var screen = new Panel(Anchor.Center, new Vector2(200, 100), Vector2.Zero, false, true, new Point(5, 10));
screen.IsHidden = false;
screen.OnUpdated += (element, time) => {
if (this.InputHandler.IsKeyPressed(Keys.Escape))
CoroutineHandler.Start(PlayAnimation(screen));
};
this.UiSystem.Add("Screen", screen);
2019-11-02 14:21:42 +01:00
for (var i = 0; i < 100; i++) {
screen.AddChild(new Button(Anchor.AutoLeft, new Vector2(1, 10), i.ToString()));
}
}
2019-11-02 14:21:42 +01:00
private static IEnumerator<Wait> PlayAnimation(Panel screen) {
var show = screen.IsHidden;
screen.IsHidden = false;
var time = 0;
const float total = 20;
2019-11-02 14:21:42 +01:00
while (time <= total) {
yield return new WaitEvent(CoroutineEvents.Update);
var percent = show ? time / total : 1 - time / total;
screen.Root.Scale = percent;
time++;
}
if (!show)
screen.IsHidden = true;
2019-09-19 20:23:18 +02:00
}
protected override void DoDraw(GameTime gameTime) {
this.GraphicsDevice.Clear(Color.Black);
base.DoDraw(gameTime);
}
}
}