Modified particle properties can be saved directly to the config file

This commit is contained in:
Joonas Rikkonen
2017-11-18 14:18:46 +02:00
parent 3a6508648f
commit 903686aed7
3 changed files with 40 additions and 3 deletions

View File

@@ -14,6 +14,7 @@ namespace Barotrauma.Particles
class ParticleManager
{
public readonly string ConfigFile;
public static int particleCount;
private const int MaxOutOfViewDist = 500;
@@ -27,6 +28,7 @@ namespace Barotrauma.Particles
public ParticleManager(string configFile, Camera cam)
{
ConfigFile = configFile;
this.cam = cam;
particles = new Particle[MaxParticles];

View File

@@ -83,13 +83,20 @@ namespace Barotrauma
rightPanel = new GUIFrame(new Rectangle(0, 0, 450, GameMain.GraphicsHeight), null, Alignment.Right, "GUIFrameRight", guiRoot);
rightPanel.Padding = new Vector4(10.0f, 20.0f, 0.0f, 20.0f);
var saveAllButton = new GUIButton(new Rectangle(leftPanel.Rect.Right + 20, 10, 150, 20), "Save all", "", guiRoot);
saveAllButton.OnClicked += (btn, obj) =>
{
SerializeAll();
return true;
};
var serializeToClipBoardButton = new GUIButton(new Rectangle(leftPanel.Rect.Right + 20, 10, 150, 20), "Copy to clipboard", "", guiRoot);
serializeToClipBoardButton.OnClicked += (btn, obj) =>
{
SerializeToClipboard(selectedPrefab);
return true;
};
emitter = new Emitter();
var emitterEditor = new SerializableEntityEditor(emitter, false, rightPanel, true);
@@ -142,6 +149,34 @@ namespace Barotrauma
}
}
private void SerializeAll()
{
XDocument doc = XMLExtensions.TryLoadXml(GameMain.ParticleManager.ConfigFile);
if (doc == null || doc.Root == null) return;
var prefabList = GameMain.ParticleManager.GetPrefabList();
foreach (ParticlePrefab prefab in prefabList)
{
foreach (XElement element in doc.Root.Elements())
{
if (element.Name.ToString().ToLowerInvariant() != prefab.Name.ToLowerInvariant()) continue;
SerializableProperty.SerializeProperties(prefab, element, true);
}
}
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.OmitXmlDeclaration = true;
settings.NewLineOnAttributes = true;
using (var writer = XmlWriter.Create(GameMain.ParticleManager.ConfigFile, settings))
{
doc.WriteTo(writer);
writer.Flush();
}
}
private void SerializeToClipboard(ParticlePrefab prefab)
{
if (prefab == null) return;

View File

@@ -443,8 +443,8 @@ namespace Barotrauma
break;
}
}
element.Add(new XAttribute(property.Name.ToLowerInvariant(), stringValue));
element.SetAttributeValue(property.Name.ToLowerInvariant(), stringValue);
}
}
}