1 using Microsoft.Xna.Framework;
7 partial class PowerTransfer : Powered
9 private GUITickBox powerIndicator;
10 private GUITickBox highVoltageIndicator;
11 private GUITickBox lowVoltageIndicator;
13 private GUITextBlock powerLabel, loadLabel;
15 private LanguageIdentifier prevLanguage;
17 partial
void InitProjectSpecific(XElement element)
27 var lightsArea =
new GUILayoutGroup(
new RectTransform(
new Vector2(0.4f, 1), paddedFrame.RectTransform,
Anchor.CenterLeft))
31 powerIndicator =
new GUITickBox(
new RectTransform(
new Vector2(1, 0.33f), lightsArea.RectTransform),
32 TextManager.Get(
"PowerTransferPowered"), font: GUIStyle.SubHeadingFont, style:
"IndicatorLightGreen")
36 highVoltageIndicator =
new GUITickBox(
new RectTransform(
new Vector2(1, 0.33f), lightsArea.RectTransform),
37 TextManager.Get(
"PowerTransferHighVoltage"), font: GUIStyle.SubHeadingFont, style:
"IndicatorLightRed")
39 ToolTip = TextManager.Get(
"PowerTransferTipOvervoltage"),
42 lowVoltageIndicator =
new GUITickBox(
new RectTransform(
new Vector2(1, 0.33f), lightsArea.RectTransform),
43 TextManager.Get(
"PowerTransferLowVoltage"), font: GUIStyle.SubHeadingFont, style:
"IndicatorLightRed")
45 ToolTip = TextManager.Get(
"PowerTransferTipLowvoltage"),
48 powerIndicator.TextBlock.OverrideTextColor(GUIStyle.TextColorNormal);
49 highVoltageIndicator.TextBlock.OverrideTextColor(GUIStyle.TextColorNormal);
50 lowVoltageIndicator.TextBlock.OverrideTextColor(GUIStyle.TextColorNormal);
51 GUITextBlock.AutoScaleAndNormalize(powerIndicator.TextBlock, highVoltageIndicator.TextBlock, lowVoltageIndicator.TextBlock);
53 var textContainer =
new GUIFrame(
new RectTransform(
new Vector2(0.58f, 1.0f), paddedFrame.RectTransform,
Anchor.CenterRight), style:
null);
54 var upperTextArea =
new GUILayoutGroup(
new RectTransform(
new Vector2(1.0f, 0.5f), textContainer.RectTransform,
Anchor.TopLeft), isHorizontal:
true, childAnchor:
Anchor.CenterLeft)
58 var lowerTextArea =
new GUILayoutGroup(
new RectTransform(
new Vector2(1.0f, 0.5f), textContainer.RectTransform,
Anchor.BottomLeft), isHorizontal:
true, childAnchor:
Anchor.CenterLeft)
63 powerLabel =
new GUITextBlock(
new RectTransform(
new Vector2(0.4f, 1), upperTextArea.RectTransform),
64 TextManager.Get(
"PowerTransferPowerLabel"), textColor: GUIStyle.TextColorBright, font: GUIStyle.LargeFont, textAlignment: Alignment.CenterRight)
66 ToolTip = TextManager.Get(
"PowerTransferTipPower")
68 loadLabel =
new GUITextBlock(
new RectTransform(
new Vector2(0.4f, 1), lowerTextArea.RectTransform),
69 TextManager.Get(
"PowerTransferLoadLabel"), textColor: GUIStyle.TextColorBright, font: GUIStyle.LargeFont, textAlignment: Alignment.CenterRight)
71 ToolTip = TextManager.Get(
"PowerTransferTipLoad")
74 var digitalBackground =
new GUIFrame(
new RectTransform(
new Vector2(0.55f, 0.8f), upperTextArea.RectTransform), style:
"DigitalFrameDark");
75 var powerText =
new GUITextBlock(
new RectTransform(
new Vector2(0.9f, 0.95f), digitalBackground.RectTransform,
Anchor.Center),
76 "", font: GUIStyle.DigitalFont, textColor: GUIStyle.TextColorDark)
78 TextAlignment = Alignment.CenterRight,
79 ToolTip = TextManager.Get(
"PowerTransferTipPower"),
86 return ((
int)Math.Round(currPower)).ToString();
89 var kw1 =
new GUITextBlock(
new RectTransform(
new Vector2(0.15f, 0.5f), upperTextArea.RectTransform),
90 TextManager.Get(
"kilowatt"), textColor: GUIStyle.TextColorNormal, font: GUIStyle.Font)
92 Padding = Vector4.Zero,
93 TextAlignment = Alignment.BottomCenter
96 digitalBackground =
new GUIFrame(
new RectTransform(
new Vector2(0.55f, 0.8f), lowerTextArea.RectTransform), style:
"DigitalFrameDark");
97 var loadText =
new GUITextBlock(
new RectTransform(
new Vector2(0.9f, 0.95f), digitalBackground.RectTransform,
Anchor.Center),
98 "", font: GUIStyle.DigitalFont, textColor: GUIStyle.TextColorDark)
100 TextAlignment = Alignment.CenterRight,
101 ToolTip = TextManager.Get(
"PowerTransferTipLoad"),
105 if (
this is RelayComponent relay)
107 load = relay.DisplayLoad;
113 return ((
int)Math.Round(load)).ToString();
116 var kw2 =
new GUITextBlock(
new RectTransform(
new Vector2(0.15f, 0.5f), lowerTextArea.RectTransform),
117 TextManager.Get(
"kilowatt"), textColor: GUIStyle.TextColorNormal, font: GUIStyle.Font)
119 Padding = Vector4.Zero,
120 TextAlignment = Alignment.BottomCenter
123 GUITextBlock.AutoScaleAndNormalize(powerLabel, loadLabel);
124 GUITextBlock.AutoScaleAndNormalize(
true,
true, powerText, loadText);
125 GUITextBlock.AutoScaleAndNormalize(kw1, kw2);
127 prevLanguage = GameSettings.CurrentConfig.Language;
135 powerIndicator.Selected =
IsActive && voltage > 0;
136 highVoltageIndicator.Selected = Timing.TotalTime % 0.5f < 0.25f && powerIndicator.Selected && voltage > 1.2f;
137 lowVoltageIndicator.Selected = Timing.TotalTime % 0.5f < 0.25f && powerIndicator.Selected && voltage < 0.8f;
139 if (prevLanguage != GameSettings.CurrentConfig.Language)
143 prevLanguage = GameSettings.CurrentConfig.Language;
RectTransform RectTransform
static void AutoScaleAndNormalize(params GUITextBlock[] textBlocks)
Set the text scale of the GUITextBlocks so that they all use the same scale and can fit the text with...
List< Connection > PowerConnections
override void UpdateHUDComponentSpecific(Character character, float deltaTime, Camera cam)