diff --git a/WhackerLinkConsoleV2/AlertTone.xaml b/WhackerLinkConsoleV2/AlertTone.xaml
new file mode 100644
index 0000000..53e560a
--- /dev/null
+++ b/WhackerLinkConsoleV2/AlertTone.xaml
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+
+
diff --git a/WhackerLinkConsoleV2/AlertTone.xaml.cs b/WhackerLinkConsoleV2/AlertTone.xaml.cs
new file mode 100644
index 0000000..9b9ae1e
--- /dev/null
+++ b/WhackerLinkConsoleV2/AlertTone.xaml.cs
@@ -0,0 +1,121 @@
+/*
+* WhackerLink - WhackerLinkConsoleV2
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program. If not, see .
+*
+* Copyright (C) 2024 Caleb, K4PHP
+*
+*/
+
+using System.Media;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Input;
+using System.Windows.Media;
+
+namespace WhackerLinkConsoleV2.Controls
+{
+ public partial class AlertTone : UserControl
+ {
+ public static readonly DependencyProperty AlertFileNameProperty =
+ DependencyProperty.Register("AlertFileName", typeof(string), typeof(AlertTone), new PropertyMetadata(string.Empty));
+
+ public string AlertFileName
+ {
+ get => (string)GetValue(AlertFileNameProperty);
+ set => SetValue(AlertFileNameProperty, value);
+ }
+
+ public string AlertFilePath { get; set; }
+
+ private Point _startPoint;
+ private bool _isDragging;
+
+ public bool IsEditMode { get; set; }
+
+ public AlertTone(string alertFilePath)
+ {
+ InitializeComponent();
+ AlertFilePath = alertFilePath;
+ AlertFileName = System.IO.Path.GetFileNameWithoutExtension(alertFilePath);
+
+ this.MouseLeftButtonDown += AlertTone_MouseLeftButtonDown;
+ this.MouseMove += AlertTone_MouseMove;
+ this.MouseRightButtonDown += AlertTone_MouseRightButtonDown;
+ }
+
+ private void PlayAlert_Click(object sender, RoutedEventArgs e)
+ {
+ if (!string.IsNullOrEmpty(AlertFilePath) && System.IO.File.Exists(AlertFilePath))
+ {
+ try
+ {
+ using (var player = new SoundPlayer(AlertFilePath))
+ {
+ player.Play();
+ }
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show($"Failed to play alert: {ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
+ }
+ }
+ else
+ {
+ MessageBox.Show("Alert file not set or file not found.", "Alert", MessageBoxButton.OK, MessageBoxImage.Warning);
+ }
+ }
+
+ private void AlertTone_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
+ {
+ if (!IsEditMode) return;
+
+ _startPoint = e.GetPosition(this);
+ _isDragging = true;
+ }
+
+ private void AlertTone_MouseMove(object sender, MouseEventArgs e)
+ {
+ if (_isDragging && IsEditMode)
+ {
+ var parentCanvas = VisualTreeHelper.GetParent(this) as Canvas;
+ if (parentCanvas != null)
+ {
+ Point mousePos = e.GetPosition(parentCanvas);
+ double newLeft = mousePos.X - _startPoint.X;
+ double newTop = mousePos.Y - _startPoint.Y;
+
+ Canvas.SetLeft(this, Math.Max(0, newLeft));
+ Canvas.SetTop(this, Math.Max(0, newTop));
+ }
+ }
+ }
+
+ private void AlertTone_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
+ {
+ if (!IsEditMode || !_isDragging) return;
+
+ _isDragging = false;
+
+ var parentCanvas = VisualTreeHelper.GetParent(this) as Canvas;
+ if (parentCanvas != null)
+ {
+ double x = Canvas.GetLeft(this);
+ double y = Canvas.GetTop(this);
+ }
+
+ ReleaseMouseCapture();
+ }
+ }
+}
diff --git a/WhackerLinkConsoleV2/MainWindow.xaml b/WhackerLinkConsoleV2/MainWindow.xaml
index 9612d4d..6b83bc8 100644
--- a/WhackerLinkConsoleV2/MainWindow.xaml
+++ b/WhackerLinkConsoleV2/MainWindow.xaml
@@ -12,42 +12,13 @@
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/WhackerLinkConsoleV2/MainWindow.xaml.cs b/WhackerLinkConsoleV2/MainWindow.xaml.cs
index ea5886f..7c1b062 100644
--- a/WhackerLinkConsoleV2/MainWindow.xaml.cs
+++ b/WhackerLinkConsoleV2/MainWindow.xaml.cs
@@ -105,8 +105,16 @@ namespace WhackerLinkConsoleV2
{
var systemStatusBox = new SystemStatusBox(system.Name, system.Address, system.Port);
- Canvas.SetLeft(systemStatusBox, offsetX);
- Canvas.SetTop(systemStatusBox, offsetY);
+ if (_settingsManager.SystemStatusPositions.TryGetValue(system.Name, out var position))
+ {
+ Canvas.SetLeft(systemStatusBox, position.X);
+ Canvas.SetTop(systemStatusBox, position.Y);
+ }
+ else
+ {
+ Canvas.SetLeft(systemStatusBox, offsetX);
+ Canvas.SetTop(systemStatusBox, offsetY);
+ }
systemStatusBox.MouseLeftButtonDown += SystemStatusBox_MouseLeftButtonDown;
systemStatusBox.MouseMove += SystemStatusBox_MouseMove;
@@ -156,6 +164,29 @@ namespace WhackerLinkConsoleV2
}
}
}
+
+ foreach (var alertPath in _settingsManager.AlertToneFilePaths)
+ {
+ var alertTone = new AlertTone(alertPath)
+ {
+ IsEditMode = isEditMode
+ };
+
+ if (_settingsManager.AlertTonePositions.TryGetValue(alertPath, out var position))
+ {
+ Canvas.SetLeft(alertTone, position.X);
+ Canvas.SetTop(alertTone, position.Y);
+ }
+ else
+ {
+ Canvas.SetLeft(alertTone, 20);
+ Canvas.SetTop(alertTone, 20);
+ }
+
+ alertTone.MouseRightButtonUp += AlertTone_MouseRightButtonUp;
+
+ ChannelsCanvas.Children.Add(alertTone);
+ }
}
private void SelectWidgets_Click(object sender, RoutedEventArgs e)
@@ -212,13 +243,84 @@ namespace WhackerLinkConsoleV2
private void SystemStatusBox_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) => ChannelBox_MouseLeftButtonDown(sender, e);
private void SystemStatusBox_MouseMove(object sender, MouseEventArgs e) => ChannelBox_MouseMove(sender, e);
- private void SystemStatusBox_MouseRightButtonDown(object sender, MouseButtonEventArgs e) => ChannelBox_MouseRightButtonDown(sender, e);
+
+ private void SystemStatusBox_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
+ {
+ if (!isEditMode) return;
+
+ if (sender is SystemStatusBox systemStatusBox)
+ {
+ double x = Canvas.GetLeft(systemStatusBox);
+ double y = Canvas.GetTop(systemStatusBox);
+ _settingsManager.SystemStatusPositions[systemStatusBox.SystemName] = new ChannelPosition { X = x, Y = y };
+
+ ChannelBox_MouseRightButtonDown(sender, e);
+ }
+ }
private void ToggleEditMode_Click(object sender, RoutedEventArgs e)
{
isEditMode = !isEditMode;
var menuItem = (MenuItem)sender;
menuItem.Header = isEditMode ? "Disable Edit Mode" : "Enable Edit Mode";
+ UpdateEditModeForWidgets();
+ }
+
+ private void UpdateEditModeForWidgets()
+ {
+ foreach (var child in ChannelsCanvas.Children)
+ {
+ if (child is AlertTone alertTone)
+ {
+ alertTone.IsEditMode = isEditMode;
+ }
+ }
+ }
+
+ private void AddAlertTone_Click(object sender, RoutedEventArgs e)
+ {
+ OpenFileDialog openFileDialog = new OpenFileDialog
+ {
+ Filter = "WAV Files (*.wav)|*.wav|All Files (*.*)|*.*",
+ Title = "Select Alert Tone"
+ };
+
+ if (openFileDialog.ShowDialog() == true)
+ {
+ string alertFilePath = openFileDialog.FileName;
+ var alertTone = new AlertTone(alertFilePath)
+ {
+ IsEditMode = isEditMode
+ };
+
+ if (_settingsManager.AlertTonePositions.TryGetValue(alertFilePath, out var position))
+ {
+ Canvas.SetLeft(alertTone, position.X);
+ Canvas.SetTop(alertTone, position.Y);
+ }
+ else
+ {
+ Canvas.SetLeft(alertTone, 20);
+ Canvas.SetTop(alertTone, 20);
+ }
+
+ alertTone.MouseRightButtonUp += AlertTone_MouseRightButtonUp;
+
+ ChannelsCanvas.Children.Add(alertTone);
+ _settingsManager.UpdateAlertTonePaths(alertFilePath);
+ }
+ }
+
+ private void AlertTone_MouseRightButtonUp(object sender, MouseButtonEventArgs e)
+ {
+ if (!isEditMode) return;
+
+ if (sender is AlertTone alertTone)
+ {
+ double x = Canvas.GetLeft(alertTone);
+ double y = Canvas.GetTop(alertTone);
+ _settingsManager.UpdateAlertTonePosition(alertTone.AlertFilePath, x, y);
+ }
}
protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
@@ -238,13 +340,5 @@ namespace WhackerLinkConsoleV2
GenerateChannelWidgets();
}
}
- private void Button_Click(object sender, RoutedEventArgs e)
- {
- if (sender is Button button)
- {
- string buttonContent = button.Content.ToString();
- MessageBox.Show($"Beep boop {buttonContent}");
- }
- }
}
-}
\ No newline at end of file
+}
diff --git a/WhackerLinkConsoleV2/SettingsManager.cs b/WhackerLinkConsoleV2/SettingsManager.cs
index 51ff0ad..9dfa993 100644
--- a/WhackerLinkConsoleV2/SettingsManager.cs
+++ b/WhackerLinkConsoleV2/SettingsManager.cs
@@ -32,6 +32,9 @@ namespace WhackerLinkConsoleV2
public string LastCodeplugPath { get; set; } = null;
public Dictionary ChannelPositions { get; set; } = new Dictionary();
+ public Dictionary SystemStatusPositions { get; set; } = new Dictionary();
+ public List AlertToneFilePaths { get; set; } = new List();
+ public Dictionary AlertTonePositions { get; set; } = new Dictionary();
public void LoadSettings()
{
@@ -48,6 +51,9 @@ namespace WhackerLinkConsoleV2
ShowChannels = loadedSettings.ShowChannels;
LastCodeplugPath = loadedSettings.LastCodeplugPath;
ChannelPositions = loadedSettings.ChannelPositions ?? new Dictionary();
+ SystemStatusPositions = loadedSettings.SystemStatusPositions ?? new Dictionary();
+ AlertToneFilePaths = loadedSettings.AlertToneFilePaths ?? new List();
+ AlertTonePositions = loadedSettings.AlertTonePositions ?? new Dictionary();
}
}
catch (Exception ex)
@@ -56,29 +62,43 @@ namespace WhackerLinkConsoleV2
}
}
- public void SaveSettings()
+ public void UpdateAlertTonePaths(string newFilePath)
{
- try
- {
- var json = JsonConvert.SerializeObject(this, Formatting.Indented);
- File.WriteAllText(SettingsFilePath, json);
- }
- catch (Exception ex)
+ if (!AlertToneFilePaths.Contains(newFilePath))
{
- Console.WriteLine($"Error saving settings: {ex.Message}");
+ AlertToneFilePaths.Add(newFilePath);
+ SaveSettings();
}
}
+ public void UpdateAlertTonePosition(string alertFileName, double x, double y)
+ {
+ AlertTonePositions[alertFileName] = new ChannelPosition { X = x, Y = y };
+ SaveSettings();
+ }
+
public void UpdateChannelPosition(string channelName, double x, double y)
{
- if (ChannelPositions.ContainsKey(channelName))
+ ChannelPositions[channelName] = new ChannelPosition { X = x, Y = y };
+ SaveSettings();
+ }
+
+ public void UpdateSystemStatusPosition(string systemName, double x, double y)
+ {
+ SystemStatusPositions[systemName] = new ChannelPosition { X = x, Y = y };
+ SaveSettings();
+ }
+
+ public void SaveSettings()
+ {
+ try
{
- ChannelPositions[channelName].X = x;
- ChannelPositions[channelName].Y = y;
+ var json = JsonConvert.SerializeObject(this, Formatting.Indented);
+ File.WriteAllText(SettingsFilePath, json);
}
- else
+ catch (Exception ex)
{
- ChannelPositions[channelName] = new ChannelPosition { X = x, Y = y };
+ Console.WriteLine($"Error saving settings: {ex.Message}");
}
}
}