Skip to content

Commit

Permalink
Merge pull request #20 from ChrisAdderley/dev
Browse files Browse the repository at this point in the history
Release 0.2.2
  • Loading branch information
ChrisAdderley authored Oct 30, 2020
2 parents 89545f1 + d25ec35 commit cbb4364
Show file tree
Hide file tree
Showing 14 changed files with 450 additions and 3 deletions.
Binary file not shown.
Binary file modified GameData/Waterfall/Plugins/Waterfall.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion GameData/Waterfall/Versioning/Waterfall.version
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{
"MAJOR":0,
"MINOR":2,
"PATCH":1,
"PATCH":2,
"BUILD":0
},
"KSP_VERSION":
Expand Down
178 changes: 178 additions & 0 deletions Source/Waterfall/Modules/ModuleWaterfallSmoke.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using UnityEngine.Experimental.PlayerLoop;

namespace Waterfall.Modules
{
public class ModuleWaterfallSmoke : PartModule
{

// This links to an EngineID from a ModuleEnginesFX
[KSPField(isPersistant = false)]
public string waterfallModuleID = "";

// This links to an EngineID from a ModuleEnginesFX
[KSPField(isPersistant = false)]
public string smokeTransformName = "";

// This links to an EngineID from a ModuleEnginesFX
[KSPField(isPersistant = false)]
public string smokePrefabName = "WaterfallSmokeProto";

// Map speed to emission
[KSPField(isPersistant = false)]
public FloatCurve SpeedEmissionScaleCurve = new FloatCurve();

[KSPField(isPersistant = false)]
public FloatCurve SpeedLifetimeScaleCurve = new FloatCurve();

[KSPField(isPersistant = false)]
public FloatCurve AtmoSizeScaleCurve = new FloatCurve();

[KSPField(isPersistant = false)]
public FloatCurve AtmoAlphaFadeCurve = new FloatCurve();

[KSPField(isPersistant = false)]
public Vector2 emissionRateRange;

[KSPField(isPersistant = false)]
public Vector2 emissionSpeedRange;

[KSPField(isPersistant = false)]
public Vector2 startSizeRange;

[KSPField(isPersistant = false)]
public Vector2 lifetimeRange;

List<WaterfallSmokeEmitter> emitters;

public void Start()
{
if (HighLogic.LoadedSceneIsFlight)
{
InstantiateEffect();
}

}

public void InstantiateEffect()
{
emitters = new List<WaterfallSmokeEmitter>();
if (smokeTransformName != "")
{
foreach (Transform t in part.FindModelTransforms(smokeTransformName))
{

emitters.Add(new WaterfallSmokeEmitter(smokePrefabName, t));
}
}
else
emitters.Add(new WaterfallSmokeEmitter(smokePrefabName, part.transform));

}
public void SetRanges(
Vector2 emissionRangeNew,
Vector2 speedRangeNew,
Vector2 sizeRangeNew,
Vector2 lifetimeRangeNew)
{
emissionRateRange = emissionRangeNew;
emissionSpeedRange = speedRangeNew;
startSizeRange = sizeRangeNew;
lifetimeRange = lifetimeRangeNew;
}
protected void SetParticles()
{
float srfSpeed = (float)part.vessel.srfSpeed;
float pressureAtm = (float)vessel.mainBody.GetPressureAtm(part.vessel.altitude);
for (int i = 0; i < emitters.Count; i++)
{
emitters[i].Set(
emissionRateRange * SpeedEmissionScaleCurve.Evaluate(srfSpeed),
emissionSpeedRange,
startSizeRange * AtmoSizeScaleCurve.Evaluate(pressureAtm),
lifetimeRange * SpeedLifetimeScaleCurve.Evaluate(srfSpeed),
AtmoAlphaFadeCurve.Evaluate(pressureAtm));
}
}

public void FixedUpdate()
{

if (HighLogic.LoadedSceneIsFlight && emitters != null)
{
SetParticles();
for (int i = 0; i < emitters.Count; i++)
{
emitters[i].Update();
}
}
}
}

public class WaterfallSmokeEmitter
{
private string prefab;
private Transform parent;
private ParticleSystem emitter;
private ParticleSystemRenderer renderer;

private static ParticleSystem.Particle[] particles;

public WaterfallSmokeEmitter(string prefabName, Transform parentTransform)
{
prefab = prefabName;
parent = parentTransform;
GameObject go = GameObject.Instantiate(WaterfallParticleLoader.GetParticles(prefabName), Vector3.zero, Quaternion.identity) as GameObject;

emitter = go.GetComponent<ParticleSystem>();
renderer = go.GetComponent<ParticleSystemRenderer>();
go.transform.SetParent(parentTransform);
go.transform.localPosition = Vector3.zero;
go.transform.localScale = Vector3.one;
go.transform.localRotation = Quaternion.identity;

FloatingOrigin.RegisterParticleSystem(emitter);
}

public void Update()
{
//if (particles == null || emitter.main.maxParticles > particles.Length)
// particles = new ParticleSystem.Particle[emitter.main.maxParticles];

//int numParticlesAlive = emitter.GetParticles(particles);

//for (int j = 0; j < numParticlesAlive; j++)
//{
// //particles[j].v Krakensbane.GetFrameVelocity
//}
}

public void Set(
Vector2 emissionRange,
Vector2 speedRange,
Vector2 sizeRange,
Vector2 lifetimeRange,
float fade
)
{
var main = emitter.main;
main.startSpeed = new ParticleSystem.MinMaxCurve(speedRange.x, speedRange.y);
main.startSize = new ParticleSystem.MinMaxCurve(sizeRange.x, sizeRange.y);
main.startLifetime = new ParticleSystem.MinMaxCurve(lifetimeRange.x, lifetimeRange.y);

var emit = emitter.emission;
emit.rateOverTime = new ParticleSystem.MinMaxCurve(emissionRange.x, emissionRange.y);

var color = emitter.colorOverLifetime;

Gradient grad = color.color.gradient;
grad.SetKeys(grad.colorKeys, new GradientAlphaKey[] { new GradientAlphaKey(0f, 0f), new GradientAlphaKey(fade * 1f, 0.01f), new GradientAlphaKey(fade * 0.3f, 0.5f), new GradientAlphaKey(0f, 1f) });
color.color = new ParticleSystem.MinMaxGradient(grad);

}
}
}
7 changes: 6 additions & 1 deletion Source/Waterfall/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ public static void Load()

// Setting parsing goes here
//settingsNode.TryGetValue("MinimumWarpFactor", ref TimeWarpLimit);

settingsNode.TryGetValue("DebugModules", ref DebugModules);
settingsNode.TryGetValue("DebugSettings", ref DebugSettings);
settingsNode.TryGetValue("DebugEffects", ref DebugEffects);
settingsNode.TryGetValue("DebugModifiers", ref DebugModifiers);
settingsNode.TryGetValue("DebugMode", ref DebugMode);
settingsNode.TryGetValue("DebugUIMode", ref DebugUIMode);

}
else
Expand Down
1 change: 1 addition & 0 deletions Source/Waterfall/UI/UIMaterialEditWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public void ChangeMaterial(WaterfallModel modelToEdit)

protected override void DrawWindow(int windowId)
{

// Draw the header/tab controls
DrawTitle();
DrawMaterials();
Expand Down
1 change: 1 addition & 0 deletions Source/Waterfall/UI/UIPopupWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public UIPopupWindow(bool show)
Utils.Log("[UI]: Start fired");
showWindow = show;


}

/// <summary>
Expand Down
125 changes: 125 additions & 0 deletions Source/Waterfall/UI/UISmokeEditWindow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using Waterfall.Modules;

namespace Waterfall.UI
{
public class UISmokeEditWindow : UIPopupWindow
{


protected string windowTitle = "";

Vector2 startSizeRange;
string[] startSizeRangeString;
Vector2 lifetimeRange;
string[] lifetimeRangeString;
Vector2 emissionRateRange;
string[] emissionRateRangeString;
Vector2 emissionSpeedRange;
string[] emissionSpeedRangeString;

ModuleWaterfallSmoke smokeModule;

public UISmokeEditWindow(ModuleWaterfallSmoke smoke, bool show) : base(show)
{
smokeModule = smoke;
Utils.Log($"[UISmokeEditWindoww]: Started editing smoke on {true.ToString()}", LogType.UI);

startSizeRange = smoke.startSizeRange;
emissionRateRange = smoke.emissionRateRange;
emissionSpeedRange = smoke.emissionSpeedRange;
lifetimeRange = smoke.lifetimeRange;

startSizeRangeString = new string[] {startSizeRange.x.ToString(), startSizeRange.y.ToString() };
emissionRateRangeString = new string[] { emissionRateRange.x.ToString(), emissionRateRange.y.ToString() };
emissionSpeedRangeString = new string[] { emissionSpeedRange.x.ToString(), emissionSpeedRange.y.ToString() };
lifetimeRangeString = new string[] { lifetimeRange.x.ToString(), lifetimeRange.y.ToString() };

WindowPosition = new Rect(Screen.width / 2 - 200, Screen.height / 2f, 400, 100);
}

protected override void InitUI()
{
windowTitle = "Smoke Editor";
base.InitUI();


}
public void Update()
{

if (smokeModule)
{
if (smokeModule.startSizeRange != startSizeRange ||
smokeModule.emissionRateRange != emissionRateRange ||
smokeModule.emissionSpeedRange != emissionSpeedRange ||
smokeModule.lifetimeRange != lifetimeRange)
{
// Utils.Log(string.Format("{0} {1} {2} {3}", emissionRateRange, emissionSpeedRange, startSizeRange, lifetimeRange));
smokeModule.SetRanges(
emissionRateRange, emissionSpeedRange, startSizeRange, lifetimeRange);
}
}
}

protected override void DrawWindow(int windowId)
{
DrawTitle();
DrawEditor();
GUI.DragWindow();
}


protected void DrawTitle()
{
GUILayout.BeginHorizontal();
GUILayout.Label(windowTitle, GUIResources.GetStyle("window_header"), GUILayout.MaxHeight(26f), GUILayout.MinHeight(26f));

GUILayout.FlexibleSpace();

Rect buttonRect = GUILayoutUtility.GetRect(22f, 22f);
GUI.color = resources.GetColor("cancel_color");
if (GUI.Button(buttonRect, "", GUIResources.GetStyle("button_cancel")))
{
ToggleWindow();
}

GUI.DrawTextureWithTexCoords(buttonRect, GUIResources.GetIcon("cancel").iconAtlas, GUIResources.GetIcon("cancel").iconRect);
GUI.color = Color.white;
GUILayout.EndHorizontal();
}

protected void DrawEditor()
{

bool delta = false;

GUILayout.BeginVertical(GUILayout.MaxWidth(400f));
GUILayout.BeginHorizontal();
GUILayout.Label("Start Size");
startSizeRange = UIUtils.Vector2InputField(GUILayoutUtility.GetRect(200f, 30f), startSizeRange, startSizeRangeString, GUI.skin.label, GUI.skin.textArea, out delta);
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
GUILayout.Label("Emission Rate");
emissionRateRange = UIUtils.Vector2InputField(GUILayoutUtility.GetRect(200f, 30f), emissionRateRange, emissionRateRangeString, GUI.skin.label, GUI.skin.textArea, out delta);
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
GUILayout.Label("Emission Speed");
emissionSpeedRange = UIUtils.Vector2InputField(GUILayoutUtility.GetRect(200f, 30f), emissionSpeedRange, emissionSpeedRangeString, GUI.skin.label, GUI.skin.textArea, out delta);
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
GUILayout.Label("Lifetime Range");
lifetimeRange = UIUtils.Vector2InputField(GUILayoutUtility.GetRect(200f, 30f), lifetimeRange, lifetimeRangeString, GUI.skin.label, GUI.skin.textArea, out delta);
GUILayout.EndHorizontal();

GUILayout.EndVertical();



}


}
}
Loading

0 comments on commit cbb4364

Please sign in to comment.