1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-25 22:18:34 +01:00

fixed some panel issues

This commit is contained in:
Ellpeck 2019-11-02 14:21:42 +01:00
parent 3723c3ec97
commit cb7abbbbef
2 changed files with 29 additions and 30 deletions

View file

@ -82,7 +82,8 @@ namespace MLEM.Ui.Elements {
if (this.renderTarget == null || targetArea.Width != this.renderTarget.Width || targetArea.Height != this.renderTarget.Height) {
if (this.renderTarget != null)
this.renderTarget.Dispose();
this.renderTarget = new RenderTarget2D(this.System.GraphicsDevice, targetArea.Width, targetArea.Height);
var empty = targetArea.Width <= 0 || targetArea.Height <= 0;
this.renderTarget = empty ? null : new RenderTarget2D(this.System.GraphicsDevice, targetArea.Width, targetArea.Height);
}
}
}
@ -97,6 +98,7 @@ namespace MLEM.Ui.Elements {
}
public override void Update(GameTime time) {
base.Update(time);
if (this.relevantChildrenDirty) {
this.relevantChildrenDirty = false;
@ -115,7 +117,6 @@ namespace MLEM.Ui.Elements {
}
}
}
base.Update(time);
}
protected override List<Element> GetRelevantChildren() {

View file

@ -1,6 +1,9 @@
using System;
using System.Collections.Generic;
using Coroutine;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using MLEM.Cameras;
using MLEM.Extended.Extensions;
using MLEM.Extended.Tiled;
@ -16,11 +19,6 @@ using MonoGame.Extended.Tiled;
namespace Sandbox {
public class GameImpl : MlemGame {
private Camera camera;
private TiledMap map;
private IndividualTiledMapRenderer mapRenderer;
private ProgressBar progress;
public GameImpl() {
this.IsMouseVisible = true;
}
@ -28,15 +26,6 @@ namespace Sandbox {
protected override void LoadContent() {
base.LoadContent();
this.map = LoadContent<TiledMap>("Tiled/Map");
this.mapRenderer = new IndividualTiledMapRenderer(this.map);
this.camera = new Camera(this.GraphicsDevice) {
AutoScaleWithScreen = true,
Scale = 2,
LookingPosition = new Vector2(25, 25) * this.map.GetTileSize()
};
var tex = LoadContent<Texture2D>("Textures/Test");
this.UiSystem.Style = new UntexturedStyle(this.SpriteBatch) {
Font = new GenericSpriteFont(LoadContent<SpriteFont>("Fonts/TestFont")),
@ -48,27 +37,36 @@ namespace Sandbox {
this.UiSystem.AutoScaleWithScreen = true;
this.UiSystem.GlobalScale = 5;
var root = new Panel(Anchor.Center, new Vector2(50, 50), Vector2.Zero);
this.UiSystem.Add("Root", root);
var group = root.AddChild(new CustomDrawGroup(Anchor.AutoLeft, new Vector2(1, 10)));
group.AddChild(new Button(Anchor.AutoLeft, Vector2.One, "Test text"));
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);
this.progress = new ProgressBar(Anchor.Center, new Vector2(0.8F, 0.5F), Direction2.Down, 1);
this.progress.Texture.Set(new NinePatch(new TextureRegion(tex, 0, 8, 24, 24), 8));
this.progress.ProgressTexture.Set(new NinePatch(new TextureRegion(tex, 24, 8, 16, 16), 4));
this.UiSystem.Add("Progress", this.progress);
for (var i = 0; i < 100; i++) {
screen.AddChild(new Button(Anchor.AutoLeft, new Vector2(1, 10), i.ToString()));
}
}
protected override void Update(GameTime gameTime) {
base.Update(gameTime);
this.progress.CurrentValue = (float) (Math.Sin(gameTime.TotalGameTime.TotalSeconds / 2) + 1) / 2;
private static IEnumerator<Wait> PlayAnimation(Panel screen) {
var show = screen.IsHidden;
screen.IsHidden = false;
var time = 0;
const float total = 200;
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;
}
protected override void DoDraw(GameTime gameTime) {
this.GraphicsDevice.Clear(Color.Black);
this.SpriteBatch.Begin(SpriteSortMode.Deferred, null, SamplerState.PointClamp, null, null, null, this.camera.ViewMatrix);
this.mapRenderer.Draw(this.SpriteBatch, this.camera.GetVisibleRectangle());
this.SpriteBatch.End();
base.DoDraw(gameTime);
}