/*
* ParticleEditor.cs
* Authors: Brian Murphy, Adam Nabinger
* Copyright (c) 2007-2008 Cornell University
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using TACParticleEngine.Emitters;
using TACParticleEngine.Particles;
namespace TACParticleEditor
{
///
/// The form used in loading/saving created/modified particle effect files
///
public partial class ParticleEditor : Form
{
#region Fields
// Reference to the current particle game screen
private readonly ParticleGame Game;
// The particle effect in which all the emitters are part of
private ParticleEngine mParticleEngine;
// The list of all the emitters within the particle effect
private List mEmitterList;
// The current emitter that is being modified in the particle editor
private Emitter mEmitter;
#endregion
#region Properties
///
/// Gets the particle effect that is used in the particle editor
///
public ParticleEngine ParticleEngine { get { return mParticleEngine; } }
#endregion
#region Delegates
///
/// Used for invoking updates in the emitter list when a new particle effect is loaded
///
public delegate void UpdateEmitters();
#endregion
#region Creation
///
/// Constructor
///
/// Reference to the current particle game screen
public ParticleEditor(ParticleGame mainGame)
{
Game = mainGame;
mEmitterList = new List();
mParticleEngine = new ParticleEngine(mEmitterList);
InitializeComponent();
}
#endregion
#region Initialization
///
/// Preforms the needed initializations upon creation of the particle editor form
///
/// All of the parameter arguments associated with the event
protected override void OnLoad(EventArgs e)
{
System.Reflection.Assembly assembly = System.Reflection.Assembly.LoadFrom("TACParticleEngine.dll");
List emitterTypes = new List();
foreach (Type type in assembly.GetTypes())
{
if (type.IsSubclassOf(typeof(TACParticleEngine.Emitters.Emitter)))
{
emitterTypes.Add(type);
}
}
emitterType.Items.AddRange(emitterTypes.ToArray());
base.OnLoad(e);
}
#endregion
#region Status Updates
///
/// Sets all the information of the particle editor to that of the newly loaded particle effect
///
/// The newly loaded particle effect
public void ProcessOpenFile(ParticleEngine pEngine)
{
mParticleEngine = pEngine;
mEmitterList.Clear();
mEmitterList.AddRange(pEngine.Emitters);
Invoke(new UpdateEmitters(UpdateEmitterList));
}
///
/// Updates the emitter list to include all of the emmitters of the newly loaded particle effect
///
private void UpdateEmitterList()
{
emitterList.Items.Clear();
emitterList.Items.AddRange(mEmitterList.ToArray());
}
#endregion
#region Events
///
/// Processes clicking of the open button
///
/// The sender of the event
/// All of the parameter arguments associated with the event
private void OpenButton_Click(object sender, EventArgs e)
{
Game.DoOpenFile = true;
}
///
/// Processes the clicking of the save button
///
/// The sender of the event
/// All of the parameter arguments associated with the event
private void saveButton_Click(object sender, EventArgs e)
{
if (emitterList.Items.Count > 0)
{
Game.DoSaveFile = true;
}
}
///
/// Processes the clicking of the add button
///
/// The sender of the event
/// All of the parameter arguments associated with the event
private void addButton_Click(object sender, EventArgs e)
{
if (emitterType.SelectedItem != null)
{
mEmitter = (Emitter)((Type)emitterType.SelectedItem).GetConstructor(new Type[0]).Invoke(new object[0]);
mEmitter.IsActive = true;
mEmitterList.Add(mEmitter);
emitterInfoGrid.SelectedObject = mEmitter;
mParticleEngine = new ParticleEngine(mEmitterList);
Game.AddEffect(mParticleEngine);
emitterList.Items.Clear();
emitterList.Items.AddRange(mEmitterList.ToArray());
}
}
///
/// Processes the clicking of the remove button
///
/// The sender of the event
/// All of the parameter arguments associated with the event
private void removeButton_Click(object sender, EventArgs e)
{
if (emitterList.SelectedIndex != -1)
{
mEmitter.IsActive = false;
mEmitter = null;
emitterInfoGrid.SelectedObject = null;
mEmitterList.RemoveAt(emitterList.SelectedIndex);
mParticleEngine = new ParticleEngine(mEmitterList);
Game.AddEffect(mParticleEngine);
emitterList.Items.Clear();
emitterList.Items.AddRange(mEmitterList.ToArray());
}
}
///
/// Processes a change in the selected index of the emitter list
///
/// The sender of the event
/// All of the parameter arguments associated with the event
private void emitterList_SelectedIndexChanged(object sender, EventArgs e)
{
if (emitterList.SelectedIndex != -1)
{
mEmitter = mEmitterList[emitterList.SelectedIndex];
emitterInfoGrid.SelectedObject = mEmitter;
}
}
#endregion
}
}