Skip to content

Commit

Permalink
entity support
Browse files Browse the repository at this point in the history
  • Loading branch information
EFLFE committed Aug 12, 2022
1 parent ba85584 commit 2f85948
Show file tree
Hide file tree
Showing 13 changed files with 330 additions and 134 deletions.
2 changes: 1 addition & 1 deletion Artorio/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ namespace Artorio
/// </summary>
public partial class App : Application
{
public const string VERSION = "1.2.1";
public const string VERSION = "1.3.0";
}
}
14 changes: 14 additions & 0 deletions Artorio/Artorio.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@
<ApplicationIcon>Resources\Icon.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="ColorPicker, Version=3.3.1.0, Culture=neutral, PublicKeyToken=1c61eec504ce2276, processorArchitecture=MSIL">
<HintPath>..\packages\PixiEditor.ColorPicker.3.3.1\lib\net451\ColorPicker.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Xaml.Behaviors, Version=1.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Xaml.Behaviors.Wpf.1.1.31\lib\net45\Microsoft.Xaml.Behaviors.dll</HintPath>
</Reference>
<Reference Include="Pngcs">
<HintPath>..\dlls\Pngcs.dll</HintPath>
</Reference>
Expand Down Expand Up @@ -74,6 +80,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="ColorsPickerWIndow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="GetJSONBP.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand All @@ -92,6 +102,9 @@
<Compile Include="ColorItemCast.xaml.cs">
<DependentUpon>ColorItemCast.xaml</DependentUpon>
</Compile>
<Compile Include="ColorsPickerWIndow.xaml.cs">
<DependentUpon>ColorsPickerWIndow.xaml</DependentUpon>
</Compile>
<Compile Include="EFPNG\Color.cs" />
<Compile Include="EFPNG\PngData.cs" />
<Compile Include="Extra.cs" />
Expand Down Expand Up @@ -124,6 +137,7 @@
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
Expand Down
35 changes: 14 additions & 21 deletions Artorio/ColorItemCast.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@
mc:Ignorable="d" Width="621" Height="40">
<Grid Background="#FFCEE6E6">
<Button x:Name="removeThis" Click="removeThisClick" Width="13" Height="20" Content="X" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top"/>
<Button Click="MoveUpClick" ToolTip="Move up" Width="13" Height="20" Content="" HorizontalAlignment="Left" Margin="560,10,0,0" VerticalAlignment="Top"/>
<Button Click="MoveDownClick" ToolTip="Move down" Width="13" Height="20" Content="" HorizontalAlignment="Left" Margin="578,10,0,0" VerticalAlignment="Top"/>
<Button Click="MoveUpClick" ToolTip="Move up" Width="13" Height="20" Content="" HorizontalAlignment="Left" Margin="585,0,0,0" VerticalAlignment="Center"/>
<Button Click="MoveDownClick" ToolTip="Move down" Width="13" Height="20" Content="" HorizontalAlignment="Left" Margin="603,0,0,0" VerticalAlignment="Center"/>

<Button x:Name="colorFrom" Click="ColorFromClick" HorizontalAlignment="Left" Height="24" Margin="149,8,0,0" VerticalAlignment="Top" Width="24" Background="White">
<Button x:Name="colorFrom" Click="ColorFromClick" HorizontalAlignment="Left" Height="24" Margin="62,0,0,0" VerticalAlignment="Center" Width="24" Background="White">
<Button.BorderBrush>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="Black" Offset="0"/>
<GradientStop Color="White" Offset="1"/>
</LinearGradientBrush>
</Button.BorderBrush>
</Button>
<Button x:Name="colorTo" Click="ColorToClick" HorizontalAlignment="Left" Height="24" Margin="198,8,0,0" VerticalAlignment="Top" Width="24" Background="White">

<Button x:Name="colorTo" Click="ColorToClick" HorizontalAlignment="Left" Height="24" Margin="182,0,0,0" VerticalAlignment="Center" Width="24" Background="White">
<Button.BorderBrush>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="Black" Offset="0"/>
Expand All @@ -27,23 +28,15 @@
</Button.BorderBrush>
</Button>

<TextBlock HorizontalAlignment="Left" Margin="28,11,0,0" TextWrapping="Wrap" Text="Color (" VerticalAlignment="Top"/>
<TextBlock HorizontalAlignment="Left" Margin="178,11,0,0" TextWrapping="Wrap" Text="to)" VerticalAlignment="Top"/>
<TextBlock HorizontalAlignment="Left" Margin="227,11,0,0" TextWrapping="Wrap" Text="place item" VerticalAlignment="Top"/>
<ComboBox x:Name="itemName" IsEditable="false" HorizontalAlignment="Left" Margin="286,10,0,0" VerticalAlignment="Top" Width="245">
<ComboBoxItem Content="stone-path"/>
<ComboBoxItem Content="concrete"/>
<ComboBoxItem Content="hazard-concrete-left"/>
<ComboBoxItem Content="refined-concrete"/>
<ComboBoxItem Content="refined-hazard-concrete-left"/>
<ComboBoxItem Content="transport-belt"/>
<ComboBoxItem Content="wooden-chest"/>
<ComboBoxItem Content="stone-wall"/>
<ComboBoxItem Content="gate"/>
<TextBlock HorizontalAlignment="Left" Margin="28,0,0,0" TextWrapping="Wrap" Text="Color:" VerticalAlignment="Center"/>
<TextBlock HorizontalAlignment="Left" Margin="217,0,0,0" TextWrapping="Wrap" Text="place item" VerticalAlignment="Center"/>
<ComboBox x:Name="itemName" IsEditable="false" HorizontalAlignment="Left" Margin="275,0,0,0" VerticalAlignment="Center" Width="245">
<!--<ComboBoxItem Content="stone-path"/>-->
</ComboBox>
<CheckBox x:Name="useRangeColor" HorizontalAlignment="Left" Margin="67,14,0,0" VerticalAlignment="Top"/>
<TextBlock HorizontalAlignment="Left" Margin="85,12,0,0" TextWrapping="Wrap" Text="range from" VerticalAlignment="Top"/>
<Rectangle Panel.ZIndex="-1" Fill="#FFA0A6B9" HorizontalAlignment="Left" Margin="59,0,0,0" Width="136"/>
<Rectangle x:Name="itemColorRect" HorizontalAlignment="Left" Margin="536,10,0,10" Width="19" Fill="{x:Null}"/>
<CheckBox x:Name="useRangeColor" HorizontalAlignment="Left" Margin="114,14,0,0" VerticalAlignment="Top"/>
<TextBlock HorizontalAlignment="Left" Margin="132,0,0,0" TextWrapping="Wrap" Text="range to" VerticalAlignment="Center"/>
<Rectangle Panel.ZIndex="-1" Fill="#FFA0A6B9" HorizontalAlignment="Left" Margin="106,0,0,0" Width="106"/>
<Rectangle x:Name="itemColorRect" HorizontalAlignment="Left" Margin="525,10,0,10" Width="19" Fill="{x:Null}"/>
<TextBlock x:Name="filterTag" HorizontalAlignment="Left" Margin="549,0,0,0" Text="" VerticalAlignment="Center" Height="20" Width="31"/>
</Grid>
</UserControl>
67 changes: 46 additions & 21 deletions Artorio/ColorItemCast.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;

namespace Artorio
{
Expand All @@ -12,7 +11,6 @@ namespace Artorio
public partial class ColorItemCast : UserControl
{
private static int idIncrement;
private static System.Windows.Forms.ColorDialog colorDialog;

private FilterConfig filterConfig;
private bool isUnloaded;
Expand All @@ -27,7 +25,8 @@ public IReadOnlyFilterConfig GetFilterConfig
{
get
{
filterConfig.ItemName = itemName.Text;
ItemColors.FindItem(itemName.Text, out var itemData);
SetFilterItem(itemData);
return filterConfig;
}
}
Expand All @@ -42,20 +41,25 @@ public ColorItemCast(FilterConfig _filterConfig)
useRangeColor.Checked += UseRangeColor_Checked;
useRangeColor.Unchecked += UseRangeColor_Unchecked;

// load combobox items
foreach (var data in ItemColors.ForEachItemData())
{
itemName.Items.Add(new ComboBoxItem { Content = data.InternalName });
}

//if (App.ExtremeMode)
itemName.IsEditable = true;

//App.OnExtremeModeChanged += App_OnExtremeModeChanged;

if (_filterConfig != null)
if (_filterConfig != null && _filterConfig.Item != null)
{
if (_filterConfig.UseRangeColor)
useRangeColor.IsChecked = true;

for (int i = 0; i < itemName.Items.Count; i++)
{
// I love WPF
if (((string)((ComboBoxItem)itemName.Items[i]).Content).Equals(_filterConfig.ItemName))
if (((string)((ComboBoxItem)itemName.Items[i]).Content).Equals(_filterConfig.Item.InternalName))
{
itemName.SelectedIndex = i;
break;
Expand All @@ -64,7 +68,7 @@ public ColorItemCast(FilterConfig _filterConfig)

if (itemName.SelectedIndex == -1 /*&& App.ExtremeMode*/)
{
itemName.Text = _filterConfig.ItemName;
itemName.Text = _filterConfig.Item.InternalName;
}

filterConfig.FromColor = _filterConfig.FromColor;
Expand Down Expand Up @@ -130,7 +134,9 @@ private void ItemName_SelectionChanged(object sender, SelectionChangedEventArgs
{
var comboBoxItem = (ComboBoxItem)itemName.SelectedItem;
string placeItem = (string)comboBoxItem.Content;
filterConfig.ItemName = placeItem;

ItemColors.FindItem(placeItem, out var itemData);
SetFilterItem(itemData);
FindItemColor(placeItem);
}
else
Expand All @@ -139,28 +145,47 @@ private void ItemName_SelectionChanged(object sender, SelectionChangedEventArgs
}
}

private bool SelectColor(Button owner, out Color? selectedColor)
private void SetFilterItem(ItemData itemData)
{
selectedColor = null;
filterConfig.Item = itemData;

if (colorDialog == null)
switch (itemData.ItemType)
{
colorDialog = new System.Windows.Forms.ColorDialog
{
AllowFullOpen = true,
FullOpen = true
};
case ItemTypeEnum.Floor:
filterTag.Text = "f";
break;

case ItemTypeEnum.Entity:
filterTag.Text = "E";
break;

case ItemTypeEnum.Entity_2x2:
filterTag.Text = "E 2x2";
break;

case ItemTypeEnum.Entity_3x3:
filterTag.Text = "E 3x3";
break;

default:
filterTag.Text = "?";
break;
}
}

colorDialog.Color = Extra.ToWinFormColor(((SolidColorBrush)owner.Background).Color);
private bool SelectColor(Button owner, out Color? selectedColor)
{
ColorsPickerWIndow.OpenWindow(((SolidColorBrush)owner.Background).Color);

if (colorDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
if (ColorsPickerWIndow.Instance.ColorWasSelected)
{
var color = Extra.ToWPFColor(colorDialog.Color);
owner.Background = new SolidColorBrush(color);
selectedColor = color;
var clr = ColorsPickerWIndow.Instance.GetSelectedColor;
selectedColor = clr;
owner.Background = new SolidColorBrush(clr);
return true;
}

selectedColor = null;
return false;
}

Expand Down
17 changes: 17 additions & 0 deletions Artorio/ColorsPickerWIndow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Window x:Class="Artorio.ColorsPickerWIndow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Artorio"
xmlns:colorpicker="clr-namespace:ColorPicker;assembly=ColorPicker"
mc:Ignorable="d"
WindowStyle="ToolWindow"
ResizeMode="NoResize"
Title="Color picker" Height="458" Width="213">
<Grid>
<colorpicker:StandardColorPicker x:Name="main" PickerType="HSV" Height="385" VerticalAlignment="Top"/>
<Button Click="OnApplyClick" Content="Apply" HorizontalAlignment="Left" Margin="10,0,0,10" Height="20" VerticalAlignment="Bottom"/>
<Button Click="OnCancelClick" Content="Cancel" HorizontalAlignment="Right" Margin="0,0,10,10" Height="20" VerticalAlignment="Bottom"/>
</Grid>
</Window>
66 changes: 66 additions & 0 deletions Artorio/ColorsPickerWIndow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using System.Windows;
using System.Windows.Media;

namespace Artorio
{
/// <summary>
/// Interaction logic for ColorsPickerWIndow.xaml
/// </summary>
public partial class ColorsPickerWIndow : Window
{
public static ColorsPickerWIndow Instance { get; private set; }

public static void OpenWindow(Color? selectColor = null)
{
if (Instance == null)
Instance = new ColorsPickerWIndow();

if (selectColor.HasValue)
Instance.SelectColor(selectColor.Value);

Instance.ShowDialog();
}

private bool stayOpen;
public Color GetSelectedColor => main.SelectedColor;
public bool ColorWasSelected { get; private set; }

public ColorsPickerWIndow()
{
InitializeComponent();
stayOpen = true;
Closing += ColorsPickerWIndow_Closing;
}

public void CloseWindow()
{
stayOpen = false;
Close();
}

public void SelectColor(Color clr)
{
main.SelectedColor = clr;
}

private void ColorsPickerWIndow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
if (stayOpen)
{
e.Cancel = false;
}
}

private void OnApplyClick(object sender, RoutedEventArgs e)
{
ColorWasSelected = true;
Hide();
}

private void OnCancelClick(object sender, RoutedEventArgs e)
{
ColorWasSelected = false;
Hide();
}
}
}
Loading

0 comments on commit 2f85948

Please sign in to comment.