v0.14.6.0

This commit is contained in:
Joonas Rikkonen
2021-06-17 17:54:52 +03:00
parent 3f324b14e8
commit c27e2ea5ab
348 changed files with 13156 additions and 4266 deletions
@@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.Xml.Linq;
using System.Text;
using Barotrauma.Extensions;
using FarseerPhysics;
#if DEBUG
using System.IO;
using System.Xml;
@@ -15,57 +16,8 @@ using Barotrauma.IO;
namespace Barotrauma
{
class ParticleEditorScreen : Screen
class ParticleEditorScreen : EditorScreen
{
class Emitter : ISerializableEntity
{
public float EmitTimer;
public float BurstTimer;
[Editable(), Serialize("0.0,360.0", false)]
public Vector2 AngleRange { get; private set; }
[Editable(), Serialize("0.0,0.0", false)]
public Vector2 VelocityRange { get; private set; }
[Editable(), Serialize("1.0,1.0", false)]
public Vector2 ScaleRange { get; private set; }
[Editable(), Serialize(0, false)]
public int ParticleBurstAmount { get; private set; }
[Editable(), Serialize(1.0f, false)]
public float ParticleBurstInterval { get; private set; }
[Editable(), Serialize(1.0f, false)]
public float ParticlesPerSecond { get; private set; }
public string Name
{
get
{
return TextManager.Get("particleeditor.emitter");
}
}
public Dictionary<string, SerializableProperty> SerializableProperties
{
get;
private set;
}
public Emitter()
{
ScaleRange = Vector2.One;
AngleRange = new Vector2(0.0f, 360.0f);
ParticleBurstAmount = 1;
ParticleBurstInterval = 1.0f;
SerializableProperties = SerializableProperty.GetProperties(this);
}
}
private GUIComponent rightPanel, leftPanel;
private GUIListBox prefabList;
private GUITextBox filterBox;
@@ -73,23 +25,38 @@ namespace Barotrauma
private ParticlePrefab selectedPrefab;
private Emitter emitter;
private readonly ParticleEmitterProperties emitterProperties = new ParticleEmitterProperties(null)
{
ScaleMax = 1f,
ScaleMin = 1f,
AngleMax = 360f,
AngleMin = 0,
ParticlesPerSecond = 1f
};
private ParticleEmitterPrefab emitterPrefab;
private ParticleEmitter emitter;
private readonly Camera cam;
public override Camera Cam
{
get
{
return cam;
}
}
public override Camera Cam => cam;
private const string sizeRefFilePath = "Content/size_reference.png";
private readonly Texture2D sizeReference;
private Vector2 sizeRefPosition = Vector2.Zero;
private readonly Vector2 sizeRefOrigin;
private bool sizeRefEnabled;
public ParticleEditorScreen()
{
cam = new Camera();
GameMain.Instance.ResolutionChanged += CreateUI;
CreateUI();
if (File.Exists(sizeRefFilePath))
{
sizeReference = TextureLoader.FromFile(sizeRefFilePath, compress: false);
sizeRefOrigin = new Vector2(sizeReference.Width / 2f, sizeReference.Height / 2f);
}
}
private void CreateUI()
@@ -122,8 +89,8 @@ namespace Barotrauma
}
};
var serializeToClipBoardButton = new GUIButton(new RectTransform(new Vector2(1.0f, 0.03f), paddedRightPanel.RectTransform),
TextManager.Get("editor.copytoclipboard"))
new GUIButton(new RectTransform(new Vector2(1.0f, 0.03f), paddedRightPanel.RectTransform),
TextManager.Get("ParticleEditor.CopyPrefabToClipboard"))
{
OnClicked = (btn, obj) =>
{
@@ -132,11 +99,18 @@ namespace Barotrauma
}
};
emitter = new Emitter();
var emitterEditorContainer = new GUIFrame(new RectTransform(new Vector2(1.0f, 0.25f), paddedRightPanel.RectTransform), style: null);
var emitterEditor = new SerializableEntityEditor(emitterEditorContainer.RectTransform, emitter, false, true, elementHeight: 20, titleFont: GUI.SubHeadingFont);
emitterEditor.RectTransform.RelativeSize = Vector2.One;
emitterEditorContainer.RectTransform.Resize(new Point(emitterEditorContainer.RectTransform.NonScaledSize.X, emitterEditor.ContentHeight), false);
new GUIButton(new RectTransform(new Vector2(1.0f, 0.03f), paddedRightPanel.RectTransform),
TextManager.Get("ParticleEditor.CopyEmitterToClipboard"))
{
OnClicked = (btn, obj) =>
{
SerializeEmitterToClipboard();
return true;
}
};
var emitterListBox = new GUIListBox(new RectTransform(new Vector2(1.0f, 0.25f), paddedRightPanel.RectTransform));
new SerializableEntityEditor(emitterListBox.Content.RectTransform, emitterProperties, false, true, elementHeight: 20, titleFont: GUI.SubHeadingFont);
var listBox = new GUIListBox(new RectTransform(new Vector2(1.0f, 0.6f), paddedRightPanel.RectTransform));
@@ -157,7 +131,10 @@ namespace Barotrauma
prefabList = new GUIListBox(new RectTransform(new Vector2(1.0f, 0.8f), paddedLeftPanel.RectTransform));
prefabList.OnSelected += (GUIComponent component, object obj) =>
{
cam.Position = Vector2.Zero;
selectedPrefab = obj as ParticlePrefab;
emitterPrefab = new ParticleEmitterPrefab(selectedPrefab, emitterProperties);
emitter = new ParticleEmitter(emitterPrefab);
listBox.ClearChildren();
new SerializableEntityEditor(listBox.Content.RectTransform, selectedPrefab, false, true, elementHeight: 20, titleFont: GUI.SubHeadingFont);
//listBox.Content.RectTransform.NonScaledSize = particlePrefabEditor.RectTransform.NonScaledSize;
@@ -198,19 +175,6 @@ namespace Barotrauma
}
}
private void Emit(Vector2 position)
{
float angle = MathHelper.ToRadians(Rand.Range(emitter.AngleRange.X, emitter.AngleRange.Y));
Vector2 velocity = new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle)) * Rand.Range(emitter.VelocityRange.X, emitter.VelocityRange.Y);
var particle = GameMain.ParticleManager.CreateParticle(selectedPrefab, position, velocity, 0.0f);
if (particle != null)
{
particle.Size *= Rand.Range(emitter.ScaleRange.X, emitter.ScaleRange.Y);
}
}
private void FilterEmitters(string text)
{
if (string.IsNullOrWhiteSpace(text))
@@ -263,9 +227,34 @@ namespace Barotrauma
Barotrauma.IO.Validation.SkipValidationInDebugBuilds = false;
}
private void SerializeEmitterToClipboard()
{
XElement element = new XElement(nameof(ParticleEmitter));
if (selectedPrefab is { } prefab)
{
element.Add(new XAttribute("particle", prefab.Identifier));
}
SerializableProperty.SerializeProperties(emitterProperties, element, saveIfDefault: false, ignoreEditable: true);
StringBuilder sb = new StringBuilder();
System.Xml.XmlWriterSettings settings = new System.Xml.XmlWriterSettings
{
OmitXmlDeclaration = true
};
using (var writer = System.Xml.XmlWriter.Create(sb, settings))
{
element.WriteTo(writer);
writer.Flush();
}
Clipboard.SetText(sb.ToString());
}
private void SerializeToClipboard(ParticlePrefab prefab)
{
#if WINDOWS
if (prefab == null) { return; }
System.Xml.XmlWriterSettings settings = new System.Xml.XmlWriterSettings
@@ -308,43 +297,39 @@ namespace Barotrauma
}
Clipboard.SetText(sb.ToString());
#endif
}
public override void Update(double deltaTime)
{
cam.MoveCamera((float)deltaTime, allowMove: true, allowZoom: GUI.MouseOn == null);
if (selectedPrefab != null)
if (GUI.MouseOn is null && PlayerInput.PrimaryMouseButtonHeld())
{
emitter.EmitTimer += (float)deltaTime;
emitter.BurstTimer += (float)deltaTime;
sizeRefPosition = cam.ScreenToWorld(PlayerInput.MousePosition);
}
if (PlayerInput.SecondaryMouseButtonClicked())
{
CreateContextMenu();
}
if (emitter.ParticlesPerSecond > 0)
{
float emitInterval = 1.0f / emitter.ParticlesPerSecond;
while (emitter.EmitTimer > emitInterval)
{
Emit(Vector2.Zero);
emitter.EmitTimer -= emitInterval;
}
}
if (emitter.BurstTimer > emitter.ParticleBurstInterval)
{
for (int i = 0; i < emitter.ParticleBurstAmount; i++)
{
Emit(Vector2.Zero);
}
emitter.BurstTimer = 0.0f;
}
if (selectedPrefab != null && emitter != null)
{
emitter.Emit((float) deltaTime, Vector2.Zero);
}
GameMain.ParticleManager.Update((float)deltaTime);
}
private void CreateContextMenu()
{
GUIContextMenu.CreateContextMenu
(
new ContextMenuOption("subeditor.editbackgroundcolor", true, CreateBackgroundColorPicker),
new ContextMenuOption("editor.togglereferencecharacter", true, delegate { sizeRefEnabled = !sizeRefEnabled; })
);
}
public override void Draw(double deltaTime, GraphicsDevice graphics, SpriteBatch spriteBatch)
{
cam.UpdateTransform();
@@ -357,7 +342,7 @@ namespace Barotrauma
null, null, null, null,
cam.Transform);
graphics.Clear(new Color(0.051f, 0.149f, 0.271f, 1.0f));
graphics.Clear(BackgroundColor);
GameMain.ParticleManager.Draw(spriteBatch, false, false, ParticleBlendState.AlphaBlend);
GameMain.ParticleManager.Draw(spriteBatch, true, false, ParticleBlendState.AlphaBlend);
@@ -374,6 +359,20 @@ namespace Barotrauma
spriteBatch.End();
if (sizeRefEnabled && !(sizeReference is null))
{
spriteBatch.Begin(SpriteSortMode.Deferred,
BlendState.NonPremultiplied,
null, null, null, null,
cam.Transform);
Vector2 pos = sizeRefPosition;
pos.Y = -pos.Y;
spriteBatch.Draw(sizeReference, pos, null, Color.White, 0f, sizeRefOrigin, new Vector2(0.4f), SpriteEffects.None, 0f);
spriteBatch.End();
}
//-------------------------------------------------------
spriteBatch.Begin(SpriteSortMode.Deferred, null, GUI.SamplerState, null, GameMain.ScissorTestEnable);