mirror of
https://github.com/ZuneDev/ZuneModdingHelper.git
synced 2026-07-27 13:12:21 -07:00
Initial work for AbstractUI options
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
using System.Windows.Controls;
|
||||
using OwlCore.AbstractUI.Models;
|
||||
|
||||
namespace OwlCore.Wpf.AbstractUI.Controls
|
||||
{
|
||||
/// <summary>
|
||||
/// A control that displays an <see cref="AbstractBooleanUIElement"/>.
|
||||
/// </summary>
|
||||
public partial class AbstractBooleanPresenter : Control
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using System.Windows.Controls;
|
||||
using OwlCore.AbstractUI.Models;
|
||||
|
||||
namespace OwlCore.Wpf.AbstractUI.Controls
|
||||
{
|
||||
/// <summary>
|
||||
/// A control that displays an <see cref="AbstractButton"/>.
|
||||
/// </summary>
|
||||
public partial class AbstractButtonPresenter : Control
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="AbstractButtonPresenter"/>.
|
||||
/// </summary>
|
||||
public AbstractButtonPresenter()
|
||||
{
|
||||
this.DefaultStyleKey = typeof(AbstractButtonPresenter);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using System.Windows.Controls;
|
||||
using OwlCore.AbstractUI.Models;
|
||||
|
||||
namespace OwlCore.Wpf.AbstractUI.Controls
|
||||
{
|
||||
/// <summary>
|
||||
/// A control that displays an <see cref="AbstractDataList"/>.
|
||||
/// </summary>
|
||||
public partial class AbstractDataListPresenter : Control
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using System.Windows.Controls;
|
||||
using OwlCore.AbstractUI.Models;
|
||||
|
||||
namespace OwlCore.Wpf.AbstractUI.Controls
|
||||
{
|
||||
/// <summary>
|
||||
/// A control that displays an <see cref="AbstractMultiChoiceUIElement"/>.
|
||||
/// </summary>
|
||||
public partial class AbstractMultiChoicePresenter : Control
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using System.Windows.Controls;
|
||||
using OwlCore.AbstractUI.Models;
|
||||
|
||||
namespace OwlCore.Wpf.AbstractUI.Controls
|
||||
{
|
||||
/// <summary>
|
||||
/// A control that displays an <see cref="AbstractProgressUIElement"/>.
|
||||
/// </summary>
|
||||
public partial class AbstractProgessUIElementPresenter : Control
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using System.Windows.Controls;
|
||||
using OwlCore.AbstractUI.Models;
|
||||
|
||||
namespace OwlCore.Wpf.AbstractUI.Controls
|
||||
{
|
||||
/// <summary>
|
||||
/// A control that displays an <see cref="AbstractTextBox"/>.
|
||||
/// </summary>
|
||||
public partial class AbstractRichTextBlockPresenter : Control
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using System.Windows.Controls;
|
||||
using OwlCore.AbstractUI.Models;
|
||||
|
||||
namespace OwlCore.Wpf.AbstractUI.Controls
|
||||
{
|
||||
/// <summary>
|
||||
/// A control that displays an <see cref="AbstractTextBox"/>.
|
||||
/// </summary>
|
||||
public partial class AbstractTextBoxPresenter : Control
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using OwlCore.AbstractUI.ViewModels;
|
||||
using Microsoft.Toolkit.Diagnostics;
|
||||
using OwlCore.AbstractUI.Models;
|
||||
using OwlCore.Wpf.Extensions;
|
||||
|
||||
namespace OwlCore.Wpf.AbstractUI.Controls
|
||||
{
|
||||
/// <summary>
|
||||
/// The template selector used to display Abstract UI elements. Use this to define your own custom styles for each control. You may specify the existing, default styles for those you don't want to override.
|
||||
/// </summary>
|
||||
public class AbstractUIGroupItemTemplateSelector : DataTemplateSelector
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="AbstractUIGroupItemTemplateSelector"/>.
|
||||
/// </summary>
|
||||
public AbstractUIGroupItemTemplateSelector()
|
||||
{
|
||||
if (!new Themes.AbstractTextBoxStyle().TryGetValue("DefaultAbstractTextBoxTemplate", out var textBoxTemplate))
|
||||
{
|
||||
TextBoxTemplate = ThrowHelper.ThrowArgumentNullException<DataTemplate>(nameof(textBoxTemplate));
|
||||
}
|
||||
|
||||
if (!new Themes.AbstractDataListStyle().TryGetValue("DefaultAbstractDataListTemplate", out var dataListTemplate))
|
||||
{
|
||||
DataListTemplate = ThrowHelper.ThrowArgumentNullException<DataTemplate>(nameof(dataListTemplate));
|
||||
}
|
||||
|
||||
if (!new Themes.AbstractButtonStyle().TryGetValue("DefaultAbstractButtonTemplate", out var buttonTemplate))
|
||||
{
|
||||
ButtonTemplate = ThrowHelper.ThrowArgumentNullException<DataTemplate>(nameof(buttonTemplate));
|
||||
}
|
||||
|
||||
if (!new Themes.AbstractMultiChoiceUIElementStyle().TryGetValue("DefaultAbstractMultipleChoiceTemplate", out var multiChoiceTemplate))
|
||||
{
|
||||
MultiChoiceTemplate = ThrowHelper.ThrowArgumentNullException<DataTemplate>(nameof(multiChoiceTemplate));
|
||||
}
|
||||
|
||||
if (!new Themes.AbstractBooleanStyle().TryGetValue("DefaultAbstractBooleanTemplate", out var booleanTemplate))
|
||||
{
|
||||
BooleanTemplate = ThrowHelper.ThrowArgumentNullException<DataTemplate>(nameof(booleanTemplate));
|
||||
}
|
||||
|
||||
if (!new Themes.AbstractProgressUIElementStyle().TryGetValue("DefaultAbstractProgressUIElementTemplate", out var progressTemplate))
|
||||
{
|
||||
ProgressTemplate = ThrowHelper.ThrowArgumentNullException<DataTemplate>(nameof(progressTemplate));
|
||||
}
|
||||
|
||||
TextBoxTemplate = (DataTemplate)textBoxTemplate;
|
||||
DataListTemplate = (DataTemplate)dataListTemplate;
|
||||
ButtonTemplate = (DataTemplate)buttonTemplate;
|
||||
MultiChoiceTemplate = (DataTemplate)multiChoiceTemplate;
|
||||
BooleanTemplate = (DataTemplate)booleanTemplate;
|
||||
ProgressTemplate = (DataTemplate)progressTemplate;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The data template used to display an <see cref="AbstractUIElementGroup"/>.
|
||||
/// </summary>
|
||||
public DataTemplate? ElementGroupTemplate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The data template used to display an <see cref="AbstractTextBox"/>.
|
||||
/// </summary>
|
||||
public DataTemplate TextBoxTemplate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The data template used to display an <see cref="AbstractDataList"/>.
|
||||
/// </summary>
|
||||
public DataTemplate DataListTemplate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The data template used to display an <see cref="AbstractButton"/>.
|
||||
/// </summary>
|
||||
public DataTemplate ButtonTemplate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The data template used to display an <see cref="AbstractBooleanUIElement"/>.
|
||||
/// </summary>
|
||||
public DataTemplate BooleanTemplate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The data template used to display an <see cref="AbstractProgressUIElement"/>.
|
||||
/// </summary>
|
||||
public DataTemplate ProgressTemplate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The data template used to display an <see cref="AbstractMultiChoiceUIElement"/>.
|
||||
/// </summary>
|
||||
public DataTemplate MultiChoiceTemplate { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public override DataTemplate SelectTemplate(object item, DependencyObject container)
|
||||
{
|
||||
if (!new Themes.AbstractUIGroupPresenterStyle().TryGetValue("DefaultAbstractUIElementGroupTemplate", out var elementGroupTemplate))
|
||||
ElementGroupTemplate = ThrowHelper.ThrowArgumentNullException<DataTemplate>(nameof(elementGroupTemplate));
|
||||
|
||||
ElementGroupTemplate = (DataTemplate)elementGroupTemplate;
|
||||
|
||||
return item switch
|
||||
{
|
||||
AbstractTextBoxViewModel => TextBoxTemplate,
|
||||
AbstractDataListViewModel => DataListTemplate,
|
||||
AbstractButtonViewModel => ButtonTemplate,
|
||||
AbstractMultiChoiceUIElementViewModel => MultiChoiceTemplate,
|
||||
AbstractBooleanViewModel => BooleanTemplate,
|
||||
AbstractProgressUIElementViewModel => ProgressTemplate,
|
||||
AbstractUIElementGroupViewModel => ElementGroupTemplate,
|
||||
_ => null!
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using OwlCore.AbstractUI.ViewModels;
|
||||
using OwlCore.AbstractUI.Models;
|
||||
|
||||
namespace OwlCore.Wpf.AbstractUI.Controls
|
||||
{
|
||||
/// <summary>
|
||||
/// Displays a group of abstract UI elements.
|
||||
/// </summary>
|
||||
public sealed partial class AbstractUIGroupPresenter : Control
|
||||
{
|
||||
private bool _dataContextBeingSet;
|
||||
|
||||
/// <summary>
|
||||
/// Backing property for <see cref="ViewModel"/>.
|
||||
/// </summary>
|
||||
public static readonly DependencyProperty ViewModelProperty =
|
||||
DependencyProperty.Register(nameof(ViewModel), typeof(AbstractUIElementGroupViewModel), typeof(AbstractUIGroupPresenter), new PropertyMetadata(null, (d, e) => ((AbstractUIGroupPresenter)d).OnViewModelChanged()));
|
||||
|
||||
/// <summary>
|
||||
/// Backing property for <see cref="TemplateSelector"/>.
|
||||
/// </summary>
|
||||
public static readonly DependencyProperty TemplateSelectorProperty =
|
||||
DependencyProperty.Register(nameof(TemplateSelector), typeof(DataTemplateSelector), typeof(AbstractUIGroupPresenter), new PropertyMetadata(null));
|
||||
|
||||
/// <summary>
|
||||
/// The ViewModel for this UserControl.
|
||||
/// </summary>
|
||||
public AbstractUIElementGroupViewModel? ViewModel
|
||||
{
|
||||
get => (AbstractUIElementGroupViewModel)GetValue(ViewModelProperty);
|
||||
set => SetValue(ViewModelProperty, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The template selector used to display Abstract UI elements. Use this to define your own custom styles for each control. You may specify the existing, default styles for those you don't want to override.
|
||||
/// </summary>
|
||||
public DataTemplateSelector? TemplateSelector
|
||||
{
|
||||
get => (DataTemplateSelector)GetValue(TemplateSelectorProperty);
|
||||
set => SetValue(TemplateSelectorProperty, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="AbstractUIGroupPresenter"/>.
|
||||
/// </summary>
|
||||
public AbstractUIGroupPresenter()
|
||||
{
|
||||
this.DefaultStyleKey = typeof(AbstractUIGroupPresenter);
|
||||
|
||||
AttachEvents();
|
||||
}
|
||||
|
||||
private void AttachEvents()
|
||||
{
|
||||
Loaded += OnLoaded;
|
||||
|
||||
DataContextChanged += OnDataContextChanged;
|
||||
}
|
||||
|
||||
private void DetachEvents()
|
||||
{
|
||||
DataContextChanged -= OnDataContextChanged;
|
||||
}
|
||||
|
||||
private void OnDataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
if (_dataContextBeingSet)
|
||||
return;
|
||||
|
||||
_dataContextBeingSet = true;
|
||||
|
||||
if (DataContext is AbstractUIElementGroup elementGroup)
|
||||
ViewModel = new AbstractUIElementGroupViewModel(elementGroup);
|
||||
|
||||
if (DataContext is AbstractUIElementGroupViewModel elementGroupViewModel)
|
||||
ViewModel = elementGroupViewModel;
|
||||
|
||||
_dataContextBeingSet = false;
|
||||
}
|
||||
|
||||
private void OnLoaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Loaded -= OnLoaded;
|
||||
Unloaded += OnUnloaded;
|
||||
}
|
||||
|
||||
private void OnUnloaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Unloaded -= OnUnloaded;
|
||||
|
||||
DetachEvents();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raised when the <see cref="ViewModel"/> changes.
|
||||
/// </summary>
|
||||
public void OnViewModelChanged()
|
||||
{
|
||||
if (_dataContextBeingSet)
|
||||
return;
|
||||
|
||||
_dataContextBeingSet = true;
|
||||
DataContext = ViewModel;
|
||||
_dataContextBeingSet = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user