Load custom settings from settings.ini (reading from commandline currently doesn't work)
This commit is contained in:
@@ -9,9 +9,8 @@ namespace OpenRa.FileFormats
|
|||||||
static List<IFolder> mountedFolders = new List<IFolder>();
|
static List<IFolder> mountedFolders = new List<IFolder>();
|
||||||
static List<IFolder> temporaryMounts = new List<IFolder>();
|
static List<IFolder> temporaryMounts = new List<IFolder>();
|
||||||
|
|
||||||
public static void MountDefault( bool useAftermath )
|
public static void MountDefaultPackages()
|
||||||
{
|
{
|
||||||
FileSystem.Mount( new Folder( "./" ) );
|
|
||||||
if( File.Exists( "main.mix" ) )
|
if( File.Exists( "main.mix" ) )
|
||||||
FileSystem.Mount( new Package( "main.mix" ) );
|
FileSystem.Mount( new Package( "main.mix" ) );
|
||||||
FileSystem.Mount( new Package( "redalert.mix" ) );
|
FileSystem.Mount( new Package( "redalert.mix" ) );
|
||||||
@@ -23,11 +22,12 @@ namespace OpenRa.FileFormats
|
|||||||
FileSystem.Mount( new Package( "speech.mix" ) );
|
FileSystem.Mount( new Package( "speech.mix" ) );
|
||||||
FileSystem.Mount( new Package( "allies.mix" ) );
|
FileSystem.Mount( new Package( "allies.mix" ) );
|
||||||
FileSystem.Mount( new Package( "russian.mix" ) );
|
FileSystem.Mount( new Package( "russian.mix" ) );
|
||||||
if( useAftermath )
|
}
|
||||||
{
|
|
||||||
FileSystem.Mount( new Package( "expand2.mix" ) );
|
public static void MountAftermathPackages()
|
||||||
FileSystem.Mount( new Package( "hires1.mix" ) );
|
{
|
||||||
}
|
FileSystem.Mount( new Package( "expand2.mix" ) );
|
||||||
|
FileSystem.Mount( new Package( "hires1.mix" ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Mount(IFolder folder)
|
public static void Mount(IFolder folder)
|
||||||
|
|||||||
@@ -22,7 +22,8 @@ namespace OpenRa.Game
|
|||||||
public static WorldRenderer worldRenderer;
|
public static WorldRenderer worldRenderer;
|
||||||
public static Controller controller;
|
public static Controller controller;
|
||||||
public static Chrome chrome;
|
public static Chrome chrome;
|
||||||
|
public static UserSettings Settings;
|
||||||
|
|
||||||
public static OrderManager orderManager;
|
public static OrderManager orderManager;
|
||||||
|
|
||||||
static int localPlayerIndex;
|
static int localPlayerIndex;
|
||||||
@@ -41,11 +42,6 @@ namespace OpenRa.Game
|
|||||||
public static BuildingInfluenceMap BuildingInfluence;
|
public static BuildingInfluenceMap BuildingInfluence;
|
||||||
public static UnitInfluenceMap UnitInfluence;
|
public static UnitInfluenceMap UnitInfluence;
|
||||||
|
|
||||||
public static string Replay;
|
|
||||||
|
|
||||||
public static string NetworkHost;
|
|
||||||
public static int NetworkPort;
|
|
||||||
|
|
||||||
public static bool skipMakeAnims = true;
|
public static bool skipMakeAnims = true;
|
||||||
|
|
||||||
static Renderer renderer;
|
static Renderer renderer;
|
||||||
@@ -121,13 +117,13 @@ namespace OpenRa.Game
|
|||||||
|
|
||||||
ChangeMap(mapName);
|
ChangeMap(mapName);
|
||||||
|
|
||||||
if (Replay != "")
|
if (Settings.Replay != "")
|
||||||
orderManager = new OrderManager(new IOrderSource[] { new ReplayOrderSource(Replay) });
|
orderManager = new OrderManager(new IOrderSource[] { new ReplayOrderSource(Settings.Replay) });
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var orderSources = (string.IsNullOrEmpty(NetworkHost))
|
var orderSources = (string.IsNullOrEmpty(Settings.NetworkHost))
|
||||||
? new IOrderSource[] { new LocalOrderSource() }
|
? new IOrderSource[] { new LocalOrderSource() }
|
||||||
: new IOrderSource[] { new LocalOrderSource(), new NetworkOrderSource(new TcpClient(NetworkHost, NetworkPort)) };
|
: new IOrderSource[] { new LocalOrderSource(), new NetworkOrderSource(new TcpClient(Settings.NetworkHost, Settings.NetworkPort)) };
|
||||||
orderManager = new OrderManager(orderSources, "replay.rep");
|
orderManager = new OrderManager(orderSources, "replay.rep");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -149,7 +145,6 @@ namespace OpenRa.Game
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int lastTime = Environment.TickCount;
|
static int lastTime = Environment.TickCount;
|
||||||
public static int timestep = 40;
|
|
||||||
|
|
||||||
public static void ResetTimer()
|
public static void ResetTimer()
|
||||||
{
|
{
|
||||||
@@ -166,11 +161,11 @@ namespace OpenRa.Game
|
|||||||
{
|
{
|
||||||
int t = Environment.TickCount;
|
int t = Environment.TickCount;
|
||||||
int dt = t - lastTime;
|
int dt = t - lastTime;
|
||||||
if (dt >= timestep)
|
if (dt >= Settings.Timestep)
|
||||||
{
|
{
|
||||||
using (new PerfSample("tick_time"))
|
using (new PerfSample("tick_time"))
|
||||||
{
|
{
|
||||||
lastTime += timestep;
|
lastTime += Settings.Timestep;
|
||||||
UpdatePalette(world.Actors.SelectMany(
|
UpdatePalette(world.Actors.SelectMany(
|
||||||
a => a.traits.WithInterface<IPaletteModifier>()));
|
a => a.traits.WithInterface<IPaletteModifier>()));
|
||||||
orderManager.TickImmediate();
|
orderManager.TickImmediate();
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ namespace OpenRa.Game.GameRules
|
|||||||
{
|
{
|
||||||
foreach( var x in ini )
|
foreach( var x in ini )
|
||||||
{
|
{
|
||||||
var field = self.GetType().GetField( x.Key );
|
var field = self.GetType().GetField( x.Key.Trim() );
|
||||||
field.SetValue( self, GetValue( field.FieldType, x.Value ) );
|
field.SetValue( self, GetValue( field.FieldType, x.Value.Trim() ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ using System.Windows.Forms;
|
|||||||
using OpenRa.FileFormats;
|
using OpenRa.FileFormats;
|
||||||
using OpenRa.Game.Graphics;
|
using OpenRa.Game.Graphics;
|
||||||
using OpenRa.Game.Orders;
|
using OpenRa.Game.Orders;
|
||||||
|
using OpenRa.Game.GameRules;
|
||||||
|
|
||||||
|
|
||||||
namespace OpenRa.Game
|
namespace OpenRa.Game
|
||||||
{
|
{
|
||||||
@@ -16,34 +18,44 @@ namespace OpenRa.Game
|
|||||||
static Size GetResolution(Settings settings)
|
static Size GetResolution(Settings settings)
|
||||||
{
|
{
|
||||||
var desktopResolution = Screen.PrimaryScreen.Bounds.Size;
|
var desktopResolution = Screen.PrimaryScreen.Bounds.Size;
|
||||||
|
if (Game.Settings.Width > 0 && Game.Settings.Height > 0)
|
||||||
|
{
|
||||||
|
desktopResolution.Width = Game.Settings.Width;
|
||||||
|
desktopResolution.Height = Game.Settings.Height;
|
||||||
|
}
|
||||||
return new Size(
|
return new Size(
|
||||||
settings.GetValue("width", desktopResolution.Width),
|
desktopResolution.Width,
|
||||||
settings.GetValue("height", desktopResolution.Height));
|
desktopResolution.Height);
|
||||||
}
|
}
|
||||||
|
|
||||||
[DllImport("user32")]
|
[DllImport("user32")]
|
||||||
static extern int ShowCursor([MarshalAs(UnmanagedType.Bool)] bool visible);
|
static extern int ShowCursor([MarshalAs(UnmanagedType.Bool)] bool visible);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public MainWindow(Settings settings)
|
public MainWindow(Settings settings)
|
||||||
{
|
{
|
||||||
|
FileSystem.Mount(new Folder("./"));
|
||||||
|
|
||||||
FormBorderStyle = FormBorderStyle.None;
|
FormBorderStyle = FormBorderStyle.None;
|
||||||
BackColor = Color.Black;
|
BackColor = Color.Black;
|
||||||
StartPosition = FormStartPosition.Manual;
|
StartPosition = FormStartPosition.Manual;
|
||||||
Location = Point.Empty;
|
Location = Point.Empty;
|
||||||
Visible = true;
|
Visible = true;
|
||||||
|
|
||||||
UiOverlay.ShowUnitDebug = settings.GetValue("udebug", false);
|
// Load user settings
|
||||||
UiOverlay.ShowBuildDebug = settings.GetValue("bdebug", false);
|
Game.Settings = new UserSettings();
|
||||||
WorldRenderer.ShowUnitPaths = settings.GetValue("pathdebug", false);
|
try
|
||||||
Game.timestep = settings.GetValue("rate", 40);
|
{
|
||||||
Game.Replay = settings.GetValue("replay", "");
|
IniFile SettingsRules = new IniFile(FileSystem.Open("settings.ini"));
|
||||||
Game.NetworkHost = settings.GetValue("host", "");
|
FieldLoader.Load(Game.Settings, SettingsRules.GetSection("Settings"));
|
||||||
Game.NetworkPort = int.Parse(settings.GetValue("port", "0"));
|
}
|
||||||
|
catch (FileNotFoundException) {}
|
||||||
var useAftermath = bool.Parse(settings.GetValue("aftermath", "false"));
|
|
||||||
|
UiOverlay.ShowUnitDebug = Game.Settings.UnitDebug;
|
||||||
Renderer.SheetSize = int.Parse(settings.GetValue("sheetsize", "512"));
|
UiOverlay.ShowBuildDebug = Game.Settings.BuildingDebug;
|
||||||
|
WorldRenderer.ShowUnitPaths = Game.Settings.PathDebug;
|
||||||
|
Renderer.SheetSize = Game.Settings.SheetSize;
|
||||||
|
|
||||||
while (!File.Exists("redalert.mix"))
|
while (!File.Exists("redalert.mix"))
|
||||||
{
|
{
|
||||||
@@ -53,15 +65,20 @@ namespace OpenRa.Game
|
|||||||
Directory.SetCurrentDirectory("..");
|
Directory.SetCurrentDirectory("..");
|
||||||
}
|
}
|
||||||
|
|
||||||
FileSystem.MountDefault(useAftermath);
|
FileSystem.MountDefaultPackages();
|
||||||
|
|
||||||
|
if (Game.Settings.UseAftermath)
|
||||||
|
{
|
||||||
|
FileSystem.MountAftermathPackages();
|
||||||
|
}
|
||||||
|
|
||||||
bool windowed = !settings.GetValue("fullscreen", false);
|
bool windowed = !Game.Settings.Fullscreen;
|
||||||
renderer = new Renderer(this, GetResolution(settings), windowed);
|
renderer = new Renderer(this, GetResolution(settings), windowed);
|
||||||
|
|
||||||
var controller = new Controller(() => (Modifiers)(int)ModifierKeys); /* a bit of insane input routing */
|
var controller = new Controller(() => (Modifiers)(int)ModifierKeys); /* a bit of insane input routing */
|
||||||
|
|
||||||
Game.Initialize(settings.GetValue("map", "scm12ea.ini"), renderer, new int2(ClientSize),
|
Game.Initialize(Game.Settings.Map, renderer, new int2(ClientSize),
|
||||||
settings.GetValue("player", 1), useAftermath, controller);
|
Game.Settings.Player, Game.Settings.UseAftermath, controller);
|
||||||
|
|
||||||
ShowCursor(false);
|
ShowCursor(false);
|
||||||
Game.ResetTimer();
|
Game.ResetTimer();
|
||||||
|
|||||||
@@ -92,6 +92,7 @@
|
|||||||
<Compile Include="GameRules\GeneralInfo.cs" />
|
<Compile Include="GameRules\GeneralInfo.cs" />
|
||||||
<Compile Include="GameRules\SupportPowerInfo.cs" />
|
<Compile Include="GameRules\SupportPowerInfo.cs" />
|
||||||
<Compile Include="GameRules\TechTree.cs" />
|
<Compile Include="GameRules\TechTree.cs" />
|
||||||
|
<Compile Include="GameRules\UserSettings.cs" />
|
||||||
<Compile Include="GameRules\VoiceInfo.cs" />
|
<Compile Include="GameRules\VoiceInfo.cs" />
|
||||||
<Compile Include="Effects\IEffect.cs" />
|
<Compile Include="Effects\IEffect.cs" />
|
||||||
<Compile Include="Orders\IOrderSource.cs" />
|
<Compile Include="Orders\IOrderSource.cs" />
|
||||||
|
|||||||
@@ -70,16 +70,12 @@ namespace SequenceEditor
|
|||||||
{
|
{
|
||||||
Application.EnableVisualStyles();
|
Application.EnableVisualStyles();
|
||||||
Application.SetCompatibleTextRenderingDefault(false);
|
Application.SetCompatibleTextRenderingDefault(false);
|
||||||
|
FileSystem.MountDefaultPackages();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
FileSystem.MountDefault( true );
|
FileSystem.MountAftermathPackages();
|
||||||
}
|
|
||||||
catch( FileNotFoundException fnf )
|
|
||||||
{
|
|
||||||
if( fnf.FileName != "expand2.mix" )
|
|
||||||
throw new InvalidOperationException( "Unable to load MIX files" );
|
|
||||||
}
|
}
|
||||||
|
catch( FileNotFoundException ){}
|
||||||
|
|
||||||
FileSystem.MountTemporary(new Package("temperat.mix"));
|
FileSystem.MountTemporary(new Package("temperat.mix"));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user