ItemComponent GUIFrames, functional steering, radar, separate power and signals, improved d.gz, tweak swimming

This commit is contained in:
Regalis
2015-06-29 23:51:01 +03:00
parent 004608acd8
commit b493ed2b39
42 changed files with 473 additions and 182 deletions
+1 -1
View File
@@ -310,7 +310,7 @@ namespace Subsurface.Items.Components
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")
{
@@ -35,8 +35,8 @@ namespace Subsurface.Items.Components
public RangedWeapon(Item item, XElement element)
: base(item, element)
{
barrelPos = ToolBox.GetAttributeVector2(element, "barrelpos", Vector2.Zero);
barrelPos = ConvertUnits.ToSimUnits(barrelPos);
//barrelPos = ToolBox.GetAttributeVector2(element, "barrelpos", Vector2.Zero);
//barrelPos = ConvertUnits.ToSimUnits(barrelPos);
}
public override void Update(float deltaTime, Camera cam)
+42 -1
View File
@@ -54,6 +54,8 @@ namespace Subsurface
private List<ItemSound> sounds;
private GUIFrame guiFrame;
public readonly Dictionary<string, ObjectProperty> properties;
public Dictionary<string, ObjectProperty> ObjectProperties
{
@@ -96,6 +98,19 @@ namespace Subsurface
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)]
public string Msg
{
@@ -153,6 +168,32 @@ namespace Subsurface
case "statuseffect":
statusEffects.Add(StatusEffect.Load(subElement));
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":
string filePath = ToolBox.GetAttributeString(subElement, "file", "");
if (filePath=="") continue;
@@ -284,7 +325,7 @@ namespace Subsurface
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)
{
@@ -71,17 +71,18 @@ namespace Subsurface.Items.Components
public override void DrawHUD(SpriteBatch spriteBatch, Character character)
{
//isActive = true;
GuiFrame.Draw(spriteBatch);
//int width = 300, height = 300;
//int x = Game1.GraphicsWidth / 2 - width / 2;
//int y = Game1.GraphicsHeight / 2 - height / 2 - 50;
int width = 300, height = 300;
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);
GUI.DrawRectangle(spriteBatch, new Rectangle(x, y, width, height), Color.Black, true);
spriteBatch.DrawString(GUI.font, "Force: " + (int)targetForce + " %", new Vector2(GuiFrame.Rect.X + 30, GuiFrame.Rect.Y + 30), Color.White);
spriteBatch.DrawString(GUI.font, "Force: " + (int)targetForce+" %", 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;
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(GuiFrame.Rect.X + 280, GuiFrame.Rect.Y + 80, 40, 40), "-", true)) targetForce -= 1.0f;
item.NewComponentEvent(this, true);
}
@@ -91,9 +92,9 @@ namespace Subsurface.Items.Components
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")
{
@@ -32,12 +32,13 @@ namespace Subsurface.Items.Components
public override void DrawHUD(SpriteBatch spriteBatch, Character character)
{
int width = 500, height = 400;
int x = Game1.GraphicsWidth / 2 - width / 2;
int y = Game1.GraphicsHeight / 2 - height / 2;
int width = GuiFrame.Rect.Width, height = GuiFrame.Rect.Height;
int x = GuiFrame.Rect.X;
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);
@@ -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")
{
@@ -150,7 +152,7 @@ namespace Subsurface.Items.Components
float 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()
{
}
}
}
@@ -300,9 +300,11 @@ namespace Subsurface.Items.Components
{
isActive = true;
int width = 500, height = 420;
int x = Game1.GraphicsWidth / 2 - width / 2;
int y = Game1.GraphicsHeight / 2 - height / 2 - 50;
int width = GuiFrame.Rect.Width, height = GuiFrame.Rect.Height;
int x = GuiFrame.Rect.X;
int y = GuiFrame.Rect.Y;
GuiFrame.Draw(spriteBatch);
float xOffset = (graphTimer / (float)updateGraphInterval);
@@ -23,24 +23,22 @@ namespace Subsurface.Items.Components
{
base.Update(deltaTime, cam);
item.SendSignal(targetVelocity.X.ToString(), "velocity_x_out", item);
item.SendSignal(targetVelocity.Y.ToString(), "velocity_y_out", item);
item.SendSignal(targetVelocity.X.ToString(), "velocity_x_out");
item.SendSignal((-targetVelocity.Y).ToString(), "velocity_y_out");
}
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;
int x = Game1.GraphicsWidth / 2 - width / 2;
int y = Game1.GraphicsHeight / 2 - height / 2 - 50;
GuiFrame.Draw(spriteBatch);
GUI.DrawRectangle(spriteBatch, new Rectangle(x, y, width, height), Color.Black, true);
Rectangle velRect = new Rectangle(x+20, y+20, 100, 100);
Rectangle velRect = new Rectangle(x + 20, y + 20, width - 40, height - 40);
GUI.DrawRectangle(spriteBatch, velRect, Color.White, false);
GUI.DrawLine(spriteBatch,
GUI.DrawLine(spriteBatch,
new Vector2(velRect.Center.X,velRect.Center.Y),
new Vector2(velRect.Center.X + currVelocity.X, velRect.Center.Y - currVelocity.Y),
Color.Gray);
@@ -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);
}
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")
{
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();
}
}
}
@@ -49,9 +49,8 @@ namespace Subsurface.Items.Components
{
pt.powerLoad += (fullLoad - pt.powerLoad) / inertia;
pt.currPowerConsumption += (-fullPower - pt.currPowerConsumption) / inertia;
pt.Item.SendSignal(
(fullPower / Math.Max(fullLoad,1.0f)).ToString(CultureInfo.InvariantCulture),
"power_out");
pt.Item.SendSignal("",
"power", fullPower / Math.Max(fullLoad, 1.0f));
}
else
@@ -126,9 +125,11 @@ namespace Subsurface.Items.Components
public override void DrawHUD(SpriteBatch spriteBatch, Character character)
{
int width = 300, height = 200;
int x = Game1.GraphicsWidth / 2 - width / 2;
int y = Game1.GraphicsHeight / 2 - height / 2;
int width = GuiFrame.Rect.Width, height = GuiFrame.Rect.Height;
int x = GuiFrame.Rect.X;
int y = GuiFrame.Rect.Y;
GuiFrame.Draw(spriteBatch);
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);
}
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);
}
}
}
}
@@ -59,15 +59,9 @@ namespace Subsurface.Items.Components
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 (!float.TryParse(signal, NumberStyles.Any, CultureInfo.InvariantCulture, out voltage))
{
voltage = 0.0f;
}
}
if (connection.name=="power_in") voltage = power;
}
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)
{
@@ -135,7 +135,7 @@ namespace Subsurface.Items.Components
// 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++)
{
@@ -146,7 +146,7 @@ namespace Subsurface.Items.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);
}
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)
{
@@ -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;
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)
{
@@ -44,11 +44,11 @@ namespace Subsurface.Items.Components
}
catch
{
item.SendSignal("ERROR", "signal_out", item);
item.SendSignal("ERROR", "signal_out");
return;
}
item.SendSignal(success ? output : "0", "signal_out", item);
item.SendSignal(success ? output : "0", "signal_out");
break;
case "set_output":