public double this[int row, int column] { get { if (row < 0 && row >= Size) { throw new ArgumentOutOfRangeException(); } if (column < 0 && column >= Size) { throw new ArgumentOutOfRangeException(); } return(data[row, column]); } set { if (row < 0 && row >= Size) { throw new ArgumentOutOfRangeException(); } if (column < 0 && column >= Size) { throw new ArgumentOutOfRangeException(); } data[row, column] = value; CellChanged?.Invoke(row, column, value); } }
int RemoveResource(string resourceType, CPos cell, int amount = 1) { if (!Content.Contains(cell)) { return(0); } var content = Content[cell]; if (content.Type == null || content.Type != resourceType) { return(0); } var oldDensity = content.Density; var density = Math.Max(0, oldDensity - amount); if (density == 0) { Content[cell] = ResourceLayerContents.Empty; Map.CustomTerrain[cell] = byte.MaxValue; --resCells; CellChanged?.Invoke(cell, null); } else { Content[cell] = new ResourceLayerContents(content.Type, density); CellChanged?.Invoke(cell, content.Type); } return(oldDensity - density); }
public ResourceType Harvest(CPos cell) { var c = Content[cell]; if (c.Type == null) { return(null); } if (--c.Density < 0) { Content[cell] = ResourceLayerContents.Empty; world.Map.CustomTerrain[cell] = byte.MaxValue; --resCells; foreach (var rl in resourceLogicLayers) { rl.UpdatePosition(cell, c.Type, 0); } } else { Content[cell] = c; foreach (var rl in resourceLogicLayers) { rl.UpdatePosition(cell, c.Type, c.Density); } } CellChanged?.Invoke(cell, c.Type); return(c.Type); }
void OnMouseMove(int x, int y) { var id = Mouse.HitEntityId; Previous = Current; Current = EntitySystem.EntityFramework.GetEntity(id) as ConstructionPoint; if (Previous != Current) { CellChanged?.Invoke(Current); } if (Current == null) { NoCell?.Invoke(); } else if (!Current.Controller.Occupied && CanSelect()) { EnterUnoccupiedCell?.Invoke(Current); } else { EnterOccupiedCell?.Invoke(Current); } }
protected virtual void OnCellChanged(int i_RowNumber, int i_ColNumber) { if (CellChanged != null) { CellChanged.Invoke(i_RowNumber, i_ColNumber); } }
public void UpdateCell(CPos cell) { var uv = cell.ToMPos(Map); if (!Map.Resources.Contains(uv)) { return; } var tile = Map.Resources[uv]; var t = Tiles[uv]; var newTile = ResourceLayerContents.Empty; var newTerrain = byte.MaxValue; if (Resources.TryGetValue(tile.Type, out var type)) { newTile = new ResourceLayerContents { Type = type, Density = CalculateCellDensity(type, cell) }; newTerrain = Map.Rules.TerrainInfo.GetTerrainIndex(type.Info.TerrainType); } // Nothing has changed if (newTile.Type == t.Type && newTile.Density == t.Density) { return; } UpdateNetWorth(t.Type, t.Density, newTile.Type, newTile.Density); Tiles[uv] = newTile; Map.CustomTerrain[uv] = newTerrain; CellChanged?.Invoke(cell, type); // Neighbouring cell density depends on this cell foreach (var d in CVec.Directions) { var neighbouringCell = cell + d; if (!Tiles.Contains(neighbouringCell)) { continue; } var neighbouringTile = Tiles[neighbouringCell]; var density = CalculateCellDensity(neighbouringTile.Type, neighbouringCell); if (neighbouringTile.Density == density) { continue; } UpdateNetWorth(neighbouringTile.Type, neighbouringTile.Density, neighbouringTile.Type, density); neighbouringTile.Density = density; Tiles[neighbouringCell] = neighbouringTile; CellChanged?.Invoke(neighbouringCell, type); } }
int AddResource(string resourceType, CPos cell, int amount = 1) { if (!Content.Contains(cell)) { return(0); } if (resourceType == null || !info.ResourceTypes.TryGetValue(resourceType, out var resourceInfo)) { return(0); } var content = Content[cell]; if (content.Type == null) { content = CreateResourceCell(resourceType, cell, 0); } if (content.Type != resourceType) { return(0); } var oldDensity = content.Density; var density = Math.Min(resourceInfo.MaxDensity, oldDensity + amount); Content[cell] = new ResourceLayerContents(content.Type, density); CellChanged?.Invoke(cell, content.Type); return(density - oldDensity); }
protected virtual void OnCellChanged(CellChangedEventArgs e) { // check if someone is listening if (CellChanged != null) { // raise the event: CellChanged.Invoke(this, e); } }
public void ChangeCell(Vector cellVector, Cell newCell) { if (!InBounds(cellVector)) { return; } Map[cellVector.X, cellVector.Y] = newCell; CellChanged?.Invoke(cellVector); }
private void SendCellInfo(int column, int row, Element element, ChangeType changeType) { var eventArgs = new CellChangedArgs(); eventArgs.column = column; eventArgs.row = row; eventArgs.changeType = changeType; eventArgs.element = element; CellChanged?.Invoke(eventArgs); }
private void DrawManually(MouseEventArgs e) { var coords = _coordinatesTranslator.FindCell(e.X, e.Y); coords.X--; coords.Y--; if (_painter.TryChangeCell(coords.X, coords.Y, PaintMode)) { CellChanged?.Invoke(coords.X, coords.Y, PaintMode); } }
private void OnCellValueChanged(Cell cell) { Contract.Requires(cell != null); Contract.Requires(!cell.IsEmpty); if (Disabled) { return; } CellChanged?.Invoke(cell); }
public void AddResource(ResourceType t, CPos p, int n) { var cell = Content[p]; if (cell.Type == null) cell = CreateResourceCell(t, p); if (cell.Type != t) return; cell.Density = Math.Min(cell.Type.Info.MaxDensity, cell.Density + n); Content[p] = cell; CellChanged?.Invoke(p, cell.Type); }
public void Destroy(CPos cell) { // Don't break other users of CustomTerrain if there are no resources var c = Content[cell]; if (c.Type == null) return; --resCells; // Clear cell Content[cell] = ResourceLayerContents.Empty; world.Map.CustomTerrain[cell] = byte.MaxValue; CellChanged?.Invoke(cell, c.Type); }
void SudokuBoard_KeyPress(object sender, KeyPressEventArgs e) { if (selected == null) { return; } if (e != null && ((e.KeyChar == 48 && board[selected] != 0) || (e.KeyChar > 48 && e.KeyChar <= 57))) { board[selected].ChangeOriginal(e.KeyChar - 48); Logger.Log("Changed cell", new Cell[] { board[selected] }, board[selected].ToString()); CellChanged?.Invoke(board[selected]); } selected = null; ReDraw(false); }
void SudokuBoard_KeyPress(object sender, KeyPressEventArgs e) { if (selectedCell == null) { return; } if (e != null && ((e.KeyChar == 48 && selectedCell.Value != 0) || (e.KeyChar > 48 && e.KeyChar <= 57))) { selectedCell.ChangeOriginalValue(e.KeyChar - 48); puzzle.LogAction("Changed cell", new Cell[] { selectedCell }, selectedCell.ToString()); CellChanged?.Invoke(selectedCell); } selectedCell = null; ReDraw(false); }
private void SudokuBoard_KeyPress(object sender, KeyPressEventArgs e) { if (_selectedCell == null) { return; } if (e != null && ((e.KeyChar == '0' && _selectedCell.Value != 0) || (e.KeyChar > '0' && e.KeyChar <= '9'))) { _selectedCell.ChangeOriginalValue(e.KeyChar - '0'); _puzzle.LogAction(Puzzle.TechniqueFormat("Changed cell", _selectedCell.ToString()), _selectedCell, (Cell)null); CellChanged?.Invoke(_selectedCell); } _selectedCell = null; ReDraw(false); }
public ResourceType Harvest(CPos cell) { var c = Content[cell]; if (c.Type == null) return null; if (--c.Density < 0) { Content[cell] = ResourceLayerContents.Empty; world.Map.CustomTerrain[cell] = byte.MaxValue; --resCells; } else Content[cell] = c; CellChanged?.Invoke(cell, c.Type); return c.Type; }
void ClearResources(CPos cell) { if (!Content.Contains(cell)) { return; } // Don't break other users of CustomTerrain if there are no resources var content = Content[cell]; if (content.Type == null) { return; } Content[cell] = ResourceLayerContents.Empty; Map.CustomTerrain[cell] = byte.MaxValue; --resCells; CellChanged?.Invoke(cell, null); }
public Area(Cell[,] map, Vector playerLocation) { PlayerLocation = playerLocation; Map = map; foreach (var cell in map) { if (cell?.Creature != null) { cell.Creature.StateChanged += (Vector vector) => { if (cell.Creature.Health <= 0 && cell.Creature.IsMortal) { ChangeCell(vector, cell.RemoveCreature()); } CellChanged?.Invoke(vector); } } } ; }
public void Destroy(CPos cell) { // Don't break other users of CustomTerrain if there are no resources var c = Content[cell]; if (c.Type == null) { return; } --resCells; foreach (var rl in resourceLogicLayers) { rl.UpdatePosition(cell, Content[cell].Type, 0); } // Clear cell Content[cell] = ResourceLayerContents.Empty; world.Map.CustomTerrain[cell] = byte.MaxValue; CellChanged?.Invoke(cell, c.Type); }
public void UpdateCell(CPos cell) { var uv = cell.ToMPos(Map); if (!Map.Resources.Contains(uv)) { return; } var tile = Map.Resources[uv]; var t = Tiles[uv]; var newTile = ResourceLayerContents.Empty; var newTerrain = byte.MaxValue; if (Resources.TryGetValue(tile.Type, out ResourceType type)) { newTile = new ResourceLayerContents { Type = type, Density = tile.Index }; newTerrain = Tileset.GetTerrainIndex(type.Info.TerrainType); } // Nothing has changed if (newTile.Type == t.Type && newTile.Density == t.Density) { return; } UpdateNetWorth(t.Type, t.Density, newTile.Type, newTile.Density); Tiles[uv] = newTile; Map.CustomTerrain[uv] = newTerrain; CellChanged?.Invoke(cell, type); }
public void AddResource(ResourceType t, CPos p, int n) { var cell = Content[p]; if (cell.Type == null) { cell = CreateResourceCell(t, p); } if (cell.Type != t) { return; } cell.Density = Math.Min(cell.Type.Info.MaxDensity, cell.Density + n); Content[p] = cell; CellChanged?.Invoke(p, cell.Type); foreach (var rl in resourceLogicLayers) { rl.UpdatePosition(p, t, cell.Density); } }
public void OnCellChanged(string map, string cell, string pad) { CellChanged?.Invoke(Bot, map, cell, pad); }
public void Update() { CellChanged?.Invoke(this, EventArgs.Empty); }
/// <summary> /// Triggering the cell changed event /// </summary> /// <param name="x">The x-coordinate of the cell</param> /// <param name="y">The y-coordinate of the cell</param> /// <param name="cell">The new state of the cell</param> private void OnCellChanged(int x, int y, Cell cell) { CellChanged?.Invoke(this, new CellChangedEventArgs(x, y, cell)); }
private void MakeCell(int x, int y, ICell cell) { _field[x, y] = cell; CellChanged?.Invoke(new CellChangedEventArgs <ICell>(x, y, cell)); }
public void OnMessage(CellChanged message) { Refresh(); }
//--------------internal method is responsible for raising the event-------------- protected virtual void OnCellChanged(CellChangeEventArgs e) { CellChanged?.Invoke(e); }