Merge pull request #131 from mrpimpunicorn/resolution-options

Added support for changing preferred resolution in options
This commit is contained in:
Drew DeVault 2015-06-17 15:09:40 -04:00
commit f5f0958bf1
8 changed files with 106 additions and 6 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

View File

@ -0,0 +1 @@
No description available.

View File

@ -38,7 +38,7 @@ namespace TrueCraft.Client.Rendering
lock (_syncLock)
{
_vertices = new VertexBuffer(_graphicsDevice, VertexPositionNormalTexture.VertexDeclaration,
value.Length, BufferUsage.WriteOnly);
(value.Length + 1), BufferUsage.WriteOnly);
_vertices.SetData(value);
}
@ -119,7 +119,7 @@ namespace TrueCraft.Client.Rendering
_indices[index].Dispose();
_indices[index] = new IndexBuffer(_graphicsDevice, typeof(int),
indices.Length, BufferUsage.WriteOnly);
(indices.Length + 1), BufferUsage.WriteOnly);
_indices[index].SetData(indices);
}
}

View File

@ -162,6 +162,12 @@
<ItemGroup />
<ItemGroup />
<ItemGroup>
<Content Include="Content\default-pack.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\default-pack.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\items.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>

View File

@ -51,9 +51,9 @@ namespace TrueCraft.Client
Window.Title = "TrueCraft";
Content.RootDirectory = "Content";
Graphics = new GraphicsDeviceManager(this);
Graphics.IsFullScreen = false;
Graphics.PreferredBackBufferWidth = 1280;
Graphics.PreferredBackBufferHeight = 720;
Graphics.IsFullScreen = UserSettings.Local.IsFullscreen;
Graphics.PreferredBackBufferWidth = UserSettings.Local.WindowResolution.Width;
Graphics.PreferredBackBufferHeight = UserSettings.Local.WindowResolution.Height;
Client = client;
EndPoint = endPoint;
NextPhysicsUpdate = DateTime.MinValue;

View File

@ -32,7 +32,7 @@ namespace TrueCraft.Core
{
get
{
return System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),
return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),
".truecraft/texturepacks/");
}
}

View File

@ -23,6 +23,8 @@ namespace TrueCraft.Core
public string LastIP { get; set; }
public string SelectedTexturePack { get; set; }
public FavoriteServer[] FavoriteServers { get; set; }
public bool IsFullscreen { get; set; }
public WindowResolution WindowResolution { get; set; }
public UserSettings()
{
@ -32,6 +34,12 @@ namespace TrueCraft.Core
LastIP = "";
SelectedTexturePack = TexturePack.Default.Name;
FavoriteServers = new FavoriteServer[0];
IsFullscreen = false;
WindowResolution = new WindowResolution()
{
Width = 1280,
Height = 720
};
}
public void Load()
@ -52,4 +60,40 @@ namespace TrueCraft.Core
public string Name { get; set; }
public string Address { get; set; }
}
public class WindowResolution
{
public static readonly WindowResolution[] Defaults =
new WindowResolution[]
{
// (from Wikipedia/other)
WindowResolution.FromString("800 x 600"), // SVGA
WindowResolution.FromString("960 x 640"), // DVGA
WindowResolution.FromString("1024 x 600"), // WSVGA
WindowResolution.FromString("1024 x 768"), // XGA
WindowResolution.FromString("1280 x 1024"), // SXGA
WindowResolution.FromString("1600 x 1200"), // UXGA
WindowResolution.FromString("1920 x 1080"), // big
WindowResolution.FromString("1920 x 1200"), // really big
WindowResolution.FromString("4096 x 2160"), // huge
};
public static WindowResolution FromString(string str)
{
var tmp = str.Split('x');
return new WindowResolution()
{
Width = int.Parse(tmp[0].Trim()),
Height = int.Parse(tmp[1].Trim())
};
}
public int Width { get; set; }
public int Height { get; set; }
public override string ToString()
{
return string.Format("{0} x {1}", Width, Height);
}
}
}

View File

@ -13,6 +13,9 @@ namespace TrueCraft.Launcher.Views
public LauncherWindow Window { get; set; }
public Label OptionLabel { get; set; }
public Label ResolutionLabel { get; set; }
public ComboBox ResolutionComboBox { get; set; }
public CheckBox FullscreenCheckBox { get; set; }
public Label TexturePackLabel { get; set; }
public DataField<Image> TexturePackImageField { get; set; }
public DataField<string> TexturePackTextField { get; set; }
@ -37,6 +40,36 @@ namespace TrueCraft.Launcher.Views
Font = Font.WithSize(16),
TextAlignment = Alignment.Center
};
ResolutionLabel = new Label("Select a resolution...");
ResolutionComboBox = new ComboBox();
int resolutionIndex = -1;
for (int i = 0; i < WindowResolution.Defaults.Length; i++)
{
ResolutionComboBox.Items.Add(WindowResolution.Defaults[i].ToString());
if (resolutionIndex == -1)
{
resolutionIndex =
((WindowResolution.Defaults[i].Width == UserSettings.Local.WindowResolution.Width) &&
(WindowResolution.Defaults[i].Height == UserSettings.Local.WindowResolution.Height)) ? i : -1;
}
}
if (resolutionIndex == -1)
{
ResolutionComboBox.Items.Add(UserSettings.Local.WindowResolution.ToString());
resolutionIndex = ResolutionComboBox.Items.Count - 1;
}
ResolutionComboBox.SelectedIndex = resolutionIndex;
FullscreenCheckBox = new CheckBox()
{
Label = "Fullscreen mode",
State = (UserSettings.Local.IsFullscreen) ? CheckBoxState.On : CheckBoxState.Off
};
TexturePackLabel = new Label("Select a texture pack...");
TexturePackImageField = new DataField<Image>();
TexturePackTextField = new DataField<string>();
@ -54,6 +87,19 @@ namespace TrueCraft.Launcher.Views
TexturePackListView.Columns.Add("Image", TexturePackImageField);
TexturePackListView.Columns.Add("Text", TexturePackTextField);
ResolutionComboBox.SelectionChanged += (sender, e) =>
{
UserSettings.Local.WindowResolution =
WindowResolution.FromString(ResolutionComboBox.SelectedText);
UserSettings.Local.Save();
};
FullscreenCheckBox.Clicked += (sender, e) =>
{
UserSettings.Local.IsFullscreen = !UserSettings.Local.IsFullscreen;
UserSettings.Local.Save();
};
TexturePackListView.SelectionChanged += (sender, e) =>
{
var texturePack = _texturePacks[TexturePackListView.SelectedRow];
@ -79,6 +125,9 @@ namespace TrueCraft.Launcher.Views
LoadTexturePacks();
this.PackStart(OptionLabel);
this.PackStart(ResolutionLabel);
this.PackStart(ResolutionComboBox);
this.PackStart(FullscreenCheckBox);
this.PackStart(TexturePackLabel);
this.PackStart(TexturePackListView);
this.PackStart(OpenFolderButton);