public void UpdateCell(CPos cell) { var uv = cell.ToMPos(Map); var tile = Map.MapResources.Value[uv]; ResourceType type; if (Resources.TryGetValue(tile.Type, out type)) { Tiles[uv] = new CellContents { Type = type, Variant = ChooseRandomVariant(type), }; Map.CustomTerrain[uv] = Tileset.GetTerrainIndex(type.Info.TerrainType); } else { Tiles[uv] = CellContents.Empty; Map.CustomTerrain[uv] = byte.MaxValue; } // Ingame resource rendering is a giant hack (#6395), // so we must also touch all the neighbouring tiles Dirty.Add(cell); foreach (var d in CVec.Directions) { Dirty.Add(cell + d); } }
public Form1(string filepath) { InitializeComponent(); //make sure the file path is not null before intializing the spreadsheet if (filepath != null) { spread = new Spreadsheet(filepath, s => true, s => s.ToUpper(), "ps6"); this.Text = filepath; fileName = filepath; saved = true; } //initializing the state of the spreadsheet by // setting the selection to the first cell spreadsheetPanel1.SetSelection(0, 0); // Setting the textbox for the name to A1 CellName.Text = "A1"; // Displaying the cells DisplayPanelOnOpen(spreadsheetPanel1); //Adding the displayControlsOnSelection as a listener to the event handler for the panel spreadsheetPanel1.SelectionChanged += DisplayControlsOnSelection; // adding the function pd_PrintPage to the event handler pd.PrintPage, so that pd_PrintPage will be called // when the event is triggered. pd.PrintPage += new PrintPageEventHandler(pd_PrintPage); // Setting the cursor to the textbox for cell contents. CellContents.Select(); }
/// <summary> /// Pasting into the CellContents textbook if it is selected. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void pasteToolStripMenuItem_Click(object sender, EventArgs e) { if (CellContents.Focused) { CellContents.Paste(); } }
/// <summary> /// Cutting the CellContents textbox if it is selected /// Called on the click of the cut in the menu. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void cutToolStripMenuItem_Click(object sender, EventArgs e) { if (CellContents.Focused) { CellContents.Cut(); } }
/// <summary> /// Initializes a new instance of the <see cref="Cell"/> class. /// </summary> /// <param name="name">The name of the cell. <seealso cref="Name"/>.</param> /// <param name="location">The location of the cell. <seealso cref="Location"/></param> /// <param name="level">The level where the cell is located. <seealso cref="Level"/></param> /// <param name="contents">The contents of this cell. <seealso cref="CellContents"/>/param> public Cell(string name, Location location, Level level, CellContents contents) : this(name, location, level) { /* Add to this cell. */ CellContents = contents; /* Make sure the content knows where it is. */ contents.Cell = this; }
private void CreateUnit(FlatHexPoint point, GameObject prefab, CellContents owner) { GameObject newUnit = Instantiate(prefab, Map [point], Quaternion.identity) as GameObject; Unit unit = newUnit.GetComponent <Unit> (); grid [point].contents = owner; grid [point].unit = unit; grid [point].isAccessible = false; }
public void ShouldProvideAMechanismToOpenItself() { var cell1 = new Cell(new CellContents(false), new Position(0, 0)); var expectedContents1 = new CellContents(false); Assert.AreEqual(expectedContents1, cell1.Open()); var cell2 = new Cell(new CellContents(true), new Position(0, 0)); var expectedContents2 = new CellContents(true); Assert.AreEqual(expectedContents2, cell2.Open()); }
/// <summary> /// users can still click-select cells /// </summary> /// <remarks> /// This is actually trickier than it seems. We need to update the /// cell value and cell content txt boxes, update col,row, /// and ensure that focus is passed to the panel. /// Deselecting should release(write) the edit box text to the cell /// </remarks> /// <param name="sender"></param> private void Panel_SelectionChanged(SpreadsheetPanel sender) { Panel.GetSelection(out col, out row); CellNameBox.Text = this.ColRow_To_string(col, row); CellVal.Text = this.PrintableValue(sheetModel.GetCellValue(CellNameBox.Text)); string To_cell_content_box; Panel.GetValue(col, row, out To_cell_content_box); CellContents.Text = To_cell_content_box; CellContents.Select(0, CellContents.Text.Length); this.Panel.Select(); PanelFocus = true; }
/// <summary> /// I'm using this event to handle arrow keys. probably bad practice... /// oh well /// </summary> /// <param name="msg">I don't know what this does</param> /// <param name="keyData">Data about the keypress</param> /// <returns>a boolean...for obvious reasons...</returns> protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { if (PanelFocus) { switch (keyData) { case Keys.Down: Panel.SetSelection(col, ++row); this.Panel_SelectionChanged(Panel); break; case Keys.Up: Panel.SetSelection(col, --row); this.Panel_SelectionChanged(Panel); break; case Keys.Left: Panel.SetSelection(--col, row); this.Panel_SelectionChanged(Panel); break; case Keys.Right: Panel.SetSelection(++col, row); this.Panel_SelectionChanged(Panel); break; default: PanelFocus = false; CellContents.Text += new string((char)keyData, 1); CellContents.Select(CellContents.Text.Length, 0); //Panel.SetValue(col, row, CellContents.Text); break; } this.CellContents.Select(); return(true); } return(base.ProcessCmdKey(ref msg, keyData)); }
/// <summary> /// Creates a file dialog that allows an existing file to be opened in the same window /// It will clear the contents of the existing window, and populate the window with the contents /// of the spreadsheet to be opened. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void openFileDialog1_FileOk(object sender, CancelEventArgs e) { try { // getting the filename from the file dialog string filePath = openFileDialog1.FileName; // emptying the spreadsheet spreadsheetPanel1.Clear(); //creating a new spreadsheet from the specified file path spread = new Spreadsheet(filePath, s => true, s => s.ToUpper(), "ps6"); this.Text = filePath; // updating the name of the spreadsheet window fileName = filePath; saved = true; // setting the displays of the input boxes at the top DisplayControlsOnSelection(spreadsheetPanel1); // setting the display of the panels DisplayPanelOnOpen(spreadsheetPanel1); // adding the DisplayControlsOnSelection to event handler for the spreadsheet panel spreadsheetPanel1.SelectionChanged += DisplayControlsOnSelection; // setting the cursor to the CellContents input box CellContents.Select(); } catch { MessageBox.Show("There was an error opening the file. Please make sure that the filepath is correct, and that the file is a valid spreadsheet file."); } }
/// <summary> /// Tries to the set the cell contents. /// </summary> /// <param name="contents">The contents to place in the cell.</param> /// <returns><code>true</code> if the specified contents /// was able to be placed in this cell; <code>false</code> otherwise.</returns> public virtual bool TrySetContents(CellContents contents) { if (CanEnter) { contents.Cell.RemoveContents(); /* Add to this cell. */ CellContents = contents; /* Make sure the content knows where it is. */ contents.Cell = this; OnPropertyChanged("CellContents"); return true; } return false; }
public override void Initialize() { base.Initialize(); Size = Constants.DefaultZeroSize; CellContents = new CellContents(); }
public TablixCell CreateCell(string fieldName, uint? colSpan, uint? rowSpan,bool hidden) { TextboxType textbox = null; if (hidden) { textbox = CreateTextbox(fieldName, true); } else { textbox = CreateTextbox(fieldName); } var cellContents = new CellContents() { Textbox = textbox }; if (colSpan != null && colSpan > 1) { cellContents.ColSpan = colSpan; } if (rowSpan != null && rowSpan > 1) { cellContents.RowSpan = rowSpan; } var cell = new TablixCell { CellContents = cellContents.Create(), IsEmpty = false, HasSetValue = true }; return cell; }
public TablixMembersType CreateMs(TablixMembersType parent, bool isStart, bool isRow) { if (isStart) { _level = 0; } var limit = isRow ? this.Columns.Count : this.Rows.Count; var tablixMember = new TablixMember(); if ((!isRow && _level == limit - 1) || (isRow && _level==0)) { tablixMember.Visibility = new Visibility() {Hidden = "true"}.Create(); var group = new Group { GroupExpressions = new GroupExpressionsType() {GroupExpression=new string[]{""} } }; tablixMember.Group = group.Create(isRow?"RowGroup":"ColumnGroup"); } var heaer = new TablixHeader(); var contents = new CellContents() { Textbox = CreateTextbox("",true) }.Create(); heaer.CellContents = new CellContentsType[] { contents }; string size = isRow ? this.Columns[_level].Width : this.Rows[_level].Height; heaer.Size = new string[] { size }; tablixMember.TablixHeader = heaer.Create(); _level++; if (_level < limit) { tablixMember.TablixMembers = CreateMs(new TablixMembersType(), false, isRow); } parent.TablixMember = new TablixMemberType[] { tablixMember.Create() }; return parent; }
private void Update() { // if we're currently animating, don't update grid state until the display of the grid is caught up ith the current grid state. if (GridDisplayer.TweenInProgress()) { return; } if (primaryTouchInfo.touching && !cellSelected) { // user is touching inside the grid if (primaryTouchInfo.startGridPosition != new Vector2Int(int.MinValue, int.MinValue)) { selectedCell = primaryTouchInfo.startGridPosition; cellSelected = true; Debug.Log(grid[selectedCell.x, selectedCell.y].cellContent); } } if (!primaryTouchInfo.touching && cellSelected) { cellSelected = false; } #region Candy Swapping if (shouldGetSwipedCell) { // user has touched inside the grid if (primaryTouchInfo.startGridPosition != new Vector2Int(int.MinValue, int.MinValue)) { int x = primaryTouchInfo.startGridPosition.x + primaryTouchInfo.swipeDirection.x; int y = primaryTouchInfo.startGridPosition.y - primaryTouchInfo.swipeDirection.y; // user is swiping inside the grid if (x < GRID_WIDTH && y < GRID_HEIGHT && x >= 0 && y >= 0) { // the cell the player is swiping swipedCell = new Vector2Int(x, y); // swap the cellContent variables of the cells being swapped CellContents temp = grid[swipedCell.x, swipedCell.y].cellContent; grid[swipedCell.x, swipedCell.y].cellContent = grid[selectedCell.x, selectedCell.y].cellContent; grid[selectedCell.x, selectedCell.y].cellContent = temp; // check for matches List <Vector2Int> matches = new List <Vector2Int>(); matches.AddRange(GetMatchesAtCell(swipedCell)); matches.AddRange(GetMatchesAtCell(selectedCell)); if (matches.Count != 0) { // this is kind of a hack : // Basically, when a GridElement swaps, it deregisters its swap method from its // current cell and registers it on the new cell. however, since the new // cell's swap method gets called right after, the first GridElement's swap // method was being called twice. // We "solve" this by taking a "snapshot" of the swiped gridcell before the // first GridElement registers its swap method on it, and calling the swap // method of this "snapshot". The first GridElement's swap method is only // called once and still registers itself on the right cell. GridCell swipedCellCopy = grid[swipedCell.x, swipedCell.y]; if (grid[selectedCell.x, selectedCell.y].Swap != null) { grid[selectedCell.x, selectedCell.y].Swap(swipedCell); } if (swipedCellCopy.Swap != null) { swipedCellCopy.Swap(selectedCell); } foreach (Vector2Int cell in matches) { if (grid[cell.x, cell.y].Pop != null) { grid[cell.x, cell.y].Pop(); } grid[cell.x, cell.y].cellContent = CellContents.empty; } return; } else { // call swap fail event (no need for the above hack since GridElement_Candy's // SwapFail method doesn't do any registering/deregistering) if (grid[selectedCell.x, selectedCell.y].SwapFail != null) { grid[selectedCell.x, selectedCell.y].SwapFail(swipedCell); } if (grid[swipedCell.x, swipedCell.y].SwapFail != null) { grid[swipedCell.x, swipedCell.y].SwapFail(selectedCell); } // swap cell contents back CellContents temp2 = grid[swipedCell.x, swipedCell.y].cellContent; grid[swipedCell.x, swipedCell.y].cellContent = grid[selectedCell.x, selectedCell.y].cellContent; grid[selectedCell.x, selectedCell.y].cellContent = temp2; } } } //shouldGetSwipedCell = false; } #endregion #region Candy Falling if (GridHasEmptyCells()) { // check for cells i which new candies should be spawned for (int i = GRID_WIDTH - 1; i >= 0; --i) { int topColumnCellYCoord = 0; // if the top cell of the column is a hole, go down until we find one that's not if (grid[i, topColumnCellYCoord].cellContent == CellContents.hole) { for (int j = 0; j < GRID_HEIGHT; ++j) { if (grid[i, j].cellContent == CellContents.hole) { ++topColumnCellYCoord; } else { break; } } } if (grid[i, topColumnCellYCoord].cellContent == CellContents.empty) { // get a random color for the new candy // FIND A BETTER WAY TO DO THIS CellContents color = (CellContents)Random.Range(1, 6); // Call a GridDisplayer Function to spawn in a new candy in the top row cell GridDisplayer.SpawnNewCandy(color, new Vector2Int(i, topColumnCellYCoord)); grid[i, topColumnCellYCoord].cellContent = color; } } bool candiesFellThisFrame = false; // go backwards throught the grid, starting 1 line above the bottom because we're checking if cells below are emtpy for (int j = GRID_HEIGHT - 2; j >= 0; --j) { for (int i = GRID_WIDTH - 1; i >= 0; --i) { if (grid[i, j].cellContent == CellContents.hole) { continue; } // if we find a non empty cell above an empty cell or a hole if ((grid[i, j + 1].cellContent == CellContents.empty || grid[i, j + 1].cellContent == CellContents.hole) && grid[i, j].cellContent != CellContents.empty) { int dist = 0; int holeCounter = 0; // go down until we find a cell that's above a non empty cell or at the bottom of the grid for (int y = j + 1; y < GRID_HEIGHT; ++y) { if (grid[i, y].cellContent == CellContents.hole) { // if the cell we're checking is a hole, we don't want to add to dist just yet in // case its holes all the way down, in which case the candy should not drop, so // we keep a separate counter for holes holeCounter++; } else { dist++; // if we've hit a cell that's not a hole and the holeCounter is greater than 0, // that means the ccandy can fall down through the holes. we add the holecounter // to dist and we reset it in case we find more holes lower in the grid. if (holeCounter > 0) { dist += holeCounter; holeCounter = 0; } } if (y < GRID_HEIGHT - 1) { // break if the cell below the one we're checking is not empty and not a hole if (grid[i, y + 1].cellContent != CellContents.empty && grid[i, y + 1].cellContent != CellContents.hole) { break; } } } // dist is now the number of empty cells between the cell we're at and the next non-empty cell under it // we call Fall on grid[i,j] and pass it dist if (dist > 0) { if (grid[i, j].Fall != null) { grid[i, j].Fall(dist); } grid[i, j + dist].cellContent = grid[i, j].cellContent; grid[i, j].cellContent = CellContents.empty; candiesFellThisFrame = true; } } } } if (candiesFellThisFrame) { return; } //for each grid column i, check if grid[i, 0] is empty. if yes, new candies should be spawned. //for (int i = GRID_WIDTH - 1; i >= 0; --i) //{ // int topColumnCellYCoord = 0; // // // if the top cell of the column is a hole, go down until we find one that's not // if (grid[i, topColumnCellYCoord].cellContent == CellContents.hole) // { // for (int j = 0; j < GRID_HEIGHT; ++j) // { // if (grid[i, j].cellContent == CellContents.hole) // { // ++topColumnCellYCoord; // } // else // { // break; // } // } // } // // if (grid[i, topColumnCellYCoord].cellContent == CellContents.empty) // { // // "probe" down to see how far down the next non-empty cell is // int dist = 0; // int holeCounter = 0; // // for (int j = topColumnCellYCoord+1; j < GRID_WIDTH; ++j) // { // if (grid[i, j].cellContent == CellContents.empty ) // { // ++dist; // // if (holeCounter > 0) // { // dist += holeCounter; // holeCounter = 0; // } // } // else if (grid[i, j].cellContent == CellContents.hole) // { // ++holeCounter; // } // else // { // break; // } // } // // // get a random color for the new candy // // FIND A BETTER WAY TO DO THIS // CellContents color = (CellContents)Random.Range(1, 6); // // // Call a GridDisplayer Function to spawn in a new candy in the top row cell // GridDisplayer.SpawnNewCandy(color, new Vector2Int(i, topColumnCellYCoord)); // // // call Fall on this top row cell if dist > 0 // if (dist > 0) // { // if (grid[i, 0].Fall != null) // grid[i, 0].Fall(dist); // // grid[i, dist].cellContent = color; // } // else // { // grid[i, 0].cellContent = color; // } // // } //} } #endregion if (!GridHasEmptyCells()) { // check the whole grid for matches and pop them // for some reason this doesn't detect 4+ matches sometimes ? for (int i = 0; i < GRID_WIDTH; ++i) { for (int j = 0; j < GRID_HEIGHT; ++j) { foreach (Vector2Int cellPos in GetMatchesAtCell(new Vector2Int(i, j))) { if (grid[cellPos.x, cellPos.y].Pop != null) { grid[cellPos.x, cellPos.y].Pop(); } grid[cellPos.x, cellPos.y].cellContent = CellContents.empty; } } } } }
private Rdl.TablixCellType CreateTablixCell(int i, string fieldName) { TablixCell cell = new TablixCell(); //cell.CellContents CellContents contents = new CellContents(); contents.Textbox = CreateTableCellTextbox(i, fieldName); cell.CellContents = contents.Create(); return cell.Create(); }
/// <summary> /// Initializes a new instance of the <see cref="FloorCell"/> class. /// </summary> /// <param name="location">The location of the cell.</param> /// <param name="level">The level on which the cell is located.</param> /// <param name="contents">The contents of this cell.</param> public FloorCell(Location location, Level level, CellContents contents) : base(cellName, location, level, contents) { }