68 lines
No EOL
2.8 KiB
C#
68 lines
No EOL
2.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Numerics;
|
|
using Coroutine;
|
|
using Microsoft.Xna.Framework;
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
using MLEM.Font;
|
|
using MLEM.Startup;
|
|
using MLEM.Textures;
|
|
using MLEM.Ui;
|
|
using MLEM.Ui.Elements;
|
|
|
|
namespace ThemeParkClicker {
|
|
public class Ui {
|
|
|
|
public static readonly UniformTextureAtlas Texture = new UniformTextureAtlas(MlemGame.LoadContent<Texture2D>("Textures/Ui"), 16, 16);
|
|
|
|
public Ui(UiSystem uiSystem) {
|
|
uiSystem.GlobalScale = 4;
|
|
uiSystem.AutoScaleWithScreen = true;
|
|
uiSystem.AutoScaleReferenceSize = new Point(720, 1280);
|
|
uiSystem.Style.Font = new GenericSpriteFont(MlemGame.LoadContent<SpriteFont>("Fonts/Regular"));
|
|
uiSystem.Style.TextScale = 0.1F;
|
|
|
|
// ticket store ui
|
|
var rainingTickets = new List<RainingTicket>();
|
|
Group ticketStoreUi = new Group(Anchor.TopLeft, Vector2.One, false) {
|
|
OnUpdated = (e, time) => {
|
|
for (var i = rainingTickets.Count - 1; i >= 0; i--) {
|
|
if (rainingTickets[i].Update())
|
|
rainingTickets.RemoveAt(i);
|
|
}
|
|
while (rainingTickets.Count < BigInteger.Min(GameImpl.Instance.Tickets / 100, 500))
|
|
rainingTickets.Add(new RainingTicket());
|
|
},
|
|
OnDrawn = (e, time, batch, alpha) => {
|
|
foreach (var ticket in rainingTickets)
|
|
ticket.Draw(batch, e.DisplayArea.Size, e.Scale);
|
|
}
|
|
};
|
|
ticketStoreUi.AddChild(new Paragraph(Anchor.AutoCenter, 1, p => GameImpl.Instance.DisplayTicketCount(), true) {
|
|
TextScale = 0.3F
|
|
});
|
|
var storeGroup = ticketStoreUi.AddChild(new CustomDrawGroup(Anchor.AutoLeft, Vector2.One));
|
|
storeGroup.AddChild(new Image(Anchor.TopLeft, Vector2.One, Texture[0, 0, 2, 3]) {
|
|
OnPressed = e => {
|
|
GameImpl.Instance.Tickets++;
|
|
CoroutineHandler.Start(WobbleElement(storeGroup));
|
|
},
|
|
CanBeSelected = true,
|
|
CanBeMoused = true
|
|
});
|
|
ticketStoreUi.OnAreaUpdated += e => storeGroup.Size = new Vector2(e.DisplayArea.Width / e.Scale);
|
|
uiSystem.Add("TicketStore", ticketStoreUi);
|
|
}
|
|
|
|
private static IEnumerator<IWait> WobbleElement(CustomDrawGroup element, float intensity = 0.01F) {
|
|
var sin = 0F;
|
|
while (sin < MathHelper.Pi) {
|
|
element.ScaleOrigin(1 + (float) Math.Sin(sin) * intensity);
|
|
sin += 0.2F;
|
|
yield return new WaitEvent(CoroutineEvents.Update);
|
|
}
|
|
element.Transform = Matrix.Identity;
|
|
}
|
|
|
|
}
|
|
} |