-
Notifications
You must be signed in to change notification settings - Fork 68
/
Copy pathEditorData.cs
140 lines (121 loc) · 4.29 KB
/
EditorData.cs
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AxeSoftware.Quest;
using AxeSoftware.Quest.Scripts;
namespace AxeSoftware.Quest
{
internal class EditorAttributeData : IEditorAttributeData
{
public EditorAttributeData(string attributeName, bool isInherited, string source, bool isDefaultType)
{
AttributeName = attributeName;
IsInherited = isInherited;
Source = source;
IsDefaultType = isDefaultType;
}
public string AttributeName
{
get;
private set;
}
public bool IsInherited
{
get;
private set;
}
public string Source
{
get;
set;
}
public bool IsDefaultType
{
get;
set;
}
}
internal class EditorData : IEditorDataExtendedAttributeInfo
{
private Element m_element;
private EditorController m_controller;
public event EventHandler Changed;
public EditorData(Element element, EditorController controller)
{
m_element = element;
m_controller = controller;
element.Fields.AttributeChanged += Fields_AttributeChanged;
element.Fields.AttributeChangedSilent += Fields_AttributeChanged;
}
void Fields_AttributeChanged(object sender, AttributeChangedEventArgs e)
{
if (Changed != null) Changed(this, new EventArgs());
}
public string Name
{
get { return m_element.Name; }
}
public object GetAttribute(string attribute)
{
if (attribute == "name" && m_element.Fields[FieldDefinitions.Anonymous])
{
return string.Empty;
}
return m_controller.WrapValue(m_element.Fields.Get(attribute), m_element, attribute);
}
public void SetAttribute(string attribute, object value)
{
if (attribute == "name" && m_element.Fields[FieldDefinitions.Anonymous])
{
m_element.Fields[FieldDefinitions.Anonymous] = false;
}
IDataWrapper wrapper = value as IDataWrapper;
if (wrapper != null)
{
value = wrapper.GetUnderlyingValue();
}
m_element.Fields.Set(attribute, value);
}
// When the "anonymous" field is updated, that affects how the "name" attribute is displayed.
public IEnumerable<string> GetAffectedRelatedAttributes(string attribute)
{
if (attribute == "anonymous")
{
return new List<string> { "name" };
}
else
{
return null;
}
}
public IEnumerable<IEditorAttributeData> GetAttributeData()
{
DebugData data = m_controller.WorldModel.GetDebugData(m_element.Name);
return ConvertDebugDataToEditorAttributeData(data);
}
public IEditorAttributeData GetAttributeData(string attribute)
{
DebugDataItem data = m_controller.WorldModel.GetDebugDataItem(m_element.Name, attribute);
return new EditorAttributeData(attribute, data.IsInherited, data.Source, data.IsDefaultType);
}
public void RemoveAttribute(string attribute)
{
m_element.Fields.RemoveField(attribute);
}
public IEnumerable<IEditorAttributeData> GetInheritedTypes()
{
DebugData data = m_controller.WorldModel.GetInheritedTypesDebugData(m_element.Name);
return ConvertDebugDataToEditorAttributeData(data);
}
private IEnumerable<IEditorAttributeData> ConvertDebugDataToEditorAttributeData(DebugData data)
{
List<EditorAttributeData> result = new List<EditorAttributeData>();
foreach (var item in data.Data)
{
result.Add(new EditorAttributeData(item.Key, item.Value.IsInherited, item.Value.Source, item.Value.IsDefaultType));
}
return result;
}
}
}