/// <summary> /// 企图关闭一个当前的View,当存在当前View时候,并且传入的View是需要Dispatch的。 /// </summary> private void MaybeCloseTopView(View.State rViewState) { // 得到顶层结点 CKeyValuePair <string, View> rTopNode = null; if (this.mCurPageViews.Count > 0) { rTopNode = this.mCurPageViews.Last(); } if (rTopNode == null) { return; } string rViewGUID = rTopNode.Key; View rView = rTopNode.Value; if (rView == null) { return; } if (rViewState == View.State.PageSwitch) { // 移除顶层结点 this.mCurPageViews.Remove(rViewGUID); rView.Close(); DestroyView(rView); } }
/// <summary> /// 移除顶层View /// </summary> public void Pop(Action rCloseComplted = null) { // 得到顶层结点 CKeyValuePair <string, View> rTopNode = this.mCurPageViews.Last(); if (rTopNode == null) { UtilTool.SafeExecute(rCloseComplted); return; } string rViewGUID = rTopNode.Key; View rView = rTopNode.Value; if (rView == null) { UtilTool.SafeExecute(rCloseComplted); return; } // 移除顶层结点 this.mCurPageViews.Remove(rViewGUID); rView.Close(); DestroyView(rView); UtilTool.SafeExecute(rCloseComplted); }
/// <summary> /// 企图关闭一个当前的View,当存在当前View时候,并且传入的View是需要Dispatch的。 /// </summary> private void MaybeCloseTopView(View.State rViewState) { // 得到顶层结点 CKeyValuePair <string, View> rTopNode = null; if (this.mCurFixedViews.Count > 0) { rTopNode = this.mCurViews.Last(); } if (rTopNode == null) { return; } string rViewGUID = rTopNode.Key; View rView = rTopNode.Value; if (rView == null) { return; } if (rViewState == View.State.dispatch) { // 移除顶层结点 this.mCurViews.Remove(rViewGUID); rView.Close(); CoroutineManager.Instance.Start(DestroyView_Async(rView)); } }
/// <summary> /// 移除顶层View /// </summary> public void Pop(Action rCloseComplted = null) { // 得到顶层结点 CKeyValuePair <string, View> rTopNode = this.mCurViews.Last(); string rViewGUID = rTopNode.Key; View rView = rTopNode.Value; if (rView == null) { UtilTool.SafeExecute(rCloseComplted); return; } // 移除顶层结点 this.mCurViews.Remove(rViewGUID); rView.Close(); CoroutineManager.Instance.Start(DestroyView_Async(rView, () => { UtilTool.SafeExecute(rCloseComplted); })); }
private async void btnAddGameSubmit_Click(object sender, RoutedEventArgs e) { // Stop if there is no tournament selected if (itemListView.SelectedIndex == -1) { return; } TournamentRound selectedRound = itemListView.SelectedItem as TournamentRound; // We can add the game from the details they have provided usually // First check they have selected if (cmbAddGameGames.SelectedIndex == -1 || cmbAddGameOutcome.SelectedIndex == -1) { return; } // The combobox item for addGameGames should be named in the form WhitePlayerID:BlackPlayerID string matchDetails = (cmbAddGameGames.SelectedItem as ComboBoxItem).Name; string[] matchDetailsSplit = matchDetails.Split(new char[] { ':' }); int whitePlayerID = int.Parse(matchDetailsSplit[0]); int blackPlayerID = int.Parse(matchDetailsSplit[1]); CKeyValuePair <int, int> selectedGame = selectedRound.PlannedMatches.Where(x => x.Key == whitePlayerID && x.Val == blackPlayerID).First(); // We have the selected game and all details required to insert it into the database and update the tournament selectedRound.PlannedMatches.Remove(selectedGame); Game game = new Game(); await game.Initialize(); game.WhitePlayerID = whitePlayerID; game.BlackPlayerID = blackPlayerID; game.BlackPlayerELO = game.BlackPlayer.ELO; game.WhitePlayerELO = game.WhitePlayer.ELO; game.BlackPlayerKFactor = game.BlackPlayer.K_Factor; game.WhitePlayerKFactor = game.WhitePlayer.K_Factor; switch ((cmbAddGameOutcome.SelectedItem as ComboBoxItem).Name) { case "checkW": // Remove loser from tournament selectedRound.Tournament.RemainingContestantIDs.Remove(blackPlayerID); game.Outcome = Enums.Outcome.WHITE_WIN; break; case "checkB": // Remove loser from tournament selectedRound.Tournament.RemainingContestantIDs.Remove(whitePlayerID); game.Outcome = Enums.Outcome.BLACK_WIN; break; case "resignW": // Remove loser from tournament selectedRound.Tournament.RemainingContestantIDs.Remove(blackPlayerID); game.Outcome = Enums.Outcome.BLACK_RESIGN; break; case "resignB": // Remove loser from tournament selectedRound.Tournament.RemainingContestantIDs.Remove(whitePlayerID); game.Outcome = Enums.Outcome.WHITE_RESIGN; break; } // Find the most recent session Session mostRecent = null; foreach (Session session in App.db.Sessions) { if (mostRecent == null || session.Date < DateTime.Now && session.Date > mostRecent.Date) { mostRecent = session; } } game.ApplyELOChange(); game.SessionID = mostRecent.ID; selectedRound.GameIDs.Add(game.ID); // Check if the tournament has been won if (selectedRound.Tournament.RemainingContestantIDs.Count == 1) { selectedRound.Tournament.WinnerID = selectedRound.Tournament.RemainingContestantIDs.First(); // Award them the prize ELO selectedRound.Tournament.Winner.ELO += selectedRound.Tournament.ELOPrize; } App.db.Games.Add(game); App.db.SaveData(); grdGames.ItemsSource = selectedRound.Games; brdAddGame.Visibility = Visibility.Collapsed; }