private bool Reload(GUIButton button, object obj) { var pathBox = obj as GUITextBox; if (!File.Exists(pathBox.Text)) { new GUIMessageBox(TextManager.Get("Error"), TextManager.GetWithVariable("ReloadLinkedSubError", "[file]", pathBox.Text)); pathBox.Flash(GUI.Style.Red); pathBox.Text = filePath; return(false); } XDocument doc = SubmarineInfo.OpenFile(pathBox.Text); if (doc == null || doc.Root == null) { return(false); } doc.Root.SetAttributeValue("filepath", pathBox.Text); pathBox.Flash(GUI.Style.Green); GenerateWallVertices(doc.Root); saveElement = doc.Root; saveElement.Name = "LinkedSubmarine"; filePath = pathBox.Text; return(true); }
public static LinkedSubmarine CreateDummy(Submarine mainSub, string filePath, Vector2 position) { XDocument doc = SubmarineInfo.OpenFile(filePath); if (doc == null || doc.Root == null) { return(null); } LinkedSubmarine sl = CreateDummy(mainSub, doc.Root, position); sl.filePath = filePath; return(sl); }
public static LinkedSubmarine CreateDummy(Submarine mainSub, string filePath, Vector2 position) { XDocument doc = SubmarineInfo.OpenFile(filePath); if (doc == null || doc.Root == null) { return(null); } LinkedSubmarine sl = CreateDummy(mainSub, doc.Root, position); sl.filePath = filePath; sl.saveElement = doc.Root; sl.saveElement.Name = "LinkedSubmarine"; sl.saveElement.SetAttributeValue("filepath", filePath); return(sl); }
public override XElement Save(XElement parentElement) { XElement saveElement = null; if (sub == null) { if (this.saveElement == null) { var doc = SubmarineInfo.OpenFile(filePath); saveElement = doc.Root; saveElement.Name = "LinkedSubmarine"; saveElement.Add(new XAttribute("filepath", filePath)); } else { saveElement = this.saveElement; } if (saveElement.Attribute("pos") != null) { saveElement.Attribute("pos").Remove(); } saveElement.Add(new XAttribute("pos", XMLExtensions.Vector2ToString(Position - Submarine.HiddenSubPosition))); var linkedPort = linkedTo.FirstOrDefault(lt => (lt is Item) && ((Item)lt).GetComponent <DockingPort>() != null); if (linkedPort != null) { saveElement.Attribute("linkedto")?.Remove(); saveElement.Add(new XAttribute("linkedto", linkedPort.ID)); } } else { saveElement = new XElement("LinkedSubmarine"); sub.SaveToXElement(saveElement); } saveElement.Attribute("originallinkedto")?.Remove(); saveElement.Add(new XAttribute("originallinkedto", originalLinkedPort != null ? originalLinkedPort.Item.ID : originalLinkedToID)); saveElement.Attribute("originalmyport")?.Remove(); saveElement.Add(new XAttribute("originalmyport", originalMyPortID)); if (sub != null) { bool leaveBehind = false; if (!sub.DockedTo.Contains(Submarine.MainSub)) { System.Diagnostics.Debug.Assert(Submarine.MainSub.AtEndPosition || Submarine.MainSub.AtStartPosition); if (Submarine.MainSub.AtEndPosition) { leaveBehind = sub.AtEndPosition != Submarine.MainSub.AtEndPosition; } else { leaveBehind = sub.AtStartPosition != Submarine.MainSub.AtStartPosition; } } if (leaveBehind) { saveElement.SetAttributeValue("location", Level.Loaded.Seed); saveElement.SetAttributeValue("worldpos", XMLExtensions.Vector2ToString(sub.SubBody.Position)); } else { if (saveElement.Attribute("location") != null) { saveElement.Attribute("location").Remove(); } if (saveElement.Attribute("worldpos") != null) { saveElement.Attribute("worldpos").Remove(); } } saveElement.SetAttributeValue("pos", XMLExtensions.Vector2ToString(Position - Submarine.HiddenSubPosition)); } parentElement.Add(saveElement); return(saveElement); }