CellDescriptor GetNearestCell(CellDescriptor toCell, out int x, out int y) { float previous; float current = float.MaxValue; for (x = 0; x < FieldSize; ++x) { previous = current; current = Mathf.Abs(toCell.Center.x - CellGrid.Elements[x].Center.x); if (previous < current) { break; } } --x; current = float.MaxValue; for (y = 0; y < FieldSize; ++y) { previous = current; current = Mathf.Abs(toCell.Center.y - CellGrid.Elements[y * FieldSize].Center.y); if (previous < current) { break; } } --y; return(CellGrid.Elements[x + y * FieldSize]); }
void ChangeCellAlpha(CellDescriptor cell, float value) { Color newColor = cell.Icon.color; newColor.a = value; cell.Icon.color = newColor; }
void StopAlphaProcessing(CellDescriptor cell) { if (CellAlphaProcessings.ContainsKey(cell)) { if (CellAlphaProcessings[cell] != null) { Executor.StopCoroutine(CellAlphaProcessings[cell]); } CellAlphaProcessings.Remove(cell); } }
public void HideCell(CellDescriptor cell) { StopAlphaProcessing(cell); CellAlphaProcessings.Add ( cell, Executor.ExecCoroutine ( CellAlphaProcessing(cell, 0f) ) ); }
IEnumerator CellAlphaProcessing(CellDescriptor cell, float target) { float current = cell.Icon.color.a; float stepMult = target == 1f ? 1f : -1f; while (current != target) { current = Mathf.Clamp(current + stepMult * alphaChangeStep * Time.deltaTime, 0f, 1f); ChangeCellAlpha(cell, current); yield return(null); } }
//[Inject] //public ValidateFieldSignal ValidateSignal { get; private set; } public override void Execute() { Retain(); Dictionary <CellDescriptor, CellFilling> cellsToFill = new Dictionary <CellDescriptor, CellFilling>(); List <Vector2> coords = new List <Vector2>(); foreach (CellDescriptor cell in Cursor.Nest.Elements) { if (!cell.Enabled) { continue; } int x, y; CellDescriptor nearestCell = GetNearestCell(cell, out x, out y); if (cellsToFill.ContainsKey(nearestCell) || nearestCell.Enabled || !nearestCell.IsUnderCell(cell)) { Revoke(); return; } cellsToFill.Add(nearestCell, cell.Filling); coords.Add(new Vector2(x, y)); } Cursor.NestSelected.Used = true; AlphaManager.ForceHideCells(Cursor.Nest.Elements); int i = 0; foreach (CellDescriptor cell in cellsToFill.Keys) { Model.Cells[(int)coords[i].x, (int)coords[i].y].Filling = cell.Filling = cellsToFill[cell]; Model.Cells[(int)coords[i].x, (int)coords[i].y].Filled = cell.Enabled = true; i++; } AlphaManager.HighlightCells(cellsToFill.Keys, false); foreach (NestDescriptor nest in NestGrid.Elements) { if (!nest.Used) { Release(); //ValidateSignal.Dispatch(); return; } } OverSignal.Dispatch(); //ValidateSignal.Dispatch(); Release(); }
public bool IsUnderCell(CellDescriptor cell) { return(cell.Center.x >= minX && cell.Center.x <= maxX && cell.Center.y >= minY && cell.Center.y <= maxY); }
public void ForceHighlightCell(CellDescriptor cell) { StopAlphaProcessing(cell); ChangeCellAlpha(cell, 1f); }