Пример #1
0
        private void CreateRows(bool configure = false)
        {
            configPanel.SetValue(Panel.ZIndexProperty, 3);
            configPanel.SetValue(Canvas.RightProperty, 4.0);
            savePanel.SetValue(Panel.ZIndexProperty, 3);
            savePanel.SetValue(Canvas.BottomProperty, 1.0);

            TitleRectangle = OverlayUtil.CreateRectangle(TITLECOLOR);
            overlayCanvas.Children.Add(TitleRectangle);

            TitlePanel            = OverlayUtil.CreateNameStackPanel();
            TitleBlock            = OverlayUtil.CreateTextBlock();
            TitleBlock.Foreground = configure ? OverlayUtil.TEXTBRUSH : OverlayUtil.TITLEBRUSH;
            TitlePanel.Children.Add(TitleBlock);
            overlayCanvas.Children.Add(TitlePanel);

            TitleDamagePanel = OverlayUtil.CreateDamageStackPanel();
            TitleDamageBlock = OverlayUtil.CreateTextBlock();
            TitleDamagePanel.Children.Add(TitleDamageBlock);
            overlayCanvas.Children.Add(TitleDamagePanel);

            if (!configure)
            {
                TitlePanel.SizeChanged       += TitleResizing;
                TitleDamagePanel.SizeChanged += TitleResizing;
            }

            for (int i = 0; i < CurrentMaxRows; i++)
            {
                var rectangle = OverlayUtil.CreateRectangle(ColorList[i]);
                RectangleList.Add(rectangle);
                overlayCanvas.Children.Add(rectangle);

                var nameStack = OverlayUtil.CreateNameStackPanel();
                NamePanels.Add(nameStack);

                var classImage = OverlayUtil.CreateImage();
                NameIconList.Add(classImage);
                nameStack.Children.Add(classImage);

                var nameBlock = OverlayUtil.CreateTextBlock();
                NameBlockList.Add(nameBlock);
                nameStack.Children.Add(nameBlock);
                overlayCanvas.Children.Add(nameStack);

                var damageStack = OverlayUtil.CreateDamageStackPanel();
                DamagePanels.Add(damageStack);

                if (configure)
                {
                    var colorChoice = new ColorComboBox(ColorComboBox.Theme.Dark)
                    {
                        Tag = string.Format(CultureInfo.CurrentCulture, "OverlayRankColor{0}", i + 1)
                    };
                    colorChoice.SelectionChanged += (object sender, SelectionChangedEventArgs e) =>
                    {
                        rectangle.Fill = OverlayUtil.CreateBrush((colorChoice.SelectedValue as ColorItem).Brush.Color);
                    };

                    if (colorChoice.ItemsSource is List <ColorItem> colors)
                    {
                        colorChoice.SelectedItem = colors.Find(item => item.Brush.Color == ColorList[i]);
                    }

                    ColorComboBoxList.Add(colorChoice);
                    damageStack.Children.Add(colorChoice);
                }
                else
                {
                    var damageRate = OverlayUtil.CreateImageAwesome();
                    DamageRateList.Add(damageRate);
                    damageStack.Children.Add(damageRate);

                    var damageBlock = OverlayUtil.CreateTextBlock();
                    DamageBlockList.Add(damageBlock);
                    damageStack.Children.Add(damageBlock);
                }

                overlayCanvas.Children.Add(damageStack);
            }
        }
Пример #2
0
        public OverlayWindow(bool configure = false)
        {
            InitializeComponent();
            LoadColorSettings();

            string width  = ConfigUtil.GetSetting("OverlayWidth");
            string height = ConfigUtil.GetSetting("OverlayHeight");
            string top    = ConfigUtil.GetSetting("OverlayTop");
            string left   = ConfigUtil.GetSetting("OverlayLeft");

            // Hide other player names on overlay
            IsHideOverlayOtherPlayersEnabled = ConfigUtil.IfSet("HideOverlayOtherPlayers");
            showNameSelection.SelectedIndex  = IsHideOverlayOtherPlayersEnabled ? 1 : 0;

            // Hide/Show crit rate
            IsShowOverlayCritRateEnabled        = ConfigUtil.IfSet("ShowOverlayCritRate");
            showCritRateSelection.SelectedIndex = IsShowOverlayCritRateEnabled ? 1 : 0;

            // Max Rows
            string maxRows = ConfigUtil.GetSetting("MaxOverlayRows");

            if (!string.IsNullOrEmpty(maxRows) && int.TryParse(maxRows, out int max) && max >= 5 && max <= 10)
            {
                CurrentMaxRows = max;
            }

            // selected class
            string savedClass = ConfigUtil.GetSetting("SelectedOverlayClass");

            if (!string.IsNullOrEmpty(savedClass) && PlayerManager.Instance.GetClassList().Contains(savedClass))
            {
                SelectedClass = savedClass;
            }

            var  margin     = SystemParameters.WindowNonClientFrameThickness;
            bool offsetSize = configure || width == null || height == null || top == null || left == null;

            if (!offsetSize)
            {
                CreateRows();
                Title       = "Overlay";
                MinHeight   = 0;
                UpdateTimer = new DispatcherTimer {
                    Interval = new TimeSpan(0, 0, 0, 0, 1000)
                };
                UpdateTimer.Tick  += UpdateTimerTick;
                AllowsTransparency = true;
                Style       = null;
                WindowStyle = WindowStyle.None;
                SetVisible(false);
                ShowActivated = false;
            }
            else
            {
                overlayCanvas.Background = new SolidColorBrush(Color.FromRgb(45, 45, 48));
                CreateRows(true);
                MinHeight          = 130;
                AllowsTransparency = false;
                WindowStyle        = WindowStyle.SingleBorderWindow;
                SetVisible(true);
                var list = PlayerManager.Instance.GetClassList();
                list.Insert(0, Properties.Resources.ANY_CLASS);
                classesList.ItemsSource       = list;
                classesList.SelectedItem      = SelectedClass;
                maxRowsSelection.SelectedItem = maxRowsSelection.Items[CurrentMaxRows - 5];
                LoadTestData();
            }

            if (width != null && double.TryParse(width, out double dvalue) && !double.IsNaN(dvalue))
            {
                Width = offsetSize ? dvalue + margin.Left + margin.Right : dvalue;
            }

            if (height != null && double.TryParse(height, out dvalue) && !double.IsNaN(dvalue))
            {
                Height = offsetSize ? dvalue + margin.Top + margin.Bottom : 0;
                if (!offsetSize)
                {
                    CalculatedRowHeight = dvalue / (CurrentMaxRows + 1);
                }
            }

            if (top != null && double.TryParse(top, out dvalue) && !double.IsNaN(dvalue))
            {
                var test = offsetSize ? dvalue - margin.Top : dvalue;
                if (test >= SystemParameters.VirtualScreenTop && test < SystemParameters.VirtualScreenHeight)
                {
                    Top = test;
                }
            }

            if (left != null && double.TryParse(left, out dvalue) && !double.IsNaN(dvalue))
            {
                var test = offsetSize ? dvalue - margin.Left : dvalue;
                if (test >= SystemParameters.VirtualScreenLeft && test < SystemParameters.VirtualScreenWidth)
                {
                    Left = test;
                }
            }

            int damageMode = ConfigUtil.GetSettingAsInteger("OverlayDamageMode");

            foreach (var item in damageModeSelection.Items.Cast <ComboBoxItem>())
            {
                if ((string)item.Tag == damageMode.ToString(CultureInfo.CurrentCulture))
                {
                    damageModeSelection.SelectedItem = item;
                    CurrentDamageSelectionMode       = damageMode;
                }
            }

            string fontSize       = ConfigUtil.GetSetting("OverlayFontSize");
            bool   fontHasBeenSet = false;

            if (fontSize != null && int.TryParse(fontSize, out CurrentFontSize) && CurrentFontSize >= 0 && CurrentFontSize <= 64)
            {
                foreach (var item in fontSizeSelection.Items)
                {
                    if ((item as ComboBoxItem).Tag as string == fontSize)
                    {
                        fontSizeSelection.SelectedItem = item;
                        SetFont();
                        fontHasBeenSet = true;
                    }
                }
            }

            if (!fontHasBeenSet)
            {
                SetFont();
            }

            if (!offsetSize)
            {
                DataManager.Instance.EventsNewOverlayFight += Instance_NewOverlayFight;
                Active = true;
            }
            else
            {
                // remove when configuring
                DataManager.Instance.EventsNewOverlayFight -= Instance_NewOverlayFight;
            }

            if (!configure)
            {
                var settingsButton = OverlayUtil.CreateButton("Change Settings", "\xE713", CurrentFontSize - 1);
                settingsButton.Click += (object sender, RoutedEventArgs e) => OverlayUtil.OpenOverlay(Dispatcher, true, false);
                settingsButton.Margin = new Thickness(4, 0, 0, 0);

                var copyButton = OverlayUtil.CreateButton("Copy Parse", "\xE8C8", CurrentFontSize - 1);
                copyButton.Click += (object sender, RoutedEventArgs e) =>
                {
                    lock (StatsLock)
                    {
                        (Application.Current.MainWindow as MainWindow)?.AddAndCopyDamageParse(Stats, Stats.StatsList);
                    }
                };

                var refreshButton = OverlayUtil.CreateButton("Cancel Current Parse", "\xE8BB", CurrentFontSize - 1);
                refreshButton.Click += (object sender, RoutedEventArgs e) => OverlayUtil.ResetOverlay(Dispatcher);

                ButtonPopup  = new Popup();
                ButtonsPanel = OverlayUtil.CreateNameStackPanel();
                ButtonsPanel.Children.Add(settingsButton);
                ButtonsPanel.Children.Add(copyButton);
                ButtonsPanel.Children.Add(refreshButton);
                ButtonPopup.Child = ButtonsPanel;
                ButtonPopup.AllowsTransparency = true;
                ButtonPopup.Opacity            = 0.3;
                ButtonPopup.Placement          = PlacementMode.Relative;
                ButtonPopup.PlacementTarget    = this;
                ButtonPopup.VerticalOffset     = -1;

                ButtonsPanel.SizeChanged += (object sender, SizeChangedEventArgs e) =>
                {
                    if (TitlePanel.Margin.Left != e.NewSize.Width + 2)
                    {
                        TitlePanel.Margin = new Thickness(e.NewSize.Width + 2, TitlePanel.Margin.Top, 0, TitlePanel.Margin.Bottom);
                    }

                    if (ButtonsPanel != null && ButtonsPanel.ActualHeight != TitlePanel.ActualHeight)
                    {
                        ButtonsPanel.Height = TitlePanel.ActualHeight;
                    }
                };

                if (DataManager.Instance.GetOverlayFights().Count > 0)
                {
                    UpdateTimer.Start();
                }
            }
        }