public static void MarkTiles(List <Tile> tilesToMark, TermTile taken) { foreach (Tile t in tilesToMark) { t.Taken = taken; } }
public bool Equals(TermTile obj) { if (obj == null) { return(false); } return(Term == obj.Term); }
public TermTile(TermTile other) { InitializeComponent(); DataContext = this; TileText = other.TileText; TileColor = other.TileColor; TileStrokeColor = other.TileStrokeColor; StrokeThickness = other.StrokeThickness; TextFontSize = other.TextFontSize; Term = other.Term; Focusable = true; }
//ukoliko su vec zauzete od strane nekog drugog termina vraca false, kako bi obavestili korisnika da se termini ne mogu preklapati public static bool CheckAndMarkTiles(List <Tile> tilesToMark, TermTile tTile) { foreach (Tile t in tilesToMark) { if (t.Taken != null && !t.Taken.Equals(tTile)) { return(false); } } //ako su sve plocice slobodne :) MarkTiles(tilesToMark, tTile); return(true); }
public void HandleOldTermTile(TermTile termTile, TermTile oldTermTile, Grid grid) { int oldRow = Grid.GetRow(oldTermTile); int oldColumn = Grid.GetColumn(oldTermTile); int oldRowSpan = Grid.GetRowSpan(oldTermTile); //oslobadjamo stare plocice gde se termin nekad prostirao :D List <Tuple <int, int> > oldCoordinates = TilesUtil.GetAllTermCoordinates(oldRow, oldColumn, oldRowSpan); var tilesToMark = TilesUtil.GetTiles(grid, oldCoordinates); TilesUtil.MarkTiles(tilesToMark, null); //ukoliko je stara plocica bila selektovana pre prevlacenja, nova mora biti isto if (oldTermTile.Equals(TermTile.LastSelectedTermTile)) { TermTile.LastSelectedTermTile = termTile; } grid.Children.Remove(oldTermTile); }
private void FillGridWithTerms() { foreach (Term t in ChosenClassroom.Terms) { Tuple <int, int> position = CalculatePosition(t); var tile = new TermTile() { Term = t, TileText = t.Subject.Label }; Grid.SetColumn(tile, position.Item2); Grid.SetRow(tile, position.Item1); Grid.SetRowSpan(tile, t.Length * 3); var coordinates = TilesUtil.GetAllTermCoordinates(position.Item1, position.Item2, Grid.GetRowSpan(tile)); var tiles = TilesUtil.GetTiles(grid, coordinates); TilesUtil.MarkTiles(tiles, tile); grid.Children.Add(tile); tile.TileColor = "Yellow"; } }
public void DoDrop(bool isNewTerm, DragEventArgs e) { //TODO postavi podatke Grid grid = ((Grid)this.Parent); TermTile termTile; TermTile oldTermTile = null; if (!isNewTerm) { oldTermTile = (TermTile)e.Data.GetData("Object"); termTile = new TermTile(oldTermTile); } else { Term t = new Term(); t.Subject = (Subject)e.Data.GetData("Object"); if (t.Subject.NumRequiredTerms <= 0) { MessageBox.Show("Nema vise termina za predmet.", "Obaveštenje", MessageBoxButton.OK, MessageBoxImage.Information); return; } t.Subject.NumRequiredTerms = t.Subject.NumRequiredTerms - 1; t.Classroom = (Classroom)e.Data.GetData("ChosenClassroom"); termTile = new TermTile(); t.Length = t.Subject.MinimalTermLength; termTile.TileText = t.Subject.Label; termTile.Term = t; } int row = Grid.GetRow(this); int column = Grid.GetColumn(this); int newTileRowspan = 3 * (termTile.Term.Length); if (row + newTileRowspan > (grid.RowDefinitions.Count)) { MessageBox.Show("Nemoguce prevuci tu. Termin ce probiti limite.", "Obaveštenje", MessageBoxButton.OK, MessageBoxImage.Information); return; } List <Tuple <int, int> > coordinates = TilesUtil.GetAllTermCoordinates(row, column, newTileRowspan); List <Tile> tilesToMark = TilesUtil.GetTiles(grid, coordinates); if (!TilesUtil.CheckAndMarkTiles(tilesToMark, termTile)) { MessageBox.Show("Termini se ne mogu preklapati.", "Obaveštenje", MessageBoxButton.OK, MessageBoxImage.Information); return; } Grid.SetRow(termTile, row); Grid.SetRowSpan(termTile, newTileRowspan); Grid.SetColumn(termTile, column); grid.Children.Add(termTile); if (oldTermTile != null) { HandleOldTermTile(termTile, oldTermTile, grid); } e.Effects = DragDropEffects.Move; //na osnovu pozicije plocice cemo da provalimo novi termin termTile.UpdateTerm(); controller.CustomEvents.RaiseTutorialStepCompletedEvent(Steps.DRAG_AND_DROP_DONE); }