Skip to content

Commit

Permalink
Add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
cake-pie committed Jun 23, 2017
1 parent c8de8f8 commit eb6a9ae
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Source/CTIAddon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@

namespace CommunityTraitIcons
{
// CTIAddon runs once when game first loads into the main menu scene, reads trait icon settings from config file, and makes them available for lookup.
[KSPAddon(KSPAddon.Startup.MainMenu, true)]
public class CTIAddon : MonoBehaviour
{
// have the trait icon settings been loaded from file yet?
public static bool Loaded { get; private set; }

private static Dictionary<string, KerbalTraitSetting> traitSettings = new Dictionary<string, KerbalTraitSetting>();
Expand All @@ -17,6 +19,7 @@ internal static void log(string s, params object[] m)
Debug.Log(string.Format("[Community Trait Icons] " + s, m));
}

// reads trait icon settings from config file
private void Start()
{
if (!Loaded)
Expand Down Expand Up @@ -93,6 +96,7 @@ private Color parseColor(ConfigNode node, string name, Color c)
}
}

// lookup trait icon settings by trait name (ProtoCrewMember.experienceTrait.TypeName)
public static KerbalTraitSetting getTrait(string traitName)
{
if (!Loaded) return null;
Expand Down
11 changes: 11 additions & 0 deletions Source/KerbalTraitSetting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,34 @@ public KerbalTraitSetting(string name, Texture2D icon, Color color)
Color = color;
}

#region Icon Generation
// Generate a Sprite of the icon for this trait. Note: not tinted with color.
public Sprite makeSprite()
{
if (Icon == null) return null;
return Sprite.Create(Icon, new Rect(0, 0, Icon.width, Icon.height), new Vector2(0.5f, 0.5f));
}

// Generate a KSP DialogGUIImage of the icon for this trait.
public DialogGUIImage makeDialogGUIImage(Vector2 s, Vector2 p)
{
if (Icon == null || Color == null) return null;
return new DialogGUIImage(s,p,Color,Icon);
}

// Generate a KSP DialogGUISprite of the icon for this trait.
public DialogGUISprite makeDialogGUISprite(Vector2 s, Vector2 p)
{
if (Icon == null || Color == null) return null;
return new DialogGUISprite(s,p,Color,makeSprite());
}

// Generate a GameObject with an Image component of the icon for this trait.
// Also comes with RectTransform and CanvasRenderer.
// After obtaining the GameObject, you will most likely likely want to:
// - Set its parent: go.transform.SetParent(parent, false);
// - Make it active: go.SetActive(true);
// - Position it manually by manipulating its RectTransform, or automatically using Unity's auto layout system
public GameObject makeGameObject()
{
if (Icon == null || Color == null) return null;
Expand All @@ -50,5 +60,6 @@ public GameObject makeGameObject()

return icon;
}
#endregion Icon Generation
}
}

0 comments on commit eb6a9ae

Please sign in to comment.