1 using Microsoft.Xna.Framework.Graphics;
2 using Microsoft.Xna.Framework;
5 using System.Collections.Generic;
35 ParticlesPerSecond = 1f
41 private readonly
Camera cam;
45 private const string sizeRefFilePath =
"Content/size_reference.png";
46 private readonly Texture2D sizeReference;
47 private Vector2 sizeRefPosition = Vector2.Zero;
48 private readonly Vector2 sizeRefOrigin;
49 private bool sizeRefEnabled;
56 if (File.Exists(sizeRefFilePath))
58 sizeReference = TextureLoader.FromFile(sizeRefFilePath, compress:
false);
59 sizeRefOrigin =
new Vector2(sizeReference.Width / 2f, sizeReference.Height / 2f);
63 private void CreateUI()
68 style:
"GUIFrameLeft");
71 RelativeSpacing = 0.01f,
75 rightPanel =
new GUIFrame(
new RectTransform(
new Vector2(0.25f, 1.0f),
Frame.
RectTransform,
Anchor.TopRight) { MinSize = new Point(350, 0) },
76 style:
"GUIFrameRight");
77 var paddedRightPanel =
new GUILayoutGroup(
new RectTransform(
new Vector2(0.95f, 0.95f), rightPanel.
RectTransform,
Anchor.Center) { RelativeOffset = new Vector2(0.02f, 0.0f) })
79 RelativeSpacing = 0.01f,
83 var saveAllButton =
new GUIButton(
new RectTransform(
new Vector2(1.0f, 0.03f), paddedRightPanel.RectTransform),
84 TextManager.Get(
"editor.saveall"))
86 OnClicked = (btn, obj) =>
93 new GUIButton(
new RectTransform(
new Vector2(1.0f, 0.03f), paddedRightPanel.RectTransform),
94 TextManager.Get(
"ParticleEditor.CopyPrefabToClipboard"))
96 OnClicked = (btn, obj) =>
98 SerializeToClipboard(selectedPrefab);
103 new GUIButton(
new RectTransform(
new Vector2(1.0f, 0.03f), paddedRightPanel.RectTransform),
104 TextManager.Get(
"ParticleEditor.CopyEmitterToClipboard"))
106 OnClicked = (btn, obj) =>
108 SerializeEmitterToClipboard();
113 var emitterListBox =
new GUIListBox(
new RectTransform(
new Vector2(1.0f, 0.25f), paddedRightPanel.RectTransform));
114 new SerializableEntityEditor(emitterListBox.Content.RectTransform, emitterProperties,
false,
true, elementHeight: 20, titleFont: GUIStyle.SubHeadingFont);
116 var listBox =
new GUIListBox(
new RectTransform(
new Vector2(1.0f, 0.6f), paddedRightPanel.RectTransform));
118 var filterArea =
new GUILayoutGroup(
new RectTransform(
new Vector2(1.0f, 0.03f), paddedLeftPanel.RectTransform) { MinSize = new Point(0, 20) }, isHorizontal:
true)
121 UserData =
"filterarea"
124 filterLabel =
new GUITextBlock(
new RectTransform(Vector2.One, filterArea.RectTransform), TextManager.Get(
"serverlog.filter"), font: GUIStyle.Font) { IgnoreLayoutGroups =
true };
125 filterBox =
new GUITextBox(
new RectTransform(
new Vector2(0.8f, 1.0f), filterArea.RectTransform), font: GUIStyle.Font);
126 filterBox.
OnTextChanged += (textBox, text) => { FilterEmitters(text);
return true; };
127 new GUIButton(
new RectTransform(
new Vector2(0.05f, 1.0f), filterArea.RectTransform, scaleBasis:
ScaleBasis.BothHeight), style:
"GUICancelButton")
129 OnClicked = (btn, userdata) => { FilterEmitters(
""); filterBox.
Text =
""; filterBox.
Flash(Color.White);
return true; }
132 prefabList =
new GUIListBox(
new RectTransform(
new Vector2(1.0f, 0.8f), paddedLeftPanel.RectTransform))
134 PlaySoundOnSelect =
true,
136 prefabList.
OnSelected += (GUIComponent component,
object obj) =>
138 cam.Position = Vector2.Zero;
142 listBox.ClearChildren();
143 new SerializableEntityEditor(listBox.Content.RectTransform, selectedPrefab,
false,
true, elementHeight: 20, titleFont: GUIStyle.SubHeadingFont);
149 if (GameMain.ParticleManager !=
null) { RefreshPrefabList(); }
165 private void RefreshPrefabList()
175 Padding = Vector4.Zero,
176 UserData = particlePrefab
181 private void FilterEmitters(
string text)
183 if (
string.IsNullOrWhiteSpace(text))
190 text = text.ToLower();
194 if (!(child is GUITextBlock textBlock)) {
continue; }
195 textBlock.Visible = textBlock.Text.ToLower().Contains(text);
199 private void SerializeAll()
202 foreach (var configFile
in ContentPackageManager.AllPackages.SelectMany(p => p.GetFiles<ParticlesFile>()))
204 XDocument doc = XMLExtensions.TryLoadXml(configFile.Path);
205 if (doc ==
null) {
continue; }
210 foreach (XElement element
in doc.Root.Elements())
212 if (!element.Name.ToString().Equals(prefab.
Name, StringComparison.OrdinalIgnoreCase)) {
continue; }
213 SerializableProperty.SerializeProperties(prefab, element,
true);
217 System.Xml.XmlWriterSettings settings =
new System.Xml.XmlWriterSettings
220 OmitXmlDeclaration =
true,
221 NewLineOnAttributes =
true
233 private void SerializeEmitterToClipboard()
236 if (selectedPrefab is { } prefab)
238 element.Add(
new XAttribute(
"particle", prefab.
Identifier));
241 SerializableProperty.SerializeProperties(emitterProperties, element, saveIfDefault:
false, ignoreEditable:
true);
243 StringBuilder sb =
new StringBuilder();
245 System.Xml.XmlWriterSettings settings =
new System.Xml.XmlWriterSettings
247 OmitXmlDeclaration =
true
250 using (var writer = System.Xml.XmlWriter.Create(sb, settings))
252 element.WriteTo(writer);
256 Clipboard.SetText(sb.ToString());
261 if (prefab ==
null) {
return; }
263 System.Xml.XmlWriterSettings settings =
new System.Xml.XmlWriterSettings
266 OmitXmlDeclaration =
true,
267 NewLineOnAttributes =
true
270 XElement originalElement =
null;
271 foreach (var configFile
in ContentPackageManager.AllPackages.SelectMany(p => p.GetFiles<ParticlesFile>()))
273 XDocument doc = XMLExtensions.TryLoadXml(configFile.Path);
274 if (doc ==
null) {
continue; }
279 foreach (var subElement
in doc.Root.Elements())
281 if (!subElement.Name.ToString().Equals(prefab.
Name, StringComparison.OrdinalIgnoreCase)) {
continue; }
282 SerializableProperty.SerializeProperties(prefab, subElement,
true);
283 originalElement = subElement;
289 if (originalElement ==
null)
291 originalElement =
new XElement(prefab.
Name);
292 SerializableProperty.SerializeProperties(prefab, originalElement,
true);
295 StringBuilder sb =
new StringBuilder();
296 using (var writer = System.Xml.XmlWriter.Create(sb, settings))
298 originalElement.WriteTo(writer);
302 Clipboard.SetText(sb.ToString());
305 public override void Update(
double deltaTime)
307 cam.MoveCamera((
float)deltaTime, allowMove:
true, allowZoom: GUI.MouseOn ==
null);
319 if (selectedPrefab !=
null && emitter !=
null)
321 emitter.
Emit((
float) deltaTime, Vector2.Zero);
327 private void CreateContextMenu()
329 GUIContextMenu.CreateContextMenu
332 new ContextMenuOption(
"editor.togglereferencecharacter",
true, delegate { sizeRefEnabled = !sizeRefEnabled; })
336 public override void Draw(
double deltaTime, GraphicsDevice graphics, SpriteBatch spriteBatch)
338 cam.UpdateTransform();
343 spriteBatch.Begin(SpriteSortMode.Deferred,
344 BlendState.NonPremultiplied,
345 null,
null,
null,
null,
355 spriteBatch.Begin(SpriteSortMode.Deferred,
357 null,
null,
null,
null,
365 if (sizeRefEnabled && !(sizeReference is
null))
367 spriteBatch.Begin(SpriteSortMode.Deferred,
368 BlendState.NonPremultiplied,
369 null,
null,
null,
null,
372 Vector2 pos = sizeRefPosition;
374 spriteBatch.Draw(sizeReference, pos,
null, Color.White, 0f, sizeRefOrigin,
new Vector2(0.4f), SpriteEffects.None, 0f);
383 GUI.Draw(
Cam, spriteBatch);
static Color BackgroundColor
void CreateBackgroundColorPicker()
virtual void ClearChildren()
RectTransform RectTransform
IEnumerable< GUIComponent > Children
OnSelectedHandler OnSelected
Triggers when some element is clicked on the listbox. Note that SelectedData is not set yet when this...
GUIFrame Content
A frame that contains the contents of the listbox. The frame itself is not rendered.
override void ClearChildren()
OnTextChangedHandler OnTextChanged
Don't set the Text property on delegates that register to this event, because modifying the Text will...
override void Flash(Color? color=null, float flashDuration=1.5f, bool useRectangleFlash=false, bool useCircularFlash=false, Vector2? flashRectOffset=null)
static RasterizerState ScissorTestEnable
Action ResolutionChanged
NOTE: Use very carefully. You need to ensure that you ALWAYS unsubscribe from this when you no longer...
static GameScreen GameScreen
static ParticleManager ParticleManager
static XmlWriter Create(string path, System.Xml.XmlWriterSettings settings)
override void DeselectEditorSpecific()
override void Update(double deltaTime)
override void Draw(double deltaTime, GraphicsDevice graphics, SpriteBatch spriteBatch)
void Emit(float deltaTime, Vector2 position, Hull? hullGuess=null, float angle=0.0f, float particleRotation=0.0f, float velocityMultiplier=1.0f, float sizeMultiplier=1.0f, float amountMultiplier=1.0f, Color? colorMultiplier=null, ParticlePrefab? overrideParticle=null, bool mirrorAngle=false, Tuple< Vector2, Vector2 >? tracerPoints=null)
void Draw(SpriteBatch spriteBatch, bool inWater, bool? inSub, ParticleBlendState blendState, bool? background=false)
static List< ParticlePrefab > GetPrefabList()
void Update(float deltaTime)
readonly Identifier Identifier