diff --git a/Subsurface/Characters/Character.cs b/Subsurface/Characters/Character.cs index 9c810492a..c8c669313 100644 --- a/Subsurface/Characters/Character.cs +++ b/Subsurface/Characters/Character.cs @@ -38,7 +38,7 @@ namespace Subsurface public double LastNetworkUpdate; - public float LargeUpdateTimer; + public int LargeUpdateTimer; public readonly Dictionary Properties; public Dictionary ObjectProperties @@ -898,6 +898,19 @@ namespace Subsurface { if (isDead) return; + //if the game is run by a client, characters are only killed when the server says so + if (Game1.Client != null) + { + if (networkMessage) + { + new NetworkEvent(NetworkEventType.KillCharacter, ID, true); + } + else + { + return; + } + } + isDead = true; AnimController.movement = Vector2.Zero; AnimController.TargetMovement = Vector2.Zero; @@ -923,20 +936,6 @@ namespace Subsurface joint.MaxMotorTorque = 0.0f; } - - //if the game is run by a client, characters are only killed when the server says so - if (Game1.Client != null) - { - if (networkMessage) - { - new NetworkEvent(NetworkEventType.KillCharacter, ID, true); - } - else - { - return; - } - } - if (Game1.Server != null) { new NetworkEvent(NetworkEventType.KillCharacter, ID, false); @@ -999,6 +998,7 @@ namespace Subsurface } message.Write(AnimController.StunTimer); + message.Write((byte)health); LargeUpdateTimer = 5; } @@ -1021,18 +1021,23 @@ namespace Subsurface { if (type == NetworkEventType.PickItem) { - int itemId = message.ReadInt32(); + int itemId = -1; + + try + { + itemId = message.ReadInt32(); + } + catch + { + return; + } + Item item = FindEntityByID(itemId) as Item; if (item != null) { Debug.WriteLine("pickitem "+itemId ); item.Pick(this); } - else - { - } - - //DebugConsole.ThrowError("pickitem"); return; } @@ -1088,21 +1093,25 @@ namespace Subsurface { foreach (Limb limb in AnimController.limbs) { - Vector2 pos = Vector2.Zero; - pos.X = message.ReadFloat(); - pos.Y = message.ReadFloat(); + Vector2 pos = Vector2.Zero, vel = Vector2.Zero; + float rotation = 0.0f, angularVel = 0.0f; - Vector2 vel = Vector2.Zero; - vel.X = message.ReadFloat(); - vel.Y = message.ReadFloat(); + try + { + pos.X = message.ReadFloat(); + pos.Y = message.ReadFloat(); - float rotation = message.ReadFloat(); - float angularVel = message.ReadFloat(); + vel.X = message.ReadFloat(); + vel.Y = message.ReadFloat(); - //if (vel != Vector2.Zero && vel.Length() > 100.0f) { } + rotation = message.ReadFloat(); + angularVel = message.ReadFloat(); + } + catch + { + return; + } - //if (pos != Vector2.Zero && pos.Length() > 100.0f) { } - if (limb.body != null) { limb.body.TargetVelocity = vel; @@ -1113,15 +1122,31 @@ namespace Subsurface } - AnimController.StunTimer = message.ReadFloat(); + float newStunTimer = 0.0f, newHealth = 0.0f; + + try + { + newStunTimer = message.ReadFloat(); + newHealth = message.ReadByte(); + } + catch { return; } + + AnimController.StunTimer = newStunTimer; + Health = newHealth; LargeUpdateTimer = 1; } else { Vector2 pos = Vector2.Zero; - pos.X = message.ReadFloat(); - pos.Y = message.ReadFloat(); + try + { + pos.X = message.ReadFloat(); + pos.Y = message.ReadFloat(); + } + + catch { return; } + Limb torso = AnimController.GetLimb(LimbType.Torso); torso.body.TargetPosition = pos; diff --git a/Subsurface/Characters/Ragdoll.cs b/Subsurface/Characters/Ragdoll.cs index 6f764c0e7..5d1c09d1a 100644 --- a/Subsurface/Characters/Ragdoll.cs +++ b/Subsurface/Characters/Ragdoll.cs @@ -320,10 +320,11 @@ namespace Subsurface } avgVelocity = avgVelocity / limbs.Count(); - - + float impact = Vector2.Dot((f1.Body.LinearVelocity + avgVelocity) / 2.0f, -normal); + if (Game1.Server != null) impact = impact / 2.0f; + Limb l = (Limb)f1.Body.UserData; if (impact > 1.0f && l.HitSound != null && l.soundTimer <= 0.0f) l.HitSound.Play(Math.Min(impact / 5.0f, 1.0f), impact * 100.0f, l.body.FarseerBody); @@ -335,10 +336,8 @@ namespace Subsurface } } - public virtual void Draw(SpriteBatch spriteBatch) - { - + { foreach (Limb limb in limbs) { limb.Draw(spriteBatch); diff --git a/Subsurface/Content/Items/Engine/engine.xml b/Subsurface/Content/Items/Engine/engine.xml index 1cf0af13f..3ae2f1d81 100644 --- a/Subsurface/Content/Items/Engine/engine.xml +++ b/Subsurface/Content/Items/Engine/engine.xml @@ -31,7 +31,7 @@ - + @@ -40,6 +40,7 @@ + diff --git a/Subsurface/Content/Items/Pump/pump.png b/Subsurface/Content/Items/Pump/pump.png index 30a173465..8fe06b478 100644 Binary files a/Subsurface/Content/Items/Pump/pump.png and b/Subsurface/Content/Items/Pump/pump.png differ diff --git a/Subsurface/Content/Quests.xml b/Subsurface/Content/Quests.xml index a2aa744b7..dd9dfd2e5 100644 --- a/Subsurface/Content/Quests.xml +++ b/Subsurface/Content/Quests.xml @@ -5,7 +5,9 @@ description="Researchers of [location1] have picked up an infrasonic signal highly similar to those emitted by alien artifacts previously discovered on Europa. Investigate the signal and retrieve the potential artifact." commonness="10" reward="1000" - successmessage="You have successfully retrieved the artifact." + radarlabel="Infrasonic signal" + failuremessage="fail" + successmessage="The artifact has been succesfully retrived" itemname="Skyholder Artifact"> @@ -14,7 +16,9 @@ description="A particularly aggressive Moloch has been terrorizing vessels traveling between [location1] and [location2]. A reward of 1000 credits has been promised to those who kill the creature." commonness="10" reward="1000" - successmessage="You have successfully killed the Moloch." + radarlabel="Moloch" + failuremessage="fail" + successmessage="The Moloch has been killed." monsterfile="Content/Characters/Moloch/moloch.xml"> @@ -23,7 +27,9 @@ description="A particularly aggressive Tiger Thresher has been terrorizing vessels traveling between [location1] and [location2]. A reward of 800 credits has been promised to those who kill the creature." commonness="10" reward="800" - successmessage="You have successfully killed the Tiger Thresher." + radarlabel="Tiger Thresher" + failuremessage="fail" + successmessage="The Tiger Thresher has been killed." monsterfile="Content/Characters/TigerThresher/tigerthresher.xml"> @@ -32,6 +38,7 @@ description="Researchers of [location1] have picked up an infrasonic signal highly similar to those emitted by alien artifacts previously discovered on Europa. Investigate the signal and retrieve the potential artifact." commonness="5" reward="1000" + radarlabel="Infrasonic signal" failuremessage="It turns out the signal picked up by [location1] was emitted by a Moloch." successmessage="It turns out the signal was emitted by a Moloch. The researchers of [location1] have agreed to pay you the reward nevertheless for killing the Moloch." monsterfile="Content/Characters/Moloch/moloch.xml"> diff --git a/Subsurface/ContentPackage.cs b/Subsurface/ContentPackage.cs index 18054e039..1fddd191e 100644 --- a/Subsurface/ContentPackage.cs +++ b/Subsurface/ContentPackage.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Security.Cryptography; using System.Text; using System.Xml.Linq; @@ -120,17 +121,36 @@ namespace Subsurface { StringBuilder sb = new StringBuilder(); + List hashes = new List(); + + //foreach (ContentFile file in files) + //{ + // if (file.path.EndsWith(".xml", true, System.Globalization.CultureInfo.InvariantCulture)) + // { + // XDocument doc = ToolBox.TryLoadXml(file.path); + // sb.Append(doc.ToString()); + // } + //} + var md5 = MD5.Create(); foreach (ContentFile file in files) { - XDocument doc = ToolBox.TryLoadXml(file.path); - - sb.Append(doc.ToString()); + using (var stream = File.OpenRead(file.path)) + { + hashes.Add(md5.ComputeHash(stream)); + } } - string str = sb.ToString(); - byte[] bytes = new byte[str.Length * sizeof(char)]; - System.Buffer.BlockCopy(str.ToCharArray(), 0, bytes, 0, bytes.Length); - md5Hash = new Md5Hash(bytes); + + + //string str = sb.ToString(); + byte[] bytes = new byte[hashes.Count()*16]; + for (int i = 0; i < hashes.Count; i++ ) + { + hashes[i].CopyTo(bytes, i*16); + } + //System.Buffer.BlockCopy(str.ToCharArray(), 0, bytes, 0, bytes.Length); + + md5Hash = new Md5Hash(bytes); } public List GetFilesOfType(ContentType type) diff --git a/Subsurface/DebugConsole.cs b/Subsurface/DebugConsole.cs index 3a326162f..0844322dc 100644 --- a/Subsurface/DebugConsole.cs +++ b/Subsurface/DebugConsole.cs @@ -246,12 +246,12 @@ namespace Subsurface break; case "savemap": if (commands.Length < 2) break; - Submarine.SaveCurrent("Content/SavedMaps/" + commands[1]); + Submarine.SaveCurrent("Content/SavedMaps/" + string.Join(" ", commands.Skip(1))); NewMessage("map saved", Color.Green); break; case "loadmap": if (commands.Length < 2) break; - Submarine.Load("Content/SavedMaps/" + commands[1]); + Submarine.Load("Content/SavedMaps/" + string.Join(" ", commands.Skip(1))); break; case "savegame": SaveUtil.SaveGame(SaveUtil.SaveFolder+"save"); diff --git a/Subsurface/Events/Quests/MonsterQuest.cs b/Subsurface/Events/Quests/MonsterQuest.cs index 1a0b8ec85..37f049dc1 100644 --- a/Subsurface/Events/Quests/MonsterQuest.cs +++ b/Subsurface/Events/Quests/MonsterQuest.cs @@ -16,14 +16,6 @@ namespace Subsurface Character monster; - public override string RadarLabel - { - get - { - return monster.SpeciesName; - } - } - public override Vector2 RadarPosition { get @@ -35,7 +27,6 @@ namespace Subsurface public MonsterQuest(XElement element) : base(element) { - //monsterName = ToolBox.GetAttributeString(element, "monstername", ""); monsterFile = ToolBox.GetAttributeString(element, "monsterfile", ""); } @@ -48,7 +39,11 @@ namespace Subsurface public override void End() { - if (!monster.IsDead) return; + if (!monster.IsDead) + { + new GUIMessageBox("Quest failed", failureMessage); + return; + } GiveReward(); diff --git a/Subsurface/Events/Quests/Quest.cs b/Subsurface/Events/Quests/Quest.cs index f7789789d..2296522b8 100644 --- a/Subsurface/Events/Quests/Quest.cs +++ b/Subsurface/Events/Quests/Quest.cs @@ -20,8 +20,10 @@ namespace Subsurface protected bool completed; - private string successMessage; - private string failureMessage; + protected string successMessage; + protected string failureMessage; + + protected string radarLabel; private int reward; @@ -47,7 +49,7 @@ namespace Subsurface public virtual string RadarLabel { - get { return ""; } + get { return radarLabel; } } public virtual Vector2 RadarPosition @@ -65,6 +67,8 @@ namespace Subsurface successMessage = ToolBox.GetAttributeString(element, "successmessage", ""); failureMessage = ToolBox.GetAttributeString(element, "failuremessage", ""); + + radarLabel = ToolBox.GetAttributeString(element, "radarlabel", ""); } public static Quest LoadRandom(Location[] locations, Random rand) diff --git a/Subsurface/Events/Quests/SalvageQuest.cs b/Subsurface/Events/Quests/SalvageQuest.cs index ac8afc1ec..7b4456dd6 100644 --- a/Subsurface/Events/Quests/SalvageQuest.cs +++ b/Subsurface/Events/Quests/SalvageQuest.cs @@ -13,14 +13,6 @@ namespace Subsurface Item item; - public override string RadarLabel - { - get - { - return "Infrasonic signal"; - } - } - public override Vector2 RadarPosition { get @@ -52,8 +44,11 @@ namespace Subsurface public override void End() { - if (item.CurrentHull == null) return; - + if (item.CurrentHull == null) + { + new GUIMessageBox("Quest failed", failureMessage); + return; + } item.Remove(); GiveReward(); diff --git a/Subsurface/GUI/GUI.cs b/Subsurface/GUI/GUI.cs index 386c642d3..5adb10e2f 100644 --- a/Subsurface/GUI/GUI.cs +++ b/Subsurface/GUI/GUI.cs @@ -297,6 +297,9 @@ namespace Subsurface } DebugConsole.Draw(spriteBatch); + + + if (GUIComponent.MouseOn != null && !string.IsNullOrWhiteSpace(GUIComponent.MouseOn.ToolTip)) GUIComponent.MouseOn.DrawToolTip(spriteBatch); } public static void Update(float deltaTime) diff --git a/Subsurface/GUI/GUIComponent.cs b/Subsurface/GUI/GUIComponent.cs index c89948873..fec02c78a 100644 --- a/Subsurface/GUI/GUIComponent.cs +++ b/Subsurface/GUI/GUIComponent.cs @@ -42,6 +42,14 @@ namespace Subsurface set; } + public string ToolTip + { + get; + set; + } + + private GUITextBlock toolTipBlock; + //protected float alpha; public GUIComponent Parent @@ -222,6 +230,20 @@ namespace Subsurface //DrawChildren(spriteBatch); } + public void DrawToolTip(SpriteBatch spriteBatch) + { + int width = 200; + if (toolTipBlock==null || (string)toolTipBlock.userData != ToolTip) + { + string wrappedText = ToolBox.WrapText(ToolTip, width, GUI.SmallFont); + toolTipBlock = new GUITextBlock(new Rectangle(0,0,width, wrappedText.Split('\n').Length*15), ToolTip, GUI.style, null, true); + toolTipBlock.userData = ToolTip; + } + + toolTipBlock.rect = new Rectangle((int)PlayerInput.MousePosition.X, (int)PlayerInput.MousePosition.Y, toolTipBlock.rect.Width, toolTipBlock.rect.Height); + toolTipBlock.Draw(spriteBatch); + } + public virtual void Update(float deltaTime) { if (CanBeFocused) diff --git a/Subsurface/GUI/GUIListBox.cs b/Subsurface/GUI/GUIListBox.cs index ffaf15f1e..39af7f1a2 100644 --- a/Subsurface/GUI/GUIListBox.cs +++ b/Subsurface/GUI/GUIListBox.cs @@ -111,9 +111,10 @@ namespace Subsurface if (parent != null) parent.AddChild(this); + scrollBarHidden = true; scrollBar = new GUIScrollBar( - new Rectangle(this.rect.X + this.rect.Width, this.rect.Y, 20, this.rect.Height), color, 1.0f, style); + new Rectangle(this.rect.X + this.rect.Width-20, this.rect.Y, 20, this.rect.Height), color, 1.0f, style); frame = new GUIFrame(Rectangle.Empty, style, this); if (style != null) style.Apply(frame, this); @@ -214,14 +215,15 @@ namespace Subsurface private void ShowScrollBar() { + if (scrollBarHidden) Rect = new Rectangle(rect.X, rect.Y, rect.Width - scrollBar.Rect.Width, rect.Height); scrollBarHidden = false; - Rect = new Rectangle(rect.X, rect.Y, rect.Width - scrollBar.Rect.Width, rect.Height); + } private void HideScrollBar() { + if (!scrollBarHidden) Rect = new Rectangle(rect.X, rect.Y, rect.Width + scrollBar.Rect.Width, rect.Height); scrollBarHidden = true; - Rect = new Rectangle(rect.X, rect.Y, rect.Width + scrollBar.Rect.Width, rect.Height); } public override void Draw(SpriteBatch spriteBatch) diff --git a/Subsurface/GUI/GUITextBox.cs b/Subsurface/GUI/GUITextBox.cs index 514a68165..bb5516663 100644 --- a/Subsurface/GUI/GUITextBox.cs +++ b/Subsurface/GUI/GUITextBox.cs @@ -193,6 +193,7 @@ namespace Subsurface new Vector2((int)caretPos.X + 2, caretPos.Y + Font.MeasureString("I").Y - 3), textBlock.TextColor * (textBlock.TextColor.A / 255.0f)); } + } public void ReceiveTextInput(char inputChar) diff --git a/Subsurface/GUI/TitleScreen.cs b/Subsurface/GUI/TitleScreen.cs index 277030099..7379d5fb3 100644 --- a/Subsurface/GUI/TitleScreen.cs +++ b/Subsurface/GUI/TitleScreen.cs @@ -81,7 +81,17 @@ namespace Subsurface titlePos, null, Color.White * Math.Min((state - 3.0f) / 5.0f, 1.0f), 0.0f, new Vector2(titleTexture.Width / 2.0f, titleTexture.Height / 2.0f), scale, SpriteEffects.None, 0.0f); - string loadText = (loadState<100.0f) ? "Loading... "+(int)loadState+" %" : "Press any key to continue"; + string loadText = ""; + if (loadState == 100.0f) + { + loadText = "Press any key to continue"; + + } + else if (loadState > 0.0f) + { + loadText = "Loading... " + (int)loadState + " %"; + } + spriteBatch.DrawString(GUI.Font, loadText, new Vector2(Game1.GraphicsWidth/2.0f - 50.0f, Game1.GraphicsHeight*0.8f), Color.White); spriteBatch.End(); diff --git a/Subsurface/Game1.cs b/Subsurface/Game1.cs index 3ffe5a805..be882f75e 100644 --- a/Subsurface/Game1.cs +++ b/Subsurface/Game1.cs @@ -196,6 +196,8 @@ namespace Subsurface loadState = 70.0f; yield return Status.Running; + GameMode.Init(); + Submarine.Preload("Content/SavedMaps"); loadState = 80.0f; yield return Status.Running; @@ -214,7 +216,6 @@ namespace Subsurface ParticleManager = new ParticleManager("Content/Particles/prefabs.xml", Cam); yield return Status.Running; - GameMode.Init(); GUIComponent.Init(Window); DebugConsole.Init(Window); yield return Status.Running; diff --git a/Subsurface/Items/Components/Holdable/Holdable.cs b/Subsurface/Items/Components/Holdable/Holdable.cs index dd5048d39..a06616106 100644 --- a/Subsurface/Items/Components/Holdable/Holdable.cs +++ b/Subsurface/Items/Components/Holdable/Holdable.cs @@ -204,7 +204,7 @@ namespace Subsurface.Items.Components AnimController ac = picker.AnimController; - item.sprite.Depth = picker.AnimController.GetLimb(LimbType.RightHand).sprite.Depth + 0.01f; + //item.sprite.Depth = picker.AnimController.GetLimb(LimbType.RightHand).sprite.Depth + 0.01f; ac.HoldItem(deltaTime, cam, item, handlePos, holdPos, aimPos, holdAngle); } diff --git a/Subsurface/Items/Components/Label.cs b/Subsurface/Items/Components/Label.cs index 9d57c5f4d..411fbdeee 100644 --- a/Subsurface/Items/Components/Label.cs +++ b/Subsurface/Items/Components/Label.cs @@ -24,8 +24,6 @@ namespace Subsurface.Items.Components } } - - public Label(Item item, XElement element) : base(item, element) { diff --git a/Subsurface/Items/Components/Machines/Radar.cs b/Subsurface/Items/Components/Machines/Radar.cs index 8333ea1f2..89a995781 100644 --- a/Subsurface/Items/Components/Machines/Radar.cs +++ b/Subsurface/Items/Components/Machines/Radar.cs @@ -59,9 +59,7 @@ namespace Subsurface.Items.Components else { pingState = 0.0f; - } - - + } } public override bool Use(float deltaTime, Character character = null) @@ -84,7 +82,7 @@ namespace Subsurface.Items.Components int radius = GuiFrame.Rect.Height / 2 - 10; DrawRadar(spriteBatch, new Rectangle((int)GuiFrame.Center.X - radius, (int)GuiFrame.Center.Y - radius, radius * 2, radius * 2)); - voltage = 0.0f; + //voltage = 0.0f; } private void DrawRadar(SpriteBatch spriteBatch, Rectangle rect) @@ -198,8 +196,6 @@ namespace Subsurface.Items.Components quest.RadarLabel, quest.RadarPosition, displayScale, center, (rect.Width * 0.55f)); } - - } } @@ -218,8 +214,7 @@ namespace Subsurface.Items.Components GUI.DrawRectangle(spriteBatch, new Rectangle((int)markerPos.X, (int)markerPos.Y, 5, 5), Color.LightGreen); spriteBatch.DrawString(GUI.SmallFont, label, new Vector2(markerPos.X + 10, markerPos.Y), Color.LightGreen); - spriteBatch.DrawString(GUI.SmallFont, (int)(dist / 80.0f) + " m", new Vector2(markerPos.X + 10, markerPos.Y + 15), Color.LightGreen); - + spriteBatch.DrawString(GUI.SmallFont, (int)(dist / 80.0f) + " m", new Vector2(markerPos.X + 10, markerPos.Y + 15), Color.LightGreen); } } diff --git a/Subsurface/Items/Components/Machines/Steering.cs b/Subsurface/Items/Components/Machines/Steering.cs index 7a2c6cb70..f61e7c734 100644 --- a/Subsurface/Items/Components/Machines/Steering.cs +++ b/Subsurface/Items/Components/Machines/Steering.cs @@ -47,7 +47,6 @@ namespace Subsurface.Items.Components { if (float.IsNaN(value.X) || float.IsNaN(value.Y)) { - targetVelocity = Vector2.Zero; return; } targetVelocity.X = MathHelper.Clamp(value.X, -100.0f, 100.0f); diff --git a/Subsurface/Items/Components/Signal/Connection.cs b/Subsurface/Items/Components/Signal/Connection.cs index 43589f7d0..234f86d50 100644 --- a/Subsurface/Items/Components/Signal/Connection.cs +++ b/Subsurface/Items/Components/Signal/Connection.cs @@ -459,7 +459,7 @@ namespace Subsurface.Items.Components if (Wires[i]!=null) { Wires[i].Item.body.Enabled = false; - Wires[i].Connect(this, false); + Wires[i].Connect(this, false, true); } } diff --git a/Subsurface/Items/Components/Signal/ConnectionPanel.cs b/Subsurface/Items/Components/Signal/ConnectionPanel.cs index 50cbd499f..18b743e89 100644 --- a/Subsurface/Items/Components/Signal/ConnectionPanel.cs +++ b/Subsurface/Items/Components/Signal/ConnectionPanel.cs @@ -91,6 +91,11 @@ namespace Subsurface.Items.Components } } + public override void Remove() + { + base.Remove(); + } + public override void FillNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetOutgoingMessage message) { foreach (Connection c in connections) diff --git a/Subsurface/Items/Components/Signal/Wire.cs b/Subsurface/Items/Components/Signal/Wire.cs index aaa2245ef..65b8344b4 100644 --- a/Subsurface/Items/Components/Signal/Wire.cs +++ b/Subsurface/Items/Components/Signal/Wire.cs @@ -61,7 +61,7 @@ namespace Subsurface.Items.Components if (connection == connections[1]) connections[1] = null; } - public void Connect(Connection newConnection, bool addNode = true) + public void Connect(Connection newConnection, bool addNode = true, bool loading = false) { for (int i = 0; i < 2; i++) { @@ -85,7 +85,6 @@ namespace Subsurface.Items.Components Nodes.Add(newConnection.Item.Position); } - break; } @@ -110,7 +109,7 @@ namespace Subsurface.Items.Components CleanNodes(); } - Item.NewComponentEvent(this, true); + if (!loading) Item.NewComponentEvent(this, true); } public override void Equip(Character character) diff --git a/Subsurface/Items/Inventory.cs b/Subsurface/Items/Inventory.cs index f0516245c..75db0a607 100644 --- a/Subsurface/Items/Inventory.cs +++ b/Subsurface/Items/Inventory.cs @@ -287,10 +287,19 @@ namespace Subsurface public override void ReadNetworkData(NetworkEventType type, NetIncomingMessage message) { - int itemId = message.ReadInt32(); - if (itemId == -1) return; + int itemId=-1, slotIndex = -1; - int slotIndex = message.ReadInt32(); + try + { + itemId = message.ReadInt32(); + slotIndex = message.ReadInt32(); + } + catch + { + return; + } + + if (itemId == -1) return; Item item = FindEntityByID(itemId) as Item; if (item == null) return; diff --git a/Subsurface/Items/Item.cs b/Subsurface/Items/Item.cs index 04937ab11..6474c6bb4 100644 --- a/Subsurface/Items/Item.cs +++ b/Subsurface/Items/Item.cs @@ -1184,7 +1184,7 @@ namespace Subsurface public override void Remove() { base.Remove(); - + //sprite.Remove(); if (body != null) body.Remove(); @@ -1194,6 +1194,14 @@ namespace Subsurface } itemList.Remove(this); + + foreach (Item it in itemList) + { + if (it.linkedTo.Contains(this)) + { + it.linkedTo.Remove(this); + } + } } } diff --git a/Subsurface/Map/Md5Hash.cs b/Subsurface/Map/Md5Hash.cs index 93e03c935..d13aa078c 100644 --- a/Subsurface/Map/Md5Hash.cs +++ b/Subsurface/Map/Md5Hash.cs @@ -1,4 +1,5 @@ -using System.Security.Cryptography; +using System.IO; +using System.Security.Cryptography; using System.Text; using System.Text.RegularExpressions; using System.Xml.Linq; @@ -40,6 +41,13 @@ namespace Subsurface shortHash = GetShortHash(hash); } + public Md5Hash(FileStream fileStream) + { + hash = CalculateHash(fileStream); + + shortHash = GetShortHash(hash); + } + public Md5Hash(XDocument doc) { string docString = Regex.Replace(doc.ToString(), @"\s+", ""); @@ -51,6 +59,20 @@ namespace Subsurface shortHash = GetShortHash(hash); } + private string CalculateHash(FileStream stream) + { + MD5 md5 = MD5.Create(); + byte[] byteHash = md5.ComputeHash(stream); + // step 2, convert byte array to hex string + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < byteHash.Length; i++) + { + sb.Append(byteHash[i].ToString("X2")); + } + + return sb.ToString(); + } + private string CalculateHash(byte[] bytes) { MD5 md5 = MD5.Create(); diff --git a/Subsurface/Screens/MainMenu.cs b/Subsurface/Screens/MainMenu.cs index b83d0ff7c..0bd277acc 100644 --- a/Subsurface/Screens/MainMenu.cs +++ b/Subsurface/Screens/MainMenu.cs @@ -162,12 +162,13 @@ namespace Subsurface new GUITextBlock(new Rectangle(0, 100, 0, 30), "Server port:", GUI.style, Alignment.CenterX, Alignment.CenterX, menuTabs[(int)Tabs.HostServer]); portBox = new GUITextBox(new Rectangle(0, 130, 200, 30), Color.White, Color.Black, Alignment.CenterX, Alignment.CenterX, null, menuTabs[(int)Tabs.HostServer]); portBox.Text = NetworkMember.DefaultPort.ToString(); + portBox.ToolTip = "Server port"; GUIButton hostButton = new GUIButton(new Rectangle(0, 0, 200, 30), "Start", Alignment.BottomCenter, GUI.style, menuTabs[(int)Tabs.HostServer]); hostButton.OnClicked = HostServerClicked; //---------------------------------------------------------------------- - for (int i = 1; i < 4; i++ ) + for (int i = 1; i < 5; i++ ) { button = new GUIButton(new Rectangle(-20, -20, 100, 30), "Back", Alignment.TopLeft, GUI.style, menuTabs[i]); button.OnClicked = PreviousTab; diff --git a/Subsurface/Screens/NetLobbyScreen.cs b/Subsurface/Screens/NetLobbyScreen.cs index 1d0c86ead..d757a2466 100644 --- a/Subsurface/Screens/NetLobbyScreen.cs +++ b/Subsurface/Screens/NetLobbyScreen.cs @@ -34,6 +34,8 @@ namespace Subsurface public bool IsServer; public string ServerName, ServerMessage; + private GUITextBox serverMessage; + public Submarine SelectedMap { get { return subList.SelectedData as Submarine; } @@ -101,10 +103,12 @@ namespace Subsurface public NetLobbyScreen() { - Rectangle panelRect = new Rectangle( - 40, 40, Game1.GraphicsWidth - 80, Game1.GraphicsHeight - 80); + int width = Math.Min(Game1.GraphicsWidth - 80, 1500); + int height = Math.Min(Game1.GraphicsHeight - 80, 800); - menu = new GUIFrame(panelRect, Color.Transparent); + Rectangle panelRect = new Rectangle(0,0,width,height); + + menu = new GUIFrame(panelRect, Color.Transparent, Alignment.Center); //menu.Padding = GUI.style.smallPadding; //server info panel ------------------------------------------------------------ @@ -139,28 +143,15 @@ namespace Subsurface GUI.style, menu); playerList = new GUIListBox(new Rectangle(0,0,0,0), null, GUI.style, playerListFrame); - } - public override void Deselect() - { - textBox.Deselect(); - } + //submarine list ------------------------------------------------------------------ - public override void Select() - { - Game1.LightManager.LosEnabled = false; + int columnWidth = infoFrame.Rect.Width / 3 - 30; + int columnX = 0; - infoFrame.ClearChildren(); - - textBox.Select(); - - Character.Controlled = null; - Game1.GameScreen.Cam.TargetPos = Vector2.Zero; - - new GUITextBlock(new Rectangle(0, 110, 0, 30), "Selected submarine:", GUI.style, infoFrame); - subList = new GUIListBox(new Rectangle(0, 140, 200, 200), Color.White, GUI.style, infoFrame); + new GUITextBlock(new Rectangle(columnX, 120, columnWidth, 30), "Selected submarine:", GUI.style, infoFrame); + subList = new GUIListBox(new Rectangle(columnX, 150, columnWidth, 200), Color.White, GUI.style, infoFrame); subList.OnSelected = SelectMap; - subList.Enabled = (Game1.Server != null); if (Submarine.SavedSubmarines.Count > 0) { @@ -181,10 +172,13 @@ namespace Subsurface return; } - new GUITextBlock(new Rectangle(220, 110, 0, 30), "Selected game mode: ", GUI.style, infoFrame); - modeList = new GUIListBox(new Rectangle(220, 140, 200, 200), GUI.style, infoFrame); - modeList.Enabled = (Game1.Server != null); + columnX += columnWidth + 20; + //gamemode ------------------------------------------------------------------ + + new GUITextBlock(new Rectangle(columnX, 120, 0, 30), "Selected game mode: ", GUI.style, infoFrame); + modeList = new GUIListBox(new Rectangle(columnX, 150, columnWidth, 200), GUI.style, infoFrame); + foreach (GameModePreset mode in GameModePreset.list) { if (mode.IsSinglePlayer) continue; @@ -198,40 +192,72 @@ namespace Subsurface textBlock.UserData = mode; } - GUITextBlock durationText = new GUITextBlock(new Rectangle((int)(modeList.Rect.Right + 20 - 80), 110, 100, 20), + columnX += columnWidth + 20; + + //duration ------------------------------------------------------------------ + + GUITextBlock durationText = new GUITextBlock(new Rectangle(columnX, 120, columnWidth, 20), "Game duration: ", GUI.style, Alignment.Left, Alignment.TopLeft, infoFrame); durationText.TextGetter = DurationText; - durationBar = new GUIScrollBar(new Rectangle((int)(modeList.Rect.Right + 20 - 80), 140, 180, 20), + durationBar = new GUIScrollBar(new Rectangle(columnX, 150, columnWidth, 20), GUI.style, 0.1f, infoFrame); durationBar.BarSize = 0.1f; - durationBar.Enabled = (Game1.Server != null); - new GUITextBlock(new Rectangle((int)(modeList.Rect.Right + 20 - 80), 180, 100, 20), + //seed ------------------------------------------------------------------ + + new GUITextBlock(new Rectangle(columnX, 190, columnWidth, 20), "Level Seed: ", GUI.style, Alignment.Left, Alignment.TopLeft, infoFrame); - seedBox = new GUITextBox(new Rectangle((int)(modeList.Rect.Right + 20 - 80), 210, 180, 20), + seedBox = new GUITextBox(new Rectangle(columnX, 220, columnWidth, 20), Alignment.TopLeft, GUI.style, infoFrame); - seedBox.OnEnter = SelectSeed; - seedBox.Enabled = (Game1.Server != null); + seedBox.OnTextChanged = SelectSeed; LevelSeed = ToolBox.RandomSeed(8); + //server info ------------------------------------------------------------------ + var serverName = new GUITextBox(new Rectangle(0, 0, 200, 20), null, null, Alignment.TopLeft, Alignment.TopLeft, GUI.style, infoFrame); serverName.TextGetter = GetServerName; serverName.Enabled = Game1.Server != null; serverName.OnTextChanged = ChangeServerName; - ServerName = (Game1.Server==null) ? "Server" : Game1.Server.Name; - var serverMessage = new GUITextBox(new Rectangle(0, 30, 360, 70), null, null, Alignment.TopLeft, Alignment.TopLeft, GUI.style, infoFrame); - serverMessage.Enabled = Game1.Server != null; + + serverMessage = new GUITextBox(new Rectangle(0, 30, 360, 70), null, null, Alignment.TopLeft, Alignment.TopLeft, GUI.style, infoFrame); serverMessage.Wrap = true; serverMessage.TextGetter = GetServerMessage; serverMessage.OnTextChanged = UpdateServerMessage; + } + + public override void Deselect() + { + textBox.Deselect(); + } + + public override void Select() + { + Game1.LightManager.LosEnabled = false; + + //infoFrame.ClearChildren(); + + textBox.Select(); + + Character.Controlled = null; + Game1.GameScreen.Cam.TargetPos = Vector2.Zero; + + subList.Enabled = Game1.Server != null; + modeList.Enabled = Game1.Server != null; + durationBar.Enabled = Game1.Server != null; + seedBox.Enabled = Game1.Server != null; + serverMessage.Enabled = Game1.Server != null; + ServerName = (Game1.Server==null) ? "Server" : Game1.Server.Name; + + infoFrame.RemoveChild(infoFrame.children.Find(c => c.UserData as string == "startButton")); if (IsServer && Game1.Server != null) { GUIButton startButton = new GUIButton(new Rectangle(0, 0, 200, 30), "Start", Alignment.TopRight, GUI.style, infoFrame); startButton.OnClicked = Game1.Server.StartGame; + startButton.UserData = "startButton"; //mapList.OnSelected = new GUIListBox.OnSelectedHandler(Game1.server.UpdateNetLobby); modeList.OnSelected = Game1.Server.UpdateNetLobby; @@ -244,6 +270,8 @@ namespace Subsurface { int x = playerFrame.Rect.Width / 2; + playerFrame.ClearChildren(); + new GUITextBlock(new Rectangle(x, 0, 200, 30), "Name: ", GUI.style, playerFrame); GUITextBox playerName = new GUITextBox(new Rectangle(x, 30, 0, 20), @@ -462,7 +490,7 @@ namespace Subsurface } //textBox.Text = LevelSeed; - textBox.Selected = false; + //textBox.Selected = false; if (Game1.Server != null) Game1.Server.UpdateNetLobby(null); diff --git a/Subsurface_Solution.v12.suo b/Subsurface_Solution.v12.suo index ae2eb7bcb..d1ca1d9c2 100644 Binary files a/Subsurface_Solution.v12.suo and b/Subsurface_Solution.v12.suo differ