Skip to content

Commit

Permalink
Gui fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
rbray89 committed Dec 24, 2013
1 parent 169dee4 commit d33b538
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 19 deletions.
7 changes: 6 additions & 1 deletion Clouds/CloudLayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace Clouds
internal class CloudLayer
{
public static Dictionary<String, List<CloudLayer>> BodyDatabase = new Dictionary<string, List<CloudLayer>>();
public static List<CloudLayer> Layers = new List<CloudLayer>();
private static Shader GlobalCloudShader;
private static Shader GlobalUndersideCloudShader;
private Material CloudMaterial;
Expand Down Expand Up @@ -274,11 +275,15 @@ internal static bool IsDefaultShaderFloat(ShaderFloats shaderFloats, bool isUnde
}
}

internal void Remove()
internal void Remove(bool fromList = true)
{
this.CloudOverlay.RemoveOverlay();
this.UndersideCloudOverlay.RemoveOverlay();
BodyDatabase[body].Remove(this);
if (fromList)
{
Layers.Remove(this);
}
}
}
}
56 changes: 40 additions & 16 deletions Clouds/Clouds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ namespace Clouds
[KSPAddon(KSPAddon.Startup.EveryScene, false)]
public class Clouds : MonoBehaviour
{
static List<CloudLayer> CloudLayers = new List<CloudLayer>();
static bool Loaded = false;
static KeyCode GUI_KEYCODE = KeyCode.N;

Expand All @@ -34,11 +33,11 @@ public class Clouds : MonoBehaviour

private void loadCloudLayers(String configString)
{
foreach (CloudLayer cl in CloudLayers)
foreach (CloudLayer cl in CloudLayer.Layers)
{
cl.Remove();
cl.Remove(false);
}
CloudLayers.Clear();
CloudLayer.Layers.Clear();
if (configString == null)
{
configString = KSPUtil.ApplicationRootPath + "GameData/BoulderCo/Clouds/userCloudLayers.cfg";
Expand Down Expand Up @@ -100,9 +99,10 @@ private void loadCloudLayers(String configString)
Color color = new Color(
float.Parse(colorNode.GetValue("r")),
float.Parse(colorNode.GetValue("g")),
float.Parse(colorNode.GetValue("b")));
float.Parse(colorNode.GetValue("b")),
float.Parse(colorNode.GetValue("a")));

CloudLayers.Add(
CloudLayer.Layers.Add(
new CloudLayer(body, color, radius,
mTexture, dTexture, bTexture, shaderFloats, undersideShaderFloats));
}
Expand Down Expand Up @@ -139,6 +139,7 @@ private void saveCloudLayers(String configString)
colorNode.AddValue("r", cloudLayer.Color.r);
colorNode.AddValue("g", cloudLayer.Color.g);
colorNode.AddValue("b", cloudLayer.Color.b);
colorNode.AddValue("a", cloudLayer.Color.a);
newNode.AddNode(cloudLayer.MainTexture.GetNode("main_texture"));
ConfigNode detailNode = cloudLayer.DetailTexture.GetNode("detail_texture");
if (detailNode != null)
Expand Down Expand Up @@ -523,7 +524,7 @@ protected void Awake()
protected void Update()
{

foreach (CloudLayer layer in CloudLayers)
foreach (CloudLayer layer in CloudLayer.Layers)
{
layer.PerformUpdate();
}
Expand Down Expand Up @@ -588,7 +589,7 @@ private void OnGUI()
}
if (CloudLayer.GetBodyLayerCount(current.name) != 0)
{
_mainWindowRect.height = 715;
_mainWindowRect.height = 745;
_mainWindowRect = GUI.Window(0x8100, _mainWindowRect, DrawMainWindow, "Clouds");
}
else
Expand Down Expand Up @@ -641,13 +642,13 @@ private void DrawMainWindow(int windowID)
//{
// spawnVolumeClouds();
//}
halfWidth = (itemFullWidth / 2) - 5;
if (GUI.Button(new Rect(itemFullWidth + 20, 50, halfWidth, 25), "Reset to Save"))
halfWidth = (itemFullWidth / 2);
if (GUI.Button(new Rect(itemFullWidth + 30, 50, halfWidth, 25), "Reset to Save"))
{
loadCloudLayers(null);
oldBody = null;
}
if (GUI.Button(new Rect(itemFullWidth + (itemFullWidth / 2) + 20, 50, halfWidth, 25), "Reset to Default"))
if (GUI.Button(new Rect(itemFullWidth + halfWidth + 35, 50, halfWidth-5, 25), "Reset to Default"))
{
loadCloudLayers("cloudLayers.cfg");
oldBody = null;
Expand All @@ -660,8 +661,8 @@ private void DrawMainWindow(int windowID)
halfWidth = hasLayers ? (itemFullWidth / 2) - 5 : itemFullWidth;
if (GUI.Button(new Rect(10, 80, halfWidth, 25), "Add"))
{
CloudLayers.Add(
new CloudLayer(currentBody.name, new Color(1, 1, 1), 1.01f,
CloudLayer.Layers.Add(
new CloudLayer(currentBody.name, new Color(1, 1, 1, 1), 1.01f,
new TextureSet(), new TextureSet(), new TextureSet(), null, null));
}
if (hasLayers)
Expand All @@ -670,6 +671,7 @@ private void DrawMainWindow(int windowID)
if (GUI.Button(new Rect(halfWidth + 20, 80, halfWidth, 25), "Remove"))
{
CloudLayer.RemoveLayer(currentBody.name, SelectedLayer);
return;
}
GUI.Box(new Rect(10, 110, itemFullWidth, 115), "");
String[] layerList = CloudLayer.GetBodyLayerStringList(currentBody.name);
Expand All @@ -696,7 +698,11 @@ private void DrawMainWindow(int windowID)

if (CloudGUI.IsValid())
{
if (GUI.Button(new Rect(145, 50, 105, 25), "Apply & Save"))
if (GUI.Button(new Rect(145, 50, 50, 25), "Apply"))
{
CloudLayer.BodyDatabase[currentBody.name][SelectedLayer].ApplyGUIUpdate(CloudGUI);
}
if (GUI.Button(new Rect(200, 50, 50, 25), "Save"))
{
CloudLayer.BodyDatabase[currentBody.name][SelectedLayer].ApplyGUIUpdate(CloudGUI);
saveCloudLayers(null);
Expand Down Expand Up @@ -945,8 +951,26 @@ private int HandleColorGUI(ColorSetGUI color, int y)
}
string SBlue = GUI.TextField(new Rect(80, y, 50, 25), color.Blue, texFieldGS);
float FBlue = GUI.HorizontalSlider(new Rect(135, y + 5, 115, 25), color.Color.b, 0, 1);

color.Update(SRed, FRed, SGreen, FGreen, SBlue, FBlue);
y += 30;
GUI.Label(
new Rect(10, y, 65, 25), "A: ", gs);
if (float.TryParse(color.Alpha, out dummyFloat))
{
texFieldGS.normal.textColor = normalColor;
texFieldGS.hover.textColor = normalColor;
texFieldGS.active.textColor = normalColor;
texFieldGS.focused.textColor = normalColor;
}
else
{
texFieldGS.normal.textColor = errorColor;
texFieldGS.hover.textColor = errorColor;
texFieldGS.active.textColor = errorColor;
texFieldGS.focused.textColor = errorColor;
}
string SAlpha = GUI.TextField(new Rect(80, y, 50, 25), color.Alpha, texFieldGS);
float FAlpha = GUI.HorizontalSlider(new Rect(135, y + 5, 115, 25), color.Color.a, 0, 1);
color.Update(SRed, FRed, SGreen, FGreen, SBlue, FBlue, SAlpha, FAlpha);
return y += 30;
}

Expand Down
17 changes: 15 additions & 2 deletions CommonUtils/GuiUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,18 @@ public class ColorSetGUI
public string Red = "";
public string Green = "";
public string Blue = "";
public string Alpha = "";

public void Clone(Color color)
{
this.Color = color;
this.Red = color.r.ToString("R");
this.Green = color.g.ToString("R");
this.Blue = color.b.ToString("R");
this.Alpha = color.a.ToString("R");
}

public void Update(string SRed, float FRed, string SGreen, float FGreen, string SBlue, float FBlue)
public void Update(string SRed, float FRed, string SGreen, float FGreen, string SBlue, float FBlue, String SAlpha, float FAlpha)
{
if (this.Red != SRed)
{
Expand Down Expand Up @@ -86,14 +88,25 @@ public void Update(string SRed, float FRed, string SGreen, float FGreen, string
this.Color.b = FBlue;
this.Blue = FBlue.ToString("R");
}
if (this.Alpha != SAlpha)
{
this.Alpha = SAlpha;
float.TryParse(SAlpha, out this.Color.a);
}
else if (this.Color.a != FAlpha)
{
this.Color.a = FAlpha;
this.Alpha = FAlpha.ToString("R");
}
}

public bool IsValid()
{
float dummy;
if (float.TryParse(Red, out dummy) &&
float.TryParse(Green, out dummy) &&
float.TryParse(Blue, out dummy))
float.TryParse(Blue, out dummy) &&
float.TryParse(Alpha, out dummy))
{
return true;
}
Expand Down
18 changes: 18 additions & 0 deletions GameData/BoulderCo/Clouds/cloudLayers.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ CLOUD_LAYER
r = 0.4
g = 0.4
b = 0.6
a = 1
}
main_texture
{
Expand Down Expand Up @@ -49,6 +50,7 @@ CLOUD_LAYER
r = 0.38
g = 0.16
b = 0.098
a = 1
}
main_texture
{
Expand Down Expand Up @@ -89,6 +91,7 @@ CLOUD_LAYER
r = 1
g = 1
b = 1
a = 1
}
main_texture
{
Expand Down Expand Up @@ -144,6 +147,7 @@ CLOUD_LAYER
r = 0.909
g = 0.909
b = 0.878
a = 1
}
main_texture
{
Expand Down Expand Up @@ -199,6 +203,7 @@ CLOUD_LAYER
r = 0.314
g = 0.216
b = 0.435
a = 1
}
main_texture
{
Expand Down Expand Up @@ -239,6 +244,7 @@ CLOUD_LAYER
r = 0.314
g = 0.216
b = 0.435
a = 1
}
main_texture
{
Expand Down Expand Up @@ -279,6 +285,7 @@ CLOUD_LAYER
r = 0.411
g = 0.204
b = 0.663
a = 1
}
main_texture
{
Expand Down Expand Up @@ -319,6 +326,7 @@ CLOUD_LAYER
r = 0.411
g = 0.204
b = 0.663
a = 1
}
main_texture
{
Expand Down Expand Up @@ -359,6 +367,7 @@ CLOUD_LAYER
r = 0.643
g = 0.424
b = 0.914
a = 1
}
main_texture
{
Expand Down Expand Up @@ -399,6 +408,7 @@ CLOUD_LAYER
r = 0.102
g = 0.169
b = 0.063
a = 1
}
main_texture
{
Expand Down Expand Up @@ -439,6 +449,7 @@ CLOUD_LAYER
r = 0.102
g = 0.169
b = 0.063
a = 1
}
main_texture
{
Expand Down Expand Up @@ -479,6 +490,7 @@ CLOUD_LAYER
r = 0.102
g = 0.169
b = 0.063
a = 1
}
main_texture
{
Expand Down Expand Up @@ -551,6 +563,7 @@ CLOUD_LAYER
r = 0.694
g = 0.62
b = 0.567
a = 1
}
}
Expand Down Expand Up @@ -607,6 +620,7 @@ CLOUD_LAYER
r = 1
g = 1
b = 1
a = 1
}
}
Expand Down Expand Up @@ -663,6 +677,7 @@ CLOUD_LAYER
r = 1
g = 1
b = 1
a = 1
}
}
Expand Down Expand Up @@ -704,6 +719,7 @@ CLOUD_LAYER
r = 0.102
g = 0.169
b = 0.063
a = 1
}
}
Expand Down Expand Up @@ -745,6 +761,7 @@ CLOUD_LAYER
r = 0.102
g = 0.169
b = 0.063
a = 1
}
}
Expand Down Expand Up @@ -786,5 +803,6 @@ CLOUD_LAYER
r = 0.102
g = 0.169
b = 0.063
a = 1
}
}
Binary file modified GameData/BoulderCo/Plugins/CityLights.dll
Binary file not shown.
Binary file modified GameData/BoulderCo/Plugins/Clouds.dll
Binary file not shown.
Binary file modified GameData/BoulderCo/Plugins/CommonUtils.dll
Binary file not shown.
Binary file modified GameData/BoulderCo/Plugins/Equirectangular2Cubic.dll
Binary file not shown.

0 comments on commit d33b538

Please sign in to comment.