Improved MiniMap: shows hull integrity and oxygen levels, and can be configured to only show oxy/water data if the rooms have detectors in place
+ itemprefab "aliases" (allows changing item names while keeping backwards compatibility with older sub files)
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
<Item
|
<Item
|
||||||
name="MiniMap"
|
name="Status Monitor"
|
||||||
|
aliases="MiniMap"
|
||||||
category="Machine"
|
category="Machine"
|
||||||
linkable="true"
|
linkable="true"
|
||||||
pickdistance="150">
|
pickdistance="150">
|
||||||
@@ -12,7 +13,9 @@
|
|||||||
|
|
||||||
<ConnectionPanel selectkey="Action" canbeselected = "true" msg="Rewire [Screwdriver]">
|
<ConnectionPanel selectkey="Action" canbeselected = "true" msg="Rewire [Screwdriver]">
|
||||||
<requireditem name="Screwdriver" type="Equipped"/>
|
<requireditem name="Screwdriver" type="Equipped"/>
|
||||||
<input name="power_in"/>
|
<input name="power_in"/>
|
||||||
|
<input name="water_data_in"/>
|
||||||
|
<input name="oxygen_data_in"/>
|
||||||
</ConnectionPanel>
|
</ConnectionPanel>
|
||||||
|
|
||||||
</Item>
|
</Item>
|
||||||
@@ -261,6 +261,16 @@ namespace Barotrauma
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void DrawRectangle(SpriteBatch sb, Rectangle rect, Color clr, int thickness, float depth = 0.0f)
|
||||||
|
{
|
||||||
|
DrawLine(sb, new Vector2(rect.X, rect.Y), new Vector2(rect.Right, rect.Y), clr, depth, thickness);
|
||||||
|
DrawLine(sb, new Vector2(rect.X, rect.Bottom-thickness), new Vector2(rect.Right, rect.Bottom-thickness), clr, depth, thickness);
|
||||||
|
|
||||||
|
DrawLine(sb, new Vector2(rect.X+thickness, rect.Y+thickness), new Vector2(rect.X+thickness, rect.Bottom-thickness), clr, depth, thickness);
|
||||||
|
|
||||||
|
DrawLine(sb, new Vector2(rect.Right, rect.Y + thickness), new Vector2(rect.Right, rect.Bottom - thickness), clr, depth, thickness);
|
||||||
|
}
|
||||||
|
|
||||||
public static void DrawProgressBar(SpriteBatch sb, Vector2 start, Vector2 size, float progress, Color clr, float depth = 0.0f)
|
public static void DrawProgressBar(SpriteBatch sb, Vector2 start, Vector2 size, float progress, Color clr, float depth = 0.0f)
|
||||||
{
|
{
|
||||||
//outlinecolor = "0.5, 0.57, 0.6, 1.0" >
|
//outlinecolor = "0.5, 0.57, 0.6, 1.0" >
|
||||||
|
|||||||
@@ -2,22 +2,65 @@
|
|||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace Barotrauma.Items.Components
|
namespace Barotrauma.Items.Components
|
||||||
{
|
{
|
||||||
class MiniMap : Powered
|
class MiniMap : Powered
|
||||||
{
|
{
|
||||||
|
class HullData
|
||||||
|
{
|
||||||
|
public float? Oxygen;
|
||||||
|
public float? Water;
|
||||||
|
}
|
||||||
|
|
||||||
|
private DateTime resetDataTime;
|
||||||
|
|
||||||
|
bool hasPower;
|
||||||
|
|
||||||
|
[Editable, HasDefaultValue(false, true)]
|
||||||
|
public bool RequireWaterDetectors
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Editable, HasDefaultValue(true, true)]
|
||||||
|
public bool RequireOxygenDetectors
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Editable, HasDefaultValue(false, true)]
|
||||||
|
public bool ShowHullIntegrity
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private Dictionary<Hull, HullData> hullDatas;
|
||||||
|
|
||||||
public MiniMap(Item item, XElement element)
|
public MiniMap(Item item, XElement element)
|
||||||
: base(item, element)
|
: base(item, element)
|
||||||
{
|
{
|
||||||
IsActive = true;
|
IsActive = true;
|
||||||
|
|
||||||
|
hullDatas = new Dictionary<Hull, HullData>();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hasPower;
|
|
||||||
|
|
||||||
public override void Update(float deltaTime, Camera cam)
|
public override void Update(float deltaTime, Camera cam)
|
||||||
{
|
{
|
||||||
|
//periodically reset all hull data
|
||||||
|
//(so that outdated hull info won't be shown if detectors stop sending signals)
|
||||||
|
if (DateTime.Now > resetDataTime)
|
||||||
|
{
|
||||||
|
hullDatas.Clear();
|
||||||
|
resetDataTime = DateTime.Now + new TimeSpan(0, 0, 1);
|
||||||
|
}
|
||||||
|
|
||||||
currPowerConsumption = powerConsumption;
|
currPowerConsumption = powerConsumption;
|
||||||
|
|
||||||
hasPower = voltage > minVoltage;
|
hasPower = voltage > minVoltage;
|
||||||
@@ -46,46 +89,150 @@ namespace Barotrauma.Items.Components
|
|||||||
|
|
||||||
if (!hasPower) return;
|
if (!hasPower) return;
|
||||||
|
|
||||||
//GUI.DrawRectangle(spriteBatch, new Rectangle(x,y,width,height), Color.Black, true);
|
|
||||||
|
|
||||||
Rectangle miniMap = new Rectangle(x + 20, y + 40, width - 40, height - 60);
|
Rectangle miniMap = new Rectangle(x + 20, y + 40, width - 40, height - 60);
|
||||||
|
|
||||||
float size = Math.Min((float)miniMap.Width / (float)item.Submarine.Borders.Width, (float)miniMap.Height / (float)item.Submarine.Borders.Height);
|
float size = Math.Min((float)miniMap.Width / (float)item.Submarine.Borders.Width, (float)miniMap.Height / (float)item.Submarine.Borders.Height);
|
||||||
foreach (Hull hull in Hull.hullList)
|
foreach (Hull hull in Hull.hullList)
|
||||||
{
|
{
|
||||||
Rectangle hullRect = new Rectangle(
|
Point topLeft = new Point(
|
||||||
miniMap.X + (int)((hull.Rect.X - item.Submarine.HiddenSubPosition.X - item.Submarine.Borders.X) * size),
|
miniMap.X + (int)((hull.Rect.X - item.Submarine.HiddenSubPosition.X - item.Submarine.Borders.X) * size),
|
||||||
miniMap.Y - (int)((hull.Rect.Y - item.Submarine.HiddenSubPosition.Y - item.Submarine.Borders.Y) * size),
|
miniMap.Y - (int)((hull.Rect.Y - item.Submarine.HiddenSubPosition.Y - item.Submarine.Borders.Y) * size));
|
||||||
(int)(hull.Rect.Width * size),
|
|
||||||
(int)(hull.Rect.Height * size));
|
Point bottomRight = new Point(
|
||||||
|
topLeft.X + (int)(hull.Rect.Width * size),
|
||||||
|
topLeft.Y + (int)(hull.Rect.Height * size));
|
||||||
|
|
||||||
float waterAmount = Math.Min(hull.Volume / hull.FullVolume, 1.0f);
|
topLeft.X = (int)MathUtils.RoundTowardsClosest(topLeft.X, 4);
|
||||||
|
topLeft.Y = (int)MathUtils.RoundTowardsClosest(topLeft.Y, 4);
|
||||||
|
bottomRight.X = (int)MathUtils.RoundTowardsClosest(bottomRight.X, 4);
|
||||||
|
bottomRight.Y = (int)MathUtils.RoundTowardsClosest(bottomRight.Y, 4);
|
||||||
|
|
||||||
if (hullRect.Height * waterAmount > 1.0f)
|
Rectangle hullRect = new Rectangle(
|
||||||
|
topLeft, bottomRight - topLeft);
|
||||||
|
|
||||||
|
HullData hullData;
|
||||||
|
hullDatas.TryGetValue(hull, out hullData);
|
||||||
|
|
||||||
|
Color borderColor = Color.Green;
|
||||||
|
|
||||||
|
|
||||||
|
//hull integrity -----------------------------------
|
||||||
|
|
||||||
|
float? gapOpenSum = 0.0f;
|
||||||
|
if (ShowHullIntegrity)
|
||||||
{
|
{
|
||||||
Rectangle waterRect = new Rectangle(
|
gapOpenSum = hull.ConnectedGaps.Where(g => !g.IsRoomToRoom).Sum(g => g.Open);
|
||||||
hullRect.X,
|
borderColor = Color.Lerp(borderColor, Color.Red, Math.Min((float)gapOpenSum, 1.0f));
|
||||||
(int)(hullRect.Y + hullRect.Height * (1.0f - waterAmount)),
|
|
||||||
hullRect.Width,
|
|
||||||
(int)(hullRect.Height * waterAmount));
|
|
||||||
|
|
||||||
GUI.DrawRectangle(spriteBatch, waterRect, Color.DarkBlue, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GUI.DrawRectangle(spriteBatch, hullRect, Color.White);
|
//oxygen -----------------------------------
|
||||||
|
|
||||||
|
float? oxygenAmount = null;
|
||||||
|
if (RequireOxygenDetectors && (hullData == null || hullData.Oxygen == null))
|
||||||
|
{
|
||||||
|
borderColor *= 0.5f;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
oxygenAmount = hullData != null && hullData.Oxygen != null ? (float)hullData.Oxygen : hull.OxygenPercentage;
|
||||||
|
GUI.DrawRectangle(spriteBatch, hullRect, Color.Lerp(Color.Red * 0.5f, Color.Green * 0.3f, (float)oxygenAmount / 100.0f), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
//water -----------------------------------
|
||||||
|
|
||||||
|
float? waterAmount = null;
|
||||||
|
if (RequireWaterDetectors && (hullData == null || hullData.Water == null))
|
||||||
|
{
|
||||||
|
borderColor *= 0.5f;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
waterAmount = hullData != null && hullData.Water != null ?
|
||||||
|
(float)hullData.Water :
|
||||||
|
Math.Min(hull.Volume / hull.FullVolume, 1.0f);
|
||||||
|
|
||||||
|
if (hullRect.Height * waterAmount > 3.0f)
|
||||||
|
{
|
||||||
|
Rectangle waterRect = new Rectangle(
|
||||||
|
hullRect.X,
|
||||||
|
(int)(hullRect.Y + hullRect.Height * (1.0f - waterAmount)),
|
||||||
|
hullRect.Width,
|
||||||
|
(int)(hullRect.Height * waterAmount));
|
||||||
|
|
||||||
|
waterRect.Inflate(-3, -3);
|
||||||
|
|
||||||
|
GUI.DrawRectangle(spriteBatch, waterRect, Color.DarkBlue, true);
|
||||||
|
GUI.DrawLine(spriteBatch, new Vector2(waterRect.X, waterRect.Y), new Vector2(waterRect.Right, waterRect.Y), Color.LightBlue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hullRect.Contains(PlayerInput.MousePosition))
|
||||||
|
{
|
||||||
|
borderColor = Color.White;
|
||||||
|
|
||||||
|
if (gapOpenSum > 0.1f)
|
||||||
|
{
|
||||||
|
GUI.DrawString(spriteBatch,
|
||||||
|
new Vector2(x + 10, y + height - 60),
|
||||||
|
"Hull breach", Color.Red, Color.Black * 0.5f, 2, GUI.SmallFont);
|
||||||
|
}
|
||||||
|
|
||||||
|
GUI.DrawString(spriteBatch,
|
||||||
|
new Vector2(x+10, y+height-40),
|
||||||
|
oxygenAmount == null ? "Air quality data not available" : "Air quality: "+(int)oxygenAmount+" %",
|
||||||
|
oxygenAmount == null ? Color.Red : Color.Lerp(Color.Red, Color.LightGreen, (float)oxygenAmount / 100.0f),
|
||||||
|
Color.Black * 0.5f, 2, GUI.SmallFont);
|
||||||
|
|
||||||
|
GUI.DrawString(spriteBatch,
|
||||||
|
new Vector2(x + 10, y + height - 20),
|
||||||
|
waterAmount == null ? "Water level data not available" : "Water level: " + (int)(waterAmount*100.0f) + " %",
|
||||||
|
waterAmount == null ? Color.Red : Color.Lerp(Color.LightGreen, Color.Red, (float)waterAmount),
|
||||||
|
Color.Black * 0.5f, 2, GUI.SmallFont);
|
||||||
|
}
|
||||||
|
|
||||||
|
GUI.DrawRectangle(spriteBatch, hullRect, borderColor, 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void ReceiveSignal(int stepsTaken, string signal, Connection connection, Item sender, float power = 0)
|
||||||
|
{
|
||||||
|
base.ReceiveSignal(stepsTaken, signal, connection, sender, power);
|
||||||
|
|
||||||
|
if (sender == null || sender.CurrentHull == null) return;
|
||||||
|
|
||||||
|
Hull senderHull = sender.CurrentHull;
|
||||||
|
|
||||||
|
HullData hullData;
|
||||||
|
if (!hullDatas.TryGetValue(senderHull, out hullData))
|
||||||
|
{
|
||||||
|
hullData = new HullData();
|
||||||
|
hullDatas.Add(senderHull, hullData);
|
||||||
}
|
}
|
||||||
|
|
||||||
//foreach (Character c in Character.CharacterList)
|
switch (connection.Name)
|
||||||
//{
|
{
|
||||||
// if (c.AnimController.CurrentHull!=null) continue;
|
case "water_data_in":
|
||||||
|
//cheating a bit because water detectors don't actually send the water level
|
||||||
|
if (sender.GetComponent<WaterDetector>() == null)
|
||||||
|
{
|
||||||
|
hullData.Water = Rand.Range(0.0f, 1.0f);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
hullData.Water = Math.Min(senderHull.Volume / senderHull.FullVolume, 1.0f);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "oxygen_data_in":
|
||||||
|
float oxy = Rand.Range(0.0f, 100.0f);
|
||||||
|
|
||||||
// Rectangle characterRect = new Rectangle(
|
if (!float.TryParse(signal, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out oxy))
|
||||||
// miniMap.X + (int)((c.Position.X - Submarine.Borders.X) * size),
|
{
|
||||||
// miniMap.Y - (int)((c.Position.Y - Submarine.Borders.Y) * size),
|
int asdfasdf = 1;
|
||||||
// 5, 5);
|
}
|
||||||
|
|
||||||
// GUI.DrawRectangle(spriteBatch, characterRect, Color.White, true);
|
hullData.Oxygen = oxy;
|
||||||
//}
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1549,7 +1549,7 @@ namespace Barotrauma
|
|||||||
ItemPrefab ip = ep as ItemPrefab;
|
ItemPrefab ip = ep as ItemPrefab;
|
||||||
if (ip == null) continue;
|
if (ip == null) continue;
|
||||||
|
|
||||||
if (ip.Name != name) continue;
|
if (ip.Name != name && (ip.Aliases == null || !ip.Aliases.Contains(name))) continue;
|
||||||
|
|
||||||
if (rect.Width==0 && rect.Height==0)
|
if (rect.Width==0 && rect.Height==0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -58,6 +58,14 @@ namespace Barotrauma
|
|||||||
private set;
|
private set;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//if a matching itemprefab is not found when loading a sub, the game will attempt to find a prefab with a matching alias
|
||||||
|
//(allows changing item names while keeping backwards compatibility with older sub files)
|
||||||
|
public string[] Aliases
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
private set;
|
||||||
|
}
|
||||||
|
|
||||||
public List<DeconstructItem> DeconstructItems
|
public List<DeconstructItem> DeconstructItems
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
@@ -236,6 +244,12 @@ namespace Barotrauma
|
|||||||
|
|
||||||
ImpactTolerance = ToolBox.GetAttributeFloat(element, "impacttolerance", 0.0f);
|
ImpactTolerance = ToolBox.GetAttributeFloat(element, "impacttolerance", 0.0f);
|
||||||
|
|
||||||
|
string aliases = ToolBox.GetAttributeString(element, "aliases", "");
|
||||||
|
if (!string.IsNullOrWhiteSpace(aliases))
|
||||||
|
{
|
||||||
|
Aliases = aliases.Split(',');
|
||||||
|
}
|
||||||
|
|
||||||
MapEntityCategory category;
|
MapEntityCategory category;
|
||||||
|
|
||||||
if (!Enum.TryParse(ToolBox.GetAttributeString(element, "category", "Misc"), true, out category))
|
if (!Enum.TryParse(ToolBox.GetAttributeString(element, "category", "Misc"), true, out category))
|
||||||
|
|||||||
Reference in New Issue
Block a user