-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEditorUI_Edit.cs
More file actions
245 lines (197 loc) · 9.38 KB
/
Copy pathEditorUI_Edit.cs
File metadata and controls
245 lines (197 loc) · 9.38 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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
using System;
using System.IO;
using System.Windows.Forms;
using Sandbox.Graphics.GUI;
using Sandbox.ModAPI;
using VRage.Game;
using VRage.Render.Particles;
using VRageMath;
namespace Digi.ParticleEditor
{
public partial class EditorUI
{
enum TabEnum { Emitters, Lights, General, Debug }
TabEnum Tab;
public VerticalControlsHost ScrollHost;
public MyGuiControlScrollablePanel ScrollablePanel;
public readonly EditorLights EditorLights;
public readonly EditorEmitters EditorEmitters;
public readonly EditorGeneral EditorGeneral;
public readonly EditorDebug EditorDebug;
float LastScrollEmitters = 0f;
float LastScrollLights = 0f;
bool IgnoreScrollEvent;
MyGuiControlButton.StyleDefinition ButtonStyle_TabSelected = new MyGuiControlButton.StyleDefinition
{
NormalTexture = MyGuiConstants.TEXTURE_RECTANGLE_BUTTON_ACTIVE_BORDER,
HighlightTexture = MyGuiConstants.TEXTURE_RECTANGLE_BUTTON_FOCUS_BORDER,
FocusTexture = MyGuiConstants.TEXTURE_RECTANGLE_BUTTON_ACTIVE_BORDER,
ActiveTexture = MyGuiConstants.TEXTURE_RECTANGLE_BUTTON_ACTIVE_BORDER,
NormalFont = "White",
HighlightFont = "White",
Padding = new MyGuiBorderThickness(5f / MyGuiConstants.GUI_OPTIMAL_SIZE.X, 5f / MyGuiConstants.GUI_OPTIMAL_SIZE.Y),
TextColorFocus = Color.White,
BackgroundColor = Color.White,
};
void Controls_EditParticle()
{
MyGuiControlLabel tabsLabel = Host.CreateLabel("Tabs:");
MyGuiControlButton buttonEmitters = Host.CreateButton("Emitters", "Show list of emitters", clicked: (c) =>
{
Tab = TabEnum.Emitters;
RefreshShowOnlySelected();
RefreshUI();
});
MyGuiControlButton buttonLights = Host.CreateButton("Lights", "Show list of lights", clicked: (c) =>
{
Tab = TabEnum.Lights;
RefreshShowOnlySelected();
RefreshUI();
});
MyGuiControlButton buttonGeneral = Host.CreateButton("General", "Edit general properties of the particle", clicked: (c) =>
{
Tab = TabEnum.General;
RefreshUI();
});
MyGuiControlButton buttonDebug = Host.CreateButton("Debug", "Global settings for debugging/experimenting", clicked: (c) =>
{
Tab = TabEnum.Debug;
RefreshUI();
});
//float availableWidth = tabsLabel.Size.X - (Host.ControlSpacing * 4) - (Host.Padding.X * 2);
//float tabButtonWidth = availableWidth / 4f;
//buttonEmitters.Size = new Vector2(tabButtonWidth, buttonEmitters.Size.Y);
//buttonLights.Size = new Vector2(tabButtonWidth, buttonLights.Size.Y);
//buttonGeneral.Size = new Vector2(tabButtonWidth, buttonGeneral.Size.Y);
//buttonDebug.Size = new Vector2(tabButtonWidth, buttonDebug.Size.Y);
//Host.PositionControlsNoSize(tabsLabel, buttonEmitters, buttonLights, buttonGeneral, buttonDebug);
Host.PositionControls(tabsLabel, buttonEmitters, buttonLights, buttonGeneral, buttonDebug);
Host.InsertSeparator();
Vector2 size = new Vector2(Host.PanelSize.X - Host.Padding.X * 2 - EyeballedScrollbarWidth, 0f);
ScrollHost = new VerticalControlsHost(null, Vector2.Zero, size);
ScrollablePanel = Host.CreateScrollableArea(ScrollHost.Panel, new Vector2(ScreenSize.X - Host.Padding.X * 2, 0.62f));
IgnoreScrollEvent = true;
ScrollablePanel.PanelScrolled += (panel) =>
{
if(IgnoreScrollEvent)
return;
if(Tab == TabEnum.Emitters)
LastScrollEmitters = panel.ScrollbarVPosition;
else if(Tab == TabEnum.Lights)
LastScrollLights = panel.ScrollbarVPosition;
};
MyGuiControlButton highlightButton = null;
if(Tab == TabEnum.Emitters)
{
highlightButton = buttonEmitters;
EditorEmitters.RecreateControls(Host);
ScrollablePanel.SetVerticalScrollbarValue(LastScrollEmitters);
}
else if(Tab == TabEnum.Lights)
{
highlightButton = buttonLights;
EditorLights.RecreateControls(Host);
ScrollablePanel.SetVerticalScrollbarValue(LastScrollLights);
}
else if(Tab == TabEnum.General)
{
highlightButton = buttonGeneral;
EditorGeneral.RecreateControls(Host);
}
else if(Tab == TabEnum.Debug)
{
highlightButton = buttonDebug;
EditorDebug.RecreateControls(Host);
}
if(highlightButton != null)
{
highlightButton.CustomStyle = ButtonStyle_TabSelected;
FocusedControl = highlightButton;
}
IgnoreScrollEvent = false;
Host.SetPosition(new Vector2(Host.CurrentPosition.X, (ScreenSize.Y / 2) - ButtonSize.Y - (Host.Padding.Y * 2)));
MyGuiControlButton buttonSaveToFile = Host.CreateButton("Save to file", "Saves the particle to a .sbc file in the folder that you pick.");
buttonSaveToFile.ButtonClicked += (b) =>
{
if(SelectedParticle.SpawnedEffect == null)
return;
buttonSaveToFile.Enabled = false;
try
{
if(DrawOnlySelected)
{
RestoreEnabled();
}
MyObjectBuilder_Definitions definitionsOB = new MyObjectBuilder_Definitions()
{
ParticleEffects = new MyObjectBuilder_ParticleEffect[]
{
MyParticleEffectDataSerializer.SerializeToObjectBuilder(SelectedParticle.Data),
},
};
string fileName = SelectedParticle.Name;
foreach(char c in Path.GetInvalidFileNameChars())
{
fileName = fileName.Replace(c, '_');
}
FileDialog<SaveFileDialog>("Save a particle effect", null, FileDialogFilterSBC, (filePath) =>
{
try
{
if(EditorUI.SerializeToXML(filePath, definitionsOB))
{
Notifications.Show($"Succesfully saved {SelectedParticle.Name} to:\n{filePath}", 5, Color.LimeGreen);
}
}
catch(Exception e)
{
Log.Error(e);
}
}, preFilledFileName: fileName);
}
catch(Exception e)
{
Log.Error(e);
Editor.Backup.BackupCurrentParticle();
}
finally
{
buttonSaveToFile.Enabled = true;
}
};
MyGuiControlButton buttonHelp = Host.CreateButton("Help/hotkeys",
"Hold RMB while not on any UI to have normal game control." +
"\nF to restart particle playback." +
"\nR to toggle parenting particle to character." +
"\nAlso various hotkeys in individual controls like in sliders, input boxes, timelines, etc, see their tooltips." +
"\n");
MyGuiControlButton buttonResetAll = Host.CreateButton("Full Reset",
"Resets the entire particle to its original state, if it was a loaded particle.",
clicked: (b) =>
{
if(SelectedParticle == null)
return;
if(SelectedParticle.OriginalData == null)
{
Notifications.Show("No original data found, this is likely a new particle.", 5, Color.Red);
return;
}
EditorUI.PopupConfirmation("Are you sure you want to reset this entire effect back to its original state?", () =>
{
MyParticleEffectData data = new MyParticleEffectData();
data.Start(SelectedParticle.Data.ID, SelectedParticle.Data.Name);
MyParticleEffectDataSerializer.DeserializeFromObjectBuilder(data, SelectedParticle.OriginalData);
MyParticleEffectsLibrary.Remove(data.Name);
MyParticleEffectsLibrary.Add(data);
SelectedParticle.Despawn();
SelectedParticle.Spawn(data.Name, true);
SelectedParticle.HasChanges = false;
Notifications.Show("Particle reset to original state.", 5);
RefreshUI();
}, focusNoButton: true);
});
Host.PositionControls(buttonHelp, buttonResetAll, buttonSaveToFile);
// TODO: revert entire particle to OriginalParticleData
}
}
}