Esempio n. 1
0
 private void CheckLiveSegmentDelta(LiveSplitState state, string comparison)
 {
     IsLiveDeltaActive = false;
     if (Settings.IsLiveGraph)
     {
         if (state.CurrentPhase == TimerPhase.Running || state.CurrentPhase == TimerPhase.Paused)
         {
             var bestSeg  = LiveSplitStateHelper.CheckLiveDelta(state, true, comparison, state.CurrentTimingMethod);
             var curSplit = state.Run[state.CurrentSplitIndex].Comparisons[comparison][state.CurrentTimingMethod];
             var curTime  = state.CurrentTime[state.CurrentTimingMethod];
             if (bestSeg == null && curSplit != null && curTime - curSplit > MinDelta)
             {
                 bestSeg = curTime - curSplit;
             }
             if (bestSeg != null)
             {
                 if (bestSeg > MaxDelta)
                 {
                     MaxDelta = bestSeg.Value;
                 }
                 if (bestSeg < MinDelta)
                 {
                     MinDelta = bestSeg.Value;
                 }
                 Deltas.Add(bestSeg);
                 IsLiveDeltaActive = true;
             }
         }
     }
 }
        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");
        }
        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)
                                 ));
        }
        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 = "";
                }
            }
        }