Repository navigation
Expand file tree
/
Copy pathVariableEditorItemVisualStateVM.cs
More file actions
101 lines (85 loc) · 3.15 KB
/
Copy pathVariableEditorItemVisualStateVM.cs
File metadata and controls
101 lines (85 loc) · 3.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
using System.Linq;
using TaleWorlds.GauntletUI;
using TaleWorlds.Library;
namespace InGameUIDesigner
{
public class VariableEditorItemVisualStateVM : ViewModel
{
[DataSourceProperty]
public string VisualStateName
{
get => _visualStateName;
set
{
if (_visualStateName != value)
{
string oldName = _visualStateName;
_visualStateName = value;
// Update the actual VisualState's State property
if (VisualState != null && !string.IsNullOrEmpty(oldName) && oldName != value)
{
// The State property is readonly, so we need to use reflection
var stateField = VisualState.GetType().GetField("_state",
System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
if (stateField != null)
{
stateField.SetValue(VisualState, value);
}
}
OnPropertyChangedWithValue(value, "VisualStateName");
}
}
}
[DataSourceProperty]
public MBBindingList<VariableEditorItemPropertyVM> Properties
{
get => _properties;
set
{
if (_properties != value)
{
_properties = value;
OnPropertyChangedWithValue(value, "Properties");
}
}
}
public VisualState VisualState { get; private set; }
private string _visualStateName = "";
private MBBindingList<VariableEditorItemPropertyVM> _properties = new();
public VariableEditorItemVisualStateVM(string name, VisualState visualState)
{
VisualState = visualState;
_visualStateName = name;
InitializeProperties();
}
public VariableEditorItemVisualStateVM(string name)
{
VisualState = new VisualState(name);
_visualStateName = name;
InitializeProperties();
}
public VariableEditorItemVisualStateVM()
{
_visualStateName = "VisualState1";
VisualState = new VisualState(_visualStateName);
InitializeProperties();
}
private void InitializeProperties()
{
Properties.Clear();
// Get all public properties of VisualState
var properties = VisualState.GetType()
.GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance)
.Where(p => p.CanRead && p.CanWrite && p.Name != "State")
.ToList();
foreach (var prop in properties)
{
Properties.Add(new VariableEditorItemPropertyVM(this, VisualState, prop));
}
}
public void OnPropertyUpdated()
{
// Called when a property of the VisualState is updated
}
}
}