added attraction removal
This commit is contained in:
parent
38f8537408
commit
e00b345a81
3 changed files with 47 additions and 4 deletions
|
@ -1,6 +1,7 @@
|
||||||
{
|
{
|
||||||
"Back": "Back",
|
"Back": "Back",
|
||||||
"Place": "Place",
|
"Place": "Place",
|
||||||
|
"Remove": "Remove",
|
||||||
"EarnStar": "Earn <i star>",
|
"EarnStar": "Earn <i star>",
|
||||||
"ReallyEarnStar": "Cashing in your <i ticket> now would earn you {0}<i star>. It will also remove all placed attractions and reset your <i ticket>. Are you sure?",
|
"ReallyEarnStar": "Cashing in your <i ticket> now would earn you {0}<i star>. It will also remove all placed attractions and reset your <i ticket>. Are you sure?",
|
||||||
"Yes": "Yes",
|
"Yes": "Yes",
|
||||||
|
|
|
@ -30,6 +30,7 @@ namespace TouchyTickets {
|
||||||
public float TicketsPerSecond { get; private set; }
|
public float TicketsPerSecond { get; private set; }
|
||||||
public Attraction PlacingAttraction;
|
public Attraction PlacingAttraction;
|
||||||
public Point PlacingPosition;
|
public Point PlacingPosition;
|
||||||
|
public Point? SelectedPosition;
|
||||||
private bool draggingAttraction;
|
private bool draggingAttraction;
|
||||||
|
|
||||||
public ParkMap(int width, int height) {
|
public ParkMap(int width, int height) {
|
||||||
|
@ -107,6 +108,18 @@ namespace TouchyTickets {
|
||||||
this.draggingAttraction = this.PlacingAttraction.Type.GetCoveredTiles()
|
this.draggingAttraction = this.PlacingAttraction.Type.GetCoveredTiles()
|
||||||
.Any(p => this.PlacingPosition + p == offset);
|
.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);
|
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
|
// draw attractions
|
||||||
foreach (var (pos, attraction) in this.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);
|
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));
|
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) {
|
public Attraction GetAttractionAt(Point position) {
|
||||||
if (position.X < 0 || position.Y < 0 || position.X >= this.Width || position.Y >= this.Height)
|
if (position.X < 0 || position.Y < 0 || position.X >= this.Width || position.Y >= this.Height)
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -110,12 +110,22 @@ namespace TouchyTickets {
|
||||||
map.Draw(time, batch, pos, scale, alpha, false, new RectangleF(Vector2.Zero, mapSize * scale));
|
map.Draw(time, batch, pos, scale, alpha, false, new RectangleF(Vector2.Zero, mapSize * scale));
|
||||||
},
|
},
|
||||||
OnPressed = e => {
|
OnPressed = e => {
|
||||||
var backUi = new Group(Anchor.BottomLeft, new Vector2(1));
|
var map = GameImpl.Instance.Map;
|
||||||
backUi.AddChild(new Button(Anchor.AutoInlineIgnoreOverflow, new Vector2(1, 30), Localization.Get("Back")) {
|
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))
|
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
|
// 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);
|
this.FadeUi(true);
|
||||||
}
|
}
|
||||||
|
@ -328,8 +338,10 @@ namespace TouchyTickets {
|
||||||
this.currentUi.IsHidden = fadeOut;
|
this.currentUi.IsHidden = fadeOut;
|
||||||
// disable horizontal and vertical drag on map view to allow free drag to take priority
|
// disable horizontal and vertical drag on map view to allow free drag to take priority
|
||||||
InputHandler.SetGesturesEnabled(!fadeOut, GestureType.HorizontalDrag, GestureType.VerticalDrag);
|
InputHandler.SetGesturesEnabled(!fadeOut, GestureType.HorizontalDrag, GestureType.VerticalDrag);
|
||||||
if (!fadeOut)
|
if (!fadeOut) {
|
||||||
GameImpl.Instance.Map.PlacingAttraction = null;
|
GameImpl.Instance.Map.PlacingAttraction = null;
|
||||||
|
GameImpl.Instance.Map.SelectedPosition = null;
|
||||||
|
}
|
||||||
after?.Invoke();
|
after?.Invoke();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue