[Solved] Make WornGizmo to display my shield gauge

Started by Latta, February 27, 2015, 10:30:44 AM

Previous topic - Next topic

Latta

I made a custom shield by copy&paste decompiled PersonalShield class. But (as always) WornGizmo didn't decompiled correctly and I can't check my shield gauge.

Anyone know how to write this code?

Tynan

I do! I do!



internal class Gizmo_PersonalShieldStatus : Gizmo
{
//Links
public PersonalShield shield;

//Constants
private static readonly Texture2D FullTex = SolidColorMaterials.NewSolidColorTexture( new Color(0.2f, 0.2f, 0.24f) );
private static readonly Texture2D EmptyTex = SolidColorMaterials.NewSolidColorTexture( Color.clear );

//Properties
public override float Width{get { return 140; }}



public override GizmoResult GizmoOnGUI(UnityEngine.Vector2 topLeft)
{
Rect overRect = new Rect(topLeft.x, topLeft.y, Width, Height);
Widgets.DrawWindow(overRect);

Rect inRect = overRect.ContractedBy(6);

//Item label
{
Rect textRect = inRect;
textRect.height = overRect.height/2;
Text.Font = GameFont.Tiny;
Widgets.Label( textRect, shield.LabelCap );
}

//Bar
{
Rect barRect = inRect;
barRect.yMin = overRect.y + overRect.height/2f;
float ePct = shield.Energy/ Mathf.Max(1f, shield.GetStatValue(StatDefOf.PersonalShieldEnergyMax));
Widgets.FillableBar( barRect, ePct, FullTex, EmptyTex, false);
Text.Font = GameFont.Small;
Text.Anchor = TextAnchor.MiddleCenter;
Widgets.Label( barRect, (shield.Energy*100).ToString("F0") + " / " + (shield.GetStatValue(StatDefOf.PersonalShieldEnergyMax)*100).ToString("F0") );
Text.Anchor = TextAnchor.UpperLeft;
}

return new GizmoResult(GizmoState.Clear);
}


}
Tynan Sylvester - @TynanSylvester - Tynan's Blog

skullywag

God damn it why didnt i think to...you know..ask the dev...shiiiii
Skullywag modded to death.
I'd never met an iterator I liked....until Zhentar saved me.
Why Unity5, WHY do you forsake me?

Latta

Oooh yeah sweet smell of the original code!
Thank you. It's solved now.

KnucklyDuck

Quote from: Tynan on February 27, 2015, 05:10:37 PM
I do! I do!



internal class Gizmo_PersonalShieldStatus : Gizmo
{
//Links
public PersonalShield shield;

//Constants
private static readonly Texture2D FullTex = SolidColorMaterials.NewSolidColorTexture( new Color(0.2f, 0.2f, 0.24f) );
private static readonly Texture2D EmptyTex = SolidColorMaterials.NewSolidColorTexture( Color.clear );

//Properties
public override float Width{get { return 140; }}



public override GizmoResult GizmoOnGUI(UnityEngine.Vector2 topLeft)
{
Rect overRect = new Rect(topLeft.x, topLeft.y, Width, Height);
Widgets.DrawWindow(overRect);

Rect inRect = overRect.ContractedBy(6);

//Item label
{
Rect textRect = inRect;
textRect.height = overRect.height/2;
Text.Font = GameFont.Tiny;
Widgets.Label( textRect, shield.LabelCap );
}

//Bar
{
Rect barRect = inRect;
barRect.yMin = overRect.y + overRect.height/2f;
float ePct = shield.Energy/ Mathf.Max(1f, shield.GetStatValue(StatDefOf.PersonalShieldEnergyMax));
Widgets.FillableBar( barRect, ePct, FullTex, EmptyTex, false);
Text.Font = GameFont.Small;
Text.Anchor = TextAnchor.MiddleCenter;
Widgets.Label( barRect, (shield.Energy*100).ToString("F0") + " / " + (shield.GetStatValue(StatDefOf.PersonalShieldEnergyMax)*100).ToString("F0") );
Text.Anchor = TextAnchor.UpperLeft;
}

return new GizmoResult(GizmoState.Clear);
}


}


Show Off :P
Why do Java programmers have glasses?
.
.
Because they can't C#.