Skip to content

Commit

Permalink
** WARNING ** - This update contains potentially breaking changes for…
Browse files Browse the repository at this point in the history
… fuel tank parts due to their prior lack of persistent data handling

* FIX - RBDC nullref and crash in flight scene (thanks KSP for your inconsistent loading sequence and calling methods on PartModules before OnStart)
* FIX - Procedural decoupler hollow collider to actually be hollow in flight scene (useful for LC setups)
* FIX - SSTUVolumeContainer will now properly update persistent data at all points where it is needed.
* CHANGE - VolumeContainer - now persist 'fuelType' selection for containers
* CHANGE - VolumeContainer - ability to specify base container index; this is the container that the 'next fuel type' interaction has influence over.
* CHANGE - VolumeContainer - ability to completely disable the 'fuel type' selection
* CHANGE - VolumeContainer - ability to completely disable the 'configure containers' button (e.g. for a single-resource part that still needs volume handling -- MSRBs)
* CHANGE - VolumeContainer - now use a UI_ChooseOption (string slider) for fuel type selection; might be a bit wonky with 'custom' fuel types
* CHANGE - VolumeContainer Configuration GUI - remove slider, replace with % text, as the slider might have led to someone believing they could adjust the ratio through it; will look into some sort of graphical display-only ratio bar, but my options might be limited with the unity IMGUI (still pretty new at it, have not investigated yet)
* CHANGE - VolumeContainer Configuration GUI - hold CTRL while clicking a fuel type to Set to that fuel type; hold SHIFT to subtract that fuel types ratio
* NEW MODULE - Add basic implementation of ModelSwitch module; used for LanderCore pod ascent fuel tanks currently, and will be used for other 'generic' modular parts in the future (probes, station parts... other things...).
  * Will enable various 'groups' of mutually-exclusive models that are controlled independently; a model may be used in more than one group, in more than one orientation.  Currently only a single orientation per-group is supported but that may change in the near future
  * GUI interaction is mostly non-functional at the moment and merely enables/disables -all- models regardless of grouping/etc; this will be changing soon (likely by the weekend).
* CHANGE - Add integration between ModelSwitch and VolumeContainer; volume container has had its persistent data format updated, but I've added in some temp code to enable loading data from the last version
* OLD PART - LC2-POD is back in-game as a test case for the model switching and VolumeContainer integration.
  * The aptly named 'EnableStuff' and 'DisableStuff' buttons enable and disable the ascent fuel tanks
  * The buttons -will- be changed in the near future and will likely end up with a more complex GUI system for parts that need it
  * This part will likely break a few times before I get all the model-switching stuff... finished.
  * Add built in docking port; untested
  * Using default 'placeholder' IVA until I can re-add the old WIP IVA
  • Loading branch information
shadowmage45 committed Apr 21, 2016
1 parent cdb028a commit d633350
Show file tree
Hide file tree
Showing 11 changed files with 405 additions and 135 deletions.
3 changes: 3 additions & 0 deletions GameData/SSTU/Parts/ShipCore/tanks/SC-MFT-A.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ breakingTorque = 2000
MODULE
{
name = SSTUVolumeContainer
//default placeholder volume; set by MFT module below
volume = 100000
enableContainerEdit = true
enableFuelTypeChange = true
CONTAINER
{
name = Main Tank
Expand Down
Binary file modified GameData/SSTU/Plugins/SSTUTools.dll
Binary file not shown.
27 changes: 23 additions & 4 deletions Source/GUI/VolumeContainerGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public static void openGUI(SSTUVolumeContainer container, ContainerDefinition[]
}
windowRect = new Rect(Screen.width - 900, 40, 800, 600);
statWindowRect = new Rect(Screen.width - 900 - 250, 40, 250, 300);
containerIndex = 0;
module = container;
containers = modContainers;
id = module.GetInstanceID();
Expand Down Expand Up @@ -177,7 +178,7 @@ private static void addWindowContainerTypeControls(ContainerDefinition container

private static void addWindowFuelTypeControls(ContainerDefinition container)
{
GUILayout.Label("Select an optional pre-filled fuel type:");
GUILayout.Label("Fuel Types -- Click to add ratio, CTRL click to set ratio, SHIFT click to subtract ratio");
ContainerFuelPreset[] presets = container.fuelPresets;
ContainerFuelPreset preset;
GUILayout.BeginHorizontal();
Expand All @@ -191,23 +192,41 @@ private static void addWindowFuelTypeControls(ContainerDefinition container)
}
if (GUILayout.Button(preset.name, GUILayout.Width(175)))
{
container.addPresetRatios(presets[i]);
if (ctrlPressed())//ctrl == set fuel type
{
container.setFuelPreset(presets[i]);
}
else if (shiftPressed())
{
container.subtractPresetRatios(presets[i]);
}
else
{
container.addPresetRatios(presets[i]);
}
}
}
GUILayout.EndHorizontal();
}

private static bool ctrlPressed()
{
return Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl) || Input.GetKey(KeyCode.LeftCommand) || Input.GetKey(KeyCode.RightCommand);
}

private static bool shiftPressed() { return Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift); }

private static void addWindowContainerRatioControls(ContainerDefinition container)
{
GUILayout.Label("Adjust ratio through input box to change resource ratios");
VolumeRatioEntry[] ratioData = resourceEntries[containerIndex];
scrollPos = GUILayout.BeginScrollView(scrollPos);
GUILayout.BeginHorizontal();
GUILayout.Label("Resource", GUILayout.Width(150));
GUILayout.Label("% of Tank", GUILayout.Width(100));
GUILayout.Label("Unit Ratio", GUILayout.Width(100));
GUILayout.Label("Units", GUILayout.Width(100));
GUILayout.Label("Volume", GUILayout.Width(100));
GUILayout.Label("% of Tank", GUILayout.Width(100));
GUILayout.EndHorizontal();
int len = ratioData.Length;
for (int i = 0; i < len; i++)
Expand Down Expand Up @@ -248,7 +267,6 @@ public void draw()
}
GUILayout.Label(resourceName, GUILayout.Width(150));//resource name
float tankPercent = container.getResourceVolume(resourceName) / container.usableVolume;//. container.usableVolume > 0 ? currentVolumeRatio / totalVolumeRatio : 0;
GUILayout.HorizontalSlider(tankPercent, 0, 1, GUILayout.Width(100));
string textVal = GUILayout.TextField(textRatio, GUILayout.Width(100));
if (textVal != textRatio)
{
Expand All @@ -264,6 +282,7 @@ public void draw()
GUILayout.Label(tankUnits.ToString(), GUILayout.Width(100));
float tankVolume = container.getResourceVolume(resourceName);
GUILayout.Label(tankVolume.ToString(), GUILayout.Width(100));
GUILayout.Label(tankPercent.ToString(), GUILayout.Width(100));
}

}
Expand Down
46 changes: 9 additions & 37 deletions Source/MeshGenerator/ProceduralModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,59 +11,49 @@ public class ProceduralModel

protected bool meshColliderEnabled = false;
protected bool meshColliderConvex = false;

//DONE

protected virtual void generateModel(GameObject root)
{
throw new NotImplementedException("Cannot call generateModel() on base ProceduralModel; must utilize sublcasses for implementation!");
}

//DONE

public void setParent(Transform tr)
{
root.transform.NestToParent(tr);
}

//DONE

public void createModel()
{
root = new GameObject(rootName);
generateModel(root);
updateModelMaterial();
updateColliders();
}

//DONE

public void recreateModel()
{
destroyModel();
generateModel(root);
updateModelMaterial();
updateColliders();
}

//DONE

public void destroyModel()
{
SSTUUtils.destroyChildren(root.transform);
}

//DONE

public void setMaterial(Material mat)
{
currentMaterial = mat;
updateModelMaterial();
}

//DONE

public void setMainTexture(String texName)
{
if (currentMaterial == null) { MonoBehaviour.print("ERROR: Material was null when trying to set diffuse texture: "+texName); }
currentMaterial.mainTexture = GameDatabase.Instance.GetTexture(texName, false);
updateModelMaterial();
}

//DONE

public void setNormalTexture(String texName)
{
if (currentMaterial == null) { MonoBehaviour.print("ERROR: Material was null when trying to set normal texture: " + texName); }
Expand All @@ -77,32 +67,14 @@ public void setNormalTexture(String texName)
}
updateModelMaterial();
}

//DONE
public void setMeshColliderStatus(bool enable, bool convex)
{
meshColliderEnabled = enable;
meshColliderConvex = convex;
updateColliders();
}

//DONE

protected void updateModelMaterial()
{
if (root != null)
{
SSTUUtils.setMaterialRecursive(root.transform, currentMaterial);
}
}

//DONE
protected void updateColliders()
{
if (root != null)
{
SSTUUtils.addMeshCollidersRecursive(root.transform, meshColliderEnabled, meshColliderConvex);
}
}
}
}

4 changes: 2 additions & 2 deletions Source/Module/SSTUAnimateUsable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ private void initializeGuiFields()
}
catch (Exception e)
{
MonoBehaviour.print("ERROR PARSING ACTION GROUP FOR NAME: " + deployActionGroup);
MonoBehaviour.print("ERROR PARSING ACTION GROUP FOR NAME: " + deployActionGroup + " :: " + e.Message);
}
}
if (retractActionGroup != "NONE")
Expand All @@ -186,7 +186,7 @@ private void initializeGuiFields()
}
catch (Exception e)
{
MonoBehaviour.print("ERROR PARSING ACTION GROUP FOR NAME: " + retractActionGroup);
MonoBehaviour.print("ERROR PARSING ACTION GROUP FOR NAME: " + retractActionGroup + " :: " + e.Message);
}
}

Expand Down
27 changes: 16 additions & 11 deletions Source/Module/SSTUCustomRadialDecoupler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ class SSTUCustomRadialDecoupler : PartModule, IPartMassModifier, IPartCostModifi
private float prevHeight;
private float prevDiameter;

private float modifiedCost;
private float modifiedMass;

private Transform topMountTransform;
private Transform bottomMountTransform;
private Transform scalarTransform;
Expand Down Expand Up @@ -140,17 +143,11 @@ public override void OnStart(StartState state)

public float GetModuleMass(float defaultMass, ModifierStagingSituation sit)
{
float scale = getScale();
float modifiedMass = defaultMass * Mathf.Pow(scale, 3);
return -defaultMass + modifiedMass;
}

public float GetModuleCost(float defaultCost, ModifierStagingSituation sit)
{
float scale = getScale();
float modifiedCost = defaultCost * Mathf.Pow(scale, 3);
float currentVolume = resourceVolume * Mathf.Pow(getCurrentModelScale(), thrustScalePower);
modifiedCost += fuelType.getResourceCost(currentVolume);
return -defaultCost + modifiedCost;
}

Expand Down Expand Up @@ -238,6 +235,7 @@ private void updateModelPositions()
private void updateModelScales()
{
setModelScale(scalarTransform, getScale());
updateMassAndCost();
}

private float getScale()
Expand All @@ -264,7 +262,7 @@ private void updateAttachNodes(bool userInput)

private void updateEngineThrust()
{
float currentScale = getCurrentModelScale();
float currentScale = getScale();
float thrustScalar = Mathf.Pow(currentScale, thrustScalePower);
float maxThrust = engineThrust * thrustScalar;
guiEngineThrust = maxThrust;
Expand All @@ -280,7 +278,7 @@ private void updateEngineThrust()

private void updatePartResources()
{
float resourceScalar = Mathf.Pow(getCurrentModelScale(), thrustScalePower);
float resourceScalar = Mathf.Pow(getScale(), thrustScalePower);
float currentVolume = resourceVolume * resourceScalar;
if (SSTUModInterop.isRFInstalled())
{
Expand All @@ -292,10 +290,17 @@ private void updatePartResources()
res.setResourcesToPart(part, HighLogic.LoadedSceneIsEditor);
}
}
private float getCurrentModelScale()

private void updateMassAndCost()
{
return diameter / modelDiameter;
float scale = getScale();
float defaultMass = part.partInfo==null? part.mass : part.prefabMass;
modifiedMass = defaultMass * Mathf.Pow(scale, 3);

float defaultCost = part.partInfo == null ? 100 : part.partInfo.cost;
float currentVolume = resourceVolume * Mathf.Pow(scale, thrustScalePower);
float modifiedCost = defaultCost * Mathf.Pow(scale, 3);
modifiedCost += fuelType.getResourceCost(currentVolume);
}
}

Expand Down
Loading

0 comments on commit d633350

Please sign in to comment.