Launcher bugfixes, fixed submarine position syncing, previewing the sub after round ends, wiring bugfix, slower reactor overheat, itemlabel, wifi components

This commit is contained in:
Regalis
2015-08-21 20:21:22 +03:00
parent c044d27071
commit d8904eaa56
43 changed files with 546 additions and 228 deletions
@@ -119,7 +119,6 @@ namespace Subsurface.Items.Components
(int)doorSprite.size.X,
(int)doorSprite.size.Y);
body = new PhysicsBody(BodyFactory.CreateRectangle(Game1.World,
ConvertUnits.ToSimUnits(Math.Max(doorRect.Width, 1)),
ConvertUnits.ToSimUnits(Math.Max(doorRect.Height, 1)),
@@ -101,7 +101,7 @@ namespace Subsurface.Items.Components
Msg = "";
}
if (attachedByDefault) Use(1.0f);
if (attachedByDefault || Screen.Selected == Game1.EditMapScreen) Use(1.0f);
//holdAngle = ToolBox.GetAttributeFloat(element, "holdangle", 0.0f);
@@ -0,0 +1,66 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System.Xml.Linq;
namespace Subsurface.Items.Components
{
class ItemLabel : ItemComponent
{
private GUITextBlock textBlock;
[HasDefaultValue("", true), Editable(100)]
public string Text
{
get { return textBlock.Text; }
set
{
if (value == TextBlock.Text || item.Rect.Width < 5) return;
TextBlock.Text = value;
}
}
private Color textColor;
[Editable, HasDefaultValue("0.0,0.0,0.0,1.0", true)]
public string TextColor
{
get { return ToolBox.Vector4ToString(textColor.ToVector4()); }
set
{
textColor = new Color(ToolBox.ParseToVector4(value));
}
}
private GUITextBlock TextBlock
{
get
{
if (textBlock==null)
{
textBlock = new GUITextBlock(new Rectangle(item.Rect.X,-item.Rect.Y,item.Rect.Width, item.Rect.Height), "",
Color.Transparent, Color.Black,
Alignment.TopLeft, Alignment.Center,
null, null, true);
textBlock.Font = GUI.SmallFont;
textBlock.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f);
}
return textBlock;
}
}
public override void Move(Vector2 amount)
{
textBlock.Rect = new Rectangle(item.Rect.X, -item.Rect.Y, item.Rect.Width, item.Rect.Height);
}
public ItemLabel(Item item, XElement element)
: base(item, element)
{
}
public override void Draw(SpriteBatch spriteBatch, bool editing = false)
{
base.Draw(spriteBatch, editing);
textBlock.Draw(spriteBatch);
}
}
}
@@ -140,7 +140,7 @@ namespace Subsurface.Items.Components
float heat = 100 * fissionRate * (AvailableFuel/2000.0f);
float heatDissipation = 50 * coolingRate + ExtraCooling;
float deltaTemp = (((heat - heatDissipation) * 5) - temperature) / 1000.0f;
float deltaTemp = (((heat - heatDissipation) * 5) - temperature) / 10000.0f;
Temperature = temperature + deltaTemp;
if (temperature > meltDownTemp)
@@ -155,8 +155,7 @@ namespace Subsurface.Items.Components
powerUpTask = new PropertyTask(item, IsRunning, 50.0f, "Power up the reactor");
}
}
item.Condition -= temperature * deltaTime * 0.00005f;
if (temperature > shutDownTemp)
@@ -201,8 +200,7 @@ namespace Subsurface.Items.Components
//fission rate can't be lowered below a certain amount if the core is too hot
FissionRate = Math.Max(fissionRate, heat / 200.0f);
//the power generated by the reactor is equal to the temperature
currPowerConsumption = -temperature*powerPerTemp;
@@ -216,6 +214,8 @@ namespace Subsurface.Items.Components
ExtraCooling = 0.0f;
AvailableFuel = 0.0f;
item.SendSignal(((int)temperature).ToString(), "temperature_out");
}
public override void UpdateBroken(float deltaTime, Camera cam)
@@ -402,6 +402,16 @@ namespace Subsurface.Items.Components
GUI.DrawLine(spriteBatch, prevPoint, lastPoint, Color.White);
}
public override void ReceiveSignal(string signal, Connection connection, Item sender, float power)
{
switch (connection.Name)
{
case "shutdown":
shutDownTemp = 0.0f;
break;
}
}
public override void FillNetworkData(NetworkEventType type, NetOutgoingMessage message)
{
message.Write(autoTemp);
@@ -319,14 +319,13 @@ namespace Subsurface.Items.Components
if (index>-1)
{
Wires[index].RemoveConnection(this);
Wires[index].Item.SetTransform(item.SimPosition, 0.0f);
Wires[index].Item.Drop();
Wires[index].Item.body.Enabled = true;
//Wires[index].Item.SetTransform(item.SimPosition, 0.0f);
//Wires[index].Item.Drop();
//Wires[index].Item.body.Enabled = true;
Wires[index] = null;
}
}
}
}
}
@@ -9,6 +9,8 @@ namespace Subsurface.Items.Components
private string expression;
private string receivedSignal;
[InGameEditable, HasDefaultValue("1", true)]
public string Output
{
@@ -26,6 +28,27 @@ namespace Subsurface.Items.Components
public RegExFindComponent(Item item, XElement element)
: base(item, element)
{
isActive = true;
}
public override void Update(float deltaTime, Camera cam)
{
if (string.IsNullOrWhiteSpace(expression)) return;
bool success = false;
try
{
Regex regex = new Regex(@expression);
Match match = regex.Match(receivedSignal);
success = match.Success;
}
catch
{
item.SendSignal("ERROR", "signal_out");
return;
}
item.SendSignal(success ? output : "0", "signal_out");
}
public override void ReceiveSignal(string signal, Connection connection, Item sender, float power = 0.0f)
@@ -33,22 +56,7 @@ namespace Subsurface.Items.Components
switch (connection.Name)
{
case "signal_in":
if (string.IsNullOrWhiteSpace(expression)) return;
bool success = false;
try
{
Regex regex = new Regex(@expression);
Match match = regex.Match(signal);
success = match.Success;
}
catch
{
item.SendSignal("ERROR", "signal_out");
return;
}
item.SendSignal(success ? output : "0", "signal_out");
receivedSignal = signal;
break;
case "set_output":
@@ -0,0 +1,56 @@
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Xml.Linq;
namespace Subsurface.Items.Components
{
class WifiComponent : ItemComponent
{
private static List<WifiComponent> list = new List<WifiComponent>();
private int channel;
[InGameEditable, HasDefaultValue(1, true)]
public int Channel
{
get { return channel; }
set
{
channel = MathHelper.Clamp(value, 0, 100);
}
}
public WifiComponent(Item item, XElement element)
: base (item, element)
{
list.Add(this);
}
public override void ReceiveSignal(string signal, Connection connection, Item sender, float power=0.0f)
{
//prevent an ininite loop of wificomponents sending messages between each other
if (sender.GetComponent<WifiComponent>()!=null) return;
switch (connection.Name)
{
case "signal_in":
foreach (WifiComponent wifiComp in list)
{
if (wifiComp == this || wifiComp.channel != channel) continue;
wifiComp.item.SendSignal(signal, "signal_out");
}
break;
}
}
public override void Remove()
{
base.Remove();
list.Remove(this);
}
}
}