GUIStyle improvements & some simple UI graphics, networking bugfixes, separate Random class, some StyleCop cleanup

This commit is contained in:
Regalis
2015-07-02 22:24:50 +03:00
parent b493ed2b39
commit d836a99515
119 changed files with 8842 additions and 1277 deletions
+7 -7
View File
@@ -120,7 +120,7 @@ namespace Subsurface.Items.Components
(int)doorSprite.size.Y);
body = new PhysicsBody(BodyFactory.CreateRectangle(Game1.world,
body = new PhysicsBody(BodyFactory.CreateRectangle(Game1.World,
ConvertUnits.ToSimUnits(Math.Max(doorRect.Width, 1)),
ConvertUnits.ToSimUnits(Math.Max(doorRect.Height, 1)),
1.5f));
@@ -281,10 +281,10 @@ namespace Subsurface.Items.Components
Vector2 simSize = ConvertUnits.ToSimUnits(new Vector2(item.Rect.Width,
item.Rect.Height * (1.0f - openState)));
foreach (Character c in Character.characterList)
foreach (Character c in Character.CharacterList)
{
int dir = Math.Sign(c.animController.limbs[0].SimPosition.X - simPos.X);
foreach (Limb l in c.animController.limbs)
int dir = Math.Sign(c.AnimController.limbs[0].SimPosition.X - simPos.X);
foreach (Limb l in c.AnimController.limbs)
{
if (l.SimPosition.Y < simPos.Y || l.SimPosition.Y > simPos.Y - simSize.Y) continue;
if (Math.Abs(l.SimPosition.X - simPos.X) > simSize.X * 2.0f) continue;
@@ -300,7 +300,7 @@ namespace Subsurface.Items.Components
{
base.Remove();
Game1.world.RemoveBody(body.FarseerBody);
Game1.World.RemoveBody(body.FarseerBody);
if (linkedGap!=null) linkedGap.Remove();
@@ -312,11 +312,11 @@ namespace Subsurface.Items.Components
public override void ReceiveSignal(string signal, Connection connection, Item sender, float power=0.0f)
{
if (connection.name=="toggle")
if (connection.Name=="toggle")
{
isOpen = !isOpen;
}
else if (connection.name == "set_state")
else if (connection.Name == "set_state")
{
isOpen = (signal!="0");
}
@@ -129,7 +129,7 @@ namespace Subsurface.Items.Components
if (!item.body.Enabled)
{
Limb rightHand = picker.animController.GetLimb(LimbType.RightHand);
Limb rightHand = picker.AnimController.GetLimb(LimbType.RightHand);
item.SetTransform(rightHand.SimPosition, 0.0f);
}
@@ -197,9 +197,9 @@ namespace Subsurface.Items.Components
ApplyStatusEffects(ActionType.OnActive, deltaTime, picker);
if (item.body.Dir != picker.animController.Dir) Flip(item);
if (item.body.Dir != picker.AnimController.Dir) Flip(item);
AnimController ac = picker.animController;
AnimController ac = picker.AnimController;
ac.HoldItem(deltaTime, cam, item, handlePos, holdPos, aimPos, holdAngle);
}
@@ -81,7 +81,7 @@ namespace Subsurface.Items.Components
if (item.body!= null && !item.body.Enabled)
{
Limb rightHand = picker.animController.GetLimb(LimbType.RightHand);
Limb rightHand = picker.AnimController.GetLimb(LimbType.RightHand);
item.SetTransform(rightHand.SimPosition, 0.0f);
item.body.Enabled = true;
}
@@ -58,7 +58,7 @@ namespace Subsurface.Items.Components
reload = 1.0f;
List<Body> limbBodies = new List<Body>();
foreach (Limb l in character.animController.limbs)
foreach (Limb l in character.AnimController.limbs)
{
limbBodies.Add(l.body.FarseerBody);
}
@@ -104,7 +104,7 @@ namespace Subsurface.Items.Components
(float)Math.Sin(item.body.Rotation)) * range * item.body.Dir;
List<Body> ignoredBodies = new List<Body>();
foreach (Limb limb in character.animController.limbs)
foreach (Limb limb in character.AnimController.limbs)
{
ignoredBodies.Add(limb.body.FarseerBody);
}
@@ -64,9 +64,9 @@ namespace Subsurface.Items.Components
ApplyStatusEffects(ActionType.OnActive, deltaTime, picker);
if (item.body.Dir != picker.animController.Dir) Flip(item);
if (item.body.Dir != picker.AnimController.Dir) Flip(item);
AnimController ac = picker.animController;
AnimController ac = picker.AnimController;
ac.HoldItem(deltaTime, cam, item, handlePos, new Vector2(throwPos, 0.0f), aimPos, holdAngle);
+15 -15
View File
@@ -15,18 +15,18 @@ namespace Subsurface
{
class ItemSound
{
public readonly Sound sound;
public readonly ActionType type;
public readonly Sound Sound;
public readonly ActionType Type;
public string volumeProperty;
public string VolumeProperty;
public readonly float range;
public readonly float Range;
public ItemSound(Sound sound, ActionType type, float range)
{
this.sound = sound;
this.type = type;
this.range = range;
this.Sound = sound;
this.Type = type;
this.Range = range;
}
}
@@ -191,7 +191,7 @@ namespace Subsurface
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;
//guiFrame.Alpha = color.W;
break;
case "sound":
@@ -218,7 +218,7 @@ namespace Subsurface
float range = ToolBox.GetAttributeFloat(subElement, "range", 800.0f);
ItemSound itemSound = new ItemSound(sound, type, range);
itemSound.volumeProperty = ToolBox.GetAttributeString(subElement, "volume", "");
itemSound.VolumeProperty = ToolBox.GetAttributeString(subElement, "volume", "");
sounds.Add(itemSound);
break;
}
@@ -233,16 +233,16 @@ namespace Subsurface
ItemSound itemSound = null;
if (!loop || !Sounds.SoundManager.IsPlaying(loopingSoundIndex))
{
List<ItemSound> matchingSounds = sounds.FindAll(x => x.type == type);
List<ItemSound> matchingSounds = sounds.FindAll(x => x.Type == type);
if (matchingSounds.Count == 0) return;
int index = Game1.localRandom.Next(matchingSounds.Count);
int index = Rand.Int(matchingSounds.Count);
itemSound = sounds[index];
if (itemSound.volumeProperty != "")
if (itemSound.VolumeProperty != "")
{
ObjectProperty op = null;
if (properties.TryGetValue(itemSound.volumeProperty.ToLower(), out op))
if (properties.TryGetValue(itemSound.VolumeProperty.ToLower(), out op))
{
float newVolume = 0.0f;
float.TryParse(op.GetValue().ToString(), NumberStyles.Any, CultureInfo.InvariantCulture, out newVolume);
@@ -258,12 +258,12 @@ namespace Subsurface
if (loop)
{
//if (loopingSound != null && loopingSound.volumeProperty != "") volume = float.Parse(properties[loopingSound.volumeProperty].GetValue().ToString());
loopingSoundIndex = loopingSound.sound.Loop(loopingSoundIndex, volume, position, loopingSound.range);
loopingSoundIndex = loopingSound.Sound.Loop(loopingSoundIndex, volume, position, loopingSound.Range);
}
else
{
itemSound.sound.Play(volume, itemSound.range, position);
itemSound.Sound.Play(volume, itemSound.Range, position);
}
}
+1 -1
View File
@@ -14,7 +14,7 @@ namespace Subsurface.Items.Components
{
if (picker == null) return false;
picker.animController.anim = AnimController.Animation.Climbing;
picker.AnimController.Anim = AnimController.Animation.Climbing;
//picker.SelectedConstruction = item;
return true;
@@ -80,7 +80,7 @@ namespace Subsurface.Items.Components
if (character != null)
{
character.SelectedConstruction = null;
character.animController.anim = AnimController.Animation.None;
character.AnimController.Anim = AnimController.Animation.None;
character = null;
}
isActive = false;
@@ -89,33 +89,33 @@ namespace Subsurface.Items.Components
ApplyStatusEffects(ActionType.OnActive, deltaTime, character);
if (userPos != 0.0f && character.animController.anim != AnimController.Animation.UsingConstruction)
if (userPos != 0.0f && character.AnimController.Anim != AnimController.Animation.UsingConstruction)
{
Limb torso = character.animController.GetLimb(LimbType.Torso);
Limb torso = character.AnimController.GetLimb(LimbType.Torso);
float torsoX = ConvertUnits.ToDisplayUnits(torso.SimPosition.X);
if (Math.Abs(torsoX - item.Rect.X + userPos) > 10.0f)
{
character.animController.anim = AnimController.Animation.None;
character.AnimController.Anim = AnimController.Animation.None;
character.animController.TargetMovement =
character.AnimController.TargetMovement =
new Vector2(
Math.Min(Math.Max(item.Rect.X + userPos - torsoX, -1.0f), 1.0f),
0.0f);
character.animController.targetDir = (Math.Sign(torsoX - item.Rect.X + userPos) == 1) ? Direction.Right : Direction.Left;
character.AnimController.TargetDir = (Math.Sign(torsoX - item.Rect.X + userPos) == 1) ? Direction.Right : Direction.Left;
return;
}
}
if (limbPositions.Count == 0) return;
character.animController.anim = AnimController.Animation.UsingConstruction;
character.animController.ResetPullJoints();
if (dir != 0) character.animController.targetDir = dir;
character.AnimController.Anim = AnimController.Animation.UsingConstruction;
character.AnimController.ResetPullJoints();
if (dir != 0) character.AnimController.TargetDir = dir;
foreach (LimbPos lb in limbPositions)
{
Limb limb = character.animController.GetLimb(lb.limbType);
Limb limb = character.AnimController.GetLimb(lb.limbType);
if (limb == null) continue;
FixedMouseJoint fmj = limb.pullJoint;
@@ -167,7 +167,7 @@ namespace Subsurface.Items.Components
{
character = null;
isActive = false;
if (activator != null) activator.animController.anim = AnimController.Animation.None;
if (activator != null) activator.AnimController.Anim = AnimController.Animation.None;
return false;
}
+15 -6
View File
@@ -30,7 +30,7 @@ namespace Subsurface.Items.Components
}
}
[Editable, HasDefaultValue(50000.0f, true)]
[Editable, HasDefaultValue(500.0f, true)]
public float MaxForce
{
get { return maxForce; }
@@ -62,9 +62,17 @@ namespace Subsurface.Items.Components
Force = MathHelper.Lerp(force, (voltage < minVoltage) ? 0.0f : targetForce, 0.1f);
if (Force != 0.0f)
{
Submarine.Loaded.ApplyForce(new Vector2((force / 100.0f) * maxForce * (voltage / minVoltage), 0.0f));
Vector2 currForce = new Vector2((force / 100.0f) * maxForce * (voltage / minVoltage), 0.0f);
Submarine.Loaded.ApplyForce(currForce);
for (int i = 0; i < 5; i++)
{
Game1.particleManager.CreateParticle("bubbles", item.SimPosition,
-currForce/500.0f + new Vector2(Rand.Range(-1.0f, 1.0f), Rand.Range(-0.5f, 0.5f)));
}
}
voltage = 0.0f;
}
@@ -79,7 +87,7 @@ namespace Subsurface.Items.Components
//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(GuiFrame.Rect.X + 30, GuiFrame.Rect.Y + 30), Color.White);
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;
@@ -96,12 +104,13 @@ namespace Subsurface.Items.Components
{
base.ReceiveSignal(signal, connection, sender, power);
if (connection.name == "set_force")
if (connection.Name == "set_force")
{
float tempForce;
if (float.TryParse(signal, NumberStyles.Float, CultureInfo.InvariantCulture, out tempForce))
{
Force = tempForce;
targetForce = tempForce;
targetForce = MathHelper.Clamp(targetForce, -100.0f, 100.0f);
}
}
}
@@ -90,12 +90,9 @@ namespace Subsurface.Items.Components
//frame.SelectedColor = Color.Gold * 0.5f;
GUITextBlock textBlock = new GUITextBlock(
new Rectangle(0, 0, 0, 25),
fi.TargetItem.Name,
new Rectangle(0, 0, 0, 25), fi.TargetItem.Name,
color, Color.Black,
Alignment.Left,
Alignment.Left,
itemList);
Alignment.Left, Alignment.Left, null, itemList);
textBlock.UserData = fi;
textBlock.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f);
@@ -114,7 +111,7 @@ namespace Subsurface.Items.Components
int width = 200, height = 150;
selectedItemFrame = new GUIFrame(new Rectangle(Game1.GraphicsWidth / 2 - width / 2, itemList.Rect.Bottom+20, width, height), Color.Black*0.8f);
selectedItemFrame.Padding = GUI.style.smallPadding;
//selectedItemFrame.Padding = GUI.style.smallPadding;
if (targetItem.TargetItem.sprite != null)
{
@@ -134,10 +131,10 @@ namespace Subsurface.Items.Components
text,
Color.Transparent, Color.White,
Alignment.CenterX | Alignment.CenterY,
Alignment.Left,
Alignment.Left, null,
selectedItemFrame);
GUIButton button = new GUIButton(new Rectangle(0,0,100,20), "Create", Color.White, Alignment.CenterX | Alignment.Bottom, selectedItemFrame);
GUIButton button = new GUIButton(new Rectangle(0,0,100,20), "Create", Color.White, Alignment.CenterX | Alignment.Bottom, GUI.style, selectedItemFrame);
button.OnClicked = StartFabricating;
button.UserData = targetItem;
@@ -67,9 +67,9 @@ namespace Subsurface.Items.Components
GUI.DrawRectangle(spriteBatch, hullRect, Color.White);
}
foreach (Character c in Character.characterList)
foreach (Character c in Character.CharacterList)
{
if (c.animController.CurrentHull!=null) continue;
if (c.AnimController.CurrentHull!=null) continue;
Rectangle characterRect = new Rectangle(
miniMap.X + (int)((c.Position.X - Submarine.Borders.X) * size),
@@ -36,7 +36,7 @@ namespace Subsurface.Items.Components
currPowerConsumption = powerConsumption;
if (item.currentHull == null) return;
if (item.CurrentHull == null) return;
if (voltage < minVoltage)
{
@@ -56,7 +56,7 @@ namespace Subsurface.Items.Components
running = true;
float deltaOxygen = Math.Min(voltage, 1.0f) * 50000.0f;
item.currentHull.Oxygen += deltaOxygen * deltaTime;
item.CurrentHull.Oxygen += deltaOxygen * deltaTime;
UpdateVents(deltaOxygen);
+25 -4
View File
@@ -10,6 +10,8 @@ namespace Subsurface.Items.Components
float flowPercentage;
float maxFlow;
float? targetLevel;
//bool flowIn;
Hull hull1, hull2;
@@ -41,7 +43,18 @@ namespace Subsurface.Items.Components
float powerFactor = (currPowerConsumption==0.0f) ? 1.0f : voltage;
//flowPercentage = maxFlow * powerFactor;
float deltaVolume = (flowPercentage/100.0f) * maxFlow * powerFactor;
float deltaVolume = 0.0f;
if (targetLevel!=null)
{
float hullPercentage = 0.0f;
if (hull1 != null) hullPercentage = (hull1.Volume / hull1.FullVolume)*100.0f;
deltaVolume = ((float)targetLevel - hullPercentage)/100.0f * maxFlow * powerFactor;
}
else
{
deltaVolume = (flowPercentage/100.0f) * maxFlow * powerFactor;
}
hull1.Volume += deltaVolume;
if (hull2 != null) hull2.Volume -= deltaVolume;
@@ -139,15 +152,15 @@ namespace Subsurface.Items.Components
isActive = true;
if (connection.name == "toggle")
if (connection.Name == "toggle")
{
isActive = !isActive;
}
else if (connection.name == "set_active")
else if (connection.Name == "set_active")
{
isActive = (signal != "0");
}
else if (connection.name == "set_speed")
else if (connection.Name == "set_speed")
{
float tempSpeed;
if (float.TryParse(signal, NumberStyles.Float, CultureInfo.InvariantCulture, out tempSpeed))
@@ -155,6 +168,14 @@ namespace Subsurface.Items.Components
flowPercentage = MathHelper.Clamp(tempSpeed, -100.0f, 100.0f);
}
}
else if (connection.Name == "set_targetlevel")
{
float tempTarget;
if (float.TryParse(signal, NumberStyles.Float, CultureInfo.InvariantCulture, out tempTarget))
{
targetLevel = MathHelper.Clamp(tempTarget, 0.0f, 100.0f);
}
}
}
@@ -55,7 +55,7 @@ namespace Subsurface.Items.Components
float scale = 0.01f;
List<Vector2[]> edges = Level.Loaded.GetCellEdges(-Level.Loaded.position, 5);
List<Vector2[]> edges = Level.Loaded.GetCellEdges(-Level.Loaded.Position, 5);
Vector2 offset = Vector2.Zero; //Level.Loaded.position;
//offset.Y = -offset.Y;
@@ -181,10 +181,10 @@ namespace Subsurface.Items.Components
//the power generated by the reactor is equal to the temperature
currPowerConsumption = -temperature*powerPerTemp;
if (item.currentHull != null)
if (item.CurrentHull != null)
{
//the sound can be heard from 20 000 display units away when everything running at 100%
item.currentHull.SoundRange += (coolingRate + fissionRate) * 100;
item.CurrentHull.SoundRange += (coolingRate + fissionRate) * 100;
}
UpdateGraph(deltaTime);
@@ -68,7 +68,7 @@ namespace Subsurface.Items.Components
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);
}
+2 -2
View File
@@ -23,9 +23,9 @@ namespace Subsurface.Items.Components
{
base.Update(deltaTime, cam);
if (item.currentHull == null) return;
if (item.CurrentHull == null) return;
item.currentHull.Oxygen += oxygenFlow * deltaTime;
item.CurrentHull.Oxygen += oxygenFlow * deltaTime;
OxygenFlow -= deltaTime * 1000.0f;
}
}
@@ -141,7 +141,7 @@ namespace Subsurface.Items.Components
{
base.ReceiveSignal(signal, connection, sender, power);
if (connection.name=="signal")
if (connection.Name=="signal")
{
connection.SendSignal(signal, item, 0.0f);
}
+1 -1
View File
@@ -61,7 +61,7 @@ namespace Subsurface.Items.Components
public override void ReceiveSignal(string signal, Connection connection, Item sender, float power)
{
if (connection.name=="power_in") voltage = power;
if (connection.Name=="power_in") voltage = power;
}
public override void Update(float deltaTime, Camera cam)
+4 -4
View File
@@ -106,7 +106,7 @@ namespace Subsurface.Items.Components
if (stickJoint != null && doesStick)
{
if (stickTarget!=null) item.body.FarseerBody.RestoreCollisionWith(stickTarget);
Game1.world.RemoveJoint(stickJoint);
Game1.World.RemoveJoint(stickJoint);
stickJoint = null;
}
}
@@ -122,7 +122,7 @@ namespace Subsurface.Items.Components
item.body.FarseerBody.RestoreCollisionWith(stickTarget);
}
Game1.world.RemoveJoint(stickJoint);
Game1.World.RemoveJoint(stickJoint);
stickJoint = null;
isActive = false;
@@ -181,7 +181,7 @@ namespace Subsurface.Items.Components
ignoredBodies.Clear();
if (attackResult.hitArmor)
if (attackResult.HitArmor)
{
item.body.LinearVelocity *= 0.5f;
}
@@ -211,7 +211,7 @@ namespace Subsurface.Items.Components
item.body.FarseerBody.IgnoreCollisionWith(targetBody);
stickTarget = targetBody;
Game1.world.AddJoint(stickJoint);
Game1.World.AddJoint(stickJoint);
isActive = true;
+7 -7
View File
@@ -90,7 +90,7 @@ namespace Subsurface.Items.Components
Vertices box = PolygonTools.CreateRectangle(sectionLength, 0.05f);
PolygonShape shape = new PolygonShape(box, 5);
List<Body>ropeList = PathManager.EvenlyDistributeShapesAlongPath(Game1.world, ropePath, shape, BodyType.Dynamic, (int)(length/sectionLength));
List<Body>ropeList = PathManager.EvenlyDistributeShapesAlongPath(Game1.World, ropePath, shape, BodyType.Dynamic, (int)(length/sectionLength));
ropeBodies = new PhysicsBody[ropeList.Count()];
for (int i = 0; i<ropeBodies.Length; i++)
@@ -104,14 +104,14 @@ namespace Subsurface.Items.Components
ropeBodies[i] = new PhysicsBody(ropeList[i]);
}
List<RevoluteJoint> joints = PathManager.AttachBodiesWithRevoluteJoint(Game1.world, ropeList,
List<RevoluteJoint> joints = PathManager.AttachBodiesWithRevoluteJoint(Game1.World, ropeList,
new Vector2(-sectionLength/2, 0.0f), new Vector2(sectionLength/2, 0.0f), false, false);
ropeJoints = new RevoluteJoint[joints.Count+1];
//ropeJoints[0] = JointFactory.CreateRevoluteJoint(Game1.world, item.body, ropeList[0], new Vector2(0f, -0.0f));
for (int i = 0; i < joints.Count; i++)
{
var distanceJoint = JointFactory.CreateDistanceJoint(Game1.world, ropeList[i], ropeList[i + 1]);
var distanceJoint = JointFactory.CreateDistanceJoint(Game1.World, ropeList[i], ropeList[i + 1]);
distanceJoint.Length = sectionLength;
distanceJoint.DampingRatio = 1.0f;
@@ -299,8 +299,8 @@ namespace Subsurface.Items.Components
ropeBodies[ropeBodies.Length - 1].SetTransform(projectile.body.Position, projectile.body.Rotation);
//attach projectile to the last section of the rope
if (ropeJoints[ropeJoints.Length-1] != null) Game1.world.RemoveJoint(ropeJoints[ropeJoints.Length-1]);
ropeJoints[ropeJoints.Length - 1] = JointFactory.CreateRevoluteJoint(Game1.world,
if (ropeJoints[ropeJoints.Length-1] != null) Game1.World.RemoveJoint(ropeJoints[ropeJoints.Length-1]);
ropeJoints[ropeJoints.Length - 1] = JointFactory.CreateRevoluteJoint(Game1.World,
projectile.body.FarseerBody, ropeBodies[ropeBodies.Length - 1].FarseerBody,
projectileAnchor, new Vector2(sectionLength / 2, 0.0f));
@@ -315,7 +315,7 @@ namespace Subsurface.Items.Components
body.SetTransform(TransformedBarrelPos, rotation);
//Vector2 axis = new Vector2((float)Math.Cos(rotation), (float)Math.Sin(rotation));
if (gunJoint != null) Game1.world.RemoveJoint(gunJoint);
if (gunJoint != null) Game1.World.RemoveJoint(gunJoint);
gunJoint = new DistanceJoint(item.body.FarseerBody, body, BarrelPos,
new Vector2(sectionLength / 2, 0.0f));
@@ -328,7 +328,7 @@ namespace Subsurface.Items.Components
//gunJoint.LimitEnabled = true;
//gunJoint.ReferenceAngle = 0.0f;
Game1.world.AddJoint(gunJoint);
Game1.World.AddJoint(gunJoint);
}
}
@@ -55,7 +55,7 @@ namespace Subsurface.Items.Components
public override void ReceiveSignal(string signal, Connection connection, Item sender, float power=0.0f)
{
switch (connection.name)
switch (connection.Name)
{
case "signal_in1":
if (signal == "0") return;
@@ -16,13 +16,13 @@ namespace Subsurface.Items.Components
//how many wires can be linked to a single connector
private const int MaxLinked = 5;
public readonly string name;
public readonly string Name;
public Wire[] wires;
public Wire[] Wires;
private Item item;
public readonly bool isOutput;
public readonly bool IsOutput;
private static Item draggingConnected;
@@ -35,8 +35,8 @@ namespace Subsurface.Items.Components
List<Connection> recipients = new List<Connection>();
for (int i = 0; i<MaxLinked; i++)
{
if (wires[i] == null) continue;
Connection recipient = wires[i].OtherConnection(this);
if (Wires[i] == null) continue;
Connection recipient = Wires[i].OtherConnection(this);
if (recipient != null) recipients.Add(recipient);
}
return recipients;
@@ -62,10 +62,10 @@ namespace Subsurface.Items.Components
this.item = item;
//recipient = new Connection[MaxLinked];
wires = new Wire[MaxLinked];
Wires = new Wire[MaxLinked];
isOutput = (element.Name.ToString() == "output");
name = ToolBox.GetAttributeString(element, "name", (isOutput) ? "output" : "input");
IsOutput = (element.Name.ToString() == "output");
Name = ToolBox.GetAttributeString(element, "name", (IsOutput) ? "output" : "input");
wireId = new int[MaxLinked];
@@ -88,7 +88,7 @@ namespace Subsurface.Items.Components
{
for (int i = 0; i < MaxLinked; i++)
{
if (wires[i]==null) return i;
if (Wires[i]==null) return i;
}
return -1;
}
@@ -107,8 +107,8 @@ namespace Subsurface.Items.Components
{
for (int i = 0; i < MaxLinked; i++)
{
if (wires[i] == null && wireItem == null) return i;
if (wires[i] != null && wires[i].Item == wireItem) return i;
if (Wires[i] == null && wireItem == null) return i;
if (Wires[i] != null && Wires[i].Item == wireItem) return i;
}
return -1;
}
@@ -117,7 +117,7 @@ namespace Subsurface.Items.Components
{
//linked[index] = connectedItem;
//recipient[index] = otherConnection;
wires[index] = wire;
Wires[index] = wire;
}
//public bool AddLink(Item connectedItem, Connection otherConnection)
@@ -139,9 +139,9 @@ namespace Subsurface.Items.Components
{
for (int i = 0; i<MaxLinked; i++)
{
if (wires[i]==null) continue;
if (Wires[i]==null) continue;
Connection recipient = wires[i].OtherConnection(this);
Connection recipient = Wires[i].OtherConnection(this);
if (recipient == null) continue;
foreach (ItemComponent ic in recipient.item.components)
@@ -155,10 +155,10 @@ namespace Subsurface.Items.Components
{
for (int i = 0; i<MaxLinked; i++)
{
if (wires[i] == null) continue;
if (Wires[i] == null) continue;
wires[i].RemoveConnection(this);
wires[i] = null;
Wires[i].RemoveConnection(this);
Wires[i] = null;
}
}
@@ -204,12 +204,12 @@ namespace Subsurface.Items.Components
int linkIndex = c.FindWireIndex(draggingConnected);
if (linkIndex>-1)
{
Inventory.draggingItem = c.wires[linkIndex].Item;
Inventory.draggingItem = c.Wires[linkIndex].Item;
}
}
//outputs are drawn at the right side of the panel, inputs at the left
if (c.isOutput)
if (c.IsOutput)
{
c.Draw(spriteBatch, panel.Item, rightPos,
new Vector2(rightPos.X + 20, rightPos.Y),
@@ -235,7 +235,7 @@ namespace Subsurface.Items.Components
//and the wire hasn't been connected yet, draw it on the panel
if (equippedWire!=null)
{
if (panel.connections.Find(c => c.wires.Contains(equippedWire)) == null)
if (panel.connections.Find(c => c.Wires.Contains(equippedWire)) == null)
{
DrawWire(spriteBatch, equippedWire.Item, equippedWire.Item,
new Vector2(x + width / 2, y + height - 100),
@@ -274,19 +274,19 @@ namespace Subsurface.Items.Components
private void Draw(SpriteBatch spriteBatch, Item item, Vector2 position, Vector2 labelPos, Vector2 wirePosition, bool mouseIn, bool wireEquipped)
{
spriteBatch.DrawString(GUI.font, name, new Vector2(labelPos.X, labelPos.Y-10), Color.White);
spriteBatch.DrawString(GUI.font, Name, new Vector2(labelPos.X, labelPos.Y-10), Color.White);
GUI.DrawRectangle(spriteBatch, new Rectangle((int)position.X-10, (int)position.Y-10, 20, 20), Color.White);
for (int i = 0; i<MaxLinked; i++)
{
if (wires[i]==null) continue;
if (Wires[i]==null) continue;
Connection recipient = wires[i].OtherConnection(this);
Connection recipient = Wires[i].OtherConnection(this);
DrawWire(spriteBatch, wires[i].Item, (recipient == null) ? wires[i].Item : recipient.item, position, wirePosition, mouseIn, wireEquipped);
wirePosition.X += (isOutput) ? -20 : 20;
DrawWire(spriteBatch, Wires[i].Item, (recipient == null) ? Wires[i].Item : recipient.item, position, wirePosition, mouseIn, wireEquipped);
wirePosition.X += (IsOutput) ? -20 : 20;
}
//dragging a wire and released the mouse -> see if the wire can be connected to this connection
@@ -301,9 +301,9 @@ namespace Subsurface.Items.Components
Wire wireComponent = draggingConnected.GetComponent<Wire>();
if (index>-1 && wireComponent!=null && !wires.Contains(wireComponent))
if (index>-1 && wireComponent!=null && !Wires.Contains(wireComponent))
{
wires[index] = wireComponent;
Wires[index] = wireComponent;
wireComponent.Connect(this);
}
}
@@ -313,11 +313,11 @@ namespace Subsurface.Items.Components
int index = FindWireIndex(draggingConnected);
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] = null;
Wires[index].RemoveConnection(this);
Wires[index].Item.SetTransform(item.SimPosition, 0.0f);
Wires[index].Item.Drop();
Wires[index].Item.body.Enabled = true;
Wires[index] = null;
}
}
}
@@ -396,9 +396,9 @@ namespace Subsurface.Items.Components
public void Save(XElement parentElement)
{
XElement newElement = new XElement(isOutput ? "output" : "input", new XAttribute("name", name));
XElement newElement = new XElement(IsOutput ? "output" : "input", new XAttribute("name", Name));
Array.Sort(wires, delegate(Wire wire1, Wire wire2)
Array.Sort(Wires, delegate(Wire wire1, Wire wire2)
{
if (wire1 == null) return 1;
if (wire2 == null) return -1;
@@ -407,13 +407,13 @@ namespace Subsurface.Items.Components
for (int i = 0; i < MaxLinked; i++ )
{
if (wires[i] == null) continue;
if (Wires[i] == null) continue;
//Connection recipient = wires[i].OtherConnection(this);
//int connectionIndex = recipient.item.Connections.FindIndex(x => x == recipient);
newElement.Add(new XElement("link",
new XAttribute("w", wires[i].Item.ID.ToString())));
new XAttribute("w", Wires[i].Item.ID.ToString())));
}
parentElement.Add(newElement);
@@ -432,12 +432,12 @@ namespace Subsurface.Items.Components
Item wireItem = MapEntity.FindEntityByID(wireId[i]) as Item;
if (wireItem == null) continue;
wires[i] = wireItem.GetComponent<Wire>();
Wires[i] = wireItem.GetComponent<Wire>();
if (wires[i]!=null)
if (Wires[i]!=null)
{
wires[i].Item.body.Enabled = false;
wires[i].Connect(this, false);
Wires[i].Item.body.Enabled = false;
Wires[i].Connect(this, false);
}
}
@@ -107,10 +107,10 @@ namespace Subsurface.Items.Components
{
foreach (Connection c in connections)
{
int wireCount = c.wires.Length;
int wireCount = c.Wires.Length;
for (int i = 0 ; i < wireCount; i++)
{
message.Write(c.wires[i]==null ? -1 : c.wires[i].Item.ID);
message.Write(c.Wires[i]==null ? -1 : c.Wires[i].Item.ID);
}
}
}
@@ -120,7 +120,7 @@ namespace Subsurface.Items.Components
System.Diagnostics.Debug.WriteLine("connectionpanel update");
foreach (Connection c in connections)
{
int wireCount = c.wires.Length;
int wireCount = c.Wires.Length;
c.ClearConnections();
for (int i = 0; i < wireCount; i++)
@@ -134,7 +134,7 @@ namespace Subsurface.Items.Components
Wire wireComponent = wireItem.GetComponent<Wire>();
if (wireComponent == null) continue;
c.wires[i] = wireComponent;
c.Wires[i] = wireComponent;
wireComponent.Connect(c, false);
}
}
@@ -40,7 +40,7 @@ namespace Subsurface.Items.Components
public override void ReceiveSignal(string signal, Connection connection, Item sender, float power=0.0f)
{
switch (connection.name)
switch (connection.Name)
{
case "toggle":
isActive = !isActive;
@@ -11,7 +11,7 @@ namespace Subsurface.Items.Components
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");
}
@@ -30,7 +30,7 @@ namespace Subsurface.Items.Components
public override void ReceiveSignal(string signal, Connection connection, Item sender, float power=0.0f)
{
switch (connection.name)
switch (connection.Name)
{
case "signal_in":
if (string.IsNullOrWhiteSpace(expression)) return;
+3 -3
View File
@@ -123,15 +123,15 @@ namespace Subsurface.Items.Components
Vector2 position = item.Position;
position.X = MathUtils.Round(item.Position.X, nodeDistance);
if (item.currentHull == null)
if (item.CurrentHull == null)
{
position.Y = MathUtils.Round(item.Position.Y, nodeDistance);
}
else
{
position.Y -= item.currentHull.Rect.Y - item.currentHull.Rect.Height;
position.Y -= item.CurrentHull.Rect.Y - item.CurrentHull.Rect.Height;
position.Y = Math.Max(MathUtils.Round(position.Y, nodeDistance), heightFromFloor);
position.Y += item.currentHull.Rect.Y - item.currentHull.Rect.Height;
position.Y += item.CurrentHull.Rect.Y - item.CurrentHull.Rect.Height;
}
newNodePos = position;
+1 -1
View File
@@ -137,7 +137,7 @@ namespace Subsurface.Items.Components
if (character == Character.Controlled && cam!=null)
{
Lights.LightManager.viewPos = centerPos;
Lights.LightManager.ViewPos = centerPos;
cam.TargetPos = new Vector2(item.Rect.X + barrelPos.X, item.Rect.Y - barrelPos.Y);
}
}
+2 -2
View File
@@ -55,7 +55,7 @@ namespace Subsurface.Items.Components
picker = character;
for (int i = 0; i < sprite.Length; i++ )
{
Limb equipLimb = character.animController.GetLimb(limbType[i]);
Limb equipLimb = character.AnimController.GetLimb(limbType[i]);
if (equipLimb == null) continue;
//something is already on the limb -> unequip it
@@ -91,7 +91,7 @@ namespace Subsurface.Items.Components
if (picker == null) return;
for (int i = 0; i < sprite.Length; i++)
{
Limb equipLimb = character.animController.GetLimb(limbType[i]);
Limb equipLimb = character.AnimController.GetLimb(limbType[i]);
if (equipLimb == null) continue;
if (equipLimb.WearingItem != item) continue;