From a13d3147bceda0e2d1d5b3fb09b2597453f79ab3 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Mon, 30 Nov 2015 14:16:48 +1100 Subject: [PATCH] Use gui.png. --- .../Bindings/AdvancedKeyBindingsScreen.cs | 33 +++++++++ .../{Menu => Bindings}/KeyBindingsScreen.cs | 43 ++++-------- .../Bindings/NormalKeyBindingsScreen.cs | 33 +++++++++ ClassicalSharp/2D/Screens/ClickableScreen.cs | 7 ++ ClassicalSharp/2D/Screens/FilesScreen.cs | 3 +- ClassicalSharp/2D/Screens/FpsScreen.cs | 5 +- ClassicalSharp/2D/Screens/HotkeyScreen.cs | 6 +- .../2D/Screens/Menu/EnvSettingsScreen.cs | 9 +-- .../2D/Screens/Menu/GuiOptionsScreen.cs | 13 +--- .../2D/Screens/Menu/LoadLevelScreen.cs | 9 +-- .../2D/Screens/Menu/MenuInputScreen.cs | 2 +- ClassicalSharp/2D/Screens/Menu/MenuScreen.cs | 5 ++ .../2D/Screens/Menu/OptionsScreen.cs | 11 +-- ClassicalSharp/2D/Screens/Menu/PauseScreen.cs | 10 +-- .../2D/Screens/Menu/SaveLevelScreen.cs | 6 +- .../2D/Screens/Menu/TexturePackScreen.cs | 8 +-- ClassicalSharp/2D/Screens/Screen.cs | 7 ++ .../2D/Widgets/BlockHotbarWidget.cs | 69 ++++++++----------- ClassicalSharp/2D/Widgets/ButtonWidget.cs | 25 +++---- .../2D/Widgets/Chat/ChatTextWidget.cs | 2 +- ClassicalSharp/ClassicalSharp.csproj | 5 +- ClassicalSharp/Game/Game.Properties.cs | 2 +- ClassicalSharp/Game/Game.cs | 5 +- ClassicalSharp/Game/KeyMap.cs | 8 +-- 24 files changed, 177 insertions(+), 149 deletions(-) create mode 100644 ClassicalSharp/2D/Screens/Bindings/AdvancedKeyBindingsScreen.cs rename ClassicalSharp/2D/Screens/{Menu => Bindings}/KeyBindingsScreen.cs (56%) create mode 100644 ClassicalSharp/2D/Screens/Bindings/NormalKeyBindingsScreen.cs diff --git a/ClassicalSharp/2D/Screens/Bindings/AdvancedKeyBindingsScreen.cs b/ClassicalSharp/2D/Screens/Bindings/AdvancedKeyBindingsScreen.cs new file mode 100644 index 000000000..90ccaa7e8 --- /dev/null +++ b/ClassicalSharp/2D/Screens/Bindings/AdvancedKeyBindingsScreen.cs @@ -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 ) ); + } + } +} \ No newline at end of file diff --git a/ClassicalSharp/2D/Screens/Menu/KeyBindingsScreen.cs b/ClassicalSharp/2D/Screens/Bindings/KeyBindingsScreen.cs similarity index 56% rename from ClassicalSharp/2D/Screens/Menu/KeyBindingsScreen.cs rename to ClassicalSharp/2D/Screens/Bindings/KeyBindingsScreen.cs index 6f14db6d1..a1a360198 100644 --- a/ClassicalSharp/2D/Screens/Menu/KeyBindingsScreen.cs +++ b/ClassicalSharp/2D/Screens/Bindings/KeyBindingsScreen.cs @@ -4,7 +4,7 @@ using OpenTK.Input; namespace ClassicalSharp { - public class KeyBindingsScreen : MenuScreen { + public abstract class KeyBindingsScreen : MenuScreen { public KeyBindingsScreen( Game game ) : base( game ) { } @@ -20,43 +20,33 @@ namespace ClassicalSharp { Font keyFont; TextWidget statusWidget; static string[] keyNames; - static string[] descriptions = new [] { "Forward", "Back", "Left", "Right", "Jump", "Respawn", - "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", }; + protected string[] descriptions; public override void Init() { + base.Init(); if( keyNames == null ) keyNames = Enum.GetNames( typeof( Key ) ); - keyFont = new Font( "Arial", 14, FontStyle.Bold ); - regularFont = new Font( "Arial", 14, FontStyle.Italic ); - titleFont = new Font( "Arial", 16, FontStyle.Bold ); - 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 ); + keyFont = new Font( "Arial", 15, FontStyle.Bold ); + regularFont = new Font( "Arial", 15, FontStyle.Italic ); + statusWidget = TextWidget.Create( game, 0, 130, "", Anchor.Centre, Anchor.Centre, regularFont ); } - int index; - void MakeKeys( int start, int len, int x ) { - int y = -200; + protected int index; + protected void MakeKeys( KeyBinding start, int descStart, int len, int x ) { + int y = -180; for( int i = 0; i < len; i++ ) { KeyBinding binding = (KeyBinding)((int)start + i); - string text = descriptions[start + i] + ": " + string text = descriptions[descStart + i] + ": " + keyNames[(int)game.Mapping( binding )]; - buttons[index++] = ButtonWidget.Create( game, x, y, 240, 25, text, - Anchor.Centre, Anchor.Centre, keyFont, OnWidgetClick ); - y += 30; + buttons[index++] = ButtonWidget.Create( game, x, y, 260, 35, text, + Anchor.Centre, Anchor.Centre, keyFont, OnBindingClick ); + y += 45; } } ButtonWidget curWidget; - void OnWidgetClick( Game game, Widget realWidget ) { + void OnBindingClick( Game game, Widget realWidget ) { this.curWidget = (ButtonWidget)realWidget; int index = Array.IndexOf( buttons, curWidget ); string text = "&ePress new key binding for " + descriptions[index] + ":"; @@ -89,11 +79,6 @@ namespace ClassicalSharp { return true; } - ButtonWidget MakeOther( int x, int y, int width, string text, Anchor hAnchor, Action onClick ) { - return ButtonWidget.Create( game, x, y, width, 35, text, - hAnchor, Anchor.BottomOrRight, titleFont, onClick ); - } - public override void Dispose() { keyFont.Dispose(); base.Dispose(); diff --git a/ClassicalSharp/2D/Screens/Bindings/NormalKeyBindingsScreen.cs b/ClassicalSharp/2D/Screens/Bindings/NormalKeyBindingsScreen.cs new file mode 100644 index 000000000..c6cf6ca98 --- /dev/null +++ b/ClassicalSharp/2D/Screens/Bindings/NormalKeyBindingsScreen.cs @@ -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 ) ); + } + } +} \ No newline at end of file diff --git a/ClassicalSharp/2D/Screens/ClickableScreen.cs b/ClassicalSharp/2D/Screens/ClickableScreen.cs index 8ff9252a7..b696ec2ae 100644 --- a/ClassicalSharp/2D/Screens/ClickableScreen.cs +++ b/ClassicalSharp/2D/Screens/ClickableScreen.cs @@ -44,5 +44,12 @@ namespace ClassicalSharp { protected virtual void WidgetSelected( Widget widget ) { } + + protected ButtonWidget MakeBack( bool toGame, Font font, Action 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 ); + } } } \ No newline at end of file diff --git a/ClassicalSharp/2D/Screens/FilesScreen.cs b/ClassicalSharp/2D/Screens/FilesScreen.cs index 9adc6a02f..ca46ce1ac 100644 --- a/ClassicalSharp/2D/Screens/FilesScreen.cs +++ b/ClassicalSharp/2D/Screens/FilesScreen.cs @@ -20,7 +20,8 @@ namespace ClassicalSharp { public override void Init() { textFont = new Font( "Arial", 14, 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.Init(); diff --git a/ClassicalSharp/2D/Screens/FpsScreen.cs b/ClassicalSharp/2D/Screens/FpsScreen.cs index b179cd4a8..cc3364736 100644 --- a/ClassicalSharp/2D/Screens/FpsScreen.cs +++ b/ClassicalSharp/2D/Screens/FpsScreen.cs @@ -82,10 +82,7 @@ namespace ClassicalSharp { game.Events.ChatFontChanged -= ChatFontChanged; } - void ChatFontChanged( object sender, EventArgs e ) { - Dispose(); - Init(); - } + void ChatFontChanged( object sender, EventArgs e ) { Recreate(); } public override void OnResize( int oldWidth, int oldHeight, int width, int height ) { } diff --git a/ClassicalSharp/2D/Screens/HotkeyScreen.cs b/ClassicalSharp/2D/Screens/HotkeyScreen.cs index ab5105811..0321f78e2 100644 --- a/ClassicalSharp/2D/Screens/HotkeyScreen.cs +++ b/ClassicalSharp/2D/Screens/HotkeyScreen.cs @@ -73,7 +73,7 @@ namespace ClassicalSharp { public override void Init() { game.Keyboard.KeyRepeat = true; - titleFont = new Font( "Arial", 16, FontStyle.Bold ); + base.Init(); regularFont = new Font( "Arial", 16, FontStyle.Regular ); hintFont = new Font( "Arial", 14, FontStyle.Italic ); 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( true ) ), - ButtonWidget.Create( game, 0, 5, 160, 35, "Back to menu", Anchor.Centre, Anchor.BottomOrRight, - titleFont, (g, w) => g.SetNewScreen( new PauseScreen( g ) ) ), + MakeBack( false, titleFont, + (g, w) => g.SetNewScreen( new PauseScreen( g ) ) ), null, // current key null, // current modifiers null, // leave open current diff --git a/ClassicalSharp/2D/Screens/Menu/EnvSettingsScreen.cs b/ClassicalSharp/2D/Screens/Menu/EnvSettingsScreen.cs index 3173a1f5b..81e711a86 100644 --- a/ClassicalSharp/2D/Screens/Menu/EnvSettingsScreen.cs +++ b/ClassicalSharp/2D/Screens/Menu/EnvSettingsScreen.cs @@ -49,8 +49,8 @@ namespace ClassicalSharp { g => g.Map.EdgeHeight.ToString(), (g, v) => g.Map.SetEdgeLevel( Int32.Parse( v ) ) ), - MakeOther( 0, 5, 160, "Back to menu", Anchor.Centre, - (g, w) => g.SetNewScreen( new PauseScreen( g ) ) ), + MakeBack( false, titleFont, + (g, w) => g.SetNewScreen( new PauseScreen( g ) ) ), null, }; buttons[7].Metadata = typeof(Weather); @@ -77,10 +77,5 @@ namespace ClassicalSharp { widget.SetValue = setter; return widget; } - - ButtonWidget MakeOther( int x, int y, int width, string text, Anchor hAnchor, Action onClick ) { - return ButtonWidget.Create( game, x, y, width, 35, text, - hAnchor, Anchor.BottomOrRight, titleFont, onClick ); - } } } \ No newline at end of file diff --git a/ClassicalSharp/2D/Screens/Menu/GuiOptionsScreen.cs b/ClassicalSharp/2D/Screens/Menu/GuiOptionsScreen.cs index 1ebbbb062..9c75c9f2b 100644 --- a/ClassicalSharp/2D/Screens/Menu/GuiOptionsScreen.cs +++ b/ClassicalSharp/2D/Screens/Menu/GuiOptionsScreen.cs @@ -37,10 +37,6 @@ namespace ClassicalSharp { 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 Make( 140, -150, "Clickable chat", Anchor.Centre, OnWidgetClick, g => g.ClickableChat ? "yes" : "no", @@ -69,10 +65,11 @@ namespace ClassicalSharp { Options.Set( OptionsKey.ArialChatFont, v == "yes" ); game.Events.RaiseChatFontChanged(); g.RefreshHud(); + Recreate(); } ), - MakeOther( 0, 5, 160, "Back to menu", Anchor.Centre, + MakeBack( false, titleFont, (g, w) => g.SetNewScreen( new PauseScreen( g ) ) ), null, }; @@ -81,7 +78,6 @@ namespace ClassicalSharp { new IntegerValidator( 1, 179 ), new BooleanValidator(), new RealValidator( 0.25f, 5f ), - new BooleanValidator(), new BooleanValidator(), new RealValidator( 0.25f, 5f ), @@ -99,10 +95,5 @@ namespace ClassicalSharp { widget.SetValue = setter; return widget; } - - ButtonWidget MakeOther( int x, int y, int width, string text, Anchor hAnchor, Action onClick ) { - return ButtonWidget.Create( game, x, y, width, 35, text, - hAnchor, Anchor.BottomOrRight, titleFont, onClick ); - } } } \ No newline at end of file diff --git a/ClassicalSharp/2D/Screens/Menu/LoadLevelScreen.cs b/ClassicalSharp/2D/Screens/Menu/LoadLevelScreen.cs index 982450b93..72596c91a 100644 --- a/ClassicalSharp/2D/Screens/Menu/LoadLevelScreen.cs +++ b/ClassicalSharp/2D/Screens/Menu/LoadLevelScreen.cs @@ -23,13 +23,8 @@ namespace ClassicalSharp { public override void Init() { base.Init(); - buttons[buttons.Length - 1] = - Make( 0, 5, "Back to menu", (g, w) => g.SetNewScreen( new PauseScreen( g ) ) ); - } - - ButtonWidget Make( int x, int y, string text, Action onClick ) { - return ButtonWidget.Create( game, x, y, 160, 35, text, - Anchor.Centre, Anchor.BottomOrRight, titleFont, onClick ); + buttons[buttons.Length - 1] = + MakeBack( false, titleFont, (g, w) => g.SetNewScreen( new PauseScreen( g ) ) ); } protected override void TextButtonClick( Game game, Widget widget ) { diff --git a/ClassicalSharp/2D/Screens/Menu/MenuInputScreen.cs b/ClassicalSharp/2D/Screens/Menu/MenuInputScreen.cs index 25f0ea3ea..21d5276aa 100644 --- a/ClassicalSharp/2D/Screens/Menu/MenuInputScreen.cs +++ b/ClassicalSharp/2D/Screens/Menu/MenuInputScreen.cs @@ -27,7 +27,7 @@ namespace ClassicalSharp { } public override void Init() { - titleFont = new Font( "Arial", 16, FontStyle.Bold ); + base.Init(); regularFont = new Font( "Arial", 16, FontStyle.Regular ); hintFont = new Font( "Arial", 14, FontStyle.Italic ); game.Keyboard.KeyRepeat = true; diff --git a/ClassicalSharp/2D/Screens/Menu/MenuScreen.cs b/ClassicalSharp/2D/Screens/Menu/MenuScreen.cs index 80e89eaac..0e0be9664 100644 --- a/ClassicalSharp/2D/Screens/Menu/MenuScreen.cs +++ b/ClassicalSharp/2D/Screens/Menu/MenuScreen.cs @@ -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() { for( int i = 0; i < buttons.Length; i++ ) { if( buttons[i] == null ) continue; diff --git a/ClassicalSharp/2D/Screens/Menu/OptionsScreen.cs b/ClassicalSharp/2D/Screens/Menu/OptionsScreen.cs index f2a0aad6c..146c70c4d 100644 --- a/ClassicalSharp/2D/Screens/Menu/OptionsScreen.cs +++ b/ClassicalSharp/2D/Screens/Menu/OptionsScreen.cs @@ -42,7 +42,7 @@ namespace ClassicalSharp { // Column 2 !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, v) => { ((SinglePlayerServer)network).physics.Enabled = v == "yes"; @@ -63,7 +63,7 @@ namespace ClassicalSharp { g => Options.GetBool( OptionsKey.AutoCloseLauncher, false ) ? "yes" : "no", (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.LocalPlayer.CanPushbackBlocks ? "yes" : "no", (g, v) => { @@ -76,7 +76,7 @@ namespace ClassicalSharp { (g, v) => { g.MouseSensitivity = Int32.Parse( 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 ) ) ), null, }; @@ -107,10 +107,5 @@ namespace ClassicalSharp { widget.SetValue = setter; return widget; } - - ButtonWidget MakeOther( int x, int y, int width, string text, Anchor hAnchor, Action onClick ) { - return ButtonWidget.Create( game, x, y, width, 35, text, - hAnchor, Anchor.BottomOrRight, titleFont, onClick ); - } } } \ No newline at end of file diff --git a/ClassicalSharp/2D/Screens/Menu/PauseScreen.cs b/ClassicalSharp/2D/Screens/Menu/PauseScreen.cs index 0df82f6d6..e7a854230 100644 --- a/ClassicalSharp/2D/Screens/Menu/PauseScreen.cs +++ b/ClassicalSharp/2D/Screens/Menu/PauseScreen.cs @@ -17,17 +17,17 @@ namespace ClassicalSharp { } public override void Init() { - titleFont = new Font( "Arial", 16, FontStyle.Bold ); + base.Init(); buttons = new ButtonWidget[] { // Column 1 Make( -140, -150, "Options", Anchor.Centre, (g, w) => g.SetNewScreen( new OptionsScreen( g ) ) ), Make( -140, -100, "Gui options", Anchor.Centre, (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 ) ) ), 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, (g, w) => g.SetNewScreen( new HotkeyScreen( g ) ) ), // Column 2 @@ -42,8 +42,8 @@ namespace ClassicalSharp { // Other MakeOther( 10, 5, 120, "Quit game", Anchor.BottomOrRight, (g, w) => g.Exit() ), - MakeOther( 0, 5, 160, "Back to game", Anchor.Centre, - (g, w) => g.SetNewScreen( null ) ), + MakeBack( true, titleFont, + (g, w) => g.SetNewScreen( null ) ), }; } diff --git a/ClassicalSharp/2D/Screens/Menu/SaveLevelScreen.cs b/ClassicalSharp/2D/Screens/Menu/SaveLevelScreen.cs index 0d92bfa12..124c8fc3c 100644 --- a/ClassicalSharp/2D/Screens/Menu/SaveLevelScreen.cs +++ b/ClassicalSharp/2D/Screens/Menu/SaveLevelScreen.cs @@ -47,7 +47,7 @@ namespace ClassicalSharp { public override void Init() { game.Keyboard.KeyRepeat = true; - titleFont = new Font( "Arial", 16, FontStyle.Bold ); + base.Init(); regularFont = new Font( "Arial", 16, FontStyle.Regular ); hintFont = new Font( "Arial", 14, FontStyle.Italic ); @@ -58,8 +58,8 @@ namespace ClassicalSharp { buttons = new [] { ButtonWidget.Create( game, 260, 50, 60, 30, "Save", Anchor.Centre, Anchor.Centre, titleFont, OkButtonClick ), - ButtonWidget.Create( game, 0, 5, 160, 35, "Back to menu", Anchor.Centre, Anchor.BottomOrRight, - titleFont, (g, w) => g.SetNewScreen( new PauseScreen( g ) ) ), + MakeBack( false, titleFont, + (g, w) => g.SetNewScreen( new PauseScreen( g ) ) ), }; } diff --git a/ClassicalSharp/2D/Screens/Menu/TexturePackScreen.cs b/ClassicalSharp/2D/Screens/Menu/TexturePackScreen.cs index 307f74910..ce5144135 100644 --- a/ClassicalSharp/2D/Screens/Menu/TexturePackScreen.cs +++ b/ClassicalSharp/2D/Screens/Menu/TexturePackScreen.cs @@ -22,12 +22,7 @@ namespace ClassicalSharp { public override void Init() { base.Init(); buttons[buttons.Length - 1] = - Make( 0, 5, "Back to menu", (g, w) => g.SetNewScreen( new PauseScreen( g ) ) ); - } - - ButtonWidget Make( int x, int y, string text, Action onClick ) { - return ButtonWidget.Create( game, x, y, 160, 35, text, - Anchor.Centre, Anchor.BottomOrRight, titleFont, onClick ); + MakeBack( false, titleFont, (g, w) => g.SetNewScreen( new PauseScreen( g ) ) ); } protected override void TextButtonClick( Game game, Widget widget ) { @@ -36,6 +31,7 @@ namespace ClassicalSharp { game.DefaultTexturePack = path; TexturePackExtractor extractor = new TexturePackExtractor(); extractor.Extract( path, game ); + Recreate(); } } } diff --git a/ClassicalSharp/2D/Screens/Screen.cs b/ClassicalSharp/2D/Screens/Screen.cs index 702e0940d..ba05409c8 100644 --- a/ClassicalSharp/2D/Screens/Screen.cs +++ b/ClassicalSharp/2D/Screens/Screen.cs @@ -22,5 +22,12 @@ namespace ClassicalSharp { public virtual bool HidesHud { get { return false; } } + + /// Causes the screen to recreate all of its contained widgets. + /// Typically used when bitmap font changes. + public virtual void Recreate() { + Dispose(); + Init(); + } } } diff --git a/ClassicalSharp/2D/Widgets/BlockHotbarWidget.cs b/ClassicalSharp/2D/Widgets/BlockHotbarWidget.cs index fbc2ebb52..7368c0841 100644 --- a/ClassicalSharp/2D/Widgets/BlockHotbarWidget.cs +++ b/ClassicalSharp/2D/Widgets/BlockHotbarWidget.cs @@ -15,7 +15,8 @@ namespace ClassicalSharp { int hotbarCount; Texture selectedBlock, background; - int blockSize, borderSize; + int barHeight, selBlockSize, elemSize; + int barXOffset, borderSize; public override bool HandlesKeyDown( Key key ) { if( key >= Key.Number1 && key <= Key.Number9 ) { @@ -25,19 +26,20 @@ namespace ClassicalSharp { 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() { - blockSize = (int)(38 * game.GuiScale); - borderSize = (int)(3 * game.GuiScale); - int width = blockSize * hotbarCount; - X = game.Width / 2 - width / 2; - Y = game.Height - blockSize; + float scale = 2 * game.GuiScale; + selBlockSize = (int)(24 * scale); + barHeight = (int)(22 * scale); + Width = (int)(182 * scale); + Height = barHeight; - Width = width; - Height = blockSize; - MakeBackgroundTexture( width ); + elemSize = (int)(16 * scale); + barXOffset = (int)(3 * scale); + borderSize = (int)(4 * scale); + X = game.Width / 2 - Width / 2; + Y = game.Height - barHeight; + + MakeBackgroundTexture(); MakeSelectionTexture(); } @@ -48,21 +50,20 @@ namespace ClassicalSharp { graphicsApi.SetBatchFormat( VertexFormat.Pos3fTex2fCol4b ); for( int i = 0; i < hotbarCount; i++ ) { - int x = X + i * blockSize; - IsometricBlockDrawer.Draw( game, (byte)game.Inventory.Hotbar[i], blockSize / 2 - borderSize - 2, - x + 1 + blockSize / 2, game.Height - blockSize / 2 ); + byte block = (byte)game.Inventory.Hotbar[i]; + int x = X + barXOffset + (elemSize + borderSize) * i + elemSize / 2; + int y = game.Height - barHeight / 2; + float scale = (elemSize - 4) / 2f; + IsometricBlockDrawer.Draw( game, block, scale, x, y ); if( i == game.Inventory.HeldBlockIndex ) - selectedBlock.X1 = x; + selectedBlock.X1 = x - selBlockSize / 2; } selectedBlock.Render( graphicsApi ); graphicsApi.Texturing = false; } - public override void Dispose() { - graphicsApi.DeleteTexture( ref selectedBlock ); - graphicsApi.DeleteTexture( ref background ); - } + public override void Dispose() { } public override void MoveTo( int newX, int newY ) { int diffX = newX - X, diffY = newY - Y; @@ -71,30 +72,16 @@ namespace ClassicalSharp { Init(); } - void MakeBackgroundTexture( int width ) { - Size size = new Size( width, blockSize ); - using( Bitmap bmp = IDrawer2D.CreatePow2Bitmap( size ) ) - 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 MakeBackgroundTexture() { + TextureRec rec = new TextureRec( 0, 0, 182/256f, 22/256f ); + background = new Texture( game.GuiTexId, X, Y, Width, Height, rec ); } void MakeSelectionTexture() { - Size size = new Size( blockSize, blockSize ); - using( Bitmap bmp = IDrawer2D.CreatePow2Bitmap( size ) ) - using( IDrawer2D drawer = game.Drawer2D ) - { - drawer.SetBitmap( bmp ); - drawer.DrawRectBounds( selCol, borderSize, 0, 0, blockSize, blockSize ); - selectedBlock = drawer.Make2DTexture( bmp, size, 0, Y ); - } + int y = game.Height - selBlockSize; + TextureRec rec = new TextureRec( 0, 22/256f, 24/256f, 24/256f ); + selectedBlock = new Texture( game.GuiTexId, 0, y, + selBlockSize, selBlockSize, rec ); } } } \ No newline at end of file diff --git a/ClassicalSharp/2D/Widgets/ButtonWidget.cs b/ClassicalSharp/2D/Widgets/ButtonWidget.cs index 8410a70c0..2bf631fcd 100644 --- a/ClassicalSharp/2D/Widgets/ButtonWidget.cs +++ b/ClassicalSharp/2D/Widgets/ButtonWidget.cs @@ -35,8 +35,11 @@ namespace ClassicalSharp { Height = defaultHeight; } - static FastColour boxCol = new FastColour( 169, 143, 192 ), shadowCol = new FastColour( 97, 81, 110 ); - //static FastColour boxCol = new FastColour( 29, 126, 192 ), shadowCol = new FastColour( 16, 72, 109 ); + static TextureRec shadowRec = new TextureRec( 0, 66/256f, 200/256f, 20/256f ); + 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 void SetText( string text ) { graphicsApi.DeleteTexture( ref texture ); @@ -55,6 +58,11 @@ namespace ClassicalSharp { public override void Render( double delta ) { 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 ); texture.Render( graphicsApi, col ); } @@ -78,26 +86,19 @@ namespace ClassicalSharp { void MakeTexture( string text ) { 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; size.Width = Math.Max( size.Width, DesiredMaxWidth ); int yOffset = Math.Max( size.Height, DesiredMaxHeight ) - size.Height; 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( IDrawer2D drawer = game.Drawer2D ) { - 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 ); - + drawer.SetBitmap( bmp ); 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 ); } } diff --git a/ClassicalSharp/2D/Widgets/Chat/ChatTextWidget.cs b/ClassicalSharp/2D/Widgets/Chat/ChatTextWidget.cs index 0dc7c9bf3..aa3f7d890 100644 --- a/ClassicalSharp/2D/Widgets/Chat/ChatTextWidget.cs +++ b/ClassicalSharp/2D/Widgets/Chat/ChatTextWidget.cs @@ -10,7 +10,7 @@ namespace ClassicalSharp { 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 ); widget.Init(); widget.HorizontalAnchor = horizontal; widget.VerticalAnchor = vertical; diff --git a/ClassicalSharp/ClassicalSharp.csproj b/ClassicalSharp/ClassicalSharp.csproj index e9be496bf..2feb36de6 100644 --- a/ClassicalSharp/ClassicalSharp.csproj +++ b/ClassicalSharp/ClassicalSharp.csproj @@ -86,6 +86,9 @@ + + + @@ -96,7 +99,6 @@ - @@ -258,6 +260,7 @@ + diff --git a/ClassicalSharp/Game/Game.Properties.cs b/ClassicalSharp/Game/Game.Properties.cs index 1c9b4240e..f6337cbca 100644 --- a/ClassicalSharp/Game/Game.Properties.cs +++ b/ClassicalSharp/Game/Game.Properties.cs @@ -111,7 +111,7 @@ namespace ClassicalSharp { public int ChatLines = 12; public bool ClickableChat, HideGui, ShowFPS = true; internal float HudScale = 1.0f, ChatScale = 1.0f; - public bool ViewBobbing, UseGuiPng, ShowBlockInHand; + public bool ViewBobbing, ShowBlockInHand; public bool UseSound, UseMusic; public Animations Animations; diff --git a/ClassicalSharp/Game/Game.cs b/ClassicalSharp/Game/Game.cs index 60641152f..8d903ab1c 100644 --- a/ClassicalSharp/Game/Game.cs +++ b/ClassicalSharp/Game/Game.cs @@ -309,10 +309,7 @@ namespace ClassicalSharp { activeScreen = screen; } - public void RefreshHud() { - hudScreen.Dispose(); - hudScreen.Init(); - } + public void RefreshHud() { hudScreen.Recreate(); } public void ShowWarning( WarningScreen screen ) { if( !(activeScreen is WarningScreen) ) { diff --git a/ClassicalSharp/Game/KeyMap.cs b/ClassicalSharp/Game/KeyMap.cs index 0c5e073c2..5600a1150 100644 --- a/ClassicalSharp/Game/KeyMap.cs +++ b/ClassicalSharp/Game/KeyMap.cs @@ -6,8 +6,8 @@ namespace ClassicalSharp { public enum KeyBinding { Forward, Back, Left, Right, Jump, Respawn, SetSpawn, OpenChat, SendChat, PauseOrExit, OpenInventory, ViewDistance, PlayerList, - Speed, NoClip, Fly, FlyUp, FlyDown, HideGui, HideFps, - Screenshot, Fullscreen, ThirdPersonCamera, ExtendedInput, + Speed, NoClip, Fly, FlyUp, FlyDown, ExtendedInput, HideFps, + Screenshot, Fullscreen, ThirdPersonCamera, HideGui, } public class KeyMap { @@ -46,9 +46,9 @@ namespace ClassicalSharp { 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[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[23] = Key.AltLeft; + Keys[23] = Key.F1; LoadKeyBindings(); }