-
Notifications
You must be signed in to change notification settings - Fork 0
/
TabDebug.cs
288 lines (225 loc) · 12.8 KB
/
TabDebug.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
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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
using System;
using System.Reflection;
using Digi.ParticleEditor.GameData;
using Digi.ParticleEditor.UIControls;
using Sandbox;
using Sandbox.Engine.Platform.VideoMode;
using Sandbox.Game.World;
using Sandbox.Graphics.GUI;
using VRage.Utils;
using VRageMath;
using VRageRender;
namespace Digi.ParticleEditor
{
public class EditorDebug
{
readonly EditorUI EditorUI;
VerticalControlsHost Host;
ParticleHandler SelectedParticle => EditorUI.SelectedParticle;
MyGuiControlLabel ParticleMulLabel;
public float? ParticleEmitterMultiplier => _particleEmitterMultiplier?.Invoke();
Func<float> _particleEmitterMultiplier;
public EditorDebug(EditorUI editorUI)
{
EditorUI = editorUI;
FindParticlesMultiplierProperty();
MySession.OnUnloaded += SessionUnloading;
}
public void Dispose()
{
MySession.OnUnloaded -= SessionUnloading;
}
void SessionUnloading()
{
MyRenderQualityEnum? quality = MySandboxGame.Config?.ShaderQuality;
if(quality != null && MyVideoSettingsManager.CurrentGraphicsSettings.PerformanceSettings.RenderSettings.ParticleQuality != quality.Value)
{
SetParticleQuality(quality.Value);
MyLog.Default.WriteLine($"ParticleEditor: Set particle quality back to {quality.Value}");
}
}
void FindParticlesMultiplierProperty()
{
Type type = typeof(MyDX11Render).Assembly.GetType("VRageRender.MyGPUEmitters");
PropertyInfo prop = type?.GetProperty("ParticleCountMultiplier", BindingFlags.Static | BindingFlags.Public);
if(prop != null)
{
MethodInfo[] methods = prop.GetAccessors(false);
_particleEmitterMultiplier = methods[0].CreateDelegate<Func<float>>(null);
}
}
void SetParticleQuality(MyRenderQualityEnum quality)
{
MyGraphicsSettings graphicsSettings = MyVideoSettingsManager.CurrentGraphicsSettings;
graphicsSettings.PerformanceSettings.RenderSettings.ParticleQuality = quality;
MyVideoSettingsManager.Apply(graphicsSettings);
// shader qualtiy in config is being set by voxel shading quality so this is no concern of being changed permanently.
// it does however persist for the duration of the game so needs to be reset on world unload.
// it also gets reset if graphics options menu is opened and OK is pressed.
}
public void RecreateControls(VerticalControlsHost host)
{
Host = host;
//Host.PositionAndFillWidth(Host.CreateLabel("Debug"));
MyGuiControlLabel shaderQualityLabel = Host.CreateLabel("Temporarily change global particle quality:");
shaderQualityLabel.SetToolTip("This particle quality setting is hidden and affected by game's Shader Quality." +
"\nThe below buttons' changes will only last until world unload and do not get saved to game config." +
"\nAlso gets reset if you go to graphics options UI and click OK.");
Host.PositionAndFillWidth(shaderQualityLabel);
string tooltipExtra = null;
MyGuiControlButton buttonLow = Host.CreateButton("Low", tooltipExtra, clicked: (button) =>
{
SetParticleQuality(MyRenderQualityEnum.LOW);
});
MyGuiControlButton buttonMed = Host.CreateButton("Medium", tooltipExtra, clicked: (button) =>
{
SetParticleQuality(MyRenderQualityEnum.NORMAL);
});
MyGuiControlButton buttonHigh = Host.CreateButton("High", tooltipExtra, clicked: (button) =>
{
SetParticleQuality(MyRenderQualityEnum.HIGH);
});
MyGuiControlButton buttonExtreme = Host.CreateButton("Extreme", tooltipExtra, clicked: (button) =>
{
SetParticleQuality(MyRenderQualityEnum.EXTREME);
});
Host.PositionControls(buttonLow, buttonMed, buttonHigh, buttonExtreme);
ParticleMulLabel = Host.CreateLabel("Particle emitter multiplier: (unknown)");
ParticleMulLabel.SetToolTip("This is what ultimately affects all particles' spawn-rate." +
"\nThis gets set by Particle Quality (buttons above) which is in turn set by game's Shader Quality in graphics options UI." +
"\n\nIf it shows up as '(unknown)' it means this plugin was not able to read it because SE code got changed." +
"\nYou can still try the buttons above and visually inspect if particles are being reduced.");
Host.PositionAndFillWidth(ParticleMulLabel);
Host.InsertSeparator();
Host.InsertCheckbox("Post-processing", "This is a shortcut for the post processing toggle from graphics options UI.\nNOTE: gets saved to game config, remember to undo it.",
MyVideoSettingsManager.CurrentGraphicsSettings.PostProcessingEnabled, (value) =>
{
MyGraphicsSettings graphicsSettings = MyVideoSettingsManager.CurrentGraphicsSettings;
graphicsSettings.PostProcessingEnabled = value;
MyVideoSettingsManager.Apply(graphicsSettings);
// the above setting gets read and written to config at unknown times... might as well make it official:
MySandboxGame.Config.PostProcessingEnabled = value;
MySandboxGame.Config.Save();
});
Host.InsertSeparator();
{
MyGuiControlLabel label = Host.CreateLabel("Simulate user multipliers");
label.SetToolTip("These do not get saved in the particle definition." +
"\nVarious things that spawn particles can choose to use multipliers, this is where you can simulate them.");
Host.PositionAndFillWidth(label);
}
void UserMultiplierSlider(string propName, Func<float> getter, Action<float> setter)
{
PropId propId = new PropId(PropType.UserMultiplier, propName);
PropertyData propInfo = VersionSpecificInfo.GetPropertyInfo(propId);
ValueInfo<float> valueRange = propInfo.ValueRangeNum;
float defaultValue = valueRange.Default ?? 1f;
float min = (valueRange.Min == 0 ? 0 : float.MinValue);
float max = float.MaxValue;
if(valueRange.LimitNumberBox)
{
min = valueRange.Min;
max = valueRange.Max;
}
MyGuiControlLabel label = Host.CreateLabel(propInfo.GetName());
UINumberBox box = Host.CreateNumberBox(propInfo.GetTooltip(),
getter.Invoke(), defaultValue: defaultValue, min: min, max: max, inputRound: 6, dragRound: 1,
changed: (value) =>
{
setter.Invoke(value);
SelectedParticle.UserMultipliers.ApplyToParticle();
});
Host.PositionControlsNoSize(box, label);
Host.MoveY(0.01f);
}
UserMultiplierSlider(nameof(SelectedParticle.SpawnedEffect.UserScale),
() => SelectedParticle.UserMultipliers.Scale,
(value) => SelectedParticle.UserMultipliers.Scale = value);
UserMultiplierSlider(nameof(SelectedParticle.SpawnedEffect.UserLifeMultiplier),
() => SelectedParticle.UserMultipliers.Life,
(value) => SelectedParticle.UserMultipliers.Life = value);
UserMultiplierSlider(nameof(SelectedParticle.SpawnedEffect.UserFadeMultiplier),
() => SelectedParticle.UserMultipliers.Fade,
(value) => SelectedParticle.UserMultipliers.Fade = value);
UserMultiplierSlider(nameof(SelectedParticle.SpawnedEffect.UserBirthMultiplier),
() => SelectedParticle.UserMultipliers.Birth,
(value) => SelectedParticle.UserMultipliers.Birth = value);
UserMultiplierSlider(nameof(SelectedParticle.SpawnedEffect.UserRadiusMultiplier),
() => SelectedParticle.UserMultipliers.Radius,
(value) => SelectedParticle.UserMultipliers.Radius = value);
UserMultiplierSlider(nameof(SelectedParticle.SpawnedEffect.UserVelocityMultiplier),
() => SelectedParticle.UserMultipliers.Velocity,
(value) => SelectedParticle.UserMultipliers.Velocity = value);
UserMultiplierSlider(nameof(SelectedParticle.SpawnedEffect.SoftParticleDistanceScaleMultiplier),
() => SelectedParticle.UserMultipliers.SoftParticle,
(value) => SelectedParticle.UserMultipliers.SoftParticle = value);
UserMultiplierSlider(nameof(SelectedParticle.SpawnedEffect.CameraSoftRadiusMultiplier),
() => SelectedParticle.UserMultipliers.CameraSoftRadius,
(value) => SelectedParticle.UserMultipliers.CameraSoftRadius = value);
UserMultiplierSlider(nameof(SelectedParticle.SpawnedEffect.UserColorIntensityMultiplier),
() => SelectedParticle.UserMultipliers.ColorIntensity,
(value) => SelectedParticle.UserMultipliers.ColorIntensity = value);
{
PropId propId = new PropId(PropType.UserMultiplier, nameof(SelectedParticle.SpawnedEffect.UserColorMultiplier));
PropertyData propInfo = VersionSpecificInfo.GetPropertyInfo(propId);
string name = propInfo.GetName();
string tooltip = propInfo.GetTooltip();
ValueInfo<Vector4> valueRange = propInfo.ValueRangeVector4;
Vector4 def = valueRange.Default ?? Vector4.One;
Vector4 min = (valueRange.Min == Vector4.Zero ? Vector4.Zero : new Vector4(float.MinValue));
Vector4 max = new Vector4(float.MaxValue);
if(valueRange.LimitNumberBox)
{
min = valueRange.Min;
max = valueRange.Max;
}
int dragRound = valueRange.Rounding;
int inputRound = valueRange.InputRounding;
Vector4 val = SelectedParticle.UserMultipliers.Color;
MyGuiControlLabel titleLabel = Host.CreateLabel(name);
titleLabel.SetToolTip(tooltip);
Host.PositionControlsNoSize(titleLabel);
MyGuiControlBase[] controls = new MyGuiControlBase[4 * 2];
for(int i = 0; i < 4; i++)
{
int dim = i; // required for reliable capture
MyGuiControlLabel dimLabel = Host.CreateLabel(EditorUI.Vector4AxisNames[dim]);
UINumberBox box = Host.CreateNumberBox(tooltip,
val.GetDim(dim), def.GetDim(dim),
min.GetDim(dim), max.GetDim(dim), inputRound, dragRound,
(value) =>
{
Vector4 vec = SelectedParticle.UserMultipliers.Color;
vec.SetDim(dim, value);
SelectedParticle.UserMultipliers.Color = vec;
SelectedParticle.UserMultipliers.ApplyToParticle();
});
float boxWidth = 0.085f - dimLabel.Size.X - Host.ControlSpacing;
box.Size = new Vector2(boxWidth, box.Size.Y);
controls[i * 2] = dimLabel;
controls[i * 2 + 1] = box;
}
Host.PositionControlsNoSize(controls);
Host.MoveY(0.01f); // HACK: box is taller than its actual size
}
Host.InsertSeparator();
Host.InsertCheckbox("Backup on changes",
$"When changed, it automatically saves up to 2 copies of the particle to '{Backup.BackupPath}\\*.sbc'." +
$"\nThis checkbox does not get saved in any config." +
$"\nIf game crashes, the plugin will backup the particle (unless plugin suspects particle caused it) regardless of this checkbox.",
EditorUI.Editor.Backup.Enable, (value) =>
{
EditorUI.Editor.Backup.Enable = value;
});
}
public void Update()
{
if(MySession.Static.GameplayFrameCounter % 10 == 0)
{
float? mul = ParticleEmitterMultiplier;
if(mul.HasValue)
ParticleMulLabel.Text = $"Particle emitter multiplier: {mul.Value:0.#####}";
}
}
}
}