Skip to content
This repository has been archived by the owner on Sep 7, 2021. It is now read-only.

Commit

Permalink
formatting, correct initilisation of module_CC_used
Browse files Browse the repository at this point in the history
  • Loading branch information
Crzyrndm committed Jun 13, 2017
1 parent 8f57b99 commit bb99f30
Show file tree
Hide file tree
Showing 7 changed files with 972 additions and 276 deletions.
69 changes: 69 additions & 0 deletions B9 PWings Fork/MathD.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@ public static double Min(params double[] values)
{
int length = values.Length;
if (length == 0)
{
return 0.0d;
}

double num = values[0];
for (int index = 1; index < length; ++index)
{
if (values[index] < num)
{
num = values[index];
}
}
return num;
}
Expand All @@ -30,12 +35,17 @@ public static int Min(params int[] values)
{
int length = values.Length;
if (length == 0)
{
return 0;
}

int num = values[0];
for (int index = 1; index < length; ++index)
{
if (values[index] < num)
{
num = values[index];
}
}
return num;
}
Expand All @@ -44,12 +54,17 @@ public static double Max(params double[] values)
{
int length = values.Length;
if (length == 0)
{
return 0d;
}

double num = values[0];
for (int index = 1; index < length; ++index)
{
if ((double)values[index] > (double)num)
{
num = values[index];
}
}
return num;
}
Expand All @@ -58,12 +73,17 @@ public static int Max(params int[] values)
{
int length = values.Length;
if (length == 0)
{
return 0;
}

int num = values[0];
for (int index = 1; index < length; ++index)
{
if (values[index] > num)
{
num = values[index];
}
}
return num;
}
Expand All @@ -86,20 +106,32 @@ public static int RoundToInt(double d)
public static T Clamp<T>(T value, T min, T max) where T : IComparable<T>
{
if (value.CompareTo(min) < 0)
{
value = min;
}
else if (value.CompareTo(max) > 0)
{
value = max;
}

return value;
}

public static double Clamp01(double value)
{
if (value < 0.0)
{
return 0.0d;
}

if (value > 1.0)
{
return 1d;
}
else
{
return value;
}
}

public static double Lerp(double from, double to, double t)
Expand All @@ -111,16 +143,23 @@ public static double LerpAngle(double a, double b, double t)
{
double num = MathD.Repeat(b - a, 360d);
if (num > 180.0d)
{
num -= 360d;
}

return a + num * MathD.Clamp01(t);
}

public static double MoveTowards(double current, double target, double maxDelta)
{
if (Math.Abs(target - current) <= maxDelta)
{
return target;
}
else
{
return current + Math.Sign(target - current) * maxDelta;
}
}

public static double MoveTowardsAngle(double current, double target, double maxDelta)
Expand All @@ -140,22 +179,33 @@ public static double Gamma(double value, double absmax, double gamma)
{
bool flag = false;
if (value < 0.0)
{
flag = true;
}

double num1 = Math.Abs(value);
if (num1 > absmax)
{
if (flag)
{
return -num1;
}
else
{
return num1;
}
}
else
{
double num2 = Math.Pow(num1 / absmax, gamma) * absmax;
if (flag)
{
return -num2;
}
else
{
return num2;
}
}
}

Expand Down Expand Up @@ -227,31 +277,50 @@ public static double InverseLerp(double from, double to, double value)
if (from < to)
{
if (value < from)
{
return 0d;
}

if (value > to)
{
return 1d;
}

value -= from;
value /= to - from;
return value;
}
else
{
if (from <= to)
{
return 0d;
}

if (value < to)
{
return 1d;
}

if (value > from)
{
return 0d;
}
else
{
return (1.0d - (value - to) / (from - to));
}
}
}

public static double DeltaAngle(double current, double target)
{
double num = MathD.Repeat(target - current, 360d);
if (num > 180.0d)
{
num -= 360d;
}

return num;
}
}
Expand Down
4 changes: 3 additions & 1 deletion B9 PWings Fork/StaticWingGlobals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ public void Start()
{
ConfigNode[] fuelNodes = node.GetNodes("FuelSet");
for (int i = 0; i < fuelNodes.Length; ++i)
{
wingTankConfigurations.Add(new WingTankConfiguration(fuelNodes[i]));
}
}
Debug.Log("[B9PW] start bundle load process");
StartCoroutine(LoadBundleAssets());
Expand All @@ -27,7 +29,7 @@ public void Start()
public IEnumerator LoadBundleAssets()
{
Debug.Log("[B9PW] Aquiring bundle data");
AssetBundle shaderBundle = AssetBundle.LoadFromFile(KSPUtil.ApplicationRootPath + "GameData" + Path.DirectorySeparatorChar + "B9_Aerospace_ProceduralWings" + Path.DirectorySeparatorChar + "wingshader");
var shaderBundle = AssetBundle.LoadFromFile(KSPUtil.ApplicationRootPath + "GameData" + Path.DirectorySeparatorChar + "B9_Aerospace_ProceduralWings" + Path.DirectorySeparatorChar + "wingshader");
if (shaderBundle != null)
{
Shader[] objects = shaderBundle.LoadAllAssets<Shader>();
Expand Down
65 changes: 42 additions & 23 deletions B9 PWings Fork/UIUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,30 @@ public static void ConfigureStyles()
}
if (uiFont != null)
{
uiStyleWindow = new GUIStyle(HighLogic.Skin.window);
uiStyleWindow.fixedWidth = 300f;
uiStyleWindow.wordWrap = true;
uiStyleWindow = new GUIStyle(HighLogic.Skin.window) {
fixedWidth = 300f,
wordWrap = true
};
uiStyleWindow.normal.textColor = Color.white;
uiStyleWindow.font = uiFont;
uiStyleWindow.fontStyle = FontStyle.Normal;
uiStyleWindow.fontSize = 13;
uiStyleWindow.alignment = TextAnchor.UpperLeft;

uiStyleLabelMedium = new GUIStyle(HighLogic.Skin.label);
uiStyleLabelMedium.stretchWidth = true;
uiStyleLabelMedium.font = uiFont;
uiStyleLabelMedium.fontStyle = FontStyle.Normal;
uiStyleLabelMedium.fontSize = 13;
uiStyleLabelMedium = new GUIStyle(HighLogic.Skin.label) {
stretchWidth = true,
font = uiFont,
fontStyle = FontStyle.Normal,
fontSize = 13
};
uiStyleLabelMedium.normal.textColor = Color.white;

uiStyleLabelHint = new GUIStyle(HighLogic.Skin.label);
uiStyleLabelHint.stretchWidth = true;
uiStyleLabelHint.font = uiFont;
uiStyleLabelHint.fontStyle = FontStyle.Normal;
uiStyleLabelHint.fontSize = 11;
uiStyleLabelHint = new GUIStyle(HighLogic.Skin.label) {
stretchWidth = true,
font = uiFont,
fontStyle = FontStyle.Normal,
fontSize = 11
};
uiStyleLabelHint.normal.textColor = Color.white;

uiStyleButton = new GUIStyle(HighLogic.Skin.button);
Expand Down Expand Up @@ -84,10 +87,11 @@ public static void ConfigureStyles()
uiStyleSliderThumb.fixedWidth = 0f;
uiStyleSliderThumb.fixedHeight = 16;

uiStyleToggle = new GUIStyle(HighLogic.Skin.toggle);
uiStyleToggle.font = uiFont;
uiStyleToggle.fontStyle = FontStyle.Normal;
uiStyleToggle.fontSize = 11;
uiStyleToggle = new GUIStyle(HighLogic.Skin.toggle) {
font = uiFont,
fontStyle = FontStyle.Normal,
fontSize = 11
};
uiStyleToggle.normal.textColor = Color.white;
uiStyleToggle.padding = new RectOffset(4, 4, 4, 4);
uiStyleToggle.margin = new RectOffset(4, 4, 4, 4);
Expand All @@ -114,7 +118,10 @@ private static void AssignTexturesToStyle(GUIStyle s)
public static float FieldSlider(float value, float increment, float incrementLarge, Vector2 limits, string name, out bool changed, Color backgroundColor, int valueType, bool allowFine = true)
{
if (!UIUtility.uiStyleConfigured)
{
UIUtility.ConfigureStyles();
}

GUILayout.BeginHorizontal();
double range = limits.y - limits.x;
double value01 = (value - limits.x) / range; // rescaling value to be <0-1> of range for convenience
Expand All @@ -124,25 +131,33 @@ public static float FieldSlider(float value, float increment, float incrementLar

GUILayout.Label(string.Empty, UIUtility.uiStyleLabelHint);
Rect rectLast = GUILayoutUtility.GetLastRect();
Rect rectSlider = new Rect(rectLast.xMin + buttonWidth + spaceWidth, rectLast.yMin, rectLast.width - 2 * (buttonWidth + spaceWidth), rectLast.height);
Rect rectSliderValue = new Rect(rectSlider.xMin, rectSlider.yMin, rectSlider.width * (float)value01, rectSlider.height - 3f);
Rect rectButtonL = new Rect(rectLast.xMin, rectLast.yMin, buttonWidth, rectLast.height);
Rect rectButtonR = new Rect(rectLast.xMin + rectLast.width - buttonWidth, rectLast.yMin, buttonWidth, rectLast.height);
Rect rectLabelValue = new Rect(rectSlider.xMin + rectSlider.width * 0.75f, rectSlider.yMin, rectSlider.width * 0.25f, rectSlider.height);
var rectSlider = new Rect(rectLast.xMin + buttonWidth + spaceWidth, rectLast.yMin, rectLast.width - 2 * (buttonWidth + spaceWidth), rectLast.height);
var rectSliderValue = new Rect(rectSlider.xMin, rectSlider.yMin, rectSlider.width * (float)value01, rectSlider.height - 3f);
var rectButtonL = new Rect(rectLast.xMin, rectLast.yMin, buttonWidth, rectLast.height);
var rectButtonR = new Rect(rectLast.xMin + rectLast.width - buttonWidth, rectLast.yMin, buttonWidth, rectLast.height);
var rectLabelValue = new Rect(rectSlider.xMin + rectSlider.width * 0.75f, rectSlider.yMin, rectSlider.width * 0.25f, rectSlider.height);

if (GUI.Button(rectButtonL, string.Empty, UIUtility.uiStyleButton))
{
if (Input.GetMouseButtonUp(0) || !allowFine)
{
value01 -= incrementLarge / range;
}
else if (Input.GetMouseButtonUp(1) && allowFine)
{
value01 -= increment01;
}
}
if (GUI.Button(rectButtonR, string.Empty, UIUtility.uiStyleButton))
{
if (Input.GetMouseButtonUp(0) || !allowFine)
{
value01 += incrementLarge / range;
}
else if (Input.GetMouseButtonUp(1) && allowFine)
{
value01 += increment01;
}
}

if (rectLast.Contains(Event.current.mousePosition) && (Event.current.type == EventType.MouseDrag || Event.current.type == EventType.MouseDown) // right click drag doesn't work properly without the event check
Expand All @@ -165,7 +180,9 @@ public static float FieldSlider(float value, float increment, float incrementLar
}
}
else
{
GUI.HorizontalSlider(rectSlider, (float)value01, 0f, 1f, UIUtility.uiStyleSlider, UIUtility.uiStyleSliderThumb);
}

value = Mathf.Clamp((float)(value01 * range + limits.x), Mathf.Min((float)(limits.x * 0.5), limits.x), limits.y); // lower limit is halved so the fine control can reduce it further but the normal tweak still snaps. Min makes -ve values work
changed = valueOld != value;
Expand Down Expand Up @@ -206,10 +223,12 @@ public static Rect SetToScreenCenterAlways(this Rect r)
public static double TextEntryForDouble(string label, int labelWidth, double prevValue)
{
string valString = prevValue.ToString();
UIUtility.TextEntryField(label, labelWidth, ref valString);
TextEntryField(label, labelWidth, ref valString);

if (!double.TryParse(valString, out double temp))
{
return prevValue;
}

return temp;
}
Expand Down
8 changes: 7 additions & 1 deletion B9 PWings Fork/UtilityTexture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,16 @@ static public Texture2D GetTexture2D(this Color c)
{
int colorKey = c.ToInt();
if (textures == null)
{
textures = new Dictionary<int, Texture2D>();
}

if (textures.ContainsKey(colorKey) && textures[colorKey] != null)
{
return textures[colorKey];
Texture2D tex = new Texture2D(1, 1, TextureFormat.ARGB32, false);
}

var tex = new Texture2D(1, 1, TextureFormat.ARGB32, false);
tex.SetPixel(0, 0, c);
tex.Apply();
textures.Add(colorKey, tex);
Expand Down
Loading

0 comments on commit bb99f30

Please sign in to comment.