示例#1
0
        public RaceLabels(RaceComponent component, int index, RaceSettings settings, RaceSplit split)
        {
            Parent         = component;
            RaceIndex      = index;
            Split          = split;
            Settings       = settings;
            MinimumHeight  = 10;
            VerticalHeight = 31;

            TimeFormatter      = new RegularSplitTimeFormatter(Settings.Accuracy);
            DeltaTimeFormatter = new DeltaSplitTimeFormatter(Settings.Accuracy, false);

            Cache     = new GraphicsCache();
            RacerName = new SimpleLabel()
            {
                HorizontalAlignment = StringAlignment.Near,
                VerticalAlignment   = StringAlignment.Near
            };
            RacerSplit = new SimpleLabel()
            {
                HorizontalAlignment = StringAlignment.Near,
                VerticalAlignment   = StringAlignment.Far
            };
            RacerTime = new SimpleLabel()
            {
                HorizontalAlignment = StringAlignment.Far,
                VerticalAlignment   = StringAlignment.Far
            };
            RacerDelta = new SimpleLabel()
            {
                HorizontalAlignment = StringAlignment.Far,
                VerticalAlignment   = StringAlignment.Near
            };
        }
示例#2
0
        public RaceComponent(LiveSplitState state)
        {
            Settings          = new RaceSettings();
            Comparison        = new RaceSplit();
            InternalComponent = new ComponentRendererComponent();
            InternalComponent.VisibleComponents = Components;

            CurrentState = state;
        }
        private void LiveSplitChannel_MessageReceived(object sender, IrcMessageEventArgs e)
        {
            if (e.Targets.Count > 0 && e.Targets[0] == liveSplitChannel)
            {
                if (raceIRC.RaceState == RaceState.RaceStarted || raceIRC.RaceState == RaceState.RaceEnded)
                {
                    if (e.Text.StartsWith("!time ") || e.Text.StartsWith("!done "))
                    {
                        var method     = e.Text.Substring("!time ".Length).StartsWith("GameTime") ? TimingMethod.GameTime : TimingMethod.RealTime;
                        var cutOff     = e.Text.Substring("!time RealTime ".Length);
                        var index      = cutOff.LastIndexOf("\"");
                        var timeString = cutOff.Substring(index > -1 ? index + 2 : 0);
                        var time       = ParseTime(timeString);

                        string splitName = null;
                        if (index >= 0)
                        {
                            splitName = Unescape(cutOff.Substring(1, index - 1));
                        }
                        else
                        {
                            splitName = raceIRC.Model.CurrentState.Run[raceIRC.Model.CurrentState.Run.Count - 1].Name;
                        }

                        string[] splitAndSub = splitName.Split('|');
                        bool     found       = false;
                        if (splitAndSub.Length == 2)
                        {
                            splitName = splitAndSub[0].Trim();
                            for (int i = raceIRC.Model.CurrentState.Run.Count - 1; i >= 0; i--)
                            {
                                ISegment seg     = raceIRC.Model.CurrentState.Run[i];
                                string   segName = seg.Name.Trim();
                                if (segName.Equals(splitName, StringComparison.OrdinalIgnoreCase))
                                {
                                    found = true;
                                    RaceSplit split = null;
                                    if (!RaceSplits.TryGetValue(e.Source.Name, out split))
                                    {
                                        split = new RaceSplit()
                                        {
                                            Name = e.Source.Name, SplitIndex = i, SplitName = segName, SplitTime = new Time(method, time), SubSplitIndex = int.Parse(splitAndSub[1])
                                        };
                                    }
                                    else
                                    {
                                        string historyName    = e.Source.Name + "|" + split.SplitIndex + "|" + split.SubSplitIndex;
                                        string newHistoryName = e.Source.Name + "|" + i + "|" + int.Parse(splitAndSub[1]);
                                        if (!historyName.Equals(newHistoryName, StringComparison.OrdinalIgnoreCase))
                                        {
                                            if (!RaceSplits.ContainsKey(historyName))
                                            {
                                                RaceSplits.Add(historyName, split.Clone());
                                            }
                                        }

                                        split.SplitIndex = i;
                                        split.SplitName  = segName;
                                        if (method == TimingMethod.RealTime)
                                        {
                                            split.SplitTime = new Time(time, split.SplitTime.GameTime);
                                        }
                                        else
                                        {
                                            split.SplitTime = new Time(split.SplitTime.RealTime, time);
                                        }
                                        split.SubSplitIndex = int.Parse(splitAndSub[1]);
                                    }
                                }
                            }
                        }
                        else
                        {
                            for (int i = raceIRC.Model.CurrentState.Run.Count - 1; i >= 0; i--)
                            {
                                ISegment seg     = raceIRC.Model.CurrentState.Run[i];
                                string   segName = seg.Name.Trim();
                                if (segName.Equals(splitName, StringComparison.OrdinalIgnoreCase))
                                {
                                    found = true;
                                    RaceSplit split = null;
                                    if (!RaceSplits.TryGetValue(e.Source.Name, out split))
                                    {
                                        split = new RaceSplit()
                                        {
                                            Name = e.Source.Name, SplitIndex = i, SplitName = segName, SplitTime = new Time(method, time), SubSplitIndex = int.MaxValue
                                        };
                                    }
                                    else
                                    {
                                        string historyName    = e.Source.Name + "|" + split.SplitIndex + "|" + split.SubSplitIndex;
                                        string newHistoryName = e.Source.Name + "|" + i + "|" + int.MaxValue;
                                        if (!historyName.Equals(newHistoryName, StringComparison.OrdinalIgnoreCase))
                                        {
                                            if (!RaceSplits.ContainsKey(historyName))
                                            {
                                                RaceSplits.Add(historyName, split.Clone());
                                            }
                                        }

                                        split.SplitIndex = i;
                                        split.SplitName  = segName;
                                        if (method == TimingMethod.RealTime)
                                        {
                                            split.SplitTime = new Time(time, split.SplitTime.GameTime);
                                        }
                                        else
                                        {
                                            split.SplitTime = new Time(split.SplitTime.RealTime, time);
                                        }
                                        split.SubSplitIndex = int.MaxValue;
                                    }
                                }
                            }
                        }

                        if (!found)
                        {
                            RaceSplit split = null;
                            if (splitAndSub.Length == 2)
                            {
                                splitName = splitAndSub[0].Trim();
                            }
                            if (!RaceSplits.TryGetValue(e.Source.Name, out split))
                            {
                                split = new RaceSplit()
                                {
                                    Name = e.Source.Name, SplitIndex = raceIRC.Model.CurrentState.CurrentSplitIndex, SplitName = splitName, SplitTime = new Time(method, time), SubSplitIndex = int.MaxValue
                                };
                            }
                            else
                            {
                                string historyName    = e.Source.Name + "|" + split.SplitIndex + "|" + split.SubSplitIndex;
                                string newHistoryName = e.Source.Name + "|" + raceIRC.Model.CurrentState.CurrentSplitIndex + "|" + int.MaxValue;
                                if (!historyName.Equals(newHistoryName, StringComparison.OrdinalIgnoreCase))
                                {
                                    if (!RaceSplits.ContainsKey(historyName))
                                    {
                                        RaceSplits.Add(historyName, split.Clone());
                                    }
                                }

                                split.SplitIndex = raceIRC.Model.CurrentState.CurrentSplitIndex;
                                split.SplitName  = splitName;
                                if (method == TimingMethod.RealTime)
                                {
                                    split.SplitTime = new Time(time, split.SplitTime.GameTime);
                                }
                                else
                                {
                                    split.SplitTime = new Time(split.SplitTime.RealTime, time);
                                }
                                split.SubSplitIndex = int.MaxValue;
                            }
                        }
                    }
                }
            }
        }
示例#4
0
        public void Update(IInvalidator invalidator, LiveSplitState state, float width, float height, LayoutMode mode)
        {
            if (Settings.RacerCount != Components.Count)
            {
                Components.Clear();
                for (int i = 0; i < Settings.RacerCount; i++)
                {
                    Components.Add(new RaceLabels(this, i + 1, Settings, null));
                }
            }

            if (state.Run.Count == 0)
            {
                return;
            }

            Watcher.CheckRace();

            List <RaceSplit> raceComparisons = new List <RaceSplit>();
            bool             inRace          = false;

            foreach (string comp in state.Run.Comparisons)
            {
                if (comp.StartsWith("[Race] "))
                {
                    string    racerName = comp.Substring(7);
                    RaceSplit split     = null;
                    if (!Watcher.RaceSplits.TryGetValue(racerName, out split))
                    {
                        split = new RaceSplit()
                        {
                            Name = racerName, SplitIndex = -1, SplitName = string.Empty, SplitTime = new Time(), SubSplitIndex = int.MaxValue
                        };
                        Watcher.RaceSplits.Add(racerName, split);
                    }
                    raceComparisons.Add(split);
                    inRace = true;
                }
            }

            if (Watcher.UserName != null)
            {
                RaceSplit split = null;
                if (!Watcher.RaceSplits.TryGetValue(Watcher.UserName, out split))
                {
                    split = new RaceSplit()
                    {
                        Name = Watcher.UserName, SplitIndex = -1, SplitName = string.Empty, SplitTime = new Time(), SubSplitIndex = int.MaxValue
                    };
                    Watcher.RaceSplits.Add(Watcher.UserName, split);
                }
                raceComparisons.Add(split);

                if (Settings.CompareAgainst == RacerComparison.Yourself)
                {
                    Comparison = split;
                }
                inRace = true;
            }

            if (!inRace)
            {
                Watcher.Clear();
                Comparison.Clear();
            }

            raceComparisons.Sort(delegate(RaceSplit one, RaceSplit two) {
                return(one.SplitIndex > two.SplitIndex ? -1
                                        : one.SplitIndex <two.SplitIndex ? 1
                                                          : one.SubSplitIndex> two.SubSplitIndex ? -1
                                        : one.SubSplitIndex < two.SubSplitIndex ? 1
                                        : !one.SplitTime.RealTime.HasValue ? 1
                                        : !two.SplitTime.RealTime.HasValue ? -1
                                        : one.SplitTime.RealTime.Value.CompareTo(two.SplitTime.RealTime.Value));
            });

            if (Settings.CompareAgainst == RacerComparison.First && raceComparisons.Count > 0)
            {
                Comparison = raceComparisons[0];
            }

            for (int i = 0; i < Settings.RacerCount; i++)
            {
                RaceLabels labels = Components[i] as RaceLabels;
                if (i < raceComparisons.Count)
                {
                    labels.Split = raceComparisons[i];
                }
                else
                {
                    labels.Split = null;
                }
            }

            InternalComponent.Update(invalidator, state, width, height, mode);
        }
示例#5
0
        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;
        }