private void Model_HistoryChanged(object sender, HistoryChangedEventArgs e) { Dispatcher.BeginInvoke(new Action(() => { try { ViewModel.Board.History.ClearAndAddHistoryItems(e.Items); try { ignoreChange = true; Result <int, ErrorDefinitions.Error> result = Controller.tryPopMoveNumberFromUndoStack(); if (result.IsSuccess) { int id = ((Result <int, ErrorDefinitions.Error> .Success)result).Item; MoveHistoryItem item = ViewModel.Board.History.FirstOrDefault(i => i.ID == id); history.SelectedItem = item; } else { history.SelectedItem = null; } } finally { ignoreChange = false; } } catch (Exception exc) { MessageBox.Show(this, string.Format("Nepodařilo se aktualizovat historii tahů: {0}", ViewModelCommon.ConvertExceptionToShortString(exc)), "Chyba", MessageBoxButton.OK, MessageBoxImage.Error); } }), System.Windows.Threading.DispatcherPriority.Background); }
private void History_SelectionChanged(object sender, SelectionChangedEventArgs e) { e.Handled = true; try { if (!ignoreChange) { MoveHistoryItem item = e.AddedItems.OfType <MoveHistoryItem>().FirstOrDefault(); if (item != null) { ModelException.TryThrow <GameController.T>(Controller.TryGoToMove(item.ID)); } } } catch (Exception exc) { MessageBox.Show(this, "Nelze přejít na tah z historie." + Environment.NewLine + ViewModelCommon.ConvertExceptionToShortString(exc), "Chyba", MessageBoxButton.OK, MessageBoxImage.Error); } }
IEnumerator MoveToDirection(Direction dir, int height, bool isRewind) { if (isRewind) { yield return(new WaitUntil(() => PlayerScript.allowRotate)); } stillMoving = true; Vector3 roundedPos = GameController.RoundedPos(transform.parent.position); switch (dir) { case Direction.Forward: targetPos = roundedPos + Vector3.forward; break; case Direction.Back: targetPos = roundedPos - Vector3.forward; break; case Direction.Left: targetPos = roundedPos - Vector3.right; break; case Direction.Right: targetPos = roundedPos + Vector3.right; break; } targetPos = new Vector3(targetPos.x, height, targetPos.z); transform.parent.position = new Vector3(transform.parent.position.x, height, transform.parent.position.z); Vector3 roundedTargetPos = GameController.RoundedPos(targetPos); moveToTargetPosition = true; bool floorIsEnabled; MoveHistoryItem move = new MoveHistoryItem(dir, colorCon.thisColorIndex, (int)transform.eulerAngles.y, (int)roundedTargetPos.y); if (!game.allowedLocations.TryGetValue(roundedTargetPos - Vector3.up, out floorIsEnabled) || !floorIsEnabled) { Pre_OutOfBounds(); } if (!isRewind) { if (!moveHistory.ContainsKey(PlayerScript.moveCount)) { moveHistory.Add(PlayerScript.moveCount, move); } else { print("BIG BUG"); moveHistory.Remove(PlayerScript.moveCount); moveHistory.Add(PlayerScript.moveCount, new MoveHistoryItem(dir, colorCon.thisColorIndex, (int)transform.eulerAngles.y, (int)roundedTargetPos.y)); } } yield return(new WaitUntil(() => !moveToTargetPosition)); yield return(new WaitUntil(() => PlayerScript.allowRotate)); if (isGonnaFall) { isBlockBelow = false; for (int i = (int)targetPos.y - 1; i >= lowest; i--) { Vector3 locationBelow = new Vector3(targetPos.x, i, targetPos.z); if (game.allowedLocations.TryGetValue(locationBelow, out floorIsEnabled) && floorIsEnabled) { isBlockBelow = true; FallTo(i + 1); moveHistory.Remove(PlayerScript.moveCount - 1); moveHistory.Add(PlayerScript.moveCount - 1, new MoveHistoryItem(dir, colorCon.thisColorIndex, (int)transform.eulerAngles.y, (int)positionAtFall.y)); //yield return new WaitWhile(()=> stillMoving); break; } } if (!isBlockBelow) { OutOfBounds(); } } transform.parent.position = targetPos; //yield return new WaitUntil(() => disintegration.doneDisintegrating); if (!disintegration.doneDisintegrating) { disintegration.StartCoroutine("Disintegrate"); } isGonnaFall = false; stillMoving = false; }