ItemComponent GUIFrames, functional steering, radar, separate power and signals, improved d.gz, tweak swimming
This commit is contained in:
@@ -32,7 +32,7 @@ namespace Subsurface
|
|||||||
{
|
{
|
||||||
case Physics.CollisionStairs:
|
case Physics.CollisionStairs:
|
||||||
Structure structure = fixture.Body.UserData as Structure;
|
Structure structure = fixture.Body.UserData as Structure;
|
||||||
if (stairs == null && (!inWater || TargetMovement.Y>0.0f) && structure!=null)
|
if (stairs == null && !inWater && structure!=null)
|
||||||
{
|
{
|
||||||
if (LowestLimb.SimPosition.Y<structure.SimPosition.Y)
|
if (LowestLimb.SimPosition.Y<structure.SimPosition.Y)
|
||||||
{
|
{
|
||||||
@@ -90,9 +90,17 @@ namespace Subsurface
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (closestFraction == 1) //raycast didn't hit anything
|
if (closestFraction == 1) //raycast didn't hit anything
|
||||||
|
{
|
||||||
floorY = (currentHull == null) ? -1000.0f : ConvertUnits.ToSimUnits(currentHull.Rect.Y - currentHull.Rect.Height);
|
floorY = (currentHull == null) ? -1000.0f : ConvertUnits.ToSimUnits(currentHull.Rect.Y - currentHull.Rect.Height);
|
||||||
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
|
{
|
||||||
floorY = rayStart.Y + (rayEnd.Y - rayStart.Y) * closestFraction;
|
floorY = rayStart.Y + (rayEnd.Y - rayStart.Y) * closestFraction;
|
||||||
|
}
|
||||||
|
|
||||||
|
System.Diagnostics.Debug.WriteLine(floorY+" - "+inWater);
|
||||||
|
|
||||||
|
|
||||||
IgnorePlatforms = (TargetMovement.Y < 0.0f);
|
IgnorePlatforms = (TargetMovement.Y < 0.0f);
|
||||||
|
|
||||||
@@ -321,10 +329,7 @@ namespace Subsurface
|
|||||||
{
|
{
|
||||||
MoveLimb(leftHand, handPos, 1.5f, true);
|
MoveLimb(leftHand, handPos, 1.5f, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < 2; i++)
|
for (int i = 0; i < 2; i++)
|
||||||
@@ -348,19 +353,21 @@ namespace Subsurface
|
|||||||
|
|
||||||
Limb head = GetLimb(LimbType.Head);
|
Limb head = GetLimb(LimbType.Head);
|
||||||
|
|
||||||
if (currentHull != null && currentHull.Volume < currentHull.FullVolume)
|
if (currentHull != null && currentHull.Volume < currentHull.FullVolume && !head.inWater)
|
||||||
{
|
{
|
||||||
surfaceLimiter = (ConvertUnits.ToDisplayUnits(head.SimPosition.Y)-surfaceY);
|
surfaceLimiter = (ConvertUnits.ToDisplayUnits(head.SimPosition.Y)-surfaceY);
|
||||||
surfaceLimiter = Math.Max(1.0f, surfaceLimiter);
|
surfaceLimiter = Math.Max(1.0f, surfaceLimiter);
|
||||||
if (surfaceLimiter > 20.0f) return;
|
if (surfaceLimiter > 20.0f) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Limb leftFoot = GetLimb(LimbType.LeftFoot);
|
|
||||||
Limb rightFoot = GetLimb(LimbType.RightFoot);
|
|
||||||
Limb torso = GetLimb(LimbType.Torso);
|
Limb torso = GetLimb(LimbType.Torso);
|
||||||
Limb leftHand = GetLimb(LimbType.LeftHand);
|
Limb leftHand = GetLimb(LimbType.LeftHand);
|
||||||
Limb rightHand = GetLimb(LimbType.RightHand);
|
Limb rightHand = GetLimb(LimbType.RightHand);
|
||||||
|
|
||||||
|
Limb leftFoot = GetLimb(LimbType.LeftFoot);
|
||||||
|
Limb rightFoot = GetLimb(LimbType.RightFoot);
|
||||||
|
Limb leftLeg = GetLimb(LimbType.LeftLeg);
|
||||||
|
Limb rightLeg = GetLimb(LimbType.RightLeg);
|
||||||
|
|
||||||
float rotation = MathHelper.WrapAngle(torso.Rotation);
|
float rotation = MathHelper.WrapAngle(torso.Rotation);
|
||||||
rotation = MathHelper.ToDegrees(rotation);
|
rotation = MathHelper.ToDegrees(rotation);
|
||||||
@@ -397,9 +404,9 @@ namespace Subsurface
|
|||||||
if (TargetMovement.X == 0.0f)
|
if (TargetMovement.X == 0.0f)
|
||||||
{
|
{
|
||||||
head.body.ApplyForce(head.Mass * new Vector2(-Dir * 5.1f, -5.0f));
|
head.body.ApplyForce(head.Mass * new Vector2(-Dir * 5.1f, -5.0f));
|
||||||
torso.body.ApplyForce(torso.Mass *new Vector2(-Dir*5.1f, -15.0f));
|
torso.body.ApplyForce(torso.Mass * new Vector2(-Dir * 5.1f, -15.0f));
|
||||||
leftFoot.body.ApplyForce(leftFoot.Mass *new Vector2(0.0f, -80.0f));
|
leftFoot.body.ApplyForce(leftFoot.Mass * new Vector2(0.0f, -80.0f));
|
||||||
rightFoot.body.ApplyForce(rightFoot.Mass *new Vector2(0.0f, -80.0f));
|
rightFoot.body.ApplyForce(rightFoot.Mass * new Vector2(0.0f, -80.0f));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -432,12 +439,19 @@ namespace Subsurface
|
|||||||
MoveLimb(leftFoot, footPos + transformedFootPos, 2.5f);
|
MoveLimb(leftFoot, footPos + transformedFootPos, 2.5f);
|
||||||
MoveLimb(rightFoot, footPos - transformedFootPos, 2.5f);
|
MoveLimb(rightFoot, footPos - transformedFootPos, 2.5f);
|
||||||
|
|
||||||
Vector2 feetExtendForce = new Vector2(
|
float legCorrection = MathUtils.GetShortestAngle(leftLeg.Rotation, torso.body.Rotation);
|
||||||
(float)-Math.Sin(torso.body.Rotation),
|
|
||||||
(float)Math.Cos(torso.body.Rotation));
|
|
||||||
|
|
||||||
leftFoot.body.ApplyForce(feetExtendForce);
|
leftLeg.body.ApplyTorque(legCorrection);
|
||||||
rightFoot.body.ApplyForce(feetExtendForce);
|
|
||||||
|
legCorrection = MathUtils.GetShortestAngle(rightLeg.Rotation, torso.body.Rotation);
|
||||||
|
|
||||||
|
rightLeg.body.ApplyTorque(legCorrection);
|
||||||
|
//Vector2 feetExtendForce = new Vector2(
|
||||||
|
// (float)-Math.Sin(torso.body.Rotation),
|
||||||
|
// (float)Math.Cos(torso.body.Rotation));
|
||||||
|
|
||||||
|
//leftFoot.body.ApplyForce(feetExtendForce);
|
||||||
|
//rightFoot.body.ApplyForce(feetExtendForce);
|
||||||
|
|
||||||
leftFoot.body.ApplyTorque(leftFoot.body.Mass * -Dir);
|
leftFoot.body.ApplyTorque(leftFoot.body.Mass * -Dir);
|
||||||
rightFoot.body.ApplyTorque(rightFoot.body.Mass * -Dir);
|
rightFoot.body.ApplyTorque(rightFoot.body.Mass * -Dir);
|
||||||
|
|||||||
@@ -187,7 +187,16 @@ namespace Subsurface
|
|||||||
|
|
||||||
if (element.Attribute("type") != null)
|
if (element.Attribute("type") != null)
|
||||||
{
|
{
|
||||||
type = (LimbType)Enum.Parse(typeof(LimbType), element.Attribute("type").Value, true);
|
try
|
||||||
|
{
|
||||||
|
type = (LimbType)Enum.Parse(typeof(LimbType), element.Attribute("type").Value, true);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
type = LimbType.None;
|
||||||
|
DebugConsole.ThrowError("Error in "+element+"! ''"+element.Attribute("type").Value+"'' is not a valid limb type");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Vector2 jointPos = ToolBox.GetAttributeVector2(element, "pullpos", Vector2.Zero);
|
Vector2 jointPos = ToolBox.GetAttributeVector2(element, "pullpos", Vector2.Zero);
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,9 @@
|
|||||||
|
|
||||||
<Sprite texture ="engine.png" depth="0.8"/>
|
<Sprite texture ="engine.png" depth="0.8"/>
|
||||||
|
|
||||||
<Engine minvoltage="0.5" powerperforce="10.0" maxforce="50" canbeselected = "true"/>
|
<Engine minvoltage="0.5" powerperforce="10.0" maxforce="50" canbeselected = "true">
|
||||||
|
<GuiFrame rect="0,0,0.3,0.3" alignment="Center" color="0.0,0.0,0.0,0.8"/>
|
||||||
|
</Engine>
|
||||||
|
|
||||||
<ConnectionPanel canbeselected = "true">
|
<ConnectionPanel canbeselected = "true">
|
||||||
<requireditem name="Screwdriver" type="Equipped"/>
|
<requireditem name="Screwdriver" type="Equipped"/>
|
||||||
@@ -24,7 +26,13 @@
|
|||||||
|
|
||||||
<Sprite texture ="fabricator.png" depth="0.8"/>
|
<Sprite texture ="fabricator.png" depth="0.8"/>
|
||||||
|
|
||||||
<Steering minvoltage="0.5" canbeselected = "true"/>
|
<Steering minvoltage="0.5" canbeselected = "true">
|
||||||
|
<GuiFrame rect="0,0,0.5,0.5" alignment="Center" color="0.0,0.0,0.0,0.8"/>
|
||||||
|
</Steering>
|
||||||
|
|
||||||
|
<Radar canbeselected = "true">
|
||||||
|
<GuiFrame rect="0,0,0.5,0.5" alignment="Center" color="0.0,0.0,0.0,0.0"/>
|
||||||
|
</Radar>
|
||||||
|
|
||||||
<ConnectionPanel canbeselected = "true">
|
<ConnectionPanel canbeselected = "true">
|
||||||
<requireditem name="Screwdriver" type="Equipped"/>
|
<requireditem name="Screwdriver" type="Equipped"/>
|
||||||
|
|||||||
@@ -6,7 +6,9 @@
|
|||||||
|
|
||||||
<trigger/>
|
<trigger/>
|
||||||
|
|
||||||
<MiniMap MinVoltage="0.5" PowerConsumption="100" canbeselected = "true"/>
|
<MiniMap MinVoltage="0.5" PowerConsumption="100" canbeselected = "true">
|
||||||
|
<GuiFrame rect="0,0,0.5,0.5" alignment="Center" color="0.0,0.0,0.0,0.8"/>
|
||||||
|
</MiniMap>
|
||||||
|
|
||||||
<ConnectionPanel canbeselected = "true">
|
<ConnectionPanel canbeselected = "true">
|
||||||
<requireditem name="Screwdriver" type="Equipped"/>
|
<requireditem name="Screwdriver" type="Equipped"/>
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
<Sprite texture ="reactor.png" depth="0.8"/>
|
<Sprite texture ="reactor.png" depth="0.8"/>
|
||||||
|
|
||||||
<Reactor canbeselected = "true">
|
<Reactor canbeselected = "true">
|
||||||
|
<GuiFrame rect="0,0,0.8,0.8" alignment="Center" color="0.0,0.0,0.0,0.8"/>
|
||||||
<requireditem name="Fuel Rod" type="Contained"/>
|
<requireditem name="Fuel Rod" type="Contained"/>
|
||||||
<StatusEffect type="OnActive" target="Contained" targetnames="Fuel Rod, Heat Absorber, Temperature Control Circuit" Condition="-0.1" />
|
<StatusEffect type="OnActive" target="Contained" targetnames="Fuel Rod, Heat Absorber, Temperature Control Circuit" Condition="-0.1" />
|
||||||
<sound file="reactor.ogg" type="OnActive" range="1000.0" volume="FissionRate"/>
|
<sound file="reactor.ogg" type="OnActive" range="1000.0" volume="FissionRate"/>
|
||||||
|
|||||||
@@ -8,12 +8,15 @@
|
|||||||
|
|
||||||
<Sprite texture ="junctionbox.png" depth="0.8"/>
|
<Sprite texture ="junctionbox.png" depth="0.8"/>
|
||||||
|
|
||||||
<PowerTransfer canbeselected = "true"/>
|
<PowerTransfer canbeselected = "true">
|
||||||
|
<GuiFrame rect="0,0,0.3,0.3" alignment="Center" color="0.0,0.0,0.0,0.8"/>
|
||||||
|
</PowerTransfer>
|
||||||
|
|
||||||
<ConnectionPanel canbeselected = "true">
|
<ConnectionPanel canbeselected = "true">
|
||||||
<requireditem name="Screwdriver" type="Equipped"/>
|
<requireditem name="Screwdriver" type="Equipped"/>
|
||||||
<output name="power_out"/>
|
<output name="power"/>
|
||||||
</ConnectionPanel>
|
<output name="signal"/>
|
||||||
|
</ConnectionPanel>
|
||||||
|
|
||||||
</Item>
|
</Item>
|
||||||
|
|
||||||
@@ -24,7 +27,9 @@
|
|||||||
|
|
||||||
<Sprite texture ="battery.png" depth="0.8"/>
|
<Sprite texture ="battery.png" depth="0.8"/>
|
||||||
|
|
||||||
<PowerContainer capacity="2000.0" maxrechargespeed="500.0" maxoutput="1000.0" canbeselected = "true"/>
|
<PowerContainer capacity="2000.0" maxrechargespeed="500.0" maxoutput="1000.0" canbeselected = "true">
|
||||||
|
<GuiFrame rect="0,0,0.3,0.3" alignment="Center" color="0.0,0.0,0.0,0.8"/>
|
||||||
|
</PowerContainer>
|
||||||
|
|
||||||
<ConnectionPanel canbeselected = "true">
|
<ConnectionPanel canbeselected = "true">
|
||||||
<requireditem name="Screwdriver" type="Equipped"/>
|
<requireditem name="Screwdriver" type="Equipped"/>
|
||||||
|
|||||||
@@ -264,15 +264,15 @@ namespace Subsurface
|
|||||||
|
|
||||||
public static void Draw(float deltaTime, SpriteBatch spriteBatch, Camera cam)
|
public static void Draw(float deltaTime, SpriteBatch spriteBatch, Camera cam)
|
||||||
{
|
{
|
||||||
spriteBatch.DrawString(font,
|
//spriteBatch.DrawString(font,
|
||||||
"FPS: " + (int)Game1.frameCounter.AverageFramesPerSecond
|
// "FPS: " + (int)Game1.frameCounter.AverageFramesPerSecond
|
||||||
+ " - render: " + Game1.renderTimeElapsed,
|
// + " - render: " + Game1.renderTimeElapsed,
|
||||||
new Vector2(10, 10), Color.White);
|
// new Vector2(10, 10), Color.White);
|
||||||
|
|
||||||
spriteBatch.DrawString(font,
|
//spriteBatch.DrawString(font,
|
||||||
"Physics: " + Game1.world.UpdateTime
|
// "Physics: " + Game1.world.UpdateTime
|
||||||
+ " - bodies: " + Game1.world.BodyList.Count,
|
// + " - bodies: " + Game1.world.BodyList.Count,
|
||||||
new Vector2(10, 30), Color.White);
|
// new Vector2(10, 30), Color.White);
|
||||||
|
|
||||||
|
|
||||||
if (Character.Controlled != null && cam!=null) Character.Controlled.DrawHud(spriteBatch, cam);
|
if (Character.Controlled != null && cam!=null) Character.Controlled.DrawHud(spriteBatch, cam);
|
||||||
|
|||||||
@@ -40,6 +40,11 @@ namespace Subsurface
|
|||||||
get { return parent; }
|
get { return parent; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Vector2 Center
|
||||||
|
{
|
||||||
|
get { return new Vector2(rect.Center.X, rect.Center.Y); }
|
||||||
|
}
|
||||||
|
|
||||||
public Rectangle Rect
|
public Rectangle Rect
|
||||||
{
|
{
|
||||||
get { return rect; }
|
get { return rect; }
|
||||||
@@ -192,43 +197,44 @@ namespace Subsurface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void UpdateDimensions(GUIComponent parent)
|
protected virtual void UpdateDimensions(GUIComponent parent = null)
|
||||||
{
|
{
|
||||||
if (parent!=null)
|
Rectangle parentRect = (parent==null) ? new Rectangle(0,0,Game1.GraphicsWidth, Game1.GraphicsHeight) : parent.rect;
|
||||||
|
|
||||||
|
Vector4 padding = (parent == null) ? Vector4.Zero : parent.padding;
|
||||||
|
|
||||||
|
if (rect.Width == 0) rect.Width = parentRect.Width - rect.X
|
||||||
|
- (int)padding.X - (int)padding.Z;
|
||||||
|
|
||||||
|
if (rect.Height == 0) rect.Height = parentRect.Height - rect.Y
|
||||||
|
- (int)padding.Y - (int)padding.W;
|
||||||
|
|
||||||
|
if (alignment.HasFlag(Alignment.CenterX))
|
||||||
{
|
{
|
||||||
if (rect.Width == 0) rect.Width = parent.Rect.Width - rect.X
|
rect.X += parentRect.X + (int)parentRect.Width/2 - (int)rect.Width/2;
|
||||||
- (int)parent.Padding.X - (int)parent.Padding.Z;
|
|
||||||
|
|
||||||
if (rect.Height == 0) rect.Height = parent.Rect.Height - rect.Y
|
|
||||||
- (int)parent.Padding.Y - (int)parent.Padding.W;
|
|
||||||
|
|
||||||
if (alignment.HasFlag(Alignment.CenterX))
|
|
||||||
{
|
|
||||||
rect.X += parent.Rect.X + (int)parent.Rect.Width/2 - (int)rect.Width/2;
|
|
||||||
}
|
|
||||||
else if (alignment.HasFlag(Alignment.Right))
|
|
||||||
{
|
|
||||||
rect.X += parent.Rect.X + (int)parent.Rect.Width - (int)parent.Padding.Z - (int)rect.Width;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
rect.X += parent.Rect.X + (int)parent.Padding.X;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (alignment.HasFlag(Alignment.CenterY))
|
|
||||||
{
|
|
||||||
rect.Y += parent.Rect.Y + (int)parent.Rect.Height / 2 - (int)rect.Height / 2;
|
|
||||||
}
|
|
||||||
else if (alignment.HasFlag(Alignment.Bottom))
|
|
||||||
{
|
|
||||||
rect.Y += parent.Rect.Y + (int)parent.Rect.Height - (int)parent.Padding.W - (int)rect.Height;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
rect.Y += parent.Rect.Y + (int)parent.Padding.Y;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
else if (alignment.HasFlag(Alignment.Right))
|
||||||
|
{
|
||||||
|
rect.X += parentRect.X + (int)parentRect.Width - (int)padding.Z - (int)rect.Width;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
rect.X += parentRect.X + (int)padding.X;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (alignment.HasFlag(Alignment.CenterY))
|
||||||
|
{
|
||||||
|
rect.Y += parentRect.Y + (int)parentRect.Height / 2 - (int)rect.Height / 2;
|
||||||
|
}
|
||||||
|
else if (alignment.HasFlag(Alignment.Bottom))
|
||||||
|
{
|
||||||
|
rect.Y += parentRect.Y + (int)parentRect.Height - (int)padding.W - (int)rect.Height;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
rect.Y += parentRect.Y + (int)padding.Y;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void DrawChildren(SpriteBatch spriteBatch)
|
public virtual void DrawChildren(SpriteBatch spriteBatch)
|
||||||
|
|||||||
@@ -23,8 +23,15 @@ namespace Subsurface
|
|||||||
this.alignment = alignment;
|
this.alignment = alignment;
|
||||||
|
|
||||||
this.color = color;
|
this.color = color;
|
||||||
if (parent!=null)
|
|
||||||
|
if (parent != null)
|
||||||
|
{
|
||||||
parent.AddChild(this);
|
parent.AddChild(this);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
UpdateDimensions();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch)
|
public override void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch)
|
||||||
|
|||||||
+1
-1
@@ -49,7 +49,7 @@ namespace Subsurface
|
|||||||
public static Random random;
|
public static Random random;
|
||||||
|
|
||||||
//private Stopwatch renderTimer;
|
//private Stopwatch renderTimer;
|
||||||
public static int renderTimeElapsed;
|
//public static int renderTimeElapsed;
|
||||||
|
|
||||||
|
|
||||||
public Camera Cam
|
public Camera Cam
|
||||||
|
|||||||
@@ -310,7 +310,7 @@ namespace Subsurface.Items.Components
|
|||||||
if (convexHull2 != null) convexHull2.Remove();
|
if (convexHull2 != null) convexHull2.Remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void ReceiveSignal(string signal, Connection connection, Item sender)
|
public override void ReceiveSignal(string signal, Connection connection, Item sender, float power=0.0f)
|
||||||
{
|
{
|
||||||
if (connection.name=="toggle")
|
if (connection.name=="toggle")
|
||||||
{
|
{
|
||||||
|
|||||||
+2
-2
@@ -35,8 +35,8 @@ namespace Subsurface.Items.Components
|
|||||||
public RangedWeapon(Item item, XElement element)
|
public RangedWeapon(Item item, XElement element)
|
||||||
: base(item, element)
|
: base(item, element)
|
||||||
{
|
{
|
||||||
barrelPos = ToolBox.GetAttributeVector2(element, "barrelpos", Vector2.Zero);
|
//barrelPos = ToolBox.GetAttributeVector2(element, "barrelpos", Vector2.Zero);
|
||||||
barrelPos = ConvertUnits.ToSimUnits(barrelPos);
|
//barrelPos = ConvertUnits.ToSimUnits(barrelPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Update(float deltaTime, Camera cam)
|
public override void Update(float deltaTime, Camera cam)
|
||||||
@@ -54,6 +54,8 @@ namespace Subsurface
|
|||||||
|
|
||||||
private List<ItemSound> sounds;
|
private List<ItemSound> sounds;
|
||||||
|
|
||||||
|
private GUIFrame guiFrame;
|
||||||
|
|
||||||
public readonly Dictionary<string, ObjectProperty> properties;
|
public readonly Dictionary<string, ObjectProperty> properties;
|
||||||
public Dictionary<string, ObjectProperty> ObjectProperties
|
public Dictionary<string, ObjectProperty> ObjectProperties
|
||||||
{
|
{
|
||||||
@@ -96,6 +98,19 @@ namespace Subsurface
|
|||||||
get { return name; }
|
get { return name; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected GUIFrame GuiFrame
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (guiFrame==null)
|
||||||
|
{
|
||||||
|
DebugConsole.ThrowError("Error: the component "+name+" in "+item.Name+" doesn't have a guiFrame");
|
||||||
|
guiFrame = new GUIFrame(new Rectangle(0, 0, 100, 100), Color.Black);
|
||||||
|
}
|
||||||
|
return guiFrame;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[HasDefaultValue("", false)]
|
[HasDefaultValue("", false)]
|
||||||
public string Msg
|
public string Msg
|
||||||
{
|
{
|
||||||
@@ -153,6 +168,32 @@ namespace Subsurface
|
|||||||
case "statuseffect":
|
case "statuseffect":
|
||||||
statusEffects.Add(StatusEffect.Load(subElement));
|
statusEffects.Add(StatusEffect.Load(subElement));
|
||||||
break;
|
break;
|
||||||
|
case "guiframe":
|
||||||
|
Vector4 rect = ToolBox.GetAttributeVector4(subElement, "rect", Vector4.One);
|
||||||
|
rect.X *= Game1.GraphicsWidth;
|
||||||
|
rect.Y *= Game1.GraphicsHeight;
|
||||||
|
rect.Z *= Game1.GraphicsWidth;
|
||||||
|
rect.W *= Game1.GraphicsHeight;
|
||||||
|
|
||||||
|
Vector4 color = ToolBox.GetAttributeVector4(subElement, "color", Vector4.One);
|
||||||
|
|
||||||
|
Alignment alignment = Alignment.Center;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
alignment = (Alignment)Enum.Parse(typeof(Alignment),
|
||||||
|
ToolBox.GetAttributeString(subElement, "alignment", "Center"), true);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
DebugConsole.ThrowError("Error in " + element + "! ''" + element.Attribute("type").Value + "'' is not a valid alignment");
|
||||||
|
}
|
||||||
|
|
||||||
|
guiFrame = new GUIFrame(
|
||||||
|
new Rectangle((int)rect.X, (int)rect.Y, (int)rect.Z, (int)rect.W),
|
||||||
|
new Color(color.X, color.Y, color.Z), alignment);
|
||||||
|
guiFrame.Alpha = color.W;
|
||||||
|
|
||||||
|
break;
|
||||||
case "sound":
|
case "sound":
|
||||||
string filePath = ToolBox.GetAttributeString(subElement, "file", "");
|
string filePath = ToolBox.GetAttributeString(subElement, "file", "");
|
||||||
if (filePath=="") continue;
|
if (filePath=="") continue;
|
||||||
@@ -284,7 +325,7 @@ namespace Subsurface
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void ReceiveSignal(string signal, Connection connection, Item sender) { }
|
public virtual void ReceiveSignal(string signal, Connection connection, Item sender, float power = 0.0f) { }
|
||||||
|
|
||||||
public virtual bool Combine(Item item)
|
public virtual bool Combine(Item item)
|
||||||
{
|
{
|
||||||
|
|||||||
+10
-9
@@ -71,17 +71,18 @@ namespace Subsurface.Items.Components
|
|||||||
public override void DrawHUD(SpriteBatch spriteBatch, Character character)
|
public override void DrawHUD(SpriteBatch spriteBatch, Character character)
|
||||||
{
|
{
|
||||||
//isActive = true;
|
//isActive = true;
|
||||||
|
GuiFrame.Draw(spriteBatch);
|
||||||
|
|
||||||
int width = 300, height = 300;
|
//int width = 300, height = 300;
|
||||||
int x = Game1.GraphicsWidth / 2 - width / 2;
|
//int x = Game1.GraphicsWidth / 2 - width / 2;
|
||||||
int y = Game1.GraphicsHeight / 2 - height / 2 - 50;
|
//int y = Game1.GraphicsHeight / 2 - height / 2 - 50;
|
||||||
|
|
||||||
GUI.DrawRectangle(spriteBatch, new Rectangle(x, y, width, height), Color.Black, true);
|
//GUI.DrawRectangle(spriteBatch, new Rectangle(x, y, width, height), Color.Black, true);
|
||||||
|
|
||||||
spriteBatch.DrawString(GUI.font, "Force: " + (int)targetForce+" %", new Vector2(x + 30, y + 30), Color.White);
|
spriteBatch.DrawString(GUI.font, "Force: " + (int)targetForce + " %", new Vector2(GuiFrame.Rect.X + 30, GuiFrame.Rect.Y + 30), Color.White);
|
||||||
|
|
||||||
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 280, y + 30, 40, 40), "+", true)) targetForce += 1.0f;
|
if (GUI.DrawButton(spriteBatch, new Rectangle(GuiFrame.Rect.X + 280, GuiFrame.Rect.Y + 30, 40, 40), "+", true)) targetForce += 1.0f;
|
||||||
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 280, y + 80, 40, 40), "-", true)) targetForce -= 1.0f;
|
if (GUI.DrawButton(spriteBatch, new Rectangle(GuiFrame.Rect.X + 280, GuiFrame.Rect.Y + 80, 40, 40), "-", true)) targetForce -= 1.0f;
|
||||||
|
|
||||||
item.NewComponentEvent(this, true);
|
item.NewComponentEvent(this, true);
|
||||||
}
|
}
|
||||||
@@ -91,9 +92,9 @@ namespace Subsurface.Items.Components
|
|||||||
force = MathHelper.Lerp(force, 0.0f, 0.1f);
|
force = MathHelper.Lerp(force, 0.0f, 0.1f);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void ReceiveSignal(string signal, Connection connection, Item sender)
|
public override void ReceiveSignal(string signal, Connection connection, Item sender, float power=0.0f)
|
||||||
{
|
{
|
||||||
base.ReceiveSignal(signal, connection, sender);
|
base.ReceiveSignal(signal, connection, sender, power);
|
||||||
|
|
||||||
if (connection.name == "set_force")
|
if (connection.name == "set_force")
|
||||||
{
|
{
|
||||||
+5
-4
@@ -32,12 +32,13 @@ namespace Subsurface.Items.Components
|
|||||||
|
|
||||||
public override void DrawHUD(SpriteBatch spriteBatch, Character character)
|
public override void DrawHUD(SpriteBatch spriteBatch, Character character)
|
||||||
{
|
{
|
||||||
int width = 500, height = 400;
|
int width = GuiFrame.Rect.Width, height = GuiFrame.Rect.Height;
|
||||||
int x = Game1.GraphicsWidth / 2 - width / 2;
|
int x = GuiFrame.Rect.X;
|
||||||
int y = Game1.GraphicsHeight / 2 - height / 2;
|
int y = GuiFrame.Rect.Y;
|
||||||
|
|
||||||
|
GuiFrame.Draw(spriteBatch);
|
||||||
|
|
||||||
GUI.DrawRectangle(spriteBatch, new Rectangle(x,y,width,height), Color.Black, true);
|
//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);
|
||||||
|
|
||||||
@@ -133,9 +133,11 @@ namespace Subsurface.Items.Components
|
|||||||
// }
|
// }
|
||||||
//}
|
//}
|
||||||
|
|
||||||
public override void ReceiveSignal(string signal, Connection connection, Item sender)
|
public override void ReceiveSignal(string signal, Connection connection, Item sender, float power=0.0f)
|
||||||
{
|
{
|
||||||
base.ReceiveSignal(signal, connection, sender);
|
base.ReceiveSignal(signal, connection, sender, power);
|
||||||
|
|
||||||
|
isActive = true;
|
||||||
|
|
||||||
if (connection.name == "toggle")
|
if (connection.name == "toggle")
|
||||||
{
|
{
|
||||||
@@ -150,7 +152,7 @@ namespace Subsurface.Items.Components
|
|||||||
float tempSpeed;
|
float tempSpeed;
|
||||||
if (float.TryParse(signal, NumberStyles.Float, CultureInfo.InvariantCulture, out tempSpeed))
|
if (float.TryParse(signal, NumberStyles.Float, CultureInfo.InvariantCulture, out tempSpeed))
|
||||||
{
|
{
|
||||||
flowPercentage = MathHelper.Clamp(flowPercentage, -100.0f, 100.0f);
|
flowPercentage = MathHelper.Clamp(tempSpeed, -100.0f, 100.0f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
using FarseerPhysics;
|
||||||
|
using Microsoft.Xna.Framework;
|
||||||
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
|
namespace Subsurface.Items.Components
|
||||||
|
{
|
||||||
|
class Radar : ItemComponent
|
||||||
|
{
|
||||||
|
float range;
|
||||||
|
|
||||||
|
float angle;
|
||||||
|
|
||||||
|
//RenderTarget2D renderTarget;
|
||||||
|
|
||||||
|
[HasDefaultValue(0.0f, false)]
|
||||||
|
public float Range
|
||||||
|
{
|
||||||
|
get { return ConvertUnits.ToDisplayUnits(range); }
|
||||||
|
set { range = ConvertUnits.ToSimUnits(value); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public Radar(Item item, XElement element)
|
||||||
|
: base(item, element)
|
||||||
|
{
|
||||||
|
//renderTarget = new RenderTarget2D(Game1.CurrGraphicsDevice, GuiFrame.Rect.Width, GuiFrame.Rect.Height);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Update(float deltaTime, Camera cam)
|
||||||
|
{
|
||||||
|
base.Update(deltaTime, cam);
|
||||||
|
|
||||||
|
angle = (angle + deltaTime) % MathHelper.TwoPi;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void DrawHUD(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch, Character character)
|
||||||
|
{
|
||||||
|
int width = GuiFrame.Rect.Width, height = GuiFrame.Rect.Height;
|
||||||
|
int x = GuiFrame.Rect.X;
|
||||||
|
int y = GuiFrame.Rect.Y;
|
||||||
|
|
||||||
|
GuiFrame.Draw(spriteBatch);
|
||||||
|
|
||||||
|
if (GUI.DrawButton(spriteBatch, new Rectangle(x+20, y+20, 200, 30), "Activate Radar")) isActive = !isActive;
|
||||||
|
|
||||||
|
Vector2 lineEnd = GuiFrame.Center;
|
||||||
|
lineEnd += new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle))*Math.Min(width,height)/2.0f;
|
||||||
|
GUI.DrawLine(spriteBatch, GuiFrame.Center, lineEnd, Color.Green);
|
||||||
|
|
||||||
|
if (!isActive) return;
|
||||||
|
|
||||||
|
float scale = 0.01f;
|
||||||
|
|
||||||
|
List<Vector2[]> edges = Level.Loaded.GetCellEdges(-Level.Loaded.position, 5);
|
||||||
|
Vector2 offset = Vector2.Zero; //Level.Loaded.position;
|
||||||
|
//offset.Y = -offset.Y;
|
||||||
|
|
||||||
|
for (int i = 0; i < edges.Count; i++)
|
||||||
|
{
|
||||||
|
GUI.DrawLine(spriteBatch,
|
||||||
|
GuiFrame.Center + (edges[i][0] - offset) * scale,
|
||||||
|
GuiFrame.Center + (edges[i][1] - offset) * scale, Color.Green);
|
||||||
|
}
|
||||||
|
|
||||||
|
scale = ConvertUnits.ToDisplayUnits(scale);
|
||||||
|
for (int i = 0; i< Submarine.Loaded.HullVertices.Count; i++)
|
||||||
|
{
|
||||||
|
Vector2 start =Submarine.Loaded.HullVertices[i] * scale;
|
||||||
|
start.Y = -start.Y;
|
||||||
|
Vector2 end = Submarine.Loaded.HullVertices[(i+1)%Submarine.Loaded.HullVertices.Count] * scale;
|
||||||
|
end.Y = -end.Y;
|
||||||
|
|
||||||
|
GUI.DrawLine(spriteBatch, GuiFrame.Center + start,GuiFrame.Center + end, Color.Green);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateRendertarget()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+5
-3
@@ -300,9 +300,11 @@ namespace Subsurface.Items.Components
|
|||||||
{
|
{
|
||||||
isActive = true;
|
isActive = true;
|
||||||
|
|
||||||
int width = 500, height = 420;
|
int width = GuiFrame.Rect.Width, height = GuiFrame.Rect.Height;
|
||||||
int x = Game1.GraphicsWidth / 2 - width / 2;
|
int x = GuiFrame.Rect.X;
|
||||||
int y = Game1.GraphicsHeight / 2 - height / 2 - 50;
|
int y = GuiFrame.Rect.Y;
|
||||||
|
|
||||||
|
GuiFrame.Draw(spriteBatch);
|
||||||
|
|
||||||
float xOffset = (graphTimer / (float)updateGraphInterval);
|
float xOffset = (graphTimer / (float)updateGraphInterval);
|
||||||
|
|
||||||
+20
-15
@@ -23,21 +23,19 @@ namespace Subsurface.Items.Components
|
|||||||
{
|
{
|
||||||
base.Update(deltaTime, cam);
|
base.Update(deltaTime, cam);
|
||||||
|
|
||||||
item.SendSignal(targetVelocity.X.ToString(), "velocity_x_out", item);
|
item.SendSignal(targetVelocity.X.ToString(), "velocity_x_out");
|
||||||
item.SendSignal(targetVelocity.Y.ToString(), "velocity_y_out", item);
|
item.SendSignal((-targetVelocity.Y).ToString(), "velocity_y_out");
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void DrawHUD(SpriteBatch spriteBatch, Character character)
|
public override void DrawHUD(SpriteBatch spriteBatch, Character character)
|
||||||
{
|
{
|
||||||
//isActive = true;
|
int width = GuiFrame.Rect.Width, height = GuiFrame.Rect.Height;
|
||||||
|
int x = GuiFrame.Rect.X;
|
||||||
|
int y = GuiFrame.Rect.Y;
|
||||||
|
|
||||||
int width = 300, height = 300;
|
GuiFrame.Draw(spriteBatch);
|
||||||
int x = Game1.GraphicsWidth / 2 - width / 2;
|
|
||||||
int y = Game1.GraphicsHeight / 2 - height / 2 - 50;
|
|
||||||
|
|
||||||
GUI.DrawRectangle(spriteBatch, new Rectangle(x, y, width, height), Color.Black, true);
|
Rectangle velRect = new Rectangle(x + 20, y + 20, width - 40, height - 40);
|
||||||
|
|
||||||
Rectangle velRect = new Rectangle(x+20, y+20, 100, 100);
|
|
||||||
GUI.DrawRectangle(spriteBatch, velRect, Color.White, false);
|
GUI.DrawRectangle(spriteBatch, velRect, Color.White, false);
|
||||||
|
|
||||||
GUI.DrawLine(spriteBatch,
|
GUI.DrawLine(spriteBatch,
|
||||||
@@ -65,20 +63,27 @@ namespace Subsurface.Items.Components
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//spriteBatch.DrawString(GUI.font, "Force: " + (int)force + " %", new Vector2(x + 30, y + 30), Color.White);
|
|
||||||
|
|
||||||
//if (GUI.DrawButton(spriteBatch, new Rectangle(x + 280, y + 30, 40, 40), "+", true)) targetForce += 1.0f;
|
|
||||||
//if (GUI.DrawButton(spriteBatch, new Rectangle(x + 280, y + 80, 40, 40), "-", true)) targetForce -= 1.0f;
|
|
||||||
|
|
||||||
item.NewComponentEvent(this, true);
|
item.NewComponentEvent(this, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void ReceiveSignal(string signal, Connection connection, Item sender)
|
public override void ReceiveSignal(string signal, Connection connection, Item sender, float power=0.0f)
|
||||||
{
|
{
|
||||||
if (connection.name == "velocity_in")
|
if (connection.name == "velocity_in")
|
||||||
{
|
{
|
||||||
currVelocity = ToolBox.ParseToVector2(signal, false);
|
currVelocity = ToolBox.ParseToVector2(signal, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void FillNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetOutgoingMessage message)
|
||||||
|
{
|
||||||
|
message.Write(targetVelocity.X);
|
||||||
|
message.Write(targetVelocity.Y);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void ReadNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetIncomingMessage message)
|
||||||
|
{
|
||||||
|
targetVelocity.X = message.ReadFloat();
|
||||||
|
targetVelocity.Y = message.ReadFloat();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+17
-6
@@ -49,9 +49,8 @@ namespace Subsurface.Items.Components
|
|||||||
{
|
{
|
||||||
pt.powerLoad += (fullLoad - pt.powerLoad) / inertia;
|
pt.powerLoad += (fullLoad - pt.powerLoad) / inertia;
|
||||||
pt.currPowerConsumption += (-fullPower - pt.currPowerConsumption) / inertia;
|
pt.currPowerConsumption += (-fullPower - pt.currPowerConsumption) / inertia;
|
||||||
pt.Item.SendSignal(
|
pt.Item.SendSignal("",
|
||||||
(fullPower / Math.Max(fullLoad,1.0f)).ToString(CultureInfo.InvariantCulture),
|
"power", fullPower / Math.Max(fullLoad, 1.0f));
|
||||||
"power_out");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -126,9 +125,11 @@ namespace Subsurface.Items.Components
|
|||||||
|
|
||||||
public override void DrawHUD(SpriteBatch spriteBatch, Character character)
|
public override void DrawHUD(SpriteBatch spriteBatch, Character character)
|
||||||
{
|
{
|
||||||
int width = 300, height = 200;
|
int width = GuiFrame.Rect.Width, height = GuiFrame.Rect.Height;
|
||||||
int x = Game1.GraphicsWidth / 2 - width / 2;
|
int x = GuiFrame.Rect.X;
|
||||||
int y = Game1.GraphicsHeight / 2 - height / 2;
|
int y = GuiFrame.Rect.Y;
|
||||||
|
|
||||||
|
GuiFrame.Draw(spriteBatch);
|
||||||
|
|
||||||
GUI.DrawRectangle(spriteBatch, new Rectangle(x, y, width, height), Color.Black, true);
|
GUI.DrawRectangle(spriteBatch, new Rectangle(x, y, width, height), Color.Black, true);
|
||||||
|
|
||||||
@@ -136,5 +137,15 @@ namespace Subsurface.Items.Components
|
|||||||
spriteBatch.DrawString(GUI.font, "Load: " + (int)powerLoad, new Vector2(x + 30, y + 100), Color.White);
|
spriteBatch.DrawString(GUI.font, "Load: " + (int)powerLoad, new Vector2(x + 30, y + 100), Color.White);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void ReceiveSignal(string signal, Connection connection, Item sender, float power)
|
||||||
|
{
|
||||||
|
base.ReceiveSignal(signal, connection, sender, power);
|
||||||
|
|
||||||
|
if (connection.name=="signal")
|
||||||
|
{
|
||||||
|
connection.SendSignal(signal, item, 0.0f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+2
-8
@@ -59,15 +59,9 @@ namespace Subsurface.Items.Components
|
|||||||
set { voltage = Math.Max(0.0f, value); }
|
set { voltage = Math.Max(0.0f, value); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void ReceiveSignal(string signal, Connection connection, Item sender)
|
public override void ReceiveSignal(string signal, Connection connection, Item sender, float power)
|
||||||
{
|
{
|
||||||
if (connection.name=="power_in")
|
if (connection.name=="power_in") voltage = power;
|
||||||
{
|
|
||||||
if (!float.TryParse(signal, NumberStyles.Any, CultureInfo.InvariantCulture, out voltage))
|
|
||||||
{
|
|
||||||
voltage = 0.0f;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Update(float deltaTime, Camera cam)
|
public override void Update(float deltaTime, Camera cam)
|
||||||
@@ -53,7 +53,7 @@ namespace Subsurface.Items.Components
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void ReceiveSignal(string signal, Connection connection, Item sender)
|
public override void ReceiveSignal(string signal, Connection connection, Item sender, float power=0.0f)
|
||||||
{
|
{
|
||||||
switch (connection.name)
|
switch (connection.name)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ namespace Subsurface.Items.Components
|
|||||||
// return false;
|
// return false;
|
||||||
//}
|
//}
|
||||||
|
|
||||||
public void SendSignal(string signal, Item sender)
|
public void SendSignal(string signal, Item sender, float power)
|
||||||
{
|
{
|
||||||
for (int i = 0; i<MaxLinked; i++)
|
for (int i = 0; i<MaxLinked; i++)
|
||||||
{
|
{
|
||||||
@@ -146,7 +146,7 @@ namespace Subsurface.Items.Components
|
|||||||
|
|
||||||
foreach (ItemComponent ic in recipient.item.components)
|
foreach (ItemComponent ic in recipient.item.components)
|
||||||
{
|
{
|
||||||
ic.ReceiveSignal(signal, recipient, sender);
|
ic.ReceiveSignal(signal, recipient, sender, power);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ namespace Subsurface.Items.Components
|
|||||||
sprite.Draw(spriteBatch, new Vector2(item.Position.X, -item.Position.Y), 0.0f, 1.0f, Microsoft.Xna.Framework.Graphics.SpriteEffects.None);
|
sprite.Draw(spriteBatch, new Vector2(item.Position.X, -item.Position.Y), 0.0f, 1.0f, Microsoft.Xna.Framework.Graphics.SpriteEffects.None);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void ReceiveSignal(string signal, Connection connection, Item sender)
|
public override void ReceiveSignal(string signal, Connection connection, Item sender, float power=0.0f)
|
||||||
{
|
{
|
||||||
switch (connection.name)
|
switch (connection.name)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -9,11 +9,11 @@ namespace Subsurface.Items.Components
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void ReceiveSignal(string signal, Connection connection, Item sender)
|
public override void ReceiveSignal(string signal, Connection connection, Item sender, float power=0.0f)
|
||||||
{
|
{
|
||||||
if (connection.name != "signal_in") return;
|
if (connection.name != "signal_in") return;
|
||||||
|
|
||||||
item.SendSignal(signal=="0" ? "1" : "0", "signal_out", item);
|
item.SendSignal(signal=="0" ? "1" : "0", "signal_out");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ namespace Subsurface.Items.Components
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void ReceiveSignal(string signal, Connection connection, Item sender)
|
public override void ReceiveSignal(string signal, Connection connection, Item sender, float power=0.0f)
|
||||||
{
|
{
|
||||||
switch (connection.name)
|
switch (connection.name)
|
||||||
{
|
{
|
||||||
@@ -44,11 +44,11 @@ namespace Subsurface.Items.Components
|
|||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
item.SendSignal("ERROR", "signal_out", item);
|
item.SendSignal("ERROR", "signal_out");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
item.SendSignal(success ? output : "0", "signal_out", item);
|
item.SendSignal(success ? output : "0", "signal_out");
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case "set_output":
|
case "set_output":
|
||||||
|
|||||||
@@ -641,8 +641,7 @@ namespace Subsurface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SendSignal(string signal, string connectionName, float power=0.0f)
|
||||||
public void SendSignal(string signal, string connectionName, Item ignoredReceiver = null)
|
|
||||||
{
|
{
|
||||||
ConnectionPanel panel = GetComponent<ConnectionPanel>();
|
ConnectionPanel panel = GetComponent<ConnectionPanel>();
|
||||||
if (panel == null) return;
|
if (panel == null) return;
|
||||||
@@ -650,7 +649,7 @@ namespace Subsurface
|
|||||||
{
|
{
|
||||||
if (c.name != connectionName) continue;
|
if (c.name != connectionName) continue;
|
||||||
|
|
||||||
c.SendSignal(signal, this);
|
c.SendSignal(signal, this, power);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+109
-22
@@ -181,10 +181,33 @@ namespace Subsurface
|
|||||||
cells.Remove(cell);
|
cells.Remove(cell);
|
||||||
}
|
}
|
||||||
|
|
||||||
//GenerateBodies(cells, pathCells);
|
for (int x = 0; x < cellGrid.GetLength(0); x++ )
|
||||||
|
{
|
||||||
|
for (int y = 0; y < cellGrid.GetLength(1); y++ )
|
||||||
|
{
|
||||||
|
cellGrid[x, y].Clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (VoronoiCell cell in cells)
|
||||||
|
{
|
||||||
|
cellGrid[(int)Math.Floor(cell.Center.X / gridCellWidth), (int)Math.Floor(cell.Center.Y / gridCellWidth)].Add(cell);
|
||||||
|
}
|
||||||
|
|
||||||
GeneratePolygons(cells, pathCells);
|
GeneratePolygons(cells, pathCells);
|
||||||
|
|
||||||
|
foreach (VoronoiCell cell in cells)
|
||||||
|
{
|
||||||
|
foreach (GraphEdge edge in cell.edges)
|
||||||
|
{
|
||||||
|
edge.cell1 = null;
|
||||||
|
edge.cell2 = null;
|
||||||
|
edge.site1 = null;
|
||||||
|
edge.site2 = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
Debug.WriteLine("Generatelevel: " + sw2.ElapsedMilliseconds + " ms");
|
Debug.WriteLine("Generatelevel: " + sw2.ElapsedMilliseconds + " ms");
|
||||||
sw2.Restart();
|
sw2.Restart();
|
||||||
|
|
||||||
@@ -452,6 +475,8 @@ namespace Subsurface
|
|||||||
VoronoiCell adjacentCell = ge.AdjacentCell(cell);
|
VoronoiCell adjacentCell = ge.AdjacentCell(cell);
|
||||||
if (!emptyCells.Contains(adjacentCell)) continue;
|
if (!emptyCells.Contains(adjacentCell)) continue;
|
||||||
|
|
||||||
|
ge.isSolid = true;
|
||||||
|
|
||||||
if (!bodyPoints.Contains(ge.point1)) bodyPoints.Add(ge.point1);
|
if (!bodyPoints.Contains(ge.point1)) bodyPoints.Add(ge.point1);
|
||||||
if (!bodyPoints.Contains(ge.point2)) bodyPoints.Add(ge.point2);
|
if (!bodyPoints.Contains(ge.point2)) bodyPoints.Add(ge.point2);
|
||||||
}
|
}
|
||||||
@@ -624,39 +649,101 @@ namespace Subsurface
|
|||||||
// }
|
// }
|
||||||
//}
|
//}
|
||||||
|
|
||||||
int gridPosX = (int)Math.Floor(-observerPosition.X / gridCellWidth);
|
//int gridPosX = (int)Math.Floor(-observerPosition.X / gridCellWidth);
|
||||||
int gridPosY = (int)Math.Floor(-observerPosition.Y / gridCellWidth);
|
//int gridPosY = (int)Math.Floor(-observerPosition.Y / gridCellWidth);
|
||||||
int searchOffset = 2;
|
//int searchOffset = 2;
|
||||||
|
|
||||||
int startX = Math.Max(gridPosX - searchOffset, 0);
|
//int startX = Math.Max(gridPosX - searchOffset, 0);
|
||||||
int endX = Math.Min(gridPosX + searchOffset, cellGrid.GetLength(0) - 1);
|
//int endX = Math.Min(gridPosX + searchOffset, cellGrid.GetLength(0) - 1);
|
||||||
|
|
||||||
int startY = Math.Max(gridPosY - searchOffset, 0);
|
//int startY = Math.Max(gridPosY - searchOffset, 0);
|
||||||
int endY = Math.Min(gridPosY + searchOffset, cellGrid.GetLength(1) - 1);
|
//int endY = Math.Min(gridPosY + searchOffset, cellGrid.GetLength(1) - 1);
|
||||||
|
|
||||||
|
//for (int x = startX; x < endX; x++)
|
||||||
|
//{
|
||||||
|
// for (int y = startY; y < endY; y++)
|
||||||
|
// {
|
||||||
|
// GUI.DrawRectangle(spriteBatch,
|
||||||
|
// new Rectangle(x * gridCellWidth + (int)position.X, borders.Y - borders.Height + y * gridCellWidth - (int)position.Y, gridCellWidth, gridCellWidth),
|
||||||
|
// Color.Cyan);
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
|
List<Vector2[]> edges = GetCellEdges(-observerPosition);
|
||||||
|
|
||||||
|
for (int i = 0; i < edges.Count; i++ )
|
||||||
|
{
|
||||||
|
GUI.DrawLine(spriteBatch, edges[i][0], edges[i][1], Color.Green);
|
||||||
|
}
|
||||||
|
|
||||||
|
//foreach (VoronoiCell cell in cells)
|
||||||
|
//{
|
||||||
|
// for (int i = 0; i < cell.edges.Count; i++)
|
||||||
|
// {
|
||||||
|
// Vector2 start = cell.edges[i].point1 + position;
|
||||||
|
// start.Y = -start.Y;
|
||||||
|
|
||||||
|
// Vector2 end = cell.edges[i].point2 + position;
|
||||||
|
// end.Y = -end.Y;
|
||||||
|
|
||||||
|
// GUI.DrawLine(spriteBatch, start, end, (cell.body != null && cell.body.Enabled) ? Color.Green : Color.Red);
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Vector2[]> GetCellEdges(Vector2 refPos, int searchDepth = 2, bool onlySolid = true)
|
||||||
|
{
|
||||||
|
|
||||||
|
int gridPosX = (int)Math.Floor(refPos.X / gridCellWidth);
|
||||||
|
int gridPosY = (int)Math.Floor(refPos.Y / gridCellWidth);
|
||||||
|
|
||||||
|
int startX = Math.Max(gridPosX - searchDepth, 0);
|
||||||
|
int endX = Math.Min(gridPosX + searchDepth, cellGrid.GetLength(0) - 1);
|
||||||
|
|
||||||
|
int startY = Math.Max(gridPosY - searchDepth, 0);
|
||||||
|
int endY = Math.Min(gridPosY + searchDepth, cellGrid.GetLength(1) - 1);
|
||||||
|
|
||||||
|
|
||||||
|
List<Vector2[]> edges = new List<Vector2[]>();
|
||||||
|
|
||||||
for (int x = startX; x < endX; x++)
|
for (int x = startX; x < endX; x++)
|
||||||
{
|
{
|
||||||
for (int y = startY; y < endY; y++)
|
for (int y = startY; y < endY; y++)
|
||||||
{
|
{
|
||||||
GUI.DrawRectangle(spriteBatch,
|
foreach (VoronoiCell cell in cellGrid[x,y])
|
||||||
new Rectangle(x * gridCellWidth + (int)position.X, borders.Y - borders.Height + y * gridCellWidth - (int)position.Y, gridCellWidth, gridCellWidth),
|
{
|
||||||
Color.Cyan);
|
for (int i = 0; i < cell.edges.Count; i++)
|
||||||
|
{
|
||||||
|
if (onlySolid && !cell.edges[i].isSolid) continue;
|
||||||
|
Vector2 start = cell.edges[i].point1 + position;
|
||||||
|
start.Y = -start.Y;
|
||||||
|
|
||||||
|
Vector2 end = cell.edges[i].point2 + position;
|
||||||
|
end.Y = -end.Y;
|
||||||
|
|
||||||
|
edges.Add(new Vector2[] { start, end });
|
||||||
|
//GUI.DrawLine(spriteBatch, start, end, (cell.body != null && cell.body.Enabled) ? Color.Green : Color.Red);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (VoronoiCell cell in cells)
|
//foreach (VoronoiCell cell in cells)
|
||||||
{
|
//{
|
||||||
for (int i = 0; i<cell.edges.Count; i++)
|
// for (int i = 0; i < cell.edges.Count; i++)
|
||||||
{
|
// {
|
||||||
Vector2 start = cell.edges[i].point1+position;
|
// Vector2 start = cell.edges[i].point1 + position;
|
||||||
start.Y = -start.Y;
|
// start.Y = -start.Y;
|
||||||
|
|
||||||
Vector2 end = cell.edges[i].point2+position;
|
// Vector2 end = cell.edges[i].point2 + position;
|
||||||
end.Y = -end.Y;
|
// end.Y = -end.Y;
|
||||||
|
|
||||||
GUI.DrawLine(spriteBatch, start, end, (cell.body!=null && cell.body.Enabled) ? Color.Green : Color.Red);
|
// edges.Add(new Vector2[] {start, end});
|
||||||
}
|
// //GUI.DrawLine(spriteBatch, start, end, (cell.body != null && cell.body.Enabled) ? Color.Green : Color.Red);
|
||||||
}
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
|
return edges;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Render(GraphicsDevice graphicsDevice, Camera cam)
|
public void Render(GraphicsDevice graphicsDevice, Camera cam)
|
||||||
|
|||||||
@@ -62,6 +62,12 @@ namespace Subsurface
|
|||||||
get { return lastPickedFraction; }
|
get { return lastPickedFraction; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Vector2> HullVertices
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
private set;
|
||||||
|
}
|
||||||
|
|
||||||
public Md5Hash Hash
|
public Md5Hash Hash
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@@ -402,8 +408,6 @@ namespace Subsurface
|
|||||||
}
|
}
|
||||||
//hullBodies[0].body.LinearVelocity = -hullBodies[0].body.Position;
|
//hullBodies[0].body.LinearVelocity = -hullBodies[0].body.Position;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
hullBody.SetTransform(Vector2.Zero , 0.0f);
|
hullBody.SetTransform(Vector2.Zero , 0.0f);
|
||||||
|
|
||||||
if (collidingCell == null)
|
if (collidingCell == null)
|
||||||
@@ -697,6 +701,9 @@ namespace Subsurface
|
|||||||
}
|
}
|
||||||
|
|
||||||
List<Vector2> convexHull = GenerateConvexHull();
|
List<Vector2> convexHull = GenerateConvexHull();
|
||||||
|
|
||||||
|
HullVertices = convexHull;
|
||||||
|
|
||||||
for (int i = 0; i < convexHull.Count; i++)
|
for (int i = 0; i < convexHull.Count; i++)
|
||||||
{
|
{
|
||||||
convexHull[i] = ConvertUnits.ToSimUnits(convexHull[i]);
|
convexHull[i] = ConvertUnits.ToSimUnits(convexHull[i]);
|
||||||
@@ -718,7 +725,7 @@ namespace Subsurface
|
|||||||
|
|
||||||
var triangulatedVertices = Triangulate.ConvexPartition(_shapevertices, TriangulationAlgorithm.Bayazit);
|
var triangulatedVertices = Triangulate.ConvexPartition(_shapevertices, TriangulationAlgorithm.Bayazit);
|
||||||
|
|
||||||
Body hullBody = BodyFactory.CreateCompoundPolygon(Game1.world, triangulatedVertices, 5.0f);
|
hullBody = BodyFactory.CreateCompoundPolygon(Game1.world, triangulatedVertices, 5.0f);
|
||||||
hullBody.BodyType = BodyType.Dynamic;
|
hullBody.BodyType = BodyType.Dynamic;
|
||||||
|
|
||||||
hullBody.CollisionCategories = Physics.CollisionMisc;
|
hullBody.CollisionCategories = Physics.CollisionMisc;
|
||||||
|
|||||||
@@ -143,6 +143,8 @@ namespace Voronoi2
|
|||||||
public Site site1, site2;
|
public Site site1, site2;
|
||||||
public VoronoiCell cell1, cell2;
|
public VoronoiCell cell1, cell2;
|
||||||
|
|
||||||
|
public bool isSolid;
|
||||||
|
|
||||||
public VoronoiCell AdjacentCell(VoronoiCell cell)
|
public VoronoiCell AdjacentCell(VoronoiCell cell)
|
||||||
{
|
{
|
||||||
if (cell1==cell)
|
if (cell1==cell)
|
||||||
|
|||||||
@@ -78,10 +78,11 @@
|
|||||||
<Compile Include="GUI\GUITickBox.cs" />
|
<Compile Include="GUI\GUITickBox.cs" />
|
||||||
<Compile Include="IPropertyObject.cs" />
|
<Compile Include="IPropertyObject.cs" />
|
||||||
<Compile Include="Items\CharacterInventory.cs" />
|
<Compile Include="Items\CharacterInventory.cs" />
|
||||||
<Compile Include="Items\Components\Fabricator.cs" />
|
<Compile Include="Items\Components\Machines\Fabricator.cs" />
|
||||||
<Compile Include="Items\Components\MiniMap.cs" />
|
<Compile Include="Items\Components\Machines\MiniMap.cs" />
|
||||||
<Compile Include="Items\Components\Engine.cs" />
|
<Compile Include="Items\Components\Machines\Engine.cs" />
|
||||||
<Compile Include="Items\Components\Pump.cs" />
|
<Compile Include="Items\Components\Machines\Pump.cs" />
|
||||||
|
<Compile Include="Items\Components\Machines\Radar.cs" />
|
||||||
<Compile Include="Items\Components\Signal\OxygenDetector.cs" />
|
<Compile Include="Items\Components\Signal\OxygenDetector.cs" />
|
||||||
<Compile Include="Items\Components\Signal\LightComponent.cs" />
|
<Compile Include="Items\Components\Signal\LightComponent.cs" />
|
||||||
<Compile Include="Items\Components\Signal\NotComponent.cs" />
|
<Compile Include="Items\Components\Signal\NotComponent.cs" />
|
||||||
@@ -89,8 +90,8 @@
|
|||||||
<Compile Include="Items\Components\Signal\AndComponent.cs" />
|
<Compile Include="Items\Components\Signal\AndComponent.cs" />
|
||||||
<Compile Include="Items\Components\Signal\ConnectionPanel.cs" />
|
<Compile Include="Items\Components\Signal\ConnectionPanel.cs" />
|
||||||
<Compile Include="Items\Components\Signal\RegExFindComponent.cs" />
|
<Compile Include="Items\Components\Signal\RegExFindComponent.cs" />
|
||||||
<Compile Include="Items\Components\Steering.cs" />
|
<Compile Include="Items\Components\Machines\Steering.cs" />
|
||||||
<Compile Include="Items\Components\Throwable.cs" />
|
<Compile Include="Items\Components\Holdable\Throwable.cs" />
|
||||||
<Compile Include="Items\Components\Turret.cs" />
|
<Compile Include="Items\Components\Turret.cs" />
|
||||||
<Compile Include="Items\Components\Signal\Wire.cs" />
|
<Compile Include="Items\Components\Signal\Wire.cs" />
|
||||||
<Compile Include="Items\Components\Signal\Connection.cs" />
|
<Compile Include="Items\Components\Signal\Connection.cs" />
|
||||||
@@ -108,18 +109,18 @@
|
|||||||
<Compile Include="GUI\GUIStyle.cs" />
|
<Compile Include="GUI\GUIStyle.cs" />
|
||||||
<Compile Include="GUI\GUITextBox.cs" />
|
<Compile Include="GUI\GUITextBox.cs" />
|
||||||
<Compile Include="Items\Components\Container.cs" />
|
<Compile Include="Items\Components\Container.cs" />
|
||||||
<Compile Include="Items\Components\Controller.cs" />
|
<Compile Include="Items\Components\Machines\Controller.cs" />
|
||||||
<Compile Include="Items\Components\Door.cs" />
|
<Compile Include="Items\Components\Door.cs" />
|
||||||
<Compile Include="Items\Components\Ladder.cs" />
|
<Compile Include="Items\Components\Ladder.cs" />
|
||||||
<Compile Include="Items\Components\Pickable.cs" />
|
<Compile Include="Items\Components\Holdable\Pickable.cs" />
|
||||||
<Compile Include="Items\Components\PowerContainer.cs" />
|
<Compile Include="Items\Components\Power\PowerContainer.cs" />
|
||||||
<Compile Include="Items\Components\OxygenGenerator.cs" />
|
<Compile Include="Items\Components\Machines\OxygenGenerator.cs" />
|
||||||
<Compile Include="Items\Components\Powered.cs" />
|
<Compile Include="Items\Components\Power\Powered.cs" />
|
||||||
<Compile Include="Items\Components\PowerTransfer.cs" />
|
<Compile Include="Items\Components\Power\PowerTransfer.cs" />
|
||||||
<Compile Include="Items\Components\RangedWeapon.cs" />
|
<Compile Include="Items\Components\Holdable\RangedWeapon.cs" />
|
||||||
<Compile Include="Items\Components\Reactor.cs" />
|
<Compile Include="Items\Components\Machines\Reactor.cs" />
|
||||||
<Compile Include="Items\Components\RepairTool.cs" />
|
<Compile Include="Items\Components\Holdable\RepairTool.cs" />
|
||||||
<Compile Include="Items\Components\Vent.cs" />
|
<Compile Include="Items\Components\Machines\Vent.cs" />
|
||||||
<Compile Include="Items\RelatedItem.cs" />
|
<Compile Include="Items\RelatedItem.cs" />
|
||||||
<Compile Include="Items\Components\Rope.cs" />
|
<Compile Include="Items\Components\Rope.cs" />
|
||||||
<Compile Include="Items\Components\Wearable.cs" />
|
<Compile Include="Items\Components\Wearable.cs" />
|
||||||
@@ -159,7 +160,7 @@
|
|||||||
<Compile Include="GUI\GUIProgressBar.cs" />
|
<Compile Include="GUI\GUIProgressBar.cs" />
|
||||||
<Compile Include="GUI\GUIScrollBar.cs" />
|
<Compile Include="GUI\GUIScrollBar.cs" />
|
||||||
<Compile Include="GUI\GUITextBlock.cs" />
|
<Compile Include="GUI\GUITextBlock.cs" />
|
||||||
<Compile Include="Items\Components\Holdable.cs" />
|
<Compile Include="Items\Components\Holdable\Holdable.cs" />
|
||||||
<Compile Include="Items\Components\ItemComponent.cs" />
|
<Compile Include="Items\Components\ItemComponent.cs" />
|
||||||
<Compile Include="Items\ItemPrefab.cs" />
|
<Compile Include="Items\ItemPrefab.cs" />
|
||||||
<Compile Include="Items\Item.cs" />
|
<Compile Include="Items\Item.cs" />
|
||||||
|
|||||||
@@ -189,7 +189,7 @@ namespace Subsurface
|
|||||||
if (components.Length!=2)
|
if (components.Length!=2)
|
||||||
{
|
{
|
||||||
if (!errorMessages) return vector;
|
if (!errorMessages) return vector;
|
||||||
DebugConsole.ThrowError("Failed to parse the string "+stringVector2+" to Vector2");
|
DebugConsole.ThrowError("Failed to parse the string ''"+stringVector2+"'' to Vector2");
|
||||||
return vector;
|
return vector;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -212,7 +212,7 @@ namespace Subsurface
|
|||||||
|
|
||||||
if (components.Length < 3)
|
if (components.Length < 3)
|
||||||
{
|
{
|
||||||
DebugConsole.ThrowError("Failed to parse the string " + stringVector4 + " to Vector4");
|
DebugConsole.ThrowError("Failed to parse the string ''" + stringVector4 + "'' to Vector4");
|
||||||
return vector;
|
return vector;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user