Skip to content

Commit

Permalink
module cost implemented in fuel switch
Browse files Browse the repository at this point in the history
  • Loading branch information
snjo committed Jul 26, 2014
1 parent aeeda17 commit f4a6598
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 14 deletions.
48 changes: 40 additions & 8 deletions Firespitter/customization/FSfuelSwitch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Firespitter.customization
{
public class FSfuelSwitch : PartModule
public class FSfuelSwitch : PartModule, IPartCostModifier
{
[KSPField]
public string resourceNames = "ElectricCharge;LiquidFuel,Oxidizer;MonoPropellant";
Expand All @@ -15,11 +15,16 @@ public class FSfuelSwitch : PartModule
[KSPField]
public string tankMass = "0;0;0;0";
[KSPField]
public string tankCost = "0,0,0,0";
[KSPField]
public bool displayCurrentTankCost = false;
[KSPField]
public bool hasGUI = true;
[KSPField]
public bool availableInFlight = false;
[KSPField]
public bool availableInEditor = true;


[KSPField(isPersistant = true)]
public Vector4 currentAmounts = Vector4.zero;
Expand All @@ -30,16 +35,18 @@ public class FSfuelSwitch : PartModule
[KSPField]
public bool showInfo = true; // if false, does not feed info to the part list pop up info menu

[KSPField(guiActive = false, guiActiveEditor = false, guiName = "Added cost")]
public float addedCost = 0f;
[KSPField(guiActive = false, guiActiveEditor = true, guiName = "Dry mass")]
public float dryMassInfo = 0f;
private List<FSmodularTank> tankList = new List<FSmodularTank>();
private List<float> weightList = new List<float>();
private List<float> tankCostList = new List<float>();
private bool initialized = false;
[KSPField (isPersistant = true)]
private bool brandNewPart = true;

private bool brandNewPart = true;

UIPartActionWindow tweakableUI;
UIPartActionWindow tweakableUI;

public override void OnStart(PartModule.StartState state)
{
Expand All @@ -53,7 +60,8 @@ private void initializeData()
if (!initialized)
{
setupTankList(false);
this.weightList = Tools.parseFloats(this.tankMass);
weightList = Tools.parseFloats(tankMass);
tankCostList = Tools.parseFloats(tankCost);
if (HighLogic.LoadedSceneIsFlight) hasLaunched = true;
if (hasGUI)
{
Expand All @@ -65,6 +73,12 @@ private void initializeData()
Events["nextTankSetupEvent"].guiActive = false;
Events["nextTankSetupEvent"].guiActiveEditor = false;
}

if (HighLogic.CurrentGame.Mode == Game.Modes.CAREER)
{
Fields["addedCost"].guiActiveEditor = displayCurrentTankCost;
}

initialized = true;
}
}
Expand Down Expand Up @@ -108,7 +122,7 @@ private void assignResourcesToPart(bool calledByPlayer)
}
}

Debug.Log("refreshing UI");
//Debug.Log("refreshing UI");

if (tweakableUI == null)
{
Expand All @@ -120,7 +134,7 @@ private void assignResourcesToPart(bool calledByPlayer)
}
else
{
Debug.Log("no UI");
Debug.Log("no UI to refresh");
}
}

Expand Down Expand Up @@ -167,8 +181,21 @@ private void setupTankInPart(Part currentPart, bool calledByPlayer)
}
currentPart.Resources.UpdateList();
updateWeight(currentPart, selectedTankSetup);
updateCost();
}


private float updateCost()
{
if (selectedTankSetup < tankCostList.Count)
{
addedCost = tankCostList[selectedTankSetup];
}
else
{
addedCost = 0f;
}
//GameEvents.onEditorShipModified.Fire(EditorLogic.fetch.ship); //crashes game
return addedCost;
}

private void updateWeight(Part currentPart, int newTankSetup)
Expand Down Expand Up @@ -308,6 +335,11 @@ private void setupTankList(bool calledByPlayer)
}
}

public float GetModuleCost()
{
return updateCost();
}

public override string GetInfo()
{
if (showInfo)
Expand Down
13 changes: 10 additions & 3 deletions Firespitter/customization/FSmeshSwitch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Firespitter.customization
{
public class FSmeshSwitch : PartModule
public class FSmeshSwitch : PartModule //, IPartCostModifier
{
[KSPField]
public int moduleID = 0;
Expand Down Expand Up @@ -54,6 +54,8 @@ public class FSmeshSwitch : PartModule

[KSPField(guiActiveEditor = true, guiName = "Current Variant")]
public string currentObjectName = string.Empty;

private float moduleCost;

[KSPEvent(guiActive = false, guiActiveEditor = true, guiActiveUnfocused = false, guiName = "Next part variant")]
public void nextObjectEvent()
Expand All @@ -63,7 +65,7 @@ public void nextObjectEvent()
{
selectedObject = 0;
}
switchToObject(selectedObject, true);
switchToObject(selectedObject, true);
}

[KSPEvent(guiActive = false, guiActiveEditor = true, guiActiveUnfocused = false, guiName = "Prev part variant")]
Expand All @@ -74,7 +76,7 @@ public void previousObjectEvent()
{
selectedObject = objectTransforms.Count - 1;
}
switchToObject(selectedObject, true);
switchToObject(selectedObject, true);
}

private void parseObjectNames()
Expand Down Expand Up @@ -254,6 +256,11 @@ public void initializeData()
}
}

//public float GetModuleCost()
//{
// return moduleCost;
//}

public override string GetInfo()
{
if (showInfo)
Expand Down
5 changes: 2 additions & 3 deletions Firespitter/tools/FSversionCheck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ public class FSversionCheck : MonoBehaviour

public void Start()
{
FSversion = Assembly.GetExecutingAssembly().GetName().Version;
Debug.Log("firespitter.dll version: " + FSversion.ToString() + ", compiled for KSP " + CompatibleWithMajor + "." + CompatibleWithMinor + "." + CompatibleWithRevision);
}

public static bool IsCompatible()
{

FSversion = Assembly.GetExecutingAssembly().GetName().Version;
{

if (Versioning.version_major != CompatibleWithMajor
||
Expand Down
Binary file modified For release/Firespitter/Plugins/Firespitter.dll
Binary file not shown.

0 comments on commit f4a6598

Please sign in to comment.