Use gui.png.

This commit is contained in:
UnknownShadow200 2015-11-30 14:16:48 +11:00
parent 4ccbc900a1
commit a13d3147bc
24 changed files with 177 additions and 149 deletions

View File

@ -0,0 +1,33 @@
using System;
using System.Drawing;
using OpenTK.Input;
namespace ClassicalSharp {
public class AdvancedKeyBindingsScreen : KeyBindingsScreen {
public AdvancedKeyBindingsScreen( Game game ) : base( game ) {
}
static string[] normDescriptions = new [] { "Speed", "Toggle noclip", "Toggle fly",
"Fly up", "Fly down", "Toggle extended input", "Hide FPS", "Take screenshot",
"Toggle fullscreen", "Toggle 3rd person", "Hide gui" };
public override void Init() {
base.Init();
descriptions = normDescriptions;
buttons = new ButtonWidget[descriptions.Length + 2];
MakeKeys( KeyBinding.Speed, 0, 6, -150 );
MakeKeys( KeyBinding.HideFps, 6, 5, 150 );
buttons[index++] = MakeBack( false, titleFont,
(g, w) => g.SetNewScreen( new PauseScreen( g ) ) );
buttons[index++] = ButtonWidget.Create(
game, 0, 170, 300, 35, "Normal key bindings",
Anchor.Centre, Anchor.Centre, titleFont, NextClick );
}
void NextClick( Game game, Widget widget ) {
game.SetNewScreen( new NormalKeyBindingsScreen( game ) );
}
}
}

View File

@ -4,7 +4,7 @@ using OpenTK.Input;
namespace ClassicalSharp { namespace ClassicalSharp {
public class KeyBindingsScreen : MenuScreen { public abstract class KeyBindingsScreen : MenuScreen {
public KeyBindingsScreen( Game game ) : base( game ) { public KeyBindingsScreen( Game game ) : base( game ) {
} }
@ -20,43 +20,33 @@ namespace ClassicalSharp {
Font keyFont; Font keyFont;
TextWidget statusWidget; TextWidget statusWidget;
static string[] keyNames; static string[] keyNames;
static string[] descriptions = new [] { "Forward", "Back", "Left", "Right", "Jump", "Respawn", protected string[] descriptions;
"Set spawn", "Open chat", "Send chat", "Pause", "Open inventory", "Cycle view distance",
"Show player list", "Speed", "Toggle noclip", "Toggle fly", "Fly up", "Fly down",
"Hide gui", "Hide FPS", "Take screenshot", "Toggle fullscreen", "Toggle 3rd person",
"Toggle extended input", };
public override void Init() { public override void Init() {
base.Init();
if( keyNames == null ) if( keyNames == null )
keyNames = Enum.GetNames( typeof( Key ) ); keyNames = Enum.GetNames( typeof( Key ) );
keyFont = new Font( "Arial", 14, FontStyle.Bold ); keyFont = new Font( "Arial", 15, FontStyle.Bold );
regularFont = new Font( "Arial", 14, FontStyle.Italic ); regularFont = new Font( "Arial", 15, FontStyle.Italic );
titleFont = new Font( "Arial", 16, FontStyle.Bold ); statusWidget = TextWidget.Create( game, 0, 130, "", Anchor.Centre, Anchor.Centre, regularFont );
buttons = new ButtonWidget[descriptions.Length + 1];
MakeKeys( 0, 12, -140 );
MakeKeys( 12, 12, 140 );
buttons[index] = MakeOther( 0, 5, 160, "Back to menu", Anchor.Centre,
(g, w) => g.SetNewScreen( new PauseScreen( g ) ) );
statusWidget = TextWidget.Create( game, 0, 160, "", Anchor.Centre, Anchor.Centre, regularFont );
} }
int index; protected int index;
void MakeKeys( int start, int len, int x ) { protected void MakeKeys( KeyBinding start, int descStart, int len, int x ) {
int y = -200; int y = -180;
for( int i = 0; i < len; i++ ) { for( int i = 0; i < len; i++ ) {
KeyBinding binding = (KeyBinding)((int)start + i); KeyBinding binding = (KeyBinding)((int)start + i);
string text = descriptions[start + i] + ": " string text = descriptions[descStart + i] + ": "
+ keyNames[(int)game.Mapping( binding )]; + keyNames[(int)game.Mapping( binding )];
buttons[index++] = ButtonWidget.Create( game, x, y, 240, 25, text, buttons[index++] = ButtonWidget.Create( game, x, y, 260, 35, text,
Anchor.Centre, Anchor.Centre, keyFont, OnWidgetClick ); Anchor.Centre, Anchor.Centre, keyFont, OnBindingClick );
y += 30; y += 45;
} }
} }
ButtonWidget curWidget; ButtonWidget curWidget;
void OnWidgetClick( Game game, Widget realWidget ) { void OnBindingClick( Game game, Widget realWidget ) {
this.curWidget = (ButtonWidget)realWidget; this.curWidget = (ButtonWidget)realWidget;
int index = Array.IndexOf<ButtonWidget>( buttons, curWidget ); int index = Array.IndexOf<ButtonWidget>( buttons, curWidget );
string text = "&ePress new key binding for " + descriptions[index] + ":"; string text = "&ePress new key binding for " + descriptions[index] + ":";
@ -89,11 +79,6 @@ namespace ClassicalSharp {
return true; return true;
} }
ButtonWidget MakeOther( int x, int y, int width, string text, Anchor hAnchor, Action<Game, Widget> onClick ) {
return ButtonWidget.Create( game, x, y, width, 35, text,
hAnchor, Anchor.BottomOrRight, titleFont, onClick );
}
public override void Dispose() { public override void Dispose() {
keyFont.Dispose(); keyFont.Dispose();
base.Dispose(); base.Dispose();

View File

@ -0,0 +1,33 @@
using System;
using System.Drawing;
using OpenTK.Input;
namespace ClassicalSharp {
public class NormalKeyBindingsScreen : KeyBindingsScreen {
public NormalKeyBindingsScreen( Game game ) : base( game ) {
}
static string[] normDescriptions = new [] { "Forward", "Back", "Left",
"Right", "Jump", "Respawn", "Set spawn", "Open chat", "Send chat",
"Pause", "Open inventory", "Cycle view distance", "Show player list" };
public override void Init() {
base.Init();
descriptions = normDescriptions;
buttons = new ButtonWidget[descriptions.Length + 2];
MakeKeys( KeyBinding.Forward, 0, 6, -150 );
MakeKeys( KeyBinding.SetSpawn, 6, 7, 150 );
buttons[index++] = MakeBack( false, titleFont,
(g, w) => g.SetNewScreen( new PauseScreen( g ) ) );
buttons[index++] = ButtonWidget.Create(
game, 0, 170, 300, 35, "Advanced key bindings",
Anchor.Centre, Anchor.Centre, titleFont, NextClick );
}
void NextClick( Game game, Widget widget ) {
game.SetNewScreen( new AdvancedKeyBindingsScreen( game ) );
}
}
}

View File

@ -44,5 +44,12 @@ namespace ClassicalSharp {
protected virtual void WidgetSelected( Widget widget ) { protected virtual void WidgetSelected( Widget widget ) {
} }
protected ButtonWidget MakeBack( bool toGame, Font font, Action<Game, Widget> onClick ) {
string text = toGame ? "Back to game" : "Back to menu";
return ButtonWidget.Create(
game, 0, 5, 180, 35, text,
Anchor.Centre, Anchor.BottomOrRight, font, onClick );
}
} }
} }

View File

@ -20,7 +20,8 @@ namespace ClassicalSharp {
public override void Init() { public override void Init() {
textFont = new Font( "Arial", 14, FontStyle.Bold ); textFont = new Font( "Arial", 14, FontStyle.Bold );
arrowFont = new Font( "Arial", 18, FontStyle.Bold ); arrowFont = new Font( "Arial", 18, FontStyle.Bold );
titleFont = new Font( "Arial", 16, FontStyle.Bold ); int size = game.Drawer2D.UseBitmappedChat ? 13 : 16;
titleFont = new Font( "Arial", size, FontStyle.Bold );
title = TextWidget.Create( game, 0, -130, titleText, Anchor.Centre, Anchor.Centre, titleFont ); title = TextWidget.Create( game, 0, -130, titleText, Anchor.Centre, Anchor.Centre, titleFont );
title.Init(); title.Init();

View File

@ -82,10 +82,7 @@ namespace ClassicalSharp {
game.Events.ChatFontChanged -= ChatFontChanged; game.Events.ChatFontChanged -= ChatFontChanged;
} }
void ChatFontChanged( object sender, EventArgs e ) { void ChatFontChanged( object sender, EventArgs e ) { Recreate(); }
Dispose();
Init();
}
public override void OnResize( int oldWidth, int oldHeight, int width, int height ) { public override void OnResize( int oldWidth, int oldHeight, int width, int height ) {
} }

View File

@ -73,7 +73,7 @@ namespace ClassicalSharp {
public override void Init() { public override void Init() {
game.Keyboard.KeyRepeat = true; game.Keyboard.KeyRepeat = true;
titleFont = new Font( "Arial", 16, FontStyle.Bold ); base.Init();
regularFont = new Font( "Arial", 16, FontStyle.Regular ); regularFont = new Font( "Arial", 16, FontStyle.Regular );
hintFont = new Font( "Arial", 14, FontStyle.Italic ); hintFont = new Font( "Arial", 14, FontStyle.Italic );
arrowFont = new Font( "Arial", 18, FontStyle.Bold ); arrowFont = new Font( "Arial", 18, FontStyle.Bold );
@ -88,8 +88,8 @@ namespace ClassicalSharp {
Make( -160, -80, "<", 40, 40, arrowFont, (g, w) => PageClick( false ) ), Make( -160, -80, "<", 40, 40, arrowFont, (g, w) => PageClick( false ) ),
Make( 160, -80, ">", 40, 40, arrowFont, (g, w) => PageClick( true ) ), Make( 160, -80, ">", 40, 40, arrowFont, (g, w) => PageClick( true ) ),
ButtonWidget.Create( game, 0, 5, 160, 35, "Back to menu", Anchor.Centre, Anchor.BottomOrRight, MakeBack( false, titleFont,
titleFont, (g, w) => g.SetNewScreen( new PauseScreen( g ) ) ), (g, w) => g.SetNewScreen( new PauseScreen( g ) ) ),
null, // current key null, // current key
null, // current modifiers null, // current modifiers
null, // leave open current null, // leave open current

View File

@ -49,8 +49,8 @@ namespace ClassicalSharp {
g => g.Map.EdgeHeight.ToString(), g => g.Map.EdgeHeight.ToString(),
(g, v) => g.Map.SetEdgeLevel( Int32.Parse( v ) ) ), (g, v) => g.Map.SetEdgeLevel( Int32.Parse( v ) ) ),
MakeOther( 0, 5, 160, "Back to menu", Anchor.Centre, MakeBack( false, titleFont,
(g, w) => g.SetNewScreen( new PauseScreen( g ) ) ), (g, w) => g.SetNewScreen( new PauseScreen( g ) ) ),
null, null,
}; };
buttons[7].Metadata = typeof(Weather); buttons[7].Metadata = typeof(Weather);
@ -77,10 +77,5 @@ namespace ClassicalSharp {
widget.SetValue = setter; widget.SetValue = setter;
return widget; return widget;
} }
ButtonWidget MakeOther( int x, int y, int width, string text, Anchor hAnchor, Action<Game, Widget> onClick ) {
return ButtonWidget.Create( game, x, y, width, 35, text,
hAnchor, Anchor.BottomOrRight, titleFont, onClick );
}
} }
} }

View File

@ -37,10 +37,6 @@ namespace ClassicalSharp {
g.RefreshHud(); g.RefreshHud();
} ), } ),
Make( -140, 50, "Use gui.png (WIP)", Anchor.Centre, OnWidgetClick,
g => g.UseGuiPng ? "yes" : "no",
(g, v) => game.UseGuiPng = v == "yes" ),
// Column 2 // Column 2
Make( 140, -150, "Clickable chat", Anchor.Centre, OnWidgetClick, Make( 140, -150, "Clickable chat", Anchor.Centre, OnWidgetClick,
g => g.ClickableChat ? "yes" : "no", g => g.ClickableChat ? "yes" : "no",
@ -69,10 +65,11 @@ namespace ClassicalSharp {
Options.Set( OptionsKey.ArialChatFont, v == "yes" ); Options.Set( OptionsKey.ArialChatFont, v == "yes" );
game.Events.RaiseChatFontChanged(); game.Events.RaiseChatFontChanged();
g.RefreshHud(); g.RefreshHud();
Recreate();
} ), } ),
MakeOther( 0, 5, 160, "Back to menu", Anchor.Centre, MakeBack( false, titleFont,
(g, w) => g.SetNewScreen( new PauseScreen( g ) ) ), (g, w) => g.SetNewScreen( new PauseScreen( g ) ) ),
null, null,
}; };
@ -81,7 +78,6 @@ namespace ClassicalSharp {
new IntegerValidator( 1, 179 ), new IntegerValidator( 1, 179 ),
new BooleanValidator(), new BooleanValidator(),
new RealValidator( 0.25f, 5f ), new RealValidator( 0.25f, 5f ),
new BooleanValidator(),
new BooleanValidator(), new BooleanValidator(),
new RealValidator( 0.25f, 5f ), new RealValidator( 0.25f, 5f ),
@ -99,10 +95,5 @@ namespace ClassicalSharp {
widget.SetValue = setter; widget.SetValue = setter;
return widget; return widget;
} }
ButtonWidget MakeOther( int x, int y, int width, string text, Anchor hAnchor, Action<Game, Widget> onClick ) {
return ButtonWidget.Create( game, x, y, width, 35, text,
hAnchor, Anchor.BottomOrRight, titleFont, onClick );
}
} }
} }

View File

@ -24,12 +24,7 @@ namespace ClassicalSharp {
public override void Init() { public override void Init() {
base.Init(); base.Init();
buttons[buttons.Length - 1] = buttons[buttons.Length - 1] =
Make( 0, 5, "Back to menu", (g, w) => g.SetNewScreen( new PauseScreen( g ) ) ); MakeBack( false, titleFont, (g, w) => g.SetNewScreen( new PauseScreen( g ) ) );
}
ButtonWidget Make( int x, int y, string text, Action<Game, Widget> onClick ) {
return ButtonWidget.Create( game, x, y, 160, 35, text,
Anchor.Centre, Anchor.BottomOrRight, titleFont, onClick );
} }
protected override void TextButtonClick( Game game, Widget widget ) { protected override void TextButtonClick( Game game, Widget widget ) {

View File

@ -27,7 +27,7 @@ namespace ClassicalSharp {
} }
public override void Init() { public override void Init() {
titleFont = new Font( "Arial", 16, FontStyle.Bold ); base.Init();
regularFont = new Font( "Arial", 16, FontStyle.Regular ); regularFont = new Font( "Arial", 16, FontStyle.Regular );
hintFont = new Font( "Arial", 14, FontStyle.Italic ); hintFont = new Font( "Arial", 14, FontStyle.Italic );
game.Keyboard.KeyRepeat = true; game.Keyboard.KeyRepeat = true;

View File

@ -22,6 +22,11 @@ namespace ClassicalSharp {
} }
} }
public override void Init() {
int size = game.Drawer2D.UseBitmappedChat ? 13 : 16;
titleFont = new Font( "Arial", size, FontStyle.Bold );
}
public override void Dispose() { public override void Dispose() {
for( int i = 0; i < buttons.Length; i++ ) { for( int i = 0; i < buttons.Length; i++ ) {
if( buttons[i] == null ) continue; if( buttons[i] == null ) continue;

View File

@ -42,7 +42,7 @@ namespace ClassicalSharp {
// Column 2 // Column 2
!network.IsSinglePlayer ? null : !network.IsSinglePlayer ? null :
Make( 140, -200, "Singleplayer physics", Anchor.Centre, OnWidgetClick, Make( 140, -200, "Block physics", Anchor.Centre, OnWidgetClick,
g => ((SinglePlayerServer)network).physics.Enabled ? "yes" : "no", g => ((SinglePlayerServer)network).physics.Enabled ? "yes" : "no",
(g, v) => { (g, v) => {
((SinglePlayerServer)network).physics.Enabled = v == "yes"; ((SinglePlayerServer)network).physics.Enabled = v == "yes";
@ -63,7 +63,7 @@ namespace ClassicalSharp {
g => Options.GetBool( OptionsKey.AutoCloseLauncher, false ) ? "yes" : "no", g => Options.GetBool( OptionsKey.AutoCloseLauncher, false ) ? "yes" : "no",
(g, v) => Options.Set( OptionsKey.AutoCloseLauncher, v == "yes" ) ), (g, v) => Options.Set( OptionsKey.AutoCloseLauncher, v == "yes" ) ),
Make( 140, 0, "Pushback block placing", Anchor.Centre, OnWidgetClick, Make( 140, 0, "Pushback placing", Anchor.Centre, OnWidgetClick,
g => g.LocalPlayer.PushbackBlockPlacing g => g.LocalPlayer.PushbackBlockPlacing
&& g.LocalPlayer.CanPushbackBlocks ? "yes" : "no", && g.LocalPlayer.CanPushbackBlocks ? "yes" : "no",
(g, v) => { (g, v) => {
@ -76,7 +76,7 @@ namespace ClassicalSharp {
(g, v) => { g.MouseSensitivity = Int32.Parse( v ); (g, v) => { g.MouseSensitivity = Int32.Parse( v );
Options.Set( OptionsKey.Sensitivity, v ); } ), Options.Set( OptionsKey.Sensitivity, v ); } ),
MakeOther( 0, 5, 160, "Back to menu", Anchor.Centre, MakeBack( false, titleFont,
(g, w) => g.SetNewScreen( new PauseScreen( g ) ) ), (g, w) => g.SetNewScreen( new PauseScreen( g ) ) ),
null, null,
}; };
@ -107,10 +107,5 @@ namespace ClassicalSharp {
widget.SetValue = setter; widget.SetValue = setter;
return widget; return widget;
} }
ButtonWidget MakeOther( int x, int y, int width, string text, Anchor hAnchor, Action<Game, Widget> onClick ) {
return ButtonWidget.Create( game, x, y, width, 35, text,
hAnchor, Anchor.BottomOrRight, titleFont, onClick );
}
} }
} }

View File

@ -17,17 +17,17 @@ namespace ClassicalSharp {
} }
public override void Init() { public override void Init() {
titleFont = new Font( "Arial", 16, FontStyle.Bold ); base.Init();
buttons = new ButtonWidget[] { buttons = new ButtonWidget[] {
// Column 1 // Column 1
Make( -140, -150, "Options", Anchor.Centre, Make( -140, -150, "Options", Anchor.Centre,
(g, w) => g.SetNewScreen( new OptionsScreen( g ) ) ), (g, w) => g.SetNewScreen( new OptionsScreen( g ) ) ),
Make( -140, -100, "Gui options", Anchor.Centre, Make( -140, -100, "Gui options", Anchor.Centre,
(g, w) => g.SetNewScreen( new GuiOptionsScreen( g ) ) ), (g, w) => g.SetNewScreen( new GuiOptionsScreen( g ) ) ),
Make( -140, -50, "Environment settings", Anchor.Centre, Make( -140, -50, "Env settings", Anchor.Centre,
(g, w) => g.SetNewScreen( new EnvSettingsScreen( g ) ) ), (g, w) => g.SetNewScreen( new EnvSettingsScreen( g ) ) ),
Make( -140, 0, "Key bindings", Anchor.Centre, Make( -140, 0, "Key bindings", Anchor.Centre,
(g, w) => g.SetNewScreen( new KeyBindingsScreen( g ) ) ), (g, w) => g.SetNewScreen( new NormalKeyBindingsScreen( g ) ) ),
Make( -140, 50, "Hotkeys", Anchor.Centre, Make( -140, 50, "Hotkeys", Anchor.Centre,
(g, w) => g.SetNewScreen( new HotkeyScreen( g ) ) ), (g, w) => g.SetNewScreen( new HotkeyScreen( g ) ) ),
// Column 2 // Column 2
@ -42,8 +42,8 @@ namespace ClassicalSharp {
// Other // Other
MakeOther( 10, 5, 120, "Quit game", Anchor.BottomOrRight, MakeOther( 10, 5, 120, "Quit game", Anchor.BottomOrRight,
(g, w) => g.Exit() ), (g, w) => g.Exit() ),
MakeOther( 0, 5, 160, "Back to game", Anchor.Centre, MakeBack( true, titleFont,
(g, w) => g.SetNewScreen( null ) ), (g, w) => g.SetNewScreen( null ) ),
}; };
} }

View File

@ -47,7 +47,7 @@ namespace ClassicalSharp {
public override void Init() { public override void Init() {
game.Keyboard.KeyRepeat = true; game.Keyboard.KeyRepeat = true;
titleFont = new Font( "Arial", 16, FontStyle.Bold ); base.Init();
regularFont = new Font( "Arial", 16, FontStyle.Regular ); regularFont = new Font( "Arial", 16, FontStyle.Regular );
hintFont = new Font( "Arial", 14, FontStyle.Italic ); hintFont = new Font( "Arial", 14, FontStyle.Italic );
@ -58,8 +58,8 @@ namespace ClassicalSharp {
buttons = new [] { buttons = new [] {
ButtonWidget.Create( game, 260, 50, 60, 30, "Save", Anchor.Centre, ButtonWidget.Create( game, 260, 50, 60, 30, "Save", Anchor.Centre,
Anchor.Centre, titleFont, OkButtonClick ), Anchor.Centre, titleFont, OkButtonClick ),
ButtonWidget.Create( game, 0, 5, 160, 35, "Back to menu", Anchor.Centre, Anchor.BottomOrRight, MakeBack( false, titleFont,
titleFont, (g, w) => g.SetNewScreen( new PauseScreen( g ) ) ), (g, w) => g.SetNewScreen( new PauseScreen( g ) ) ),
}; };
} }

View File

@ -22,12 +22,7 @@ namespace ClassicalSharp {
public override void Init() { public override void Init() {
base.Init(); base.Init();
buttons[buttons.Length - 1] = buttons[buttons.Length - 1] =
Make( 0, 5, "Back to menu", (g, w) => g.SetNewScreen( new PauseScreen( g ) ) ); MakeBack( false, titleFont, (g, w) => g.SetNewScreen( new PauseScreen( g ) ) );
}
ButtonWidget Make( int x, int y, string text, Action<Game, Widget> onClick ) {
return ButtonWidget.Create( game, x, y, 160, 35, text,
Anchor.Centre, Anchor.BottomOrRight, titleFont, onClick );
} }
protected override void TextButtonClick( Game game, Widget widget ) { protected override void TextButtonClick( Game game, Widget widget ) {
@ -36,6 +31,7 @@ namespace ClassicalSharp {
game.DefaultTexturePack = path; game.DefaultTexturePack = path;
TexturePackExtractor extractor = new TexturePackExtractor(); TexturePackExtractor extractor = new TexturePackExtractor();
extractor.Extract( path, game ); extractor.Extract( path, game );
Recreate();
} }
} }
} }

View File

@ -22,5 +22,12 @@ namespace ClassicalSharp {
public virtual bool HidesHud { public virtual bool HidesHud {
get { return false; } get { return false; }
} }
/// <summary> Causes the screen to recreate all of its contained widgets. </summary>
/// <remarks> Typically used when bitmap font changes. </remarks>
public virtual void Recreate() {
Dispose();
Init();
}
} }
} }

View File

@ -15,7 +15,8 @@ namespace ClassicalSharp {
int hotbarCount; int hotbarCount;
Texture selectedBlock, background; Texture selectedBlock, background;
int blockSize, borderSize; int barHeight, selBlockSize, elemSize;
int barXOffset, borderSize;
public override bool HandlesKeyDown( Key key ) { public override bool HandlesKeyDown( Key key ) {
if( key >= Key.Number1 && key <= Key.Number9 ) { if( key >= Key.Number1 && key <= Key.Number9 ) {
@ -25,19 +26,20 @@ namespace ClassicalSharp {
return false; return false;
} }
static FastColour backCol = new FastColour( 60, 60, 60, 160 );
static FastColour outlineCol = new FastColour( 151, 120, 180 );
static FastColour selCol = new FastColour( 213, 200, 223 );
public override void Init() { public override void Init() {
blockSize = (int)(38 * game.GuiScale); float scale = 2 * game.GuiScale;
borderSize = (int)(3 * game.GuiScale); selBlockSize = (int)(24 * scale);
int width = blockSize * hotbarCount; barHeight = (int)(22 * scale);
X = game.Width / 2 - width / 2; Width = (int)(182 * scale);
Y = game.Height - blockSize; Height = barHeight;
Width = width; elemSize = (int)(16 * scale);
Height = blockSize; barXOffset = (int)(3 * scale);
MakeBackgroundTexture( width ); borderSize = (int)(4 * scale);
X = game.Width / 2 - Width / 2;
Y = game.Height - barHeight;
MakeBackgroundTexture();
MakeSelectionTexture(); MakeSelectionTexture();
} }
@ -48,21 +50,20 @@ namespace ClassicalSharp {
graphicsApi.SetBatchFormat( VertexFormat.Pos3fTex2fCol4b ); graphicsApi.SetBatchFormat( VertexFormat.Pos3fTex2fCol4b );
for( int i = 0; i < hotbarCount; i++ ) { for( int i = 0; i < hotbarCount; i++ ) {
int x = X + i * blockSize; byte block = (byte)game.Inventory.Hotbar[i];
IsometricBlockDrawer.Draw( game, (byte)game.Inventory.Hotbar[i], blockSize / 2 - borderSize - 2, int x = X + barXOffset + (elemSize + borderSize) * i + elemSize / 2;
x + 1 + blockSize / 2, game.Height - blockSize / 2 ); int y = game.Height - barHeight / 2;
float scale = (elemSize - 4) / 2f;
IsometricBlockDrawer.Draw( game, block, scale, x, y );
if( i == game.Inventory.HeldBlockIndex ) if( i == game.Inventory.HeldBlockIndex )
selectedBlock.X1 = x; selectedBlock.X1 = x - selBlockSize / 2;
} }
selectedBlock.Render( graphicsApi ); selectedBlock.Render( graphicsApi );
graphicsApi.Texturing = false; graphicsApi.Texturing = false;
} }
public override void Dispose() { public override void Dispose() { }
graphicsApi.DeleteTexture( ref selectedBlock );
graphicsApi.DeleteTexture( ref background );
}
public override void MoveTo( int newX, int newY ) { public override void MoveTo( int newX, int newY ) {
int diffX = newX - X, diffY = newY - Y; int diffX = newX - X, diffY = newY - Y;
@ -71,30 +72,16 @@ namespace ClassicalSharp {
Init(); Init();
} }
void MakeBackgroundTexture( int width ) { void MakeBackgroundTexture() {
Size size = new Size( width, blockSize ); TextureRec rec = new TextureRec( 0, 0, 182/256f, 22/256f );
using( Bitmap bmp = IDrawer2D.CreatePow2Bitmap( size ) ) background = new Texture( game.GuiTexId, X, Y, Width, Height, rec );
using( IDrawer2D drawer = game.Drawer2D )
{
drawer.SetBitmap( bmp );
drawer.Clear( backCol );
for( int xx = 0; xx < hotbarCount; xx++ ) {
drawer.DrawRectBounds( outlineCol, borderSize, xx * blockSize,
0, blockSize, blockSize );
}
background = drawer.Make2DTexture( bmp, size, X, Y );
}
} }
void MakeSelectionTexture() { void MakeSelectionTexture() {
Size size = new Size( blockSize, blockSize ); int y = game.Height - selBlockSize;
using( Bitmap bmp = IDrawer2D.CreatePow2Bitmap( size ) ) TextureRec rec = new TextureRec( 0, 22/256f, 24/256f, 24/256f );
using( IDrawer2D drawer = game.Drawer2D ) selectedBlock = new Texture( game.GuiTexId, 0, y,
{ selBlockSize, selBlockSize, rec );
drawer.SetBitmap( bmp );
drawer.DrawRectBounds( selCol, borderSize, 0, 0, blockSize, blockSize );
selectedBlock = drawer.Make2DTexture( bmp, size, 0, Y );
}
} }
} }
} }

View File

@ -35,8 +35,11 @@ namespace ClassicalSharp {
Height = defaultHeight; Height = defaultHeight;
} }
static FastColour boxCol = new FastColour( 169, 143, 192 ), shadowCol = new FastColour( 97, 81, 110 ); static TextureRec shadowRec = new TextureRec( 0, 66/256f, 200/256f, 20/256f );
//static FastColour boxCol = new FastColour( 29, 126, 192 ), shadowCol = new FastColour( 16, 72, 109 ); static TextureRec selectedRec = new TextureRec( 0, 86/256f, 200/256f, 20/256f );
static Texture shadowTex = new Texture( 0, 0, 0, 0, 0, shadowRec );
static Texture selectedTex = new Texture( 0, 0, 0, 0, 0, selectedRec );
public string Text; public string Text;
public void SetText( string text ) { public void SetText( string text ) {
graphicsApi.DeleteTexture( ref texture ); graphicsApi.DeleteTexture( ref texture );
@ -55,6 +58,11 @@ namespace ClassicalSharp {
public override void Render( double delta ) { public override void Render( double delta ) {
if( texture.IsValid ) { if( texture.IsValid ) {
Texture backTex = Active ? selectedTex : shadowTex;
backTex.ID = game.GuiTexId;
backTex.X1 = X; backTex.Y1 = Y;
backTex.Width = Width; backTex.Height = Height;
backTex.Render( graphicsApi );
FastColour col = Active ? FastColour.White : new FastColour( 200, 200, 200 ); FastColour col = Active ? FastColour.White : new FastColour( 200, 200, 200 );
texture.Render( graphicsApi, col ); texture.Render( graphicsApi, col );
} }
@ -78,26 +86,19 @@ namespace ClassicalSharp {
void MakeTexture( string text ) { void MakeTexture( string text ) {
DrawTextArgs args = new DrawTextArgs( text, font, true ); DrawTextArgs args = new DrawTextArgs( text, font, true );
Size size = game.Drawer2D.MeasureSize( ref args ); Size size = game.Drawer2D.MeasureChatSize( ref args );
int xOffset = Math.Max( size.Width, DesiredMaxWidth ) - size.Width; int xOffset = Math.Max( size.Width, DesiredMaxWidth ) - size.Width;
size.Width = Math.Max( size.Width, DesiredMaxWidth ); size.Width = Math.Max( size.Width, DesiredMaxWidth );
int yOffset = Math.Max( size.Height, DesiredMaxHeight ) - size.Height; int yOffset = Math.Max( size.Height, DesiredMaxHeight ) - size.Height;
size.Height = Math.Max( size.Height, DesiredMaxHeight ); size.Height = Math.Max( size.Height, DesiredMaxHeight );
Size baseSize = size;
const int borderSize = 3; // 1 px for base border, 2 px for shadow, 1 px for offset text
size.Width += borderSize; size.Height += borderSize;
using( Bitmap bmp = IDrawer2D.CreatePow2Bitmap( size ) ) using( Bitmap bmp = IDrawer2D.CreatePow2Bitmap( size ) )
using( IDrawer2D drawer = game.Drawer2D ) using( IDrawer2D drawer = game.Drawer2D )
{ {
drawer.SetBitmap( bmp ); drawer.SetBitmap( bmp );
drawer.DrawRoundedRect( shadowCol, 3, IDrawer2D.Offset, IDrawer2D.Offset,
baseSize.Width, baseSize.Height );
drawer.DrawRoundedRect( boxCol, 3, 0, 0, baseSize.Width, baseSize.Height );
args.SkipPartsCheck = true; args.SkipPartsCheck = true;
drawer.DrawText( ref args, 1 + xOffset / 2, 1 + yOffset / 2 ); drawer.DrawChatText( ref args, xOffset / 2, yOffset / 2 );
texture = drawer.Make2DTexture( bmp, size, 0, 0 ); texture = drawer.Make2DTexture( bmp, size, 0, 0 );
} }
} }

View File

@ -10,7 +10,7 @@ namespace ClassicalSharp {
public ChatTextWidget( Game game, Font font ) : base( game, font ) { public ChatTextWidget( Game game, Font font ) : base( game, font ) {
} }
public static ChatTextWidget Create( Game game, int x, int y, string text, Anchor horizontal, Anchor vertical, Font font ) { public static new ChatTextWidget Create( Game game, int x, int y, string text, Anchor horizontal, Anchor vertical, Font font ) {
ChatTextWidget widget = new ChatTextWidget( game, font ); ChatTextWidget widget = new ChatTextWidget( game, font );
widget.Init(); widget.Init();
widget.HorizontalAnchor = horizontal; widget.VerticalAnchor = vertical; widget.HorizontalAnchor = horizontal; widget.VerticalAnchor = vertical;

View File

@ -86,6 +86,9 @@
<Compile Include="2D\Drawing\DrawTextArgs.cs" /> <Compile Include="2D\Drawing\DrawTextArgs.cs" />
<Compile Include="2D\Drawing\GdiPlusDrawer2D.cs" /> <Compile Include="2D\Drawing\GdiPlusDrawer2D.cs" />
<Compile Include="2D\Drawing\IDrawer2D.cs" /> <Compile Include="2D\Drawing\IDrawer2D.cs" />
<Compile Include="2D\Screens\Bindings\AdvancedKeyBindingsScreen.cs" />
<Compile Include="2D\Screens\Bindings\KeyBindingsScreen.cs" />
<Compile Include="2D\Screens\Bindings\NormalKeyBindingsScreen.cs" />
<Compile Include="2D\Screens\BlockSelectScreen.cs" /> <Compile Include="2D\Screens\BlockSelectScreen.cs" />
<Compile Include="2D\Screens\ChatScreen.cs" /> <Compile Include="2D\Screens\ChatScreen.cs" />
<Compile Include="2D\Screens\ClickableScreen.cs" /> <Compile Include="2D\Screens\ClickableScreen.cs" />
@ -96,7 +99,6 @@
<Compile Include="2D\Screens\LoadingMapScreen.cs" /> <Compile Include="2D\Screens\LoadingMapScreen.cs" />
<Compile Include="2D\Screens\Menu\EnvSettingsScreen.cs" /> <Compile Include="2D\Screens\Menu\EnvSettingsScreen.cs" />
<Compile Include="2D\Screens\Menu\GuiOptionsScreen.cs" /> <Compile Include="2D\Screens\Menu\GuiOptionsScreen.cs" />
<Compile Include="2D\Screens\Menu\KeyBindingsScreen.cs" />
<Compile Include="2D\Screens\Menu\LoadLevelScreen.cs" /> <Compile Include="2D\Screens\Menu\LoadLevelScreen.cs" />
<Compile Include="2D\Screens\Menu\MenuInputScreen.cs" /> <Compile Include="2D\Screens\Menu\MenuInputScreen.cs" />
<Compile Include="2D\Screens\Menu\MenuScreen.cs" /> <Compile Include="2D\Screens\Menu\MenuScreen.cs" />
@ -258,6 +260,7 @@
<ItemGroup> <ItemGroup>
<Folder Include="2D\Drawing" /> <Folder Include="2D\Drawing" />
<Folder Include="2D\Screens" /> <Folder Include="2D\Screens" />
<Folder Include="2D\Screens\Bindings" />
<Folder Include="2D\Screens\Menu" /> <Folder Include="2D\Screens\Menu" />
<Folder Include="2D\Widgets" /> <Folder Include="2D\Widgets" />
<Folder Include="2D\Widgets\Menu" /> <Folder Include="2D\Widgets\Menu" />

View File

@ -111,7 +111,7 @@ namespace ClassicalSharp {
public int ChatLines = 12; public int ChatLines = 12;
public bool ClickableChat, HideGui, ShowFPS = true; public bool ClickableChat, HideGui, ShowFPS = true;
internal float HudScale = 1.0f, ChatScale = 1.0f; internal float HudScale = 1.0f, ChatScale = 1.0f;
public bool ViewBobbing, UseGuiPng, ShowBlockInHand; public bool ViewBobbing, ShowBlockInHand;
public bool UseSound, UseMusic; public bool UseSound, UseMusic;
public Animations Animations; public Animations Animations;

View File

@ -309,10 +309,7 @@ namespace ClassicalSharp {
activeScreen = screen; activeScreen = screen;
} }
public void RefreshHud() { public void RefreshHud() { hudScreen.Recreate(); }
hudScreen.Dispose();
hudScreen.Init();
}
public void ShowWarning( WarningScreen screen ) { public void ShowWarning( WarningScreen screen ) {
if( !(activeScreen is WarningScreen) ) { if( !(activeScreen is WarningScreen) ) {

View File

@ -6,8 +6,8 @@ namespace ClassicalSharp {
public enum KeyBinding { public enum KeyBinding {
Forward, Back, Left, Right, Jump, Respawn, SetSpawn, OpenChat, Forward, Back, Left, Right, Jump, Respawn, SetSpawn, OpenChat,
SendChat, PauseOrExit, OpenInventory, ViewDistance, PlayerList, SendChat, PauseOrExit, OpenInventory, ViewDistance, PlayerList,
Speed, NoClip, Fly, FlyUp, FlyDown, HideGui, HideFps, Speed, NoClip, Fly, FlyUp, FlyDown, ExtendedInput, HideFps,
Screenshot, Fullscreen, ThirdPersonCamera, ExtendedInput, Screenshot, Fullscreen, ThirdPersonCamera, HideGui,
} }
public class KeyMap { public class KeyMap {
@ -46,9 +46,9 @@ namespace ClassicalSharp {
Keys[8] = Key.Enter; Keys[9] = Key.Escape; Keys[10] = Key.B; Keys[8] = Key.Enter; Keys[9] = Key.Escape; Keys[10] = Key.B;
Keys[11] = Key.F; Keys[12] = Key.Tab; Keys[13] = Key.ShiftLeft; Keys[11] = Key.F; Keys[12] = Key.Tab; Keys[13] = Key.ShiftLeft;
Keys[14] = Key.X; Keys[15] = Key.Z; Keys[16] = Key.Q; Keys[14] = Key.X; Keys[15] = Key.Z; Keys[16] = Key.Q;
Keys[17] = Key.E; Keys[18] = Key.F1; Keys[19] = Key.F3; Keys[17] = Key.E; Keys[18] = Key.AltLeft; Keys[19] = Key.F3;
Keys[20] = Key.F12; Keys[21] = Key.F11; Keys[22] = Key.F5; Keys[20] = Key.F12; Keys[21] = Key.F11; Keys[22] = Key.F5;
Keys[23] = Key.AltLeft; Keys[23] = Key.F1;
LoadKeyBindings(); LoadKeyBindings();
} }