Repository navigation
Expand file tree
/
Copy pathUIEditorScreen.cs
More file actions
211 lines (188 loc) · 8.03 KB
/
Copy pathUIEditorScreen.cs
File metadata and controls
211 lines (188 loc) · 8.03 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
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
using System.Collections.Generic;
using TaleWorlds.Core;
using TaleWorlds.Engine.GauntletUI;
using TaleWorlds.Engine;
using TaleWorlds.GauntletUI.Data;
using TaleWorlds.InputSystem;
using TaleWorlds.Library;
using TaleWorlds.MountAndBlade;
using TaleWorlds.ScreenSystem;
using TaleWorlds.TwoDimension;
using TaleWorlds.MountAndBlade.View.Screens;
using Path = System.IO.Path;
using System.Windows.Forms;
namespace InGameUIDesigner
{
[GameStateScreen(typeof(UIEditorState))]
public class UIEditorScreen : ScreenBase, IGameStateListener
{
public UIEditorScreen(UIEditorState state)
{
_editorState = state;
_editorState.RegisterListener(this);
_alreadyLoadedCategories = new List<SpriteCategory>();
_saveFile = new SaveFileDialog();
_saveFile.Title = "Export Prefab";
_saveFile.FileName = "prefab";
_saveFile.DefaultExt = ".xml";
_saveFile.CreatePrompt = false;
_saveFile.OverwritePrompt = true;
_saveFile.Filter = "XML File (.xml)|*.xml";
_saveFile.InitialDirectory = Path.GetFullPath(BasePath.Name + "Modules");
_saveFile.AddExtension = true;
_openFile = new OpenFileDialog();
_openFile.Title = "Import Prefab";
_openFile.FileName = "";
_openFile.DefaultExt = ".xml";
_openFile.Filter = "XML File (.xml)|*.xml";
_openFile.InitialDirectory = Path.GetFullPath(BasePath.Name + "Modules");
}
protected override void OnFrameTick(float dt)
{
base.OnFrameTick(dt);
if (_editorDataSource == null || _editorLayer == null) return;
if (!_popupDataSource.PopUpsEnabled)
{
if (_editorLayer.Input.IsKeyPressed(InputKey.LeftMouseButton)) _editorDataSource.OnMousePressed();
if (_editorLayer.Input.IsKeyReleased(InputKey.LeftMouseButton)) _editorDataSource.OnMouseReleased();
if (_editorLayer.Input.IsKeyPressed(InputKey.Z) && _editorLayer.Input.IsKeyDown(InputKey.LeftControl))
{
if (_editorLayer.Input.IsKeyDown(InputKey.LeftShift)) _editorDataSource.Redo();
else _editorDataSource.Undo();
}
}
if (_editorLayer.Input.IsHotKeyPressed(_doneKey.Id))
{
OpenExportPrompt();
}
else if (_editorLayer.Input.IsHotKeyPressed(_exitKey.Id))
{
if (_popupDataSource.PopUpsEnabled) HideBrushAndSpritePreviewList();
else OpenExitPrompt();
}
_editorDataSource.Tick(dt);
}
void IGameStateListener.OnActivate()
{
_doneKey = HotKeyManager.GetCategory("GenericPanelGameKeyCategory").GetHotKey("Confirm");
_exitKey = HotKeyManager.GetCategory("GenericPanelGameKeyCategory").GetHotKey("Exit");
_alreadyLoadedCategories.Clear();
foreach (var spriteCategory in UIResourceManager.SpriteData.SpriteCategories.Values)
{
if (spriteCategory.IsLoaded) _alreadyLoadedCategories.Add(spriteCategory);
else spriteCategory.Load(UIResourceManager.ResourceContext, UIResourceManager.ResourceDepot);
}
_editorDataSource = new UIEditorVM(this);
_editorLayer = new GauntletLayer("UIEditorLayer", 3000, true);
_editorMovie = _editorLayer.LoadMovie("UIEditor", _editorDataSource).Movie;
_editorLayer.Input.RegisterHotKeyCategory(HotKeyManager.GetCategory("GenericPanelGameKeyCategory"));
_editorLayer.InputRestrictions.SetInputRestrictions(true, InputUsageMask.All);
_editorLayer.IsFocusLayer = true;
AddLayer(_editorLayer);
ScreenManager.TrySetFocus(_editorLayer);
if (BannerlordConfig.ForceVSyncInMenus)
{
Utilities.SetForceVsync(true);
}
InitializeVM();
_popupDataSource = new UIEditorPopUpsVM();
_popUpLayer = new GauntletLayer("UIEditorPopUpsLayer", 4000, true);
_popUpMovie = _popUpLayer.LoadMovie("UIEditor.PopUps", _popupDataSource).Movie;
_popupDataSource.SetColourPickerWidget(_popUpMovie.RootWidget.FindChild("HueSaturationPicker", true));
_popUpLayer.InputRestrictions.SetInputRestrictions(true, InputUsageMask.All);
AddLayer(_popUpLayer);
_variableEditorDataSource = new VariableEditorVM();
_variableEditorLayer = new GauntletLayer("UIEditorVariableEditorLayer", 5000, true);
_variableEditorMovie = _variableEditorLayer.LoadMovie("UIEditor.VariableEditor",_variableEditorDataSource).Movie;
_variableEditorLayer.InputRestrictions.SetInputRestrictions(true,InputUsageMask.All);
AddLayer(_variableEditorLayer);
}
void IGameStateListener.OnDeactivate()
{
Utilities.SetForceVsync(false);
_editorLayer.InputRestrictions.ResetInputRestrictions();
RemoveLayer(_editorLayer);
_editorLayer = null;
_popUpLayer.InputRestrictions.ResetInputRestrictions();
RemoveLayer(_popUpLayer);
_popUpLayer = null;
foreach (var spriteCategory in UIResourceManager.SpriteData.SpriteCategories.Values)
{
if (_alreadyLoadedCategories.Contains(spriteCategory)) continue;
spriteCategory.Unload();
}
}
void IGameStateListener.OnInitialize()
{
}
void IGameStateListener.OnFinalize()
{
}
public void OpenExportPrompt()
{
if (_saveFile.ShowDialog() == DialogResult.OK)
{
_editorDataSource.ExportPrefab(_saveFile.FileName);
}
}
public void OpenImportPrompt()
{
if(_openFile.ShowDialog() == DialogResult.OK)
{
_editorDataSource.ImportPrefabFromFile(_openFile.FileName);
}
}
public void OpenExitPrompt()
{
_popupDataSource.ShowExitConfirmation();
}
public void ShowBrushPreviewList()
{
_popupDataSource.ShowBrushList();
}
public void ShowSpritePreviewList()
{
_popupDataSource.ShowSpriteList();
}
public void HideBrushAndSpritePreviewList()
{
_popupDataSource.ClosePopUps();
}
public void HideVariableEditor()
{
_variableEditorDataSource.CloseVariableEditor();
}
public void ShowColourPicker(WidgetPropertyVM property)
{
_popupDataSource.ShowColourPickerMethod(property);
}
public void ShowVariableEditor()
{
_variableEditorDataSource.ShowVariableEditorMethod();
}
public VariableEditorVM GetVariableEditorVM()
{
return _variableEditorDataSource;
}
private void InitializeVM()
{
var previewRootWidget = _editorMovie.RootWidget.FindChild("PreviewRootWidget", true);
_editorDataSource.Initialize(previewRootWidget, _editorLayer.UIContext, (GauntletMovie)_editorMovie);
}
private UIEditorState _editorState;
private UIEditorVM _editorDataSource;
private GauntletLayer _editorLayer;
private IGauntletMovie _editorMovie;
private UIEditorPopUpsVM _popupDataSource;
private GauntletLayer _popUpLayer;
private IGauntletMovie _popUpMovie;
private SaveFileDialog _saveFile;
private OpenFileDialog _openFile;
private HotKey _doneKey;
private HotKey _exitKey;
private List<SpriteCategory> _alreadyLoadedCategories;
private VariableEditorVM _variableEditorDataSource;
private GauntletLayer _variableEditorLayer;
private IGauntletMovie _variableEditorMovie;
}
}