Release 1.9.7.0 - Summer Update 2025
This commit is contained in:
@@ -6,125 +6,84 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
partial class PowerTransfer : Powered
|
||||
{
|
||||
public override bool RecreateGUIOnResolutionChange => true;
|
||||
protected GUIComponent guiContent;
|
||||
|
||||
private GUITickBox powerIndicator;
|
||||
private GUITickBox highVoltageIndicator;
|
||||
private GUITickBox lowVoltageIndicator;
|
||||
|
||||
private GUITextBlock powerLabel, loadLabel;
|
||||
protected GUITextBlock powerDisplay, loadDisplay;
|
||||
|
||||
private LanguageIdentifier prevLanguage;
|
||||
protected LanguageIdentifier prevLanguage;
|
||||
|
||||
partial void InitProjectSpecific(XElement element)
|
||||
{
|
||||
if (GuiFrame == null) { return; }
|
||||
CreateGUI();
|
||||
prevLanguage = GameSettings.CurrentConfig.Language;
|
||||
}
|
||||
|
||||
var paddedFrame = new GUIFrame(new RectTransform(GuiFrame.Rect.Size - GUIStyle.ItemFrameMargin, GuiFrame.RectTransform, Anchor.Center) { AbsoluteOffset = GUIStyle.ItemFrameOffset },
|
||||
style: null)
|
||||
protected override void CreateGUI()
|
||||
{
|
||||
if (GuiFrame == null) { return; }
|
||||
guiContent = new GUIFrame(new RectTransform(GuiFrame.Rect.Size - GUIStyle.ItemFrameMargin, GuiFrame.RectTransform, Anchor.Center) { AbsoluteOffset = GUIStyle.ItemFrameOffset }, style: null)
|
||||
{
|
||||
CanBeFocused = false
|
||||
};
|
||||
CreateDefaultPowerUI(guiContent);
|
||||
}
|
||||
|
||||
var lightsArea = new GUILayoutGroup(new RectTransform(new Vector2(0.4f, 1), paddedFrame.RectTransform, Anchor.CenterLeft))
|
||||
protected void CreateDefaultPowerUI(GUIComponent parent)
|
||||
{
|
||||
GUILayoutGroup lightsArea = new(new RectTransform(new Vector2(0.4f, 1f), parent.RectTransform, Anchor.CenterLeft))
|
||||
{
|
||||
Stretch = true
|
||||
};
|
||||
powerIndicator = new GUITickBox(new RectTransform(new Vector2(1, 0.33f), lightsArea.RectTransform),
|
||||
TextManager.Get("PowerTransferPowered"), font: GUIStyle.SubHeadingFont, style: "IndicatorLightGreen")
|
||||
{
|
||||
CanBeFocused = false
|
||||
};
|
||||
highVoltageIndicator = new GUITickBox(new RectTransform(new Vector2(1, 0.33f), lightsArea.RectTransform),
|
||||
TextManager.Get("PowerTransferHighVoltage"), font: GUIStyle.SubHeadingFont, style: "IndicatorLightRed")
|
||||
{
|
||||
ToolTip = TextManager.Get("PowerTransferTipOvervoltage"),
|
||||
Enabled = false
|
||||
};
|
||||
lowVoltageIndicator = new GUITickBox(new RectTransform(new Vector2(1, 0.33f), lightsArea.RectTransform),
|
||||
TextManager.Get("PowerTransferLowVoltage"), font: GUIStyle.SubHeadingFont, style: "IndicatorLightRed")
|
||||
{
|
||||
ToolTip = TextManager.Get("PowerTransferTipLowvoltage"),
|
||||
Enabled = false
|
||||
};
|
||||
powerIndicator.TextBlock.OverrideTextColor(GUIStyle.TextColorNormal);
|
||||
highVoltageIndicator.TextBlock.OverrideTextColor(GUIStyle.TextColorNormal);
|
||||
lowVoltageIndicator.TextBlock.OverrideTextColor(GUIStyle.TextColorNormal);
|
||||
powerIndicator = GUI.CreateIndicatorLight(new RectTransform(new Vector2(1, 0.33f), lightsArea.RectTransform),
|
||||
"IndicatorLightGreen", TextManager.Get("PowerTransferPowered"));
|
||||
highVoltageIndicator = GUI.CreateIndicatorLight(new RectTransform(new Vector2(1, 0.33f), lightsArea.RectTransform),
|
||||
"IndicatorLightRed", TextManager.Get("PowerTransferHighVoltage"), TextManager.Get("PowerTransferTipOvervoltage"));
|
||||
lowVoltageIndicator = GUI.CreateIndicatorLight(new RectTransform(new Vector2(1, 0.33f), lightsArea.RectTransform),
|
||||
"IndicatorLightRed", TextManager.Get("PowerTransferLowVoltage"), TextManager.Get("PowerTransferTipLowvoltage"));
|
||||
GUITextBlock.AutoScaleAndNormalize(powerIndicator.TextBlock, highVoltageIndicator.TextBlock, lowVoltageIndicator.TextBlock);
|
||||
|
||||
var textContainer = new GUIFrame(new RectTransform(new Vector2(0.58f, 1.0f), paddedFrame.RectTransform, Anchor.CenterRight), style: null);
|
||||
var upperTextArea = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.5f), textContainer.RectTransform, Anchor.TopLeft), isHorizontal: true, childAnchor: Anchor.CenterLeft)
|
||||
{
|
||||
Stretch = true
|
||||
};
|
||||
var lowerTextArea = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.5f), textContainer.RectTransform, Anchor.BottomLeft), isHorizontal: true, childAnchor: Anchor.CenterLeft)
|
||||
{
|
||||
Stretch = true
|
||||
};
|
||||
GUIFrame textContainer = new(new RectTransform(new Vector2(0.58f, 1f), parent.RectTransform, Anchor.CenterRight), style: null);
|
||||
|
||||
powerLabel = new GUITextBlock(new RectTransform(new Vector2(0.4f, 1), upperTextArea.RectTransform),
|
||||
TextManager.Get("PowerTransferPowerLabel"), textColor: GUIStyle.TextColorBright, font: GUIStyle.LargeFont, textAlignment: Alignment.CenterRight)
|
||||
{
|
||||
ToolTip = TextManager.Get("PowerTransferTipPower")
|
||||
};
|
||||
loadLabel = new GUITextBlock(new RectTransform(new Vector2(0.4f, 1), lowerTextArea.RectTransform),
|
||||
TextManager.Get("PowerTransferLoadLabel"), textColor: GUIStyle.TextColorBright, font: GUIStyle.LargeFont, textAlignment: Alignment.CenterRight)
|
||||
{
|
||||
ToolTip = TextManager.Get("PowerTransferTipLoad")
|
||||
};
|
||||
powerDisplay = GUI.CreateDigitalDisplay(new RectTransform(new Vector2(1f, 0.5f), textContainer.RectTransform, Anchor.TopLeft),
|
||||
out powerLabel, out GUITextBlock unitLabel1, TextManager.Get("PowerTransferPowerLabel"), TextManager.Get("kilowatt"), TextManager.Get("PowerTransferTipPower"));
|
||||
|
||||
var digitalBackground = new GUIFrame(new RectTransform(new Vector2(0.55f, 0.8f), upperTextArea.RectTransform), style: "DigitalFrameDark");
|
||||
var powerText = new GUITextBlock(new RectTransform(new Vector2(0.9f, 0.95f), digitalBackground.RectTransform, Anchor.Center),
|
||||
"", font: GUIStyle.DigitalFont, textColor: GUIStyle.TextColorDark)
|
||||
powerDisplay.TextGetter = () =>
|
||||
{
|
||||
TextAlignment = Alignment.CenterRight,
|
||||
ToolTip = TextManager.Get("PowerTransferTipPower"),
|
||||
TextGetter = () => {
|
||||
float currPower = powerLoad < 0 ? -powerLoad: 0;
|
||||
if (this is not RelayComponent && PowerConnections != null && PowerConnections.Count > 0 && PowerConnections[0].Grid != null)
|
||||
{
|
||||
currPower = PowerConnections[0].Grid.Power;
|
||||
}
|
||||
return ((int)Math.Round(currPower)).ToString();
|
||||
}
|
||||
};
|
||||
var kw1 = new GUITextBlock(new RectTransform(new Vector2(0.15f, 0.5f), upperTextArea.RectTransform),
|
||||
TextManager.Get("kilowatt"), textColor: GUIStyle.TextColorNormal, font: GUIStyle.Font)
|
||||
{
|
||||
Padding = Vector4.Zero,
|
||||
TextAlignment = Alignment.BottomCenter
|
||||
};
|
||||
|
||||
digitalBackground = new GUIFrame(new RectTransform(new Vector2(0.55f, 0.8f), lowerTextArea.RectTransform), style: "DigitalFrameDark");
|
||||
var loadText = new GUITextBlock(new RectTransform(new Vector2(0.9f, 0.95f), digitalBackground.RectTransform, Anchor.Center),
|
||||
"", font: GUIStyle.DigitalFont, textColor: GUIStyle.TextColorDark)
|
||||
{
|
||||
TextAlignment = Alignment.CenterRight,
|
||||
ToolTip = TextManager.Get("PowerTransferTipLoad"),
|
||||
TextGetter = () =>
|
||||
float currPower = powerLoad < 0 ? -powerLoad : 0;
|
||||
if (this is not RelayComponent && PowerConnections != null && PowerConnections.Count > 0 && PowerConnections[0].Grid != null)
|
||||
{
|
||||
float load = PowerLoad;
|
||||
if (this is RelayComponent relay)
|
||||
{
|
||||
load = relay.DisplayLoad;
|
||||
}
|
||||
else if (load < 0)
|
||||
{
|
||||
load = 0;
|
||||
}
|
||||
return ((int)Math.Round(load)).ToString();
|
||||
currPower = PowerConnections[0].Grid.Power;
|
||||
}
|
||||
return MathUtils.RoundToInt(currPower).ToString();
|
||||
};
|
||||
var kw2 = new GUITextBlock(new RectTransform(new Vector2(0.15f, 0.5f), lowerTextArea.RectTransform),
|
||||
TextManager.Get("kilowatt"), textColor: GUIStyle.TextColorNormal, font: GUIStyle.Font)
|
||||
|
||||
loadDisplay = GUI.CreateDigitalDisplay(new RectTransform(new Vector2(1f, 0.5f), textContainer.RectTransform, Anchor.BottomLeft),
|
||||
out loadLabel, out GUITextBlock unitLabel2, TextManager.Get("PowerTransferLoadLabel"), TextManager.Get("kilowatt"), TextManager.Get("PowerTransferTipLoad"));
|
||||
|
||||
loadDisplay.TextGetter = () =>
|
||||
{
|
||||
Padding = Vector4.Zero,
|
||||
TextAlignment = Alignment.BottomCenter
|
||||
float load = PowerLoad;
|
||||
if (this is RelayComponent relay)
|
||||
{
|
||||
load = relay.DisplayLoad;
|
||||
}
|
||||
else if (load < 0)
|
||||
{
|
||||
load = 0;
|
||||
}
|
||||
return MathUtils.RoundToInt(load).ToString();
|
||||
};
|
||||
|
||||
GUITextBlock.AutoScaleAndNormalize(powerLabel, loadLabel);
|
||||
GUITextBlock.AutoScaleAndNormalize(true, true, powerText, loadText);
|
||||
GUITextBlock.AutoScaleAndNormalize(kw1, kw2);
|
||||
|
||||
prevLanguage = GameSettings.CurrentConfig.Language;
|
||||
GUITextBlock.AutoScaleAndNormalize(true, true, powerDisplay, loadDisplay);
|
||||
GUITextBlock.AutoScaleAndNormalize(unitLabel1, unitLabel2);
|
||||
}
|
||||
|
||||
public override void UpdateHUDComponentSpecific(Character character, float deltaTime, Camera cam)
|
||||
|
||||
Reference in New Issue
Block a user