diff --git a/Launcher/Form1.cs b/Launcher/Form1.cs index d80ed81b5..9a92d6ccc 100644 --- a/Launcher/Form1.cs +++ b/Launcher/Form1.cs @@ -17,7 +17,6 @@ namespace Launcher { public partial class LauncherMain : Form { - public static string ContentPackageFolder = "Data/ContentPackages/"; private const string configPath = "config.xml"; private Subsurface.GameSettings settings; @@ -42,7 +41,7 @@ namespace Launcher { InitializeComponent(); - ContentPackage.LoadAll(LauncherMain.ContentPackageFolder); + ContentPackage.LoadAll(ContentPackage.Folder); contentPackageBox.DataSource = ContentPackage.list; supportedModes = new List(); diff --git a/Launcher/PackageManager.Designer.cs b/Launcher/PackageManager.Designer.cs index 9cfc78428..7584ed37e 100644 --- a/Launcher/PackageManager.Designer.cs +++ b/Launcher/PackageManager.Designer.cs @@ -102,6 +102,7 @@ this.itemList.Name = "itemList"; this.itemList.Size = new System.Drawing.Size(255, 134); this.itemList.TabIndex = 8; + this.itemList.PreviewKeyDown += new System.Windows.Forms.PreviewKeyDownEventHandler(this.fileList_KeyPress); // // itemButton // @@ -161,6 +162,7 @@ this.structureList.Name = "structureList"; this.structureList.Size = new System.Drawing.Size(255, 121); this.structureList.TabIndex = 8; + this.structureList.PreviewKeyDown += new System.Windows.Forms.PreviewKeyDownEventHandler(this.fileList_KeyPress); // // structureButton // @@ -189,6 +191,7 @@ this.jobList.Name = "jobList"; this.jobList.Size = new System.Drawing.Size(255, 134); this.jobList.TabIndex = 11; + this.jobList.PreviewKeyDown += new System.Windows.Forms.PreviewKeyDownEventHandler(this.fileList_KeyPress); // // label4 // diff --git a/Launcher/PackageManager.cs b/Launcher/PackageManager.cs index b1270721f..420b1fdd6 100644 --- a/Launcher/PackageManager.cs +++ b/Launcher/PackageManager.cs @@ -142,7 +142,7 @@ namespace Launcher OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "XML files (*.xml)|*.xml;*.XML"; - //ofd.RestoreDirectory? + ofd.RestoreDirectory = true; if (ofd.ShowDialog() == DialogResult.OK) { @@ -253,7 +253,7 @@ namespace Launcher private void okButton_Click(object sender, EventArgs e) { - if (selectedPackage!=null) selectedPackage.Save(LauncherMain.ContentPackageFolder); + if (selectedPackage!=null) selectedPackage.Save(ContentPackage.Folder); this.Close(); } diff --git a/Subsurface/Content/Items/Electricity/regex.png b/Subsurface/Content/Items/Electricity/regex.png new file mode 100644 index 000000000..52a4c0295 Binary files /dev/null and b/Subsurface/Content/Items/Electricity/regex.png differ diff --git a/Subsurface/Content/Items/Electricity/signalitems.xml b/Subsurface/Content/Items/Electricity/signalitems.xml index 7bcb2e020..c42fd6b19 100644 --- a/Subsurface/Content/Items/Electricity/signalitems.xml +++ b/Subsurface/Content/Items/Electricity/signalitems.xml @@ -185,7 +185,7 @@ linkable="true" price="10"> - + @@ -203,5 +203,30 @@ + + + + + + + + + + + + + + + + + + + diff --git a/Subsurface/Content/Items/Electricity/wifi.png b/Subsurface/Content/Items/Electricity/wifi.png new file mode 100644 index 000000000..bb63ff272 Binary files /dev/null and b/Subsurface/Content/Items/Electricity/wifi.png differ diff --git a/Subsurface/Content/Items/Ladder/item.xml b/Subsurface/Content/Items/Ladder/ladder.xml similarity index 100% rename from Subsurface/Content/Items/Ladder/item.xml rename to Subsurface/Content/Items/Ladder/ladder.xml diff --git a/Subsurface/Content/Items/Reactor/reactor.xml b/Subsurface/Content/Items/Reactor/reactor.xml index 758928870..306b9b1f0 100644 --- a/Subsurface/Content/Items/Reactor/reactor.xml +++ b/Subsurface/Content/Items/Reactor/reactor.xml @@ -34,6 +34,8 @@ + + diff --git a/Subsurface/Content/Items/blank.png b/Subsurface/Content/Items/blank.png new file mode 100644 index 000000000..9a1af9801 Binary files /dev/null and b/Subsurface/Content/Items/blank.png differ diff --git a/Subsurface/Content/Items/itemlabel.xml b/Subsurface/Content/Items/itemlabel.xml new file mode 100644 index 000000000..56e4fcc9f --- /dev/null +++ b/Subsurface/Content/Items/itemlabel.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + diff --git a/Subsurface/Source/Camera.cs b/Subsurface/Source/Camera.cs index 978c2d385..b06f26bdd 100644 --- a/Subsurface/Source/Camera.cs +++ b/Subsurface/Source/Camera.cs @@ -18,12 +18,13 @@ namespace Subsurface private Vector2 position; private float rotation; + private Vector2 prevPosition; + private float prevZoom; + public float Shake; private Vector2 shakePosition; private Vector2 shakeTargetPosition; - - - + //the area of the world inside the camera view private Rectangle worldView; @@ -130,9 +131,9 @@ namespace Subsurface private void UpdateTransform() { - Vector2 interpolatedPosition = position;//Physics.Interpolate(prevPosition,position); + Vector2 interpolatedPosition = Physics.Interpolate(prevPosition, position); - float interpolatedZoom = zoom;// Physics.Interpolate(prevZoom, zoom); + float interpolatedZoom = Physics.Interpolate(prevZoom, zoom); worldView.X = (int)(interpolatedPosition.X - worldView.Width / 2.0); worldView.Y = (int)(interpolatedPosition.Y + worldView.Height / 2.0); @@ -154,13 +155,19 @@ namespace Subsurface { float moveSpeed = 20.0f/zoom; + prevPosition = position; + prevZoom = zoom; + Vector2 moveCam = Vector2.Zero; if (targetPos == Vector2.Zero) { - if (Keyboard.GetState().IsKeyDown(Keys.A)) moveCam.X -= moveSpeed; - if (Keyboard.GetState().IsKeyDown(Keys.D)) moveCam.X += moveSpeed; - if (Keyboard.GetState().IsKeyDown(Keys.S)) moveCam.Y -= moveSpeed; - if (Keyboard.GetState().IsKeyDown(Keys.W)) moveCam.Y += moveSpeed; + + if (PlayerInput.KeyDown(Keys.A)) moveCam.X -= moveSpeed; + if (PlayerInput.KeyDown(Keys.D)) moveCam.X += moveSpeed; + if (PlayerInput.KeyDown(Keys.S)) moveCam.Y -= moveSpeed; + if (PlayerInput.KeyDown(Keys.W)) moveCam.Y += moveSpeed; + + moveCam = moveCam * deltaTime * 60.0f; Zoom = MathHelper.Clamp(Zoom + PlayerInput.ScrollWheelSpeed / 1000.0f, 0.1f, 2.0f); } @@ -179,15 +186,26 @@ namespace Subsurface float newZoom = Math.Min(DefaultZoom - Math.Min(offset.Length() / resolution.Y, 1.0f),1.0f); Zoom += (newZoom - zoom) / ZoomSmoothness; - - moveCam = (targetPos + offset - position) / MoveSmoothness; + + Vector2 diff = (targetPos + offset) - position; + + if (diff == Vector2.Zero) + { + moveCam = Vector2.Zero; + } + else + { + float dist = diff == Vector2.Zero ? 0.0f : diff.Length(); + + moveCam = Vector2.Normalize(diff) * Math.Min(dist, (dist * deltaTime * 60.0f) / MoveSmoothness); + } } shakeTargetPosition = Rand.Vector(Shake); shakePosition = Vector2.Lerp(shakePosition, shakeTargetPosition, 0.5f); Shake = MathHelper.Lerp(Shake, 0.0f, 0.03f); - Translate((moveCam+shakePosition)*deltaTime*60.0f); + Translate(moveCam+shakePosition); } public Vector2 Position diff --git a/Subsurface/Source/Characters/Character.cs b/Subsurface/Source/Characters/Character.cs index 0760b87c1..00093844e 100644 --- a/Subsurface/Source/Characters/Character.cs +++ b/Subsurface/Source/Characters/Character.cs @@ -36,7 +36,7 @@ namespace Subsurface private CharacterInventory inventory; - public double LastNetworkUpdate; + public float LastNetworkUpdate; public int LargeUpdateTimer; @@ -1037,7 +1037,7 @@ namespace Subsurface message.Write(secondaryKeyDown.Dequeue); //} - message.Write(NetTime.Now); + message.Write((float)NetTime.Now); // Write byte = move direction message.WriteRangedSingle(MathHelper.Clamp(AnimController.TargetMovement.X, -10.0f, 10.0f), -10.0f, 10.0f, 8); @@ -1132,7 +1132,7 @@ namespace Subsurface bool actionKeyState = false; bool secondaryKeyState = false; - double sendingTime = 0.0f; + float sendingTime = 0.0f; Vector2 targetMovement = Vector2.Zero; bool targetDir = false; Vector2 cursorPos = Vector2.Zero; @@ -1142,7 +1142,7 @@ namespace Subsurface actionKeyState = message.ReadBoolean(); secondaryKeyState = message.ReadBoolean(); - sendingTime = message.ReadDouble(); + sendingTime = message.ReadFloat(); targetMovement = new Vector2(message.ReadRangedSingle(-10.0f, 10.0f, 8), message.ReadRangedSingle(-10.0f, 10.0f, 8)); targetMovement.X = MathUtils.Round(targetMovement.X, 0.1f); diff --git a/Subsurface/Source/ContentPackage.cs b/Subsurface/Source/ContentPackage.cs index 16f2dd94b..9a31a1bf3 100644 --- a/Subsurface/Source/ContentPackage.cs +++ b/Subsurface/Source/ContentPackage.cs @@ -15,6 +15,9 @@ namespace Subsurface public class ContentPackage { + + public static string Folder = "Data/ContentPackages/"; + public static List list = new List(); @@ -80,6 +83,7 @@ namespace Subsurface { ContentPackage newPackage = new ContentPackage(); newPackage.name = name; + newPackage.Path = Folder + name; list.Add(newPackage); return newPackage; diff --git a/Subsurface/Source/DebugConsole.cs b/Subsurface/Source/DebugConsole.cs index bab270824..edf99ab91 100644 --- a/Subsurface/Source/DebugConsole.cs +++ b/Subsurface/Source/DebugConsole.cs @@ -136,11 +136,13 @@ namespace Subsurface public static void ExecuteCommand(string command, Game1 game) { +#if !DEBUG if (Game1.Client!=null) { ThrowError("Console commands are disabled in multiplayer mode"); return; } +#endif if (command == "") return; string[] commands = command.Split(' '); diff --git a/Subsurface/Source/GUI/GUI.cs b/Subsurface/Source/GUI/GUI.cs index c0a0bfd7e..70b667c2d 100644 --- a/Subsurface/Source/GUI/GUI.cs +++ b/Subsurface/Source/GUI/GUI.cs @@ -301,8 +301,16 @@ namespace Subsurface spriteBatch.DrawString(Font, "Physics: " + Game1.World.UpdateTime + " - bodies: " + Game1.World.BodyList.Count - + "Camera pos: " + Game1.GameScreen.Cam.Position, + + " Camera pos: " + Game1.GameScreen.Cam.Position, new Vector2(10, 30), Color.White); + + if (Submarine.Loaded!=null) + { + spriteBatch.DrawString(Font, + "Sub pos: " + Submarine.Loaded.Position, + new Vector2(10, 50), Color.White); + } + } diff --git a/Subsurface/Source/GUI/GUIMessageBox.cs b/Subsurface/Source/GUI/GUIMessageBox.cs index f5cfccb00..c56cda83f 100644 --- a/Subsurface/Source/GUI/GUIMessageBox.cs +++ b/Subsurface/Source/GUI/GUIMessageBox.cs @@ -15,6 +15,12 @@ namespace Subsurface //GUIFrame frame; public GUIButton[] Buttons; + public string Text + { + get { return (children[1] as GUITextBlock).Text; } + set { (children[1] as GUITextBlock).Text = value; } + } + public GUIMessageBox(string header, string text) : this(header, text, new string[] {"OK"}) { diff --git a/Subsurface/Source/GUI/GUITextBlock.cs b/Subsurface/Source/GUI/GUITextBlock.cs index 3edce2fd4..8842689c3 100644 --- a/Subsurface/Source/GUI/GUITextBlock.cs +++ b/Subsurface/Source/GUI/GUITextBlock.cs @@ -120,11 +120,7 @@ namespace Subsurface if (parent != null) parent.AddChild(this); - //if (wrap) - //{ - this.Wrap = wrap; - // this.text = ToolBox.WrapText(this.text, rect.Width); - //} + this.Wrap = wrap; SetTextPos(); } @@ -138,7 +134,7 @@ namespace Subsurface if (Wrap && rect.Width>0) { //text = text.Replace("\n"," "); - text = ToolBox.WrapText(text, rect.Width, Font); + text = ToolBox.WrapText(text, rect.Width - padding.X - padding.Z, Font); Vector2 newSize = MeasureText(text); diff --git a/Subsurface/Source/GUI/GUITextBox.cs b/Subsurface/Source/GUI/GUITextBox.cs index 74a4ca8d3..4401d2cd0 100644 --- a/Subsurface/Source/GUI/GUITextBox.cs +++ b/Subsurface/Source/GUI/GUITextBox.cs @@ -146,6 +146,7 @@ namespace Subsurface public void Deselect() { + Selected = false; if (keyboardDispatcher.Subscriber == this) keyboardDispatcher.Subscriber = null; } diff --git a/Subsurface/Source/Game1.cs b/Subsurface/Source/Game1.cs index d4bcb9aff..e6562c43a 100644 --- a/Subsurface/Source/Game1.cs +++ b/Subsurface/Source/Game1.cs @@ -265,7 +265,7 @@ namespace Subsurface DebugConsole.Update(this, (float)deltaTime); - if ((!DebugConsole.IsOpen && !GUI.PauseMenuOpen) || NetworkMember != null) Screen.Selected.Update(deltaTime); + if ((!DebugConsole.IsOpen && !GUI.PauseMenuOpen) || (NetworkMember != null && NetworkMember.GameStarted)) Screen.Selected.Update(deltaTime); GUI.Update((float)deltaTime); diff --git a/Subsurface/Source/GameSession/GameSession.cs b/Subsurface/Source/GameSession/GameSession.cs index 6ea2a2f8d..8ac5a91a9 100644 --- a/Subsurface/Source/GameSession/GameSession.cs +++ b/Subsurface/Source/GameSession/GameSession.cs @@ -132,7 +132,7 @@ namespace Subsurface if (Game1.Server!=null) { - Game1.Server.EndGame(endMessage); + CoroutineManager.StartCoroutine(Game1.Server.EndGame(endMessage)); } else if (Game1.Client==null) diff --git a/Subsurface/Source/Items/Components/Door.cs b/Subsurface/Source/Items/Components/Door.cs index 3558efb76..1a7ee9cd7 100644 --- a/Subsurface/Source/Items/Components/Door.cs +++ b/Subsurface/Source/Items/Components/Door.cs @@ -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)), diff --git a/Subsurface/Source/Items/Components/Holdable/Holdable.cs b/Subsurface/Source/Items/Components/Holdable/Holdable.cs index fb285428d..33711de9e 100644 --- a/Subsurface/Source/Items/Components/Holdable/Holdable.cs +++ b/Subsurface/Source/Items/Components/Holdable/Holdable.cs @@ -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); diff --git a/Subsurface/Source/Items/Components/ItemLabel.cs b/Subsurface/Source/Items/Components/ItemLabel.cs new file mode 100644 index 000000000..0b9ff1323 --- /dev/null +++ b/Subsurface/Source/Items/Components/ItemLabel.cs @@ -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); + } + } +} \ No newline at end of file diff --git a/Subsurface/Source/Items/Components/Machines/Reactor.cs b/Subsurface/Source/Items/Components/Machines/Reactor.cs index b5bc0a300..960667c9c 100644 --- a/Subsurface/Source/Items/Components/Machines/Reactor.cs +++ b/Subsurface/Source/Items/Components/Machines/Reactor.cs @@ -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); diff --git a/Subsurface/Source/Items/Components/Signal/Connection.cs b/Subsurface/Source/Items/Components/Signal/Connection.cs index 86ddc2556..258af00b1 100644 --- a/Subsurface/Source/Items/Components/Signal/Connection.cs +++ b/Subsurface/Source/Items/Components/Signal/Connection.cs @@ -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; } } - } - + } } diff --git a/Subsurface/Source/Items/Components/Signal/RegExFindComponent.cs b/Subsurface/Source/Items/Components/Signal/RegExFindComponent.cs index 28ea8b161..917c45ac8 100644 --- a/Subsurface/Source/Items/Components/Signal/RegExFindComponent.cs +++ b/Subsurface/Source/Items/Components/Signal/RegExFindComponent.cs @@ -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": diff --git a/Subsurface/Source/Items/Components/Signal/WifiComponent.cs b/Subsurface/Source/Items/Components/Signal/WifiComponent.cs new file mode 100644 index 000000000..d1486eca7 --- /dev/null +++ b/Subsurface/Source/Items/Components/Signal/WifiComponent.cs @@ -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 list = new List(); + + 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()!=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); + } + } +} diff --git a/Subsurface/Source/Items/Item.cs b/Subsurface/Source/Items/Item.cs index cf030ec47..d8cbe19d6 100644 --- a/Subsurface/Source/Items/Item.cs +++ b/Subsurface/Source/Items/Item.cs @@ -551,15 +551,19 @@ namespace Subsurface Color color = (isSelected && editing) ? color = Color.Red : spriteColor; if (isHighlighted) color = Color.Orange; - if (body==null) + if (prefab.sprite!=null) { - prefab.sprite.DrawTiled(spriteBatch, new Vector2(rect.X, -rect.Y), new Vector2(rect.Width, rect.Height), color); - } - else if (body.Enabled) - { - body.Draw(spriteBatch, prefab.sprite, color); + if (body==null) + { + prefab.sprite.DrawTiled(spriteBatch, new Vector2(rect.X, -rect.Y), new Vector2(rect.Width, rect.Height), color); + } + else if (body.Enabled) + { + body.Draw(spriteBatch, prefab.sprite, color); + } } + foreach (ItemComponent component in components) component.Draw(spriteBatch, editing); if (!editing || (body!=null && !body.Enabled)) @@ -670,7 +674,13 @@ namespace Subsurface foreach (var objectProperty in editableProperties) { new GUITextBlock(new Rectangle(0, y, 100, 20), objectProperty.Name, Color.Transparent, Color.White, Alignment.Left, null, editingHUD); - GUITextBox propertyBox = new GUITextBox(new Rectangle(100, y, 200, 20), GUI.style, editingHUD); + + int height = 20; + var editable = objectProperty.Attributes.OfType().FirstOrDefault(); + if (editable != null) height = (int)(Math.Ceiling(editable.MaxLength / 20.0f) * 20.0f); + + GUITextBox propertyBox = new GUITextBox(new Rectangle(100, y, 200, height), GUI.style, editingHUD); + if (height>20) propertyBox.Wrap = true; object value = objectProperty.GetValue(); if (value != null) @@ -681,7 +691,7 @@ namespace Subsurface propertyBox.UserData = objectProperty; propertyBox.OnEnter = EnterProperty; propertyBox.OnTextChanged = PropertyChanged; - y = y + 30; + y = y + height+10; } return editingHUD; } @@ -938,8 +948,8 @@ namespace Subsurface if (objectProperty == null) return false; object prevValue = objectProperty.GetValue(); - - textBox.Selected = false; + + textBox.Deselect(); if (objectProperty.TrySetValue(text)) { diff --git a/Subsurface/Source/Items/ItemPrefab.cs b/Subsurface/Source/Items/ItemPrefab.cs index e13b087be..504bd9016 100644 --- a/Subsurface/Source/Items/ItemPrefab.cs +++ b/Subsurface/Source/Items/ItemPrefab.cs @@ -106,7 +106,7 @@ namespace Subsurface position = placePosition; } - sprite.DrawTiled(spriteBatch, new Vector2(position.X, -position.Y), placeSize, Color.White); + if (sprite != null) sprite.DrawTiled(spriteBatch, new Vector2(position.X, -position.Y), placeSize, Color.White); } if (PlayerInput.GetMouseState.RightButton == ButtonState.Pressed) selected = null; diff --git a/Subsurface/Source/Map/Submarine.cs b/Subsurface/Source/Map/Submarine.cs index e520bc943..3f02177da 100644 --- a/Subsurface/Source/Map/Submarine.cs +++ b/Subsurface/Source/Map/Submarine.cs @@ -50,7 +50,7 @@ namespace Subsurface private string name; - private double lastNetworkUpdate; + private float lastNetworkUpdate; //properties ---------------------------------------------------- @@ -564,7 +564,7 @@ namespace Subsurface public override void FillNetworkData(Networking.NetworkEventType type, NetOutgoingMessage message, object data) { - message.Write(NetTime.Now); + message.Write((float)NetTime.Now); message.Write(Position.X); message.Write(Position.Y); @@ -575,11 +575,11 @@ namespace Subsurface public override void ReadNetworkData(Networking.NetworkEventType type, NetIncomingMessage message) { - double sendingTime; + float sendingTime; Vector2 newTargetPosition, newSpeed; try { - sendingTime = message.ReadDouble(); + sendingTime = message.ReadFloat(); if (sendingTime <= lastNetworkUpdate) return; @@ -595,7 +595,7 @@ namespace Subsurface return; } - if (!speed.IsValid() || targetPosition.IsValid()) return; + if (!newSpeed.IsValid() || !newTargetPosition.IsValid()) return; //newTargetPosition = newTargetPosition + newSpeed * (float)(NetTime.Now - sendingTime); diff --git a/Subsurface/Source/Networking/GameClient.cs b/Subsurface/Source/Networking/GameClient.cs index b1f1d0936..0a13ddd5f 100644 --- a/Subsurface/Source/Networking/GameClient.cs +++ b/Subsurface/Source/Networking/GameClient.cs @@ -377,7 +377,7 @@ namespace Subsurface.Networking break; case (byte)PacketTypes.EndGame: string endMessage = inc.ReadString(); - EndGame(endMessage); + CoroutineManager.StartCoroutine(EndGame(endMessage)); break; case (byte)PacketTypes.PlayerJoined: @@ -429,19 +429,48 @@ namespace Subsurface.Networking } } - public void EndGame(string endMessage) + public IEnumerable EndGame(string endMessage) { + gameStarted = false; + + var messageBox = new GUIMessageBox("The round has ended", endMessage); + + Character.Controlled = null; + Game1.LightManager.LosEnabled = false; + + float endPreviewLength = 10.0f; + + DateTime endTime = DateTime.Now + new TimeSpan(0,0,0,0,(int)(1000.0f*endPreviewLength)); + float secondsLeft = endPreviewLength; + + do + { + secondsLeft = (float)(endTime - DateTime.Now).TotalSeconds; + + float camAngle = (float)((DateTime.Now - endTime).TotalSeconds / endPreviewLength) * MathHelper.TwoPi; + Vector2 offset = (new Vector2( + (float)Math.Cos(camAngle) * (Submarine.Borders.Width / 2.0f), + (float)Math.Sin(camAngle) * (Submarine.Borders.Height / 2.0f))); + + Game1.GameScreen.Cam.TargetPos = offset * 0.8f; + //Game1.GameScreen.Cam.MoveCamera((float)deltaTime); + + messageBox.Text = endMessage + "\nReturning to lobby in " + (int)secondsLeft + " s"; + yield return Status.Running; + } while (secondsLeft > 0.0f); + + messageBox.Text = endMessage; + Submarine.Unload(); Game1.NetLobbyScreen.Select(); if (Game1.GameSession!=null) Game1.GameSession.EndShift(""); - new GUIMessageBox("The round has ended", endMessage); - myCharacter = null; - gameStarted = false; + yield return Status.Success; + } public override void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch) diff --git a/Subsurface/Source/Networking/GameServer.cs b/Subsurface/Source/Networking/GameServer.cs index 1f4021e8f..6b6d0b572 100644 --- a/Subsurface/Source/Networking/GameServer.cs +++ b/Subsurface/Source/Networking/GameServer.cs @@ -149,13 +149,7 @@ namespace Subsurface.Networking yield return Status.Running; } - - yield return Status.Success; - - - - } private void MasterServerCallBack(IRestResponse response) @@ -617,9 +611,10 @@ namespace Subsurface.Networking return true; } - public void EndGame(string endMessage) + public IEnumerable EndGame(string endMessage) { + gameStarted = false; if (connectedClients.Count > 0) { @@ -639,13 +634,34 @@ namespace Subsurface.Networking } } + float endPreviewLength = 10.0f; + + DateTime endTime = DateTime.Now + new TimeSpan(0, 0, 0, 0, (int)(1000.0f * endPreviewLength)); + float secondsLeft = endPreviewLength; + + do + { + secondsLeft = (float)(endTime - DateTime.Now).TotalSeconds; + + float camAngle = (float)((DateTime.Now - endTime).TotalSeconds / endPreviewLength) * MathHelper.TwoPi; + Vector2 offset = (new Vector2( + (float)Math.Cos(camAngle) * (Submarine.Borders.Width / 2.0f), + (float)Math.Sin(camAngle) * (Submarine.Borders.Height / 2.0f))); + + Game1.GameScreen.Cam.TargetPos = offset * 0.8f; + //Game1.GameScreen.Cam.MoveCamera((float)deltaTime); + + yield return Status.Running; + } while (secondsLeft > 0.0f); + Submarine.Unload(); - - gameStarted = false; Game1.NetLobbyScreen.Select(); DebugConsole.ThrowError(endMessage); + + yield return Status.Success; + } private void DisconnectClient(NetConnection senderConnection) diff --git a/Subsurface/Source/Networking/NetworkMember.cs b/Subsurface/Source/Networking/NetworkMember.cs index e28c54583..7e7f4c7b6 100644 --- a/Subsurface/Source/Networking/NetworkMember.cs +++ b/Subsurface/Source/Networking/NetworkMember.cs @@ -64,6 +64,11 @@ namespace Subsurface.Networking } } + public bool GameStarted + { + get { return gameStarted; } + } + public GUIFrame InGameHUD { get { return inGameHUD; } diff --git a/Subsurface/Source/PlayerInput.cs b/Subsurface/Source/PlayerInput.cs index 75e879775..01a19573b 100644 --- a/Subsurface/Source/PlayerInput.cs +++ b/Subsurface/Source/PlayerInput.cs @@ -3,156 +3,156 @@ using Microsoft.Xna.Framework.Input; namespace Subsurface { - class Key - { - private bool state, stateQueue; - private bool canBeHeld; - - public Key(bool canBeHeld) - { - this.canBeHeld = canBeHeld; - } + class Key + { + private bool state, stateQueue; + private bool canBeHeld; + + public Key(bool canBeHeld) + { + this.canBeHeld = canBeHeld; + } - public bool State - { - get - { - return state; - } - set - { - //if (value == false) return; - state = value; - //if (value) stateQueue = value; - } - } + public bool State + { + get + { + return state; + } + set + { + //if (value == false) return; + state = value; + //if (value) stateQueue = value; + } + } - public void SetState(bool value) - { - state = value; - if (value) stateQueue = value; - } + public void SetState(bool value) + { + state = value; + if (value) stateQueue = value; + } - public bool Dequeue - { - get - { - bool value = stateQueue; - stateQueue = false; - return value; - } - //set - //{ - // stateQueue = value; - //} - } + public bool Dequeue + { + get + { + bool value = stateQueue; + stateQueue = false; + return value; + } + //set + //{ + // stateQueue = value; + //} + } - public void Reset() - { - if (!canBeHeld) state = false; - //stateQueue = false; - } - } + public void Reset() + { + if (!canBeHeld) state = false; + //stateQueue = false; + } + } - static class PlayerInput - { - static MouseState mouseState, oldMouseState; - static KeyboardState keyboardState, oldKeyboardState; + static class PlayerInput + { + static MouseState mouseState, oldMouseState; + static KeyboardState keyboardState, oldKeyboardState; - static double timeSinceClick; + static double timeSinceClick; - const double doubleClickDelay = 0.4; + const double doubleClickDelay = 0.4; - static bool doubleClicked; + static bool doubleClicked; - public static Keys selectKey = Keys.E; + public static Keys selectKey = Keys.E; - public static Vector2 MousePosition - { - get { return new Vector2(mouseState.Y, mouseState.X); } - } + public static Vector2 MousePosition + { + get { return new Vector2(mouseState.X, mouseState.Y); } + } - public static MouseState GetMouseState - { - get { return mouseState; } - } - public static MouseState GetOldMouseState - { - get { return oldMouseState; } - } + public static MouseState GetMouseState + { + get { return mouseState; } + } + public static MouseState GetOldMouseState + { + get { return oldMouseState; } + } - public static Vector2 MouseSpeed - { - get - { + public static Vector2 MouseSpeed + { + get + { return MousePosition - new Vector2(oldMouseState.X, oldMouseState.Y); - } - } + } + } - public static KeyboardState GetKeyboardState - { - get { return keyboardState; } - } + public static KeyboardState GetKeyboardState + { + get { return keyboardState; } + } - public static KeyboardState GetOldKeyboardState - { - get { return oldKeyboardState; } - } + public static KeyboardState GetOldKeyboardState + { + get { return oldKeyboardState; } + } - public static int ScrollWheelSpeed - { - get { return mouseState.ScrollWheelValue - oldMouseState.ScrollWheelValue; } - - } + public static int ScrollWheelSpeed + { + get { return mouseState.ScrollWheelValue - oldMouseState.ScrollWheelValue; } + + } - public static bool LeftButtonDown() - { - return mouseState.LeftButton == ButtonState.Pressed; - } + public static bool LeftButtonDown() + { + return mouseState.LeftButton == ButtonState.Pressed; + } - public static bool LeftButtonClicked() - { - return (oldMouseState.LeftButton == ButtonState.Pressed - && mouseState.LeftButton == ButtonState.Released); - } + public static bool LeftButtonClicked() + { + return (oldMouseState.LeftButton == ButtonState.Pressed + && mouseState.LeftButton == ButtonState.Released); + } - public static bool RightButtonClicked() - { - return (oldMouseState.RightButton == ButtonState.Pressed - && mouseState.RightButton == ButtonState.Released); - } + public static bool RightButtonClicked() + { + return (oldMouseState.RightButton == ButtonState.Pressed + && mouseState.RightButton == ButtonState.Released); + } - public static bool DoubleClicked() - { - return doubleClicked; - } + public static bool DoubleClicked() + { + return doubleClicked; + } - public static bool KeyHit(Keys button) - { - return (oldKeyboardState.IsKeyDown(button) && keyboardState.IsKeyUp(button)); - } + public static bool KeyHit(Keys button) + { + return (oldKeyboardState.IsKeyDown(button) && keyboardState.IsKeyUp(button)); + } - public static bool KeyDown(Keys button) - { - return (keyboardState.IsKeyDown(button)); - } + public static bool KeyDown(Keys button) + { + return (keyboardState.IsKeyDown(button)); + } - public static void Update(double deltaTime) - { - timeSinceClick += deltaTime; + public static void Update(double deltaTime) + { + timeSinceClick += deltaTime; - oldMouseState = mouseState; - mouseState = Mouse.GetState(); + oldMouseState = mouseState; + mouseState = Mouse.GetState(); - oldKeyboardState = keyboardState; - keyboardState = Keyboard.GetState(); + oldKeyboardState = keyboardState; + keyboardState = Keyboard.GetState(); - doubleClicked = false; - if (LeftButtonClicked()) - { - if (timeSinceClick < doubleClickDelay) doubleClicked = true; - timeSinceClick = 0.0; - } - } - } + doubleClicked = false; + if (LeftButtonClicked()) + { + if (timeSinceClick < doubleClickDelay) doubleClicked = true; + timeSinceClick = 0.0; + } + } + } } diff --git a/Subsurface/Source/Properties.cs b/Subsurface/Source/Properties.cs index c985ce848..e27bdf52a 100644 --- a/Subsurface/Source/Properties.cs +++ b/Subsurface/Source/Properties.cs @@ -11,6 +11,12 @@ namespace Subsurface [AttributeUsage(AttributeTargets.Property)] public class Editable : System.Attribute { + public int MaxLength; + + public Editable(int maxLength = 20) + { + MaxLength = maxLength; + } } [AttributeUsage(AttributeTargets.Property)] diff --git a/Subsurface/Source/Screens/EditMapScreen.cs b/Subsurface/Source/Screens/EditMapScreen.cs index 326d199ef..6bfc35afe 100644 --- a/Subsurface/Source/Screens/EditMapScreen.cs +++ b/Subsurface/Source/Screens/EditMapScreen.cs @@ -176,7 +176,7 @@ namespace Subsurface // CreateDummyCharacter(); //} - cam.MoveCamera((float)deltaTime); + if (GUIComponent.MouseOn==null) cam.MoveCamera((float)deltaTime); cam.Zoom = MathHelper.Clamp(cam.Zoom + PlayerInput.ScrollWheelSpeed/1000.0f,0.1f, 2.0f); if (characterMode) diff --git a/Subsurface/Source/Screens/GameScreen.cs b/Subsurface/Source/Screens/GameScreen.cs index 27af439f4..96a4d111a 100644 --- a/Subsurface/Source/Screens/GameScreen.cs +++ b/Subsurface/Source/Screens/GameScreen.cs @@ -75,11 +75,12 @@ namespace Subsurface StatusEffect.UpdateAll((float)deltaTime); - cam.MoveCamera((float)deltaTime); Physics.accumulator = Math.Min(Physics.accumulator, Physics.step * 4); while (Physics.accumulator >= Physics.step) { + cam.MoveCamera((float)Physics.step); + foreach (PhysicsBody pb in PhysicsBody.list) { pb.SetPrevTransform(pb.Position, pb.Rotation); diff --git a/Subsurface/Source/Screens/Screen.cs b/Subsurface/Source/Screens/Screen.cs index 36e95f6d3..e0a8268ab 100644 --- a/Subsurface/Source/Screens/Screen.cs +++ b/Subsurface/Source/Screens/Screen.cs @@ -5,7 +5,7 @@ namespace Subsurface class Screen { private static Screen selected; - + public static Screen Selected { get { return selected; } diff --git a/Subsurface/Source/Utils/MathUtils.cs b/Subsurface/Source/Utils/MathUtils.cs index e16b13542..10b736eee 100644 --- a/Subsurface/Source/Utils/MathUtils.cs +++ b/Subsurface/Source/Utils/MathUtils.cs @@ -29,16 +29,14 @@ namespace Subsurface public static bool IsValid(float value) { - return (!float.IsInfinity(value) && !float.IsInfinity(value)); + return (!float.IsInfinity(value) && !float.IsNaN(value)); } public static bool IsValid(Vector2 vector) { - return (!float.IsInfinity(vector.X) && !float.IsInfinity(vector.Y) && !float.IsNaN(vector.X) && !float.IsNaN(vector.Y)); + return (IsValid(vector.X) && IsValid(vector.Y)); } - - - + public static float CurveAngle(float from, float to, float step) { diff --git a/Subsurface/Source/Utils/ToolBox.cs b/Subsurface/Source/Utils/ToolBox.cs index f64c02bdd..b37a172bc 100644 --- a/Subsurface/Source/Utils/ToolBox.cs +++ b/Subsurface/Source/Utils/ToolBox.cs @@ -36,9 +36,9 @@ namespace Subsurface { font = contentManager.Load(file); } - catch + catch (Exception e) { - DebugConsole.ThrowError("Loading font ''"+file+"'' failed"); + DebugConsole.ThrowError("Loading font ''"+file+"'' failed", e); } return font; diff --git a/Subsurface/StyleCop.Cache b/Subsurface/StyleCop.Cache index c2264d137..456c5e6fd 100644 --- a/Subsurface/StyleCop.Cache +++ b/Subsurface/StyleCop.Cache @@ -6336,9 +6336,6 @@ - - DEBUG;TRACE;WINDOWS - 2014.04.01 10:18:24.000 @@ -6464,4 +6461,30 @@ + + DEBUG;TRACE;WINDOWS + + + + 2014.04.01 10:18:24.000 + 2015.07.02 21:22:42.115 + 2015.08.21 17:49:13.627 + 2014.04.01 10:18:24.000 + 2014.04.01 10:18:24.000 + -1945363787 + 2014.04.01 10:18:24.000 + 0 + 2014.04.01 10:18:24.000 + 0 + 2014.04.01 10:18:24.000 + 0 + 2014.04.01 10:18:24.000 + 0 + 2014.04.01 10:18:24.000 + 0 + 2014.04.01 10:18:24.000 + 0 + + + \ No newline at end of file diff --git a/Subsurface/Subsurface.csproj b/Subsurface/Subsurface.csproj index ff3e2615a..95a6a0383 100644 --- a/Subsurface/Subsurface.csproj +++ b/Subsurface/Subsurface.csproj @@ -76,7 +76,9 @@ + + @@ -301,6 +303,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest @@ -310,6 +315,12 @@ PreserveNewest + + PreserveNewest + + + PreserveNewest + Designer PreserveNewest @@ -320,6 +331,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest Designer @@ -557,7 +571,7 @@ PreserveNewest - + PreserveNewest diff --git a/Subsurface_Solution.v12.suo b/Subsurface_Solution.v12.suo index 24e07d133..3a2a29164 100644 Binary files a/Subsurface_Solution.v12.suo and b/Subsurface_Solution.v12.suo differ