/// ------------------------------------------------------------------------------------ /// <summary> /// Clean up any resources being used. /// </summary> /// <param name="disposing">set to <c>true</c> if called from the Dispose() method, /// set to <c>false</c> if called by GC. If this parameter is <c>false</c> we shouldn't /// access any managed objects since these might already have been destroyed.</param> /// ------------------------------------------------------------------------------------ protected override void Dispose(bool disposing) { // Debug.WriteLineIf statement disabled because of a bug in .NET DataGridView: // DataGridView.AddRange() creates a temporary clone that it doesn't dispose, so we // will always get this warning message and we can't do anything about it. // Debug.WriteLineIf(!disposing, "****** Missing Dispose() call for " + GetType().Name + ". ****** "); if (disposing) { if (m_textBoxControl != null) { m_textBoxControl.Dispose(); } if (m_fontCache != null) { foreach (Font fnt in m_fontCache.Values) { fnt.Dispose(); } m_fontCache.Clear(); } if (m_DisposeCellTemplate && CellTemplate != null) { CellTemplate.Dispose(); CellTemplate = null; m_DisposeCellTemplate = false; } } m_textBoxControl = null; m_cache = null; m_fontCache = null; base.Dispose(disposing); }
public virtual UIElement GenerateCell() { var cell = CellTemplate == null ? null : CellTemplate.LoadContent() as UIElement; cell = cell ?? new TextBlock(); SetColumn(cell, this); var element = cell as FrameworkElement; if (element != null) { var dataPath = string.IsNullOrWhiteSpace(DataMember) ? "(0).Item" : "(0).Item." + DataMember; element.SetBinding(FrameworkElement.DataContextProperty, new Binding { Path = new PropertyPath(dataPath, LiteRow.RowProperty.DependencyProperty), Source = element, Mode = BindingMode.OneWay }); } var text = cell as TextBlock; if (text != null) { text.SetBinding(TextBlock.TextProperty, new Binding("DataContext") { Source = text, Mode = BindingMode.OneWay }); } return(cell); }
public void SetCell(int x, CellTemplate cell) { if (x >= 0 && x < width) { lineCells[x] = cell; } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Clean up any resources being used. /// </summary> /// <param name="disposing">set to <c>true</c> if called from the Dispose() method, /// set to <c>false</c> if called by GC. If this parameter is <c>false</c> we shouldn't /// access any managed objects since these might already have been destroyed.</param> /// ------------------------------------------------------------------------------------ //[SuppressMessage("Clouseau", "MissingDisposeCall", Justification = "Debug.WriteLineIf statement disabled because of a bug in .NET DataGridView:" // + "DataGridView.AddRange() creates a temporary clone that it doesn't dispose, so we will always get this warning message and we can't do anything about it.")] protected override void Dispose(bool disposing) { Debug.WriteLineIf(!disposing, "****** Missing Dispose() call for " + GetType().Name + ". ****** (but this might not be your fault)"); if (disposing) { if (m_textBoxControl != null) { m_textBoxControl.Dispose(); } if (m_fontCache != null) { foreach (Font fnt in m_fontCache.Values) { fnt.Dispose(); } m_fontCache.Clear(); } if (m_DisposeCellTemplate && CellTemplate != null) { CellTemplate.Dispose(); CellTemplate = null; m_DisposeCellTemplate = false; } } m_textBoxControl = null; m_cache = null; m_fontCache = null; base.Dispose(disposing); }
// Returns this cell's template public CellTemplate GetCellTemplate() { CellTemplate template = new CellTemplate(); template.cellOcc = cellType; return(template); }
private UITableViewCell GetCellForCommand(UITableView tableView, NSIndexPath indexPath) { var commandBinding = GetCommand(indexPath); var commandArguments = new ApplicationCommandArguments( _applicationMetadata, MetadataRepository, _dataMap, new DataRepository(), _composite, User.Current, _detailController); return(CellTemplate.ConstructCommandCell(tableView, commandBinding, commandArguments, _commandPreCondition)); }
//public int LastMainSelected { private set { _LastMainSelection = value; } get { return _LastMainSelection; } } protected override void OnSafeInit() { base.OnSafeInit(); if (poolNode == null) { poolNode = RectTrans; } CellTemplate.SetParent(poolNode, false); }
/// <summary> /// Creates a new cell in this holder of type celltype. /// If type is blocked then it's gonna disable cell by default and the returned cell will be null /// </summary> /// <param name="cellType"></param> /// <param name="animate">Whether to animate the cell or not</param> /// <returns>Return null if the cell could not be created</returns> public Cell NewCell(Cell.CellOcc cellType, bool animate = true) { if (!cell) { // We have a blocking cell, for example a hole filler if (cellType == Cell.CellOcc.BLOCKED) { Disable(); currentTemplate = new CellTemplate(); currentTemplate.cellOcc = cellType; return(null); } cellGameObject = CellPooling.GetCell(); SpriteRenderer sprR = cellGameObject.GetComponent <SpriteRenderer>(); sprR.sortingLayerName = "Signs" + cellType.ToString(); // Set sorting layer for dynamic batching sprR.color = SignResourceStorage.Instance.GetColorRelatedTo(cellType); if (Grid.cellParent != null) { cellGameObject.transform.parent = Grid.cellParent.transform; } // current cell template currentTemplate = new CellTemplate(); currentTemplate.cellOcc = cellType; // Set cell type both for animation and data storage purposes cell = cellGameObject.GetComponent <Cell>(); cell.cellType = cellType; // Animation if (animate) { cell.TriggerDraw(); } else { cell.TriggerIdle(); } // Subtract .five because the center is the pivot (because we want to rotate it to give it better look) cellGameObject.transform.position = GetRandomPosBasedOnWorldPos(); cellGameObject.transform.eulerAngles = GetRandomAngles(); } else { return(null); } return(cell); }
/// <summary> /// 行オブジェクトのセットアップを行います. /// </summary> /// <returns>行を構成する <c>GameObject</c>.</returns> protected virtual GameObject SetupRowTemplate() { var cell = CellTemplate.GetComponent <RectTransform>(); var row = RowTemplate.GetComponent <RectTransform>(); row.sizeDelta = Scroller.ScrollDirection == ScrollDirection.Horizontal ? new Vector2(cell.rect.width, row.sizeDelta.y) : new Vector2(row.sizeDelta.x, cell.rect.height); return(row.gameObject); }
// Modify cells public CellTemplate GetShipCell(int x, int y) { CellTemplate outCell = null; if (y >= 0 && y < Height) { outCell = pieceLines[y].GetCell(x); } return(outCell); }
public static CellTemplateDto AsDto(this CellTemplate entity) { return(new CellTemplateDto() { Row = entity.Row, Column = entity.Column, RowSpan = entity.RowSpan, ColumnSpan = entity.ColumnSpan, DefaultValue = entity.DefaultValue, InputType = entity.InputType }); }
public void RefreshContent() { if (isRefreshing) { return; // nicht rekusiv ;) } try { isRefreshing = true; Element cont = GetEmptyView(); if (SelectedItem != null) { if (filledContent == null) { filledContent = (CellTemplate?.CreateContent() as ViewCell).View; } cont = filledContent; } if (cont == null) { cont = GetEmptyView(); } //cont.InputTransparent = true; lv.ItemTemplate = this.CellTemplate; // to avoid nullreference excetion in Xamarin.Forms.ListView //lv.SelectedItem = null; //lv.ItemsSource = null; lv.ItemsSource = ItemsSource; lv.SelectedItem = SelectedItem; var vc = cont as View; if (vc != null) { frame.Content = vc; frame.Content.Margin = 0; frame.HeightRequest = ListViewRowHeight; frame.Content.BindingContext = SelectedItem; } } finally { isRefreshing = false; } }
/// <summary> /// Dispose the object /// </summary> protected override void Dispose(bool disposing) { System.Diagnostics.Debug.WriteLineIf(!disposing, "****** Missing Dispose() call for " + GetType() + ". ****** "); base.Dispose(disposing); if (disposing) { if (CellTemplate != null) { CellTemplate.Dispose(); } CellTemplate = null; } }
private FrameworkElement GenerateElement(object childData) { if (CellTemplate != null) { FrameworkElement element = CellTemplate.LoadContent() as FrameworkElement; element.DataContext = childData; return(element); } else //we are going to make a ToString() of the element the user tries to show: { TextBlock textBlock = new TextBlock(); textBlock.Text = childData.ToString(); return(textBlock); } }
internal override FrameworkElement GenerateElement(object childData) { if (CellTemplate != null) { FrameworkElement element = CellTemplate.INTERNAL_InstantiateFrameworkTemplate(); element.DataContext = childData; return(element); } else //we are going to make a ToString() of the element the user tries to show: { TextBlock textBlock = new TextBlock(); textBlock.Text = childData.ToString(); return(textBlock); } }
public void DebugDrawShip() { foreach (ShipPiece piece in shipPieces) { for (int j = 0; j < piece.Height; ++j) { for (int i = 0; i < piece.Width; ++i) { CellTemplate cell = piece.GetShipCell(i, j); if (piece.GetShipCell(i, j).CellState != 0) { Vector3 p = new Vector3(piece.Position.x + i, piece.Position.y + j, 0) * 3.2f; if ((piece.GetShipCell(i, j).CurWallState & WallState.Up) != WallState.None) { Debug.DrawLine(transform.TransformPoint(p + new Vector3(1.5f, 1.5f, 0)), transform.TransformPoint(p + new Vector3(-1.5f, 1.5f, 0)), Color.red); } if ((piece.GetShipCell(i, j).CurWallState & WallState.Right) != WallState.None) { Debug.DrawLine(transform.TransformPoint(p + new Vector3(1.5f, -1.5f, 0)), transform.TransformPoint(p + new Vector3(1.5f, 1.5f, 0)), Color.red); } if ((piece.GetShipCell(i, j).CurWallState & WallState.Down) != WallState.None) { Debug.DrawLine(transform.TransformPoint(p + new Vector3(-1.5f, -1.5f, 0)), transform.TransformPoint(p + new Vector3(1.5f, -1.5f, 0)), Color.red); } if ((piece.GetShipCell(i, j).CurWallState & WallState.Left) != WallState.None) { Debug.DrawLine(transform.TransformPoint(p + new Vector3(-1.5f, 1.5f, 0)), transform.TransformPoint(p + new Vector3(-1.5f, -1.5f, 0)), Color.red); } } } } int connectionCount = piece.GetConnectionCount(); for (int i = 0; i < connectionCount; ++i) { ShipConnection connection = piece.GetConnectionByIndex(i); Vector3 p0 = new Vector3(connection.LocalCell.x + piece.Position.x, connection.LocalCell.y + piece.Position.y, 0) * 3.2f; Vector3 p1 = new Vector3(connection.OtherCell.x + connection.OtherPiece.Position.x, connection.OtherCell.y + connection.OtherPiece.Position.y, 0) * 3.2f; Debug.DrawLine( transform.TransformPoint(p0), transform.TransformPoint(p1), Color.green); } } }
public void Navigate(ShipRuntime targetShip, Vector2Int globalStartPos, Vector2Int globalEndPos) { Init(); this.targetShip = targetShip; if (globalStartPos == globalEndPos) { StartCoroutine("DelaySearch"); return; } nextIndex = 1; CellTemplate startCell = targetShip.GetCellByGlobalPos(globalStartPos); CellTemplate endCell = targetShip.GetCellByGlobalPos(globalEndPos); // Invalid path supplied if (startCell == null || endCell == null || startCell.CellState == 0 || endCell.CellState == 0) { return; } ShipPiece startPiece = targetShip.GetPieceByGlobalCellPos(globalStartPos); ShipPiece endPiece = targetShip.GetPieceByGlobalCellPos(globalEndPos); NavGrid startGrid = new NavGrid(startPiece); startGrid.Generate(); NavGrid goalGrid = startGrid; if (startPiece != endPiece) { goalGrid = new NavGrid(endPiece); goalGrid.Generate(); } AStarAlgorithm aStarAlgorithm = new AStarAlgorithm(startGrid, goalGrid, globalStartPos, globalEndPos); int newTTmp = 0; curPath = aStarAlgorithm.AStarSearch(ref newTTmp); wiggleTimer = Random.Range(0, 6.28318f); }
public void Generate() { cells = new NavCell[width * height]; for (int w = 0; w < width; w++) { for (int h = 0; h < height; h++) { int index = w * height + h; CellTemplate shipCell = shipPiece.GetShipCell(w, h); var navCell = new NavCell(this, new Vector2Int(w, h) + shipPiece.Position, shipCell); cells[index] = navCell; } } }
internal override FrameworkElement GenerateElement(object childData) { if (CellTemplate != null) { FrameworkElement element = CellTemplate.INTERNAL_InstantiateFrameworkTemplate(); element.DataContext = childData; Binding b = this.INTERNAL_GetBinding(DataGridBoundColumn.BindingProperty); //we get the Binding in the Binding property set by the user. if (b != null) { if (b.Mode == BindingMode.OneWay) { if (!b.INTERNAL_WasModeSetByUserRatherThanDefaultValue()) { b.Mode = BindingMode.TwoWay; } } element.SetBinding(FrameworkElement.DataContextProperty, b); } return(element); } else //we are going to make a ToString() of the element the user tries to show: { TextBlock textBlock = new TextBlock(); textBlock.DataContext = childData; Binding b = this.INTERNAL_GetBinding(DataGridBoundColumn.BindingProperty); //we get the Binding in the Binding property set by the user. if (b != null) { if (b.Mode == BindingMode.OneWay) { if (!b.INTERNAL_WasModeSetByUserRatherThanDefaultValue()) { b.Mode = BindingMode.TwoWay; } } textBlock.SetBinding(TextBlock.TextProperty, b); } else { textBlock.Text = childData.ToString(); } return(textBlock); } }
private void ToggleDatePicker(NSIndexPath target) { var shouldAttach = true; var targetBeforeOffset = target; TableView.BeginUpdates(); // Do we already have a date picker being // displayed? If so, we need to get rid of it. if (null != _datePicker) { // We do have a date picker displayed! If it's attached // to another cell we'll detach it first, but we must // remember to re-attach ("move") it to the new target. // Otherwise we'll simply turn it off. shouldAttach = false == _datePicker.IsAttachedTo(target); // We'll soon detach the date picker from the table, // which can cause our current target path pointing // to somewhere else after committing the changes. // So we'll "convert" it to its original value, as // if the date picker didn't exist. targetBeforeOffset = _datePicker.IndexPathBeforeOffset(target); _datePicker.Detach(); _datePicker = null; } if (shouldAttach) { var datePickerCell = CellTemplate.ConstructDatePickerCell(TableView); var targetField = GetField(targetBeforeOffset); _datePicker = DetailDatePickerCell.Attachment.Attach(TableView, targetBeforeOffset, targetField, datePickerCell); } TableView.EndUpdates(); }
// Connect 2 pieces by index, positions are relative to respective pieces public void ConnectPiecesByIndex(int localPieceIndex, int otherPieceIndex, Vector2Int localPos, Vector2Int otherPos) { if (localPieceIndex >= 0 && localPieceIndex < shipPieces.Count && otherPieceIndex >= 0 && otherPieceIndex < shipPieces.Count) { ShipPiece localPiece = shipPieces[localPieceIndex]; ShipPiece otherPiece = shipPieces[otherPieceIndex]; localPiece.AddConnection(new ShipConnection(localPos, otherPos, shipPieces[otherPieceIndex])); otherPiece.AddConnection(new ShipConnection(otherPos, localPos, shipPieces[localPieceIndex])); CellTemplate localCell = localPiece.GetShipCell(localPos.x, localPos.y); CellTemplate otherCell = otherPiece.GetShipCell(otherPos.x, otherPos.y); // Flag the connection cells if (localCell != null) { localCell.HasConnections = true; } if (otherCell != null) { otherCell.HasConnections = true; } } }
// Updates attributes in cell template public void UpdateAttributes(CellTemplate cellTemplate) { cellType = cellTemplate.cellOcc; }
private UITableViewCell GetCellForField(UITableView tableView, NSIndexPath indexPath) { var fieldBinding = GetField(indexPath); return(CellTemplate.ConstructFieldCell(tableView, fieldBinding)); }
/// <inheritdoc /> protected override CellTemplate GetItemCellTemplate(TItem item) => CellTemplate.Create(ContextMenu(item));
/// <summary> /// Both in current and previous cell template /// </summary> public void StoreTemplate(Cell.CellOcc type, Vector2 position) { currentTemplate = new CellTemplate(); currentTemplate.cellOcc = type; }
public CellHolder(int[] worldPos) { this.worldPos = worldPos; currentTemplate = new CellTemplate(); currentTemplate.cellOcc = Cell.CellOcc.NONE; }
public Board GetRandomBoard(Game game) { _game = game; var template = new BoardTemplate(game.RuleSet.BoardSize); var fleet = game.RuleSet.GetFleet().OrderByDescending(t => t.Size); List <List <Point> > mapped = new List <List <Point> >(); int shipId = 0; int x, y; List <Point> fallback; int fallbackIndex; foreach (var ship in fleet) { for (int i = 0; i < ship.Count; i++) { List <Point> placed = new List <Point>(); IEnumerable <CellTemplate> tmp; int toPlace = ship.Size; int it = 0; do { randomxy(out x, out y); if (++it > 1000000) { return(GetRandomBoard(game)); } } while (template.Cells[x, y].State != CellTemplateState.EMPTY || template.GetZone(x, y).Count(t => t.State == CellTemplateState.EMPTY) < toPlace); template.PlaceCore(x, y, shipId); placed.Add(new Point(x, y)); toPlace--; while (toPlace > 0) { fallback = new List <Point>(placed); do { fallbackIndex = _random.Next(0, fallback.Count); Point item = fallback[fallbackIndex]; fallback.RemoveAt(fallbackIndex); tmp = template.GetSides((int)item.X, (int)item.Y).Where(t => t.State == CellTemplateState.EMPTY || (t.State == CellTemplateState.ZONE && t.ShipID == shipId));//.Where(t => template.GetZone(t.X, t.Y).All(t2 => t2.IsNotColliding(shipId))); }while ((tmp == null || tmp.Count() == 0) && fallback.Count > 0); if (tmp.Count() == 0) { throw new Exception(); } CellTemplate target = tmp.ElementAt(_random.Next(0, tmp.Count())); template.PlaceCore(target.X, target.Y, shipId); placed.Add(new Point(target.X, target.Y)); toPlace--; } mapped.Add(placed); shipId++; } } Board board = new Board(game.RuleSet.BoardSize); for (int i = 0; i < mapped.Count; i++) { var ship = new Ship(mapped[i].Count); foreach (var pt in mapped[i]) { ship.AddCell(new SeaCell((int)pt.X, (int)pt.Y)); } board.AddShip(ship); } //var ship1 = new Ship(5); //ship1.AddCells(new SeaCell[] { new SeaCell(0, 0), new SeaCell(0, 1), new SeaCell(0, 2), new SeaCell(0, 3), new SeaCell(0, 4) }); //board.AddShip(ship1); //var ship2 = new Ship(4); //ship2.AddCells(new SeaCell[] { new SeaCell(2, 0), new SeaCell(2, 1), new SeaCell(2, 2), new SeaCell(2, 3) }); //board.AddShip(ship2); //var ship3 = new Ship(3); //ship3.AddCells(new SeaCell[] { new SeaCell(4, 0), new SeaCell(4, 1), new SeaCell(4, 2) }); //board.AddShip(ship3); //var ship4 = new Ship(2); //ship4.AddCells(new SeaCell[] { new SeaCell(6, 0), new SeaCell(6, 1) }); //board.AddShip(ship4); //var ship5 = new Ship(1); //ship5.AddCells(new SeaCell[] { new SeaCell(8, 0) }); //board.AddShip(ship5); return(board); }
public bool Navigate(ShipRuntime targetShip, Vector2Int globalStartPos, Vector2Int globalEndPos) { if (globalStartPos == globalEndPos) { return(false); } NavCell[] overrideStart = null; // Cur, prev and T evaluation if (curPath != null) { if (nextIndex < curPath.Length) { overrideStart = new NavCell[2]; // Store C0 and C1 overrideStart[0] = curPath[nextIndex - 1]; overrideStart[1] = curPath[nextIndex]; } } nextIndex = 1; CellTemplate startCell = targetShip.GetCellByGlobalPos(globalStartPos); CellTemplate endCell = targetShip.GetCellByGlobalPos(globalEndPos); // Invalid path supplied if (startCell == null || endCell == null || startCell.CellState == 0 || endCell.CellState == 0) { return(false); } ShipPiece startPiece = targetShip.GetPieceByGlobalCellPos(globalStartPos); ShipPiece endPiece = targetShip.GetPieceByGlobalCellPos(globalEndPos); NavGrid startGrid = new NavGrid(startPiece); startGrid.Generate(); NavGrid goalGrid = startGrid; if (startPiece != endPiece) { goalGrid = new NavGrid(endPiece); goalGrid.Generate(); } AStarAlgorithm aStarAlgorithm = new AStarAlgorithm(startGrid, goalGrid, globalStartPos, globalEndPos); int newTState = -1; curPath = aStarAlgorithm.AStarSearch(ref newTState, overrideStart); // Either reset, invert or leave move timer switch (newTState) { case -1: moveTimer = 0; break; case 1: moveTimer = 1 - moveTimer; break; } pathTracer.SetPositions(GetNavArray()); return(curPath != null); }