1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-06-06 14:53:37 +02:00
MLEM/Tests/GameImpl.cs

87 lines
3.5 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using Coroutine;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using MLEM.Extended.Extensions;
2019-08-09 19:28:48 +02:00
using MLEM.Font;
using MLEM.Input;
2019-08-07 21:26:16 +02:00
using MLEM.Startup;
using MLEM.Textures;
2019-08-09 18:26:28 +02:00
using MLEM.Ui;
using MLEM.Ui.Elements;
2019-08-10 21:37:10 +02:00
using MLEM.Ui.Style;
2019-08-07 21:26:16 +02:00
namespace Tests {
public class GameImpl : MlemGame {
private Texture2D testTexture;
private NinePatch testPatch;
2019-08-09 18:26:28 +02:00
public GameImpl() {
this.IsMouseVisible = true;
}
protected override void LoadContent() {
this.testTexture = LoadContent<Texture2D>("Textures/Test");
this.testPatch = new NinePatch(new TextureRegion(this.testTexture, 0, 8, 24, 24), 8);
2019-08-10 21:37:10 +02:00
base.LoadContent();
2019-08-09 18:26:28 +02:00
2019-08-10 21:37:10 +02:00
var style = new UiStyle {
Font = new GenericSpriteFont(LoadContent<SpriteFont>("Fonts/TestFont")),
TextScale = 0.8F,
2019-08-10 21:37:10 +02:00
PanelTexture = this.testPatch,
ButtonTexture = new NinePatch(new TextureRegion(this.testTexture, 24, 8, 16, 16), 4),
TextFieldTexture = new NinePatch(new TextureRegion(this.testTexture, 24, 8, 16, 16), 4),
ButtonHoveredColor = Color.LightGray,
TextFieldHoveredColor = Color.LightGray
};
var untexturedStyle = this.UiSystem.Style;
this.UiSystem.Style = style;
this.UiSystem.GlobalScale = 1.25F;
2019-08-09 18:26:28 +02:00
2019-08-11 18:50:39 +02:00
var root = new Panel(Anchor.BottomLeft, new Vector2(300, 450), Point.Zero, true);
2019-08-10 21:37:10 +02:00
this.UiSystem.Add("Test", root);
2019-08-10 18:41:56 +02:00
root.AddChild(new Paragraph(Anchor.AutoLeft, 1, "This is a test text that is hopefully long enough to cover at least a few lines, otherwise it would be very sad."));
2019-08-11 18:50:39 +02:00
var image = root.AddChild(new Image(Anchor.AutoCenter, new Vector2(70, 70), new TextureRegion(this.testTexture, 0, 0, 8, 8)) {IsHidden = true, Padding = new Point(10)});
root.AddChild(new Button(Anchor.AutoCenter, new Vector2(1, 40), "Test Button") {
OnClicked = (element, button) => {
if (button == MouseButton.Left)
2019-08-09 22:23:16 +02:00
image.IsHidden = !image.IsHidden;
}
});
root.AddChild(new Button(Anchor.AutoCenter, new Vector2(1, 40), "Change Style") {
OnClicked = (element, button) => {
2019-08-10 21:37:10 +02:00
if (button == MouseButton.Left)
this.UiSystem.Style = this.UiSystem.Style is UntexturedStyle ? style : untexturedStyle;
},
HasCustomStyle = true,
Texture = this.testPatch,
HoveredColor = Color.LightGray
});
root.AddChild(new TextField(Anchor.AutoLeft, new Vector2(1, 40)));
root.AddChild(new VerticalSpace(3));
root.AddChild(new Button(Anchor.AutoLeft, new Vector2(40), "+") {
OnClicked = (element, button) => {
if (element.Root.Scale < 2)
element.Root.Scale += 0.1F;
}
});
root.AddChild(new Button(Anchor.AutoInline, new Vector2(40), "-") {
OnClicked = (element, button) => {
if (element.Root.Scale > 0.5F)
element.Root.Scale -= 0.1F;
}
});
}
2019-08-07 21:26:16 +02:00
protected override void Draw(GameTime gameTime) {
this.GraphicsDevice.Clear(Color.Black);
2019-08-09 23:43:50 +02:00
base.Draw(gameTime);
}
2019-08-07 21:26:16 +02:00
}
}