Skip to content

Commit

Permalink
[Conditions] Universal conditions editor
Browse files Browse the repository at this point in the history
  • Loading branch information
BAndysc committed May 8, 2021
1 parent 058b1c2 commit d885c29
Show file tree
Hide file tree
Showing 67 changed files with 1,622 additions and 130 deletions.
1 change: 1 addition & 0 deletions LoaderAvalonia/LoaderAvalonia.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<ProjectReference Include="..\WDE.AzerothCore\WDE.AzerothCore.csproj" />
<ProjectReference Include="..\WDE.Common.Avalonia\WDE.Common.Avalonia.csproj" />
<ProjectReference Include="..\WDE.CommonViews.Avalonia\WDE.CommonViews.Avalonia.csproj" />
<ProjectReference Include="..\WDE.Conditions.Avalonia\WDE.Conditions.Avalonia.csproj" />
<ProjectReference Include="..\WDE.Conditions\WDE.Conditions.csproj" />
<ProjectReference Include="..\WDE.DatabaseEditors.Avalonia\WDE.DatabaseEditors.Avalonia.csproj" />
<ProjectReference Include="..\WDE.DatabaseEditors\WDE.DatabaseEditors.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
using System.Windows.Controls;
using System.Windows.Documents;

namespace WDE.SmartScriptEditor.WPF.Editor.Views.Helpers
namespace WDE.Common.WPF.Attached
{
public static class SmartFormattedText
public class SmartFormattedText
{
public static string GetSmartFormattedText(DependencyObject obj) => (string)obj.GetValue(SmartFormattedTextProperty);
public static void SetSmartFormattedText(DependencyObject obj, string value) => obj.SetValue(SmartFormattedTextProperty, value);
public static readonly DependencyProperty SmartFormattedTextProperty =
DependencyProperty.RegisterAttached("SmartFormattedText", typeof(string), typeof(SmartFormattedText), new PropertyMetadata("", AllowOnlyString));
public static string GetText(DependencyObject obj) => (string)obj.GetValue(TextProperty);
public static void SetText(DependencyObject obj, string value) => obj.SetValue(TextProperty, value);
public static readonly DependencyProperty TextProperty =
DependencyProperty.RegisterAttached("Text", typeof(string), typeof(SmartFormattedText), new PropertyMetadata("", AllowOnlyString));

public static Style GetParamStyle(DependencyObject obj) => (Style)obj.GetValue(ParamStyleProperty);
public static void SetParamStyle(DependencyObject obj, Style value) => obj.SetValue(ParamStyleProperty, value);
Expand All @@ -29,11 +29,12 @@ public static class SmartFormattedText
public static readonly DependencyProperty SourceStyleProperty =
DependencyProperty.RegisterAttached("SourceStyle", typeof(Style), typeof(SmartFormattedText), new PropertyMetadata(null, AllowOnlyString));


private static void AllowOnlyString(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is TextBlock tb)
{
var text = GetSmartFormattedText(d);
var text = GetText(d);
var paramStyle = GetParamStyle(d);
var sourceStyle = GetSourceStyle(d);
var contextArray = GetContextArray(d);
Expand All @@ -47,7 +48,7 @@ private static void AllowOnlyString(DependencyObject d, DependencyPropertyChange
State state = State.Text;
Styles currentStyle = Styles.Normal;
int currentContextIndex = -1;
Run lastRun = null;
Run? lastRun = null;

void Append(string s)
{
Expand All @@ -56,14 +57,14 @@ void Append(string s)
lastRun.Text += s;
return;
}

lastRun = new Run(s);

if (contextArray != null && currentContextIndex >= 0 && currentContextIndex < contextArray.Count)
lastRun.DataContext = contextArray[currentContextIndex];
else
lastRun.DataContext = null;

if (currentStyle.HasFlag(Styles.Parameter) && paramStyle != null)
lastRun.Style = paramStyle;

Expand Down Expand Up @@ -112,16 +113,16 @@ void Append(string s)
currentStyle = currentStyle | Styles.Source;
}

if (text[start + 1] == '=' && Char.IsDigit(text[start + 2]))
if (text[start + 1] == '=' && char.IsDigit(text[start + 2]))
currentContextIndex = text[start + 2] - '0';

start = i + 1;
state = State.Text;
}
else if (l == ']' && state == State.InClosingTag)
{
if (text[start] == 'p')
currentStyle = currentStyle &~Styles.Parameter;
currentStyle = currentStyle & ~Styles.Parameter;
else if (text[start] == 's')
currentStyle = currentStyle & ~Styles.Source;

Expand Down
23 changes: 23 additions & 0 deletions WDE.Common.WPF/Components/ParameterValueHolderView.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

namespace WDE.Common.WPF.Components
{
public class ParameterValueHolderView : Control
{
public ICommand PickCommand
{
get => (ICommand)GetValue(PickCommandProperty);
set => SetValue(PickCommandProperty, value);
}

public static readonly DependencyProperty PickCommandProperty =
DependencyProperty.Register("PickCommand", typeof(ICommand), typeof(ParameterValueHolderView));

static ParameterValueHolderView()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(ParameterValueHolderView), new FrameworkPropertyMetadata(typeof(ParameterValueHolderView)));
}
}
}
59 changes: 57 additions & 2 deletions WDE.Common.WPF/Themes/Generic.xaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:components="clr-namespace:WDE.Common.WPF.Components"
xmlns:viewHelpers="clr-namespace:WDE.Common.WPF.ViewHelpers"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:themes="clr-namespace:WDE.Common.WPF.Themes">
<viewHelpers:LongToBoolConverter x:Key="LongToBoolConverter" />
<Style TargetType="{x:Type components:TeachingTip}">
<Setter Property="Background" Value="{DynamicResource TeachingTipBackground}" />
<Setter Property="BorderBrush" Value="{DynamicResource TeachingTipBorderBrush}" />
Expand Down Expand Up @@ -50,4 +51,58 @@
</Trigger>
</Style.Triggers>
</Style>
</ResourceDictionary>

<Style x:Key="ParameterTextBoxStyle" TargetType="{x:Type TextBox}" BasedOn="{StaticResource {x:Type TextBox}}">
<Setter Property="Text" Value="{Binding String, Mode=OneWay}" />
<Style.Triggers>
<Trigger Property="IsFocused" Value="true">
<Setter Property="Text" Value="{Binding Value, Mode=TwoWay}" />
</Trigger>
</Style.Triggers>
</Style>

<Style TargetType="{x:Type components:ParameterValueHolderView}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type components:ParameterValueHolderView}">
<ContentControl Content="{Binding ., Mode=OneWay}">
<ContentControl.ContentTemplateSelector>
<themes:ParameterDataTemplateSelector>
<themes:ParameterDataTemplateSelector.Generic>
<DataTemplate>
<DockPanel LastChildFill="True">
<Button DockPanel.Dock="Right" Content=" ... "
CommandParameter="{Binding .}"
Command="{Binding PickCommand, RelativeSource={RelativeSource AncestorType={x:Type components:ParameterValueHolderView}}}" Margin="3,0,0,0">
<Button.Style>
<Style TargetType="{x:Type Button}" BasedOn="{StaticResource {x:Type Button}}">
<Style.Triggers>
<DataTrigger Binding="{Binding HasItems}" Value="False">
<Setter Property="Visibility" Value="Collapsed" />
</DataTrigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
<TextBox TabIndex="0"
VerticalContentAlignment="Center"
FontFamily="Consolas"
Style="{StaticResource ParameterTextBoxStyle}">
</TextBox>
</DockPanel>
</DataTemplate>
</themes:ParameterDataTemplateSelector.Generic>
<themes:ParameterDataTemplateSelector.BoolParameter>
<DataTemplate>
<CheckBox Focusable="True" VerticalContentAlignment="Center" HorizontalAlignment="Stretch"
IsChecked="{Binding Value, Converter={StaticResource LongToBoolConverter}}" />
</DataTemplate>
</themes:ParameterDataTemplateSelector.BoolParameter>
</themes:ParameterDataTemplateSelector>
</ContentControl.ContentTemplateSelector>
</ContentControl>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
26 changes: 26 additions & 0 deletions WDE.Common.WPF/Themes/ParameterDataTemplateSelector.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using WDE.Parameters;
using WDE.Parameters.Models;

namespace WDE.Common.WPF.Themes
{
internal class ParameterDataTemplateSelector : DataTemplateSelector
{
public DataTemplate? Generic { get; set; }
public DataTemplate? BoolParameter { get; set; }

public override DataTemplate SelectTemplate(object item, DependencyObject container)
{
if (item is ParameterValueHolder<long> intParam && intParam.Parameter is BoolParameter boolParameter && BoolParameter != null)
return BoolParameter;
return Generic!;
}
}

}
1 change: 1 addition & 0 deletions WDE.Common.WPF/WDE.Common.WPF.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\WDE.Parameters\WDE.Parameters.csproj" />
<ProjectReference Include="..\WoWDatabaseEditor.Common\WDE.Common\WDE.Common.csproj" />
<PackageReference Include="AvalonEdit">
<Version>6.1.0-preview1</Version>
Expand Down
9 changes: 9 additions & 0 deletions WDE.Conditions.Avalonia/ConditionsAvaloniaModule.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using WDE.Module;

namespace WDE.Conditions.Avalonia
{
public class ConditionsAvaloniaModule : ModuleBase
{

}
}

0 comments on commit d885c29

Please sign in to comment.