Esempio n. 1
0
        private void SaveClick(object sender, RoutedEventArgs e)
        {
            if (!double.IsNaN(overlayCanvas.ActualHeight) && overlayCanvas.ActualHeight > 0)
            {
                ConfigUtil.SetSetting("OverlayHeight", overlayCanvas.ActualHeight.ToString(CultureInfo.CurrentCulture));
            }

            if (!double.IsNaN(overlayCanvas.ActualWidth) && overlayCanvas.ActualWidth > 0)
            {
                ConfigUtil.SetSetting("OverlayWidth", overlayCanvas.ActualWidth.ToString(CultureInfo.CurrentCulture));
            }

            var margin = SystemParameters.WindowNonClientFrameThickness;

            if (Top + margin.Top >= SystemParameters.VirtualScreenTop && (Left + margin.Left) >= SystemParameters.VirtualScreenLeft)
            {
                ConfigUtil.SetSetting("OverlayTop", (Top + margin.Top).ToString(CultureInfo.CurrentCulture));
                ConfigUtil.SetSetting("OverlayLeft", (Left + margin.Left).ToString(CultureInfo.CurrentCulture));
            }

            if (TitleBlock != null)
            {
                if (int.TryParse((fontSizeSelection.SelectedValue as ComboBoxItem).Tag as string, out int size))
                {
                    ConfigUtil.SetSetting("OverlayFontSize", size.ToString(CultureInfo.CurrentCulture));
                }

                ConfigUtil.SetSetting("OverlayDamageMode", (string)(damageModeSelection.SelectedItem as ComboBoxItem).Tag);
                ConfigUtil.SetSetting("HideOverlayOtherPlayers", IsHideOverlayOtherPlayersEnabled.ToString(CultureInfo.CurrentCulture));
                ConfigUtil.SetSetting("ShowOverlayCritRate", IsShowOverlayCritRateEnabled.ToString(CultureInfo.CurrentCulture));
                ConfigUtil.SetSetting("SelectedOverlayClass", SelectedClass);

                ColorComboBoxList.ForEach(colorChoice =>
                {
                    ConfigUtil.SetSetting(colorChoice.Tag as string, (colorChoice.SelectedValue as ColorItem).Name);
                });
            }

            OverlayUtil.OpenOverlay(Dispatcher, false, true);
        }
Esempio n. 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;

            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);
                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 / (MAX_ROWS + 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;
            int    currentFontSize = DEFAULT_TEXT_FONT_SIZE;

            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(currentFontSize);
                        fontHasBeenSet = true;
                    }
                }
            }

            if (!fontHasBeenSet)
            {
                SetFont(currentFontSize);
            }

            if (!offsetSize)
            {
                NpcDamageManager.EventsPlayerAttackProcessed += NpcDamageManager_EventsPlayerAttackProcessed;
                DataManager.Instance.EventsNewInactiveFight  += Instance_EventsNewInactiveFight;
                Active = true;
            }
            else
            {
                // remove when configuring
                NpcDamageManager.EventsPlayerAttackProcessed -= NpcDamageManager_EventsPlayerAttackProcessed;
                DataManager.Instance.EventsNewInactiveFight  -= Instance_EventsNewInactiveFight;
            }

            if (!configure)
            {
                var settingsButton = 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 = CreateButton("Copy Parse", "\xE8C8", currentFontSize - 1);
                copyButton.Click += (object sender, RoutedEventArgs e) =>
                {
                    lock (Stats)
                    {
                        (Application.Current.MainWindow as MainWindow)?.AddAndCopyDamageParse(Stats, Stats.StatsList);
                    }
                };

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

                ButtonPopup  = new Popup();
                ButtonsPanel = 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;
                    }
                };
            }
        }