示例#1
0
        public SplitComponent(SplitsSettings settings)
        {
            NoIconShadow = IconShadow.Generate(NoIconImage, Color.Black);
            NameLabel    = new SimpleLabel()
            {
                HorizontalAlignment = StringAlignment.Near,
                X = 8,
            };
            MeasureTimeLabel   = new SimpleLabel();
            MeasureDeltaLabel  = new SimpleLabel();
            Settings           = settings;
            TimeFormatter      = new RegularSplitTimeFormatter(Settings.SplitTimesAccuracy);
            DeltaTimeFormatter = new DeltaSplitTimeFormatter(Settings.DeltasAccuracy, Settings.DropDecimals);
            MinimumHeight      = 31;

            NeedUpdateAll = true;
            IsActive      = false;

            Cache      = new GraphicsCache();
            LabelsList = new List <SimpleLabel>();
        }
        private void Prepare(LiveSplitState state)
        {
            if (state != OldState)
            {
                state.OnScrollDown        += state_OnScrollDown;
                state.OnScrollUp          += state_OnScrollUp;
                state.OnStart             += state_OnStart;
                state.OnReset             += state_OnReset;
                state.OnSplit             += state_OnSplit;
                state.OnSkipSplit         += state_OnSkipSplit;
                state.OnUndoSplit         += state_OnUndoSplit;
                state.ComparisonRenamed   += state_ComparisonRenamed;
                state.RunManuallyModified += state_RunManuallyModified;
                OldState = state;
            }

            if (Settings.VisualSplitCount != visualSplitCount ||
                Settings.ShowColumnLabels != PreviousShowLabels ||
                (Settings.ShowColumnLabels && state.Layout.Mode != OldLayoutMode))
            {
                PreviousShowLabels = Settings.ShowColumnLabels;
                OldLayoutMode      = state.Layout.Mode;
                visualSplitCount   = Settings.VisualSplitCount;
                RebuildVisualSplits();
            }

            if (OldShadowsColor != state.LayoutSettings.ShadowsColor)
            {
                ShadowImages.Clear();
            }

            foreach (var split in state.Run)
            {
                if (split.Icon != null && (!ShadowImages.ContainsKey(split.Icon) || OldShadowsColor != state.LayoutSettings.ShadowsColor))
                {
                    ShadowImages.Add(split.Icon, IconShadow.Generate(split.Icon, state.LayoutSettings.ShadowsColor));
                }
            }

            var iconsNotBlank = state.Run.Where(x => x.Icon != null).Count() > 0;

            foreach (var split in SplitComponents)
            {
                var hideIconSectionSplit = !Settings.ShowIconSectionSplit && split.Split != null && state.Run.IndexOf(split.Split) == lastSplitOfSection;
                var shouldIndent         = split.Split == null || split.Split.Icon != null || Settings.IndentBlankIcons;

                if (split.Header)
                {
                    split.DisplayIcon = Settings.ShowSectionIcon && shouldIndent && iconsNotBlank;
                }
                else
                {
                    split.DisplayIcon = Settings.DisplayIcons && !hideIconSectionSplit && iconsNotBlank && shouldIndent;
                }

                if (split.Split != null && split.Split.Icon != null)
                {
                    split.ShadowImage = ShadowImages[split.Split.Icon];
                }
                else
                {
                    split.ShadowImage = null;
                }
            }
            OldShadowsColor = state.LayoutSettings.ShadowsColor;

            foreach (var component in Components)
            {
                if (component is SeparatorComponent)
                {
                    var separator = (SeparatorComponent)component;
                    var index     = Components.IndexOf(separator);
                    if (state.CurrentPhase == TimerPhase.Running || state.CurrentPhase == TimerPhase.Paused)
                    {
                        if (((SplitComponent)Components[index + 1]).Split == state.CurrentSplit)
                        {
                            separator.LockToBottom = true;
                        }
                        else if (Components[index - 1] is SplitComponent && ((SplitComponent)Components[index - 1]).Split == state.CurrentSplit)
                        {
                            separator.LockToBottom = false;
                        }
                    }
                }
                else if (component is ThinSeparatorComponent)
                {
                    var separator = (ThinSeparatorComponent)component;
                    var index     = Components.IndexOf(separator);
                    if (state.CurrentPhase == TimerPhase.Running || state.CurrentPhase == TimerPhase.Paused)
                    {
                        if (((SplitComponent)Components[index + 1]).Split == state.CurrentSplit)
                        {
                            separator.LockToBottom = true;
                        }
                        else if (Components[index - 1] is SplitComponent && ((SplitComponent)Components[index - 1]).Split == state.CurrentSplit)
                        {
                            separator.LockToBottom = false;
                        }
                    }
                }
            }
        }
示例#3
0
        private void Prepare(LiveSplitState state)
        {
            if (state != OldState)
            {
                state.OnScrollDown += state_OnScrollDown;
                state.OnScrollUp   += state_OnScrollUp;
                state.OnStart      += state_OnStart;
                state.OnReset      += state_OnReset;
                state.OnSplit      += state_OnSplit;
                state.OnSkipSplit  += state_OnSkipSplit;
                state.OnUndoSplit  += state_OnUndoSplit;
                OldState            = state;
            }

            var previousSplitCount = visualSplitCount;

            visualSplitCount = Math.Min(state.Run.Count, Settings.VisualSplitCount);
            if (previousSplitCount != visualSplitCount ||
                (Settings.ShowBlankSplits && settingsSplitCount != Settings.VisualSplitCount) ||
                Settings.ShowColumnLabels != PreviousShowLabels ||
                (Settings.ShowColumnLabels && state.Layout.Mode != OldLayoutMode))
            {
                PreviousShowLabels = Settings.ShowColumnLabels;
                OldLayoutMode      = state.Layout.Mode;
                RebuildVisualSplits();
            }
            settingsSplitCount = Settings.VisualSplitCount;

            var skipCount = Math.Min(
                Math.Max(
                    0,
                    state.CurrentSplitIndex - (visualSplitCount - 2 - Settings.SplitPreviewCount + (Settings.AlwaysShowLastSplit ? 0 : 1))),
                state.Run.Count - visualSplitCount);

            ScrollOffset = Math.Min(Math.Max(ScrollOffset, -skipCount), state.Run.Count - skipCount - visualSplitCount);
            skipCount   += ScrollOffset;

            if (OldShadowsColor != state.LayoutSettings.ShadowsColor)
            {
                ShadowImages.Clear();
            }

            foreach (var split in state.Run)
            {
                if (split.Icon != null && (!ShadowImages.ContainsKey(split.Icon) || OldShadowsColor != state.LayoutSettings.ShadowsColor))
                {
                    ShadowImages.Add(split.Icon, IconShadow.Generate(split.Icon, state.LayoutSettings.ShadowsColor));
                }
            }

            var iconsNotBlank = state.Run.Where(x => x.Icon != null).Count() > 0;

            foreach (var split in SplitComponents)
            {
                split.DisplayIcon = iconsNotBlank && Settings.DisplayIcons;

                if (split.Split != null && split.Split.Icon != null)
                {
                    split.ShadowImage = ShadowImages[split.Split.Icon];
                }
                else
                {
                    split.ShadowImage = null;
                }
            }
            OldShadowsColor = state.LayoutSettings.ShadowsColor;

            foreach (var component in Components)
            {
                if (component is SeparatorComponent)
                {
                    var separator = (SeparatorComponent)component;
                    var index     = Components.IndexOf(separator);
                    if (state.CurrentPhase == TimerPhase.Running || state.CurrentPhase == TimerPhase.Paused)
                    {
                        if (((SplitComponent)Components[index + 1]).Split == state.CurrentSplit)
                        {
                            separator.LockToBottom = true;
                        }
                        else if (Components[index - 1] is SplitComponent && ((SplitComponent)Components[index - 1]).Split == state.CurrentSplit)
                        {
                            separator.LockToBottom = false;
                        }
                    }
                    if (Settings.AlwaysShowLastSplit && Settings.SeparatorLastSplit && index == LastSplitSeparatorIndex)
                    {
                        if (skipCount >= state.Run.Count - visualSplitCount)
                        {
                            if (Settings.ShowThinSeparators)
                            {
                                separator.DisplayedSize = 1f;
                            }
                            else
                            {
                                separator.DisplayedSize = 0f;
                            }

                            separator.UseSeparatorColor = false;
                        }
                        else
                        {
                            separator.DisplayedSize     = 2f;
                            separator.UseSeparatorColor = true;
                        }
                    }
                }
                else if (component is ThinSeparatorComponent)
                {
                    var separator = (ThinSeparatorComponent)component;
                    var index     = Components.IndexOf(separator);
                    if (state.CurrentPhase == TimerPhase.Running || state.CurrentPhase == TimerPhase.Paused)
                    {
                        if (((SplitComponent)Components[index + 1]).Split == state.CurrentSplit)
                        {
                            separator.LockToBottom = true;
                        }
                        else if (((SplitComponent)Components[index - 1]).Split == state.CurrentSplit)
                        {
                            separator.LockToBottom = false;
                        }
                    }
                }
            }
        }
示例#4
0
        private void DrawGeneral(Graphics g, LiveSplitState state, float width, float height, LayoutMode mode)
        {
            if (NeedUpdateAll)
            {
                UpdateAll(state);
            }

            var splitIndex = state.Run.IndexOf(Split);

            if (Settings.BackgroundGradient == GradedExtendedGradientType.Alternating)
            {
                g.FillRectangle(new SolidBrush(
                                    splitIndex % 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;
            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 GradedRegularSplitTimeFormatter(Settings.SplitTimesAccuracy);
                CurrentAccuracy = Settings.SplitTimesAccuracy;
            }
            if (Settings.DeltasAccuracy != CurrentDeltaAccuracy || Settings.DropDecimals != CurrentDropDecimals)
            {
                DeltaTimeFormatter   = new GradedDeltaSplitTimeFormatter(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);
                }

                bool customizedImage;
                var  icon = GetIcon(state, splitIndex, out customizedImage);

                if (DisplayIcon && icon != null)
                {
                    Image shadow;
                    if (customizedImage)
                    {
                        if (!CustomShadowImages.TryGetValue(icon, out shadow))
                        {
                            shadow = IconShadow.Generate(icon, state.LayoutSettings.ShadowsColor);
                            CustomShadowImages.Add(icon, shadow);
                        }
                    }
                    else
                    {
                        shadow = ShadowImage;
                    }

                    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 == GradedColumnType.DeltaorSplitTime || column.Type == GradedColumnType.SegmentDeltaorSegmentTime)
                        {
                            labelWidth = Math.Max(MeasureDeltaLabel.ActualWidth, MeasureTimeLabel.ActualWidth);
                        }
                        else if (column.Type == GradedColumnType.Delta || column.Type == GradedColumnType.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;
            }
        }