Add support for SelectedChannelManager; update WhackerLinkLib submodule

pull/1/head
php 1 year ago
parent 8d73e7d573
commit 1527bd5034

@ -8,8 +8,8 @@
DataContext="{Binding RelativeSource={RelativeSource Self}}">
<Border BorderBrush="Gray" BorderThickness="1" CornerRadius="5" Background="Gray">
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock Text="{Binding AlertFileName}" Margin="5" TextWrapping="Wrap" HorizontalAlignment="Center"/>
<Button Content="Play Alert" Background="Green" Click="PlayAlert_Click" Width="80" />
<TextBlock Text="{Binding AlertFileName}" Margin="5" TextWrapping="Wrap" Foreground="White" HorizontalAlignment="Center"/>
<Button Content="Play Alert" Background="Green" Click="PlayAlert_Click" Foreground="White" Width="80" />
</StackPanel>
</Border>
</UserControl>

@ -1,7 +1,8 @@
<UserControl x:Class="WhackerLinkConsoleV2.Controls.ChannelBox"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="200" Height="120" Background="#222222" BorderBrush="Gray" BorderThickness="2">
Width="200" Height="120" Background="{Binding Background, RelativeSource={RelativeSource AncestorType=UserControl}}"
BorderBrush="Gray" BorderThickness="2">
<Border CornerRadius="5" Background="{Binding Background, RelativeSource={RelativeSource AncestorType=UserControl}}">
<Grid Margin="5">
<Grid.RowDefinitions>

@ -21,6 +21,7 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
namespace WhackerLinkConsoleV2.Controls
{
@ -30,56 +31,60 @@ namespace WhackerLinkConsoleV2.Controls
public string SystemName { get; set; }
public string TGID { get; set; }
public ChannelBox()
{
InitializeComponent();
DataContext = this;
public event EventHandler<ChannelBox> PTTButtonClicked;
private readonly SelectedChannelsManager _selectedChannelsManager;
public bool IsEditMode { get; set; }
MouseMove += ChannelBox_MouseMove;
MouseDown += ChannelBox_MouseDown;
MouseUp += ChannelBox_MouseUp;
private bool _isSelected;
public bool IsSelected
{
get => _isSelected;
set
{
_isSelected = value;
UpdateBackground();
}
}
public ChannelBox(string channelName, string systemName, string tgid) : this()
public ChannelBox(SelectedChannelsManager selectedChannelsManager, string channelName, string systemName, string tgid)
{
ChannelName = $"{channelName}";
InitializeComponent();
DataContext = this;
_selectedChannelsManager = selectedChannelsManager;
ChannelName = channelName;
SystemName = $"System: {systemName}";
TGID = $"TGID: {tgid}";
UpdateBackground();
MouseLeftButtonDown += ChannelBox_MouseLeftButtonDown;
}
private Point _dragStartPoint;
private bool _isDragging;
private void ChannelBox_MouseDown(object sender, MouseButtonEventArgs e)
private void ChannelBox_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
_dragStartPoint = e.GetPosition(null);
_isDragging = false;
}
if (IsEditMode) return;
private void ChannelBox_MouseMove(object sender, MouseEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
Point currentPosition = e.GetPosition(null);
IsSelected = !IsSelected;
Background = IsSelected ? Brushes.Blue : Brushes.Gray;
if (!_isDragging && (Math.Abs(currentPosition.X - _dragStartPoint.X) > SystemParameters.MinimumHorizontalDragDistance ||
Math.Abs(currentPosition.Y - _dragStartPoint.Y) > SystemParameters.MinimumVerticalDragDistance))
{
_isDragging = true;
DataObject data = new DataObject("ChannelBox", this);
DragDrop.DoDragDrop(this, data, DragDropEffects.Move);
}
if (IsSelected)
{
_selectedChannelsManager.AddSelectedChannel(this);
}
else
{
_selectedChannelsManager.RemoveSelectedChannel(this);
}
}
private void ChannelBox_MouseUp(object sender, MouseButtonEventArgs e)
private void UpdateBackground()
{
_isDragging = false;
Background = IsSelected ? Brushes.DodgerBlue : Brushes.DarkGray;
}
private void PTTButton_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show($"Imagine you were talking on {ChannelName} rn");
PTTButtonClicked.Invoke(sender, this);
}
}
}

@ -44,11 +44,14 @@ namespace WhackerLinkConsoleV2
private bool _isDragging;
private SettingsManager _settingsManager = new SettingsManager();
private SelectedChannelsManager _selectedChannelsManager;
public MainWindow()
{
InitializeComponent();
_settingsManager.LoadSettings();
_selectedChannelsManager = new SelectedChannelsManager();
Loaded += MainWindow_Loaded;
}
@ -137,7 +140,7 @@ namespace WhackerLinkConsoleV2
{
foreach (var channel in zone.Channels)
{
var channelBox = new ChannelBox(channel.Name, channel.System, channel.Tgid);
var channelBox = new ChannelBox(_selectedChannelsManager, channel.Name, channel.System, channel.Tgid);
if (_settingsManager.ChannelPositions.TryGetValue(channel.Name, out var position))
{
@ -150,6 +153,8 @@ namespace WhackerLinkConsoleV2
Canvas.SetTop(channelBox, offsetY);
}
channelBox.PTTButtonClicked += ChannelBox_PTTButtonClicked;
channelBox.MouseLeftButtonDown += ChannelBox_MouseLeftButtonDown;
channelBox.MouseMove += ChannelBox_MouseMove;
channelBox.MouseRightButtonDown += ChannelBox_MouseRightButtonDown;
@ -241,6 +246,11 @@ namespace WhackerLinkConsoleV2
_draggedElement = null;
}
private void ChannelBox_PTTButtonClicked(object sender, ChannelBox channelBox)
{
MessageBox.Show($"Imagine you were talking on {channelBox.ChannelName} rn", "PTT Action", MessageBoxButton.OK);
}
private void SystemStatusBox_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) => ChannelBox_MouseLeftButtonDown(sender, e);
private void SystemStatusBox_MouseMove(object sender, MouseEventArgs e) => ChannelBox_MouseMove(sender, e);
@ -274,6 +284,11 @@ namespace WhackerLinkConsoleV2
{
alertTone.IsEditMode = isEditMode;
}
if (child is ChannelBox channelBox)
{
channelBox.IsEditMode = isEditMode;
}
}
}

@ -0,0 +1,61 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*
* Copyright (C) 2024 Caleb, K4PHP
*
*/
using WhackerLinkConsoleV2.Controls;
namespace WhackerLinkConsoleV2
{
public class SelectedChannelsManager
{
private readonly HashSet<ChannelBox> _selectedChannels;
public SelectedChannelsManager()
{
_selectedChannels = new HashSet<ChannelBox>();
}
public void AddSelectedChannel(ChannelBox channel)
{
if (_selectedChannels.Add(channel))
{
channel.IsSelected = true;
}
}
public void RemoveSelectedChannel(ChannelBox channel)
{
if (_selectedChannels.Remove(channel))
{
channel.IsSelected = false;
}
}
public void ClearSelections()
{
foreach (var channel in _selectedChannels)
{
channel.IsSelected = false;
}
_selectedChannels.Clear();
}
public IReadOnlyCollection<ChannelBox> GetSelectedChannels() => _selectedChannels;
}
}

@ -1 +1 @@
Subproject commit d452c974cdfb7bb72425042e300c9a3442b89b57
Subproject commit d36c2ccfc141336d1a541b68f2827dc626c4ff60
Loading…
Cancel
Save

Powered by TurnKey Linux.