private string previousSegmentComponent()
        {
            var   comparison = State.CurrentComparison;
            var   method     = State.CurrentTimingMethod;
            var   text       = "Previous Segment";
            var   time       = "";
            Color?color      = Color.Transparent;

            TimeSpan?timeChange  = null;
            TimeSpan?timeSave    = null;
            var      liveSegment = LiveSplitStateHelper.CheckLiveDelta(State, false, comparison, method);

            if (State.CurrentPhase != TimerPhase.NotRunning)
            {
                if (liveSegment != null)
                {
                    timeChange = liveSegment;
                    timeSave   = GetPossibleTimeSave(State, State.CurrentSplitIndex, comparison);
                    text       = "Live Segment";
                }
                else if (State.CurrentSplitIndex > 0)
                {
                    timeChange = LiveSplitStateHelper.GetPreviousSegmentDelta(State, State.CurrentSplitIndex - 1, comparison, State.CurrentTimingMethod);
                    timeSave   = GetPossibleTimeSave(State, State.CurrentSplitIndex - 1, comparison);
                }
                if (timeChange != null)
                {
                    if (liveSegment != null)
                    {
                        color = LiveSplitStateHelper.GetSplitColor(State, timeChange, State.CurrentSplitIndex, false, false, comparison, method).Value;
                    }
                    else
                    {
                        color = LiveSplitStateHelper.GetSplitColor(State, timeChange.Value, State.CurrentSplitIndex - 1, false, true, comparison, method).Value;
                    }
                }
                else
                {
                    color = LiveSplitStateHelper.GetSplitColor(State, null, State.CurrentSplitIndex - 1, true, true, comparison, State.CurrentTimingMethod);
                    if (color == null)
                    {
                        color = State.LayoutSettings.TextColor;
                    }
                }
            }
            else
            {
                color = State.LayoutSettings.TextColor;
            }

            var a = DeltaFormatter.Accuracy;

            DeltaFormatter.Accuracy = TimeAccuracy.Tenths;
            time = DeltaFormatter.Format(timeChange);
            DeltaFormatter.Accuracy = a;

            return(formatInfoTextWithColor(text, time, color) + "\n");
        }
Пример #2
0
        public void Update(IInvalidator invalidator, LiveSplitState state, float width, float height, LayoutMode mode)
        {
            var comparison = Settings.Comparison == "Current Comparison" ? state.CurrentComparison : Settings.Comparison;

            if (!state.Run.Comparisons.Contains(comparison))
            {
                comparison = state.CurrentComparison;
            }
            var comparisonName = comparison.StartsWith("[Race] ") ? comparison.Substring(7) : comparison;

            if (InternalComponent.InformationName != comparisonName)
            {
                InternalComponent.AlternateNameText.Clear();
                InternalComponent.AlternateNameText.Add(CompositeComparisons.GetShortComparisonName(comparison));
            }
            InternalComponent.LongestString   = comparisonName;
            InternalComponent.InformationName = comparisonName;

            var useLiveDelta = false;

            if (state.CurrentPhase == TimerPhase.Running || state.CurrentPhase == TimerPhase.Paused)
            {
                TimeSpan?delta     = LiveSplitStateHelper.GetLastDelta(state, state.CurrentSplitIndex, comparison, state.CurrentTimingMethod);
                var      liveDelta = state.CurrentTime[state.CurrentTimingMethod] - state.CurrentSplit.Comparisons[comparison][state.CurrentTimingMethod];
                if (liveDelta > delta || (delta == null && liveDelta > TimeSpan.Zero))
                {
                    delta        = liveDelta;
                    useLiveDelta = true;
                }
                InternalComponent.TimeValue = delta;
            }
            else if (state.CurrentPhase == TimerPhase.Ended)
            {
                InternalComponent.TimeValue = state.Run.Last().SplitTime[state.CurrentTimingMethod] - state.Run.Last().Comparisons[comparison][state.CurrentTimingMethod];
            }
            else
            {
                InternalComponent.TimeValue = null;
            }

            var color = LiveSplitStateHelper.GetSplitColor(state, InternalComponent.TimeValue, state.CurrentSplitIndex - (useLiveDelta ? 0 : 1), true, false, comparison, state.CurrentTimingMethod);

            if (color == null)
            {
                color = Settings.OverrideTextColor ? Settings.TextColor : state.LayoutSettings.TextColor;
            }
            InternalComponent.ValueLabel.ForeColor = color.Value;

            InternalComponent.Update(invalidator, state, width, height, mode);
        }
        private string splitComponent(ISegment segment, string comparison, TimingMethod method)
        {
            TimeSpan?deltaTime = null;
            Color?   color     = null;
            var      i         = State.Run.IndexOf(segment);
            int      delta     = 9;
            int      time      = 9;
            int      split     = Settings.CharacterWidth - delta - time - 2;
            var      segName   = (segment.Name.Length > split) ? segment.Name.Substring(0, split) : segment.Name;

            if (i < State.CurrentSplitIndex)
            {
                deltaTime = segment.SplitTime[method] - segment.Comparisons[comparison][method];
                color     = LiveSplitStateHelper.GetSplitColor(State, deltaTime, i, true, true, comparison, method);
            }
            else
            {
                //Live Delta
                var bestDelta = LiveSplitStateHelper.CheckLiveDelta(State, true, comparison, method);
                if (bestDelta != null && segment == State.CurrentSplit)
                {
                    deltaTime = bestDelta;
                    color     = State.LayoutSettings.TextColor;
                }
            }

            DeltaFormatter.DropDecimals = Settings.DropDecimals;
            DeltaFormatter.Accuracy     = Settings.DeltasAccuracy;
            SplitTimeFormatter.Accuracy = Settings.SplitAccuracy;

            var splitTime = segment.SplitTime[method];

            if (splitTime == null && State.CurrentSplitIndex <= i)
            {
                splitTime = segment.Comparisons[comparison][method];
            }

            return(String.Format("{0}{1, " + -split + "}<C> {2}{3, " + delta + "}<C> {4, " + time + "}\n",
                                 (State.CurrentSplit == segment) ? "<C8>" : "",
                                 segName,
                                 getColor(color),
                                 DeltaFormatter.Format(deltaTime),
                                 SplitTimeFormatter.Format(splitTime)
                                 ));
        }
        private string timerComponent()
        {
            UpdateTimeFormat();
            var timingMethod = State.CurrentTimingMethod;

            if (Settings.TimingMethod == "Real Time")
            {
                timingMethod = TimingMethod.RealTime;
            }
            else if (Settings.TimingMethod == "Game Time")
            {
                timingMethod = TimingMethod.GameTime;
            }

            var comparison = State.CurrentComparison;
            var method     = State.CurrentTimingMethod;
            var TimerColor = Color.Transparent;

            if (State.CurrentPhase == TimerPhase.NotRunning || State.CurrentTime[method] < TimeSpan.Zero)
            {
                TimerColor = State.LayoutSettings.NotRunningColor;
            }
            else if (State.CurrentPhase == TimerPhase.Paused)
            {
                TimerColor = State.LayoutSettings.PausedColor;
            }
            else if (State.CurrentPhase == TimerPhase.Ended)
            {
                if (State.Run.Last().Comparisons[State.CurrentComparison][method] == null || State.CurrentTime[method] < State.Run.Last().Comparisons[State.CurrentComparison][method])
                {
                    TimerColor = State.LayoutSettings.PersonalBestColor;
                }
                else
                {
                    TimerColor = State.LayoutSettings.BehindLosingTimeColor;
                }
            }
            else if (State.CurrentPhase == TimerPhase.Running)
            {
                if (State.CurrentSplit.Comparisons[State.CurrentComparison][method] != null)
                {
                    TimerColor = LiveSplitStateHelper.GetSplitColor(State, State.CurrentTime[method] - State.CurrentSplit.Comparisons[State.CurrentComparison][method],
                                                                    State.CurrentSplitIndex, true, false, State.CurrentComparison, method)
                                 ?? State.LayoutSettings.AheadGainingTimeColor;
                }
                else
                {
                    TimerColor = State.LayoutSettings.AheadGainingTimeColor;
                }
            }

            var timeValue  = State.CurrentTime[timingMethod];
            var timeString = ShortFormatter.Format(timeValue, CurrentTimeFormat);
            int dotIndex   = timeString.IndexOf(".");
            var time       = timeString.Substring(0, dotIndex);
            var fraction   = String.Empty;

            if (CurrentAccuracy == TimeAccuracy.Hundredths)
            {
                fraction = timeString.Substring(dotIndex);
            }
            else if (CurrentAccuracy == TimeAccuracy.Tenths)
            {
                fraction = timeString.Substring(dotIndex, 2);
            }

            return(String.Format("{0}{1, " + Settings.CharacterWidth + "}<C>\n",
                                 getColor(TimerColor),
                                 String.Join("", time, fraction)));
        }
        public void Update(IInvalidator invalidator, LiveSplitState state, float width, float height, LayoutMode mode)
        {
            var comparison = Settings.Comparison == "Current Comparison" ? state.CurrentComparison : Settings.Comparison;

            if (!state.Run.Comparisons.Contains(comparison))
            {
                comparison = state.CurrentComparison;
            }
            var comparisonName = CompositeComparisons.GetShortComparisonName(comparison);
            var componentName  = "Previous Segment" + (Settings.Comparison == "Current Comparison" ? "" : " (" + comparisonName + ")");

            InternalComponent.LongestString   = componentName;
            InternalComponent.InformationName = componentName;

            DeltaFormatter.Accuracy     = Settings.DeltaAccuracy;
            DeltaFormatter.DropDecimals = Settings.DropDecimals;
            TimeSaveFormatter.Accuracy  = Settings.TimeSaveAccuracy;

            TimeSpan?timeChange  = null;
            TimeSpan?timeSave    = null;
            var      liveSegment = LiveSplitStateHelper.CheckLiveDelta(state, false, comparison, state.CurrentTimingMethod, false);

            if (state.CurrentPhase != TimerPhase.NotRunning)
            {
                if (liveSegment != null)
                {
                    timeChange = liveSegment;
                    timeSave   = GetPossibleTimeSave(state, state.CurrentSplitIndex, comparison);
                    InternalComponent.InformationName = "Live Segment" + (Settings.Comparison == "Current Comparison" ? "" : " (" + comparisonName + ")");
                }
                else if (state.CurrentSplitIndex > 0)
                {
                    timeChange = LiveSplitStateHelper.GetPreviousSegmentDelta(state, state.CurrentSplitIndex - 1, comparison, state.CurrentTimingMethod);
                    timeSave   = GetPossibleTimeSave(state, state.CurrentSplitIndex - 1, comparison);
                }
                if (timeChange != null)
                {
                    if (liveSegment != null)
                    {
                        InternalComponent.ValueLabel.ForeColor = LiveSplitStateHelper.GetSplitColor(state, timeChange, state.CurrentSplitIndex, false, false, comparison, state.CurrentTimingMethod).Value;
                    }
                    else
                    {
                        InternalComponent.ValueLabel.ForeColor = LiveSplitStateHelper.GetSplitColor(state, timeChange.Value, state.CurrentSplitIndex - 1, false, true, comparison, state.CurrentTimingMethod).Value;
                    }
                }
                else
                {
                    var color = LiveSplitStateHelper.GetSplitColor(state, null, state.CurrentSplitIndex - 1, true, true, comparison, state.CurrentTimingMethod);
                    if (color == null)
                    {
                        color = Settings.OverrideTextColor ? Settings.TextColor : state.LayoutSettings.TextColor;
                    }
                    InternalComponent.ValueLabel.ForeColor = color.Value;
                }
            }
            else
            {
                InternalComponent.ValueLabel.ForeColor = Settings.OverrideTextColor ? Settings.TextColor : state.LayoutSettings.TextColor;
            }

            if (InternalComponent.InformationName != previousNameText)
            {
                InternalComponent.AlternateNameText.Clear();
                if (liveSegment != null)
                {
                    InternalComponent.AlternateNameText.Add("Live Segment");
                    InternalComponent.AlternateNameText.Add("Live Seg.");
                }
                else
                {
                    InternalComponent.AlternateNameText.Add("Previous Segment");
                    InternalComponent.AlternateNameText.Add("Prev. Segment");
                    InternalComponent.AlternateNameText.Add("Prev. Seg.");
                }
                previousNameText = InternalComponent.InformationName;
            }

            InternalComponent.InformationValue = DeltaFormatter.Format(timeChange)
                                                 + (Settings.ShowPossibleTimeSave ? " / " + TimeSaveFormatter.Format(timeSave) : "");

            InternalComponent.Update(invalidator, state, width, height, mode);
        }
        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 = "";
                }
            }
        }
Пример #7
0
        public void Update(IInvalidator invalidator, LiveSplitState state, float width, float height, LayoutMode mode)
        {
            Cache.Restart();

            var timingMethod = state.CurrentTimingMethod;

            if (Settings.TimingMethod == "Real Time")
            {
                timingMethod = TimingMethod.RealTime;
            }
            else if (Settings.TimingMethod == "Game Time")
            {
                timingMethod = TimingMethod.GameTime;
            }

            var timeValue = GetTime(state, timingMethod);

            if (timeValue == null && timingMethod == TimingMethod.GameTime)
            {
                timeValue = GetTime(state, TimingMethod.RealTime);
            }

            if (timeValue != null)
            {
                var timeString = Formatter.Format(timeValue, CurrentTimeFormat);
                int dotIndex   = timeString.IndexOf(".");
                BigTextLabel.Text = timeString.Substring(0, dotIndex);
                if (CurrentAccuracy == TimeAccuracy.Hundredths)
                {
                    SmallTextLabel.Text = timeString.Substring(dotIndex);
                }
                else if (CurrentAccuracy == TimeAccuracy.Tenths)
                {
                    SmallTextLabel.Text = timeString.Substring(dotIndex, 2);
                }
                else
                {
                    SmallTextLabel.Text = "";
                }
            }
            else
            {
                SmallTextLabel.Text = TimeFormatConstants.DASH;
                BigTextLabel.Text   = "";
            }

            if (state.CurrentPhase == TimerPhase.NotRunning || state.CurrentTime[timingMethod] < TimeSpan.Zero)
            {
                TimerColor = state.LayoutSettings.NotRunningColor;
            }
            else if (state.CurrentPhase == TimerPhase.Paused)
            {
                TimerColor = state.LayoutSettings.PausedColor;
            }
            else if (state.CurrentPhase == TimerPhase.Ended)
            {
                if (state.Run.Last().Comparisons[state.CurrentComparison][timingMethod] == null || state.CurrentTime[timingMethod] < state.Run.Last().Comparisons[state.CurrentComparison][timingMethod])
                {
                    TimerColor = state.LayoutSettings.PersonalBestColor;
                }
                else
                {
                    TimerColor = state.LayoutSettings.BehindLosingTimeColor;
                }
            }
            else if (state.CurrentPhase == TimerPhase.Running)
            {
                if (state.CurrentSplit.Comparisons[state.CurrentComparison][timingMethod] != null)
                {
                    TimerColor = LiveSplitStateHelper.GetSplitColor(state, state.CurrentTime[timingMethod] - state.CurrentSplit.Comparisons[state.CurrentComparison][timingMethod],
                                                                    state.CurrentSplitIndex, true, false, state.CurrentComparison, timingMethod)
                                 ?? state.LayoutSettings.AheadGainingTimeColor;
                }
                else
                {
                    TimerColor = state.LayoutSettings.AheadGainingTimeColor;
                }
            }

            if (Settings.OverrideSplitColors)
            {
                BigTextLabel.ForeColor   = Settings.TimerColor;
                SmallTextLabel.ForeColor = Settings.TimerColor;
            }
            else
            {
                BigTextLabel.ForeColor   = TimerColor;
                SmallTextLabel.ForeColor = TimerColor;
            }

            Cache["TimerText"] = BigTextLabel.Text + SmallTextLabel.Text;
            if (BigTextLabel.Brush != null && invalidator != null)
            {
                Cache["TimerColor"] = BigTextLabel.ForeColor.ToArgb();
            }

            if (invalidator != null && Cache.HasChanged)
            {
                invalidator.Invalidate(0, 0, width, height);
            }
        }