private IEnumerable <object> Load(bool isSeparateThread) { if (GameSettings.VerboseLogging) { DebugConsole.NewMessage("LOADING COROUTINE", Color.Lime); } while (TitleScreen.WaitForLanguageSelection) { yield return(CoroutineStatus.Running); } SoundManager = new Sounds.SoundManager(); SoundManager.SetCategoryGainMultiplier("default", Config.SoundVolume); SoundManager.SetCategoryGainMultiplier("ui", Config.SoundVolume); SoundManager.SetCategoryGainMultiplier("waterambience", Config.SoundVolume); SoundManager.SetCategoryGainMultiplier("music", Config.MusicVolume); SoundManager.SetCategoryGainMultiplier("voip", Config.VoiceChatVolume * 20.0f); if (Config.EnableSplashScreen) { var pendingSplashScreens = TitleScreen.PendingSplashScreens; pendingSplashScreens?.Enqueue(new Pair <string, Point>("Content/Splash_UTG.mp4", new Point(1280, 720))); pendingSplashScreens?.Enqueue(new Pair <string, Point>("Content/Splash_FF.mp4", new Point(1280, 720))); pendingSplashScreens?.Enqueue(new Pair <string, Point>("Content/Splash_Daedalic.mp4", new Point(1920, 1080))); } //if not loading in a separate thread, wait for the splash screens to finish before continuing the loading //otherwise the videos will look extremely choppy if (!isSeparateThread) { while (TitleScreen.PlayingSplashScreen || TitleScreen.PendingSplashScreens.Count > 0) { yield return(CoroutineStatus.Running); } } GUI.Init(Window, Config.SelectedContentPackages, GraphicsDevice); DebugConsole.Init(); if (Config.AutoUpdateWorkshopItems) { if (SteamManager.AutoUpdateWorkshopItems()) { ContentPackage.LoadAll(ContentPackage.Folder); Config.ReloadContentPackages(); } } if (SelectedPackages.Count == 0) { DebugConsole.Log("No content packages selected"); } else { DebugConsole.Log("Selected content packages: " + string.Join(", ", SelectedPackages.Select(cp => cp.Name))); } /*#if DEBUG * GameSettings.ShowUserStatisticsPrompt = false; * GameSettings.SendUserStatistics = false; #endif*/ InitUserStats(); yield return(CoroutineStatus.Running); LightManager = new Lights.LightManager(base.GraphicsDevice, Content); TitleScreen.LoadState = 1.0f; yield return(CoroutineStatus.Running); GUI.LoadContent(); TitleScreen.LoadState = 2.0f; yield return(CoroutineStatus.Running); MissionPrefab.Init(); MapEntityPrefab.Init(); Tutorials.Tutorial.Init(); MapGenerationParams.Init(); LevelGenerationParams.LoadPresets(); ScriptedEventSet.LoadPrefabs(); AfflictionPrefab.LoadAll(GetFilesOfType(ContentType.Afflictions)); TitleScreen.LoadState = 10.0f; yield return(CoroutineStatus.Running); StructurePrefab.LoadAll(GetFilesOfType(ContentType.Structure)); TitleScreen.LoadState = 15.0f; yield return(CoroutineStatus.Running); ItemPrefab.LoadAll(GetFilesOfType(ContentType.Item)); TitleScreen.LoadState = 25.0f; yield return(CoroutineStatus.Running); JobPrefab.LoadAll(GetFilesOfType(ContentType.Jobs)); // Add any missing jobs from the prefab into Config.JobNamePreferences. foreach (JobPrefab job in JobPrefab.List) { if (!Config.JobPreferences.Contains(job.Identifier)) { Config.JobPreferences.Add(job.Identifier); } } NPCConversation.LoadAll(GetFilesOfType(ContentType.NPCConversations)); ItemAssemblyPrefab.LoadAll(); TitleScreen.LoadState = 30.0f; yield return(CoroutineStatus.Running); Debug.WriteLine("sounds"); int i = 0; foreach (object crObj in SoundPlayer.Init()) { CoroutineStatus status = (CoroutineStatus)crObj; if (status == CoroutineStatus.Success) { break; } i++; TitleScreen.LoadState = SoundPlayer.SoundCount == 0 ? 30.0f : Math.Min(30.0f + 40.0f * i / Math.Max(SoundPlayer.SoundCount, 1), 70.0f); yield return(CoroutineStatus.Running); } TitleScreen.LoadState = 70.0f; yield return(CoroutineStatus.Running); GameModePreset.Init(); Submarine.RefreshSavedSubs(); TitleScreen.LoadState = 80.0f; yield return(CoroutineStatus.Running); GameScreen = new GameScreen(GraphicsDeviceManager.GraphicsDevice, Content); TitleScreen.LoadState = 90.0f; yield return(CoroutineStatus.Running); MainMenuScreen = new MainMenuScreen(this); LobbyScreen = new LobbyScreen(); ServerListScreen = new ServerListScreen(); if (SteamManager.USE_STEAM) { SteamWorkshopScreen = new SteamWorkshopScreen(); } SubEditorScreen = new SubEditorScreen(); ParticleEditorScreen = new ParticleEditorScreen(); LevelEditorScreen = new LevelEditorScreen(); SpriteEditorScreen = new SpriteEditorScreen(); CharacterEditorScreen = new CharacterEditorScreen(); yield return(CoroutineStatus.Running); TitleScreen.LoadState = 95.0f; ParticleManager = new ParticleManager(GameScreen.Cam); ParticleManager.LoadPrefabs(); TitleScreen.LoadState = 97.0f; LevelObjectPrefab.LoadAll(); DecalManager = new DecalManager(); TitleScreen.LoadState = 99.0f; yield return(CoroutineStatus.Running); LocationType.Init(); MainMenuScreen.Select(); CheckContentPackage(); foreach (string steamError in SteamManager.InitializationErrors) { new GUIMessageBox(TextManager.Get("Error"), TextManager.Get(steamError)); } TitleScreen.LoadState = 100.0f; hasLoaded = true; if (GameSettings.VerboseLogging) { DebugConsole.NewMessage("LOADING COROUTINE FINISHED", Color.Lime); } yield return(CoroutineStatus.Success); }
private IEnumerable <object> Load(bool isSeparateThread) { if (GameSettings.VerboseLogging) { DebugConsole.NewMessage("LOADING COROUTINE", Color.Lime); } while (TitleScreen.WaitForLanguageSelection) { yield return(CoroutineStatus.Running); } SoundManager = new Sounds.SoundManager(); SoundManager.SetCategoryGainMultiplier("default", Config.SoundVolume, 0); SoundManager.SetCategoryGainMultiplier("ui", Config.SoundVolume, 0); SoundManager.SetCategoryGainMultiplier("waterambience", Config.SoundVolume, 0); SoundManager.SetCategoryGainMultiplier("music", Config.MusicVolume, 0); SoundManager.SetCategoryGainMultiplier("voip", Math.Min(Config.VoiceChatVolume, 1.0f), 0); if (Config.EnableSplashScreen && !ConsoleArguments.Contains("-skipintro")) { var pendingSplashScreens = TitleScreen.PendingSplashScreens; float baseVolume = MathHelper.Clamp(Config.SoundVolume * 2.0f, 0.0f, 1.0f); pendingSplashScreens?.Enqueue(new LoadingScreen.PendingSplashScreen("Content/SplashScreens/Splash_UTG.webm", baseVolume * 0.5f)); pendingSplashScreens?.Enqueue(new LoadingScreen.PendingSplashScreen("Content/SplashScreens/Splash_FF.webm", baseVolume)); pendingSplashScreens?.Enqueue(new LoadingScreen.PendingSplashScreen("Content/SplashScreens/Splash_Daedalic.webm", baseVolume * 0.1f)); } //if not loading in a separate thread, wait for the splash screens to finish before continuing the loading //otherwise the videos will look extremely choppy if (!isSeparateThread) { while (TitleScreen.PlayingSplashScreen || TitleScreen.PendingSplashScreens.Count > 0) { yield return(CoroutineStatus.Running); } } GUI.Init(Window, Config.AllEnabledPackages, GraphicsDevice); DebugConsole.Init(); if (Config.AutoUpdateWorkshopItems) { Config.WaitingForAutoUpdate = true; TaskPool.Add("AutoUpdateWorkshopItemsAsync", SteamManager.AutoUpdateWorkshopItemsAsync(), (task) => { bool result = ((Task <bool>)task).Result; Config.WaitingForAutoUpdate = false; }); while (Config.WaitingForAutoUpdate) { yield return(CoroutineStatus.Running); } } if (Config.AllEnabledPackages.None()) { DebugConsole.Log("No content packages selected"); } else { DebugConsole.Log("Selected content packages: " + string.Join(", ", Config.AllEnabledPackages.Select(cp => cp.Name))); } #if DEBUG GameSettings.ShowUserStatisticsPrompt = false; GameSettings.SendUserStatistics = false; #endif InitUserStats(); yield return(CoroutineStatus.Running); Debug.WriteLine("sounds"); int i = 0; foreach (object crObj in SoundPlayer.Init()) { CoroutineStatus status = (CoroutineStatus)crObj; if (status == CoroutineStatus.Success) { break; } i++; TitleScreen.LoadState = SoundPlayer.SoundCount == 0 ? 1.0f : Math.Min(40.0f * i / Math.Max(SoundPlayer.SoundCount, 1), 40.0f); yield return(CoroutineStatus.Running); } TitleScreen.LoadState = 40.0f; yield return(CoroutineStatus.Running); LightManager = new Lights.LightManager(base.GraphicsDevice, Content); TitleScreen.LoadState = 41.0f; yield return(CoroutineStatus.Running); GUI.LoadContent(); TitleScreen.LoadState = 42.0f; yield return(CoroutineStatus.Running); TaskPool.Add("InitRelayNetworkAccess", SteamManager.InitRelayNetworkAccess(), (t) => { }); FactionPrefab.LoadFactions(); NPCSet.LoadSets(); CharacterPrefab.LoadAll(); MissionPrefab.Init(); TraitorMissionPrefab.Init(); MapEntityPrefab.Init(); Tutorials.Tutorial.Init(); MapGenerationParams.Init(); LevelGenerationParams.LoadPresets(); OutpostGenerationParams.LoadPresets(); WreckAIConfig.LoadAll(); EventSet.LoadPrefabs(); ItemPrefab.LoadAll(GetFilesOfType(ContentType.Item)); AfflictionPrefab.LoadAll(GetFilesOfType(ContentType.Afflictions)); SkillSettings.Load(GetFilesOfType(ContentType.SkillSettings)); Order.Init(); EventManagerSettings.Init(); TitleScreen.LoadState = 50.0f; yield return(CoroutineStatus.Running); StructurePrefab.LoadAll(GetFilesOfType(ContentType.Structure)); TitleScreen.LoadState = 55.0f; yield return(CoroutineStatus.Running); UpgradePrefab.LoadAll(GetFilesOfType(ContentType.UpgradeModules)); TitleScreen.LoadState = 56.0f; yield return(CoroutineStatus.Running); JobPrefab.LoadAll(GetFilesOfType(ContentType.Jobs)); CorpsePrefab.LoadAll(GetFilesOfType(ContentType.Corpses)); NPCConversation.LoadAll(GetFilesOfType(ContentType.NPCConversations)); ItemAssemblyPrefab.LoadAll(); TitleScreen.LoadState = 60.0f; yield return(CoroutineStatus.Running); GameModePreset.Init(); SubmarineInfo.RefreshSavedSubs(); TitleScreen.LoadState = 65.0f; yield return(CoroutineStatus.Running); GameScreen = new GameScreen(GraphicsDeviceManager.GraphicsDevice, Content); TitleScreen.LoadState = 68.0f; yield return(CoroutineStatus.Running); MainMenuScreen = new MainMenuScreen(this); ServerListScreen = new ServerListScreen(); TitleScreen.LoadState = 70.0f; yield return(CoroutineStatus.Running); #if USE_STEAM SteamWorkshopScreen = new SteamWorkshopScreen(); if (SteamManager.IsInitialized) { Steamworks.SteamFriends.OnGameRichPresenceJoinRequested += OnInvitedToGame; Steamworks.SteamFriends.OnGameLobbyJoinRequested += OnLobbyJoinRequested; } #endif SubEditorScreen = new SubEditorScreen(); TitleScreen.LoadState = 75.0f; yield return(CoroutineStatus.Running); ParticleEditorScreen = new ParticleEditorScreen(); TitleScreen.LoadState = 80.0f; yield return(CoroutineStatus.Running); LevelEditorScreen = new LevelEditorScreen(); SpriteEditorScreen = new SpriteEditorScreen(); EventEditorScreen = new EventEditorScreen(); CharacterEditorScreen = new CharacterEditor.CharacterEditorScreen(); CampaignEndScreen = new CampaignEndScreen(); yield return(CoroutineStatus.Running); TitleScreen.LoadState = 85.0f; ParticleManager = new ParticleManager(GameScreen.Cam); ParticleManager.LoadPrefabs(); TitleScreen.LoadState = 88.0f; LevelObjectPrefab.LoadAll(); TitleScreen.LoadState = 90.0f; yield return(CoroutineStatus.Running); DecalManager = new DecalManager(); LocationType.Init(); MainMenuScreen.Select(); foreach (string steamError in SteamManager.InitializationErrors) { new GUIMessageBox(TextManager.Get("Error"), TextManager.Get(steamError)); } TitleScreen.LoadState = 100.0f; hasLoaded = true; if (GameSettings.VerboseLogging) { DebugConsole.NewMessage("LOADING COROUTINE FINISHED", Color.Lime); } yield return(CoroutineStatus.Success); }
private IEnumerable <object> Load() { if (GameSettings.VerboseLogging) { DebugConsole.NewMessage("LOADING COROUTINE", Color.Lime); } GUI.GraphicsDevice = base.GraphicsDevice; GUI.Init(Content); GUIComponent.Init(Window); DebugConsole.Init(Window); DebugConsole.Log(SelectedPackage == null ? "No content package selected" : "Content package \"" + SelectedPackage.Name + "\" selected"); yield return(CoroutineStatus.Running); LightManager = new Lights.LightManager(base.GraphicsDevice, Content); Hull.renderer = new WaterRenderer(base.GraphicsDevice, Content); TitleScreen.LoadState = 1.0f; yield return(CoroutineStatus.Running); GUI.LoadContent(); TitleScreen.LoadState = 2.0f; yield return(CoroutineStatus.Running); Mission.Init(); MapEntityPrefab.Init(); LevelGenerationParams.LoadPresets(); TitleScreen.LoadState = 10.0f; yield return(CoroutineStatus.Running); JobPrefab.LoadAll(SelectedPackage.GetFilesOfType(ContentType.Jobs)); // Add any missing jobs from the prefab into Config.JobNamePreferences. foreach (JobPrefab job in JobPrefab.List) { if (!Config.JobNamePreferences.Contains(job.Name)) { Config.JobNamePreferences.Add(job.Name); } } StructurePrefab.LoadAll(SelectedPackage.GetFilesOfType(ContentType.Structure)); TitleScreen.LoadState = 20.0f; yield return(CoroutineStatus.Running); ItemPrefab.LoadAll(SelectedPackage.GetFilesOfType(ContentType.Item)); TitleScreen.LoadState = 30.0f; yield return(CoroutineStatus.Running); Debug.WriteLine("sounds"); CoroutineManager.StartCoroutine(SoundPlayer.Init()); int i = 0; while (!SoundPlayer.Initialized) { i++; TitleScreen.LoadState = SoundPlayer.SoundCount == 0 ? 30.0f : Math.Min(30.0f + 40.0f * i / Math.Max(SoundPlayer.SoundCount, 1), 70.0f); yield return(CoroutineStatus.Running); } TitleScreen.LoadState = 70.0f; yield return(CoroutineStatus.Running); GameModePreset.Init(); Submarine.RefreshSavedSubs(); TitleScreen.LoadState = 80.0f; yield return(CoroutineStatus.Running); GameScreen = new GameScreen(GraphicsDeviceManager.GraphicsDevice, Content); TitleScreen.LoadState = 90.0f; yield return(CoroutineStatus.Running); MainMenuScreen = new MainMenuScreen(this); LobbyScreen = new LobbyScreen(); ServerListScreen = new ServerListScreen(); SubEditorScreen = new SubEditorScreen(Content); CharacterEditorScreen = new CharacterEditorScreen(); ParticleEditorScreen = new ParticleEditorScreen(); yield return(CoroutineStatus.Running); ParticleManager = new ParticleManager("Content/Particles/ParticlePrefabs.xml", GameScreen.Cam); ParticleManager.LoadPrefabs(); DecalManager = new DecalManager("Content/Particles/DecalPrefabs.xml"); yield return(CoroutineStatus.Running); LocationType.Init(); MainMenuScreen.Select(); TitleScreen.LoadState = 100.0f; hasLoaded = true; if (GameSettings.VerboseLogging) { DebugConsole.NewMessage("LOADING COROUTINE FINISHED", Color.Lime); } yield return(CoroutineStatus.Success); }
private IEnumerable <object> Load() { if (GameSettings.VerboseLogging) { DebugConsole.NewMessage("LOADING COROUTINE", Color.Lime); } SoundManager = new Sounds.SoundManager(); SoundManager.SetCategoryGainMultiplier("default", Config.SoundVolume); SoundManager.SetCategoryGainMultiplier("ui", Config.SoundVolume); SoundManager.SetCategoryGainMultiplier("waterambience", Config.SoundVolume); SoundManager.SetCategoryGainMultiplier("music", Config.MusicVolume); SoundManager.SetCategoryGainMultiplier("voip", Config.VoiceChatVolume); if (Config.EnableSplashScreen) { try { (TitleScreen as LoadingScreen).SplashScreen = new Video(base.GraphicsDevice, SoundManager, "Content/splashscreen.mp4", 1280, 720); } catch (Exception e) { Config.EnableSplashScreen = false; DebugConsole.ThrowError("Playing the splash screen failed.", e); } } GUI.Init(Window, Config.SelectedContentPackages, GraphicsDevice); DebugConsole.Init(); SteamManager.Initialize(); if (Config.AutoUpdateWorkshopItems) { if (SteamManager.AutoUpdateWorkshopItems()) { ContentPackage.LoadAll(ContentPackage.Folder); Config.ReloadContentPackages(); } } if (SelectedPackages.Count == 0) { DebugConsole.Log("No content packages selected"); } else { DebugConsole.Log("Selected content packages: " + string.Join(", ", SelectedPackages.Select(cp => cp.Name))); } #if DEBUG GameSettings.ShowUserStatisticsPrompt = false; GameSettings.SendUserStatistics = false; #endif InitUserStats(); yield return(CoroutineStatus.Running); LightManager = new Lights.LightManager(base.GraphicsDevice, Content); WaterRenderer.Instance = new WaterRenderer(base.GraphicsDevice, Content); TitleScreen.LoadState = 1.0f; yield return(CoroutineStatus.Running); GUI.LoadContent(); TitleScreen.LoadState = 2.0f; yield return(CoroutineStatus.Running); MissionPrefab.Init(); MapEntityPrefab.Init(); Tutorials.Tutorial.Init(); MapGenerationParams.Init(); LevelGenerationParams.LoadPresets(); ScriptedEventSet.LoadPrefabs(); AfflictionPrefab.LoadAll(GetFilesOfType(ContentType.Afflictions)); TitleScreen.LoadState = 10.0f; yield return(CoroutineStatus.Running); StructurePrefab.LoadAll(GetFilesOfType(ContentType.Structure)); TitleScreen.LoadState = 15.0f; yield return(CoroutineStatus.Running); ItemPrefab.LoadAll(GetFilesOfType(ContentType.Item)); TitleScreen.LoadState = 25.0f; yield return(CoroutineStatus.Running); JobPrefab.LoadAll(GetFilesOfType(ContentType.Jobs)); // Add any missing jobs from the prefab into Config.JobNamePreferences. foreach (JobPrefab job in JobPrefab.List) { if (!Config.JobPreferences.Contains(job.Identifier)) { Config.JobPreferences.Add(job.Identifier); } } NPCConversation.LoadAll(GetFilesOfType(ContentType.NPCConversations)); ItemAssemblyPrefab.LoadAll(); TitleScreen.LoadState = 30.0f; yield return(CoroutineStatus.Running); Debug.WriteLine("sounds"); int i = 0; foreach (object crObj in SoundPlayer.Init()) { CoroutineStatus status = (CoroutineStatus)crObj; if (status == CoroutineStatus.Success) { break; } i++; TitleScreen.LoadState = SoundPlayer.SoundCount == 0 ? 30.0f : Math.Min(30.0f + 40.0f * i / Math.Max(SoundPlayer.SoundCount, 1), 70.0f); yield return(CoroutineStatus.Running); } TitleScreen.LoadState = 70.0f; yield return(CoroutineStatus.Running); GameModePreset.Init(); Submarine.RefreshSavedSubs(); TitleScreen.LoadState = 80.0f; yield return(CoroutineStatus.Running); GameScreen = new GameScreen(GraphicsDeviceManager.GraphicsDevice, Content); TitleScreen.LoadState = 90.0f; yield return(CoroutineStatus.Running); MainMenuScreen = new MainMenuScreen(this); LobbyScreen = new LobbyScreen(); ServerListScreen = new ServerListScreen(); if (SteamManager.USE_STEAM) { SteamWorkshopScreen = new SteamWorkshopScreen(); } SubEditorScreen = new SubEditorScreen(); ParticleEditorScreen = new ParticleEditorScreen(); LevelEditorScreen = new LevelEditorScreen(); SpriteEditorScreen = new SpriteEditorScreen(); CharacterEditorScreen = new CharacterEditorScreen(); yield return(CoroutineStatus.Running); TitleScreen.LoadState = 95.0f; ParticleManager = new ParticleManager(GameScreen.Cam); ParticleManager.LoadPrefabs(); TitleScreen.LoadState = 97.0f; LevelObjectPrefab.LoadAll(); DecalManager = new DecalManager(); TitleScreen.LoadState = 99.0f; yield return(CoroutineStatus.Running); LocationType.Init(); MainMenuScreen.Select(); CheckContentPackage(); TitleScreen.LoadState = 100.0f; hasLoaded = true; if (GameSettings.VerboseLogging) { DebugConsole.NewMessage("LOADING COROUTINE FINISHED", Color.Lime); } yield return(CoroutineStatus.Success); }
public static StructurePrefab Load(XElement element) { StructurePrefab sp = new StructurePrefab(); sp.name = element.Name.ToString(); sp.tags = new List <string>(); sp.tags.AddRange(ToolBox.GetAttributeString(element, "tags", "").Split(',')); foreach (XElement subElement in element.Elements()) { switch (subElement.Name.ToString()) { case "sprite": sp.sprite = new Sprite(subElement); if (ToolBox.GetAttributeBool(subElement, "fliphorizontal", false)) { sp.sprite.effects = SpriteEffects.FlipHorizontally; } if (ToolBox.GetAttributeBool(subElement, "flipvertical", false)) { sp.sprite.effects = SpriteEffects.FlipVertically; } sp.canSpriteFlipX = ToolBox.GetAttributeBool(subElement, "canflipx", true); break; case "backgroundsprite": sp.BackgroundSprite = new Sprite(subElement); if (ToolBox.GetAttributeBool(subElement, "fliphorizontal", false)) { sp.BackgroundSprite.effects = SpriteEffects.FlipHorizontally; } if (ToolBox.GetAttributeBool(subElement, "flipvertical", false)) { sp.BackgroundSprite.effects = SpriteEffects.FlipVertically; } break; } } MapEntityCategory category; if (!Enum.TryParse(ToolBox.GetAttributeString(element, "category", "Structure"), true, out category)) { category = MapEntityCategory.Structure; } sp.Category = category; sp.Description = ToolBox.GetAttributeString(element, "description", ""); sp.size = Vector2.Zero; sp.size.X = ToolBox.GetAttributeFloat(element, "width", 0.0f); sp.size.Y = ToolBox.GetAttributeFloat(element, "height", 0.0f); string spriteColorStr = ToolBox.GetAttributeString(element, "spritecolor", "1.0,1.0,1.0,1.0"); sp.SpriteColor = new Color(ToolBox.ParseToVector4(spriteColorStr)); sp.maxHealth = ToolBox.GetAttributeFloat(element, "health", 100.0f); sp.resizeHorizontal = ToolBox.GetAttributeBool(element, "resizehorizontal", false); sp.resizeVertical = ToolBox.GetAttributeBool(element, "resizevertical", false); sp.isPlatform = ToolBox.GetAttributeBool(element, "platform", false); sp.stairDirection = (Direction)Enum.Parse(typeof(Direction), ToolBox.GetAttributeString(element, "stairdirection", "None"), true); sp.castShadow = ToolBox.GetAttributeBool(element, "castshadow", false); sp.hasBody = ToolBox.GetAttributeBool(element, "body", false); return(sp); }
public Structure(Rectangle rectangle, StructurePrefab sp, Submarine submarine) : base(sp, submarine) { if (rectangle.Width == 0 || rectangle.Height == 0) { return; } System.Diagnostics.Debug.Assert(rectangle.Width > 0 && rectangle.Height > 0); rect = rectangle; prefab = sp; isHorizontal = (rect.Width > rect.Height); StairDirection = prefab.StairDirection; if (prefab.HasBody) { bodies = new List <Body>(); //gaps = new List<Gap>(); Body newBody = BodyFactory.CreateRectangle(GameMain.World, ConvertUnits.ToSimUnits(rect.Width), ConvertUnits.ToSimUnits(rect.Height), 1.5f); newBody.BodyType = BodyType.Static; newBody.Position = ConvertUnits.ToSimUnits(new Vector2(rect.X + rect.Width / 2.0f, rect.Y - rect.Height / 2.0f)); newBody.Friction = 0.5f; newBody.OnCollision += OnWallCollision; newBody.UserData = this; newBody.CollisionCategories = (prefab.IsPlatform) ? Physics.CollisionPlatform : Physics.CollisionWall; bodies.Add(newBody); WallList.Add(this); CreateSections(); } else { sections = new WallSection[1]; sections[0] = new WallSection(rect); if (StairDirection != Direction.None) { CreateStairBodies(); } } #if CLIENT if (prefab.CastShadow) { GenerateConvexHull(); } #endif InsertToList(); }
public static StructurePrefab Load(XElement element) { StructurePrefab sp = new StructurePrefab { name = element.GetAttributeString("name", "") }; sp.ConfigElement = element; if (string.IsNullOrEmpty(sp.name)) { sp.name = element.Name.ToString(); } sp.identifier = element.GetAttributeString("identifier", ""); string translatedName = TextManager.Get("EntityName." + sp.identifier, true); if (!string.IsNullOrEmpty(translatedName)) { sp.name = translatedName; } sp.Tags = new HashSet <string>(); string joinedTags = element.GetAttributeString("tags", ""); if (string.IsNullOrEmpty(joinedTags)) { joinedTags = element.GetAttributeString("Tags", ""); } foreach (string tag in joinedTags.Split(',')) { sp.Tags.Add(tag.Trim().ToLowerInvariant()); } foreach (XElement subElement in element.Elements()) { switch (subElement.Name.ToString()) { case "sprite": sp.sprite = new Sprite(subElement, lazyLoad: true); if (subElement.Attribute("sourcerect") == null) { DebugConsole.ThrowError("Warning - sprite sourcerect not configured for structure \"" + sp.name + "\"!"); } if (subElement.GetAttributeBool("fliphorizontal", false)) { sp.sprite.effects = SpriteEffects.FlipHorizontally; } if (subElement.GetAttributeBool("flipvertical", false)) { sp.sprite.effects = SpriteEffects.FlipVertically; } sp.canSpriteFlipX = subElement.GetAttributeBool("canflipx", true); sp.canSpriteFlipY = subElement.GetAttributeBool("canflipy", true); if (subElement.Attribute("name") == null && !string.IsNullOrWhiteSpace(sp.Name)) { sp.sprite.Name = sp.Name; } sp.sprite.EntityID = sp.identifier; break; case "backgroundsprite": sp.BackgroundSprite = new Sprite(subElement, lazyLoad: true); if (subElement.GetAttributeBool("fliphorizontal", false)) { sp.BackgroundSprite.effects = SpriteEffects.FlipHorizontally; } if (subElement.GetAttributeBool("flipvertical", false)) { sp.BackgroundSprite.effects = SpriteEffects.FlipVertically; } break; } } if (!Enum.TryParse(element.GetAttributeString("category", "Structure"), true, out MapEntityCategory category)) { category = MapEntityCategory.Structure; } sp.Category = category; string aliases = element.GetAttributeString("aliases", ""); if (!string.IsNullOrWhiteSpace(aliases)) { sp.Aliases = aliases.Split(','); } SerializableProperty.DeserializeProperties(sp, element); if (sp.Body) { sp.Tags.Add("wall"); } string translatedDescription = TextManager.Get("EntityDescription." + sp.identifier, true); if (!string.IsNullOrEmpty(translatedDescription)) { sp.Description = translatedDescription; } //backwards compatibility if (element.Attribute("size") == null) { sp.size = Vector2.Zero; if (element.Attribute("width") == null && element.Attribute("height") == null) { sp.size.X = sp.sprite.SourceRect.Width; sp.size.Y = sp.sprite.SourceRect.Height; } else { sp.size.X = element.GetAttributeFloat("width", 0.0f); sp.size.Y = element.GetAttributeFloat("height", 0.0f); } } if (!category.HasFlag(MapEntityCategory.Legacy) && string.IsNullOrEmpty(sp.identifier)) { DebugConsole.ThrowError( "Structure prefab \"" + sp.name + "\" has no identifier. All structure prefabs have a unique identifier string that's used to differentiate between items during saving and loading."); } if (!string.IsNullOrEmpty(sp.identifier)) { MapEntityPrefab existingPrefab = List.Find(e => e.Identifier == sp.identifier); if (existingPrefab != null) { DebugConsole.ThrowError( "Map entity prefabs \"" + sp.name + "\" and \"" + existingPrefab.Name + "\" have the same identifier!"); } } return(sp); }
private void BakeMapEntity(XElement element) { string identifier = element.GetAttributeString("identifier", ""); if (string.IsNullOrEmpty(identifier)) { return; } Rectangle rect = element.GetAttributeRect("rect", Rectangle.Empty); if (rect.Equals(Rectangle.Empty)) { return; } float depth = element.GetAttributeFloat("spritedepth", 1f); bool flippedX = element.GetAttributeBool("flippedx", false); bool flippedY = element.GetAttributeBool("flippedy", false); float scale = element.GetAttributeFloat("scale", 1f); Color color = element.GetAttributeColor("spritecolor", Color.White); float rotation = element.GetAttributeFloat("rotation", 0f); MapEntityPrefab prefab = MapEntityPrefab.List.FirstOrDefault(p => p.Identifier.Equals(identifier, StringComparison.OrdinalIgnoreCase)); if (prefab == null) { return; } var texture = prefab.sprite.Texture; var srcRect = prefab.sprite.SourceRect; SpriteEffects spriteEffects = SpriteEffects.None; if (flippedX) { spriteEffects |= SpriteEffects.FlipHorizontally; } if (flippedY) { spriteEffects |= SpriteEffects.FlipVertically; } var prevEffects = prefab.sprite.effects; prefab.sprite.effects ^= spriteEffects; bool overrideSprite = false; ItemPrefab itemPrefab = prefab as ItemPrefab; StructurePrefab structurePrefab = prefab as StructurePrefab; if (itemPrefab != null) { BakeItemComponents(itemPrefab, rect, color, scale, rotation, depth, out overrideSprite); } if (!overrideSprite) { if (structurePrefab != null) { ParseUpgrades(structurePrefab.ConfigElement, ref scale); if (!prefab.ResizeVertical) { rect.Height = (int)(rect.Height * scale / prefab.Scale); } if (!prefab.ResizeHorizontal) { rect.Width = (int)(rect.Width * scale / prefab.Scale); } var textureScale = element.GetAttributeVector2("texturescale", Vector2.One); Vector2 backGroundOffset = Vector2.Zero; Vector2 textureOffset = element.GetAttributeVector2("textureoffset", Vector2.Zero); if (flippedX) { textureOffset.X = -textureOffset.X; } if (flippedY) { textureOffset.Y = -textureOffset.Y; } backGroundOffset = new Vector2( MathUtils.PositiveModulo((int)-textureOffset.X, prefab.sprite.SourceRect.Width), MathUtils.PositiveModulo((int)-textureOffset.Y, prefab.sprite.SourceRect.Height)); prefab.sprite.DrawTiled( spriteRecorder, rect.Location.ToVector2() * new Vector2(1f, -1f), rect.Size.ToVector2(), color: color, startOffset: backGroundOffset, textureScale: textureScale * scale, depth: depth); } else if (itemPrefab != null) { bool usePrefabValues = element.GetAttributeBool("isoverride", false) != itemPrefab.IsOverride; if (usePrefabValues) { scale = itemPrefab.ConfigElement.GetAttributeFloat(scale, "scale", "Scale"); } ParseUpgrades(itemPrefab.ConfigElement, ref scale); if (prefab.ResizeVertical || prefab.ResizeHorizontal) { if (!prefab.ResizeHorizontal) { rect.Width = (int)(prefab.sprite.size.X * scale); } if (!prefab.ResizeVertical) { rect.Height = (int)(prefab.sprite.size.Y * scale); } var spritePos = rect.Center.ToVector2(); //spritePos.Y = rect.Height - spritePos.Y; prefab.sprite.DrawTiled( spriteRecorder, rect.Location.ToVector2() * new Vector2(1f, -1f), rect.Size.ToVector2(), color: color, textureScale: Vector2.One * scale, depth: depth); foreach (var decorativeSprite in itemPrefab.DecorativeSprites) { float offsetState = 0f; Vector2 offset = decorativeSprite.GetOffset(ref offsetState, Vector2.Zero) * scale; if (flippedX && itemPrefab.CanSpriteFlipX) { offset.X = -offset.X; } if (flippedY && itemPrefab.CanSpriteFlipY) { offset.Y = -offset.Y; } decorativeSprite.Sprite.DrawTiled(spriteRecorder, new Vector2(spritePos.X + offset.X - rect.Width / 2, -(spritePos.Y + offset.Y + rect.Height / 2)), rect.Size.ToVector2(), color: color, textureScale: Vector2.One * scale, depth: Math.Min(depth + (decorativeSprite.Sprite.Depth - prefab.sprite.Depth), 0.999f)); } } else { rect.Width = (int)(rect.Width * scale / prefab.Scale); rect.Height = (int)(rect.Height * scale / prefab.Scale); var spritePos = rect.Center.ToVector2(); spritePos.Y -= rect.Height; //spritePos.Y = rect.Height - spritePos.Y; prefab.sprite.Draw( spriteRecorder, spritePos * new Vector2(1f, -1f), color, prefab.sprite.Origin, rotation, scale, prefab.sprite.effects, depth); foreach (var decorativeSprite in itemPrefab.DecorativeSprites) { float rotationState = 0f; float offsetState = 0f; float rot = decorativeSprite.GetRotation(ref rotationState, 0f); Vector2 offset = decorativeSprite.GetOffset(ref offsetState, Vector2.Zero) * scale; if (flippedX && itemPrefab.CanSpriteFlipX) { offset.X = -offset.X; } if (flippedY && itemPrefab.CanSpriteFlipY) { offset.Y = -offset.Y; } decorativeSprite.Sprite.Draw(spriteRecorder, new Vector2(spritePos.X + offset.X, -(spritePos.Y + offset.Y)), color, MathHelper.ToRadians(rotation) + rot, decorativeSprite.GetScale(0f) * scale, prefab.sprite.effects, depth: Math.Min(depth + (decorativeSprite.Sprite.Depth - prefab.sprite.Depth), 0.999f)); } } } } prefab.sprite.effects = prevEffects; }
private IEnumerable <object> Load() { if (GameSettings.VerboseLogging) { DebugConsole.NewMessage("LOADING COROUTINE", Color.Lime); } SoundManager = new Sounds.SoundManager(); SoundManager.SetCategoryGainMultiplier("default", Config.SoundVolume); SoundManager.SetCategoryGainMultiplier("ui", Config.SoundVolume); SoundManager.SetCategoryGainMultiplier("waterambience", Config.SoundVolume); SoundManager.SetCategoryGainMultiplier("music", Config.MusicVolume); GUI.Init(Window, Config.SelectedContentPackages, GraphicsDevice); DebugConsole.Init(); SteamManager.Initialize(); if (SelectedPackages.Count == 0) { DebugConsole.Log("No content packages selected"); } else { DebugConsole.Log("Selected content packages: " + string.Join(", ", SelectedPackages.Select(cp => cp.Name))); } InitUserStats(); yield return(CoroutineStatus.Running); LightManager = new Lights.LightManager(base.GraphicsDevice, Content); WaterRenderer.Instance = new WaterRenderer(base.GraphicsDevice, Content); TitleScreen.LoadState = 1.0f; yield return(CoroutineStatus.Running); GUI.LoadContent(); TitleScreen.LoadState = 2.0f; yield return(CoroutineStatus.Running); MissionPrefab.Init(); MapEntityPrefab.Init(); Tutorials.Tutorial.Init(); MapGenerationParams.Init(); LevelGenerationParams.LoadPresets(); ScriptedEventSet.LoadPrefabs(); AfflictionPrefab.LoadAll(GetFilesOfType(ContentType.Afflictions)); TitleScreen.LoadState = 10.0f; yield return(CoroutineStatus.Running); StructurePrefab.LoadAll(GetFilesOfType(ContentType.Structure)); TitleScreen.LoadState = 15.0f; yield return(CoroutineStatus.Running); ItemPrefab.LoadAll(GetFilesOfType(ContentType.Item)); TitleScreen.LoadState = 30.0f; yield return(CoroutineStatus.Running); JobPrefab.LoadAll(GetFilesOfType(ContentType.Jobs)); // Add any missing jobs from the prefab into Config.JobNamePreferences. foreach (JobPrefab job in JobPrefab.List) { if (!Config.JobPreferences.Contains(job.Identifier)) { Config.JobPreferences.Add(job.Identifier); } } NPCConversation.LoadAll(GetFilesOfType(ContentType.NPCConversations)); ItemAssemblyPrefab.LoadAll(); TitleScreen.LoadState = 35.0f; yield return(CoroutineStatus.Running); Debug.WriteLine("sounds"); CoroutineManager.StartCoroutine(SoundPlayer.Init()); int i = 0; while (!SoundPlayer.Initialized) { i++; TitleScreen.LoadState = SoundPlayer.SoundCount == 0 ? 30.0f : Math.Min(30.0f + 40.0f * i / Math.Max(SoundPlayer.SoundCount, 1), 70.0f); yield return(CoroutineStatus.Running); } TitleScreen.LoadState = 70.0f; yield return(CoroutineStatus.Running); GameModePreset.Init(); Submarine.RefreshSavedSubs(); TitleScreen.LoadState = 80.0f; yield return(CoroutineStatus.Running); GameScreen = new GameScreen(GraphicsDeviceManager.GraphicsDevice, Content); TitleScreen.LoadState = 90.0f; yield return(CoroutineStatus.Running); MainMenuScreen = new MainMenuScreen(this); LobbyScreen = new LobbyScreen(); ServerListScreen = new ServerListScreen(); if (SteamManager.USE_STEAM) { SteamWorkshopScreen = new SteamWorkshopScreen(); } SubEditorScreen = new SubEditorScreen(); ParticleEditorScreen = new ParticleEditorScreen(); LevelEditorScreen = new LevelEditorScreen(); SpriteEditorScreen = new SpriteEditorScreen(); CharacterEditorScreen = new CharacterEditorScreen(); yield return(CoroutineStatus.Running); ParticleManager = new ParticleManager(GameScreen.Cam); ParticleManager.LoadPrefabs(); LevelObjectPrefab.LoadAll(); DecalManager = new DecalManager(); yield return(CoroutineStatus.Running); LocationType.Init(); MainMenuScreen.Select(); TitleScreen.LoadState = 100.0f; hasLoaded = true; if (GameSettings.VerboseLogging) { DebugConsole.NewMessage("LOADING COROUTINE FINISHED", Color.Lime); } yield return(CoroutineStatus.Success); }
public Structure(Rectangle rectangle, StructurePrefab sp, Submarine submarine) : base(sp, submarine) { if (rectangle.Width == 0 || rectangle.Height == 0) { return; } System.Diagnostics.Debug.Assert(rectangle.Width > 0 && rectangle.Height > 0); rect = rectangle; #if CLIENT TextureScale = sp.TextureScale; #endif spriteColor = prefab.SpriteColor; if (ResizeHorizontal && !ResizeVertical) { IsHorizontal = true; } else if (ResizeVertical && !ResizeHorizontal) { IsHorizontal = false; } else { if (BodyWidth > 0.0f && BodyHeight > 0.0f) { IsHorizontal = BodyWidth > BodyHeight; } else { IsHorizontal = (rect.Width > rect.Height); } } StairDirection = Prefab.StairDirection; SerializableProperties = SerializableProperty.GetProperties(this); InitProjSpecific(); if (Prefab.Body) { Bodies = new List <Body>(); WallList.Add(this); CreateSections(); UpdateSections(); } else { Sections = new WallSection[1]; Sections[0] = new WallSection(rect); if (StairDirection != Direction.None) { CreateStairBodies(); } } // Only add ai targets automatically to walls if (aiTarget == null && HasBody && Tags.Contains("wall")) { aiTarget = new AITarget(this); } InsertToList(); }
public static List <MapEntity> LoadAll(Submarine submarine, XElement parentElement, string filePath, int idOffset) { IdRemap idRemap = new IdRemap(parentElement, idOffset); List <MapEntity> entities = new List <MapEntity>(); foreach (XElement element in parentElement.Elements()) { string typeName = element.Name.ToString(); Type t; try { t = Type.GetType("Barotrauma." + typeName, true, true); if (t == null) { DebugConsole.ThrowError("Error in " + filePath + "! Could not find a entity of the type \"" + typeName + "\"."); continue; } } catch (Exception e) { DebugConsole.ThrowError("Error in " + filePath + "! Could not find a entity of the type \"" + typeName + "\".", e); continue; } if (t == typeof(Structure)) { string name = element.Attribute("name").Value; string identifier = element.GetAttributeString("identifier", ""); StructurePrefab structurePrefab = Structure.FindPrefab(name, identifier); if (structurePrefab == null) { ItemPrefab itemPrefab = ItemPrefab.Find(name, identifier); if (itemPrefab != null) { t = typeof(Item); } } } try { MethodInfo loadMethod = t.GetMethod("Load", new[] { typeof(XElement), typeof(Submarine), typeof(IdRemap) }); if (loadMethod == null) { DebugConsole.ThrowError("Could not find the method \"Load\" in " + t + "."); } else if (!loadMethod.ReturnType.IsSubclassOf(typeof(MapEntity))) { DebugConsole.ThrowError("Error loading entity of the type \"" + t.ToString() + "\" - load method does not return a valid map entity."); } else { object newEntity = loadMethod.Invoke(t, new object[] { element, submarine, idRemap }); if (newEntity != null) { entities.Add((MapEntity)newEntity); } } } catch (TargetInvocationException e) { DebugConsole.ThrowError("Error while loading entity of the type " + t + ".", e.InnerException); } catch (Exception e) { DebugConsole.ThrowError("Error while loading entity of the type " + t + ".", e); } } return(entities); }
public static StructurePrefab Load(XElement element) { StructurePrefab sp = new StructurePrefab(); sp.name = element.Name.ToString(); sp.Tags = new List <string>(); sp.Tags.AddRange(element.GetAttributeString("tags", "").Split(',')); foreach (XElement subElement in element.Elements()) { switch (subElement.Name.ToString()) { case "sprite": sp.sprite = new Sprite(subElement); if (subElement.GetAttributeBool("fliphorizontal", false)) { sp.sprite.effects = SpriteEffects.FlipHorizontally; } if (subElement.GetAttributeBool("flipvertical", false)) { sp.sprite.effects = SpriteEffects.FlipVertically; } sp.canSpriteFlipX = subElement.GetAttributeBool("canflipx", true); break; case "backgroundsprite": sp.BackgroundSprite = new Sprite(subElement); if (subElement.GetAttributeBool("fliphorizontal", false)) { sp.BackgroundSprite.effects = SpriteEffects.FlipHorizontally; } if (subElement.GetAttributeBool("flipvertical", false)) { sp.BackgroundSprite.effects = SpriteEffects.FlipVertically; } break; } } MapEntityCategory category; if (!Enum.TryParse(element.GetAttributeString("category", "Structure"), true, out category)) { category = MapEntityCategory.Structure; } sp.Category = category; string aliases = element.GetAttributeString("aliases", ""); if (!string.IsNullOrWhiteSpace(aliases)) { sp.Aliases = aliases.Split(','); } SerializableProperty.DeserializeProperties(sp, element); //backwards compatibility if (element.Attribute("size") == null) { sp.size = Vector2.Zero; sp.size.X = element.GetAttributeFloat("width", 0.0f); sp.size.Y = element.GetAttributeFloat("height", 0.0f); } return(sp); }
private IEnumerable <object> Load(bool isSeparateThread) { if (GameSettings.VerboseLogging) { DebugConsole.NewMessage("LOADING COROUTINE", Color.Lime); } while (TitleScreen.WaitForLanguageSelection) { yield return(CoroutineStatus.Running); } SoundManager = new Sounds.SoundManager(); SoundManager.SetCategoryGainMultiplier("default", Config.SoundVolume, 0); SoundManager.SetCategoryGainMultiplier("ui", Config.SoundVolume, 0); SoundManager.SetCategoryGainMultiplier("waterambience", Config.SoundVolume, 0); SoundManager.SetCategoryGainMultiplier("music", Config.MusicVolume, 0); SoundManager.SetCategoryGainMultiplier("voip", Config.VoiceChatVolume * 20.0f, 0); if (ConsoleArguments.Contains("-skipintro")) { Config.EnableSplashScreen = false; } if (Config.EnableSplashScreen) { var pendingSplashScreens = TitleScreen.PendingSplashScreens; float baseVolume = MathHelper.Clamp(Config.SoundVolume * 2.0f, 0.0f, 1.0f); pendingSplashScreens?.Enqueue(new Triplet <string, Point, float>("Content/Splash_UTG.mp4", new Point(1280, 720), baseVolume * 0.5f)); pendingSplashScreens?.Enqueue(new Triplet <string, Point, float>("Content/Splash_FF.mp4", new Point(1280, 720), baseVolume)); pendingSplashScreens?.Enqueue(new Triplet <string, Point, float>("Content/Splash_Daedalic.mp4", new Point(1920, 1080), baseVolume * 0.15f)); } //if not loading in a separate thread, wait for the splash screens to finish before continuing the loading //otherwise the videos will look extremely choppy if (!isSeparateThread) { while (TitleScreen.PlayingSplashScreen || TitleScreen.PendingSplashScreens.Count > 0) { yield return(CoroutineStatus.Running); } } GUI.Init(Window, Config.SelectedContentPackages, GraphicsDevice); DebugConsole.Init(); CrossThread.RequestExecutionOnMainThread(() => { if (Config.AutoUpdateWorkshopItems) { if (SteamManager.AutoUpdateWorkshopItems()) { ContentPackage.LoadAll(); Config.ReloadContentPackages(); } } }); if (SelectedPackages.None()) { DebugConsole.Log("No content packages selected"); } else { DebugConsole.Log("Selected content packages: " + string.Join(", ", SelectedPackages.Select(cp => cp.Name))); } #if DEBUG GameSettings.ShowUserStatisticsPrompt = false; GameSettings.SendUserStatistics = false; #endif InitUserStats(); yield return(CoroutineStatus.Running); Debug.WriteLine("sounds"); int i = 0; foreach (object crObj in SoundPlayer.Init()) { CoroutineStatus status = (CoroutineStatus)crObj; if (status == CoroutineStatus.Success) { break; } i++; TitleScreen.LoadState = SoundPlayer.SoundCount == 0 ? 1.0f : Math.Min(40.0f * i / Math.Max(SoundPlayer.SoundCount, 1), 40.0f); yield return(CoroutineStatus.Running); } TitleScreen.LoadState = 40.0f; yield return(CoroutineStatus.Running); LightManager = new Lights.LightManager(base.GraphicsDevice, Content); TitleScreen.LoadState = 41.0f; yield return(CoroutineStatus.Running); GUI.LoadContent(); TitleScreen.LoadState = 42.0f; yield return(CoroutineStatus.Running); Character.LoadAllConfigFiles(); MissionPrefab.Init(); TraitorMissionPrefab.Init(); MapEntityPrefab.Init(); Tutorials.Tutorial.Init(); MapGenerationParams.Init(); LevelGenerationParams.LoadPresets(); ScriptedEventSet.LoadPrefabs(); AfflictionPrefab.LoadAll(GetFilesOfType(ContentType.Afflictions)); TitleScreen.LoadState = 50.0f; yield return(CoroutineStatus.Running); StructurePrefab.LoadAll(GetFilesOfType(ContentType.Structure)); TitleScreen.LoadState = 53.0f; yield return(CoroutineStatus.Running); ItemPrefab.LoadAll(GetFilesOfType(ContentType.Item)); TitleScreen.LoadState = 55.0f; yield return(CoroutineStatus.Running); JobPrefab.LoadAll(GetFilesOfType(ContentType.Jobs)); NPCConversation.LoadAll(GetFilesOfType(ContentType.NPCConversations)); ItemAssemblyPrefab.LoadAll(); TitleScreen.LoadState = 60.0f; yield return(CoroutineStatus.Running); GameModePreset.Init(); Submarine.RefreshSavedSubs(); TitleScreen.LoadState = 65.0f; yield return(CoroutineStatus.Running); GameScreen = new GameScreen(GraphicsDeviceManager.GraphicsDevice, Content); TitleScreen.LoadState = 68.0f; yield return(CoroutineStatus.Running); MainMenuScreen = new MainMenuScreen(this); LobbyScreen = new LobbyScreen(); ServerListScreen = new ServerListScreen(); TitleScreen.LoadState = 70.0f; yield return(CoroutineStatus.Running); if (SteamManager.USE_STEAM) { SteamWorkshopScreen = new SteamWorkshopScreen(); if (SteamManager.IsInitialized) { SteamManager.Instance.Friends.OnInvitedToGame += OnInvitedToGame; SteamManager.Instance.Lobby.OnLobbyJoinRequested += OnLobbyJoinRequested; } } SubEditorScreen = new SubEditorScreen(); TitleScreen.LoadState = 75.0f; yield return(CoroutineStatus.Running); ParticleEditorScreen = new ParticleEditorScreen(); TitleScreen.LoadState = 80.0f; yield return(CoroutineStatus.Running); LevelEditorScreen = new LevelEditorScreen(); SpriteEditorScreen = new SpriteEditorScreen(); CharacterEditorScreen = new CharacterEditor.CharacterEditorScreen(); yield return(CoroutineStatus.Running); TitleScreen.LoadState = 85.0f; ParticleManager = new ParticleManager(GameScreen.Cam); ParticleManager.LoadPrefabs(); TitleScreen.LoadState = 88.0f; LevelObjectPrefab.LoadAll(); TitleScreen.LoadState = 90.0f; yield return(CoroutineStatus.Running); DecalManager = new DecalManager(); LocationType.Init(); MainMenuScreen.Select(); CheckContentPackage(); foreach (string steamError in SteamManager.InitializationErrors) { new GUIMessageBox(TextManager.Get("Error"), TextManager.Get(steamError)); } TitleScreen.LoadState = 100.0f; hasLoaded = true; if (GameSettings.VerboseLogging) { DebugConsole.NewMessage("LOADING COROUTINE FINISHED", Color.Lime); } yield return(CoroutineStatus.Success); }
private static StructurePrefab Load(XElement element, bool allowOverride, ContentFile file) { StructurePrefab sp = new StructurePrefab { originalName = element.GetAttributeString("name", ""), FilePath = file.Path, ContentPackage = file.ContentPackage }; sp.name = sp.originalName; sp.ConfigElement = element; sp.identifier = element.GetAttributeString("identifier", ""); var parentType = element.Parent?.GetAttributeString("prefabtype", "") ?? string.Empty; string nameIdentifier = element.GetAttributeString("nameidentifier", ""); if (string.IsNullOrEmpty(sp.originalName)) { if (string.IsNullOrEmpty(nameIdentifier)) { sp.name = TextManager.Get("EntityName." + sp.identifier, true) ?? string.Empty; } else { sp.name = TextManager.Get("EntityName." + nameIdentifier, true) ?? string.Empty; } } if (string.IsNullOrEmpty(sp.name)) { sp.name = TextManager.Get("EntityName." + sp.identifier, returnNull: true) ?? $"Not defined ({sp.identifier})"; } sp.Tags = new HashSet <string>(); string joinedTags = element.GetAttributeString("tags", ""); if (string.IsNullOrEmpty(joinedTags)) { joinedTags = element.GetAttributeString("Tags", ""); } foreach (string tag in joinedTags.Split(',')) { sp.Tags.Add(tag.Trim().ToLowerInvariant()); } if (element.Attribute("ishorizontal") != null) { sp.IsHorizontal = element.GetAttributeBool("ishorizontal", false); } foreach (XElement subElement in element.Elements()) { switch (subElement.Name.ToString()) { case "sprite": sp.sprite = new Sprite(subElement, lazyLoad: true); if (subElement.Attribute("sourcerect") == null) { DebugConsole.ThrowError("Warning - sprite sourcerect not configured for structure \"" + sp.name + "\"!"); } #if CLIENT if (subElement.GetAttributeBool("fliphorizontal", false)) { sp.sprite.effects = SpriteEffects.FlipHorizontally; } if (subElement.GetAttributeBool("flipvertical", false)) { sp.sprite.effects = SpriteEffects.FlipVertically; } #endif sp.canSpriteFlipX = subElement.GetAttributeBool("canflipx", true); sp.canSpriteFlipY = subElement.GetAttributeBool("canflipy", true); if (subElement.Attribute("name") == null && !string.IsNullOrWhiteSpace(sp.Name)) { sp.sprite.Name = sp.Name; } sp.sprite.EntityID = sp.identifier; break; case "backgroundsprite": sp.BackgroundSprite = new Sprite(subElement, lazyLoad: true); if (subElement.Attribute("sourcerect") == null && sp.sprite != null) { sp.BackgroundSprite.SourceRect = sp.sprite.SourceRect; sp.BackgroundSprite.size = sp.sprite.size; sp.BackgroundSprite.size.X *= sp.sprite.SourceRect.Width; sp.BackgroundSprite.size.Y *= sp.sprite.SourceRect.Height; sp.BackgroundSprite.RelativeOrigin = subElement.GetAttributeVector2("origin", new Vector2(0.5f, 0.5f)); } #if CLIENT if (subElement.GetAttributeBool("fliphorizontal", false)) { sp.BackgroundSprite.effects = SpriteEffects.FlipHorizontally; } if (subElement.GetAttributeBool("flipvertical", false)) { sp.BackgroundSprite.effects = SpriteEffects.FlipVertically; } sp.BackgroundSpriteColor = subElement.GetAttributeColor("color", Color.White); #endif break; case "decorativesprite": #if CLIENT string decorativeSpriteFolder = ""; if (!subElement.GetAttributeString("texture", "").Contains("/")) { decorativeSpriteFolder = Path.GetDirectoryName(file.Path); } int groupID = 0; DecorativeSprite decorativeSprite = null; if (subElement.Attribute("texture") == null) { groupID = subElement.GetAttributeInt("randomgroupid", 0); } else { decorativeSprite = new DecorativeSprite(subElement, decorativeSpriteFolder, lazyLoad: true); sp.DecorativeSprites.Add(decorativeSprite); groupID = decorativeSprite.RandomGroupID; } if (!sp.DecorativeSpriteGroups.ContainsKey(groupID)) { sp.DecorativeSpriteGroups.Add(groupID, new List <DecorativeSprite>()); } sp.DecorativeSpriteGroups[groupID].Add(decorativeSprite); #endif break; } } if (string.Equals(parentType, "wrecked", StringComparison.OrdinalIgnoreCase)) { if (!string.IsNullOrEmpty(sp.Name)) { sp.name = TextManager.GetWithVariable("wreckeditemformat", "[name]", sp.name); } } if (!Enum.TryParse(element.GetAttributeString("category", "Structure"), true, out MapEntityCategory category)) { category = MapEntityCategory.Structure; } sp.Category = category; if (category.HasFlag(MapEntityCategory.Legacy)) { if (string.IsNullOrWhiteSpace(sp.identifier)) { sp.identifier = "legacystructure_" + sp.name.ToLowerInvariant().Replace(" ", ""); } } sp.Aliases = (element.GetAttributeStringArray("aliases", null) ?? element.GetAttributeStringArray("Aliases", new string[0])).ToHashSet(); string nonTranslatedName = element.GetAttributeString("name", null) ?? element.Name.ToString(); sp.Aliases.Add(nonTranslatedName.ToLowerInvariant()); SerializableProperty.DeserializeProperties(sp, element); if (sp.Body) { sp.Tags.Add("wall"); } if (string.IsNullOrEmpty(sp.Description)) { if (string.IsNullOrEmpty(nameIdentifier)) { sp.Description = TextManager.Get("EntityDescription." + sp.identifier, returnNull: true) ?? string.Empty; } else { sp.Description = TextManager.Get("EntityDescription." + nameIdentifier, true) ?? string.Empty; } } //backwards compatibility if (element.Attribute("size") == null) { sp.size = Vector2.Zero; if (element.Attribute("width") == null && element.Attribute("height") == null) { sp.size.X = sp.sprite.SourceRect.Width; sp.size.Y = sp.sprite.SourceRect.Height; } else { sp.size.X = element.GetAttributeFloat("width", 0.0f); sp.size.Y = element.GetAttributeFloat("height", 0.0f); } } if (string.IsNullOrEmpty(sp.identifier)) { DebugConsole.ThrowError( "Structure prefab \"" + sp.name + "\" has no identifier. All structure prefabs have a unique identifier string that's used to differentiate between items during saving and loading."); } Prefabs.Add(sp, allowOverride); return(sp); }