Fullscreen toggle & don't crash when saving null fields

This commit is contained in:
Paul Chote
2010-07-10 15:42:50 +12:00
parent 636bfd5e0a
commit 77405a7700
6 changed files with 44 additions and 11 deletions

View File

@@ -149,6 +149,9 @@ namespace OpenRA.FileFormats
public static string FormatValue(object o, FieldInfo f) public static string FormatValue(object o, FieldInfo f)
{ {
var v = f.GetValue(o); var v = f.GetValue(o);
if (v == null)
return "";
return f.FieldType.IsArray return f.FieldType.IsArray
? string.Join(",", ((Array)v).OfType<object>().Select(a => a.ToString()).ToArray()) ? string.Join(",", ((Array)v).OfType<object>().Select(a => a.ToString()).ToArray())
: v.ToString(); : v.ToString();

View File

@@ -27,6 +27,7 @@ using System.Reflection;
using System.Text; using System.Text;
using System.Windows.Forms; using System.Windows.Forms;
using OpenRA.FileFormats; using OpenRA.FileFormats;
using OpenRA.FileFormats.Graphics;
using OpenRA.GameRules; using OpenRA.GameRules;
using OpenRA.Graphics; using OpenRA.Graphics;
using OpenRA.Network; using OpenRA.Network;
@@ -546,13 +547,15 @@ namespace OpenRA
controller.SetModifiers(mods); controller.SetModifiers(mods);
} }
static Size GetResolution(Settings settings) static Size GetResolution(Settings settings, WindowMode windowmode)
{ {
var desktopResolution = Screen.PrimaryScreen.Bounds.Size; var desktopResolution = Screen.PrimaryScreen.Bounds.Size;
if (Settings.Width > 0 && Settings.Height > 0) var customSize = (windowmode == WindowMode.Windowed) ? Settings.WindowedSize : Settings.FullscreenSize;
if (customSize.X > 0 && customSize.Y > 0)
{ {
desktopResolution.Width = Settings.Width; desktopResolution.Width = customSize.X;
desktopResolution.Height = Settings.Height; desktopResolution.Height = customSize.Y;
} }
return new Size( return new Size(
desktopResolution.Width, desktopResolution.Width,
@@ -581,7 +584,7 @@ namespace OpenRA
Renderer.SheetSize = Settings.SheetSize; Renderer.SheetSize = Settings.SheetSize;
var resolution = GetResolution(settings); var resolution = GetResolution(settings, Game.Settings.WindowMode);
renderer = new Renderer(resolution, Game.Settings.WindowMode); renderer = new Renderer(resolution, Game.Settings.WindowMode);
resolution = renderer.Resolution; resolution = renderer.Resolution;

View File

@@ -22,6 +22,7 @@ using OpenRA.FileFormats;
using OpenRA.FileFormats.Graphics; using OpenRA.FileFormats.Graphics;
using System.IO; using System.IO;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing;
namespace OpenRA.GameRules namespace OpenRA.GameRules
{ {
@@ -35,9 +36,11 @@ namespace OpenRA.GameRules
public bool RecordSyncReports = true; public bool RecordSyncReports = true;
// Window settings // Window settings
public readonly int Width = 0; public WindowMode WindowMode = WindowMode.PseudoFullscreen;
public readonly int Height = 0; public int2 FullscreenSize = new int2(0,0);
public readonly WindowMode WindowMode = WindowMode.PseudoFullscreen; public int2 WindowedSize = new int2(1024,768);
public bool MusicPlayer = true; public bool MusicPlayer = true;
// Internal game settings // Internal game settings
@@ -48,7 +51,7 @@ namespace OpenRA.GameRules
public readonly string NetworkHost = null; public readonly string NetworkHost = null;
public readonly int NetworkPort = 0; public readonly int NetworkPort = 0;
public readonly string Replay = null; public readonly string Replay = null;
public readonly string PlayerName = null; public string PlayerName = null;
public readonly string[] InitialMods = { "ra" }; public readonly string[] InitialMods = { "ra" };
public readonly string GameName = "OpenRA Game"; public readonly string GameName = "OpenRA Game";

View File

@@ -2,6 +2,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using OpenRA.FileFormats.Graphics;
namespace OpenRA.Widgets.Delegates namespace OpenRA.Widgets.Delegates
{ {
@@ -12,6 +13,15 @@ namespace OpenRA.Widgets.Delegates
var r = Chrome.rootWidget; var r = Chrome.rootWidget;
// Checkboxes // Checkboxes
// Should actually be a listbox; hack with a checkbox for now
r.GetWidget<CheckboxWidget>("CHECKBOX_FULLSCREEN").Checked = () => {return Game.Settings.WindowMode != WindowMode.Windowed;};
r.GetWidget("CHECKBOX_FULLSCREEN").OnMouseDown = mi => {
Game.Settings.WindowMode = (Game.Settings.WindowMode == WindowMode.Windowed) ? WindowMode.PseudoFullscreen : WindowMode.Windowed;
Game.Settings.Save();
return true;
};
r.GetWidget<CheckboxWidget>("SETTINGS_CHECKBOX_UNITDEBUG").Checked = () => {return Game.Settings.UnitDebug;}; r.GetWidget<CheckboxWidget>("SETTINGS_CHECKBOX_UNITDEBUG").Checked = () => {return Game.Settings.UnitDebug;};
r.GetWidget("SETTINGS_CHECKBOX_UNITDEBUG").OnMouseDown = mi => { r.GetWidget("SETTINGS_CHECKBOX_UNITDEBUG").OnMouseDown = mi => {
Game.Settings.UnitDebug ^= true; Game.Settings.UnitDebug ^= true;

View File

@@ -158,6 +158,13 @@ Container:
Width:300 Width:300
Height:20 Height:20
Text:Show Music Player Text:Show Music Player
Checkbox@CHECKBOX_FULLSCREEN:
Id:CHECKBOX_FULLSCREEN
X:100
Y:240
Width:300
Height:20
Text:Fullscreen (Requires restart)
Button@SETTINGS_BUTTON_OK: Button@SETTINGS_BUTTON_OK:
Id:SETTINGS_BUTTON_OK Id:SETTINGS_BUTTON_OK
X:PARENT_RIGHT - 180 X:PARENT_RIGHT - 180

View File

@@ -158,6 +158,13 @@ Container:
Width:300 Width:300
Height:20 Height:20
Text:Show Music Player Text:Show Music Player
Checkbox@CHECKBOX_FULLSCREEN:
Id:CHECKBOX_FULLSCREEN
X:100
Y:240
Width:300
Height:20
Text:Fullscreen (Requires restart)
Button@SETTINGS_BUTTON_OK: Button@SETTINGS_BUTTON_OK:
Id:SETTINGS_BUTTON_OK Id:SETTINGS_BUTTON_OK
X:PARENT_RIGHT - 180 X:PARENT_RIGHT - 180