bool IsDummyChange(MouseDownChanges changes) { return(changes.Positions == null); }
public override void ProcessEvent(TileSelectionEvent e) { this.currSelectedTileType = e.TileType; this.currChanges = new MouseDownChanges(this.currSelectedTileType.Value); }
void ProcessInput() { // TODO rectangle selecting multiple tiles // need to check if mouse click collides with any UI if (InputManager.Instance.CanAcceptInput(TentativeFarmGrid.inputPriority)) { this.tileHighlighter.HighlightTileAtMouse = true; if (Input.LeftMouseButtonDown) { var pos = this.playerCamera.MouseToTilePosition(); if (!this.currChanges.Positions.ContainsKey(pos)) { var x = (int)pos.X; var y = (int)pos.Y; var originalTileType = this.TileGrid[x, y] != null ? this.TileGrid[x, y].Tile.TileType : FarmDefaultTiler.DefaultTileType; if (this.currSelectedTileType.Value == TileType.Destruct) { if (this.RemoveTile(x, y)) { this.AddChange(x, y, originalTileType); } } else if (this.currSelectedTileType.Value == TileType.Upgrade) { if (this.UpgradeTile(x, y)) { this.AddChange(x, y, originalTileType); } } else if (this.currSelectedTileType.Value == TileType.Reset) { if (this.ResetTile(x, y)) { this.AddChange(x, y, originalTileType); } } // else selected an actual (non utility) tile // add new tile only if no existing tile or new tile is of different type // and tile is placeable // TODO better way to determine if existing tentative tile should be directly replaceable else { var tmpTile = Tile.CreateTile(this.currSelectedTileType.Value, x, y, this); if ((this.farm.GetTile(x, y) == null || !Tile.AreSameBaseTileType(Tile.GetFutureTileType(this.farm.GetTile(x, y)), this.currSelectedTileType.Value)) && (this.TileGrid[x, y] == null || !Tile.AreSameBaseTileType(this.TileGrid[x, y].Tile.TileType, this.currSelectedTileType.Value)) && tmpTile.IsPlaceable() && this.playerState.Money >= tmpTile.Cost) { this.AddTile(new WeakTile(this.currSelectedTileType.Value, x, y, this)); this.AddChange(x, y, originalTileType); } } } } } else { this.tileHighlighter.HighlightTileAtMouse = false; } // add change to log when left click released, wherever it occurs if (Input.LeftMouseButtonReleased && !this.currChanges.IsEmpty()) { // remove all nodes after this while (this.currChangesNode.Next != null) { this.changeLog.Remove(this.currChangesNode.Next); } this.currChangesNode = this.changeLog.AddLast(this.currChanges); this.currChanges = new MouseDownChanges(this.currSelectedTileType.Value); } // clear selected tile regardless of where right click occurs if (Input.RightMouseButtonPressed) { this.currSelectedTileType = null; this.tileHighlighter.HighlightTileAtMouse = false; } }