From 364fe2b9bed97b730a302b98d8e4686428053517 Mon Sep 17 00:00:00 2001 From: Andreas Aakvik Gogstad Date: Fri, 30 May 2014 19:16:35 +0200 Subject: [PATCH] recovered lost code --- Firespitter.sln | 4 +- Firespitter/Firespitter.csproj | 1 + Firespitter/customization/FSfuelSwitch.cs | 67 ++++++++++--------- Firespitter/customization/FSmeshSwitch.cs | 32 ++++++--- Firespitter/customization/FSmodularTank.cs | 12 ++++ Firespitter/customization/FStextureSwitch2.cs | 23 +++---- Firespitter/tools/FStools.cs | 26 +++++++ 7 files changed, 109 insertions(+), 56 deletions(-) create mode 100644 Firespitter/customization/FSmodularTank.cs diff --git a/Firespitter.sln b/Firespitter.sln index 6fcffd92..902eff20 100644 --- a/Firespitter.sln +++ b/Firespitter.sln @@ -1,6 +1,8 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Express 2012 for Windows Desktop +# Visual Studio Express 2013 for Windows Desktop +VisualStudioVersion = 12.0.30110.0 +MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Firespitter", "Firespitter\Firespitter.csproj", "{BFE97E64-BF01-48AF-81EE-6B2610076542}" EndProject Global diff --git a/Firespitter/Firespitter.csproj b/Firespitter/Firespitter.csproj index 9cb11ba1..f38c0529 100644 --- a/Firespitter/Firespitter.csproj +++ b/Firespitter/Firespitter.csproj @@ -68,6 +68,7 @@ + diff --git a/Firespitter/customization/FSfuelSwitch.cs b/Firespitter/customization/FSfuelSwitch.cs index 992760da..fc380a24 100644 --- a/Firespitter/customization/FSfuelSwitch.cs +++ b/Firespitter/customization/FSfuelSwitch.cs @@ -13,28 +13,32 @@ public class FSfuelSwitch : PartModule [KSPField] public string resourceAmounts = "100;75,25;200"; [KSPField] + public float basePartMass = 0.25f; + [KSPField] + public string tankMass = "0;0;0;0"; + [KSPField] public bool hasGUI = true; [KSPField] public bool availableInFlight = false; [KSPField] public bool availableInEditor = true; - - [KSPField (isPersistant = true)] + [KSPField(isPersistant = true)] public Vector4 currentAmounts = Vector4.zero; [KSPField(isPersistant = true)] public int selectedTankSetup = 0; [KSPField(isPersistant = true)] public bool hasLaunched = false; - - [KSPField(guiActive = false, guiActiveEditor=false, guiName = "Structural")] - public string info = ""; - - private List tankList = new List(); + [KSPField(guiActive = false, guiActiveEditor = false, guiName = "Structural")] + public string structuralInfo = ""; + [KSPField(guiActive = false, guiActiveEditor = true, guiName = "Dry mass")] + public float dryMassInfo = 0f; + private List tankList = new List(); + private List weightList = new List(); public override void OnStart(PartModule.StartState state) { setupTankList(); - + this.weightList = Tools.parseFloats(this.tankMass); assignResourcesToPart(); if (HighLogic.LoadedSceneIsFlight) hasLaunched = true; if (hasGUI) @@ -66,15 +70,8 @@ public void nextTankSetupEvent() public void selectTankSetup(int i) { - //if (i < tankList.Count) - //{ - selectedTankSetup = i; - assignResourcesToPart(); - //} - //else - //{ - // Debug.Log("FSfuelSwitch: invalid tank setup, " + i); - //} + selectedTankSetup = i; + assignResourcesToPart(); } private void assignResourcesToPart() @@ -116,17 +113,26 @@ private void setupTankInPart(Part currentPart) Debug.Log("add node to part"); currentPart.AddResource(newResourceNode); //part.Resources[tankList[i].resources[j].name].enabled = true; - Fields["info"].guiActiveEditor = false; + Fields["structuralInfo"].guiActiveEditor = false; } else { - Fields["info"].guiActiveEditor = true; + Fields["structuralInfo"].guiActiveEditor = true; Debug.Log("Skipping structural fuel type"); } } } } currentPart.Resources.UpdateList(); + updateWeight(currentPart, selectedTankSetup); + } + + private void updateWeight(Part currentPart, int newTankSetup) + { + if (newTankSetup < weightList.Count) + { + currentPart.mass = basePartMass + weightList[newTankSetup]; + } } public override void OnUpdate() @@ -153,15 +159,15 @@ public override void OnUpdate() } } } - } + } - //public void Update() - //{ - // if (Input.GetKeyDown(KeyCode.F3)) - // { - // nextTankSetupEvent(); - // } - //} + public void Update() + { + if (HighLogic.LoadedSceneIsEditor) + { + dryMassInfo = part.mass; + } + } private float getResource(int number) { @@ -250,10 +256,5 @@ private void setupTankList() } } } - } - - public class FSmodularTank - { - public List resources = new List(); - } + } } diff --git a/Firespitter/customization/FSmeshSwitch.cs b/Firespitter/customization/FSmeshSwitch.cs index 4e4659bc..b970760c 100644 --- a/Firespitter/customization/FSmeshSwitch.cs +++ b/Firespitter/customization/FSmeshSwitch.cs @@ -13,6 +13,8 @@ public class FSmeshSwitch : PartModule [KSPField] public string previousButtonName = "Prev part variant"; [KSPField] + public string objectDisplayNames = "Default"; + [KSPField] public bool showPreviousButton = true; [KSPField] public bool useFuelSwitchModule = false; @@ -22,13 +24,13 @@ public class FSmeshSwitch : PartModule [KSPField] public string objects = string.Empty; - // in case of multiple instances of this module, on will be the master, the rest slaves. - [KSPField] - public bool isController = true; + //// in case of multiple instances of this module, on will be the master, the rest slaves. + //[KSPField] + //public bool isController = true; - // in case of multiple sets of master/slaves, only affect ones on the same channel. - [KSPField] - public int channel = 0; + //// in case of multiple sets of master/slaves, only affect ones on the same channel. + //[KSPField] + //public int channel = 0; [KSPField(isPersistant = true)] public int selectedObject = 0; @@ -36,9 +38,13 @@ public class FSmeshSwitch : PartModule private string[] objectNames; private List objectTransforms = new List(); private List fuelTankSetupList = new List(); + private List objectDisplayList = new List(); private FSfuelSwitch fuelSwitch; + [KSPField(guiActiveEditor = true, guiName = "Current Variant")] + public string currentObjectName = string.Empty; + [KSPEvent(guiActive = false, guiActiveEditor = true, guiActiveUnfocused = false, guiName = "Next part variant")] public void nextObjectEvent() { @@ -102,7 +108,7 @@ private void switchToObject(int objectNumber) private void setObject(int objectNumber) { - if (objectNumber >= objectTransforms.Count) return; + //if (objectNumber >= objectTransforms.Count) return; for (int i = 0; i < objectTransforms.Count; i++) { @@ -114,18 +120,28 @@ private void setObject(int objectNumber) if (useFuelSwitchModule) { - Debug.Log("FStextureSwitch2 calling on FSfuelSwitch tank setup " + objectNumber); + //Debug.Log("FStextureSwitch2 calling on FSfuelSwitch tank setup " + objectNumber); if (objectNumber < fuelTankSetupList.Count) fuelSwitch.selectTankSetup(fuelTankSetupList[objectNumber]); else Debug.Log("FStextureSwitch2: no such fuel tank setup"); } + + if (selectedObject > objectDisplayList.Count - 1) + { + currentObjectName = objectNames[selectedObject]; + } + else + { + currentObjectName = objectDisplayList[selectedObject]; + } } public override void OnStart(PartModule.StartState state) { parseObjectNames(); fuelTankSetupList = Tools.parseIntegers(fuelTankSetups); + objectDisplayList = Tools.parseNames(objectDisplayNames); if (useFuelSwitchModule) { diff --git a/Firespitter/customization/FSmodularTank.cs b/Firespitter/customization/FSmodularTank.cs new file mode 100644 index 00000000..498719e6 --- /dev/null +++ b/Firespitter/customization/FSmodularTank.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Firespitter.customization +{ + public class FSmodularTank + { + public List resources = new List(); + } +} diff --git a/Firespitter/customization/FStextureSwitch2.cs b/Firespitter/customization/FStextureSwitch2.cs index d0799289..f4466cae 100644 --- a/Firespitter/customization/FStextureSwitch2.cs +++ b/Firespitter/customization/FStextureSwitch2.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Text; using UnityEngine; +using Firespitter.info; namespace Firespitter.customization { @@ -17,7 +18,7 @@ public class FStextureSwitch2 : PartModule [KSPField] public string mapNames = string.Empty; [KSPField] - public string textureDisplayNames = string.Empty; + public string textureDisplayNames = "Default"; [KSPField(isPersistant = true)] public int selectedTexture = 0; @@ -57,7 +58,7 @@ public class FStextureSwitch2 : PartModule private FSfuelSwitch fuelSwitch; - Firespitter.info.FSdebugMessages debug = new Firespitter.info.FSdebugMessages(false, Firespitter.info.FSdebugMessages.OutputMode.both, 2f); //set to true for debug + FSdebugMessages debug = new FSdebugMessages(false, FSdebugMessages.OutputMode.both, 2f); //set to true for debug [KSPField(guiActiveEditor = true, guiName = "Current Texture")] public string currentTextureName = string.Empty; @@ -176,8 +177,8 @@ public void useTexture(Material targetMat) public override string GetInfo() { - texList = parseNames(textureNames); - textureDisplayList = parseNames(textureDisplayNames); + texList = Tools.parseNames(textureNames); + textureDisplayList = Tools.parseNames(textureDisplayNames); StringBuilder info = new StringBuilder(); info.AppendLine("Alternate textures available:"); if (texList.Count == 0) @@ -202,20 +203,14 @@ private string getTextureDisplayName(string longName) return splitString[splitString.Length - 1]; } - public List parseNames(string names) - { - string[] nameArray = names.Split(';'); - return nameArray.ToList(); - } - public override void OnStart(PartModule.StartState state) { debug.debugMode = debugMode; - objectList = parseNames(objectNames); - texList = parseNames(textureNames); - mapList = parseNames(mapNames); - textureDisplayList = parseNames(textureDisplayNames); + objectList = Tools.parseNames(objectNames); + texList = Tools.parseNames(textureNames); + mapList = Tools.parseNames(mapNames); + textureDisplayList = Tools.parseNames(textureDisplayNames); fuelTankSetupList = Tools.parseIntegers(fuelTankSetups); debug.debugMessage("FStextureSwitch2 found " + texList.Count + " textures, using number " + selectedTexture + ", found " + objectList.Count + " objects, " + mapList.Count + " maps"); diff --git a/Firespitter/tools/FStools.cs b/Firespitter/tools/FStools.cs index d66a3fab..a133aceb 100644 --- a/Firespitter/tools/FStools.cs +++ b/Firespitter/tools/FStools.cs @@ -63,6 +63,32 @@ public static List parseIntegers(string stringOfInts) } return newIntList; } + + + public static List parseFloats(string stringOfFloats) + { + System.Collections.Generic.List list = new System.Collections.Generic.List(); + string[] array = stringOfFloats.Split(';'); + for (int i = 0; i < array.Length; i++) + { + float item = 0f; + if (float.TryParse(array[i], out item)) + { + list.Add(item); + } + else + { + Debug.Log("invalid float: " + array[i]); + } + } + return list; + } + + public static List parseNames(string names) + { + string[] source = names.Split(';'); + return source.ToList(); + } } public class MouseEventHandler : MonoBehaviour