1 #region Copyright & License Information
2 /*
3  * Copyright 2007-2020 The OpenRA Developers (see AUTHORS)
4  * This file is part of OpenRA, which is free software. It is made
5  * available to you under the terms of the GNU General Public License
6  * as published by the Free Software Foundation, either version 3 of
7  * the License, or (at your option) any later version. For more
8  * information, see COPYING.
9  */
10 #endregion
11 
12 using System;
13 using System.Collections.Generic;
14 using System.IO;
15 using System.Linq;
16 using OpenRA.FileFormats;
17 using OpenRA.Mods.Common.Widgets.Logic;
18 using OpenRA.Widgets;
19 
20 namespace OpenRA.Mods.Common.LoadScreens
21 {
22 	public class BlankLoadScreen : ILoadScreen
23 	{
24 		public LaunchArguments Launch;
25 		protected ModData ModData { get; private set; }
26 
Init(ModData modData, Dictionary<string, string> info)27 		public virtual void Init(ModData modData, Dictionary<string, string> info)
28 		{
29 			ModData = modData;
30 		}
31 
Display()32 		public virtual void Display()
33 		{
34 			if (Game.Renderer == null)
35 				return;
36 
37 			// Draw a black screen
38 			Game.Renderer.BeginUI();
39 			Game.Renderer.EndFrame(new NullInputHandler());
40 		}
41 
StartGame(Arguments args)42 		public virtual void StartGame(Arguments args)
43 		{
44 			Launch = new LaunchArguments(args);
45 			Ui.ResetAll();
46 			Game.Settings.Save();
47 
48 			if (!string.IsNullOrEmpty(Launch.Benchmark))
49 			{
50 				Console.WriteLine("Saving benchmark data into {0}".F(Path.Combine(Platform.SupportDir, "Logs")));
51 
52 				Game.BenchmarkMode(Launch.Benchmark);
53 			}
54 
55 			// Join a server directly
56 			var connect = Launch.GetConnectAddress();
57 			if (!string.IsNullOrEmpty(connect))
58 			{
59 				var parts = connect.Split(':');
60 
61 				if (parts.Length == 2)
62 				{
63 					var host = parts[0];
64 					var port = Exts.ParseIntegerInvariant(parts[1]);
65 					Game.LoadShellMap();
66 					Game.RemoteDirectConnect(host, port);
67 					return;
68 				}
69 			}
70 
71 			// Start a map directly
72 			if (!string.IsNullOrEmpty(Launch.Map))
73 			{
74 				Game.LoadMap(Launch.Map);
75 				return;
76 			}
77 
78 			// Load a replay directly
79 			if (!string.IsNullOrEmpty(Launch.Replay))
80 			{
81 				ReplayMetadata replayMeta = null;
82 				try
83 				{
84 					replayMeta = ReplayMetadata.Read(Launch.Replay);
85 				}
86 				catch { }
87 
88 				if (ReplayUtils.PromptConfirmReplayCompatibility(replayMeta, Game.LoadShellMap))
89 					Game.JoinReplay(Launch.Replay);
90 
91 				if (replayMeta != null)
92 				{
93 					var mod = replayMeta.GameInfo.Mod;
94 					if (mod != null && mod != Game.ModData.Manifest.Id && Game.Mods.ContainsKey(mod))
95 						Game.InitializeMod(mod, args);
96 				}
97 
98 				return;
99 			}
100 
101 			Game.LoadShellMap();
102 			Game.Settings.Save();
103 		}
104 
Dispose(bool disposing)105 		protected virtual void Dispose(bool disposing) { }
106 
Dispose()107 		public void Dispose()
108 		{
109 			Dispose(true);
110 			GC.SuppressFinalize(this);
111 		}
112 
BeforeLoad()113 		public virtual bool BeforeLoad()
114 		{
115 			// Reset the UI scaling if the user has configured a UI scale that pushes us below the minimum allowed effective resolution
116 			var minResolution = ModData.Manifest.Get<WorldViewportSizes>().MinEffectiveResolution;
117 			var resolution = Game.Renderer.Resolution;
118 			if ((resolution.Width < minResolution.Width || resolution.Height < minResolution.Height) && Game.Settings.Graphics.UIScale > 1.0f)
119 			{
120 				Game.Settings.Graphics.UIScale = 1.0f;
121 				Game.Renderer.SetUIScale(1.0f);
122 			}
123 
124 			// Saved settings may have been invalidated by a hardware change
125 			Game.Settings.Graphics.GLProfile = Game.Renderer.GLProfile;
126 			Game.Settings.Graphics.VideoDisplay = Game.Renderer.CurrentDisplay;
127 
128 			// If a ModContent section is defined then we need to make sure that the
129 			// required content is installed or switch to the defined content installer.
130 			if (!ModData.Manifest.Contains<ModContent>())
131 				return true;
132 
133 			var content = ModData.Manifest.Get<ModContent>();
134 			var contentInstalled = content.Packages
135 				.Where(p => p.Value.Required)
136 				.All(p => p.Value.TestFiles.All(f => File.Exists(Platform.ResolvePath(f))));
137 
138 			if (contentInstalled)
139 				return true;
140 
141 			Game.InitializeMod(content.ContentInstallerMod, new Arguments(new[] { "Content.Mod=" + ModData.Manifest.Id }));
142 			return false;
143 		}
144 	}
145 }
146