Skip to content

Commit

Permalink
Added button to apply building settings to selected objects (#373, #294)
Browse files Browse the repository at this point in the history
  • Loading branch information
Atria1234 committed Jun 20, 2022
1 parent aae9349 commit 77a4a34
Show file tree
Hide file tree
Showing 11 changed files with 341 additions and 101 deletions.
25 changes: 25 additions & 0 deletions AnnoDesigner.Core/Converters/FlagToBoolConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace AnnoDesigner.Core.Converters
{
[ValueConversion(typeof(Enum), typeof(bool))]
public sealed class FlagToBoolConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is Enum e && parameter is Enum p)
{
return e.HasFlag(p);
}
return DependencyProperty.UnsetValue;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
114 changes: 66 additions & 48 deletions AnnoDesigner/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<coreConverters:BoolToVisibilityConverter x:Key="converterBoolToVisibilityCollapsed"
TrueValue="Visible"
FalseValue="Collapsed" />
<coreConverters:FlagToBoolConverter x:Key="flagToBoolConverter" />
<xctk:ColorToSolidColorBrushConverter x:Key="converterColorToSolidColorBrush" />
<HierarchicalDataTemplate DataType="{x:Type coreModels:AnnoObject}">
<TextBlock Text="{Binding Label}" />
Expand Down Expand Up @@ -335,52 +336,6 @@
</DockPanel>
<DockPanel LastChildFill="False"
Height="26">
<!--<Button Width="32"
DockPanel.Dock="Right"
Command="{Binding BuildingSettingsViewModel.ApplyColorToSelectionCommand}"
ToolTip="{Binding BuildingSettingsViewModel.TextApplyColorToSelectionToolTip}">
<Button.Resources>
<Style x:Key="stylePath"
TargetType="{x:Type Path}">
<Style.Triggers>
<Trigger Property="IsEnabled"
Value="True">
<Setter Property="Fill"
Value="#FF000000" />
</Trigger>
<Trigger Property="IsEnabled"
Value="False">
<Setter Property="Fill"
Value="Gray" />
</Trigger>
</Style.Triggers>
</Style>
</Button.Resources>
<Button.Content>
<Grid Width="24"
Height="24"
Visibility="Visible">
<Path Data="M10.237976,16.558633L15.362,21.68467C15.362,21.68467 15.362,32.671771 0,30.001748 3.9839783,29.020736 3.5959778,25.791718 5.9639893,20.122661 7.1269836,17.340638 10.237976,16.558633 10.237976,16.558633z M30.389984,0.00048406667C30.752991,0.0094867014 31.134979,0.14547426 31.494995,0.50648519 32.77597,1.7864956 31.215973,3.3455154 31.215973,3.3455152 31.215973,3.3455154 23.415985,11.147588 21.855988,12.708591 20.296997,14.270602 18.406982,18.619656 18.406982,18.619656L13.28299,13.495602C13.28299,13.495602 17.733978,11.707591 19.29599,10.147579 20.855988,8.5855531 28.655975,0.78248873 28.655975,0.78248861 28.655975,0.78248873 29.461975,-0.022526528 30.389984,0.00048406667z"
Stretch="Uniform"
Width="16"
Height="16"
Margin="0,0,0,0"
RenderTransformOrigin="0.5,0.5"
Style="{StaticResource stylePath}">
<Path.RenderTransform>
<TransformGroup>
<TransformGroup.Children>
<RotateTransform Angle="0" />
<ScaleTransform ScaleX="1"
ScaleY="1" />
</TransformGroup.Children>
</TransformGroup>
</Path.RenderTransform>
</Path>
</Grid>
</Button.Content>
</Button>-->
<!-- used when predefined colors are available -->
<xctk:SplitButton Width="48"
DockPanel.Dock="Right"
Command="{Binding BuildingSettingsViewModel.ApplyColorToSelectionCommand}"
Expand Down Expand Up @@ -507,8 +462,8 @@
Width="140"
Height="46"
IsEnabled="True"
ItemsSource="{Binding AvailableIcons}"
SelectedItem="{Binding SelectedIcon}"
ItemsSource="{Binding BuildingSettingsViewModel.AvailableIcons}"
SelectedItem="{Binding BuildingSettingsViewModel.SelectedIcon}"
TabIndex="6"
TextSearch.TextPath="DisplayName"
ScrollViewer.CanContentScroll="True">
Expand Down Expand Up @@ -640,6 +595,69 @@
Command="{Binding PlaceBuildingCommand}"
Height="23"
TabIndex="12" />

<xctk:SplitButton Height="23"
Content="ApplyBuildingSettings"
Command="{Binding BuildingSettingsViewModel.ApplySettingsToSelectionCommand}"
ToolTip="{l:Localize ApplyColorToSelectionToolTip}"
TabIndex="13">
<xctk:SplitButton.Resources>
<Style x:Key="stylePath"
TargetType="{x:Type Path}">
<Style.Triggers>
<Trigger Property="IsEnabled"
Value="True">
<Setter Property="Fill"
Value="#FF000000" />
</Trigger>
<Trigger Property="IsEnabled"
Value="False">
<Setter Property="Fill"
Value="Gray" />
</Trigger>
</Style.Triggers>
</Style>
</xctk:SplitButton.Resources>
<xctk:SplitButton.DropDownContent>
<StackPanel Orientation="Vertical">
<StackPanel.Resources>
<Style TargetType="CheckBox">
<Setter Property="Margin" Value="10,5"/>
</Style>
</StackPanel.Resources>
<CheckBox Content="Apply color"
IsChecked="{Binding BuildingSettingsViewModel.ApplySettings, Converter={StaticResource flagToBoolConverter}, ConverterParameter={x:Static viewModel:ApplySettings.Color}, Mode=OneWay}"
Tag="{x:Static viewModel:ApplySettings.Color}"
Checked="BuildingSettings_ApplySettings_Checked"
Unchecked="BuildingSettings_ApplySettings_Unchecked" />
<CheckBox Content="Apply label"
IsChecked="{Binding BuildingSettingsViewModel.ApplySettings, Converter={StaticResource flagToBoolConverter}, ConverterParameter={x:Static viewModel:ApplySettings.Label}, Mode=OneWay}"
Tag="{x:Static viewModel:ApplySettings.Label}"
Checked="BuildingSettings_ApplySettings_Checked"
Unchecked="BuildingSettings_ApplySettings_Unchecked" />
<CheckBox Content="Apply icon"
IsChecked="{Binding BuildingSettingsViewModel.ApplySettings, Converter={StaticResource flagToBoolConverter}, ConverterParameter={x:Static viewModel:ApplySettings.Icon}, Mode=OneWay}"
Tag="{x:Static viewModel:ApplySettings.Icon}"
Checked="BuildingSettings_ApplySettings_Checked"
Unchecked="BuildingSettings_ApplySettings_Unchecked" />
<CheckBox Content="Apply influence"
IsChecked="{Binding BuildingSettingsViewModel.ApplySettings, Converter={StaticResource flagToBoolConverter}, ConverterParameter={x:Static viewModel:ApplySettings.Influence}, Mode=OneWay}"
Tag="{x:Static viewModel:ApplySettings.Influence}"
Checked="BuildingSettings_ApplySettings_Checked"
Unchecked="BuildingSettings_ApplySettings_Unchecked" />
<CheckBox Content="Apply borderless"
IsChecked="{Binding BuildingSettingsViewModel.ApplySettings, Converter={StaticResource flagToBoolConverter}, ConverterParameter={x:Static viewModel:ApplySettings.Borderless}, Mode=OneWay}"
Tag="{x:Static viewModel:ApplySettings.Borderless}"
Checked="BuildingSettings_ApplySettings_Checked"
Unchecked="BuildingSettings_ApplySettings_Unchecked" />
<CheckBox Content="Apply road"
IsChecked="{Binding BuildingSettingsViewModel.ApplySettings, Converter={StaticResource flagToBoolConverter}, ConverterParameter={x:Static viewModel:ApplySettings.Road}, Mode=OneWay}"
Tag="{x:Static viewModel:ApplySettings.Road}"
Checked="BuildingSettings_ApplySettings_Checked"
Unchecked="BuildingSettings_ApplySettings_Unchecked" />
</StackPanel>
</xctk:SplitButton.DropDownContent>
</xctk:SplitButton>
</StackPanel>
</GroupBox>

Expand Down
11 changes: 11 additions & 0 deletions AnnoDesigner/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.ComponentModel;
using System.Configuration;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Threading;
Expand Down Expand Up @@ -147,6 +148,16 @@ private void WindowClosing(object sender, CancelEventArgs e)
#endif
}

private void BuildingSettings_ApplySettings_Checked(object sender, RoutedEventArgs e)
{
DataContext.BuildingSettingsViewModel.ApplySettings |= (ApplySettings)(sender as CheckBox).Tag;
}

private void BuildingSettings_ApplySettings_Unchecked(object sender, RoutedEventArgs e)
{
DataContext.BuildingSettingsViewModel.ApplySettings &= ~(ApplySettings)(sender as CheckBox).Tag;
}

private void WindowClosed(object sender, EventArgs e)
{
base.OnClosed(e);
Expand Down
6 changes: 6 additions & 0 deletions AnnoDesigner/Models/LayoutObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -591,5 +591,11 @@ public Rect GridInfluenceRangeRect
return _gridInfluenceRangeRect;
}
}

public string Label { get => WrappedAnnoObject.Label; set => WrappedAnnoObject.Label = value; }
public double InfluenceRange { get => WrappedAnnoObject.InfluenceRange; set => WrappedAnnoObject.InfluenceRange = value; }
public double Radius { get => WrappedAnnoObject.Radius; set => WrappedAnnoObject.Radius = value; }
public bool Borderless { get => WrappedAnnoObject.Borderless; set => WrappedAnnoObject.Borderless = value; }
public bool Road { get => WrappedAnnoObject.Road; set => WrappedAnnoObject.Road = value; }
}
}
58 changes: 55 additions & 3 deletions AnnoDesigner/Undo/Operations/CompositeOperation.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,63 @@
using System.Collections.Generic;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace AnnoDesigner.Undo.Operations
{
public class CompositeOperation : BaseOperation
public class CompositeOperation : BaseOperation, ICollection<IOperation>
{
public ICollection<IOperation> Operations { get; set; } = new List<IOperation>();
private ICollection<IOperation> operations = new List<IOperation>();

public IEnumerable<IOperation> Operations => operations;

public int Count => operations.Count;

public bool IsReadOnly => operations.IsReadOnly;

public CompositeOperation()
{
operations = new List<IOperation>();
}

public CompositeOperation(IEnumerable<IOperation> ops)
{
operations = new List<IOperation>(ops);
}

public void Add(IOperation item)
{
operations.Add(item);
}

public void Clear()
{
operations.Clear();
}

public bool Contains(IOperation item)
{
return operations.Contains(item);
}

public void CopyTo(IOperation[] array, int arrayIndex)
{
operations.CopyTo(array, arrayIndex);
}

public IEnumerator<IOperation> GetEnumerator()
{
return operations.GetEnumerator();
}

public bool Remove(IOperation item)
{
return operations.Remove(item);
}

IEnumerator IEnumerable.GetEnumerator()
{
return ((IEnumerable)operations).GetEnumerator();
}

protected override void RedoOperation()
{
Expand Down
4 changes: 2 additions & 2 deletions AnnoDesigner/Undo/UndoManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void RegisterOperation(IOperation operation)
{
if (CurrentCompositeOperation != null)
{
CurrentCompositeOperation.Operations.Add(operation);
CurrentCompositeOperation.Add(operation);
}
else
{
Expand All @@ -78,7 +78,7 @@ public void AsSingleUndoableOperation(Action action)
finally
{
CurrentCompositeOperation = null;
if (operation != null && operation.Operations.Count > 0)
if (operation != null && operation.Count > 0)
{
RegisterOperation(operation);
}
Expand Down
Loading

0 comments on commit 77a4a34

Please sign in to comment.