public static void LoadAll() { foreach (ContentFile file in ContentPackage.GetFilesOfType(GameMain.Config.SelectedContentPackages, ContentType.Character)) { LoadFromFile(file); } }
public static void LoadTextPacks(IEnumerable <ContentPackage> selectedContentPackages) { HashSet <string> newLanguages = new HashSet <string>(); Dictionary <string, List <TextPack> > newTextPacks = new Dictionary <string, List <TextPack> >(); var textFiles = ContentPackage.GetFilesOfType(selectedContentPackages, ContentType.Text).ToList(); foreach (ContentFile file in textFiles) { #if !DEBUG try { #endif var textPack = new TextPack(file.Path); newLanguages.Add(textPack.Language); if (!newTextPacks.ContainsKey(textPack.Language)) { newTextPacks.Add(textPack.Language, new List <TextPack>()); } newTextPacks[textPack.Language].Add(textPack); #if !DEBUG } catch (Exception e) { DebugConsole.ThrowError("Failed to load text file \"" + file.Path + "\"!", e); } #endif } if (newTextPacks.Count == 0) { DebugConsole.ThrowError("No text files available in any of the selected content packages. Attempting to find a vanilla English text file..."); if (!File.Exists(VanillaTextFilePath)) { throw new Exception("No text files found in any of the selected content packages or in the default text path!"); } var textPack = new TextPack(VanillaTextFilePath); newLanguages.Add(textPack.Language); newTextPacks.Add(textPack.Language, new List <TextPack>() { textPack }); } if (newTextPacks.Count == 0) { throw new Exception("Failed to load text packs!"); } lock (mutex) { textPacks = newTextPacks; availableLanguages = newLanguages; DebugConsole.NewMessage("Loaded languages: " + string.Join(", ", newLanguages)); } Initialized = true; }
/// <summary> /// Returns the file paths of all files of the given type in the content packages. /// </summary> /// <param name="type"></param> /// <param name="searchAllContentPackages">If true, also returns files in content packages that are installed but not currently selected.</param> public IEnumerable <string> GetFilesOfType(ContentType type, bool searchAllContentPackages = false) { if (searchAllContentPackages) { return(ContentPackage.GetFilesOfType(ContentPackage.List, type)); } else { return(ContentPackage.GetFilesOfType(SelectedPackages, type)); } }
/// <summary> /// Returns the file paths of all files of the given type in the content packages. /// </summary> /// <param name="type"></param> /// <param name="searchAllContentPackages">If true, also returns files in content packages that are installed but not currently selected.</param> public IEnumerable <ContentFile> GetFilesOfType(ContentType type, bool searchAllContentPackages = false) { if (searchAllContentPackages) { return(ContentPackage.GetFilesOfType(ContentPackage.AllPackages, type)); } else { return(ContentPackage.GetFilesOfType(Config.AllEnabledPackages, type)); } }
public static void Init() { var files = ContentPackage.GetFilesOfType(GameMain.Config.SelectedContentPackages, ContentType.MapGenerationParameters); if (!files.Any()) { DebugConsole.ThrowError("No map generation parameters found in the selected content packages!"); return; } // Let's not actually load the parameters until we have solved which file is the last, because loading the parameters takes some resources that would also need to be released. XElement selectedElement = null; foreach (string file in files) { XDocument doc = XMLExtensions.TryLoadXml(file); if (doc == null) { continue; } var mainElement = doc.Root; if (doc.Root.IsOverride()) { mainElement = doc.Root.FirstElement(); if (selectedElement != null) { DebugConsole.NewMessage($"Overriding the map generation parameters with '{file}'", Color.Yellow); } } else if (selectedElement != null) { DebugConsole.ThrowError($"Error in {file}: Another map generation parameter file already loaded! Use <override></override> tags to override it."); break; } selectedElement = mainElement; } if (selectedElement == null) { DebugConsole.ThrowError("Could not find a valid element in the map generation parameter files!"); } else { instance = new MapGenerationParams(selectedElement); } }
public static void LoadTextPacks(IEnumerable <ContentPackage> selectedContentPackages) { availableLanguages.Clear(); textPacks.Clear(); var textFiles = ContentPackage.GetFilesOfType(selectedContentPackages, ContentType.Text); foreach (string file in textFiles) { try { var textPack = new TextPack(file); availableLanguages.Add(textPack.Language); if (!textPacks.ContainsKey(textPack.Language)) { textPacks.Add(textPack.Language, new List <TextPack>()); } textPacks[textPack.Language].Add(textPack); } catch (Exception e) { DebugConsole.ThrowError("Failed to load text file \"" + file + "\"!", e); } } if (textPacks.Count == 0) { DebugConsole.ThrowError("No text files available in any of the selected content packages. Attempting to find a vanilla English text file..."); if (!File.Exists(VanillaTextFilePath)) { throw new Exception("No text files found in any of the selected content packages or in the default text path!"); } var textPack = new TextPack(VanillaTextFilePath); availableLanguages.Add(textPack.Language); textPacks.Add(textPack.Language, new List <TextPack>() { textPack }); } Initialized = true; }
public static void Init() { var files = ContentPackage.GetFilesOfType(GameMain.Config.SelectedContentPackages, ContentType.MapGenerationParameters); if (!files.Any()) { DebugConsole.ThrowError("No map generation parameters found in the selected content packages!"); return; } foreach (string file in files) { XDocument doc = XMLExtensions.TryLoadXml(file); if (doc?.Root == null) { return; } instance = new MapGenerationParams(doc.Root); break; } }
public static void Init() { List.Clear(); var locationTypeFiles = GameMain.Instance.GetFilesOfType(ContentType.LocationTypes); if (!locationTypeFiles.Any()) { DebugConsole.ThrowError("No location types configured in any of the selected content packages. Attempting to load from the vanilla content package..."); locationTypeFiles = ContentPackage.GetFilesOfType(GameMain.VanillaContent.ToEnumerable(), ContentType.LocationTypes); if (!locationTypeFiles.Any()) { throw new Exception("No location types configured in any of the selected content packages. Please try uninstalling mods or reinstalling the game."); } } foreach (ContentFile file in locationTypeFiles) { XDocument doc = XMLExtensions.TryLoadXml(file.Path); if (doc == null) { continue; } var mainElement = doc.Root; if (doc.Root.IsOverride()) { mainElement = doc.Root.FirstElement(); DebugConsole.NewMessage($"Overriding all location types with '{file.Path}'", Color.Yellow); List.Clear(); } else if (List.Any()) { DebugConsole.NewMessage($"Loading additional location types from file '{file.Path}'"); } foreach (XElement sourceElement in mainElement.Elements()) { var element = sourceElement; bool allowOverriding = false; if (sourceElement.IsOverride()) { element = sourceElement.FirstElement(); allowOverriding = true; } string identifier = element.GetAttributeString("identifier", null); if (string.IsNullOrWhiteSpace(identifier)) { DebugConsole.ThrowError($"Error in '{file.Path}': No identifier defined for {element.Name.ToString()}"); continue; } var duplicate = List.FirstOrDefault(l => l.Identifier == identifier); if (duplicate != null) { if (allowOverriding) { List.Remove(duplicate); DebugConsole.NewMessage($"Overriding the location type with the identifier '{identifier}' with '{file.Path}'", Color.Yellow); } else { DebugConsole.ThrowError($"Error in '{file.Path}': Duplicate identifier defined with the identifier '{identifier}'"); continue; } } LocationType locationType = new LocationType(element); List.Add(locationType); } } foreach (EventSet eventSet in EventSet.List) { eventSet.CheckLocationTypeErrors(); } }
public static void RefreshSavedSubs() { var contentPackageSubs = ContentPackage.GetFilesOfType( GameMain.Config.AllEnabledPackages, ContentType.Submarine, ContentType.Outpost, ContentType.OutpostModule, ContentType.Wreck, ContentType.BeaconStation); for (int i = savedSubmarines.Count - 1; i >= 0; i--) { if (File.Exists(savedSubmarines[i].FilePath)) { bool isDownloadedSub = Path.GetFullPath(Path.GetDirectoryName(savedSubmarines[i].FilePath)) == Path.GetFullPath(SaveUtil.SubmarineDownloadFolder); bool isInSubmarinesFolder = Path.GetFullPath(Path.GetDirectoryName(savedSubmarines[i].FilePath)) == Path.GetFullPath(SavePath); bool isInContentPackage = contentPackageSubs.Any(fp => Path.GetFullPath(fp.Path).CleanUpPath() == Path.GetFullPath(savedSubmarines[i].FilePath).CleanUpPath()); if (isDownloadedSub) { continue; } if (savedSubmarines[i].LastModifiedTime == File.GetLastWriteTime(savedSubmarines[i].FilePath) && (isInSubmarinesFolder || isInContentPackage)) { continue; } } savedSubmarines[i].Dispose(); } if (!Directory.Exists(SavePath)) { try { Directory.CreateDirectory(SavePath); } catch (Exception e) { DebugConsole.ThrowError("Directory \"" + SavePath + "\" not found and creating the directory failed.", e); return; } } List <string> filePaths; string[] subDirectories; try { filePaths = Directory.GetFiles(SavePath).ToList(); subDirectories = Directory.GetDirectories(SavePath).Where(s => { DirectoryInfo dir = new DirectoryInfo(s); return(!dir.Attributes.HasFlag(System.IO.FileAttributes.Hidden) && !dir.Name.StartsWith(".")); }).ToArray(); } catch (Exception e) { DebugConsole.ThrowError("Couldn't open directory \"" + SavePath + "\"!", e); return; } foreach (string subDirectory in subDirectories) { try { filePaths.AddRange(Directory.GetFiles(subDirectory).ToList()); } catch (Exception e) { DebugConsole.ThrowError("Couldn't open subdirectory \"" + subDirectory + "\"!", e); return; } } foreach (ContentFile subFile in contentPackageSubs) { if (!filePaths.Any(fp => Path.GetFullPath(fp) == Path.GetFullPath(subFile.Path))) { filePaths.Add(subFile.Path); } } filePaths.RemoveAll(p => savedSubmarines.Any(sub => sub.FilePath == p)); foreach (string path in filePaths) { var subInfo = new SubmarineInfo(path); if (subInfo.IsFileCorrupted) { #if CLIENT if (DebugConsole.IsOpen) { DebugConsole.Toggle(); } var deleteSubPrompt = new GUIMessageBox( TextManager.Get("Error"), TextManager.GetWithVariable("SubLoadError", "[subname]", subInfo.Name) + "\n" + TextManager.GetWithVariable("DeleteFileVerification", "[filename]", subInfo.Name), new string[] { TextManager.Get("Yes"), TextManager.Get("No") }); string filePath = path; deleteSubPrompt.Buttons[0].OnClicked += (btn, userdata) => { try { File.Delete(filePath); } catch (Exception e) { DebugConsole.ThrowError($"Failed to delete file \"{filePath}\".", e); } deleteSubPrompt.Close(); return(true); }; deleteSubPrompt.Buttons[1].OnClicked += deleteSubPrompt.Close; #endif } else { savedSubmarines.Add(subInfo); } } }
public static void Init() { var files = ContentPackage.GetFilesOfType(GameMain.Config.AllEnabledPackages, ContentType.MapGenerationParameters); if (!files.Any()) { DebugConsole.ThrowError("No map generation parameters found in the selected content packages!"); return; } // Let's not actually load the parameters until we have solved which file is the last, because loading the parameters takes some resources that would also need to be released. XElement selectedElement = null; string selectedFile = null; foreach (ContentFile file in files) { XDocument doc = XMLExtensions.TryLoadXml(file.Path); if (doc == null) { continue; } var mainElement = doc.Root; if (doc.Root.IsOverride()) { mainElement = doc.Root.FirstElement(); if (selectedElement != null) { DebugConsole.NewMessage($"Overriding the map generation parameters with '{file.Path}'", Color.Yellow); } } else if (selectedElement != null) { DebugConsole.ThrowError($"Error in {file.Path}: Another map generation parameter file already loaded! Use <override></override> tags to override it."); break; } selectedElement = mainElement; selectedFile = file.Path; } if (selectedFile == loadedFile) { return; } #if CLIENT if (instance != null) { instance?.ConnectionSprite?.Remove(); instance?.PassedConnectionSprite?.Remove(); instance?.SelectedLocationIndicator?.Remove(); instance?.CurrentLocationIndicator?.Remove(); instance?.DecorativeGraphSprite?.Remove(); instance?.MissionIcon?.Remove(); instance?.TypeChangeIcon?.Remove(); instance?.FogOfWarSprite?.Remove(); foreach (List <Sprite> spriteList in instance.mapTiles.Values) { foreach (Sprite sprite in spriteList) { sprite.Remove(); } } instance.mapTiles.Clear(); } #endif instance = null; if (selectedElement == null) { DebugConsole.ThrowError("Could not find a valid element in the map generation parameter files!"); } else { instance = new MapGenerationParams(selectedElement); loadedFile = selectedFile; } }
/// <summary> /// Returns the file paths of all files of the given type in the currently selected content packages. /// </summary> public IEnumerable <string> GetFilesOfType(ContentType type) { return(ContentPackage.GetFilesOfType(SelectedPackages, type)); }
public LevelEditorScreen() { cam = new Camera() { MinZoom = 0.01f, MaxZoom = 1.0f }; leftPanel = new GUIFrame(new RectTransform(new Vector2(0.125f, 0.8f), Frame.RectTransform) { MinSize = new Point(150, 0) }); var paddedLeftPanel = new GUILayoutGroup(new RectTransform(new Vector2(0.9f, 0.95f), leftPanel.RectTransform, Anchor.CenterLeft) { RelativeOffset = new Vector2(0.02f, 0.0f) }) { Stretch = true, RelativeSpacing = 0.01f }; paramsList = new GUIListBox(new RectTransform(new Vector2(1.0f, 0.3f), paddedLeftPanel.RectTransform)); paramsList.OnSelected += (GUIComponent component, object obj) => { selectedParams = obj as LevelGenerationParams; editorContainer.ClearChildren(); SortLevelObjectsList(selectedParams); new SerializableEntityEditor(editorContainer.Content.RectTransform, selectedParams, false, true, elementHeight: 20); return(true); }; var ruinTitle = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), paddedLeftPanel.RectTransform), TextManager.Get("leveleditor.ruinparams"), font: GUI.SubHeadingFont); ruinParamsList = new GUIListBox(new RectTransform(new Vector2(1.0f, 0.1f), paddedLeftPanel.RectTransform)); ruinParamsList.OnSelected += (GUIComponent component, object obj) => { var ruinGenerationParams = obj as RuinGenerationParams; editorContainer.ClearChildren(); new SerializableEntityEditor(editorContainer.Content.RectTransform, ruinGenerationParams, false, true, elementHeight: 20); return(true); }; var outpostTitle = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), paddedLeftPanel.RectTransform), TextManager.Get("leveleditor.outpostparams"), font: GUI.SubHeadingFont); GUITextBlock.AutoScaleAndNormalize(ruinTitle, outpostTitle); outpostParamsList = new GUIListBox(new RectTransform(new Vector2(1.0f, 0.2f), paddedLeftPanel.RectTransform)); outpostParamsList.OnSelected += (GUIComponent component, object obj) => { var outpostGenerationParams = obj as OutpostGenerationParams; editorContainer.ClearChildren(); var outpostParamsEditor = new SerializableEntityEditor(editorContainer.Content.RectTransform, outpostGenerationParams, false, true, elementHeight: 20); // location type ------------------------- var locationTypeGroup = new GUILayoutGroup(new RectTransform(new Point(editorContainer.Content.Rect.Width, 20)), isHorizontal: true, childAnchor: Anchor.CenterLeft) { Stretch = true }; new GUITextBlock(new RectTransform(new Vector2(0.5f, 1f), locationTypeGroup.RectTransform), TextManager.Get("outpostmoduleallowedlocationtypes"), textAlignment: Alignment.CenterLeft); HashSet <string> availableLocationTypes = new HashSet <string> { "any" }; foreach (LocationType locationType in LocationType.List) { availableLocationTypes.Add(locationType.Identifier); } var locationTypeDropDown = new GUIDropDown(new RectTransform(new Vector2(0.5f, 1f), locationTypeGroup.RectTransform), text: string.Join(", ", outpostGenerationParams.AllowedLocationTypes.Select(lt => TextManager.Capitalize(lt)) ?? "any".ToEnumerable()), selectMultiple: true); foreach (string locationType in availableLocationTypes) { locationTypeDropDown.AddItem(TextManager.Capitalize(locationType), locationType); if (outpostGenerationParams.AllowedLocationTypes.Contains(locationType)) { locationTypeDropDown.SelectItem(locationType); } } if (!outpostGenerationParams.AllowedLocationTypes.Any()) { locationTypeDropDown.SelectItem("any"); } locationTypeDropDown.OnSelected += (_, __) => { outpostGenerationParams.SetAllowedLocationTypes(locationTypeDropDown.SelectedDataMultiple.Cast <string>()); locationTypeDropDown.Text = ToolBox.LimitString(locationTypeDropDown.Text, locationTypeDropDown.Font, locationTypeDropDown.Rect.Width); return(true); }; locationTypeGroup.RectTransform.MinSize = new Point(locationTypeGroup.Rect.Width, locationTypeGroup.RectTransform.Children.Max(c => c.MinSize.Y)); outpostParamsEditor.AddCustomContent(locationTypeGroup, 100); // module count ------------------------- var moduleLabel = new GUITextBlock(new RectTransform(new Point(editorContainer.Content.Rect.Width, (int)(70 * GUI.Scale))), TextManager.Get("submarinetype.outpostmodules"), font: GUI.SubHeadingFont); outpostParamsEditor.AddCustomContent(moduleLabel, 100); foreach (KeyValuePair <string, int> moduleCount in outpostGenerationParams.ModuleCounts) { var moduleCountGroup = new GUILayoutGroup(new RectTransform(new Point(editorContainer.Content.Rect.Width, (int)(25 * GUI.Scale))), isHorizontal: true, childAnchor: Anchor.CenterLeft); new GUITextBlock(new RectTransform(new Vector2(0.5f, 1f), moduleCountGroup.RectTransform), TextManager.Capitalize(moduleCount.Key), textAlignment: Alignment.CenterLeft); new GUINumberInput(new RectTransform(new Vector2(0.5f, 1f), moduleCountGroup.RectTransform), GUINumberInput.NumberType.Int) { MinValueInt = 0, MaxValueInt = 100, IntValue = moduleCount.Value, OnValueChanged = (numInput) => { outpostGenerationParams.SetModuleCount(moduleCount.Key, numInput.IntValue); if (numInput.IntValue == 0) { outpostParamsList.Select(outpostParamsList.SelectedData); } } }; moduleCountGroup.RectTransform.MinSize = new Point(moduleCountGroup.Rect.Width, moduleCountGroup.RectTransform.Children.Max(c => c.MinSize.Y)); outpostParamsEditor.AddCustomContent(moduleCountGroup, 100); } // add module count ------------------------- var addModuleCountGroup = new GUILayoutGroup(new RectTransform(new Point(editorContainer.Content.Rect.Width, (int)(40 * GUI.Scale))), isHorizontal: true, childAnchor: Anchor.Center); HashSet <string> availableFlags = new HashSet <string>(); foreach (string flag in OutpostGenerationParams.Params.SelectMany(p => p.ModuleCounts.Select(m => m.Key))) { availableFlags.Add(flag); } foreach (var sub in SubmarineInfo.SavedSubmarines) { if (sub.OutpostModuleInfo == null) { continue; } foreach (string flag in sub.OutpostModuleInfo.ModuleFlags) { availableFlags.Add(flag); } } var moduleTypeDropDown = new GUIDropDown(new RectTransform(new Vector2(0.8f, 0.8f), addModuleCountGroup.RectTransform), text: TextManager.Get("leveleditor.addmoduletype")); foreach (string flag in availableFlags) { if (outpostGenerationParams.ModuleCounts.Any(mc => mc.Key.Equals(flag, StringComparison.OrdinalIgnoreCase))) { continue; } moduleTypeDropDown.AddItem(TextManager.Capitalize(flag), flag); } moduleTypeDropDown.OnSelected += (_, userdata) => { outpostGenerationParams.SetModuleCount(userdata as string, 1); outpostParamsList.Select(outpostParamsList.SelectedData); return(true); }; addModuleCountGroup.RectTransform.MinSize = new Point(addModuleCountGroup.Rect.Width, addModuleCountGroup.RectTransform.Children.Max(c => c.MinSize.Y)); outpostParamsEditor.AddCustomContent(addModuleCountGroup, 100); return(true); }; var createLevelObjButton = new GUIButton(new RectTransform(new Vector2(1.0f, 0.05f), paddedLeftPanel.RectTransform), TextManager.Get("leveleditor.createlevelobj")) { OnClicked = (btn, obj) => { Wizard.Instance.Create(); return(true); } }; GUITextBlock.AutoScaleAndNormalize(createLevelObjButton.TextBlock); lightingEnabled = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.025f), paddedLeftPanel.RectTransform), TextManager.Get("leveleditor.lightingenabled")); cursorLightEnabled = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.025f), paddedLeftPanel.RectTransform), TextManager.Get("leveleditor.cursorlightenabled")); new GUIButton(new RectTransform(new Vector2(1.0f, 0.05f), paddedLeftPanel.RectTransform), TextManager.Get("leveleditor.reloadtextures")) { OnClicked = (btn, obj) => { Level.Loaded?.ReloadTextures(); return(true); } }; new GUIButton(new RectTransform(new Vector2(1.0f, 0.05f), paddedLeftPanel.RectTransform), TextManager.Get("editor.saveall")) { OnClicked = (btn, obj) => { SerializeAll(); return(true); } }; rightPanel = new GUIFrame(new RectTransform(new Vector2(0.25f, 1.0f), Frame.RectTransform, Anchor.TopRight) { MinSize = new Point(450, 0) }); var paddedRightPanel = new GUILayoutGroup(new RectTransform(new Vector2(0.95f, 0.95f), rightPanel.RectTransform, Anchor.Center) { RelativeOffset = new Vector2(0.02f, 0.0f) }) { Stretch = true, RelativeSpacing = 0.01f }; editorContainer = new GUIListBox(new RectTransform(new Vector2(1.0f, 1.0f), paddedRightPanel.RectTransform)); var seedContainer = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.05f), paddedRightPanel.RectTransform), isHorizontal: true); new GUITextBlock(new RectTransform(new Vector2(0.5f, 1.0f), seedContainer.RectTransform), TextManager.Get("leveleditor.levelseed")); seedBox = new GUITextBox(new RectTransform(new Vector2(0.5f, 1.0f), seedContainer.RectTransform), ToolBox.RandomSeed(8)); new GUIButton(new RectTransform(new Vector2(1.0f, 0.05f), paddedRightPanel.RectTransform), TextManager.Get("leveleditor.generate")) { OnClicked = (btn, obj) => { Submarine.Unload(); GameMain.LightManager.ClearLights(); LevelData levelData = LevelData.CreateRandom(seedBox.Text, generationParams: selectedParams); levelData.ForceOutpostGenerationParams = outpostParamsList.SelectedData as OutpostGenerationParams; Level.Generate(levelData, mirror: false); GameMain.LightManager.AddLight(pointerLightSource); cam.Position = new Vector2(Level.Loaded.Size.X / 2, Level.Loaded.Size.Y / 2); foreach (GUITextBlock param in paramsList.Content.Children) { param.TextColor = param.UserData == selectedParams ? GUI.Style.Green : param.Style.TextColor; } seedBox.Deselect(); return(true); } }; new GUIButton(new RectTransform(new Vector2(1.0f, 0.05f), paddedRightPanel.RectTransform), TextManager.Get("leveleditor.test")) { OnClicked = (btn, obj) => { if (Level.Loaded?.LevelData == null) { return(false); } GameMain.GameScreen.Select(); var currEntities = Entity.GetEntities().ToList(); if (Submarine.MainSub != null) { var toRemove = Entity.GetEntities().Where(e => e.Submarine == Submarine.MainSub).ToList(); foreach (Entity ent in toRemove) { ent.Remove(); } Submarine.MainSub.Remove(); } //TODO: hacky workaround to check for wrecks and outposts, refactor SubmarineInfo and ContentType at some point var nonPlayerFiles = ContentPackage.GetFilesOfType(GameMain.Config.AllEnabledPackages, ContentType.Wreck).ToList(); nonPlayerFiles.AddRange(ContentPackage.GetFilesOfType(GameMain.Config.AllEnabledPackages, ContentType.Outpost)); nonPlayerFiles.AddRange(ContentPackage.GetFilesOfType(GameMain.Config.AllEnabledPackages, ContentType.OutpostModule)); SubmarineInfo subInfo = SubmarineInfo.SavedSubmarines.FirstOrDefault(s => s.Name.Equals(GameMain.Config.QuickStartSubmarineName, StringComparison.InvariantCultureIgnoreCase)); subInfo ??= SubmarineInfo.SavedSubmarines.GetRandom(s => s.IsPlayer && !s.HasTag(SubmarineTag.Shuttle) && !nonPlayerFiles.Any(f => f.Path.CleanUpPath().Equals(s.FilePath.CleanUpPath(), StringComparison.InvariantCultureIgnoreCase))); GameSession gameSession = new GameSession(subInfo, "", GameModePreset.TestMode, null); gameSession.StartRound(Level.Loaded.LevelData); (gameSession.GameMode as TestGameMode).OnRoundEnd = () => { GameMain.LevelEditorScreen.Select(); Submarine.MainSub.Remove(); var toRemove = Entity.GetEntities().Where(e => !currEntities.Contains(e)).ToList(); foreach (Entity ent in toRemove) { ent.Remove(); } Submarine.MainSub = null; }; GameMain.GameSession = gameSession; return(true); } }; bottomPanel = new GUIFrame(new RectTransform(new Vector2(0.75f, 0.22f), Frame.RectTransform, Anchor.BottomLeft) { MaxSize = new Point(GameMain.GraphicsWidth - rightPanel.Rect.Width, 1000) }, style: "GUIFrameBottom"); levelObjectList = new GUIListBox(new RectTransform(new Vector2(0.99f, 0.85f), bottomPanel.RectTransform, Anchor.Center)) { UseGridLayout = true }; levelObjectList.OnSelected += (GUIComponent component, object obj) => { selectedLevelObject = obj as LevelObjectPrefab; CreateLevelObjectEditor(selectedLevelObject); return(true); }; spriteEditDoneButton = new GUIButton(new RectTransform(new Point(200, 30), anchor: Anchor.BottomRight) { AbsoluteOffset = new Point(20, 20) }, TextManager.Get("leveleditor.spriteeditdone")) { OnClicked = (btn, userdata) => { editingSprite = null; return(true); } }; topPanel = new GUIFrame(new RectTransform(new Point(400, 100), GUI.Canvas) { RelativeOffset = new Vector2(leftPanel.RectTransform.RelativeSize.X * 2, 0.0f) }, style: "GUIFrameTop"); }
private bool HostServerClicked(GUIButton button, object obj) { string name = serverNameBox.Text; if (string.IsNullOrEmpty(name)) { serverNameBox.Flash(); return(false); } if (!int.TryParse(portBox.Text, out int port) || port < 0 || port > 65535) { portBox.Text = NetConfig.DefaultPort.ToString(); portBox.Flash(); return(false); } int queryPort = 0; if (Steam.SteamManager.USE_STEAM) { if (!int.TryParse(queryPortBox.Text, out queryPort) || queryPort < 0 || queryPort > 65535) { portBox.Text = NetConfig.DefaultQueryPort.ToString(); portBox.Flash(); return(false); } } GameMain.NetLobbyScreen = new NetLobbyScreen(); try { string exeName = ContentPackage.GetFilesOfType(GameMain.Config.SelectedContentPackages, ContentType.ServerExecutable)?.FirstOrDefault(); if (string.IsNullOrEmpty(exeName)) { DebugConsole.ThrowError("No server executable defined in the selected content packages. Attempting to use the default executable..."); exeName = "DedicatedServer.exe"; } int ownerKey = Math.Max(CryptoRandom.Instance.Next(), 1); string arguments = "-name \"" + name.Replace("\\", "\\\\").Replace("\"", "\\\"") + "\"" + " -port " + port.ToString() + " -queryport " + queryPort.ToString() + " -public " + isPublicBox.Selected.ToString() + " -password \"" + passwordBox.Text.Replace("\\", "\\\\").Replace("\"", "\\\"") + "\"" + " -upnp " + useUpnpBox.Selected + " -maxplayers " + maxPlayersBox.Text + " -ownerkey " + ownerKey.ToString(); string filename = exeName; #if LINUX || OSX filename = "./" + Path.GetFileNameWithoutExtension(exeName); #endif var processInfo = new ProcessStartInfo { FileName = filename, Arguments = arguments, #if !DEBUG WindowStyle = ProcessWindowStyle.Hidden #endif }; GameMain.ServerChildProcess = Process.Start(processInfo); Thread.Sleep(1000); //wait until the server is ready before connecting GameMain.Client = new GameClient(name, "127.0.0.1:" + port.ToString(), name, ownerKey); } catch (Exception e) { DebugConsole.ThrowError("Failed to start server", e); } return(true); }
public static void Init() { var files = ContentPackage.GetFilesOfType(GameMain.Config.SelectedContentPackages, ContentType.MapGenerationParameters); if (!files.Any()) { DebugConsole.ThrowError("No map generation parameters found in the selected content packages!"); return; } // Let's not actually load the parameters until we have solved which file is the last, because loading the parameters takes some resources that would also need to be released. XElement selectedElement = null; string selectedFile = null; foreach (ContentFile file in files) { XDocument doc = XMLExtensions.TryLoadXml(file.Path); if (doc == null) { continue; } var mainElement = doc.Root; if (doc.Root.IsOverride()) { mainElement = doc.Root.FirstElement(); if (selectedElement != null) { DebugConsole.NewMessage($"Overriding the map generation parameters with '{file.Path}'", Color.Yellow); } } else if (selectedElement != null) { DebugConsole.ThrowError($"Error in {file.Path}: Another map generation parameter file already loaded! Use <override></override> tags to override it."); break; } selectedElement = mainElement; selectedFile = file.Path; } if (selectedFile == loadedFile) { return; } instance?.ConnectionSprite?.Remove(); instance?.BackgroundTileSprites.ForEach(s => s.Remove()); #if CLIENT instance?.MapCircle?.Remove(); instance?.LocationIndicator?.Remove(); instance?.DecorativeMapSprite?.Remove(); instance?.DecorativeGraphSprite?.Remove(); instance?.DecorativeLineTop?.Remove(); instance?.DecorativeLineBottom?.Remove(); instance?.DecorativeLineCorner?.Remove(); instance?.ReticleLarge?.Remove(); instance?.ReticleMedium?.Remove(); instance?.ReticleSmall?.Remove(); #endif instance = null; if (selectedElement == null) { DebugConsole.ThrowError("Could not find a valid element in the map generation parameter files!"); } else { instance = new MapGenerationParams(selectedElement); loadedFile = selectedFile; } }