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