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> /// 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; } }