2 using Microsoft.Xna.Framework;
3 using Microsoft.Xna.Framework.Graphics;
10 private GUIProgressBar chargeIndicator;
11 private GUIScrollBar rechargeSpeedSlider;
22 get {
return Vector2.Zero; }
25 partial
void InitProjSpecific()
37 var rechargeRateContainer =
new GUIFrame(
new RectTransform(
new Vector2(1, 0.4f), upperArea.RectTransform), style:
null);
39 TextManager.Get(
"rechargerate"), textColor: GUIStyle.TextColorNormal, font: GUIStyle.SubHeadingFont, textAlignment: Alignment.CenterLeft);
42 "", textColor: GUIStyle.TextColorNormal, font: GUIStyle.Font, textAlignment: Alignment.CenterRight)
44 TextGetter = () => $
"{(int)MathF.Round(currPowerConsumption)} {kW} ({(int)MathF.Round(RechargeRatio * 100)} %)"
46 if (rechargeText.TextSize.X > rechargeText.Rect.Width) { rechargeText.
Font = GUIStyle.SmallFont; }
48 var rechargeSliderContainer =
new GUIFrame(
new RectTransform(
new Vector2(0.9f, 0.4f), upperArea.RectTransform,
Anchor.BottomCenter));
52 var rechargeSliderFill =
new GUICustomComponent(
new RectTransform(
new Vector2(0.95f, 0.9f), rechargeSliderContainer.RectTransform,
Anchor.Center), (SpriteBatch sb, GUICustomComponent c) =>
54 if (RechargeWarningIndicatorLow > 0.0f)
56 float warningLow = c.Rect.Width * RechargeWarningIndicatorLow;
57 GUI.DrawRectangle(sb, new Vector2(c.Rect.X + warningLow, c.Rect.Y), new Vector2(c.Rect.Width - warningLow, c.Rect.Height), GUIStyle.Orange, isFilled: true);
62 GUI.DrawRectangle(sb,
new Vector2(c.Rect.X + warningHigh, c.Rect.Y),
new Vector2(c.Rect.Width - warningHigh, c.Rect.Height), GUIStyle.Red, isFilled:
true);
67 rechargeSpeedSlider =
new GUIScrollBar(
new RectTransform(Vector2.One, rechargeSliderContainer.RectTransform,
Anchor.Center),
68 barSize: 0.15f, style:
"DeviceSliderSeeThrough")
71 OnMoved = (GUIScrollBar scrollBar,
float barScroll) =>
73 float newRechargeSpeed = maxRechargeSpeed * barScroll;
74 if (Math.Abs(newRechargeSpeed - rechargeSpeed) < 0.1f) {
return false; }
77 if (GameMain.Client !=
null)
79 item.CreateClientEvent(
this);
85 rechargeSpeedSlider.Bar.RectTransform.MaxSize =
new Point(rechargeSpeedSlider.Bar.Rect.Height);
90 var chargeTextContainer =
new GUIFrame(
new RectTransform(
new Vector2(1, 0.4f), lowerArea.RectTransform), style:
null);
91 var chargeLabel =
new GUITextBlock(
new RectTransform(
new Vector2(0.4f, 0.0f), chargeTextContainer.RectTransform,
Anchor.CenterLeft),
92 TextManager.Get(
"charge"), textColor: GUIStyle.TextColorNormal, font: GUIStyle.SubHeadingFont, textAlignment: Alignment.CenterLeft)
94 ToolTip = TextManager.Get(
"PowerTransferTipPower")
96 LocalizedString kWmin = TextManager.Get(
"kilowattminute");
97 var chargeText =
new GUITextBlock(
new RectTransform(
new Vector2(0.6f, 1), chargeTextContainer.RectTransform,
Anchor.CenterRight),
98 "", textColor: GUIStyle.TextColorNormal, font: GUIStyle.Font, textAlignment: Alignment.CenterRight)
100 TextGetter = () => $
"{(int)MathF.Round(charge)}/{(int)adjustedCapacity} {kWmin} ({(int)MathF.Round(MathUtils.Percentage(charge, adjustedCapacity))} %)"
102 if (chargeText.TextSize.X > chargeText.Rect.Width) { chargeText.Font = GUIStyle.SmallFont; }
104 chargeIndicator =
new GUIProgressBar(
new RectTransform(
new Vector2(1.1f, 0.5f), lowerArea.RectTransform,
Anchor.BottomCenter)
106 RelativeOffset = new Vector2(0, 0.1f)
107 }, barSize: 0.0f, style:
"DeviceProgressBar")
109 ProgressGetter = () =>
111 return adjustedCapacity <= 0.0f ? 1.0f : charge / adjustedCapacity;
119 if (rechargeSpeedSlider !=
null)
121 rechargeSpeedSlider.BarScroll = rechargeSpeed / MaxRechargeSpeed;
127 if (chargeIndicator !=
null)
129 float chargeRatio = charge / adjustedCapacity;
130 chargeIndicator.Color = ToolBox.GradientLerp(chargeRatio, Color.Red, Color.Orange, Color.Green);
134 public void Draw(SpriteBatch spriteBatch,
bool editing =
false,
float itemDepth = -1, Color? overrideColor =
null)
136 Vector2 scaledIndicatorSize = indicatorSize * item.Scale;
137 if (scaledIndicatorSize.X <= 2.0f || scaledIndicatorSize.Y <= 2.0f) {
return; }
139 const float outlineThickness = 1.0f;
140 Vector2 itemSize =
new Vector2(item.Sprite.SourceRect.Width, item.Sprite.SourceRect.Height) * item.Scale;
141 Vector2 indicatorPos = -itemSize / 2.0f + indicatorPosition * item.Scale;
142 Vector2 itemPosition =
new Vector2(item.DrawPosition.X, -item.DrawPosition.Y);
143 Vector2 flip =
new Vector2(item.FlippedX && item.Prefab.CanSpriteFlipX ? -1.0f : 1.0f, item.FlippedY && item.Prefab.CanSpriteFlipY ? -1.0f : 1.0f);
144 Matrix rotate = Matrix.CreateRotationZ(item.RotationRad);
145 Vector2 center = Vector2.Transform((indicatorPos + (scaledIndicatorSize * 0.5f)) * flip, rotate) + itemPosition;
147 if (charge > 0 && adjustedCapacity > 0)
149 float chargeRatio = MathHelper.Clamp(charge / adjustedCapacity, 0.0f, 1.0f);
150 Color indicatorColor = ToolBox.GradientLerp(chargeRatio, Color.Red, Color.Orange, Color.Green);
151 Vector2 indicatorCenter = (indicatorPos + (scaledIndicatorSize * 0.5f)) * flip;
152 Vector2 indicatorSize;
156 float indicatorLength = (scaledIndicatorSize.X - outlineThickness * 2.0f) * chargeRatio;
157 indicatorCenter.X += -scaledIndicatorSize.X * 0.5f + (flipIndicator ? scaledIndicatorSize.X - outlineThickness - indicatorLength * 0.5f : outlineThickness + indicatorLength * 0.5f);
158 indicatorSize =
new Vector2(indicatorLength, scaledIndicatorSize.Y);
162 float indicatorLength = (scaledIndicatorSize.Y - outlineThickness * 2.0f) * chargeRatio;
163 indicatorCenter.Y += -scaledIndicatorSize.Y * 0.5f + (flipIndicator ? outlineThickness + indicatorLength * 0.5f : scaledIndicatorSize.Y - outlineThickness - indicatorLength * 0.5f);
164 indicatorSize =
new Vector2(scaledIndicatorSize.X, indicatorLength);
167 indicatorCenter = Vector2.Transform(indicatorCenter, rotate) + itemPosition;
169 GUI.DrawFilledRectangle(spriteBatch, indicatorCenter, indicatorSize, indicatorSize * 0.5f, item.RotationRad, indicatorColor, item.SpriteDepth - 0.00001f);
172 GUI.DrawRectangle(spriteBatch, center, scaledIndicatorSize, scaledIndicatorSize * 0.5f, item.RotationRad, Color.Black, item.SpriteDepth - 0.000015f, outlineThickness, GUI.OutlinePosition.Inside);
182 if (correctionTimer > 0.0f)
184 StartDelayedCorrection(msg.ExtractBits(4 + 8), sendingTime);
189 RechargeSpeed = rechargeRate * MaxRechargeSpeed;
191 if (rechargeSpeedSlider !=
null)
193 rechargeSpeedSlider.BarScroll = rechargeRate;
RectTransform RectTransform
const float CorrectionDelay
override void UpdateHUDComponentSpecific(Character character, float deltaTime, Camera cam)
float RechargeWarningIndicatorLow
float RechargeWarningIndicatorHigh
void Draw(SpriteBatch spriteBatch, bool editing=false, float itemDepth=-1, Color? overrideColor=null)
override void OnItemLoaded()
Called when all the components of the item have been loaded. Use to initialize connections between co...
void ClientEventWrite(IWriteMessage msg, NetEntityEvent.IData extraData)
void ClientEventRead(IReadMessage msg, float sendingTime)
Highlights an UI element of some kind. Generally used in tutorials.
Interface for entities that the clients can send events to the server
int ReadRangedInteger(int min, int max)
Single ReadRangedSingle(Single min, Single max, int bitCount)
Interface for entities that the server can send events to the clients
void WriteRangedInteger(int val, int min, int max)