/// <summary> /// Updates Game, console, category and splits. /// </summary> /// <param name="g"></param> /// <param name="cat"></param> public void UpdateGUI(Game g, Category cat) { MainWindow.instance.Startbtn.IsEnabled = true; MainWindow.instance.Resetbtn.IsEnabled = true; MainWindow.instance.Splitbtn.IsEnabled = true; MainWindow.instance.Stopbtn.IsEnabled = true; GameTitle.Text = g.GetName(); ConsoleTitle.Text = g.GetConsole(); CategoryTitle.Text = cat.Name; if (SPLT.LoadedGame != null) { SOBTimeText.Text = SPLT.TimeSpanToString(SPLT.LoadedGame.CategoryList[0].SOBTime, false); PBTimeText.Text = SPLT.TimeSpanToString(SPLT.LoadedGame.CategoryList[0].PersonalBest, false); TargetTimeText.Text = SPLT.TimeSpanToString(SPLT.LoadedGame.CategoryList[0].TargetTime, false); } Splititemlist.Items.Clear(); foreach (Split s in cat.SplitList) { Splititemlist.Items.Add(s.GetTitle()); } switch (Preferences.DefaultComparisonSplits) { case 1: RunManager.WriteTargetTime(SPLT.LoadedGame.CategoryList[0].PBSplits); break; case 2: RunManager.WriteTargetTime(SPLT.LoadedGame.CategoryList[0].TargetSplits); break; case 3: RunManager.WriteTargetTime(SPLT.LoadedGame.CategoryList[0].SOBSplits); break; } }
/// <summary> /// Save button click function /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Save_Click(object sender, RoutedEventArgs e) { Game g = new Game(GameName.Text, ConsoleName.Text); Category c = new Category(g, CategoryName.Text); c.SplitList = SplitList; c.TargetSplits = TargetSplitList; g.CategoryList.Add(c); SPLT.WriteFile(Directory.GetCurrentDirectory() + "\\Data\\Games", g); MessageBox.Show("Saved split file to " + Directory.GetCurrentDirectory() + "\\Data\\Games", "Splitterino" + g.GetName() + ".splg", System.Windows.MessageBoxButton.OK); Close(); }
/// <summary> /// Writes target time to UI. Gets the targetsplits from passed on property /// </summary> /// <param name="sl"></param> public static void WriteTargetTime(List <Split> sl) { if (SPLT.LoadedGame != null) { TimeSpan tts = new TimeSpan(); for (int i = 0; i < sl.Count; i++) { tts += sl[i].Time; string a = SPLT.TimeSpanToString(tts, false); } } else { Debug.WriteLine("Loaded game is null"); } }
/// <summary> /// DispatchTimer Tick, for stopwatch. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void dt_Tick(object sender, EventArgs e) { if (sw.IsRunning) { TimeSpan ts = sw.Elapsed; currentTime = SPLT.TimeSpanToString(ts, false); //TODO //mitä vittua //CurrentRunCmprListbox.Items.Add(SPLT.TimeSpanToString(SPLT.CompareTS(sw.Elapsed, SPLT.CountTotalTime(SPLT.LoadedGame.CategoryList[0].PBSplits.GetRange(0, RunManager.CurrentSplitIndex + 1))), true)); if (SPLT.LoadedGame.CategoryList[0].PBSplits.Count > RunManager.CurrentSplitIndex) { List <Split> a = SPLT.LoadedGame.CategoryList[0].PBSplits.GetRange(0, RunManager.CurrentSplitIndex + 1); if (RunManager.CurrentSplitIndex < SPLT.LoadedGame.CategoryList[0].PBSplits.Count) { CurrentRunCmprListbox.Items[RunManager.CurrentSplitIndex] = SPLT.TimeSpanToString(SPLT.CompareTS(sw.Elapsed, SPLT.CountTotalTime(a)), true); } } //CurrentRunCmprListbox.Items[RunManager.CurrentSplitIndex] = CurrentRunCmprListbox.Items[RunManager.CurrentSplitIndex]; MainTimerDisplay.Text = currentTime; } }
private void SelectSplitBtn_Click(object sender, RoutedEventArgs e) { // Create OpenFileDialog Microsoft.Win32.OpenFileDialog dialog = new Microsoft.Win32.OpenFileDialog(); dialog.InitialDirectory = Directory.GetCurrentDirectory() + "\\Data\\"; // Set filter for file extension and default file extensi on dialog.DefaultExt = ".splt"; // Display OpenFileDialog by calling ShowDialog method Nullable <bool> result = dialog.ShowDialog(); // Get the selected file name and display in a TextBox if (result == true) { // Open document filename = dialog.FileName; SplitFileName.Text = filename; Debug.WriteLine(filename); RunManager.ClearUI(); SPLT.ReadAndPrint(filename); //SPLT.ReadAndPrint(System.IO.Directory.GetCurrentDirectory() + "\\Data\\" + g.GetName() + ".splt"); } }
public static void Split() { if (!MainWindow.instance.sw.IsRunning) { return; } //add current time to right list of splits MainWindow.instance.elapsedtimeitem.Items.Add(MainWindow.instance.currentTime); //save to var CurrentRunSplits.Add(new Split(MainWindow.instance.sw.Elapsed - lastTime, CurrentSplitIndex)); if (SPLT.LoadedGame != null) { //Jos Sum of Best splittejä on vähemmän kuin nykyinen splitti indexi if (SPLT.LoadedGame.CategoryList[0].SOBSplits.Count > CurrentSplitIndex) { //jos vanha SOB splittiaika on suurempi kuin nykyisen splitin aika niin tallenna splitti listaan. if (SPLT.LoadedGame.CategoryList[0].SOBSplits[CurrentSplitIndex].Time > MainWindow.instance.sw.Elapsed - lastTime) { SPLT.LoadedGame.CategoryList[0].SOBSplits[CurrentSplitIndex].Time = MainWindow.instance.sw.Elapsed - lastTime; Debug.WriteLine("Best segment! very nice job dude!"); } } else { SPLT.LoadedGame.CategoryList[0].SOBSplits.Add(new Split(MainWindow.instance.sw.Elapsed - lastTime, CurrentSplitIndex)); Debug.WriteLine("Best segment! very nice job dude!"); } } MainWindow.instance.ScrollSplitViewToBottom(); MainWindow.instance.splitCountBuffer++; if (MainWindow.instance.splitCountBuffer >= MainWindow.instance.Splititemlist.Items.Count) { if (SPLT.LoadedGame != null) { bool save = false; TimeSpan totes = TimeSpan.Zero; foreach (Split t in SPLT.LoadedGame.CategoryList[0].SOBSplits) { totes += t.Time; } if (totes != TimeSpan.Zero) { if (totes != SPLT.LoadedGame.CategoryList[0].SOBTime) { SPLT.LoadedGame.CategoryList[0].SOBTime = totes; save = true; } } if (SPLT.LoadedGame.CategoryList[0].PersonalBest > MainWindow.instance.sw.Elapsed || SPLT.LoadedGame.CategoryList[0].PersonalBest == TimeSpan.Zero) { Debug.WriteLine("PB !!!!!!!!!\n\n"); SPLT.LoadedGame.CategoryList[0].PersonalBest = MainWindow.instance.sw.Elapsed; SPLT.LoadedGame.CategoryList[0].PBSplits = CurrentRunSplits; save = true; } if (save) { SPLT.WriteFile(Directory.GetCurrentDirectory() + "\\Data\\Games\\", SPLT.LoadedGame); } } r.Time = MainWindow.instance.sw.Elapsed; r.Splits = CurrentRunSplits; SPLT.WriteRunToFile(Directory.GetCurrentDirectory() + "\\Data\\Runs\\", r); MainWindow.instance.sw.Stop(); MainWindow.instance.Splitbtn.IsEnabled = false; MainWindow.instance.Stopbtn.IsEnabled = false; MainWindow.instance.splitCountBuffer = 0; if (SPLT.LoadedGame != null) { MainWindow.instance.UpdateGUI(SPLT.LoadedGame, SPLT.LoadedGame.CategoryList[0]); } } lastTime = MainWindow.instance.sw.Elapsed; //toivottavasti toimii! if (SPLT.LoadedGame.CategoryList[0].PBSplits.Count > CurrentSplitIndex) { TimeSpan cmpr = SPLT.CountTotalTime(new List <Split>(SPLT.LoadedGame.CategoryList[0].PBSplits.GetRange(0, CurrentSplitIndex + 1))) - SPLT.CountTotalTime(CurrentRunSplits); string cmprTime = ""; if (cmpr.Ticks < 0) { cmpr.Negate(); cmprTime = "+"; } else { cmprTime = "-"; } cmprTime += SPLT.TimeSpanToString(cmpr, true); cmpr = TimeSpan.Zero; cmprTime = ""; } MainWindow.instance.CurrentRunCmprListbox.Items.Add(new CompareTimeClass("")); CurrentSplitIndex++; }
/// <summary> /// Loads preferences and updates the preferences tab with correct info. /// </summary> public static void LoadPreferences() { MainWindow.instance.ShowMSChkBox.IsChecked = ShowMS; if (WindowAlwaysOnTop) { MainWindow.instance.Topmost = true; MainWindow.instance.WindowAlwaysOnTopCheckBox.IsChecked = true; } else { MainWindow.instance.Topmost = false; MainWindow.instance.WindowAlwaysOnTopCheckBox.IsChecked = false; } try { if (DefaultGamePath != null) { SPLT.ReadAndPrint(DefaultGamePath); } else { MainWindow.instance.Startbtn.IsEnabled = false; MainWindow.instance.Resetbtn.IsEnabled = false; MainWindow.instance.Splitbtn.IsEnabled = false; MainWindow.instance.Stopbtn.IsEnabled = false; } } catch { Debug.WriteLine("failed to set defaultgame"); } try { switch (DefaultComparisonSplits) { case 1: MainWindow.instance.ComparisonTimeComboBox.SelectedIndex = 1; //MainWindow.instance.CurrentComparisonTime.SelectedIndex = 0; RunManager.WriteTargetTime(SPLT.LoadedGame.CategoryList[0].PBSplits); MainWindow.instance.ComparisonTimeComboBox.SelectedIndex = 1; break; case 2: MainWindow.instance.ComparisonTimeComboBox.SelectedIndex = 2; //MainWindow.instance.CurrentComparisonTime.SelectedIndex = 1; RunManager.WriteTargetTime(SPLT.LoadedGame.CategoryList[0].TargetSplits); MainWindow.instance.ComparisonTimeComboBox.SelectedIndex = 2; break; case 3: MainWindow.instance.ComparisonTimeComboBox.SelectedIndex = 3; //MainWindow.instance.CurrentComparisonTime.SelectedIndex = 2; RunManager.WriteTargetTime(SPLT.LoadedGame.CategoryList[0].SOBSplits); MainWindow.instance.ComparisonTimeComboBox.SelectedIndex = 3; break; } } catch { Debug.WriteLine("Failed to set defaultComparisonSplits"); } try { MainWindow.instance.TargetTimeText.Text = SPLT.TimeSpanToString(DefaultTargetTime, false); } catch { Debug.WriteLine("Failed to set defaultTargetTime"); } if (SavePrefsOnQuit) { MainWindow.instance.SavePreferencesOnQuitChkBox.IsChecked = true; } else { MainWindow.instance.SavePreferencesOnQuitChkBox.IsChecked = false; } }