diff --git a/ClassicalSharp/2D/Screens/ClickableScreen.cs b/ClassicalSharp/2D/Screens/ClickableScreen.cs index b696ec2ae..4d26d8d56 100644 --- a/ClassicalSharp/2D/Screens/ClickableScreen.cs +++ b/ClassicalSharp/2D/Screens/ClickableScreen.cs @@ -16,7 +16,7 @@ namespace ClassicalSharp { for( int i = widgets.Length - 1; i >= 0; i-- ) { Widget widget = widgets[i]; if( widget != null && widget.Bounds.Contains( mouseX, mouseY ) ) { - if( widget.OnClick != null ) + if( widget.OnClick != null && !widget.Disabled ) widget.OnClick( game, widget ); return true; } diff --git a/ClassicalSharp/2D/Screens/Menu/PauseScreen.cs b/ClassicalSharp/2D/Screens/Menu/PauseScreen.cs index ccba96729..c7ce44c15 100644 --- a/ClassicalSharp/2D/Screens/Menu/PauseScreen.cs +++ b/ClassicalSharp/2D/Screens/Menu/PauseScreen.cs @@ -18,6 +18,7 @@ namespace ClassicalSharp { public override void Init() { base.Init(); + game.Events.HackPermissionsChanged += CheckHacksAllowed; buttons = new ButtonWidget[] { // Column 1 Make( -140, -150, "Options", Anchor.Centre, @@ -51,6 +52,17 @@ namespace ClassicalSharp { MakeBack( true, titleFont, (g, w) => g.SetNewScreen( null ) ), }; + CheckHacksAllowed( null, null ); + } + + void CheckHacksAllowed( object sender, EventArgs e ) { + for( int i = 0; i < buttons.Length; i++ ) + buttons[i].Disabled = false; + if( !game.LocalPlayer.CanAnyHacks ) { + buttons[2].Disabled = true; // hack permissions + buttons[3].Disabled = true; // env settings + buttons[8].Disabled = true; // select texture pack + } } ButtonWidget Make( int x, int y, string text, Anchor vDocking, Action onClick ) { @@ -68,5 +80,10 @@ namespace ClassicalSharp { game.SetNewScreen( null ); return true; } + + public override void Dispose() { + base.Dispose(); + game.Events.HackPermissionsChanged -= CheckHacksAllowed; + } } } \ No newline at end of file diff --git a/ClassicalSharp/2D/Widgets/ButtonWidget.cs b/ClassicalSharp/2D/Widgets/ButtonWidget.cs index 2bf631fcd..e76d11d1f 100644 --- a/ClassicalSharp/2D/Widgets/ButtonWidget.cs +++ b/ClassicalSharp/2D/Widgets/ButtonWidget.cs @@ -35,11 +35,12 @@ namespace ClassicalSharp { Height = defaultHeight; } - 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 ); - + static Texture shadowTex = new Texture( 0, 0, 0, 0, 0, + new TextureRec( 0, 66/256f, 200/256f, 20/256f ) ); + static Texture selectedTex = new Texture( 0, 0, 0, 0, 0, + new TextureRec( 0, 86/256f, 200/256f, 20/256f ) ); + static Texture disdabledTex = new Texture( 0, 0, 0, 0, 0, + new TextureRec( 0, 46/256f, 200/256f, 20/256f ) ); public string Text; public void SetText( string text ) { graphicsApi.DeleteTexture( ref texture ); @@ -57,15 +58,17 @@ 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 ); - } + if( !texture.IsValid ) + return; + Texture backTex = Active ? selectedTex : shadowTex; + if( Disabled ) backTex = disdabledTex; + 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 ); + if( Disabled ) col = new FastColour( 150, 150, 150 ); + texture.Render( graphicsApi, col ); } public override void Dispose() { @@ -73,12 +76,9 @@ namespace ClassicalSharp { } public override void MoveTo( int newX, int newY ) { - int deltaX = newX - X; - int deltaY = newY - Y; - texture.X1 += deltaX; - texture.Y1 += deltaY; - X = newX; - Y = newY; + int deltaX = newX - X, deltaY = newY - Y; + texture.X1 += deltaX; texture.Y1 += deltaY; + X = newX; Y = newY; } public Func GetValue; diff --git a/ClassicalSharp/2D/Widgets/Widget.cs b/ClassicalSharp/2D/Widgets/Widget.cs index 4acc969a0..4a4ae4b6a 100644 --- a/ClassicalSharp/2D/Widgets/Widget.cs +++ b/ClassicalSharp/2D/Widgets/Widget.cs @@ -14,6 +14,9 @@ namespace ClassicalSharp { /// Whether this widget is currently being moused over. public bool Active; + /// Whether this widget is prevented from being interacted with. + public bool Disabled; + /// Invoked when this widget is clicked on. Can be left null. public Action OnClick; diff --git a/ClassicalSharp/Commands/DefaultCommands.cs b/ClassicalSharp/Commands/DefaultCommands.cs index 96340e1e7..002be6f06 100644 --- a/ClassicalSharp/Commands/DefaultCommands.cs +++ b/ClassicalSharp/Commands/DefaultCommands.cs @@ -63,9 +63,8 @@ namespace ClassicalSharp.Commands { } public override void Execute( CommandReader reader ) { - foreach( string line in game.Graphics.ApiInfo ) { + foreach( string line in game.Graphics.ApiInfo ) game.Chat.Add( "&a" + line ); - } } } diff --git a/ClassicalSharp/Entities/LocalPlayer.cs b/ClassicalSharp/Entities/LocalPlayer.cs index cc0abbf46..2d086b1d2 100644 --- a/ClassicalSharp/Entities/LocalPlayer.cs +++ b/ClassicalSharp/Entities/LocalPlayer.cs @@ -8,16 +8,30 @@ namespace ClassicalSharp { public class LocalPlayer : Player { + /// Position the player's position is set to when the 'respawn' key binding is pressed. public Vector3 SpawnPoint; + /// The distance (in blocks) that players are allowed to + /// reach to and interact/modify blocks in. public float ReachDistance = 5f; + + /// The speed that the player move at, relative to normal speed, + /// when the 'speeding' key binding is held down. public float SpeedMultiplier = 10; public byte UserType; + + /// Whether blocks that the player places that intersect themselves + /// should cause the player to be pushed back in the opposite direction of the placed block. public bool PushbackPlacing; + /// Whether the player has allowed hacks usage as an option. + /// Note that all 'can use X' set by the server override this. public bool HacksEnabled = true; + /// Whether the player is allowed to use any type of hacks. + public bool CanAnyHacks = true; + /// Whether the player is allowed to use the types of cameras that use third person. public bool CanUseThirdPersonCamera = true; @@ -27,7 +41,7 @@ namespace ClassicalSharp { /// Whether the player is allowed to fly in the world. public bool CanFly = true; - /// Whether the player is allowed to teleport to their respawn point. + /// Whether the player is allowed to teleport to their respawn coordinates. public bool CanRespawn = true; /// Whether the player is allowed to pass through all blocks. @@ -171,7 +185,6 @@ namespace ClassicalSharp { bool pastJumpPoint = liquidFeet && !(liquidBody || liquidHead) && (Position.Y % 1 >= 0.4); - Console.WriteLine( pastJumpPoint ); if( !pastJumpPoint ) { canLiquidJump = true; Velocity.Y += speeding ? 0.08f : 0.04f; @@ -267,13 +280,10 @@ namespace ClassicalSharp { /// Recognises +/-hax, +/-fly, +/-noclip, +/-speed, +/-respawn, +/-ophax public void ParseHackFlags( string name, string motd ) { string joined = name + motd; - if( joined.Contains( "-hax" ) ) { - CanFly = CanNoclip = CanRespawn = CanSpeed = - CanPushbackBlocks = CanUseThirdPersonCamera = false; - } else { // By default (this is also the case with WoM), we can use hacks. - CanFly = CanNoclip = CanRespawn = CanSpeed = - CanPushbackBlocks = CanUseThirdPersonCamera = true; - } + SetAllHacks( true ); + // By default (this is also the case with WoM), we can use hacks. + if( joined.Contains( "-hax" ) ) + SetAllHacks( false ); ParseFlag( b => CanFly = b, joined, "fly" ); ParseFlag( b => CanNoclip = b, joined, "noclip" ); @@ -281,17 +291,21 @@ namespace ClassicalSharp { ParseFlag( b => CanRespawn = b, joined, "respawn" ); if( UserType == 0x64 ) - ParseFlag( b => CanFly = CanNoclip = CanRespawn = - CanSpeed = CanPushbackBlocks = b, joined, "ophax" ); + ParseFlag( b => SetAllHacks( b ), joined, "ophax" ); CheckHacksConsistency(); + game.Events.RaiseHackPermissionmsChanged(); + } + + void SetAllHacks( bool allowed ) { + CanAnyHacks = CanFly = CanNoclip = CanRespawn = CanSpeed = + CanPushbackBlocks = CanUseThirdPersonCamera = allowed; } static void ParseFlag( Action action, string joined, string flag ) { - if( joined.Contains( "+" + flag ) ) { + if( joined.Contains( "+" + flag ) ) action( true ); - } else if( joined.Contains( "-" + flag ) ) { + else if( joined.Contains( "-" + flag ) ) action( false ); - } } /// Disables any hacks if their respective CanHackX value is set to false. diff --git a/ClassicalSharp/Game/Events.cs b/ClassicalSharp/Game/Events.cs index 74ff705ac..5a8a9f4e0 100644 --- a/ClassicalSharp/Game/Events.cs +++ b/ClassicalSharp/Game/Events.cs @@ -64,7 +64,8 @@ namespace ClassicalSharp { /// Raised when the server or a client-side command sends a message. public event EventHandler ChatReceived; - internal void RaiseChatReceived( string text, CpeMessage type ) { chatArgs.Type = type; chatArgs.Text = text; Raise( ChatReceived, chatArgs ); } + internal void RaiseChatReceived( string text, CpeMessage type ) { + chatArgs.Type = type; chatArgs.Text = text; Raise( ChatReceived, chatArgs ); } /// Raised when the user changes chat font to arial or back to bitmapped font, /// also raised when the bitmapped font changes. @@ -72,6 +73,9 @@ namespace ClassicalSharp { internal void RaiseChatFontChanged() { Raise( ChatFontChanged ); } + /// Raised when the hack permissions of the player changes. + public event EventHandler HackPermissionsChanged; + internal void RaiseHackPermissionmsChanged() { Raise( HackPermissionsChanged ); } // Cache event instances so we don't create needless new objects. IdEventArgs idArgs = new IdEventArgs(); diff --git a/ClassicalSharp/Network/NetworkProcessor.CPE.cs b/ClassicalSharp/Network/NetworkProcessor.CPE.cs index 1b282beae..b897ae8b4 100644 --- a/ClassicalSharp/Network/NetworkProcessor.CPE.cs +++ b/ClassicalSharp/Network/NetworkProcessor.CPE.cs @@ -368,6 +368,7 @@ namespace ClassicalSharp { float jumpHeight = reader.ReadInt16() / 32f; if( jumpHeight < 0 ) jumpHeight = 1.4f; p.CalculateJumpVelocity( jumpHeight ); + game.Events.RaiseHackPermissionmsChanged(); } void HandleCpeExtAddEntity2() {