mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-22 20:58:34 +01:00
fixed some panel issues
This commit is contained in:
parent
3723c3ec97
commit
cb7abbbbef
2 changed files with 29 additions and 30 deletions
|
@ -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 || targetArea.Width != this.renderTarget.Width || targetArea.Height != this.renderTarget.Height) {
|
||||||
if (this.renderTarget != null)
|
if (this.renderTarget != null)
|
||||||
this.renderTarget.Dispose();
|
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) {
|
public override void Update(GameTime time) {
|
||||||
|
base.Update(time);
|
||||||
if (this.relevantChildrenDirty) {
|
if (this.relevantChildrenDirty) {
|
||||||
this.relevantChildrenDirty = false;
|
this.relevantChildrenDirty = false;
|
||||||
|
|
||||||
|
@ -115,7 +117,6 @@ namespace MLEM.Ui.Elements {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
base.Update(time);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override List<Element> GetRelevantChildren() {
|
protected override List<Element> GetRelevantChildren() {
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Coroutine;
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
using Microsoft.Xna.Framework.Input;
|
||||||
using MLEM.Cameras;
|
using MLEM.Cameras;
|
||||||
using MLEM.Extended.Extensions;
|
using MLEM.Extended.Extensions;
|
||||||
using MLEM.Extended.Tiled;
|
using MLEM.Extended.Tiled;
|
||||||
|
@ -16,11 +19,6 @@ using MonoGame.Extended.Tiled;
|
||||||
namespace Sandbox {
|
namespace Sandbox {
|
||||||
public class GameImpl : MlemGame {
|
public class GameImpl : MlemGame {
|
||||||
|
|
||||||
private Camera camera;
|
|
||||||
private TiledMap map;
|
|
||||||
private IndividualTiledMapRenderer mapRenderer;
|
|
||||||
private ProgressBar progress;
|
|
||||||
|
|
||||||
public GameImpl() {
|
public GameImpl() {
|
||||||
this.IsMouseVisible = true;
|
this.IsMouseVisible = true;
|
||||||
}
|
}
|
||||||
|
@ -28,15 +26,6 @@ namespace Sandbox {
|
||||||
protected override void LoadContent() {
|
protected override void LoadContent() {
|
||||||
base.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");
|
var tex = LoadContent<Texture2D>("Textures/Test");
|
||||||
this.UiSystem.Style = new UntexturedStyle(this.SpriteBatch) {
|
this.UiSystem.Style = new UntexturedStyle(this.SpriteBatch) {
|
||||||
Font = new GenericSpriteFont(LoadContent<SpriteFont>("Fonts/TestFont")),
|
Font = new GenericSpriteFont(LoadContent<SpriteFont>("Fonts/TestFont")),
|
||||||
|
@ -48,27 +37,36 @@ namespace Sandbox {
|
||||||
this.UiSystem.AutoScaleWithScreen = true;
|
this.UiSystem.AutoScaleWithScreen = true;
|
||||||
this.UiSystem.GlobalScale = 5;
|
this.UiSystem.GlobalScale = 5;
|
||||||
|
|
||||||
var root = new Panel(Anchor.Center, new Vector2(50, 50), Vector2.Zero);
|
var screen = new Panel(Anchor.Center, new Vector2(200, 100), Vector2.Zero, false, true, new Point(5, 10));
|
||||||
this.UiSystem.Add("Root", root);
|
screen.IsHidden = false;
|
||||||
var group = root.AddChild(new CustomDrawGroup(Anchor.AutoLeft, new Vector2(1, 10)));
|
screen.OnUpdated += (element, time) => {
|
||||||
group.AddChild(new Button(Anchor.AutoLeft, Vector2.One, "Test text"));
|
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);
|
for (var i = 0; i < 100; i++) {
|
||||||
this.progress.Texture.Set(new NinePatch(new TextureRegion(tex, 0, 8, 24, 24), 8));
|
screen.AddChild(new Button(Anchor.AutoLeft, new Vector2(1, 10), i.ToString()));
|
||||||
this.progress.ProgressTexture.Set(new NinePatch(new TextureRegion(tex, 24, 8, 16, 16), 4));
|
}
|
||||||
this.UiSystem.Add("Progress", this.progress);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Update(GameTime gameTime) {
|
private static IEnumerator<Wait> PlayAnimation(Panel screen) {
|
||||||
base.Update(gameTime);
|
var show = screen.IsHidden;
|
||||||
this.progress.CurrentValue = (float) (Math.Sin(gameTime.TotalGameTime.TotalSeconds / 2) + 1) / 2;
|
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) {
|
protected override void DoDraw(GameTime gameTime) {
|
||||||
this.GraphicsDevice.Clear(Color.Black);
|
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);
|
base.DoDraw(gameTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue