Skip to content

Commit

Permalink
- Added custom tables
Browse files Browse the repository at this point in the history
- UI improvements + fixes
  • Loading branch information
Cjreek committed Aug 2, 2023
1 parent b2cab54 commit 8fa018a
Show file tree
Hide file tree
Showing 37 changed files with 1,232 additions and 37 deletions.
3 changes: 3 additions & 0 deletions eos-edit/App.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@
<DataTemplate DataType="{x:Type dialogVM:CustomObjectInstanceSearchViewModel}">
<dialogViews:ModelSearchView/>
</DataTemplate>
<DataTemplate DataType="{x:Type dialogVM:CustomTableInstanceSearchViewModel}">
<dialogViews:ModelSearchView/>
</DataTemplate>
<DataTemplate DataType="{x:Type dialogVM:CustomDynamicTableInstanceSearchViewModel}">
<dialogViews:ModelSearchView/>
</DataTemplate>
Expand Down
26 changes: 20 additions & 6 deletions eos-edit/Assets/CustomDataTemplateResources.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -118,18 +118,30 @@
<uc:CustomObjectComboBox CustomObjectTemplate="{Binding Property.DataType.CustomType}" SelectedValue="{Binding Value}" IsNullable="True"/>
</DataTemplate>

<DataTemplate x:Key="customEnumTemplate">
<uc:CustomEnumComboBox CustomEnum="{Binding Property.DataType.CustomType}" SelectedValue="{Binding Value}" IsNullable="True"/>
<DataTemplate x:Key="customTableTemplate">
<uc:CustomTableComboBox CustomTableTemplate="{Binding Property.DataType.CustomType}" SelectedValue="{Binding Value}" IsNullable="True"/>
</DataTemplate>

<DataTemplate x:Key="customDynamicTableTemplate">
<uc:CustomDynamicTableComboBox CustomDynamicTableTemplate="{Binding Property.DataType.CustomType}" SelectedValue="{Binding Value}" IsNullable="True"/>
</DataTemplate>

<DataTemplate x:Key="customEnumTemplate">
<uc:CustomEnumComboBox CustomEnum="{Binding Property.DataType.CustomType}" SelectedValue="{Binding Value}" IsNullable="True"/>
</DataTemplate>

<DataTemplate x:Key="customObjectVariantTemplate">
<uc:CustomObjectComboBox CustomObjectTemplate="{Binding DataType.CustomType}" SelectedValue="{Binding Value}" IsNullable="True"/>
</DataTemplate>

<DataTemplate x:Key="customTableVariantTemplate">
<uc:CustomTableComboBox CustomTableTemplate="{Binding DataType.CustomType}" SelectedValue="{Binding Value}" IsNullable="True"/>
</DataTemplate>

<DataTemplate x:Key="customDynamicTableVariantTemplate">
<uc:CustomDynamicTableComboBox CustomDynamicTableTemplate="{Binding DataType.CustomType}" SelectedValue="{Binding Value}" IsNullable="True"/>
</DataTemplate>

<DataTemplate x:Key="customEnumVariantTemplate">
<uc:CustomEnumComboBox CustomEnum="{Binding DataType.CustomType}" SelectedValue="{Binding Value}" IsNullable="True"/>
</DataTemplate>
Expand Down Expand Up @@ -170,8 +182,9 @@
CompanionTemplate="{StaticResource companionTemplate}"
FamiliarTemplate="{StaticResource familiarTemplate}"
CustomObjectTemplate="{StaticResource customObjectVariantTemplate}"
CustomEnumTemplate="{StaticResource customEnumVariantTemplate}"
CustomDynamicTableTemplate="{StaticResource customDynamicTableTemplate}"/>
CustomTableTemplate="{StaticResource customTableVariantTemplate}"
CustomDynamicTableTemplate="{StaticResource customDynamicTableVariantTemplate}"
CustomEnumTemplate="{StaticResource customEnumVariantTemplate}"/>

<DataTemplate x:Key="variantTemplate">
<Grid DataContextChanged="">
Expand Down Expand Up @@ -242,6 +255,7 @@
CompanionTemplate="{StaticResource companionTemplate}"
FamiliarTemplate="{StaticResource familiarTemplate}"
CustomObjectTemplate="{StaticResource customObjectTemplate}"
CustomEnumTemplate="{StaticResource customEnumTemplate}"
CustomDynamicTableTemplate="{StaticResource customDynamicTableTemplate}"/>
CustomTableTemplate="{StaticResource customTableTemplate}"
CustomDynamicTableTemplate="{StaticResource customDynamicTableTemplate}"
CustomEnumTemplate="{StaticResource customEnumTemplate}"/>
</ResourceDictionary>
4 changes: 4 additions & 0 deletions eos-edit/Assets/StyleResources.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,10 @@
<Setter Property="Margin" Value="2,0,0,3"/>
</Style>

<Style Selector="uc|CustomTableComboBox">
<Setter Property="Margin" Value="2,0,0,3"/>
</Style>

<Style Selector="uc|CustomDynamicTableComboBox">
<Setter Property="Margin" Value="2,0,0,3"/>
</Style>
Expand Down
9 changes: 6 additions & 3 deletions eos-edit/Extensions/InstancePropertyValueTemplateSelector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ public class InstancePropertyValueTemplateSelector : IDataTemplate
public DataTemplate? DamageTypeTemplate { get; set; }
public DataTemplate? DamageTypeGroupTemplate { get; set; }
public DataTemplate? CustomObjectTemplate { get; set; }
public DataTemplate? CustomEnumTemplate { get; set; }
public DataTemplate? CustomTableTemplate { get; set; }
public DataTemplate? CustomDynamicTableTemplate { get; set; }
public DataTemplate? CustomEnumTemplate { get; set; }


public Control? Build(object? param)
Expand Down Expand Up @@ -149,10 +150,12 @@ public bool Match(object? data)

if (dataTypeDef.CustomType is CustomObject customObject)
return CustomObjectTemplate ?? ErrorTemplate;
if (dataTypeDef.CustomType is CustomEnum customEnum)
return CustomEnumTemplate ?? ErrorTemplate;
if (dataTypeDef.CustomType is CustomTable customTable)
return CustomTableTemplate ?? ErrorTemplate;
if (dataTypeDef.CustomType is CustomDynamicTable customDynTable)
return CustomDynamicTableTemplate ?? ErrorTemplate;
if (dataTypeDef.CustomType is CustomEnum customEnum)
return CustomEnumTemplate ?? ErrorTemplate;

return ErrorTemplate;
}
Expand Down
36 changes: 36 additions & 0 deletions eos-edit/Usercontrols/CustomTableComboBox.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<UserControl xmlns="https://github.com/avaloniaui"
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="using:Eos.Usercontrols"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Eos.Usercontrols.CustomTableComboBox"
x:Name="ucCustomTableComboBox">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceInclude Source="/Assets/ConverterResources.axaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>

<Grid DataContext="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:CustomTableComboBox}}}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>

<Button x:Name="cbCustomTables" Grid.Column="0" Click="btSearch_Click" HorizontalContentAlignment="Stretch" MinHeight="22">
<Button.Content>
<TextBlock Text="{Binding ElementName=ucCustomTableComboBox, Path=SelectedValue.Label}" Margin="3,0,0,0"/>
</Button.Content>
</Button>

<Button x:Name="btClear" Grid.Column="1" Content="🞪" Click="btClear_Click" Margin="2,0,0,0"
Height="{Binding ElementName=cbCustomTables, Path=Bounds.Height}" Width="{Binding ElementName=cbCustomTables, Path=Bounds.Height}"
IsVisible="{Binding ElementName=ucCustomTableComboBox, Path=IsNullable}"/>
<Button x:Name="btGoto" Grid.Column="2" Margin="2,0,0,0" Content="👁" Click="btGoto_Click"
Height="{Binding ElementName=cbCustomTables, Path=Bounds.Height}" Width="{Binding ElementName=cbCustomTables, Path=Bounds.Height}"/>
</Grid>
</UserControl>
64 changes: 64 additions & 0 deletions eos-edit/Usercontrols/CustomTableComboBox.axaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Data;
using Avalonia.Interactivity;
using Eos.Models;
using Eos.Models.Tables;
using Eos.Repositories;
using Eos.Services;
using Eos.ViewModels.Base;
using Eos.ViewModels.Dialogs;

namespace Eos.Usercontrols
{
public partial class CustomTableComboBox : UserControl
{
public CustomTableComboBox()
{
InitializeComponent();
}

public static readonly StyledProperty<CustomTable?> CustomTableTemplateProperty = AvaloniaProperty.Register<CustomTableComboBox, CustomTable?>("CustomTableTemplate", null);
public static readonly StyledProperty<CustomTableInstance?> SelectedValueProperty = AvaloniaProperty.Register<CustomTableComboBox, CustomTableInstance?>("SelectedValue", null, false, BindingMode.TwoWay);
public static readonly StyledProperty<bool> IsNullableProperty = AvaloniaProperty.Register<CustomTableComboBox, bool>("IsNullable", true);

public CustomTable? CustomTableTemplate
{
get { return GetValue(CustomTableTemplateProperty); }
set { SetValue(CustomTableTemplateProperty, value); }
}

public CustomTableInstance? SelectedValue
{
get { return GetValue(SelectedValueProperty); }
set { SetValue(SelectedValueProperty, value); }
}

public bool IsNullable
{
get { return GetValue(IsNullableProperty); }
set { SetValue(IsNullableProperty, value); }
}

private void btClear_Click(object sender, RoutedEventArgs e)
{
SetValue(SelectedValueProperty, null);
}

private void btSearch_Click(object sender, RoutedEventArgs e)
{
if (CustomTableTemplate != null)
{
var viewModel = new CustomTableInstanceSearchViewModel(CustomTableTemplate, MasterRepository.Project.CustomTableRepositories[CustomTableTemplate]);
WindowService.OpenDialog(viewModel);
if (viewModel.ResultModel != null)
SetValue(SelectedValueProperty, viewModel.ResultModel);
}
}

private void btGoto_Click(object sender, RoutedEventArgs e)
{
MessageDispatcher.Send(MessageType.OpenDetail, SelectedValue, true);
}
}
}
5 changes: 5 additions & 0 deletions eos-edit/ViewModels/Base/ViewModelBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ protected ViewModelQueryResult DoQuery(String title, String message, ViewModelQu
MessageDispatcher.Send(MessageType.NewCustomDetail, template);
});

public ReactiveCommand<CustomTable, Unit> NewCustomTableCommand { get; private set; } = ReactiveCommand.Create<CustomTable>(template =>
{
MessageDispatcher.Send(MessageType.NewCustomDetail, template);
});

public ReactiveCommand<CustomDynamicTable, Unit> NewCustomDynamicTableCommand { get; private set; } = ReactiveCommand.Create<CustomDynamicTable>(template =>
{
MessageDispatcher.Send(MessageType.NewCustomDetail, template);
Expand Down
4 changes: 4 additions & 0 deletions eos-edit/ViewModels/Base/ViewModelFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,14 @@ public static DataDetailViewModelBase CreateViewModel(object model)
return new CustomEnumViewModel(customEnum);
if (model is CustomObject customObject)
return new CustomObjectViewModel(customObject);
if (model is CustomTable customTable)
return new CustomTableViewModel(customTable);
if (model is CustomDynamicTable customDynamicTable)
return new CustomDynamicTableViewModel(customDynamicTable);
if (model is CustomObjectInstance customObjectInstance)
return new CustomObjectInstanceViewModel(customObjectInstance);
if (model is CustomTableInstance customTableInstance)
return new CustomTableInstanceViewModel(customTableInstance);
if (model is CustomDynamicTableInstance customDynamicTableInstance)
return new CustomDynamicTableInstanceViewModel(customDynamicTableInstance);

Expand Down
6 changes: 3 additions & 3 deletions eos-edit/ViewModels/CustomDynamicTableInstanceViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class CustomDynamicTableInstanceViewModel : DataDetailViewModel<CustomDyn
public CustomDynamicTableInstanceViewModel() : base()
{
DeleteCustomDynTableItemCommand = ReactiveCommand.Create<CustomDynamicTableInstanceItem>(DeleteCustomDynTableItem);
AddCustomDynTableItemCommand = ReactiveCommand.Create(AddItemPropertyTableItem);
AddCustomDynTableItemCommand = ReactiveCommand.Create(AddCustomDynTableItem);

MoveUpCommand = ReactiveCommand.Create<CustomDynamicTableInstanceItem>(MoveUp);
MoveDownCommand = ReactiveCommand.Create<CustomDynamicTableInstanceItem>(MoveDown);
Expand All @@ -26,7 +26,7 @@ public CustomDynamicTableInstanceViewModel() : base()
public CustomDynamicTableInstanceViewModel(CustomDynamicTableInstance instance) : base(instance)
{
DeleteCustomDynTableItemCommand = ReactiveCommand.Create<CustomDynamicTableInstanceItem>(DeleteCustomDynTableItem);
AddCustomDynTableItemCommand = ReactiveCommand.Create(AddItemPropertyTableItem);
AddCustomDynTableItemCommand = ReactiveCommand.Create(AddCustomDynTableItem);

MoveUpCommand = ReactiveCommand.Create<CustomDynamicTableInstanceItem>(MoveUp);
MoveDownCommand = ReactiveCommand.Create<CustomDynamicTableInstanceItem>(MoveDown);
Expand All @@ -45,7 +45,7 @@ protected override string GetHeader()
return Data.Label;
}

private void AddItemPropertyTableItem()
private void AddCustomDynTableItem()
{
var newItem = new CustomDynamicTableInstanceItem(Data);
Data.Add(newItem);
Expand Down
57 changes: 57 additions & 0 deletions eos-edit/ViewModels/CustomTableInstanceViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using Eos.Models.Tables;
using Eos.Types;
using Eos.ViewModels.Base;
using ReactiveUI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive;
using System.Text;
using System.Threading.Tasks;

namespace Eos.ViewModels
{
public class CustomTableInstanceViewModel : DataDetailViewModel<CustomTableInstance>
{
public CustomTableInstanceViewModel() : base()
{
DeleteItemCommand = ReactiveCommand.Create<CustomTableInstanceItem>(DeleteItem);
AddItemCommand = ReactiveCommand.Create(AddItem);
}

public CustomTableInstanceViewModel(CustomTableInstance instance) : base(instance)
{
DeleteItemCommand = ReactiveCommand.Create<CustomTableInstanceItem>(DeleteItem);
AddItemCommand = ReactiveCommand.Create(AddItem);
}

protected override HashSet<String> GetHeaderSourceFields()
{
return new HashSet<String>()
{
"Label"
};
}

protected override string GetHeader()
{
return Data.Label;
}

private void AddItem()
{
var newItem = new CustomTableInstanceItem();
Data.Add(newItem);
NotifyPropertyChanged("Data");
}

private void DeleteItem(CustomTableInstanceItem item)
{
this.Data.Remove(item);
NotifyPropertyChanged("Data");
}

public ReactiveCommand<CustomTableInstanceItem, Unit> DeleteItemCommand { get; private set; }
public ReactiveCommand<Unit, Unit> AddItemCommand { get; private set; }
}
}
Loading

0 comments on commit 8fa018a

Please sign in to comment.