public virtual void UpdateState() { if (CellState != ClickableCellState.Disabled) { if (CellState == ClickableCellState.Selected) { if (IsMouseInside()) { if (WindowInput.WasMouseLeftButtonReleased) { CellState = ClickableCellState.Hovered; Clicked(CellState); } } } else { if (IsMouseInside()) { if (WindowInput.WasMouseLeftButtonReleased) { CellState = ClickableCellState.Selected; Clicked(CellState); } else { CellState = ClickableCellState.Hovered; } } else { CellState = ClickableCellState.Normal; } } } }
public void UpdateSelectedCellsList(ClickableCellState cellState) { switch (cellState) { case ClickableCellState.Hovered: for (var i = 0; i < selectedCells.Length; i++) { if ( selectedCells[i] != null && selectedCells[i].CellState == ClickableCellState.Hovered ) { selectedCells[i] = null; return; } } return; case ClickableCellState.Selected: if ( selectedCells[0] == null && selectedCells[1] == null ) { for (var y = 0; y < grid.CellCount.Y; y++) { for (var x = 0; x < grid.CellCount.X; x++) { if (cells[y, x].CellState == ClickableCellState.Selected) { selectedCells[0] = cells[y, x]; return; } } } } else if ( selectedCells[0] == null && selectedCells[1] != null ) { for (var y = 0; y < grid.CellCount.Y; y++) { for (var x = 0; x < grid.CellCount.X; x++) { if ( cells[y, x].CellState == ClickableCellState.Selected && cells[y, x] != selectedCells[1] ) { if ( (x != 0 && cells[y, x - 1] == selectedCells[1]) || (y != 0 && cells[y - 1, x] == selectedCells[1]) || (x != grid.CellCount.X - 1 && cells[y, x + 1] == selectedCells[1]) || (y != grid.CellCount.Y - 1 && cells[y + 1, x] == selectedCells[1]) ) { selectedCells[0] = cells[y, x]; } else { cells[y, x].CellState = ClickableCellState.Hovered; } return; } } } } else if ( selectedCells[0] != null && selectedCells[1] == null ) { for (var y = 0; y < grid.CellCount.Y; y++) { for (var x = 0; x < grid.CellCount.X; x++) { if ( cells[y, x].CellState == ClickableCellState.Selected && cells[y, x] != selectedCells[0] ) { if ( (x != 0 && cells[y, x - 1] == selectedCells[0]) || (y != 0 && cells[y - 1, x] == selectedCells[0]) || (x != grid.CellCount.X - 1 && cells[y, x + 1] == selectedCells[0]) || (y != grid.CellCount.Y - 1 && cells[y + 1, x] == selectedCells[0]) ) { selectedCells[1] = cells[y, x]; } else { cells[y, x].CellState = ClickableCellState.Hovered; } return; } } } } else if ( selectedCells[0] != null && selectedCells[1] != null ) { for (var y = 0; y < grid.CellCount.Y; y++) { for (var x = 0; x < grid.CellCount.X; x++) { if ( cells[y, x].CellState == ClickableCellState.Selected && cells[y, x] != selectedCells[0] && cells[y, x] != selectedCells[1] ) { cells[y, x].CellState = ClickableCellState.Hovered; return; } } } } return; } }