diff --git a/ClassicalSharp/2D/GuiElement.cs b/ClassicalSharp/2D/GuiElement.cs index d99ffbdc2..f0d0b6879 100644 --- a/ClassicalSharp/2D/GuiElement.cs +++ b/ClassicalSharp/2D/GuiElement.cs @@ -32,9 +32,7 @@ namespace ClassicalSharp.Gui { /// Causes the gui element to recreate all of its sub-elements and/or textures. /// Typically used when bitmap font changes. - public virtual void Recreate() { - Dispose(); Init(); - } + public void Recreate() { Dispose(); Init(); } /// Called when the game window is resized. public abstract void OnResize( int width, int height ); diff --git a/ClassicalSharp/2D/Screens/DeathScreen.cs b/ClassicalSharp/2D/Screens/DeathScreen.cs new file mode 100644 index 000000000..2e549c023 --- /dev/null +++ b/ClassicalSharp/2D/Screens/DeathScreen.cs @@ -0,0 +1,37 @@ +// ClassicalSharp copyright 2014-2016 UnknownShadow200 | Licensed under MIT +using System; +using System.Drawing; +using ClassicalSharp.Gui.Widgets; +using OpenTK.Input; + +namespace ClassicalSharp.Gui.Screens { + public class DeathScreen : MenuScreen { + + public DeathScreen( Game game ) : base( game ) { + } + + public override void Init() { + titleFont = new Font( game.FontName, 16, FontStyle.Bold ); + regularFont = new Font( game.FontName, 40, FontStyle.Regular ); + + widgets = new Widget[] { + ChatTextWidget.Create( game, 0, -150, "Game over!", Anchor.Centre, Anchor.Centre, regularFont ), + ChatTextWidget.Create( game, 0, -75, "Score: 0", Anchor.Centre, Anchor.Centre, titleFont ), + ButtonWidget.Create( game, 0, 25, 401, 40, "Generate new level...", + Anchor.Centre, Anchor.Centre, titleFont, GenLevelClick ), + ButtonWidget.Create( game, 0, 75, 401, 40, "Load level...", + Anchor.Centre, Anchor.Centre, titleFont, LoadLevelClick ), + }; + } + + void GenLevelClick( Game g, Widget w, MouseButton mouseBtn ) { + if( mouseBtn != MouseButton.Left ) return; + game.Gui.SetNewScreen( new GenLevelScreen( game ) ); + } + + void LoadLevelClick( Game g, Widget w, MouseButton mouseBtn ) { + if( mouseBtn != MouseButton.Left ) return; + game.Gui.SetNewScreen( new LoadLevelScreen( game ) ); + } + } +} diff --git a/ClassicalSharp/2D/Screens/ErrorScreen.cs b/ClassicalSharp/2D/Screens/ErrorScreen.cs index ef3591764..a5be0eb02 100644 --- a/ClassicalSharp/2D/Screens/ErrorScreen.cs +++ b/ClassicalSharp/2D/Screens/ErrorScreen.cs @@ -77,7 +77,7 @@ namespace ClassicalSharp.Gui.Screens { return HandleMouseMove( widgets, mouseX, mouseY ); } - public override bool HandlesMouseScroll( int delta ) { return true; } + public override bool HandlesMouseScroll( int delta ) { return true; } public override bool HandlesMouseUp( int mouseX, int mouseY, MouseButton button ) { return true; } diff --git a/ClassicalSharp/2D/Screens/FpsScreen.cs b/ClassicalSharp/2D/Screens/FpsScreen.cs index 0a8138cea..c0349285b 100644 --- a/ClassicalSharp/2D/Screens/FpsScreen.cs +++ b/ClassicalSharp/2D/Screens/FpsScreen.cs @@ -113,7 +113,8 @@ namespace ClassicalSharp.Gui.Screens { int index = 0; Texture tex = posAtlas.tex; tex.X1 = 2; tex.Width = (short)posAtlas.offset; - IGraphicsApi.Make2DQuad( ref tex, FastColour.White, game.ModelCache.vertices, ref index ); + IGraphicsApi.Make2DQuad( ref tex, FastColour.WhitePacked, + game.ModelCache.vertices, ref index ); Vector3I pos = Vector3I.Floor( game.LocalPlayer.Position ); posAtlas.curX = posAtlas.offset + 2; diff --git a/ClassicalSharp/2D/Screens/LoadingMapScreen.cs b/ClassicalSharp/2D/Screens/LoadingMapScreen.cs index 3b8fc51ca..cccf08b3b 100644 --- a/ClassicalSharp/2D/Screens/LoadingMapScreen.cs +++ b/ClassicalSharp/2D/Screens/LoadingMapScreen.cs @@ -42,7 +42,7 @@ namespace ClassicalSharp.Gui.Screens { VertexP3fT2fC4b[] vertices = game.ModelCache.vertices; int index = 0, atlasIndex = 0; int drawnY = 0, height = game.Height; - FastColour col = new FastColour( 64, 64, 64 ); + int col = new FastColour( 64, 64, 64 ).Pack(); int texLoc = game.BlockInfo.GetTextureLoc( Block.Dirt, Side.Top ); TerrainAtlas1D atlas = game.TerrainAtlas1D; diff --git a/ClassicalSharp/2D/Screens/Menu/EditHotkeyScreen.cs b/ClassicalSharp/2D/Screens/Menu/EditHotkeyScreen.cs index 394c1b88f..60dc57e72 100644 --- a/ClassicalSharp/2D/Screens/Menu/EditHotkeyScreen.cs +++ b/ClassicalSharp/2D/Screens/Menu/EditHotkeyScreen.cs @@ -22,11 +22,7 @@ namespace ClassicalSharp.Gui.Screens { } public override void Render( double delta ) { - RenderMenuBounds(); - gfx.Texturing = true; - RenderMenuWidgets( delta ); - gfx.Texturing = false; - + base.Render( delta ); float cX = game.Width / 2, cY = game.Height / 2; gfx.Draw2DQuad( cX - 250, cY - 65, 500, 2, grey ); gfx.Draw2DQuad( cX - 250, cY + 45, 500, 2, grey ); @@ -66,8 +62,9 @@ namespace ClassicalSharp.Gui.Screens { public override void Init() { game.Keyboard.KeyRepeat = true; - base.Init(); + titleFont = new Font( game.FontName, 16, FontStyle.Bold ); regularFont = new Font( game.FontName, 16, FontStyle.Regular ); + string flags = HotkeyListScreen.MakeFlagsString( curHotkey.Flags ); if( curHotkey.Text == null ) curHotkey.Text = ""; string staysOpen = curHotkey.StaysOpen ? "yes" : "no"; diff --git a/ClassicalSharp/2D/Screens/FilesScreen.cs b/ClassicalSharp/2D/Screens/Menu/FilesScreen.cs similarity index 100% rename from ClassicalSharp/2D/Screens/FilesScreen.cs rename to ClassicalSharp/2D/Screens/Menu/FilesScreen.cs diff --git a/ClassicalSharp/2D/Screens/Menu/GenLevelScreen.cs b/ClassicalSharp/2D/Screens/Menu/GenLevelScreen.cs index 02ec1d3d5..57f9edcf9 100644 --- a/ClassicalSharp/2D/Screens/Menu/GenLevelScreen.cs +++ b/ClassicalSharp/2D/Screens/Menu/GenLevelScreen.cs @@ -15,13 +15,6 @@ namespace ClassicalSharp.Gui.Screens { MenuInputWidget selectedWidget; - public override void Render( double delta ) { - RenderMenuBounds(); - gfx.Texturing = true; - RenderMenuWidgets( delta ); - gfx.Texturing = false; - } - public override bool HandlesMouseClick( int mouseX, int mouseY, MouseButton button ) { return HandleMouseClick( widgets, mouseX, mouseY, button ); } @@ -47,7 +40,6 @@ namespace ClassicalSharp.Gui.Screens { public override void Init() { game.Keyboard.KeyRepeat = true; - base.Init(); titleFont = new Font( game.FontName, 16, FontStyle.Bold ); regularFont = new Font( game.FontName, 16, FontStyle.Regular ); diff --git a/ClassicalSharp/2D/Screens/Menu/KeyBindingsScreen.cs b/ClassicalSharp/2D/Screens/Menu/KeyBindingsScreen.cs index cc094b9e3..4e919a87c 100644 --- a/ClassicalSharp/2D/Screens/Menu/KeyBindingsScreen.cs +++ b/ClassicalSharp/2D/Screens/Menu/KeyBindingsScreen.cs @@ -4,21 +4,12 @@ using System.Drawing; using ClassicalSharp.Gui.Widgets; using OpenTK.Input; -namespace ClassicalSharp.Gui.Screens { +namespace ClassicalSharp.Gui.Screens { public abstract class KeyBindingsScreen : MenuScreen { public KeyBindingsScreen( Game game ) : base( game ) { } - public override void Render( double delta ) { - RenderMenuBounds(); - gfx.Texturing = true; - RenderMenuWidgets( delta ); - statusWidget.Render( delta ); - gfx.Texturing = false; - } - Font keyFont; - TextWidget statusWidget; static string[] keyNames; protected string[] leftDesc, rightDesc; protected KeyBind[] left, right; @@ -29,13 +20,12 @@ namespace ClassicalSharp.Gui.Screens { protected Action leftPage, rightPage; public override void Init() { - base.Init(); - if( keyNames == null ) - keyNames = Enum.GetNames( typeof( Key ) ); + titleFont = new Font( game.FontName, 16, FontStyle.Bold ); keyFont = new Font( game.FontName, 16, FontStyle.Bold ); regularFont = new Font( game.FontName, 16, FontStyle.Italic ); - statusWidget = ChatTextWidget.Create( game, 0, 130, "", - Anchor.Centre, Anchor.Centre, regularFont ); + + if( keyNames == null ) + keyNames = Enum.GetNames( typeof( Key ) ); } protected void MakeWidgets( int y ) { @@ -44,14 +34,14 @@ namespace ClassicalSharp.Gui.Screens { if( right == null ) { for( int i = 0; i < left.Length; i++ ) - Make( leftDesc[i], left[i], 0, ref y ); + Make( i, 0, ref y ); } else { for( int i = 0; i < left.Length; i++ ) - Make( leftDesc[i], left[i], -btnWidth / 2 - 5, ref y ); + Make( i, -btnWidth / 2 - 5, ref y ); y = origin; for( int i = 0; i < right.Length; i++ ) - Make( rightDesc[i], right[i], btnWidth / 2 + 5, ref y ); + Make( i + left.Length, btnWidth / 2 + 5, ref y ); } MakePages( origin ); } @@ -79,8 +69,8 @@ namespace ClassicalSharp.Gui.Screens { if( rightPage == null ) widgets[index - 1].Disabled = true; } - void Make( string desc, KeyBind bind, int x, ref int y ) { - string text = desc + ": " + keyNames[(int)game.Mapping( bind )]; + void Make( int i, int x, ref int y ) { + string text = ButtonText( i ); widgets[index++] = ButtonWidget.Create( game, x, y, btnWidth, btnHeight, text, Anchor.Centre, Anchor.Centre, keyFont, OnBindingClick ); y += btnDistance; @@ -89,24 +79,32 @@ namespace ClassicalSharp.Gui.Screens { ButtonWidget curWidget; void OnBindingClick( Game game, Widget widget, MouseButton mouseBtn ) { + int index = 0; if( mouseBtn == MouseButton.Right && (curWidget == null || curWidget == widget) ) { curWidget = (ButtonWidget)widget; - int index = Array.IndexOf( widgets, curWidget ) - 2; + index = Array.IndexOf( widgets, curWidget ) - 2; KeyBind mapping = Get( index, left, right ); HandlesKeyDown( game.InputHandler.Keys.GetDefault( mapping ) ); } if( mouseBtn != MouseButton.Left ) return; - if( curWidget == widget ) { + if( curWidget != null ) { + index = Array.IndexOf( widgets, curWidget ) - 2; + curWidget.SetText( ButtonText( index ) ); curWidget = null; - statusWidget.SetText( "" ); - } else { - curWidget = (ButtonWidget)widget; - int index = Array.IndexOf( widgets, curWidget ) - 2; - string desc = Get( index, leftDesc, rightDesc ); - string text = "&ePress new key binding for " + desc + ":"; - statusWidget.SetText( text ); } + + index = Array.IndexOf( widgets, widget ) - 2; + string text = ButtonText( index ); + curWidget = (ButtonWidget)widget; + curWidget.SetText( "> " + text + " <" ); + } + + string ButtonText( int i ) { + KeyBind mapping = Get( i, left, right ); + Key key = game.InputHandler.Keys[mapping]; + string desc = Get( i, leftDesc, rightDesc ); + return desc + ": " + keyNames[(int)key]; } public override bool HandlesKeyDown( Key key ) { @@ -115,40 +113,20 @@ namespace ClassicalSharp.Gui.Screens { } else if( curWidget != null ) { int index = Array.IndexOf( widgets, curWidget ) - 2; KeyBind mapping = Get( index, left, right ); - KeyMap map = game.InputHandler.Keys; - Key oldKey = map[mapping]; - string reason; - string desc = Get( index, leftDesc, rightDesc ); - - if( !map.IsKeyOkay( oldKey, key, out reason ) ) { - const string format = "&eFailed to change \"{0}\". &c({1})"; - statusWidget.SetText( String.Format( format, desc, reason ) ); - } else { - const string format = "&e\"{0}\" changed from &7{1} &eto &7{2}&e."; - statusWidget.SetText( String.Format( format, desc, oldKey, key ) ); - - string text = desc + ": " + keyNames[(int)key]; - curWidget.SetText( text ); - map[mapping] = key; - } + game.InputHandler.Keys[mapping] = key; + curWidget.SetText( ButtonText( index ) ); curWidget = null; } - return key < Key.F1 || key > Key.F35; + return true; } T Get( int index, T[] a, T[] b ) { return index < a.Length ? a[index] : b[index - a.Length]; } - public override void OnResize( int width, int height ) { - base.OnResize( width, height ); - statusWidget.OnResize( width, height ); - } - public override void Dispose() { keyFont.Dispose(); base.Dispose(); - statusWidget.Dispose(); } } } \ No newline at end of file diff --git a/ClassicalSharp/2D/Screens/Menu/KeyBindingsScreens.cs b/ClassicalSharp/2D/Screens/Menu/KeyBindingsScreens.cs index 4e67c38b9..e8c6242ce 100644 --- a/ClassicalSharp/2D/Screens/Menu/KeyBindingsScreens.cs +++ b/ClassicalSharp/2D/Screens/Menu/KeyBindingsScreens.cs @@ -125,7 +125,7 @@ namespace ClassicalSharp.Gui.Screens { base.Init(); left = new KeyBind[3]; left[0] = KeyBind.MouseLeft; left[1] = KeyBind.MouseMiddle; left[2] = KeyBind.MouseRight; - leftDesc = new string[] { "Left mouse", "Middle mouse", "Right mouse" }; + leftDesc = new string[] { "Left", "Middle", "Right" }; widgets = new Widget[left.Length + 5]; title = "Mouse key bindings"; diff --git a/ClassicalSharp/2D/Screens/Menu/MenuOptionsScreen.cs b/ClassicalSharp/2D/Screens/Menu/MenuOptionsScreen.cs index 1c5374eb3..4d86b447e 100644 --- a/ClassicalSharp/2D/Screens/Menu/MenuOptionsScreen.cs +++ b/ClassicalSharp/2D/Screens/Menu/MenuOptionsScreen.cs @@ -14,7 +14,6 @@ namespace ClassicalSharp.Gui.Screens { protected MenuInputValidator[] validators; protected string[][] descriptions; protected TextGroupWidget extendedHelp; - Font extendedHelpFont; public override void Render( double delta ) { RenderMenuBounds(); @@ -38,9 +37,8 @@ namespace ClassicalSharp.Gui.Screens { } public override void Init() { - base.Init(); + titleFont = new Font( game.FontName, 16, FontStyle.Bold ); regularFont = new Font( game.FontName, 16, FontStyle.Regular ); - extendedHelpFont = new Font( game.FontName, 16, FontStyle.Regular ); game.Keyboard.KeyRepeat = true; } @@ -77,7 +75,6 @@ namespace ClassicalSharp.Gui.Screens { public override void Dispose() { DisposeWidgets(); game.Keyboard.KeyRepeat = false; - extendedHelpFont.Dispose(); DisposeExtendedHelp(); base.Dispose(); } @@ -155,7 +152,7 @@ namespace ClassicalSharp.Gui.Screens { int tableWidth, tableHeight; protected int extHelpY = 100; void MakeExtendedHelp( string[] desc ) { - extendedHelp = new TextGroupWidget( game, desc.Length, extendedHelpFont, null, + extendedHelp = new TextGroupWidget( game, desc.Length, regularFont, null, Anchor.Centre, Anchor.Centre ); extendedHelp.Init(); diff --git a/ClassicalSharp/2D/Screens/Menu/OptionsGroupScreen.cs b/ClassicalSharp/2D/Screens/Menu/OptionsGroupScreen.cs index 38b016be0..cbe153457 100644 --- a/ClassicalSharp/2D/Screens/Menu/OptionsGroupScreen.cs +++ b/ClassicalSharp/2D/Screens/Menu/OptionsGroupScreen.cs @@ -22,8 +22,8 @@ namespace ClassicalSharp.Gui.Screens { } public override void Init() { - base.Init(); game.Events.HackPermissionsChanged += CheckHacksAllowed; + titleFont = new Font( game.FontName, 16, FontStyle.Bold ); regularFont = new Font( game.FontName, 16, FontStyle.Regular ); MakeNormal(); diff --git a/ClassicalSharp/2D/Screens/Menu/PauseScreen.cs b/ClassicalSharp/2D/Screens/Menu/PauseScreen.cs index 399c6ddcd..6b5be359a 100644 --- a/ClassicalSharp/2D/Screens/Menu/PauseScreen.cs +++ b/ClassicalSharp/2D/Screens/Menu/PauseScreen.cs @@ -10,20 +10,16 @@ namespace ClassicalSharp.Gui.Screens { public PauseScreen( Game game ) : base( game ) { } - public override void Render( double delta ) { - RenderMenuBounds(); - gfx.Texturing = true; - RenderMenuWidgets( delta ); - gfx.Texturing = false; - } - public override void Init() { - base.Init(); + titleFont = new Font( game.FontName, 16, FontStyle.Bold ); game.Events.HackPermissionsChanged += CheckHacksAllowed; - if( game.UseClassicOptions ) + + if( game.UseClassicOptions ) { MakeClassic(); - else - MakeNormal(); + } else { + MakeNormal(); + } + if( !game.Server.IsSinglePlayer ) { widgets[1].Disabled = true; widgets[2].Disabled = true; diff --git a/ClassicalSharp/2D/Screens/Menu/SaveLevelScreen.cs b/ClassicalSharp/2D/Screens/Menu/SaveLevelScreen.cs index 44b0fb1cc..0516a321f 100644 --- a/ClassicalSharp/2D/Screens/Menu/SaveLevelScreen.cs +++ b/ClassicalSharp/2D/Screens/Menu/SaveLevelScreen.cs @@ -52,7 +52,7 @@ namespace ClassicalSharp.Gui.Screens { public override void Init() { game.Keyboard.KeyRepeat = true; - base.Init(); + titleFont = new Font( game.FontName, 16, FontStyle.Bold ); regularFont = new Font( game.FontName, 16, FontStyle.Regular ); inputWidget = MenuInputWidget.Create( diff --git a/ClassicalSharp/2D/Screens/Menu/MenuScreen.cs b/ClassicalSharp/2D/Screens/MenuScreen.cs similarity index 89% rename from ClassicalSharp/2D/Screens/Menu/MenuScreen.cs rename to ClassicalSharp/2D/Screens/MenuScreen.cs index f8225f660..7e35dc024 100644 --- a/ClassicalSharp/2D/Screens/Menu/MenuScreen.cs +++ b/ClassicalSharp/2D/Screens/MenuScreen.cs @@ -24,16 +24,21 @@ namespace ClassicalSharp.Gui.Screens { } } - public override void Init() { - titleFont = new Font( game.FontName, 16, FontStyle.Bold ); - } + public override void Render( double delta ) { + RenderMenuBounds(); + gfx.Texturing = true; + RenderMenuWidgets( delta ); + gfx.Texturing = false; + } public override void Dispose() { for( int i = 0; i < widgets.Length; i++ ) { if( widgets[i] == null ) continue; widgets[i].Dispose(); } - titleFont.Dispose(); + + if( titleFont != null ) + titleFont.Dispose(); if( regularFont != null ) regularFont.Dispose(); } diff --git a/ClassicalSharp/2D/Utils/TextAtlas.cs b/ClassicalSharp/2D/Utils/TextAtlas.cs index 18e959886..1cefca892 100644 --- a/ClassicalSharp/2D/Utils/TextAtlas.cs +++ b/ClassicalSharp/2D/Utils/TextAtlas.cs @@ -56,7 +56,8 @@ namespace ClassicalSharp { part.U2 = part.U1 + width / (float)totalWidth; curX += width; - IGraphicsApi.Make2DQuad( ref part, FastColour.White, vertices, ref index ); + IGraphicsApi.Make2DQuad( ref part, FastColour.WhitePacked, + vertices, ref index ); } public void AddInt( int value, VertexP3fT2fC4b[] vertices, ref int index ) { diff --git a/ClassicalSharp/2D/Widgets/BlockHotbarWidget.cs b/ClassicalSharp/2D/Widgets/BlockHotbarWidget.cs index 40a5ce5ef..14df91303 100644 --- a/ClassicalSharp/2D/Widgets/BlockHotbarWidget.cs +++ b/ClassicalSharp/2D/Widgets/BlockHotbarWidget.cs @@ -70,8 +70,7 @@ namespace ClassicalSharp.Gui.Widgets { public override void MoveTo( int newX, int newY ) { X = newX; Y = newY; - Dispose(); - Init(); + Recreate(); } void MakeBackgroundTexture() { diff --git a/ClassicalSharp/2D/Widgets/SurvivalHudWidget.cs b/ClassicalSharp/2D/Widgets/SurvivalHudWidget.cs new file mode 100644 index 000000000..df9c2494a --- /dev/null +++ b/ClassicalSharp/2D/Widgets/SurvivalHudWidget.cs @@ -0,0 +1,58 @@ +// ClassicalSharp copyright 2014-2016 UnknownShadow200 | Licensed under MIT +using System; +using ClassicalSharp.GraphicsAPI; + +namespace ClassicalSharp.Gui.Widgets { + public sealed class SurvivalHudWidget : Widget { + + public SurvivalHudWidget( Game game ) : base( game ) { + HorizontalAnchor = Anchor.Centre; + VerticalAnchor = Anchor.BottomOrRight; + } + + // TODO: scaling + public override void Init() { + //float scale = 2 * game.GuiHotbarScale; + Width = (int)(9 * 10);// * scale); + Height = (int)9;// * scale); + + X = game.Width / 2 - Width / 2; + Y = game.Height - Height - 100; + } + + public override void Render( double delta ) { + Model.ModelCache cache = game.ModelCache; + int index = 0, health = game.LocalPlayer.Health; + for( int heart = 0; heart < 10; heart++ ) { + Texture tex = new Texture( 0, X + 16 * heart, Y - 18, 18, 18, backRec ); + IGraphicsApi.Make2DQuad( ref tex, FastColour.WhitePacked, + cache.vertices, ref index ); + + if( health >= 2 ) { + tex = new Texture( 0, X + 16 * heart + 2, Y - 18 + 2, 14, 14, fullRec ); + } else if( health == 1 ) { + tex = new Texture( 0, X + 16 * heart + 2, Y - 18 + 2, 14, 14, halfRec ); + } else { + continue; + } + + IGraphicsApi.Make2DQuad( ref tex, FastColour.WhitePacked, + cache.vertices, ref index ); + health -= 2; + } + + game.Graphics.Texturing = true; + game.Graphics.BindTexture( game.Gui.IconsTex ); + game.Graphics.UpdateDynamicIndexedVb( DrawMode.Triangles, cache.vb, cache.vertices, index ); + game.Graphics.Texturing = false; + } + + static TextureRec backRec = new TextureRec( 16 / 256f, 0 / 256f, 9 / 256f, 9 / 256f ); + static TextureRec fullRec = new TextureRec( 53 / 256f, 1 / 256f, 7 / 256f, 7 / 256f ); + static TextureRec halfRec = new TextureRec( 62 / 256f, 1 / 256f, 7 / 256f, 7 / 256f ); + + public override void Dispose() { } + + public override void MoveTo( int newX, int newY ) { X = newX; Y = newY; } + } +} \ No newline at end of file diff --git a/ClassicalSharp/ClassicalSharp.csproj b/ClassicalSharp/ClassicalSharp.csproj index 63d69073d..4d10fb40b 100644 --- a/ClassicalSharp/ClassicalSharp.csproj +++ b/ClassicalSharp/ClassicalSharp.csproj @@ -88,16 +88,18 @@ + - + + @@ -107,7 +109,6 @@ - @@ -136,6 +137,7 @@ + diff --git a/ClassicalSharp/Entities/LocalPlayer.cs b/ClassicalSharp/Entities/LocalPlayer.cs index b159abee8..53238fdf1 100644 --- a/ClassicalSharp/Entities/LocalPlayer.cs +++ b/ClassicalSharp/Entities/LocalPlayer.cs @@ -14,6 +14,8 @@ namespace ClassicalSharp.Entities { public float SpawnYaw, SpawnPitch; + public short Health = 20; + /// The distance (in blocks) that players are allowed to /// reach to and interact/modify blocks in. public float ReachDistance = 5f; diff --git a/ClassicalSharp/Game/KeyMap.cs b/ClassicalSharp/Game/KeyMap.cs index e36722d33..61d3f2f3d 100644 --- a/ClassicalSharp/Game/KeyMap.cs +++ b/ClassicalSharp/Game/KeyMap.cs @@ -6,7 +6,7 @@ namespace ClassicalSharp { public enum KeyBind { Forward, Back, Left, Right, Jump, Respawn, SetSpawn, Chat, - Inventory, ToggleFog, SendChat, PauseOrExit, PlayerList, + Inventory, ToggleFog, SendChat, PauseOrExit, PlayerList, Speed, NoClip, Fly, FlyUp, FlyDown, ExtInput, HideFps, Screenshot, Fullscreen, ThirdPerson, HideGui, AxisLines, ZoomScrolling, HalfSpeed, MouseLeft, MouseMiddle, MouseRight, @@ -24,25 +24,6 @@ namespace ClassicalSharp { } Key[] keys, defaultKeys; - bool IsReservedKey( Key key ) { - return key == Key.Escape || key == Key.Slash || key == Key.BackSpace || - (key >= Key.Insert && key <= Key.End) || - (key >= Key.Number0 && key <= Key.Number9); // block hotbar - } - - public bool IsKeyOkay( Key oldKey, Key key, out string reason ) { - if( oldKey == Key.Escape || oldKey == Key.F12 ) { - reason = "This binding is locked"; - return false; - } - - if( IsReservedKey( key ) ) { - reason = "New key is reserved"; - return false; - } - reason = null; - return true; - } public KeyMap() { // We can't use enum array initaliser because this causes problems when building with mono @@ -70,7 +51,7 @@ namespace ClassicalSharp { for( int i = 0; i < names.Length; i++ ) { string key = "key-" + names[i]; Key mapping = Options.GetEnum( key, keys[i] ); - if( !IsReservedKey( mapping ) ) + if( mapping != Key.Escape ) keys[i] = mapping; } } diff --git a/ClassicalSharp/GraphicsAPI/IGraphicsAPI.Core.cs b/ClassicalSharp/GraphicsAPI/IGraphicsAPI.Core.cs index 44d5fcc8b..c4bb9339a 100644 --- a/ClassicalSharp/GraphicsAPI/IGraphicsAPI.Core.cs +++ b/ClassicalSharp/GraphicsAPI/IGraphicsAPI.Core.cs @@ -61,12 +61,12 @@ namespace ClassicalSharp.GraphicsAPI { internal int texVb; public virtual void Draw2DTexture( ref Texture tex, FastColour col ) { int index = 0; - Make2DQuad( ref tex, col, texVerts, ref index ); + Make2DQuad( ref tex, col.Pack(), texVerts, ref index ); SetBatchFormat( VertexFormat.P3fT2fC4b ); UpdateDynamicIndexedVb( DrawMode.Triangles, texVb, texVerts, 4 ); } - public static void Make2DQuad( ref Texture tex, FastColour col, + public static void Make2DQuad( ref Texture tex, int col, VertexP3fT2fC4b[] vertices, ref int index ) { float x1 = tex.X, y1 = tex.Y, x2 = tex.X + tex.Width, y2 = tex.Y + tex.Height; #if USE_DX @@ -75,11 +75,10 @@ namespace ClassicalSharp.GraphicsAPI { x1 -= 0.5f; x2 -= 0.5f; y1 -= 0.5f; y2 -= 0.5f; #endif - int c = col.Pack(); - vertices[index++] = new VertexP3fT2fC4b( x1, y1, 0, tex.U1, tex.V1, c ); - vertices[index++] = new VertexP3fT2fC4b( x2, y1, 0, tex.U2, tex.V1, c ); - vertices[index++] = new VertexP3fT2fC4b( x2, y2, 0, tex.U2, tex.V2, c ); - vertices[index++] = new VertexP3fT2fC4b( x1, y2, 0, tex.U1, tex.V2, c ); + vertices[index++] = new VertexP3fT2fC4b( x1, y1, 0, tex.U1, tex.V1, col ); + vertices[index++] = new VertexP3fT2fC4b( x2, y1, 0, tex.U2, tex.V1, col ); + vertices[index++] = new VertexP3fT2fC4b( x2, y2, 0, tex.U2, tex.V2, col ); + vertices[index++] = new VertexP3fT2fC4b( x1, y2, 0, tex.U1, tex.V2, col ); } /// Updates the various matrix stacks and properties so that the graphics API state diff --git a/ClassicalSharp/Rendering/MapRenderer.cs b/ClassicalSharp/Rendering/MapRenderer.cs index 98501788e..b469a3c5e 100644 --- a/ClassicalSharp/Rendering/MapRenderer.cs +++ b/ClassicalSharp/Rendering/MapRenderer.cs @@ -50,7 +50,7 @@ namespace ClassicalSharp.Renderers { internal bool[] pendingTranslucent, pendingNormal; internal int[] totalUsed; internal ChunkUpdater updater; - bool drawAllFaces = false, underWater = false; + bool inTranslucent = false; public MapRenderer( Game game ) { this.game = game; @@ -110,12 +110,12 @@ namespace ClassicalSharp.Renderers { Vector3I coords = Vector3I.Floor( pos ); byte block = game.World.SafeGetBlock( coords ); - drawAllFaces = game.BlockInfo.IsTranslucent[block]; bool outside = !game.World.IsValidPos( Vector3I.Floor( pos ) ); - underWater = drawAllFaces || (pos.Y < env.EdgeHeight && outside); + inTranslucent = game.BlockInfo.IsTranslucent[block] + || (pos.Y < env.EdgeHeight && outside); // If we are under water, render weather before to blend properly - if( !underWater || env.Weather == Weather.Sunny ) return; + if( !inTranslucent || env.Weather == Weather.Sunny ) return; gfx.AlphaBlending = true; game.WeatherRenderer.Render( deltaTime ); gfx.AlphaBlending = false; @@ -152,7 +152,7 @@ namespace ClassicalSharp.Renderers { gfx.DepthWrite = true; // If we weren't under water, render weather after to blend properly - if( !underWater && game.World.Env.Weather != Weather.Sunny ) { + if( !inTranslucent && game.World.Env.Weather != Weather.Sunny ) { gfx.AlphaTest = true; game.WeatherRenderer.Render( deltaTime ); gfx.AlphaTest = false; @@ -271,12 +271,12 @@ namespace ClassicalSharp.Renderers { void DrawTranslucentPart( ChunkInfo info, ref ChunkPartInfo part, int m ) { gfx.BindVb( part.VbId ); - bool drawLeft = (drawAllFaces || info.DrawLeft) && part.LeftCount > 0; - bool drawRight = (drawAllFaces || info.DrawRight) && part.RightCount > 0; - bool drawBottom = (drawAllFaces || info.DrawBottom) && part.BottomCount > 0; - bool drawTop = (drawAllFaces || info.DrawTop) && part.TopCount > 0; - bool drawFront = (drawAllFaces || info.DrawFront) && part.FrontCount > 0; - bool drawBack = (drawAllFaces || info.DrawBack) && part.BackCount > 0; + bool drawLeft = (inTranslucent || info.DrawLeft) && part.LeftCount > 0; + bool drawRight = (inTranslucent || info.DrawRight) && part.RightCount > 0; + bool drawBottom = (inTranslucent || info.DrawBottom) && part.BottomCount > 0; + bool drawTop = (inTranslucent || info.DrawTop) && part.TopCount > 0; + bool drawFront = (inTranslucent || info.DrawFront) && part.FrontCount > 0; + bool drawBack = (inTranslucent || info.DrawBack) && part.BackCount > 0; if( drawLeft && drawRight ) { gfx.DrawIndexedVb_TrisT2fC4b( part.LeftCount + part.RightCount, part.LeftIndex ); diff --git a/ClassicalSharp/Singleplayer/FoilagePhysics.cs b/ClassicalSharp/Singleplayer/FoilagePhysics.cs index 48eacaf1c..1e60e4a23 100644 --- a/ClassicalSharp/Singleplayer/FoilagePhysics.cs +++ b/ClassicalSharp/Singleplayer/FoilagePhysics.cs @@ -20,8 +20,8 @@ namespace ClassicalSharp.Singleplayer { physics.OnRandomTick[Block.Dandelion] = HandleFlower; physics.OnRandomTick[Block.Rose] = HandleFlower; - physics.OnRandomTick[Block.RedMushroom] = HandleFlower; - physics.OnRandomTick[Block.BrownMushroom] = HandleFlower; + physics.OnRandomTick[Block.RedMushroom] = HandleMushroom; + physics.OnRandomTick[Block.BrownMushroom] = HandleMushroom; } void HandleSapling( int index, byte block ) { @@ -42,7 +42,7 @@ namespace ClassicalSharp.Singleplayer { void HandleGrass( int index, byte block ) { int x = index % map.Width; int y = (index / map.Width) / map.Length; - int z = (index / map.Width) % map.Length; + int z = (index / map.Width) % map.Length; if( y <= map.GetLightHeight( x, z ) ) game.UpdateBlock( x, y, z, Block.Dirt ); } @@ -52,7 +52,25 @@ namespace ClassicalSharp.Singleplayer { int y = (index / map.Width) / map.Length; int z = (index / map.Width) % map.Length; if( y <= map.GetLightHeight( x, z ) ) - game.UpdateBlock( x, y, z, Block.Air ); + game.UpdateBlock( x, y, z, Block.Air ); + + byte below = Block.Dirt; + if( y > 0 ) below = map.blocks[index - map.Width * map.Length]; + if( !(below == Block.Dirt || below == Block.Grass ) ) + game.UpdateBlock( x, y, z, Block.Air ); + } + + void HandleMushroom( int index, byte block ) { + int x = index % map.Width; + int y = (index / map.Width) / map.Length; + int z = (index / map.Width) % map.Length; + if( y > map.GetLightHeight( x, z ) ) + game.UpdateBlock( x, y, z, Block.Air ); + + byte below = Block.Stone; + if( y > 0 ) below = map.blocks[index - map.Width * map.Length]; + if( !(below == Block.Stone || below == Block.Cobblestone ) ) + game.UpdateBlock( x, y, z, Block.Air ); } // Algorithm source: Looking at the trees generated by the default classic server. diff --git a/OpenTK/Input/Key.cs b/OpenTK/Input/Key.cs index 8cff94917..fccc9f61a 100644 --- a/OpenTK/Input/Key.cs +++ b/OpenTK/Input/Key.cs @@ -25,291 +25,51 @@ // #endregion -namespace OpenTK.Input -{ +namespace OpenTK.Input { /// The available keyboard keys. - public enum Key : int - { - /// A key outside the known keys. + public enum Key : int { + // Key outside the known keys Unknown = 0, // Modifiers - /// The left shift key. - ShiftLeft, - /// The right shift key. - ShiftRight, - /// The left control key. - ControlLeft, - /// The right control key. - ControlRight, - /// The left alt key. - AltLeft, - /// The right alt key. - AltRight, - /// The left win key. - WinLeft, - /// The right win key. - WinRight, - /// The menu key. - Menu, + ShiftLeft, ShiftRight, ControlLeft, ControlRight, + AltLeft, AltRight, WinLeft, WinRight, Menu, // Function keys (hopefully enough for most keyboards - mine has 26) // on X11 reports up to 35 function keys. - /// The F1 key. - F1, - /// The F2 key. - F2, - /// The F3 key. - F3, - /// The F4 key. - F4, - /// The F5 key. - F5, - /// The F6 key. - F6, - /// The F7 key. - F7, - /// The F8 key. - F8, - /// The F9 key. - F9, - /// The F10 key. - F10, - /// The F11 key. - F11, - /// The F12 key. - F12, - /// The F13 key. - F13, - /// The F14 key. - F14, - /// The F15 key. - F15, - /// The F16 key. - F16, - /// The F17 key. - F17, - /// The F18 key. - F18, - /// The F19 key. - F19, - /// The F20 key. - F20, - /// The F21 key. - F21, - /// The F22 key. - F22, - /// The F23 key. - F23, - /// The F24 key. - F24, - /// The F25 key. - F25, - /// The F26 key. - F26, - /// The F27 key. - F27, - /// The F28 key. - F28, - /// The F29 key. - F29, - /// The F30 key. - F30, - /// The F31 key. - F31, - /// The F32 key. - F32, - /// The F33 key. - F33, - /// The F34 key. - F34, - /// The F35 key. - F35, + F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, + F11, F12, F13, F14, F15, F16, F17, F18, F19, F20, + F21, F22, F23, F24, F25, F26, F27, F28, F29, F30, + F31, F32, F33, F34, F35, // Direction arrows - /// The up arrow key. - Up, - /// The down arrow key. - Down, - /// The left arrow key. - Left, - /// The right arrow key. - Right, + Up, Down, Left, Right, - /// The enter key. - Enter, - /// The escape key. - Escape, - /// The space key. - Space, - /// The tab key. - Tab, - /// The backspace key. - BackSpace, - /// The insert key. - Insert, - /// The delete key. - Delete, - /// The page up key. - PageUp, - /// The page down key. - PageDown, - /// The home key. - Home, - /// The end key. - End, - /// The caps lock key. - CapsLock, - /// The scroll lock key. - ScrollLock, - /// The print screen key. - PrintScreen, - /// The pause key. - Pause, - /// The num lock key. - NumLock, - - // Special keys - /// The clear key (Keypad5 with NumLock disabled, on typical keyboards). - Clear, - /// The sleep key. - Sleep, + // Action keys + Enter, Escape, Space, Tab, BackSpace, Insert, + Delete, PageUp, PageDown, Home, End, CapsLock, + ScrollLock, PrintScreen, Pause, NumLock, // Keypad keys - /// The keypad 0 key. - Keypad0, - /// The keypad 1 key. - Keypad1, - /// The keypad 2 key. - Keypad2, - /// The keypad 3 key. - Keypad3, - /// The keypad 4 key. - Keypad4, - /// The keypad 5 key. - Keypad5, - /// The keypad 6 key. - Keypad6, - /// The keypad 7 key. - Keypad7, - /// The keypad 8 key. - Keypad8, - /// The keypad 9 key. - Keypad9, - /// The keypad divide key. - KeypadDivide, - /// The keypad multiply key. - KeypadMultiply, - /// The keypad subtract key. - KeypadSubtract, - /// The keypad add key. - KeypadAdd, - /// The keypad decimal key. - KeypadDecimal, - /// The keypad enter key. - KeypadEnter, + Keypad0, Keypad1, Keypad2, Keypad3, Keypad4, + Keypad5, Keypad6, Keypad7, Keypad8, Keypad9, + KeypadDivide, KeypadMultiply, KeypadSubtract, + KeypadAdd, KeypadDecimal, KeypadEnter, // Letters - /// The A key. - A, - /// The B key. - B, - /// The C key. - C, - /// The D key. - D, - /// The E key. - E, - /// The F key. - F, - /// The G key. - G, - /// The H key. - H, - /// The I key. - I, - /// The J key. - J, - /// The K key. - K, - /// The L key. - L, - /// The M key. - M, - /// The N key. - N, - /// The O key. - O, - /// The P key. - P, - /// The Q key. - Q, - /// The R key. - R, - /// The S key. - S, - /// The T key. - T, - /// The U key. - U, - /// The V key. - V, - /// The W key. - W, - /// The X key. - X, - /// The Y key. - Y, - /// The Z key. - Z, + A, B, C, D, E, F, G, H, I, J, + K, L, M, N, O, P, Q, R, S, T, + U, V, W, X, Y, Z, // Numbers - /// The number 0 key. - Number0, - /// The number 1 key. - Number1, - /// The number 2 key. - Number2, - /// The number 3 key. - Number3, - /// The number 4 key. - Number4, - /// The number 5 key. - Number5, - /// The number 6 key. - Number6, - /// The number 7 key. - Number7, - /// The number 8 key. - Number8, - /// The number 9 key. - Number9, + Number0, Number1, Number2, Number3, Number4, + Number5, Number6, Number7, Number8, Number9, // Symbols - /// The tilde key. - Tilde, - /// The minus key. - Minus, - //Equal, - /// The plus key. - Plus, - /// The left bracket key. - BracketLeft, - /// The right bracket key. - BracketRight, - /// The semicolon key. - Semicolon, - /// The quote key. - Quote, - /// The comma key. - Comma, - /// The period key. - Period, - /// The slash key. - Slash, - /// The backslash key. - BackSlash, - /// Indicates the last available keyboard key. + Tilde, Minus, Plus, BracketLeft, BracketRight, + Semicolon, Quote, Comma, Period, Slash, BackSlash, + + // Last available keyboard key LastKey } } \ No newline at end of file diff --git a/OpenTK/Platform/Windows/WinKeyMap.cs b/OpenTK/Platform/Windows/WinKeyMap.cs index 1c4eadd7a..5601d23e5 100644 --- a/OpenTK/Platform/Windows/WinKeyMap.cs +++ b/OpenTK/Platform/Windows/WinKeyMap.cs @@ -69,11 +69,8 @@ namespace OpenTK.Platform.Windows { AddKey(VirtualKeys.SCROLL, Key.ScrollLock); AddKey(VirtualKeys.SNAPSHOT, Key.PrintScreen); - AddKey(VirtualKeys.CLEAR, Key.Clear); AddKey(VirtualKeys.INSERT, Key.Insert); - AddKey(VirtualKeys.SLEEP, Key.Sleep); - // Keypad for (int i = 0; i <= 9; i++) { AddKey((VirtualKeys)((int)VirtualKeys.NUMPAD0 + i), Key.Keypad0 + i);