mirror of
https://github.com/9ParsonsB/Pulsar.git
synced 2025-04-05 17:39:39 -04:00
feat: theme dropdown
This commit is contained in:
parent
231710ca68
commit
d2aa64bb3d
127
ObservatoryCore/UI/CoreForm.Designer.cs
generated
127
ObservatoryCore/UI/CoreForm.Designer.cs
generated
@ -34,7 +34,10 @@
|
||||
coreToolStripMenuItem = new ToolStripMenuItem();
|
||||
toolStripMenuItem1 = new ToolStripMenuItem();
|
||||
CorePanel = new Panel();
|
||||
ThemeDropdown = new ComboBox();
|
||||
ThemeLabel = new Label();
|
||||
AudioLabel = new Label();
|
||||
PopupLabel = new Label();
|
||||
PluginSettingsButton = new Button();
|
||||
VoiceSettingsPanel = new Panel();
|
||||
VoiceSpeedSlider = new TrackBar();
|
||||
@ -45,7 +48,6 @@
|
||||
VoiceLabel = new Label();
|
||||
VoiceSpeedLabel = new Label();
|
||||
VoiceVolumeLabel = new Label();
|
||||
VoiceNotificationLabel = new Label();
|
||||
PopupSettingsPanel = new Panel();
|
||||
DurationSpinner = new NumericUpDown();
|
||||
ScaleSpinner = new NumericUpDown();
|
||||
@ -61,7 +63,6 @@
|
||||
DisplayDropdown = new ComboBox();
|
||||
CornerLabel = new Label();
|
||||
DisplayLabel = new Label();
|
||||
PopupNotificationLabel = new Label();
|
||||
PluginFolderButton = new Button();
|
||||
PluginList = new ListView();
|
||||
NameColumn = new ColumnHeader();
|
||||
@ -119,12 +120,13 @@
|
||||
//
|
||||
CorePanel.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
CorePanel.AutoScroll = true;
|
||||
CorePanel.Controls.Add(ThemeDropdown);
|
||||
CorePanel.Controls.Add(ThemeLabel);
|
||||
CorePanel.Controls.Add(AudioLabel);
|
||||
CorePanel.Controls.Add(PopupLabel);
|
||||
CorePanel.Controls.Add(PluginSettingsButton);
|
||||
CorePanel.Controls.Add(VoiceSettingsPanel);
|
||||
CorePanel.Controls.Add(VoiceNotificationLabel);
|
||||
CorePanel.Controls.Add(PopupSettingsPanel);
|
||||
CorePanel.Controls.Add(PopupNotificationLabel);
|
||||
CorePanel.Controls.Add(PluginFolderButton);
|
||||
CorePanel.Controls.Add(PluginList);
|
||||
CorePanel.Location = new Point(123, 12);
|
||||
@ -132,16 +134,43 @@
|
||||
CorePanel.Size = new Size(665, 679);
|
||||
CorePanel.TabIndex = 1;
|
||||
//
|
||||
// ThemeDropdown
|
||||
//
|
||||
ThemeDropdown.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
ThemeDropdown.FormattingEnabled = true;
|
||||
ThemeDropdown.Location = new Point(124, 620);
|
||||
ThemeDropdown.Name = "ThemeDropdown";
|
||||
ThemeDropdown.Size = new Size(121, 23);
|
||||
ThemeDropdown.TabIndex = 10;
|
||||
ThemeDropdown.SelectedIndexChanged += ThemeDropdown_SelectedIndexChanged;
|
||||
//
|
||||
// ThemeLabel
|
||||
//
|
||||
ThemeLabel.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
ThemeLabel.BorderStyle = BorderStyle.FixedSingle;
|
||||
ThemeLabel.Location = new Point(3, 656);
|
||||
ThemeLabel.AutoSize = true;
|
||||
ThemeLabel.Location = new Point(72, 623);
|
||||
ThemeLabel.Name = "ThemeLabel";
|
||||
ThemeLabel.Size = new Size(659, 23);
|
||||
ThemeLabel.TabIndex = 7;
|
||||
ThemeLabel.Text = "❯ Theme";
|
||||
ThemeLabel.TextAlign = ContentAlignment.MiddleLeft;
|
||||
ThemeLabel.Size = new Size(46, 15);
|
||||
ThemeLabel.TabIndex = 9;
|
||||
ThemeLabel.Text = "Theme:";
|
||||
ThemeLabel.TextAlign = ContentAlignment.MiddleCenter;
|
||||
//
|
||||
// AudioLabel
|
||||
//
|
||||
AudioLabel.AutoSize = true;
|
||||
AudioLabel.Location = new Point(5, 435);
|
||||
AudioLabel.Name = "AudioLabel";
|
||||
AudioLabel.Size = new Size(106, 15);
|
||||
AudioLabel.TabIndex = 8;
|
||||
AudioLabel.Text = "Voice Notifications";
|
||||
//
|
||||
// PopupLabel
|
||||
//
|
||||
PopupLabel.AutoSize = true;
|
||||
PopupLabel.Location = new Point(5, 218);
|
||||
PopupLabel.Name = "PopupLabel";
|
||||
PopupLabel.Size = new Size(113, 15);
|
||||
PopupLabel.TabIndex = 7;
|
||||
PopupLabel.Text = "Popup Notifications";
|
||||
//
|
||||
// PluginSettingsButton
|
||||
//
|
||||
@ -159,6 +188,7 @@
|
||||
// VoiceSettingsPanel
|
||||
//
|
||||
VoiceSettingsPanel.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
VoiceSettingsPanel.BorderStyle = BorderStyle.FixedSingle;
|
||||
VoiceSettingsPanel.Controls.Add(VoiceSpeedSlider);
|
||||
VoiceSettingsPanel.Controls.Add(VoiceVolumeSlider);
|
||||
VoiceSettingsPanel.Controls.Add(VoiceTestButton);
|
||||
@ -167,11 +197,10 @@
|
||||
VoiceSettingsPanel.Controls.Add(VoiceLabel);
|
||||
VoiceSettingsPanel.Controls.Add(VoiceSpeedLabel);
|
||||
VoiceSettingsPanel.Controls.Add(VoiceVolumeLabel);
|
||||
VoiceSettingsPanel.Location = new Point(3, 479);
|
||||
VoiceSettingsPanel.Location = new Point(3, 444);
|
||||
VoiceSettingsPanel.Name = "VoiceSettingsPanel";
|
||||
VoiceSettingsPanel.Size = new Size(659, 177);
|
||||
VoiceSettingsPanel.Size = new Size(659, 170);
|
||||
VoiceSettingsPanel.TabIndex = 5;
|
||||
VoiceSettingsPanel.Visible = false;
|
||||
//
|
||||
// VoiceSpeedSlider
|
||||
//
|
||||
@ -221,6 +250,7 @@
|
||||
//
|
||||
// VoiceDropdown
|
||||
//
|
||||
VoiceDropdown.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
VoiceDropdown.FormattingEnabled = true;
|
||||
VoiceDropdown.Location = new Point(121, 102);
|
||||
VoiceDropdown.Name = "VoiceDropdown";
|
||||
@ -258,21 +288,10 @@
|
||||
VoiceVolumeLabel.Text = "Volume:";
|
||||
VoiceVolumeLabel.TextAlign = ContentAlignment.MiddleRight;
|
||||
//
|
||||
// VoiceNotificationLabel
|
||||
//
|
||||
VoiceNotificationLabel.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
VoiceNotificationLabel.BorderStyle = BorderStyle.FixedSingle;
|
||||
VoiceNotificationLabel.Location = new Point(3, 456);
|
||||
VoiceNotificationLabel.Name = "VoiceNotificationLabel";
|
||||
VoiceNotificationLabel.Size = new Size(659, 23);
|
||||
VoiceNotificationLabel.TabIndex = 4;
|
||||
VoiceNotificationLabel.Text = "❯ Voice Notifications";
|
||||
VoiceNotificationLabel.TextAlign = ContentAlignment.MiddleLeft;
|
||||
VoiceNotificationLabel.Click += VoiceNotificationLabel_Click;
|
||||
//
|
||||
// PopupSettingsPanel
|
||||
//
|
||||
PopupSettingsPanel.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
PopupSettingsPanel.BorderStyle = BorderStyle.FixedSingle;
|
||||
PopupSettingsPanel.Controls.Add(DurationSpinner);
|
||||
PopupSettingsPanel.Controls.Add(ScaleSpinner);
|
||||
PopupSettingsPanel.Controls.Add(LabelColour);
|
||||
@ -287,16 +306,15 @@
|
||||
PopupSettingsPanel.Controls.Add(DisplayDropdown);
|
||||
PopupSettingsPanel.Controls.Add(CornerLabel);
|
||||
PopupSettingsPanel.Controls.Add(DisplayLabel);
|
||||
PopupSettingsPanel.Location = new Point(3, 248);
|
||||
PopupSettingsPanel.Location = new Point(3, 227);
|
||||
PopupSettingsPanel.Name = "PopupSettingsPanel";
|
||||
PopupSettingsPanel.Size = new Size(659, 208);
|
||||
PopupSettingsPanel.Size = new Size(659, 207);
|
||||
PopupSettingsPanel.TabIndex = 3;
|
||||
PopupSettingsPanel.Visible = false;
|
||||
//
|
||||
// DurationSpinner
|
||||
//
|
||||
DurationSpinner.Increment = new decimal(new int[] { 25, 0, 0, 0 });
|
||||
DurationSpinner.Location = new Point(121, 119);
|
||||
DurationSpinner.Location = new Point(121, 123);
|
||||
DurationSpinner.Maximum = new decimal(new int[] { 60000, 0, 0, 0 });
|
||||
DurationSpinner.Minimum = new decimal(new int[] { 100, 0, 0, 0 });
|
||||
DurationSpinner.Name = "DurationSpinner";
|
||||
@ -307,7 +325,7 @@
|
||||
//
|
||||
// ScaleSpinner
|
||||
//
|
||||
ScaleSpinner.Location = new Point(121, 90);
|
||||
ScaleSpinner.Location = new Point(121, 94);
|
||||
ScaleSpinner.Maximum = new decimal(new int[] { 500, 0, 0, 0 });
|
||||
ScaleSpinner.Minimum = new decimal(new int[] { 1, 0, 0, 0 });
|
||||
ScaleSpinner.Name = "ScaleSpinner";
|
||||
@ -319,7 +337,7 @@
|
||||
// LabelColour
|
||||
//
|
||||
LabelColour.AutoSize = true;
|
||||
LabelColour.Location = new Point(68, 152);
|
||||
LabelColour.Location = new Point(68, 156);
|
||||
LabelColour.Name = "LabelColour";
|
||||
LabelColour.Size = new Size(46, 15);
|
||||
LabelColour.TabIndex = 13;
|
||||
@ -329,7 +347,7 @@
|
||||
// TestButton
|
||||
//
|
||||
TestButton.FlatStyle = FlatStyle.Flat;
|
||||
TestButton.Location = new Point(190, 148);
|
||||
TestButton.Location = new Point(190, 152);
|
||||
TestButton.Name = "TestButton";
|
||||
TestButton.Size = new Size(51, 23);
|
||||
TestButton.TabIndex = 12;
|
||||
@ -340,7 +358,7 @@
|
||||
// ColourButton
|
||||
//
|
||||
ColourButton.FlatStyle = FlatStyle.Flat;
|
||||
ColourButton.Location = new Point(121, 148);
|
||||
ColourButton.Location = new Point(121, 152);
|
||||
ColourButton.Name = "ColourButton";
|
||||
ColourButton.Size = new Size(51, 23);
|
||||
ColourButton.TabIndex = 11;
|
||||
@ -350,7 +368,7 @@
|
||||
// PopupCheckbox
|
||||
//
|
||||
PopupCheckbox.AutoSize = true;
|
||||
PopupCheckbox.Location = new Point(120, 177);
|
||||
PopupCheckbox.Location = new Point(120, 181);
|
||||
PopupCheckbox.Name = "PopupCheckbox";
|
||||
PopupCheckbox.Size = new Size(68, 19);
|
||||
PopupCheckbox.TabIndex = 10;
|
||||
@ -361,7 +379,7 @@
|
||||
// LabelDuration
|
||||
//
|
||||
LabelDuration.AutoSize = true;
|
||||
LabelDuration.Location = new Point(32, 121);
|
||||
LabelDuration.Location = new Point(32, 125);
|
||||
LabelDuration.Name = "LabelDuration";
|
||||
LabelDuration.Size = new Size(83, 15);
|
||||
LabelDuration.TabIndex = 9;
|
||||
@ -371,7 +389,7 @@
|
||||
// LabelScale
|
||||
//
|
||||
LabelScale.AutoSize = true;
|
||||
LabelScale.Location = new Point(57, 92);
|
||||
LabelScale.Location = new Point(57, 96);
|
||||
LabelScale.Name = "LabelScale";
|
||||
LabelScale.Size = new Size(58, 15);
|
||||
LabelScale.TabIndex = 7;
|
||||
@ -380,8 +398,9 @@
|
||||
//
|
||||
// FontDropdown
|
||||
//
|
||||
FontDropdown.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
FontDropdown.FormattingEnabled = true;
|
||||
FontDropdown.Location = new Point(120, 61);
|
||||
FontDropdown.Location = new Point(120, 65);
|
||||
FontDropdown.Name = "FontDropdown";
|
||||
FontDropdown.Size = new Size(121, 23);
|
||||
FontDropdown.TabIndex = 5;
|
||||
@ -390,7 +409,7 @@
|
||||
// LabelFont
|
||||
//
|
||||
LabelFont.AutoSize = true;
|
||||
LabelFont.Location = new Point(80, 64);
|
||||
LabelFont.Location = new Point(80, 68);
|
||||
LabelFont.Name = "LabelFont";
|
||||
LabelFont.Size = new Size(34, 15);
|
||||
LabelFont.TabIndex = 4;
|
||||
@ -399,9 +418,10 @@
|
||||
//
|
||||
// CornerDropdown
|
||||
//
|
||||
CornerDropdown.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
CornerDropdown.FormattingEnabled = true;
|
||||
CornerDropdown.Items.AddRange(new object[] { "Bottom-Right", "Bottom-Left", "Top-Right", "Top-Left" });
|
||||
CornerDropdown.Location = new Point(120, 32);
|
||||
CornerDropdown.Location = new Point(120, 36);
|
||||
CornerDropdown.Name = "CornerDropdown";
|
||||
CornerDropdown.Size = new Size(121, 23);
|
||||
CornerDropdown.TabIndex = 3;
|
||||
@ -409,8 +429,9 @@
|
||||
//
|
||||
// DisplayDropdown
|
||||
//
|
||||
DisplayDropdown.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
DisplayDropdown.FormattingEnabled = true;
|
||||
DisplayDropdown.Location = new Point(120, 3);
|
||||
DisplayDropdown.Location = new Point(120, 7);
|
||||
DisplayDropdown.Name = "DisplayDropdown";
|
||||
DisplayDropdown.Size = new Size(121, 23);
|
||||
DisplayDropdown.TabIndex = 2;
|
||||
@ -419,7 +440,7 @@
|
||||
// CornerLabel
|
||||
//
|
||||
CornerLabel.AutoSize = true;
|
||||
CornerLabel.Location = new Point(68, 35);
|
||||
CornerLabel.Location = new Point(68, 39);
|
||||
CornerLabel.Name = "CornerLabel";
|
||||
CornerLabel.Size = new Size(46, 15);
|
||||
CornerLabel.TabIndex = 1;
|
||||
@ -429,25 +450,13 @@
|
||||
// DisplayLabel
|
||||
//
|
||||
DisplayLabel.AutoSize = true;
|
||||
DisplayLabel.Location = new Point(66, 6);
|
||||
DisplayLabel.Location = new Point(66, 10);
|
||||
DisplayLabel.Name = "DisplayLabel";
|
||||
DisplayLabel.Size = new Size(48, 15);
|
||||
DisplayLabel.TabIndex = 0;
|
||||
DisplayLabel.Text = "Display:";
|
||||
DisplayLabel.TextAlign = ContentAlignment.MiddleRight;
|
||||
//
|
||||
// PopupNotificationLabel
|
||||
//
|
||||
PopupNotificationLabel.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
PopupNotificationLabel.BorderStyle = BorderStyle.FixedSingle;
|
||||
PopupNotificationLabel.Location = new Point(3, 225);
|
||||
PopupNotificationLabel.Name = "PopupNotificationLabel";
|
||||
PopupNotificationLabel.Size = new Size(659, 23);
|
||||
PopupNotificationLabel.TabIndex = 2;
|
||||
PopupNotificationLabel.Text = "❯ Popup Notifications";
|
||||
PopupNotificationLabel.TextAlign = ContentAlignment.MiddleLeft;
|
||||
PopupNotificationLabel.Click += PopupNotificationLabel_Click;
|
||||
//
|
||||
// PluginFolderButton
|
||||
//
|
||||
PluginFolderButton.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
@ -593,6 +602,7 @@
|
||||
CoreMenu.ResumeLayout(false);
|
||||
CoreMenu.PerformLayout();
|
||||
CorePanel.ResumeLayout(false);
|
||||
CorePanel.PerformLayout();
|
||||
VoiceSettingsPanel.ResumeLayout(false);
|
||||
VoiceSettingsPanel.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)VoiceSpeedSlider).EndInit();
|
||||
@ -627,7 +637,6 @@
|
||||
private ComboBox DisplayDropdown;
|
||||
private Label CornerLabel;
|
||||
private Label DisplayLabel;
|
||||
private Label PopupNotificationLabel;
|
||||
private NumericUpDown DurationSpinner;
|
||||
private NumericUpDown ScaleSpinner;
|
||||
private Label LabelColour;
|
||||
@ -649,9 +658,11 @@
|
||||
private Label VoiceLabel;
|
||||
private Label VoiceSpeedLabel;
|
||||
private Label VoiceVolumeLabel;
|
||||
private Label VoiceNotificationLabel;
|
||||
private Button PluginSettingsButton;
|
||||
private Label ThemeLabel;
|
||||
private ToolTip OverrideTooltip;
|
||||
private Label AudioLabel;
|
||||
private Label PopupLabel;
|
||||
private Label ThemeLabel;
|
||||
private ComboBox ThemeDropdown;
|
||||
}
|
||||
}
|
@ -12,6 +12,7 @@ namespace Observatory.UI
|
||||
public partial class CoreForm : Form
|
||||
{
|
||||
private readonly Dictionary<object, Panel> uiPanels;
|
||||
private ThemeManager themeManager;
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
private static extern int SendMessage(IntPtr hWnd, Int32 wMsg, bool wParam, Int32 lParam);
|
||||
@ -52,22 +53,20 @@ namespace Observatory.UI
|
||||
DisableOverriddenNotification();
|
||||
CoreMenu.ItemClicked += CoreMenu_ItemClicked;
|
||||
|
||||
PreCollapsePanels();
|
||||
themeManager = ThemeManager.GetInstance;
|
||||
themeManager.RegisterControl(this);
|
||||
|
||||
ThemeManager.GetInstance.RegisterControl(this);
|
||||
}
|
||||
|
||||
private void PreCollapsePanels()
|
||||
{
|
||||
AdjustPanelsBelow(VoiceSettingsPanel, AdjustmentDirection.Up);
|
||||
AdjustPanelsBelow(PopupSettingsPanel, AdjustmentDirection.Up);
|
||||
foreach (var theme in themeManager.GetThemes)
|
||||
{
|
||||
ThemeDropdown.Items.Add(theme);
|
||||
}
|
||||
ThemeDropdown.SelectedItem = themeManager.CurrentTheme;
|
||||
}
|
||||
|
||||
private void CoreMenu_SizeChanged(object? sender, EventArgs e)
|
||||
{
|
||||
CorePanel.Location = new Point(12 + CoreMenu.Width, 12);
|
||||
CorePanel.Width = Width - CoreMenu.Width - 40;
|
||||
|
||||
}
|
||||
|
||||
private readonly Dictionary<string, ToolStripMenuItem> pluginList;
|
||||
@ -88,7 +87,6 @@ namespace Observatory.UI
|
||||
|
||||
private void ResizePanels(Point location, int widthChange)
|
||||
{
|
||||
|
||||
CorePanel.Location = location;
|
||||
CorePanel.Width += widthChange;
|
||||
foreach (var panel in uiPanels)
|
||||
@ -99,7 +97,6 @@ namespace Observatory.UI
|
||||
panel.Value.Size = CorePanel.Size;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void CoreMenu_ItemClicked(object? _, ToolStripItemClickedEventArgs e)
|
||||
@ -261,61 +258,6 @@ namespace Observatory.UI
|
||||
PluginComparer?.Clear();
|
||||
}
|
||||
|
||||
private void PopupNotificationLabel_Click(object _, EventArgs e)
|
||||
{
|
||||
CorePanel.SuspendLayout();
|
||||
if (PopupNotificationLabel.Text[0] == '❯')
|
||||
{
|
||||
PopupNotificationLabel.Text = PopupNotificationLabel.Text.Replace('❯', '⌵');
|
||||
PopupSettingsPanel.Visible = true;
|
||||
AdjustPanelsBelow(PopupSettingsPanel, AdjustmentDirection.Down);
|
||||
}
|
||||
else
|
||||
{
|
||||
PopupNotificationLabel.Text = PopupNotificationLabel.Text.Replace('⌵', '❯');
|
||||
PopupSettingsPanel.Visible = false;
|
||||
AdjustPanelsBelow(PopupSettingsPanel, AdjustmentDirection.Up);
|
||||
}
|
||||
CorePanel.ResumeLayout();
|
||||
}
|
||||
|
||||
private void VoiceNotificationLabel_Click(object sender, EventArgs e)
|
||||
{
|
||||
CorePanel.SuspendLayout();
|
||||
if (VoiceNotificationLabel.Text[0] == '❯')
|
||||
{
|
||||
VoiceNotificationLabel.Text = VoiceNotificationLabel.Text.Replace('❯', '⌵');
|
||||
VoiceSettingsPanel.Visible = true;
|
||||
AdjustPanelsBelow(VoiceSettingsPanel, AdjustmentDirection.Down);
|
||||
}
|
||||
else
|
||||
{
|
||||
VoiceNotificationLabel.Text = VoiceNotificationLabel.Text.Replace('⌵', '❯');
|
||||
VoiceSettingsPanel.Visible = false;
|
||||
AdjustPanelsBelow(VoiceSettingsPanel, AdjustmentDirection.Up);
|
||||
}
|
||||
CorePanel.ResumeLayout();
|
||||
}
|
||||
|
||||
private void AdjustPanelsBelow(Control toggledControl, AdjustmentDirection adjustmentDirection)
|
||||
{
|
||||
var distance = adjustmentDirection == AdjustmentDirection.Down ? toggledControl.Height : -toggledControl.Height;
|
||||
foreach (Control control in CorePanel.Controls)
|
||||
{
|
||||
var loc = control.Location;
|
||||
if (loc.Y >= toggledControl.Location.Y && control != toggledControl)
|
||||
{
|
||||
loc.Y = control.Location.Y + distance;
|
||||
control.Location = loc;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal enum AdjustmentDirection
|
||||
{
|
||||
Up, Down
|
||||
}
|
||||
|
||||
private Observatory.NativeNotification.NativePopup? nativePopup;
|
||||
|
||||
private void TestButton_Click(object sender, EventArgs e)
|
||||
@ -345,5 +287,10 @@ namespace Observatory.UI
|
||||
{
|
||||
Process.Start(new ProcessStartInfo(url) { UseShellExecute = true });
|
||||
}
|
||||
|
||||
private void ThemeDropdown_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
themeManager.CurrentTheme = ThemeDropdown.SelectedItem.ToString() ?? themeManager.CurrentTheme;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,13 +1,5 @@
|
||||
using Observatory.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Observatory.UI
|
||||
{
|
||||
@ -15,10 +7,23 @@ namespace Observatory.UI
|
||||
{
|
||||
private CancellationTokenSource ReadAllCancel;
|
||||
|
||||
private byte[] eggBytes =
|
||||
{
|
||||
0x52, 0x65, 0x74, 0x69,
|
||||
0x63, 0x75, 0x6C, 0x61,
|
||||
0x74, 0x69, 0x6E, 0x67,
|
||||
0x20, 0x53, 0x70, 0x6C,
|
||||
0x69, 0x6E, 0x65, 0x73,
|
||||
0x2E, 0x2E, 0x2E
|
||||
};
|
||||
|
||||
public ReadAllForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
|
||||
if (new Random().Next(1, 20) == 20)
|
||||
Text = Encoding.UTF8.GetString(eggBytes);
|
||||
|
||||
var ReadAllJournals = LogMonitor.GetInstance.ReadAllGenerator(out int fileCount);
|
||||
int progressCount = 0;
|
||||
ReadAllCancel = new CancellationTokenSource();
|
||||
@ -41,7 +46,6 @@ namespace Observatory.UI
|
||||
}
|
||||
Invoke(()=>Close());
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void CancelButton_Click(object sender, EventArgs e)
|
||||
|
@ -1,368 +0,0 @@
|
||||
using Observatory.Framework;
|
||||
using Observatory.Framework.Interfaces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Common;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms.VisualStyles;
|
||||
|
||||
namespace Observatory.UI
|
||||
{
|
||||
internal class SettingsPanel : Panel
|
||||
{
|
||||
public Label Header;
|
||||
private IObservatoryPlugin _plugin;
|
||||
private Action<Control, CoreForm.AdjustmentDirection> _adjustPanelsBelow;
|
||||
|
||||
internal SettingsPanel(IObservatoryPlugin plugin, Action<Control, CoreForm.AdjustmentDirection> adjustPanelsBelow) : base()
|
||||
{
|
||||
Header = CreateHeader(plugin.Name);
|
||||
_plugin = plugin;
|
||||
_adjustPanelsBelow = adjustPanelsBelow;
|
||||
|
||||
// Filtered to only settings without SettingIgnore attribute
|
||||
var settings = PluginManagement.PluginManager.GetSettingDisplayNames(plugin.Settings).Where(s => !Attribute.IsDefined(s.Key, typeof (SettingIgnore)));
|
||||
CreateControls(settings);
|
||||
|
||||
}
|
||||
|
||||
private void CreateControls(IEnumerable<KeyValuePair<PropertyInfo, string>> settings)
|
||||
{
|
||||
int controlRow = 0;
|
||||
bool recentHalfCol = false;
|
||||
|
||||
foreach (var setting in settings)
|
||||
{
|
||||
// Reset the column tracking for checkboxes if this isn't a checkbox
|
||||
if (setting.Key.PropertyType.Name != "Boolean" && setting.Key.PropertyType.Name != "Button")
|
||||
recentHalfCol = false;
|
||||
|
||||
switch (setting.Key.GetValue(_plugin.Settings))
|
||||
{
|
||||
case bool:
|
||||
var checkBox = CreateBoolSetting(setting);
|
||||
controlRow += recentHalfCol ? 0 : 1;
|
||||
checkBox.Location = GetSettingPosition(controlRow, recentHalfCol);
|
||||
|
||||
recentHalfCol = !recentHalfCol;
|
||||
|
||||
Controls.Add(checkBox);
|
||||
break;
|
||||
case string:
|
||||
var stringLabel = CreateSettingLabel(setting.Value);
|
||||
var textBox = CreateStringSetting(setting.Key);
|
||||
controlRow++;
|
||||
stringLabel.Location = GetSettingPosition(controlRow);
|
||||
textBox.Location = GetSettingPosition(controlRow, true);
|
||||
|
||||
Controls.Add(stringLabel);
|
||||
Controls.Add(textBox);
|
||||
|
||||
break;
|
||||
case FileInfo:
|
||||
var fileLabel = CreateSettingLabel(setting.Value);
|
||||
var pathTextBox = CreateFilePathSetting(setting.Key);
|
||||
var pathButton = CreateFileBrowseSetting(setting.Key, pathTextBox);
|
||||
|
||||
controlRow++;
|
||||
|
||||
fileLabel.Location = GetSettingPosition(controlRow);
|
||||
pathTextBox.Location = GetSettingPosition(controlRow, true);
|
||||
pathButton.Location = GetSettingPosition(++controlRow, true);
|
||||
|
||||
Controls.Add(fileLabel);
|
||||
Controls.Add(pathTextBox);
|
||||
Controls.Add(pathButton);
|
||||
|
||||
break;
|
||||
case int:
|
||||
// We have two options for integer values:
|
||||
// 1) A slider (explicit by way of the SettingIntegerUseSlider attribute and bounded to 0..100 by default)
|
||||
// 2) A numeric up/down (default otherwise, and is unbounded by default).
|
||||
// Bounds for both can be set via the SettingNumericBounds attribute, only the up/down uses Increment.
|
||||
var intLabel = CreateSettingLabel(setting.Value);
|
||||
Control intControl;
|
||||
controlRow++;
|
||||
if (System.Attribute.IsDefined(setting.Key, typeof(SettingNumericUseSlider)))
|
||||
{
|
||||
intControl = CreateSettingTrackbar(setting.Key);
|
||||
}
|
||||
else
|
||||
{
|
||||
intControl = CreateSettingNumericUpDown(setting.Key);
|
||||
}
|
||||
intLabel.Location = GetSettingPosition(controlRow);
|
||||
intControl.Location = GetSettingPosition(controlRow, true);
|
||||
|
||||
Controls.Add(intLabel);
|
||||
Controls.Add(intControl);
|
||||
break;
|
||||
case Action action:
|
||||
var button = CreateSettingButton(setting.Value, action);
|
||||
|
||||
controlRow += recentHalfCol ? 0 : 1;
|
||||
button.Location = GetSettingPosition(controlRow, recentHalfCol);
|
||||
recentHalfCol = !recentHalfCol;
|
||||
|
||||
Controls.Add(button);
|
||||
break;
|
||||
case Dictionary<string, object> dictSetting:
|
||||
var dictLabel = CreateSettingLabel(setting.Value);
|
||||
var dropdown = CreateSettingDropdown(setting.Key, dictSetting);
|
||||
controlRow++;
|
||||
|
||||
dictLabel.Location = GetSettingPosition(controlRow);
|
||||
dropdown.Location = GetSettingPosition(controlRow, true);
|
||||
Controls.Add(dictLabel);
|
||||
Controls.Add(dropdown);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
Height = 3 + controlRow * 29;
|
||||
}
|
||||
|
||||
private static Point GetSettingPosition(int rowNum, bool secondCol = false)
|
||||
{
|
||||
return new Point(10 + (secondCol ? 200 : 0), -26 + rowNum * 29);
|
||||
}
|
||||
|
||||
|
||||
private Label CreateSettingLabel(string settingName)
|
||||
{
|
||||
Label label = new()
|
||||
{
|
||||
Text = settingName + ": ",
|
||||
TextAlign = System.Drawing.ContentAlignment.MiddleRight,
|
||||
Width = 200,
|
||||
ForeColor = Color.LightGray
|
||||
};
|
||||
|
||||
return label;
|
||||
}
|
||||
|
||||
private ComboBox CreateSettingDropdown(PropertyInfo setting, Dictionary<string, object> dropdownItems)
|
||||
{
|
||||
var backingValueName = (SettingBackingValue?)Attribute.GetCustomAttribute(setting, typeof(SettingBackingValue));
|
||||
|
||||
var backingValue = from s in PluginManagement.PluginManager.GetSettingDisplayNames(_plugin.Settings)
|
||||
where s.Value == backingValueName?.BackingProperty
|
||||
select s.Key;
|
||||
|
||||
if (backingValue.Count() != 1)
|
||||
throw new($"{_plugin.ShortName}: Dictionary settings must have exactly one backing value.");
|
||||
|
||||
ComboBox comboBox = new()
|
||||
{
|
||||
Width = 200,
|
||||
DropDownStyle = ComboBoxStyle.DropDownList
|
||||
};
|
||||
|
||||
comboBox.Items.AddRange(dropdownItems.OrderBy(s => s.Key).Select(s => s.Key).ToArray());
|
||||
|
||||
string? currentSelection = backingValue.First().GetValue(_plugin.Settings)?.ToString();
|
||||
|
||||
if (currentSelection?.Length > 0)
|
||||
{
|
||||
comboBox.SelectedItem = currentSelection;
|
||||
}
|
||||
|
||||
comboBox.SelectedValueChanged += (sender, e) =>
|
||||
{
|
||||
backingValue.First().SetValue(_plugin.Settings, comboBox.SelectedItem.ToString());
|
||||
SaveSettings();
|
||||
};
|
||||
|
||||
return comboBox;
|
||||
}
|
||||
|
||||
private Button CreateSettingButton(string settingName, Action action)
|
||||
{
|
||||
Button button = new()
|
||||
{
|
||||
Text = settingName
|
||||
};
|
||||
|
||||
button.Click += (sender, e) =>
|
||||
{
|
||||
action.Invoke();
|
||||
SaveSettings();
|
||||
};
|
||||
|
||||
return button;
|
||||
}
|
||||
|
||||
private TrackBar CreateSettingTrackbar(PropertyInfo setting)
|
||||
{
|
||||
SettingNumericBounds? bounds = (SettingNumericBounds?)System.Attribute.GetCustomAttribute(setting, typeof(SettingNumericBounds));
|
||||
TrackBar trackBar = new ()
|
||||
{
|
||||
Orientation = Orientation.Horizontal,
|
||||
TickStyle = TickStyle.Both,
|
||||
Width = 200,
|
||||
Minimum = Convert.ToInt32(bounds?.Minimum ?? 0),
|
||||
Maximum = Convert.ToInt32(bounds?.Maximum ?? 100)
|
||||
};
|
||||
|
||||
trackBar.Value = (int?)setting.GetValue(_plugin.Settings) ?? 0;
|
||||
|
||||
trackBar.ValueChanged += (sender, e) =>
|
||||
{
|
||||
setting.SetValue(_plugin.Settings, trackBar.Value);
|
||||
SaveSettings();
|
||||
};
|
||||
|
||||
return trackBar;
|
||||
}
|
||||
|
||||
private NumericUpDown CreateSettingNumericUpDown(PropertyInfo setting)
|
||||
{
|
||||
SettingNumericBounds? bounds = (SettingNumericBounds?)System.Attribute.GetCustomAttribute(setting, typeof(SettingNumericBounds));
|
||||
NumericUpDown numericUpDown = new()
|
||||
{
|
||||
|
||||
Width = 200,
|
||||
Minimum = Convert.ToInt32(bounds?.Minimum ?? Int32.MinValue),
|
||||
Maximum = Convert.ToInt32(bounds?.Maximum ?? Int32.MaxValue),
|
||||
Increment = Convert.ToInt32(bounds?.Increment ?? 1)
|
||||
};
|
||||
|
||||
numericUpDown.Value = (int?)setting.GetValue(_plugin.Settings) ?? 0;
|
||||
|
||||
numericUpDown.ValueChanged += (sender, e) =>
|
||||
{
|
||||
setting.SetValue(_plugin.Settings, numericUpDown.Value);
|
||||
SaveSettings();
|
||||
};
|
||||
|
||||
return numericUpDown;
|
||||
}
|
||||
|
||||
private CheckBox CreateBoolSetting(KeyValuePair<PropertyInfo, string> setting)
|
||||
{
|
||||
CheckBox checkBox = new()
|
||||
{
|
||||
Text = setting.Value,
|
||||
TextAlign= System.Drawing.ContentAlignment.MiddleLeft,
|
||||
Checked = (bool?)setting.Key.GetValue(_plugin.Settings) ?? false,
|
||||
Width = 200,
|
||||
ForeColor = Color.LightGray
|
||||
};
|
||||
|
||||
checkBox.CheckedChanged += (sender, e) =>
|
||||
{
|
||||
setting.Key.SetValue(_plugin.Settings, checkBox.Checked);
|
||||
SaveSettings();
|
||||
};
|
||||
|
||||
return checkBox;
|
||||
}
|
||||
|
||||
private TextBox CreateStringSetting(PropertyInfo setting)
|
||||
{
|
||||
TextBox textBox = new()
|
||||
{
|
||||
Text = (setting.GetValue(_plugin.Settings) ?? String.Empty).ToString(),
|
||||
Width = 200
|
||||
};
|
||||
|
||||
textBox.TextChanged += (object? sender, EventArgs e) =>
|
||||
{
|
||||
setting.SetValue(_plugin.Settings, textBox.Text);
|
||||
SaveSettings();
|
||||
};
|
||||
|
||||
return textBox;
|
||||
}
|
||||
|
||||
private TextBox CreateFilePathSetting(PropertyInfo setting)
|
||||
{
|
||||
var fileInfo = (FileInfo?)setting.GetValue(_plugin.Settings);
|
||||
|
||||
TextBox textBox = new()
|
||||
{
|
||||
Text = fileInfo?.FullName ?? string.Empty,
|
||||
Width = 200
|
||||
};
|
||||
|
||||
textBox.TextChanged += (object? sender, EventArgs e) =>
|
||||
{
|
||||
setting.SetValue(_plugin.Settings, new FileInfo(textBox.Text));
|
||||
SaveSettings();
|
||||
};
|
||||
|
||||
return textBox;
|
||||
}
|
||||
|
||||
private Button CreateFileBrowseSetting(PropertyInfo setting, TextBox textBox)
|
||||
{
|
||||
Button button = new()
|
||||
{
|
||||
Text = "Browse"
|
||||
};
|
||||
|
||||
button.Click += (object? sender, EventArgs e) =>
|
||||
{
|
||||
var currentDir = ((FileInfo?)setting.GetValue(_plugin.Settings))?.DirectoryName;
|
||||
|
||||
OpenFileDialog ofd = new OpenFileDialog()
|
||||
{
|
||||
Title = "Select File...",
|
||||
Filter = "Lua files (*.lua)|*.lua|All files (*.*)|*.*",
|
||||
FilterIndex = 0,
|
||||
InitialDirectory = currentDir ?? Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
|
||||
};
|
||||
|
||||
var browseResult = ofd.ShowDialog();
|
||||
|
||||
if (browseResult == DialogResult.OK)
|
||||
{
|
||||
textBox.Text = ofd.FileName;
|
||||
}
|
||||
};
|
||||
|
||||
return button;
|
||||
}
|
||||
|
||||
private Label CreateHeader(string pluginName)
|
||||
{
|
||||
var headerLabel = new Label()
|
||||
{
|
||||
Text = "❯ " + pluginName,
|
||||
BorderStyle = BorderStyle.FixedSingle,
|
||||
ForeColor = Color.White
|
||||
};
|
||||
|
||||
headerLabel.Click += HeaderLabel_Click;
|
||||
|
||||
return headerLabel;
|
||||
}
|
||||
|
||||
private void HeaderLabel_Click(object? _, EventArgs e)
|
||||
{
|
||||
this.Parent?.SuspendLayout();
|
||||
if (Header.Text[0] == '❯')
|
||||
{
|
||||
Header.Text = Header.Text.Replace('❯', '⌵');
|
||||
this.Visible = true;
|
||||
_adjustPanelsBelow.Invoke(this, CoreForm.AdjustmentDirection.Down);
|
||||
}
|
||||
else
|
||||
{
|
||||
Header.Text = Header.Text.Replace('⌵', '❯');
|
||||
this.Visible = false;
|
||||
_adjustPanelsBelow.Invoke(this, CoreForm.AdjustmentDirection.Up);
|
||||
}
|
||||
this.Parent?.ResumeLayout();
|
||||
}
|
||||
|
||||
private void SaveSettings()
|
||||
{
|
||||
PluginManagement.PluginManager.GetInstance.SaveSettings(_plugin, _plugin.Settings);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user