93 lines
3.0 KiB
C#
93 lines
3.0 KiB
C#
using System;
|
|
using System.Xml.Linq;
|
|
using Microsoft.Xna.Framework;
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
|
|
namespace Barotrauma.Items.Components
|
|
{
|
|
class MiniMap : Powered
|
|
{
|
|
|
|
public MiniMap(Item item, XElement element)
|
|
: base(item, element)
|
|
{
|
|
IsActive = true;
|
|
}
|
|
|
|
bool hasPower;
|
|
|
|
public override void Update(float deltaTime, Camera cam)
|
|
{
|
|
currPowerConsumption = powerConsumption;
|
|
|
|
hasPower = voltage > minVoltage;
|
|
|
|
voltage = 0.0f;
|
|
}
|
|
|
|
public override bool Pick(Character picker)
|
|
{
|
|
if (picker == null) return false;
|
|
|
|
//picker.SelectedConstruction = item;
|
|
|
|
return true;
|
|
}
|
|
|
|
public override void DrawHUD(SpriteBatch spriteBatch, Character character)
|
|
{
|
|
if (item.Submarine == null) return;
|
|
|
|
int width = GuiFrame.Rect.Width, height = GuiFrame.Rect.Height;
|
|
int x = GuiFrame.Rect.X;
|
|
int y = GuiFrame.Rect.Y;
|
|
|
|
GuiFrame.Draw(spriteBatch);
|
|
|
|
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);
|
|
|
|
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)
|
|
{
|
|
Rectangle hullRect = new Rectangle(
|
|
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),
|
|
(int)(hull.Rect.Width * size),
|
|
(int)(hull.Rect.Height * size));
|
|
|
|
float waterAmount = Math.Min(hull.Volume / hull.FullVolume, 1.0f);
|
|
|
|
if (hullRect.Height * waterAmount > 1.0f)
|
|
{
|
|
Rectangle waterRect = new Rectangle(
|
|
hullRect.X,
|
|
(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);
|
|
}
|
|
|
|
//foreach (Character c in Character.CharacterList)
|
|
//{
|
|
// if (c.AnimController.CurrentHull!=null) continue;
|
|
|
|
// Rectangle characterRect = new Rectangle(
|
|
// miniMap.X + (int)((c.Position.X - Submarine.Borders.X) * size),
|
|
// miniMap.Y - (int)((c.Position.Y - Submarine.Borders.Y) * size),
|
|
// 5, 5);
|
|
|
|
// GUI.DrawRectangle(spriteBatch, characterRect, Color.White, true);
|
|
//}
|
|
}
|
|
|
|
}
|
|
}
|