Пример #1
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   = "";
            }

            var deathCount = GetDeathCount(state);

            DeathsLabel.Text = deathCount.ToString();

            if (state.CurrentPhase == TimerPhase.NotRunning)
            {
                DeathCountColor = state.LayoutSettings.NotRunningColor;
            }
            else if (state.CurrentPhase == TimerPhase.Ended)
            {
                var pbDeathCount   = GetPbDeathCount(state);
                var bestDeathCount = GetBestDeathCount(state);
                DeathCountColor = (bestDeathCount == -1 || bestDeathCount > deathCount)
                    ? LiveSplitStateHelper.GetBestSegmentColor(state)
                    : GetActiveDeathColor(state, deathCount, pbDeathCount, state.LayoutSettings.PersonalBestColor);
            }
            else
            {
                var pbDeathCount = GetPbDeathCount(state);
                DeathCountColor = GetActiveDeathColor(state, deathCount, pbDeathCount, state.LayoutSettings.AheadGainingTimeColor);
            }

            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;
                DeathsLabel.ForeColor    = Settings.TimerColor;
            }
            else
            {
                BigTextLabel.ForeColor   = TimerColor;
                SmallTextLabel.ForeColor = TimerColor;
                DeathsLabel.ForeColor    = DeathCountColor;
            }

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