+ character input keys in array instead of separate variables
This commit is contained in:
Regalis11
2015-08-22 16:57:57 +03:00
102 changed files with 1847 additions and 709 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);
@@ -53,7 +53,7 @@ namespace Subsurface.Items.Components
public override bool Use(float deltaTime, Character character = null)
{
if (character == null) return false;
if (!character.SecondaryKeyDown.State || reload > 0.0f) return false;
if (!character.GetInputState(InputType.SecondaryHeld) || reload > 0.0f) return false;
isActive = true;
reload = 1.0f;
@@ -102,7 +102,7 @@ namespace Subsurface.Items.Components
public override bool Use(float deltaTime, Character character = null)
{
if (character == null) return false;
if (!character.SecondaryKeyDown.State) return false;
if (!character.GetInputState(InputType.SecondaryHeld)) return false;
if (DoesUseFail(character)) return false;
@@ -146,7 +146,7 @@ namespace Subsurface.Items.Components
}
else if ((targetLimb = (targetBody.UserData as Limb)) != null)
{
if (character.SecondaryKeyDown.State)
if (character.GetInputState(InputType.SecondaryHeld))
{
targetLimb.character.Health += limbFixAmount;
//isActive = true;
@@ -28,7 +28,7 @@ namespace Subsurface.Items.Components
public override bool Use(float deltaTime, Character character = null)
{
if (character == null) return false;
if (!character.SecondaryKeyDown.State || throwing) return false;
if (!character.GetInputState(InputType.SecondaryHeld) || throwing) return false;
throwing = true;
@@ -60,7 +60,7 @@ namespace Subsurface.Items.Components
if (!item.body.Enabled) return;
if (!picker.HasSelectedItem(item)) isActive = false;
if (!picker.SecondaryKeyDown.State && !throwing) throwPos = 0.0f;
if (!picker.GetInputState(InputType.SecondaryHeld) && !throwing) throwPos = 0.0f;
ApplyStatusEffects(ActionType.OnActive, deltaTime, picker);
@@ -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);
}
}
}
+4 -1
View File
@@ -92,8 +92,11 @@ namespace Subsurface.Items.Components
newText = message.ReadString();
}
catch
catch (Exception e)
{
#if DEBUG
DebugConsole.ThrowError("invalid network message", e);
#endif
return;
}
@@ -66,7 +66,9 @@ namespace Subsurface.Items.Components
{
this.cam = cam;
if (character == null || character.SelectedConstruction != item)
if (character == null
|| character.SelectedConstruction != item
|| Vector2.Distance(character.SimPosition, item.SimPosition) > item.PickDistance * 1.5f)
{
if (character != null)
{
@@ -22,8 +22,9 @@ namespace Subsurface.Items.Components
get { return flowPercentage; }
set
{
if (float.IsNaN(flowPercentage)) return;
flowPercentage = MathHelper.Clamp(value,-100.0f,100.0f);
if (!MathUtils.IsValid(flowPercentage)) return;
flowPercentage = MathHelper.Clamp(value,-100.0f,100.0f);
flowPercentage = MathUtils.Round(flowPercentage, 1.0f);
}
}
@@ -117,14 +118,14 @@ namespace Subsurface.Items.Components
spriteBatch.DrawString(GUI.Font, "Flow percentage: " + (int)flowPercentage + " %", new Vector2(x + 20, y + 80), Color.White);
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 200, y + 70, 40, 40), "+", true))
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 200, y + 70, 40, 40), "+", false))
{
FlowPercentage += 1.0f;
FlowPercentage += 10.0f;
item.NewComponentEvent(this, true);
}
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 250, y + 70, 40, 40), "-", true))
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 250, y + 70, 40, 40), "-", false))
{
FlowPercentage -= 1.0f;
FlowPercentage -= 10.0f;
item.NewComponentEvent(this, true);
}
@@ -166,7 +167,7 @@ namespace Subsurface.Items.Components
public override void FillNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetOutgoingMessage message)
{
message.Write(flowPercentage);
message.Write(Convert.ToByte(flowPercentage+100));
message.Write(isActive);
}
@@ -177,11 +178,17 @@ namespace Subsurface.Items.Components
try
{
newFlow = message.ReadFloat();
newFlow = (float)(message.ReadByte()-100);
newActive = message.ReadBoolean();
}
catch { return; }
catch (Exception e)
{
#if DEBUG
DebugConsole.ThrowError("invalid network message", e);
#endif
return;
}
FlowPercentage = newFlow;
isActive = newActive;
@@ -68,19 +68,31 @@ namespace Subsurface.Items.Components
public float FissionRate
{
get { return fissionRate; }
set { fissionRate = MathHelper.Clamp(value, 0.0f, 100.0f); }
set
{
if (!MathUtils.IsValid(value)) return;
fissionRate = MathHelper.Clamp(value, 0.0f, 100.0f);
}
}
public float CoolingRate
{
get { return coolingRate; }
set { coolingRate = MathHelper.Clamp(value, 0.0f, 100.0f); }
set
{
if (!MathUtils.IsValid(value)) return;
coolingRate = MathHelper.Clamp(value, 0.0f, 100.0f);
}
}
public float Temperature
{
get { return temperature; }
set { temperature = MathHelper.Clamp(value, 0.0f, 10000.0f); }
set
{
if (!MathUtils.IsValid(value)) return;
temperature = MathHelper.Clamp(value, 0.0f, 10000.0f);
}
}
public bool IsRunning()
@@ -100,6 +112,7 @@ namespace Subsurface.Items.Components
public float ShutDownTemp
{
get { return shutDownTemp; }
private set { shutDownTemp = MathHelper.Clamp(value, 0.0f, 10000.0f); }
}
public Reactor(Item item, XElement element)
@@ -127,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)
@@ -142,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)
@@ -188,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;
@@ -203,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)
@@ -239,24 +252,15 @@ namespace Subsurface.Items.Components
new RepairTask(item, 60.0f, "Reactor meltdown!");
item.Condition = 0.0f;
//fissionRate = 0.0f;
//coolingRate = 0.0f;
//PlaySound(ActionType.OnFailure, item.Position);
//item.ApplyStatusEffects(ActionType.OnFailure, 1.0f, null);
//new Explosion(item.SimPosition, 6.0f, 500.0f, 600.0f, 10.0f, 2.0f).Explode();
var containedItems = item.ContainedItems;
if (containedItems == null) return;
if (item.ContainedItems!=null)
foreach (Item containedItem in item.ContainedItems)
{
foreach (Item containedItem in item.ContainedItems)
{
if (containedItem == null) continue;
containedItem.Condition = 0.0f;
}
if (containedItem == null) continue;
containedItem.Condition = 0.0f;
}
}
public override bool Pick(Character picker)
@@ -343,12 +347,12 @@ namespace Subsurface.Items.Components
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 400, y + 180, 40, 40), "+", true))
{
valueChanged = true;
shutDownTemp += 100.0f;
ShutDownTemp += 100.0f;
}
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 450, y + 180, 40, 40), "-", true))
{
valueChanged = true;
shutDownTemp -= 100.0f;
ShutDownTemp -= 100.0f;
}
if (valueChanged)
@@ -398,14 +402,24 @@ 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);
message.Write(temperature);
message.Write(shutDownTemp);
message.WriteRangedSingle(temperature, 0.0f, 10000.0f, 16);
message.WriteRangedSingle(shutDownTemp, 0.0f, 10000.0f, 16);
message.Write(coolingRate);
message.Write(fissionRate);
message.WriteRangedSingle(coolingRate, 0.0f, 100.0f, 8);
message.WriteRangedSingle(fissionRate, 0.0f, 100.0f, 8);
}
public override void ReadNetworkData(NetworkEventType type, NetIncomingMessage message)
@@ -417,18 +431,24 @@ namespace Subsurface.Items.Components
try
{
newAutoTemp = message.ReadBoolean();
newTemperature = message.ReadFloat();
newShutDownTemp = message.ReadFloat();
newTemperature = message.ReadRangedSingle(0.0f, 10000.0f, 16);
newShutDownTemp = message.ReadRangedSingle(0.0f, 10000.0f, 16);
newCoolingRate = message.ReadFloat();
newFissionRate = message.ReadFloat();
newCoolingRate = message.ReadRangedSingle(0.0f, 100.0f, 8);
newFissionRate = message.ReadRangedSingle(0.0f, 100.0f, 8);
}
catch { return; }
catch (Exception e)
{
#if DEBUG
DebugConsole.ThrowError("invalid network message", e);
#endif
return;
}
autoTemp = newAutoTemp;
Temperature = newTemperature;
shutDownTemp = newShutDownTemp;
ShutDownTemp = newShutDownTemp;
CoolingRate = newCoolingRate;
FissionRate = newFissionRate;
@@ -48,10 +48,7 @@ namespace Subsurface.Items.Components
get { return targetVelocity;}
set
{
if (float.IsNaN(value.X) || float.IsNaN(value.Y))
{
return;
}
if (!MathUtils.IsValid(value)) return;
targetVelocity.X = MathHelper.Clamp(value.X, -100.0f, 100.0f);
targetVelocity.Y = MathHelper.Clamp(value.Y, -100.0f, 100.0f);
}
@@ -173,16 +173,19 @@ namespace Subsurface.Items.Components
(float)Math.Cos(item.body.Rotation),
(float)Math.Sin(item.body.Rotation));
if (Vector2.Dot(f1.Body.LinearVelocity, normal)<0 ) return StickToTarget(f2.Body, dir);
if (Vector2.Dot(f1.Body.LinearVelocity, normal) < 0.0f) return StickToTarget(f2.Body, dir);
}
foreach (Item contained in item.ContainedItems)
var containedItems = item.ContainedItems;
if (containedItems == null) return true;
foreach (Item contained in containedItems)
{
contained.Condition = 0.0f;
if (contained.body!=null)
if (contained.body != null)
{
contained.body.SetTransform(item.SimPosition, contained.body.Rotation);
contained.SetTransform(item.SimPosition, contained.body.Rotation);
}
contained.Condition = 0.0f;
}
return true;
@@ -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);
}
}
}
+24 -26
View File
@@ -106,8 +106,31 @@ namespace Subsurface.Items.Components
if (reload > 0.0f) return false;
Projectile projectileComponent = null;
//search for a projectile from linked containers
Item projectile = null;
foreach (MapEntity e in item.linkedTo)
{
Item container = e as Item;
if (container == null) continue;
ItemContainer containerComponent = container.GetComponent<ItemContainer>();
if (containerComponent == null) continue;
for (int i = 0; i < containerComponent.inventory.items.Length; i++)
{
if (containerComponent.inventory.items[i] == null) continue;
if ((projectileComponent = containerComponent.inventory.items[i].GetComponent<Projectile>()) != null)
{
projectile = containerComponent.inventory.items[i];
break;
}
}
if (projectileComponent != null) break;
}
if (projectile == null || projectileComponent == null) return false;
//currPowerConsumption = powerConsumption;
float availablePower = 0.0f;
//List<PowerContainer> batteries = new List<PowerContainer>();
@@ -132,31 +155,6 @@ namespace Subsurface.Items.Components
if (availablePower < currPowerConsumption) return false;
//search for a projectile from linked containers
Item projectile = null;
foreach (MapEntity e in item.linkedTo)
{
Item container = e as Item;
if (container == null) continue;
ItemContainer containerComponent = container.GetComponent<ItemContainer>();
if (containerComponent == null) continue;
for (int i = 0; i < containerComponent.inventory.items.Length; i++)
{
if (containerComponent.inventory.items[i] == null) continue;
if ((projectileComponent = containerComponent.inventory.items[i].GetComponent<Projectile>()) != null)
{
projectile = containerComponent.inventory.items[i];
break;
}
}
if (projectileComponent != null) break;
}
if (projectile == null || projectileComponent==null) return false;
projectile.body.ResetDynamics();
projectile.body.Enabled = true;
projectile.SetTransform(ConvertUnits.ToSimUnits(new Vector2(item.Rect.X + barrelPos.X, item.Rect.Y - barrelPos.Y)), -rotation);