From 4e48c569f1cae820ffade8a786354b2ba79b50b4 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Tue, 6 Mar 2018 18:28:51 +0200 Subject: Some improvements on hive. --- .../Tango.SharedUI/Controls/HiveControl.xaml.cs | 35 +++++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) (limited to 'Software/Visual_Studio/Tango.SharedUI/Controls') diff --git a/Software/Visual_Studio/Tango.SharedUI/Controls/HiveControl.xaml.cs b/Software/Visual_Studio/Tango.SharedUI/Controls/HiveControl.xaml.cs index 81fc1250d..5fba6eaa0 100644 --- a/Software/Visual_Studio/Tango.SharedUI/Controls/HiveControl.xaml.cs +++ b/Software/Visual_Studio/Tango.SharedUI/Controls/HiveControl.xaml.cs @@ -25,6 +25,8 @@ namespace Tango.SharedUI.Controls { public event EventHandler HexagonSelected; + public event EventHandler HiveGenerated; + public ObservableCollection Hexagons { get { return (ObservableCollection)GetValue(HexagonsProperty); } @@ -65,6 +67,21 @@ namespace Tango.SharedUI.Controls public static readonly DependencyProperty CenterHexagonProperty = DependencyProperty.Register("CenterHexagon", typeof(HexagonControl), typeof(HiveControl), new PropertyMetadata(null)); + public int HiveWidth + { + get { return (int)GetValue(HiveWidthProperty); } + set { SetValue(HiveWidthProperty, value); } + } + public static readonly DependencyProperty HiveWidthProperty = + DependencyProperty.Register("HiveWidth", typeof(int), typeof(HiveControl), new PropertyMetadata(5)); + + public int HiveHeight + { + get { return (int)GetValue(HiveHeightProperty); } + set { SetValue(HiveHeightProperty, value); } + } + public static readonly DependencyProperty HiveHeightProperty = + DependencyProperty.Register("HiveHeight", typeof(int), typeof(HiveControl), new PropertyMetadata(5)); public HiveControl() { @@ -78,13 +95,10 @@ namespace Tango.SharedUI.Controls this.Loaded += HiveControl_Loaded; } - public int HiveHeight { get; set; } - - public int HiveWidth { get; set; } - private void HiveControl_Loaded(object sender, RoutedEventArgs e) { GenerateHive(); + HiveGenerated?.Invoke(this,new EventArgs()); } private void GenerateHive() @@ -155,7 +169,20 @@ namespace Tango.SharedUI.Controls private void Hexagon_MouseUp(object sender, MouseButtonEventArgs e) { HexagonControl hexagon = sender as HexagonControl; + ToggleHexagonSelection(hexagon); + } + public void SelectHexagon(HexagonControl hexagon) + { + SelectedHexagons.Clear(); + SelectedHexagons.Add(hexagon); + Hexagons.ToList().ForEach(x => x.IsSelected = false); + hexagon.IsSelected = true; + HexagonSelected?.Invoke(this, hexagon); + } + + private void ToggleHexagonSelection(HexagonControl hexagon) + { bool selected = !hexagon.IsSelected; if (MaxSelections > Hexagons.Where(x => x.IsSelected).Count()) -- cgit v1.3.1