public static string FormatLarge(Seed seed) { return($"Вкус: {seed.Taste}\n\n" + $"Габитус: {seed.Gabitus}\n\n" + $"Время роста: {TimeFormatter.Format(seed.GrowTime)}\n\n" + $"Цена: {seed.Price}<sprite name=\"Money\">\n"); }
private void Grid_SplitSettings_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) { if (e.RowIndex < splitToEventList.Count) { if (e.ColumnIndex == COLUMNINDEX_SEGMENTNAME) { e.Value = splitToEventList[e.RowIndex].SegmentName; } else if (e.ColumnIndex == COLUMNINDEX_EVENT) { e.Value = SplitsToEvents.GetEnumDescription(splitToEventList[e.RowIndex].EventType); } else if (e.ColumnIndex == COLUMNINDEX_DELAY) { var comparisonValue = splitToEventList[e.RowIndex].Delay; e.Value = TimeFormatter.Format(TimeSpan.FromSeconds(comparisonValue)); e.FormattingApplied = true; } else if (e.ColumnIndex == COLUMNINDEX_ACTION) { bool eventUsed = splitToEventList[e.RowIndex].Action.isUsed && splitToEventList[e.RowIndex].EventType == SplitEventType.StartPredictionOnSplitStart; e.Value = eventUsed ? "!" : ""; e.CellStyle.BackColor = eventUsed ? Color.Red : Color.Transparent; } } }
private string sumOfBestComponent() { var comparison = State.CurrentComparison; var method = State.CurrentTimingMethod; var sob = SumOfBest.CalculateSumOfBest(State.Run, State.Settings.SimpleSumOfBest, true, State.CurrentTimingMethod); return(formatInfoText("Sum of Best", TimeFormatter.Format(sob)) + "\n"); }
public RunTimeStatistic() { ValueFunc = () => { var timeSpan = GetTimeSpan(); return(timeSpan == null ? null : TimeFormatter.Format(timeSpan.Value)); }; }
private void DoWork(object o, DoWorkEventArgs e) { algorithmWorker.ReportProgress(0, 0); var fullRunTime = new RunTimeStatistic(); Statistics.Put("Running time", fullRunTime); fullRunTime.Start(); Statistics.Put("Average running time", () => { var ticks = fullRunTime.GetTimeSpan()?.Ticks; return(ticks != null ? TimeFormatter.Format(new TimeSpan(ticks.Value / NumIterations)) : ""); }); //Statistics.Put("Average running time (s)", () => //{ // var timeSpan = fullRunTime.GetTimeSpan(); // if (timeSpan != null) // { // var seconds = timeSpan.Value.Seconds + (double) timeSpan.Value.Milliseconds / 1000; // return (seconds / NumIterations).ToString(CultureInfo.InvariantCulture); // } // return ""; //}); for (var it = 1; it <= NumIterations; it++) { if (algorithmWorker.CancellationPending) { e.Cancel = true; return; } var iterationRunTime = new RunTimeStatistic(); Statistics.Put("Running time - Iteration " + it, iterationRunTime); iterationRunTime.Start(); if (it == 1) { Algorithm.Compute(Input, out Output); } else { TOut outp; Algorithm.Compute(Input, out outp); } iterationRunTime.End(); algorithmWorker.ReportProgress(it / NumIterations * 100, it); } fullRunTime.End(); }
public void Format_ReturnsStringWithHourAndMinuteOnly() { // Arrange TimeFormatter target = new TimeFormatter(); // Act string result = target.Format(new DateTime(2015, 10, 12, 9, 20, 0)); // Assert result.Should().Be("9:20"); }
/// <summary> /// Обновляет время, оставшееся до нового задания /// </summary> private void Update() { if (!renderTasksHere) { return; } var secondsRemaining = (cooldownEnd - DateTime.Now).TotalSeconds; timeLabel.text = secondsRemaining >= 0 ? $"До нового задания осталось {TimeFormatter.Format((int) secondsRemaining)}" : "Доступно новое задание!"; if (taskAddBtnIsRendered || !(secondsRemaining < 0)) { return; } Instantiate(taskAddPrefab, transform); taskAddBtnIsRendered = true; }
public void ReturnsOneSecond() { var result = TimeFormatter.Format(new TimeSpan(0, 0, 1)); Assert.AreEqual("1 second ago", result); }
public void IgnoresMinutesAndSecondsWhenReturningHours() { var result = TimeFormatter.Format(new TimeSpan(3, 4, 5)); Assert.AreEqual("3 hours ago", result); }
private void DrawGeneral(Graphics g, LiveSplitState state, float width, float height, LayoutMode mode) { if (NeedUpdateAll) { UpdateAll(state); } if (Settings.BackgroundGradient == ExtendedGradientType.Alternating) { g.FillRectangle(new SolidBrush( state.Run.IndexOf(Split) % 2 + (Settings.ShowColumnLabels ? 1 : 0) == 1 ? Settings.BackgroundColor2 : Settings.BackgroundColor ), 0, 0, width, height); } MeasureTimeLabel.Text = TimeFormatter.Format(new TimeSpan(24, 0, 0)); MeasureDeltaLabel.Text = DeltaTimeFormatter.Format(new TimeSpan(0, 9, 0, 0)); MeasureTimeLabel.Font = state.LayoutSettings.TimesFont; MeasureTimeLabel.IsMonospaced = true; MeasureDeltaLabel.Font = state.LayoutSettings.TimesFont; MeasureDeltaLabel.IsMonospaced = true; MeasureTimeLabel.SetActualWidth(g); MeasureDeltaLabel.SetActualWidth(g); NameLabel.ShadowColor = state.LayoutSettings.ShadowsColor; foreach (var label in LabelsList) { label.SetActualWidth(g); label.ShadowColor = state.LayoutSettings.ShadowsColor; } MinimumWidth = CalculateLabelsWidth() + IconWidth + 10; MinimumHeight = 0.85f * (g.MeasureString("A", state.LayoutSettings.TimesFont).Height + g.MeasureString("A", state.LayoutSettings.TextFont).Height); if (Settings.SplitTimesAccuracy != CurrentAccuracy) { TimeFormatter = new RegularSplitTimeFormatter(Settings.SplitTimesAccuracy); CurrentAccuracy = Settings.SplitTimesAccuracy; } if (Settings.DeltasAccuracy != CurrentDeltaAccuracy || Settings.DropDecimals != CurrentDropDecimals) { DeltaTimeFormatter = new DeltaSplitTimeFormatter(Settings.DeltasAccuracy, Settings.DropDecimals); CurrentDeltaAccuracy = Settings.DeltasAccuracy; CurrentDropDecimals = Settings.DropDecimals; } if (Split != null) { if (mode == LayoutMode.Vertical) { NameLabel.VerticalAlignment = StringAlignment.Center; NameLabel.Y = 0; NameLabel.Height = height; foreach (var label in LabelsList) { label.VerticalAlignment = StringAlignment.Center; label.Y = 0; label.Height = height; } } else { NameLabel.VerticalAlignment = StringAlignment.Near; NameLabel.Y = 0; NameLabel.Height = 50; foreach (var label in LabelsList) { label.VerticalAlignment = StringAlignment.Far; label.Y = height - 50; label.Height = 50; } } if (IsActive) { var currentSplitBrush = new LinearGradientBrush( new PointF(0, 0), Settings.CurrentSplitGradient == GradientType.Horizontal ? new PointF(width, 0) : new PointF(0, height), Settings.CurrentSplitTopColor, Settings.CurrentSplitGradient == GradientType.Plain ? Settings.CurrentSplitTopColor : Settings.CurrentSplitBottomColor); g.FillRectangle(currentSplitBrush, 0, 0, width, height); } if (DisplayIcon) { var icon = Split.Icon ?? NoIconImage; var shadow = (Split.Icon != null) ? ShadowImage : NoIconShadow; /*if (DateTime.Now.Date.Month == 4 && DateTime.Now.Date.Day == 1) * { * icon = LiveSplit.Web.Share.TwitchEmoteResolver.Resolve("Kappa", true, false, false); * shadow = null; * }*/ if (OldImage != icon) { ImageAnimator.Animate(icon, (s, o) => { }); ImageAnimator.Animate(shadow, (s, o) => { }); OldImage = icon; } var drawWidth = Settings.IconSize; var drawHeight = Settings.IconSize; var shadowWidth = Settings.IconSize * (5 / 4f); var shadowHeight = Settings.IconSize * (5 / 4f); if (icon.Width > icon.Height) { var ratio = icon.Height / (float)icon.Width; drawHeight *= ratio; shadowHeight *= ratio; } else { var ratio = icon.Width / (float)icon.Height; drawWidth *= ratio; shadowWidth *= ratio; } ImageAnimator.UpdateFrames(shadow); if (Settings.IconShadows && shadow != null) { g.DrawImage( shadow, 7 + (Settings.IconSize * (5 / 4f) - shadowWidth) / 2 - 0.7f, (height - Settings.IconSize) / 2.0f + (Settings.IconSize * (5 / 4f) - shadowHeight) / 2 - 0.7f, shadowWidth, shadowHeight); } ImageAnimator.UpdateFrames(icon); g.DrawImage( icon, 7 + (Settings.IconSize - drawWidth) / 2, (height - Settings.IconSize) / 2.0f + (Settings.IconSize - drawHeight) / 2, drawWidth, drawHeight); } NameLabel.Font = state.LayoutSettings.TextFont; NameLabel.X = 5 + IconWidth; NameLabel.HasShadow = state.LayoutSettings.DropShadows; if (ColumnsList.Count() == LabelsList.Count) { var curX = width - 7; var nameX = width - 7; foreach (var label in LabelsList.Reverse()) { var column = ColumnsList.ElementAt(LabelsList.IndexOf(label)); var labelWidth = 0f; if (column.Type == ColumnType.DeltaorSplitTime || column.Type == ColumnType.SegmentDeltaorSegmentTime) { labelWidth = Math.Max(MeasureDeltaLabel.ActualWidth, MeasureTimeLabel.ActualWidth); } else if (column.Type == ColumnType.Delta || column.Type == ColumnType.SegmentDelta) { labelWidth = MeasureDeltaLabel.ActualWidth; } else { labelWidth = MeasureTimeLabel.ActualWidth; } label.Width = labelWidth + 20; curX -= labelWidth + 5; label.X = curX - 15; label.Font = state.LayoutSettings.TimesFont; label.HasShadow = state.LayoutSettings.DropShadows; label.IsMonospaced = true; label.Draw(g); if (!String.IsNullOrEmpty(label.Text)) { nameX = curX + labelWidth + 5 - label.ActualWidth; } } NameLabel.Width = (mode == LayoutMode.Horizontal ? width - 10 : nameX) - IconWidth; NameLabel.Draw(g); } } else { DisplayIcon = Settings.DisplayIcons; } }
public void ReturnsOneHour() { var result = TimeFormatter.Format(new TimeSpan(1, 0, 0)); Assert.AreEqual("1 hour ago", result); }
public void ReturnsTwoHours() { var result = TimeFormatter.Format(new TimeSpan(2, 0, 0)); Assert.AreEqual("2 hours ago", result); }
public void ReturnsFiveMinutes() { var result = TimeFormatter.Format(new TimeSpan(0, 5, 0)); Assert.AreEqual("5 minutes ago", result); }
public void IgnoresSecondsWhenReturningMinutes() { var result = TimeFormatter.Format(new TimeSpan(0, 12, 33)); Assert.AreEqual("12 minutes ago", result); }
protected void UpdateAll(LiveSplitState state) { if (Split == null) { RacerName.Text = RaceIndex + ": N/A"; RacerSplit.Text = ""; RacerTime.Text = TimeFormatter.Format(null); } else { RacerName.Text = RaceIndex + ": " + Split.Name; RacerSplit.Text = Split.SplitName + (Split.SubSplitIndex == int.MaxValue ? "" : " - " + Split.SubSplitIndex); RacerTime.Text = TimeFormatter.Format(Split.SplitTime.RealTime); } RacerName.ForeColor = Settings.TextColor; RacerSplit.ForeColor = Settings.TextColor; RacerTime.ForeColor = Settings.TextColor; TimeSpan?delta = null; Color color = state.LayoutSettings.TextColor; if (Split != null && Split != Parent.Comparison && Split.SplitTime.RealTime.HasValue && state.CurrentTime.RealTime.HasValue) { if (Split.SplitIndex == Parent.Comparison.SplitIndex && Split.SubSplitIndex == Parent.Comparison.SubSplitIndex) { delta = Split.SplitTime.RealTime.Value - Parent.Comparison.SplitTime.RealTime.GetValueOrDefault(state.CurrentTime.RealTime.Value); } else if (Split.SplitIndex > Parent.Comparison.SplitIndex || (Split.SplitIndex == Parent.Comparison.SplitIndex && Split.SubSplitIndex > Parent.Comparison.SubSplitIndex)) { RaceSplit history = null; if (Parent.Watcher.RaceSplits.TryGetValue(Split.Name + "|" + Parent.Comparison.SplitIndex + "|" + Parent.Comparison.SubSplitIndex, out history)) { delta = history.SplitTime.RealTime.Value - Parent.Comparison.SplitTime.RealTime.Value; } } else if (Split.SplitIndex < Parent.Comparison.SplitIndex || (Split.SplitIndex == Parent.Comparison.SplitIndex && Split.SubSplitIndex < Parent.Comparison.SubSplitIndex)) { RaceSplit history = null; if (Parent.Watcher.RaceSplits.TryGetValue(Parent.Comparison.Name + "|" + Split.SplitIndex + "|" + Split.SubSplitIndex, out history)) { delta = Split.SplitTime.RealTime.Value - history.SplitTime.RealTime.Value; } } if (delta != null) { if (delta.Value.Ticks < 0) { color = state.LayoutSettings.AheadGainingTimeColor; } else { color = state.LayoutSettings.BehindLosingTimeColor; } } } RacerDelta.Text = DeltaTimeFormatter.Format(delta); int currentIndex = 0; for (int i = 0; i < state.Run.Count; i++) { if (state.Run[i] == state.CurrentSplit) { currentIndex = i; } } if (currentIndex > 0) { currentIndex--; } RacerDelta.ForeColor = color; }
public void ReturnsOneMinute() { var result = TimeFormatter.Format(new TimeSpan(0, 1, 0)); Assert.AreEqual("1 minute ago", result); }
private void DrawGeneral(Graphics g, LiveSplitState state, float width, float height, LayoutMode mode) { if (Settings.BackgroundGradient == ExtendedGradientType.Alternating) { g.FillRectangle(new SolidBrush( Settings.BackgroundColor ), 0, 0, width, height); } MeasureTimeLabel.Text = TimeFormatter.Format(new TimeSpan(24, 0, 0)); MeasureDeltaLabel.Text = DeltaTimeFormatter.Format(new TimeSpan(0, 9, 0, 0)); MeasureTimeLabel.Font = state.LayoutSettings.TimesFont; MeasureTimeLabel.IsMonospaced = true; MeasureDeltaLabel.Font = state.LayoutSettings.TimesFont; MeasureDeltaLabel.IsMonospaced = true; MeasureTimeLabel.SetActualWidth(g); MeasureDeltaLabel.SetActualWidth(g); if (Settings.SplitTimesAccuracy != CurrentAccuracy) { TimeFormatter = new RegularSplitTimeFormatter(Settings.SplitTimesAccuracy); CurrentAccuracy = Settings.SplitTimesAccuracy; } if (Settings.DeltasAccuracy != CurrentDeltaAccuracy || Settings.DropDecimals != CurrentDropDecimals) { DeltaTimeFormatter = new DeltaSplitTimeFormatter(Settings.DeltasAccuracy, Settings.DropDecimals); CurrentDeltaAccuracy = Settings.DeltasAccuracy; CurrentDropDecimals = Settings.DropDecimals; } foreach (var label in LabelsList) { label.ShadowColor = state.LayoutSettings.ShadowsColor; label.Y = 0; label.Height = height; } MinimumWidth = 10f; if (ColumnsList.Count() == LabelsList.Count) { var curX = width - 7; foreach (var label in LabelsList.Reverse()) { var column = ColumnsList.ElementAt(LabelsList.IndexOf(label)); var labelWidth = 0f; if (column.Type == ColumnType.DeltaorSplitTime || column.Type == ColumnType.SegmentDeltaorSegmentTime) { labelWidth = Math.Max(MeasureDeltaLabel.ActualWidth, MeasureTimeLabel.ActualWidth); } else if (column.Type == ColumnType.Delta || column.Type == ColumnType.SegmentDelta) { labelWidth = MeasureDeltaLabel.ActualWidth; } else { labelWidth = MeasureTimeLabel.ActualWidth; } curX -= labelWidth + 5; label.Width = labelWidth; label.X = curX + 5; label.Font = state.LayoutSettings.TextFont; label.HasShadow = state.LayoutSettings.DropShadows; label.Draw(g); } } }
public void UpdatePresence(LiveSplitState state) { DeltaFormatter.Accuracy = Settings.Accuracy; DeltaFormatter.DropDecimals = Settings.DropDecimals; string GlobalComparison = Settings.Comparison; if (GlobalComparison == "Current Comparison") { GlobalComparison = state.CurrentComparison; } TimerPhase RunState = state.CurrentPhase; string CategoryName = state.Run.CategoryName; string DetailedCategoryName = state.Run.GetExtendedCategoryName(); string GameName = state.Run.GameName; string ShortGameName = state.Run.GameName.GetAbbreviations().Last(); TimeSpan?delta = TimeSpan.Zero; if (RunState == TimerPhase.NotRunning && Settings.NRClearActivity) { activityManager.ClearActivity((res) => { if (res != Result.Ok) { throw new ResultException(res); } }); return; } string RunningImage = "gray_square"; string SplitName = ""; if (RunState == TimerPhase.Running || RunState == TimerPhase.Paused) { SplitName = state.CurrentSplit.Name; // Want to do more with this, maybe more advanced formatting. For now, simple removal. if (Settings.SubSplitCount && SplitName.Length > 0) { int bracket1 = SplitName.IndexOf("{"); int bracket2 = SplitName.IndexOf("}"); if (SplitName.Substring(0, 1) == "-") { SplitName = SplitName.Substring(1); } if ((bracket1 != -1 && bracket2 != -1) && SplitName.Length > bracket2) { SplitName = SplitName.Substring(bracket2 + 1); } } } if (RunState != TimerPhase.NotRunning) { var timestring = ""; if (state.CurrentSplitIndex > 0) { GetDelta(GlobalComparison); } if (RunState != TimerPhase.Paused && timestring.Length > 0) { RunningImage = timestring.Substring(0, 1) == "+" ? "red_square" : "green_square"; } } long StartTime = 0; if (Settings.DisplayElapsedTimeType == ElapsedTimeType.DisplayAttemptDuration || Settings.DisplayElapsedTimeType == ElapsedTimeType.DisplayADwOffset) { DateTime sTime = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); StartTime = (long)(state.AttemptStarted - sTime).TotalSeconds; if (Settings.DisplayElapsedTimeType == ElapsedTimeType.DisplayADwOffset) { StartTime -= (long)state.Run.Offset.TotalSeconds; } } else if (Settings.DisplayElapsedTimeType == ElapsedTimeType.DisplayGameTime) { StartTime = DateTime.UtcNow.Ticks - (long)state.CurrentTime[state.CurrentTimingMethod].Value.TotalSeconds; } var activity = new Activity { Details = CheckText("Details"), State = CheckText("State"), Assets = { LargeImage = "livesplit_icon", LargeText = CheckText("largeImage") } }; if (Settings.Comparison != NoneComparisonGenerator.ComparisonName) { activity.Assets.SmallText = CheckText("smallImage"); activity.Assets.SmallImage = RunningImage; } if (RunState == TimerPhase.Running && (int)Settings.DisplayElapsedTimeType >= 1) { activity.Timestamps.Start = StartTime; } activityManager.UpdateActivity(activity, (res) => { if (res != Result.Ok) { throw new ResultException(res); } }); string CheckText(string item) { string text = GetText(item); if (text == "%inherit") { text = GetText(item, true); if (text.Contains("%delta") || text.Contains("%split")) { if (RunState == TimerPhase.NotRunning) { return("Not Running"); } else if (RunState == TimerPhase.Ended) { return("Ended. Final Time: " + TimeFormatter.Format(state.CurrentTime[state.CurrentTimingMethod])); } else if (RunState == TimerPhase.Paused) { return("Paused"); } else { text = FindDelta(text); text = text.Replace("%split", SplitName); } } } else { text = FindDelta(text); text = text.Replace("%split", SplitName); } text = text.Replace("%game_short", ShortGameName); text = text.Replace("%game", GameName); text = text.Replace("%category_detailed", DetailedCategoryName); text = text.Replace("%category", CategoryName); text = text.Replace("%attempts", state.Run.AttemptCount.ToString()); text = text.Replace("%comparison", GlobalComparison); text = text.Replace("%time", TimeFormatter.Format(state.CurrentTime[state.CurrentTimingMethod])); return(text); } string GetText(string item, bool GetRunning = false) { if (RunState == TimerPhase.Running || GetRunning) { if (item == "Details") { return(Settings.Details); } else if (item == "State") { return(Settings.State); } else if (item == "largeImage") { return(Settings.largeImageKey); } else { return(Settings.smallImageKey); } } else if (RunState == TimerPhase.NotRunning) { if (item == "Details") { return(Settings.NRDetails); } else if (item == "State") { return(Settings.NRState); } else if (item == "largeImage") { return(Settings.NRlargeImageKey); } else { return(Settings.NRsmallImageKey); } } else if (RunState == TimerPhase.Ended) { if (item == "Details") { return(Settings.EDetails); } else if (item == "State") { return(Settings.EState); } else if (item == "largeImage") { return(Settings.ElargeImageKey); } else { return(Settings.EsmallImageKey); } } else { if (item == "Details") { return(Settings.PDetails); } else if (item == "State") { return(Settings.PState); } else if (item == "largeImage") { return(Settings.PlargeImageKey); } else { return(Settings.PsmallImageKey); } } } string GetDelta(string Comparison) { int SplitIndex = (RunState == TimerPhase.Ended ? state.CurrentSplitIndex - 1 : state.CurrentSplitIndex); delta = LiveSplitStateHelper.GetLastDelta(state, SplitIndex, Comparison, state.CurrentTimingMethod); return(DeltaFormatter.Format(delta)); } string FindDelta(string SearchText) { if (SearchText.IndexOf("%delta_") != -1) { SearchText = SearchText.Replace("%delta_cur", GetDelta(state.CurrentComparison)); foreach (KeyValuePair <string, string> deltaCheck in ComparisonDict) { SearchText = SearchText.Replace(deltaCheck.Key, GetDelta(deltaCheck.Value)); } } SearchText = SearchText.Replace("%delta", GetDelta(GlobalComparison)); return(SearchText); } }
public string Format(TimeFormatter formatter) { return(formatter.Format(this.Value)); }
protected void UpdateColumn(LiveSplitState state, SimpleLabel label, ColumnData data) { var comparison = data.Comparison == "Current Comparison" ? state.CurrentComparison : data.Comparison; if (!state.Run.Comparisons.Contains(comparison)) { comparison = state.CurrentComparison; } var timingMethod = state.CurrentTimingMethod; if (data.TimingMethod == "Real Time") { timingMethod = TimingMethod.RealTime; } else if (data.TimingMethod == "Game Time") { timingMethod = TimingMethod.GameTime; } var type = data.Type; var splitIndex = state.Run.IndexOf(Split); if (splitIndex < state.CurrentSplitIndex) { if (type == ColumnType.SplitTime || type == ColumnType.SegmentTime) { label.ForeColor = Settings.OverrideTimesColor ? Settings.BeforeTimesColor : state.LayoutSettings.TextColor; if (type == ColumnType.SplitTime) { label.Text = TimeFormatter.Format(Split.SplitTime[timingMethod]); } else //SegmentTime { var segmentTime = LiveSplitStateHelper.GetPreviousSegmentTime(state, splitIndex, timingMethod); label.Text = TimeFormatter.Format(segmentTime); } } if (type == ColumnType.DeltaorSplitTime || type == ColumnType.Delta) { var deltaTime = Split.SplitTime[timingMethod] - Split.Comparisons[comparison][timingMethod]; var color = LiveSplitStateHelper.GetSplitColor(state, deltaTime, splitIndex, true, true, comparison, timingMethod); if (color == null) { color = Settings.OverrideTimesColor ? Settings.BeforeTimesColor : state.LayoutSettings.TextColor; } label.ForeColor = color.Value; if (type == ColumnType.DeltaorSplitTime) { if (deltaTime != null) { label.Text = DeltaTimeFormatter.Format(deltaTime); } else { label.Text = TimeFormatter.Format(Split.SplitTime[timingMethod]); } } else if (type == ColumnType.Delta) { label.Text = DeltaTimeFormatter.Format(deltaTime); } } else if (type == ColumnType.SegmentDeltaorSegmentTime || type == ColumnType.SegmentDelta) { var segmentDelta = LiveSplitStateHelper.GetPreviousSegmentDelta(state, splitIndex, comparison, timingMethod); var color = LiveSplitStateHelper.GetSplitColor(state, segmentDelta, splitIndex, false, true, comparison, timingMethod); if (color == null) { color = Settings.OverrideTimesColor ? Settings.BeforeTimesColor : state.LayoutSettings.TextColor; } label.ForeColor = color.Value; if (type == ColumnType.SegmentDeltaorSegmentTime) { if (segmentDelta != null) { label.Text = DeltaTimeFormatter.Format(segmentDelta); } else { label.Text = TimeFormatter.Format(LiveSplitStateHelper.GetPreviousSegmentTime(state, splitIndex, timingMethod)); } } else if (type == ColumnType.SegmentDelta) { label.Text = DeltaTimeFormatter.Format(segmentDelta); } } } else { if (type == ColumnType.SplitTime || type == ColumnType.SegmentTime || type == ColumnType.DeltaorSplitTime || type == ColumnType.SegmentDeltaorSegmentTime) { if (Split == state.CurrentSplit) { label.ForeColor = Settings.OverrideTimesColor ? Settings.CurrentTimesColor : state.LayoutSettings.TextColor; } else { label.ForeColor = Settings.OverrideTimesColor ? Settings.AfterTimesColor : state.LayoutSettings.TextColor; } if (type == ColumnType.SplitTime || type == ColumnType.DeltaorSplitTime) { label.Text = TimeFormatter.Format(Split.Comparisons[comparison][timingMethod]); } else //SegmentTime or SegmentTimeorSegmentDeltaTime { var previousTime = TimeSpan.Zero; for (var index = splitIndex - 1; index >= 0; index--) { var comparisonTime = state.Run[index].Comparisons[comparison][timingMethod]; if (comparisonTime != null) { previousTime = comparisonTime.Value; break; } } label.Text = TimeFormatter.Format(Split.Comparisons[comparison][timingMethod] - previousTime); } } //Live Delta var splitDelta = type == ColumnType.DeltaorSplitTime || type == ColumnType.Delta; var bestDelta = LiveSplitStateHelper.CheckLiveDelta(state, splitDelta, comparison, timingMethod); if (bestDelta != null && Split == state.CurrentSplit && (type == ColumnType.DeltaorSplitTime || type == ColumnType.Delta || type == ColumnType.SegmentDeltaorSegmentTime || type == ColumnType.SegmentDelta)) { if (splitDelta) //DeltaorSplitTime or Delta { label.Text = DeltaTimeFormatter.Format(bestDelta); } else //SegmentDeltaorSegmentTime or SegmentDelta { label.Text = DeltaTimeFormatter.Format(LiveSplitStateHelper.GetLiveSegmentDelta(state, splitIndex, comparison, timingMethod)); } label.ForeColor = Settings.OverrideDeltasColor ? Settings.DeltasColor : state.LayoutSettings.TextColor; } else if (type == ColumnType.Delta || type == ColumnType.SegmentDelta) { label.Text = ""; } } }
private void DrawGeneral(Graphics g, LiveSplitState state, float width, float height, LayoutMode mode) { if (NeedUpdateAll) { UpdateAll(state); } int splitIndex = state.Run.IndexOf(Split) % 7; if (IsActive) { switch (splitIndex) { case 0: img = Properties.Resources.row_0_s; break; case 1: img = Properties.Resources.row_1_s; break; case 2: img = Properties.Resources.row_2_s; break; case 3: img = Properties.Resources.row_3_s; break; case 4: img = Properties.Resources.row_4_s; break; case 5: img = Properties.Resources.row_5_s; break; case 6: img = Properties.Resources.row_6_s; break; default: img = Properties.Resources.row_0_s; break; } } else { switch (splitIndex) { case 0: img = Properties.Resources.row_0; break; case 1: img = Properties.Resources.row_1; break; case 2: img = Properties.Resources.row_2; break; case 3: img = Properties.Resources.row_3; break; case 4: img = Properties.Resources.row_4; break; case 5: img = Properties.Resources.row_5; break; case 6: img = Properties.Resources.row_6; break; default: img = Properties.Resources.row_0; break; } } g.DrawImage(img, 0, 0, width, height); MeasureTimeLabel.Text = TimeFormatter.Format(new TimeSpan(24, 0, 0)); MeasureDeltaLabel.Text = DeltaTimeFormatter.Format(new TimeSpan(0, 9, 0, 0)); MeasureTimeLabel.Font = state.LayoutSettings.TimesFont; MeasureTimeLabel.IsMonospaced = true; MeasureDeltaLabel.Font = state.LayoutSettings.TimesFont; MeasureDeltaLabel.IsMonospaced = true; MeasureTimeLabel.SetActualWidth(g); MeasureDeltaLabel.SetActualWidth(g); NameLabel.ShadowColor = state.LayoutSettings.ShadowsColor; NameLabel.OutlineColor = state.LayoutSettings.TextOutlineColor; foreach (var label in LabelsList) { label.ShadowColor = state.LayoutSettings.ShadowsColor; label.OutlineColor = state.LayoutSettings.TextOutlineColor; } if (Settings.SplitTimesAccuracy != CurrentAccuracy) { TimeFormatter = new RegularSplitTimeFormatter(Settings.SplitTimesAccuracy); CurrentAccuracy = Settings.SplitTimesAccuracy; } if (Settings.DeltasAccuracy != CurrentDeltaAccuracy || Settings.DropDecimals != CurrentDropDecimals) { DeltaTimeFormatter = new DeltaSplitTimeFormatter(Settings.DeltasAccuracy, Settings.DropDecimals); CurrentDeltaAccuracy = Settings.DeltasAccuracy; CurrentDropDecimals = Settings.DropDecimals; } if (Split != null) { if (mode == LayoutMode.Vertical) { NameLabel.VerticalAlignment = StringAlignment.Center; NameLabel.Y = 0; NameLabel.Height = height; foreach (var label in LabelsList) { label.VerticalAlignment = StringAlignment.Center; label.Y = 0; label.Height = height; } } else { NameLabel.VerticalAlignment = StringAlignment.Near; NameLabel.Y = 0; NameLabel.Height = 50; foreach (var label in LabelsList) { label.VerticalAlignment = StringAlignment.Far; label.Y = height - 50; label.Height = 50; } } if (IsActive) { g.DrawImage(SplitCursor, 2, ((height - 24f) / 2.0f), 30f, 24f); } NameLabel.Font = state.LayoutSettings.TextFont; NameLabel.X = IsActive ? 35 : 5; NameLabel.HasShadow = state.LayoutSettings.DropShadows; if (ColumnsList.Count() == LabelsList.Count) { var curX = width - 12; var nameX = width - 7; foreach (var label in LabelsList.Reverse()) { var column = ColumnsList.ElementAt(LabelsList.IndexOf(label)); var labelWidth = 0f; if (column.Type == ColumnType.DeltaorSplitTime || column.Type == ColumnType.SegmentDeltaorSegmentTime) { labelWidth = Math.Max(MeasureDeltaLabel.ActualWidth, MeasureTimeLabel.ActualWidth); } else if (column.Type == ColumnType.Delta || column.Type == ColumnType.SegmentDelta) { labelWidth = MeasureDeltaLabel.ActualWidth; } else { labelWidth = MeasureTimeLabel.ActualWidth; } label.Width = labelWidth + 20; curX -= labelWidth + 5; label.X = curX - 15; label.Font = state.LayoutSettings.TimesFont; label.HasShadow = state.LayoutSettings.DropShadows; label.OutlineColor = state.LayoutSettings.TextOutlineColor; label.IsMonospaced = true; label.Draw(g); if (!string.IsNullOrEmpty(label.Text)) { nameX = curX + labelWidth + 5 - label.ActualWidth; } } NameLabel.Width = (mode == LayoutMode.Horizontal ? width - 10 : width * 0.4f); NameLabel.Draw(g); } } }
protected string GetTime(DateTime time) { return(TimeFormatter.Format(time)); }
public void Returns23Seconds() { var result = TimeFormatter.Format(new TimeSpan(0, 0, 23)); Assert.AreEqual("23 seconds ago", result); }
private void ShowPersonalRecord(LayoutMode mode) { var centeredText = Settings.CenteredText && !Settings.Display2Rows && mode == LayoutMode.Vertical; if (PersonalRecord != null) { var time = PersonalRecord.Times.Primary; var timingMethod = State.CurrentTimingMethod; var game = State.Run.Metadata.Game; if (game != null) { timingMethod = game.Ruleset.DefaultTimingMethod.ToLiveSplitTimingMethod(); LocalTimeFormatter.Accuracy = game.Ruleset.ShowMilliseconds ? TimeAccuracy.Hundredths : TimeAccuracy.Seconds; } var formatted = TimeFormatter.Format(time); var isLoggedIn = SpeedrunCom.Client.IsAccessTokenValid; var userName = string.Empty; if (isLoggedIn) { userName = SpeedrunCom.Client.Profile.Name; } var runners = string.Join(", ", PersonalRecord.Players.Select(p => p.Name)); var finalTime = GetPBTime(timingMethod); if (IsPBTimeLower(finalTime, time, game != null ? game.Ruleset.ShowMilliseconds : false)) { formatted = LocalTimeFormatter.Format(finalTime); runners = State.Run.Metadata.Category.Players.Value > 1 ? "us" : "me"; } if (centeredText) { var textList = new List <string>(); textList.Add(string.Format("Personal Record is {0} by {1}", formatted, runners)); textList.Add(string.Format("Personal Record: {0} by {1}", formatted, runners)); textList.Add(string.Format("PR: {0} by {1}", formatted, runners)); textList.Add(string.Format("PR is {0} by {1}", formatted, runners)); InternalComponent.InformationName = textList.First(); InternalComponent.AlternateNameText = textList; } else { InternalComponent.InformationValue = string.Format("{0} by {1}", formatted, runners); } } else if (IsLoading) { if (centeredText) { InternalComponent.InformationName = "Loading Personal Record..."; InternalComponent.AlternateNameText = new[] { "Loading PR..." }; } else { InternalComponent.InformationValue = "Loading..."; } } else { if (centeredText) { InternalComponent.InformationName = "Unknown Personal Record"; InternalComponent.AlternateNameText = new[] { "Unknown PR" }; } else { InternalComponent.InformationValue = TimeFormatConstants.DASH; } } }
private void ShowWorldRecord() { if (WorldRecord != null) { var time = WorldRecord.Times.Primary; var timingMethod = State.CurrentTimingMethod; var game = State.Run.Metadata.Game; if (game != null) { timingMethod = game.Ruleset.DefaultTimingMethod.ToLiveSplitTimingMethod(); LocalTimeFormatter.Accuracy = game.Ruleset.ShowMilliseconds ? TimeAccuracy.Hundredths : TimeAccuracy.Seconds; } var formatted = TimeFormatter.Format(time); var isLoggedIn = SpeedrunCom.Client.IsAccessTokenValid; var userName = string.Empty; if (isLoggedIn) { userName = SpeedrunCom.Client.Profile.Name; } var runners = string.Join(", ", AllTies.Select(t => string.Join(" & ", t.Players.Select(p => isLoggedIn && p.Name == userName ? "me" : p.Name)))); var tieCount = AllTies.Count; var finalTime = GetPBTime(timingMethod); if (finalTime < time) { formatted = LocalTimeFormatter.Format(finalTime); runners = State.Run.Metadata.Category.Players.Value > 1 ? "us" : "me"; tieCount = 1; } if (Settings.CenteredText && !Settings.Display2Rows) { var textList = new List <string>(); textList.Add(string.Format("World Record is {0} by {1}", formatted, runners)); textList.Add(string.Format("World Record: {0} by {1}", formatted, runners)); textList.Add(string.Format("WR: {0} by {1}", formatted, runners)); textList.Add(string.Format("WR is {0} by {1}", formatted, runners)); if (tieCount > 1) { textList.Add(string.Format("World Record is {0} ({1}-way tie)", formatted, tieCount)); textList.Add(string.Format("World Record: {0} ({1}-way tie)", formatted, tieCount)); textList.Add(string.Format("WR: {0} ({1}-way tie)", formatted, tieCount)); textList.Add(string.Format("WR is {0} ({1}-way tie)", formatted, tieCount)); } InternalComponent.InformationName = textList.First(); InternalComponent.AlternateNameText = textList; } else { if (tieCount > 1) { InternalComponent.InformationValue = string.Format("{0} ({1}-way tie)", formatted, tieCount); } else { InternalComponent.InformationValue = string.Format("{0} by {1}", formatted, runners); } } } else if (IsLoading) { if (Settings.CenteredText && !Settings.Display2Rows) { InternalComponent.InformationName = "Loading World Record..."; InternalComponent.AlternateNameText = new[] { "Loading WR..." }; } else { InternalComponent.InformationValue = "Loading..."; } } else { if (Settings.CenteredText && !Settings.Display2Rows) { InternalComponent.InformationName = "Unknown World Record"; InternalComponent.AlternateNameText = new[] { "Unknown WR" }; } else { InternalComponent.InformationValue = "-"; } } }