Skip to content

Commit

Permalink
Unversioned media pack. YOU MUST NOW BUILD THIS WHEN YOU SVN UPDATE.
Browse files Browse the repository at this point in the history
Added save/load functionality to particle editor.
Particle systems are now built into the resource pack.
  • Loading branch information
spoogemonster committed Sep 18, 2013
1 parent 00893f3 commit c8cea85
Show file tree
Hide file tree
Showing 7 changed files with 217 additions and 7 deletions.
2 changes: 1 addition & 1 deletion ClientServices/Resources/ResourceManagerZip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class ResourceManager : IResourceManager
private readonly Dictionary<string, Image> _images = new Dictionary<string, Image>();
private readonly Dictionary<string, FXShader> _shaders = new Dictionary<string, FXShader>();
private readonly Dictionary<string, SpriteInfo> _spriteInfos = new Dictionary<string, SpriteInfo>();
private readonly Dictionary<string, Sprite> _sprites = new Dictionary<string, Sprite>();
private readonly Dictionary<string, Sprite> _sprites = new Dictionary<string, Sprite>();
private readonly List<string> supportedImageExtensions = new List<string> {".png"};

public ResourceManager(IConfigurationManager configurationManager)
Expand Down
66 changes: 62 additions & 4 deletions ParticleEditor/ParticleEditorMainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions ParticleEditor/ParticleEditorMainForm.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.IO;
using System.Windows.Forms;
using System.Xml.Serialization;
using ClientServices.Configuration;
using ClientServices.Resources;
using GorgonLibrary;
Expand All @@ -18,6 +20,16 @@ public ParticleEditorMainForm()
particleConfigurator.MainForm = this;
particleDisplay.MainForm = this;
particleDisplay.InitDisplay();
InitializeFileDialog();
}

private void InitializeFileDialog()
{
var currentDir = Directory.GetCurrentDirectory() + @"..\..\..\..\Media\ParticleSystems";
saveFileDialog1.InitialDirectory = Path.GetFullPath(currentDir);
saveFileDialog1.RestoreDirectory = true;
openFileDialog1.InitialDirectory = Path.GetFullPath(currentDir);
openFileDialog1.RestoreDirectory = true;
}

public void InitializeResourceManager()
Expand Down Expand Up @@ -52,5 +64,29 @@ private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
Gorgon.Terminate();
}
}

private void saveToolStripMenuItem_Click(object sender, EventArgs e)
{
if(saveFileDialog1.ShowDialog(this) == DialogResult.OK)
{
var particleSaver = new XmlSerializer(typeof(ParticleSettings));
StreamWriter particleWriter = File.CreateText(saveFileDialog1.FileName);
particleSaver.Serialize(particleWriter, particleConfigurator.ParticleSettings);
particleWriter.Flush();
particleWriter.Close();
}
}

private void toolStripMenuItem2_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog(this) == DialogResult.OK)
{
var particleLoader = new XmlSerializer(typeof(ParticleSettings));
StreamReader particleReader = File.OpenText(openFileDialog1.FileName);
var particleSettings = (ParticleSettings)particleLoader.Deserialize(particleReader);
particleReader.Close();
particleConfigurator.ParticleSettings.Load(particleSettings);
}
}
}
}
9 changes: 9 additions & 0 deletions ParticleEditor/ParticleEditorMainForm.resx
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,13 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="saveFileDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>132, 17</value>
</metadata>
<metadata name="openFileDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>268, 17</value>
</metadata>
</root>
98 changes: 97 additions & 1 deletion ParticleEditor/ParticleSettings.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
using System.ComponentModel;
using System;
using System.ComponentModel;
using System.Drawing;
using System.Xml.Serialization;
using SS13_Shared.Utility;

namespace ParticleEditor
{
[Serializable]
public class ParticleSettings : INotifyPropertyChanged
{
private PointF _emitterPosition = new PointF(0,0);
Expand Down Expand Up @@ -39,6 +43,36 @@ public ParticleSettings()
{
}

public void Load(ParticleSettings loadFrom)
{
Acceleration = loadFrom.Acceleration;
AccelerationVariance = loadFrom.AccelerationVariance;
ColorRange = loadFrom.ColorRange;
ColorVariance = loadFrom.ColorVariance;
EmissionOffset = loadFrom.EmissionOffset;
EmissionRadiusRange = loadFrom.EmissionRadiusRange;
EmitRate = loadFrom.EmitRate;
EmitterPosition = loadFrom.EmitterPosition;
Lifetime = loadFrom.Lifetime;
LifetimeVariance = loadFrom.LifetimeVariance;
MaximumParticleCount = loadFrom.MaximumParticleCount;
RadialAcceleration = loadFrom.RadialAcceleration;
RadialAccelerationVariance = loadFrom.RadialAccelerationVariance;
RadialVelocity = loadFrom.RadialVelocity;
RadialVelocityVariance = loadFrom.RadialVelocityVariance;
SizeRange = loadFrom.SizeRange;
SizeVariance = loadFrom.SizeVariance;
SpinVelocity = loadFrom.SpinVelocity;
SpinVelocityVariance = loadFrom.SpinVelocityVariance;
Sprite = loadFrom.Sprite;
TangentialAcceleration = loadFrom.TangentialAcceleration;
TangentialAccelerationVariance = loadFrom.TangentialAccelerationVariance;
TangentialVelocity = loadFrom.TangentialVelocity;
TangentialVelocityVariance = loadFrom.TangentialVelocityVariance;
Velocity = loadFrom.Velocity;
VelocityVariance = loadFrom.VelocityVariance;
}

/// <summary>
/// Sprite
/// This is the selected sprite to display.
Expand Down Expand Up @@ -376,6 +410,7 @@ public float SizeVariance
}
}

[XmlIgnore]
public SS13_Shared.Utility.Range<Color> ColorRange
{
get { return _colorRange; }
Expand All @@ -386,6 +421,13 @@ public SS13_Shared.Utility.Range<Color> ColorRange
}
}

[XmlElement(ElementName = "ColorRange")]
public SerializableColorRange ColorRangeXml
{
get { return new SerializableColorRange(ColorRange); }
set { ColorRange = value.ToRange(); }
}

/// <summary>
/// This controls how much particle color will vary between particles
/// </summary>
Expand All @@ -408,4 +450,58 @@ protected void OnPropertyChanged(string property)

public event PropertyChangedEventHandler PropertyChanged;
}

public class SerializableColor
{
public int A { get; set; }
public int R { get; set; }
public int G { get; set; }
public int B { get; set; }

public SerializableColor()
{

}

public SerializableColor(Color c)
{
A = c.A;
R = c.R;
G = c.G;
B = c.B;
}

public Color ToColor()
{
return Color.FromArgb(A, R, G, B);
}
}

public class SerializableColorRange
{
public SerializableColor Start { get; set; }
public SerializableColor End { get; set; }

public SerializableColorRange()
{

}

public SerializableColorRange(Color start, Color end)
{
Start = new SerializableColor(start);
End = new SerializableColor(end);
}

public SerializableColorRange(Range<Color> colorRange )
{
Start = new SerializableColor(colorRange.Start);
End = new SerializableColor(colorRange.End);
}

public Range<Color> ToRange()
{
return new Range<Color>(Start.ToColor(), End.ToColor());
}
}
}
5 changes: 5 additions & 0 deletions ParticleEditor/config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>

<Configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<ResourcePack>..\..\..\Media\ResourcePack.zip</ResourcePack>
</Configuration>
8 changes: 7 additions & 1 deletion SS3D_shared/Utility/Range.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ namespace SS13_Shared.Utility
/// Value type to indicate a range of values.
/// </summary>
/// <typeparam name="T">Type of data for the range.</typeparam>
[TypeConverter(typeof(RangeTypeConverter))]
[TypeConverter(typeof(RangeTypeConverter)),
Serializable]
public class Range<T>
{
/// <summary>
Expand All @@ -34,6 +35,11 @@ public Range(T start, T end)
Start = start;
End = end;
}

public Range()
{

}
}


Expand Down

0 comments on commit c8cea85

Please sign in to comment.