/// <summary> /// Called when the add modifier button is clicked. /// </summary> /// <param name="sender">Object that caused this event to be triggered.</param> /// <param name="e">Arguments explaining why this event occured.</param> private void addModButton_Click(object sender, EventArgs e) { if (modifierTypeComboBox.SelectedIndex < 0 || (!(typeListBox.SelectedItem is ParticleTypeItem) && !(typeListBox.SelectedItem is ParticleModifierItem))) { MessageBox.Show("You must select a modifier type and a particle type.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } ParticleModifier modifier = null; switch (modifierTypeComboBox.SelectedItem.ToString().ToLower()) { case "acceleration": modifier = new ParticleAccelerationModifier(); break; case "scale": modifier = new ParticleScaleModifier(); break; case "rotation": modifier = new ParticleRotationModifier(); break; case "color": modifier = new ParticleColorModifier(); break; case "render state": modifier = new ParticleRenderStateModifier(); break; case "animation": modifier = new ParticleAnimationModifier(); break; } if (typeListBox.SelectedItem is ParticleTypeItem) { ((ParticleTypeItem)typeListBox.SelectedItem).Type.RegisterParticleModifier(modifier); } else { ((ParticleModifierItem)typeListBox.SelectedItem).Type.RegisterParticleModifier(modifier); } SyncronizeTypes(); }
public void ModifyAllParticles(ParticleModifier modifier) { for (int i = 0; i < GetParticleCount(); i++) { var particleState = GetParticle(i); modifier(ref particleState); SetParticle(i, particleState); } }
void WriteParticleModifierProperties(ParticleModifier node) { WriteNodeProperties(node); WriteProperty("TexturePath", node.Texture, null); WriteProperty("FirstFrame", node.FirstFrame, 1); WriteProperty("LastFrame", node.LastFrame, 1); WriteProperty("LoopedAnimation", node.LoopedAnimation, true); WriteProperty("AnimationFPS", node.AnimationFps, 20f); float aspectRatio; float zoom; ParticleEmitter.DecomposeScale(node.Size / (Vector2)node.Texture.ImageSize * node.Scale, out aspectRatio, out zoom); WriteProperty("Scale", zoom, 1f); WriteProperty("AspectRatio", aspectRatio, 1f); WriteProperty("Velocity", node.Velocity, 1f); WriteProperty("WindAmount", node.WindAmount, 1f); WriteProperty("GravityAmount", node.GravityAmount, 1f); WriteProperty("MagnetAmount", node.MagnetAmount, 1f); WriteProperty("Spin", node.Spin, 1f); WriteProperty("AngularVelocity", node.AngularVelocity, 1f); WriteProperty("Color", node.Color, Color4.White); }
/// <summary> /// Invoked when a new instance of this class is created. /// </summary> /// <param name="type">Particle type this class is associated with.</param> /// <param name="index">Index of this item.</param> /// <param name="modifier">Particle modifier this class is associated with.</param> public ParticleModifierItem(ParticleType type, ParticleModifier modifier, int index) { _index = index; _type = type; _modifier = modifier; }
protected void ParseParticleTemplateProperty(Node node, string name) { ParticleModifier pm = (ParticleModifier)node; switch (name) { case "TexturePath": pm.Texture = new SerializableTexture(lexer.ParsePath()); try { var path = Path.ChangeExtension(pm.Texture.SerializationPath, "png"); using (var s = isTangerine ? AssetBundle.Current.OpenFile(Serialization.ExpandPath(path)) : System.IO.File.OpenRead(path)) { using (var b = new Bitmap(s)) { pm.Size = new Vector2(b.Width, b.Height); } } } catch (System.Exception e) { Console.WriteLine($"Warning: can't extract size for particle modifier from {pm.Texture.SerializationPath}, {e.Message}"); } break; case "FirstFrame": pm.FirstFrame = lexer.ParseInt(); break; case "LastFrame": pm.LastFrame = lexer.ParseInt(); break; case "LoopedAnimation": pm.LoopedAnimation = lexer.ParseBool(); break; case "AnimationFPS": pm.AnimationFps = lexer.ParseFloat(); break; case "Scale": { var scale = lexer.ParseFloat(); pm.Scale = new Vector2(scale, scale); break; } case "AspectRatio": { var ar = lexer.ParseFloat(); if (ar != 1f) { pm.Scale = ParticleEmitter.ApplyAspectRatio(pm.Scale, ar); } break; } case "Velocity": pm.Velocity = lexer.ParseFloat(); break; case "WindAmount": pm.WindAmount = lexer.ParseFloat(); break; case "GravityAmount": pm.GravityAmount = lexer.ParseFloat(); break; case "MagnetAmount": pm.MagnetAmount = lexer.ParseFloat(); break; case "Spin": pm.Spin = lexer.ParseFloat(); break; case "AngularVelocity": pm.AngularVelocity = lexer.ParseFloat(); break; case "Color": pm.Color = lexer.ParseColor4(); break; default: ParseActorProperty(node, name); break; } }
/// <summary> /// Add a new modifier to this emitter /// </summary> /// <remarks> /// Modifier can be added only once /// </remarks> /// <param name="modifier">The ParticleModifier to be added</param> public void AddParticleModifier(ParticleModifier modifier) { Debug.Assert(!modifiers.Contains(modifier), "Tried adding " + modifier.ToString() + " twice"); modifiers.Add(modifier); }