Option for all hud scaling, replaces chat font size. Also make block select screen slightly less big at higher scalings.

This commit is contained in:
UnknownShadow200 2015-11-15 21:49:35 +11:00
parent 7eff50e53b
commit 2f940aebaa
9 changed files with 43 additions and 30 deletions

View File

@ -66,8 +66,8 @@ namespace ClassicalSharp {
}
public override void OnResize( int oldWidth, int oldHeight, int width, int height ) {
blockSize = (int)(50 * Utils.GuiScale( game.Width, game.Height ));
selBlockExpand = (float)(25 * Utils.GuiScale( game.Width, game.Height ));
blockSize = (int)(50 * Math.Sqrt(game.GuiScale()));
selBlockExpand = (float)(25 * Math.Sqrt(game.GuiScale()));
startX = game.Width / 2 - (blockSize * blocksPerRow) / 2;
startY = game.Height / 2 - (rows * blockSize) / 2;
@ -76,14 +76,14 @@ namespace ClassicalSharp {
}
public override void Init() {
blockSize = (int)(50 * Utils.GuiScale( game.Width, game.Height ));
selBlockExpand = (float)(25 * Utils.GuiScale( game.Width, game.Height ));
blockSize = (int)(50 * Math.Sqrt(game.GuiScale()));
selBlockExpand = (float)(25 * Math.Sqrt(game.GuiScale()));
game.Events.BlockPermissionsChanged += BlockPermissionsChanged;
RecreateBlockTexturess();
RecreateBlockTextures();
}
void BlockPermissionsChanged( object sender, EventArgs e ) {
RecreateBlockTexturess();
RecreateBlockTextures();
if( selectedIndex >= blocksTable.Length ) {
selectedIndex = blocksTable.Length - 1;
}
@ -142,7 +142,7 @@ namespace ClassicalSharp {
blockInfoTexture = game.Drawer2D.MakeTextTexture( ref args, x, y );
}
void RecreateBlockTexturess() {
void RecreateBlockTextures() {
int blocksCount = 0;
for( int tile = 1; tile < BlockInfo.BlocksCount; tile++ ) {
if( game.Inventory.CanPlace[tile] || game.Inventory.CanDelete[tile] )

View File

@ -79,12 +79,14 @@ namespace ClassicalSharp {
Font chatFont, chatInputFont, chatUnderlineFont, announcementFont;
public override void Init() {
int fontSize = game.Chat.FontSize;//(int)(14 * Utils.GuiScale( game.Width, game.Height ));
int fontSize = (int)(14 * game.GuiScale());
Utils.Clamp( ref fontSize, 8, 40 );
chatFont = new Font( "Arial", fontSize );
chatInputFont = new Font( "Arial", fontSize, FontStyle.Bold );
chatUnderlineFont = new Font( "Arial", fontSize, FontStyle.Underline );
announcementFont = new Font( "Arial", 14 );
blockSize = (int)(40 * Utils.GuiScale( game.Width, game.Height ));
blockSize = (int)(40 * game.GuiScale());
textInput = new TextInputWidget( game, chatFont, chatInputFont );
textInput.YOffset = blockSize + 5;
@ -176,7 +178,7 @@ namespace ClassicalSharp {
public override void OnResize( int oldWidth, int oldHeight, int width, int height ) {
announcementTex.X1 += (width - oldWidth) / 2;
announcementTex.Y1 += (height - oldHeight) / 2;
blockSize = (int)(40 * Utils.GuiScale( game.Width, game.Height ));
blockSize = (int)(40 * game.GuiScale());
textInput.YOffset = blockSize + 5;
bottomRight.YOffset = blockSize * 3 / 2;

View File

@ -38,10 +38,10 @@ namespace ClassicalSharp {
(g, v) => { g.MouseSensitivity = Int32.Parse( v );
Options.Set( OptionsKey.Sensitivity, v ); } ),
Make( 140, -50, "Chat font size", Anchor.Centre, OnWidgetClick,
g => g.Chat.FontSize.ToString(),
(g, v) => { g.Chat.FontSize = Int32.Parse( v );
Options.Set( OptionsKey.FontSize, v );
Make( 140, -50, "Hud scale", Anchor.Centre, OnWidgetClick,
g => g.HudScale.ToString(),
(g, v) => { g.HudScale = Single.Parse( v );
Options.Set( OptionsKey.HudScale, v );
g.RefreshHud();
} ),
@ -95,7 +95,7 @@ namespace ClassicalSharp {
new IntegerValidator( 16, 4096 ),
new IntegerValidator( 1, 100 ),
new IntegerValidator( 6, 30 ),
new RealValidator( 0.5f, 2f ),
new IntegerValidator( 1, 30 ),
new BooleanValidator(),

View File

@ -29,8 +29,8 @@ namespace ClassicalSharp {
static FastColour outlineCol = new FastColour( 169, 143, 192 );
static FastColour selCol = new FastColour( 213, 200, 223 );
public override void Init() {
blockSize = (int)(38 * Utils.GuiScale( game.Width, game.Height ));
borderSize = (int)(3 * Utils.GuiScale( game.Width, game.Height ));
blockSize = (int)(38 * game.GuiScale());
borderSize = (int)(3 * game.GuiScale());
int width = blockSize * hotbarCount;
X = game.Width / 2 - width / 2;
Y = game.Height - blockSize;

View File

@ -22,8 +22,6 @@ namespace ClassicalSharp {
/// <summary> List of chat messages sent by the user to the server. </summary>
public List<string> InputLog = new List<string>();
public int FontSize = 12;
public void Send( string text, bool partial ) {
text = text.TrimEnd( trimChars );
if( String.IsNullOrEmpty( text ) ) return;

View File

@ -71,6 +71,7 @@ namespace ClassicalSharp {
public int MouseSensitivity = 30;
public int ChatLines = 12;
public bool HideGui = false, ShowFPS = true;
internal float HudScale = 1f;
public Animations Animations;
internal int CloudsTextureId, RainTextureId, SnowTextureId;
@ -79,6 +80,11 @@ namespace ClassicalSharp {
internal List<WarningScreen> WarningScreens = new List<WarningScreen>();
internal AcceptedUrls AcceptedUrls = new AcceptedUrls();
public float GuiScale() {
float scaleX = Width / 640f, scaleY = Height / 480f;
return Math.Min( scaleX, scaleY ) * HudScale;
}
string defTexturePack = "default.zip";
public string DefaultTexturePack {
get {
@ -117,7 +123,7 @@ namespace ClassicalSharp {
ViewDistance = Options.GetInt( OptionsKey.ViewDist, 16, 4096, 512 );
InputHandler = new InputHandler( this );
Chat = new ChatLog( this );
Chat.FontSize = Options.GetInt( OptionsKey.FontSize, 6, 30, 12 );
HudScale = Options.GetFloat( OptionsKey.HudScale, 0.5f, 2f, 1 );
defaultIb = Graphics.MakeDefaultIb();
MouseSensitivity = Options.GetInt( OptionsKey.Sensitivity, 1, 100, 30 );
BlockInfo = new BlockInfo();
@ -303,8 +309,10 @@ namespace ClassicalSharp {
}
string timestamp = DateTime.Now.ToString( "dd-MM-yyyy-HH-mm-ss" );
string path = Path.Combine( "screenshots", "screenshot_" + timestamp + ".png" );
string file = "screenshot_" + timestamp + ".png";
string path = Path.Combine( "screenshots", file );
Graphics.TakeScreenshot( path, ClientSize );
Chat.Add( "&eTaken screenshot as: " + file );
screenshotRequested = false;
}

View File

@ -44,10 +44,10 @@ namespace ClassicalSharp {
width = 640; height = 480;
if( device.Width >= 1024 && device.Height >= 768 ) {
width = 800; height = 600;
//width = 800; height = 600;
}
if( device.Width >= 1920 && device.Height >= 1080 ) {
width = 1600; height = 900;
//width = 1600; height = 900;
}
}

View File

@ -8,7 +8,7 @@ namespace ClassicalSharp {
public static class OptionsKey {
public const string ViewDist = "viewdist";
public const string FontSize = "chatfontsize";
public const string HudScale = "chatscale";
public const string Sensitivity = "mousesensitivity";
public const string Speed = "speedmultiplier";
public const string ChatLines = "chatlines";
@ -53,6 +53,17 @@ namespace ClassicalSharp {
return valueBool;
}
public static float GetFloat( string key, float min, float max, float defValue ) {
string value;
float valueFloat = 0;
if( !OptionsSet.TryGetValue( key, out value ) || String.IsNullOrEmpty( value )
|| !Single.TryParse( value, out valueFloat ) )
return defValue;
Utils.Clamp( ref valueFloat, min, max );
return valueFloat;
}
public static Key GetKey( string key, Key defValue ) {
string value = Options.Get( key.ToLower() );
if( value == null ) {

View File

@ -237,12 +237,6 @@ namespace ClassicalSharp {
return (int)(1.4142135 * value);
}
public static float GuiScale( int width, int height ) {
float scaleX = width / 640f;
float scaleY = height / 480f;
return Math.Min( scaleX, scaleY );
}
/// <summary> Returns the number of vertices needed to subdivide a quad. </summary>
internal static int CountVertices( int axis1Len, int axis2Len, int axisSize ) {
return CeilDiv( axis1Len, axisSize ) * CeilDiv( axis2Len, axisSize ) * 4;