2 using Microsoft.Xna.Framework;
3 using Microsoft.Xna.Framework.Graphics;
9 partial class Engine : Powered, IDrawableComponent
11 private float spriteIndex;
13 private SpriteSheet propellerSprite;
15 private GUITickBox powerIndicator;
16 private GUIScrollBar forceSlider;
17 private GUITickBox autoControlIndicator;
19 private int particlesPerSec = 60;
20 private float particleTimer;
32 get {
return Vector2.Zero; }
39 RelativeOffset = new Vector2(0, 0.04f)
45 RelativeOffset = new Vector2(-0.05f, 0)
46 }, TextManager.Get(
"EnginePowered"), font: GUIStyle.SubHeadingFont, style:
"IndicatorLightGreen")
52 RelativeOffset = new Vector2(0.05f, 0)
53 }, TextManager.Get(
"PumpAutoControl",
"ReactorAutoControl"), font: GUIStyle.SubHeadingFont, style:
"IndicatorLightYellow")
57 ToolTip = TextManager.Get(
"AutoControlTip")
59 powerIndicator.TextBlock.Wrap = autoControlIndicator.TextBlock.Wrap =
true;
60 powerIndicator.TextBlock.OverrideTextColor(GUIStyle.TextColorNormal);
61 autoControlIndicator.TextBlock.OverrideTextColor(GUIStyle.TextColorNormal);
66 new GUITextBlock(
new RectTransform(
new Vector2(1.0f, 0.3f), sliderArea.RectTransform,
Anchor.TopCenter),
"", textColor: GUIStyle.TextColorNormal, font: GUIStyle.SubHeadingFont, textAlignment: Alignment.Center)
68 AutoScaleHorizontal =
true,
71 return TextManager.AddPunctuation(
':', powerLabel,
72 TextManager.GetWithVariable(
"percentageformat",
"[value]", ((
int)MathF.Round(targetForce)).ToString()));
75 forceSlider =
new GUIScrollBar(
new RectTransform(
new Vector2(0.95f, 0.45f), sliderArea.RectTransform,
Anchor.Center), barSize: 0.1f, style:
"DeviceSlider")
78 OnMoved = (GUIScrollBar scrollBar,
float barScroll) =>
80 lastReceivedTargetForce =
null;
81 float newTargetForce = barScroll * 200.0f - 100.0f;
82 if (Math.Abs(newTargetForce - targetForce) < 0.01) {
return false; }
84 targetForce = newTargetForce;
87 if (GameMain.Client !=
null)
90 item.CreateClientEvent(
this);
96 var textsArea =
new GUIFrame(
new RectTransform(
new Vector2(1, 0.25f), sliderArea.RectTransform,
Anchor.BottomCenter), style:
null);
97 var backwardsLabel =
new GUITextBlock(
new RectTransform(
new Vector2(0.4f, 1.0f), textsArea.RectTransform,
Anchor.CenterLeft), TextManager.Get(
"EngineBackwards"),
98 textColor: GUIStyle.TextColorNormal, font: GUIStyle.SubHeadingFont, textAlignment: Alignment.CenterLeft);
99 var forwardsLabel =
new GUITextBlock(
new RectTransform(
new Vector2(0.4f, 1.0f), textsArea.RectTransform,
Anchor.CenterRight), TextManager.Get(
"EngineForwards"),
100 textColor: GUIStyle.TextColorNormal, font: GUIStyle.SubHeadingFont, textAlignment: Alignment.CenterRight);
101 GUITextBlock.AutoScaleAndNormalize(backwardsLabel, forwardsLabel);
103 foreach (var subElement
in element.
Elements())
105 switch (subElement.Name.ToString().ToLowerInvariant())
107 case "propellersprite":
108 propellerSprite =
new SpriteSheet(subElement);
109 AnimSpeed = subElement.GetAttributeFloat(
"animspeed", 1.0f);
117 powerIndicator.Selected = hasPower &&
IsActive;
118 autoControlIndicator.Selected = controlLockTimer > 0.0f;
119 forceSlider.Enabled = controlLockTimer <= 0.0f;
123 float newScroll = (targetForce + 100.0f) / 200.0f;
124 if (Math.Abs(newScroll - forceSlider.BarScroll) > 0.01f)
126 forceSlider.BarScroll = newScroll;
131 partial
void UpdateAnimation(
float deltaTime)
133 if (propellerSprite ==
null) {
return; }
134 spriteIndex += (force / 100.0f) *
AnimSpeed * deltaTime;
137 spriteIndex = propellerSprite.FrameCount - Math.Abs(spriteIndex) % propellerSprite.FrameCount;
141 spriteIndex = spriteIndex % propellerSprite.FrameCount;
145 public void Draw(SpriteBatch spriteBatch,
bool editing,
float itemDepth = -1, Color? overrideColor =
null)
147 if (propellerSprite !=
null)
151 drawPos.Y = -drawPos.Y;
152 propellerSprite.Draw(spriteBatch, (
int)Math.Floor(spriteIndex), drawPos, overrideColor ?? Color.White, propellerSprite.Origin, 0.0f, Vector2.One);
159 drawPos.Y = -drawPos.Y;
160 spriteBatch.DrawCircle(drawPos, propellerDamage.
DamageRange *
item.
Scale, 16, GUIStyle.Red, thickness: 2);
IEnumerable< ContentXElement > Elements()
virtual Vector2 DrawPosition
const ushort NullEntityID
static Entity FindEntityByID(ushort ID)
Find an entity based on the ID
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...
override void UpdateHUDComponentSpecific(Character character, float deltaTime, Camera cam)
void ClientEventWrite(IWriteMessage msg, NetEntityEvent.IData extraData=null)
void ClientEventRead(IReadMessage msg, float sendingTime)
void Draw(SpriteBatch spriteBatch, bool editing, float itemDepth=-1, Color? overrideColor=null)
bool DisablePropellerDamage
void StartDelayedCorrection(IReadMessage buffer, float sendingTime, bool waitForMidRoundSync=false)
const float CorrectionDelay
int ReadRangedInteger(int min, int max)
void WriteRangedInteger(int val, int min, int max)