From e00b345a812e632beba9b4217b1233480028a55d Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Fri, 5 Jun 2020 20:49:42 +0200 Subject: [PATCH] added attraction removal --- .../Content/Localization/Localization.json | 1 + TouchyTickets/ParkMap.cs | 30 +++++++++++++++++++ TouchyTickets/Ui.cs | 20 ++++++++++--- 3 files changed, 47 insertions(+), 4 deletions(-) diff --git a/TouchyTickets/Content/Localization/Localization.json b/TouchyTickets/Content/Localization/Localization.json index 64f9b6d..2fe02f7 100644 --- a/TouchyTickets/Content/Localization/Localization.json +++ b/TouchyTickets/Content/Localization/Localization.json @@ -1,6 +1,7 @@ { "Back": "Back", "Place": "Place", + "Remove": "Remove", "EarnStar": "Earn ", "ReallyEarnStar": "Cashing in your now would earn you {0}. It will also remove all placed attractions and reset your . Are you sure?", "Yes": "Yes", diff --git a/TouchyTickets/ParkMap.cs b/TouchyTickets/ParkMap.cs index 57b2f1d..e6a0ebc 100644 --- a/TouchyTickets/ParkMap.cs +++ b/TouchyTickets/ParkMap.cs @@ -30,6 +30,7 @@ namespace TouchyTickets { public float TicketsPerSecond { get; private set; } public Attraction PlacingAttraction; public Point PlacingPosition; + public Point? SelectedPosition; private bool draggingAttraction; public ParkMap(int width, int height) { @@ -107,6 +108,18 @@ namespace TouchyTickets { this.draggingAttraction = this.PlacingAttraction.Type.GetCoveredTiles() .Any(p => this.PlacingPosition + p == offset); } + } else { + // we're not placing an attraction, so we're in remove and move mode + if (MlemGame.Input.GetGesture(GestureType.Tap, out var tap)) { + var pos = (camera.ToWorldPos(tap.Position) / Attraction.TileSize).ToPoint(); + var attraction = this.GetAttractionAt(pos); + if (attraction != null) { + // actually select the top left for easy usage later + this.SelectedPosition = this.attractions.First(kv => kv.Item2 == attraction).Item1; + } else { + this.SelectedPosition = null; + } + } } camera.ConstrainWorldBounds(new Vector2(-AdditionalRadius) * Attraction.TileSize, new Vector2(this.Width + AdditionalRadius, this.Height + AdditionalRadius) * Attraction.TileSize); } @@ -133,6 +146,13 @@ namespace TouchyTickets { } } } + // selected attraction + if (this.SelectedPosition != null) { + var selected = this.SelectedPosition.Value; + var attr = this.GetAttractionAt(selected); + foreach (var pos in attr.Type.GetCoveredTiles()) + batch.Draw(batch.GetBlankTexture(), new RectangleF(position + (selected.ToVector2() + pos.ToVector2()) * tileSize, tileSize), Color.Black * 0.15F * alpha); + } // draw attractions foreach (var (pos, attraction) in this.attractions) batch.Draw(attraction.Type.TextureRegion, position + pos.ToVector2() * tileSize, Color.White * alpha, 0, Vector2.Zero, scale, SpriteEffects.None, 0); @@ -159,6 +179,16 @@ namespace TouchyTickets { this.attractions.Add((position, attraction)); } + public Attraction Remove(Point position) { + var attraction = this.GetAttractionAt(position); + if (attraction != null) { + foreach (var (x, y) in attraction.Type.GetCoveredTiles()) + this.attractionGrid[position.X + x, position.Y + y] = null; + this.attractions.Remove((position, attraction)); + } + return attraction; + } + public Attraction GetAttractionAt(Point position) { if (position.X < 0 || position.Y < 0 || position.X >= this.Width || position.Y >= this.Height) return null; diff --git a/TouchyTickets/Ui.cs b/TouchyTickets/Ui.cs index d2ade83..883ff7d 100644 --- a/TouchyTickets/Ui.cs +++ b/TouchyTickets/Ui.cs @@ -110,12 +110,22 @@ namespace TouchyTickets { map.Draw(time, batch, pos, scale, alpha, false, new RectangleF(Vector2.Zero, mapSize * scale)); }, OnPressed = e => { - var backUi = new Group(Anchor.BottomLeft, new Vector2(1)); - backUi.AddChild(new Button(Anchor.AutoInlineIgnoreOverflow, new Vector2(1, 30), Localization.Get("Back")) { + var map = GameImpl.Instance.Map; + var infoUi = new Group(Anchor.BottomLeft, new Vector2(1)); + infoUi.AddChild(new Button(Anchor.AutoInlineIgnoreOverflow, new Vector2(0.5F, 30), Localization.Get("Back")) { OnPressed = e2 => this.FadeUi(false, () => this.uiSystem.Remove(e2.Root.Name)) }); + infoUi.AddChild(new Button(Anchor.AutoInlineIgnoreOverflow, new Vector2(0.5F, 30), Localization.Get("Remove")) { + OnPressed = e2 => { + if (map.SelectedPosition == null) + return; + map.Remove(map.SelectedPosition.Value); + map.SelectedPosition = null; + }, + OnUpdated = (e2, time) => ((Button) e2).IsDisabled = map.SelectedPosition == null + }); // we want this to render below the main ui while it fades away - this.uiSystem.Add("MapViewBack", backUi).Priority = -100; + this.uiSystem.Add("MapViewInfo", infoUi).Priority = -100; this.FadeUi(true); } @@ -328,8 +338,10 @@ namespace TouchyTickets { this.currentUi.IsHidden = fadeOut; // disable horizontal and vertical drag on map view to allow free drag to take priority InputHandler.SetGesturesEnabled(!fadeOut, GestureType.HorizontalDrag, GestureType.VerticalDrag); - if (!fadeOut) + if (!fadeOut) { GameImpl.Instance.Map.PlacingAttraction = null; + GameImpl.Instance.Map.SelectedPosition = null; + } after?.Invoke(); }