diff --git a/ClassicalSharp/2D/Screens/Bindings/AdvancedKeyBindingsScreen.cs b/ClassicalSharp/2D/Screens/Bindings/AdvancedKeyBindingsScreen.cs index 54f2577d5..99cbffce1 100644 --- a/ClassicalSharp/2D/Screens/Bindings/AdvancedKeyBindingsScreen.cs +++ b/ClassicalSharp/2D/Screens/Bindings/AdvancedKeyBindingsScreen.cs @@ -11,7 +11,7 @@ namespace ClassicalSharp { 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", "Show axis lines" }; + "Toggle fullscreen", "Toggle 3rd person", "Hide gui", "Show axis lines", "Cycle zoom" }; public override void Init() { base.Init(); @@ -19,7 +19,7 @@ namespace ClassicalSharp { originKey = KeyBinding.Speed; buttons = new ButtonWidget[descriptions.Length + 2]; MakeKeys( KeyBinding.Speed, 0, 6, -150 ); - MakeKeys( KeyBinding.HideFps, 6, 6, 150 ); + MakeKeys( KeyBinding.HideFps, 6, 7, 150 ); buttons[index++] = MakeBack( false, titleFont, (g, w) => g.SetNewScreen( new PauseScreen( g ) ) ); buttons[index++] = ButtonWidget.Create( diff --git a/ClassicalSharp/2D/Screens/FpsScreen.cs b/ClassicalSharp/2D/Screens/FpsScreen.cs index e00c6d14b..eb3e90129 100644 --- a/ClassicalSharp/2D/Screens/FpsScreen.cs +++ b/ClassicalSharp/2D/Screens/FpsScreen.cs @@ -107,16 +107,17 @@ namespace ClassicalSharp { } bool speeding, noclip, fly; - Camera lastCam; + int lastZoomFov; void UpdateHackState( bool force ) { LocalPlayer p = game.LocalPlayer; - if( force || p.speeding != speeding || p.noClip != noclip || p.flying != fly || game.Camera != lastCam ) { + if( force || p.speeding != speeding || p.noClip != noclip || p.flying != fly || game.ZoomFieldOfView != lastZoomFov ) { speeding = p.speeding; noclip = p.noClip; fly = p.flying; - lastCam = game.Camera; + lastZoomFov = game.ZoomFieldOfView; int index = 0; text.Clear(); - if( lastCam.IsZoomCamera ) text.Append( ref index, "Zoom camera " ); + if( lastZoomFov != -1 ) text.Append( ref index, "Zoom fov " ) + .AppendNum( ref index, lastZoomFov ).Append( ref index, " " ); if( fly ) text.Append( ref index, "Fly ON " ); if( speeding ) text.Append( ref index, "Speed ON " ); if( noclip ) text.Append( ref index, "Noclip ON " ); diff --git a/ClassicalSharp/2D/Screens/Menu/GuiOptionsScreen.cs b/ClassicalSharp/2D/Screens/Menu/GuiOptionsScreen.cs index 244c4b59e..6fc930323 100644 --- a/ClassicalSharp/2D/Screens/Menu/GuiOptionsScreen.cs +++ b/ClassicalSharp/2D/Screens/Menu/GuiOptionsScreen.cs @@ -19,18 +19,11 @@ namespace ClassicalSharp { Options.Set( OptionsKey.ShowBlockInHand, v == "yes" ); } ), - Make( -140, -100, "Field of view", OnWidgetClick, - g => g.FieldOfView.ToString(), - (g, v) => { g.FieldOfView = Int32.Parse( v ); - Options.Set( OptionsKey.FieldOfView, v ); - g.UpdateProjection(); - } ), - - Make( -140, -50, "Show FPS", OnWidgetClick, + Make( -140, -100, "Show FPS", OnWidgetClick, g => g.ShowFPS ? "yes" : "no", (g, v) => g.ShowFPS = v == "yes" ), - Make( -140, 0, "Hud scale", OnWidgetClick, + Make( -140, -50, "Hud scale", OnWidgetClick, g => g.HudScale.ToString(), (g, v) => { g.HudScale = Single.Parse( v ); Options.Set( OptionsKey.HudScale, v ); @@ -75,7 +68,6 @@ namespace ClassicalSharp { }; validators = new MenuInputValidator[] { new BooleanValidator(), - new IntegerValidator( 1, 179 ), new BooleanValidator(), new RealValidator( 0.25f, 5f ), diff --git a/ClassicalSharp/2D/Screens/Menu/HacksSettingsScreen.cs b/ClassicalSharp/2D/Screens/Menu/HacksSettingsScreen.cs index 9724cf878..2d974ed9c 100644 --- a/ClassicalSharp/2D/Screens/Menu/HacksSettingsScreen.cs +++ b/ClassicalSharp/2D/Screens/Menu/HacksSettingsScreen.cs @@ -53,6 +53,13 @@ namespace ClassicalSharp { (g, v) => { g.LocalPlayer.NoclipSlide = v == "yes"; Options.Set( OptionsKey.NoclipSlide, v == "yes" ); } ), + Make( -140, 50, "Field of view", OnWidgetClick, + g => g.FieldOfView.ToString(), + (g, v) => { g.FieldOfView = Int32.Parse( v ); + Options.Set( OptionsKey.FieldOfView, v ); + g.UpdateProjection(); + } ), + MakeBack( false, titleFont, (g, w) => g.SetNewScreen( new PauseScreen( g ) ) ), null, @@ -61,11 +68,12 @@ namespace ClassicalSharp { validators = new MenuInputValidator[] { new BooleanValidator(), new RealValidator( 0.1f, 50 ), - new BooleanValidator(), + new BooleanValidator(), new BooleanValidator(), new BooleanValidator(), new BooleanValidator(), + new IntegerValidator( 1, 179 ), }; okayIndex = buttons.Length - 1; } diff --git a/ClassicalSharp/Entities/LocalPlayer.cs b/ClassicalSharp/Entities/LocalPlayer.cs index d9ffaaa04..acf230658 100644 --- a/ClassicalSharp/Entities/LocalPlayer.cs +++ b/ClassicalSharp/Entities/LocalPlayer.cs @@ -249,6 +249,11 @@ namespace ClassicalSharp { if( !CanUseThirdPersonCamera || !HacksEnabled ) game.CycleCamera(); + if( !HacksEnabled || !CanAnyHacks || !CanUseThirdPersonCamera ) { + game.FieldOfView = 70; + game.ZoomFieldOfView = -1; + game.UpdateProjection(); + } } /// Sets the user type of this user. This is used to control permissions for grass, diff --git a/ClassicalSharp/Game/Game.Properties.cs b/ClassicalSharp/Game/Game.Properties.cs index 41f4fd33a..dbd812921 100644 --- a/ClassicalSharp/Game/Game.Properties.cs +++ b/ClassicalSharp/Game/Game.Properties.cs @@ -40,7 +40,7 @@ namespace ClassicalSharp { /// Current camera the player is using to view the world with. /// e.g. first person, thid person, forward third person, etc. public Camera Camera; - Camera firstPersonCam, firstPersonZoomCam, thirdPersonCam, forwardThirdPersonCam; + Camera firstPersonCam, thirdPersonCam, forwardThirdPersonCam; /// Contains the metadata about each currently defined block. /// e.g. blocks light, height, texture IDs, etc. @@ -101,6 +101,7 @@ namespace ClassicalSharp { /// Field of view for the current camera in degrees. public int FieldOfView = 70; + internal int ZoomFieldOfView = -1; /// Strategy used to limit how many frames should be displayed at most each second. public FpsLimitMethod FpsLimit; diff --git a/ClassicalSharp/Game/Game.cs b/ClassicalSharp/Game/Game.cs index ede2c2a6e..3e180cbe1 100644 --- a/ClassicalSharp/Game/Game.cs +++ b/ClassicalSharp/Game/Game.cs @@ -94,7 +94,6 @@ namespace ClassicalSharp { Graphics.LostContextFunction = Network.Tick; firstPersonCam = new FirstPersonCamera( this ); - firstPersonZoomCam = new FirstPersonZoomCamera( this ); thirdPersonCam = new ThirdPersonCamera( this ); forwardThirdPersonCam = new ForwardThirdPersonCamera( this ); Camera = firstPersonCam; diff --git a/ClassicalSharp/Game/InputHandler.cs b/ClassicalSharp/Game/InputHandler.cs index e4de9f26d..782c89c02 100644 --- a/ClassicalSharp/Game/InputHandler.cs +++ b/ClassicalSharp/Game/InputHandler.cs @@ -292,10 +292,8 @@ namespace ClassicalSharp { } else if( key == Keys[KeyBinding.Screenshot] ) { game.screenshotRequested = true; } else if( !game.GetActiveScreen.HandlesKeyDown( key ) ) { - - if( !HandleBuiltinKey( key ) && !game.LocalPlayer.HandleKeyDown( key ) ) { + if( !HandleBuiltinKey( key ) && !game.LocalPlayer.HandleKeyDown( key ) ) HandleHotkey( key ); - } } } @@ -354,6 +352,8 @@ namespace ClassicalSharp { game.SetNewScreen( new PauseScreen( game ) ); } else if( key == Keys[KeyBinding.OpenInventory] ) { game.SetNewScreen( new BlockSelectScreen( game ) ); + } else if( key == Keys[KeyBinding.CycleZoom] ) { + CycleZoom(); } else { return false; } @@ -379,6 +379,22 @@ namespace ClassicalSharp { } game.SetViewDistance( viewDistances[viewDistances.Length - 1] ); } + + static int[] zoomFov = { 10, 20, 30, 40, 50, 60, -1 }; + int fovIndex = 100; + void CycleZoom() { + LocalPlayer p = game.LocalPlayer; + if( !p.HacksEnabled || !p.CanAnyHacks || !p.CanUseThirdPersonCamera ) + return; + fovIndex++; + if( fovIndex >= zoomFov.Length ) fovIndex = 0; + + game.FieldOfView = zoomFov[fovIndex]; + game.ZoomFieldOfView = game.FieldOfView; + if( game.FieldOfView == -1 ) + game.FieldOfView = Options.GetInt( OptionsKey.FieldOfView, 1, 179, 70 ); + game.UpdateProjection(); + } #endregion } } \ No newline at end of file diff --git a/ClassicalSharp/Game/KeyMap.cs b/ClassicalSharp/Game/KeyMap.cs index abecba685..4edc1c325 100644 --- a/ClassicalSharp/Game/KeyMap.cs +++ b/ClassicalSharp/Game/KeyMap.cs @@ -8,6 +8,7 @@ namespace ClassicalSharp { SendChat, PauseOrExit, OpenInventory, ViewDistance, PlayerList, Speed, NoClip, Fly, FlyUp, FlyDown, ExtendedInput, HideFps, Screenshot, Fullscreen, ThirdPersonCamera, HideGui, ShowAxisLines, + CycleZoom, } public class KeyMap { @@ -40,7 +41,7 @@ namespace ClassicalSharp { public KeyMap() { // See comment in Game() constructor - Keys = new Key[25]; + Keys = new Key[26]; Keys[0] = Key.W; Keys[1] = Key.S; Keys[2] = Key.A; Keys[3] = Key.D; Keys[4] = Key.Space; Keys[5] = Key.R; Keys[6] = Key.Y; Keys[7] = Key.T; Keys[8] = Key.Enter; Keys[9] = Key.Escape; Keys[10] = Key.B; @@ -48,7 +49,7 @@ namespace ClassicalSharp { Keys[14] = Key.X; Keys[15] = Key.Z; Keys[16] = Key.Q; 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.F1; Keys[24] = Key.F7; + Keys[23] = Key.F1; Keys[24] = Key.F7; Keys[25] = Key.C; LoadKeyBindings(); } diff --git a/ClassicalSharp/Utils/Camera.cs b/ClassicalSharp/Utils/Camera.cs index 60d21efbf..00c2d60fe 100644 --- a/ClassicalSharp/Utils/Camera.cs +++ b/ClassicalSharp/Utils/Camera.cs @@ -20,8 +20,6 @@ namespace ClassicalSharp { /// This causes the local player to be renderered if true. public abstract bool IsThirdPerson { get; } - public virtual bool IsZoomCamera { get { return false; } } - public virtual void Tick( double elapsed ) { } @@ -216,36 +214,4 @@ namespace ClassicalSharp { return eyePos; } } - - public class FirstPersonZoomCamera : PerspectiveCamera { - - public FirstPersonZoomCamera( Game window ) : base( window ) { - } - - public override bool IsZoomCamera { get { return true; } } - - float distance = 3; - public override bool MouseZoom( MouseWheelEventArgs e ) { - distance += e.DeltaPrecise; - if( distance < 2 ) distance = 2; - return true; - } - - public override Matrix4 GetView( double delta ) { - CalcViewBobbing( delta ); - Vector3 eyePos = player.EyePosition; - eyePos.Y += bobYOffset; - Vector3 dir = Utils.GetDirVector( player.YawRadians, player.PitchRadians ); - Vector3 cameraPos = eyePos + dir * distance; - return Matrix4.LookAt( cameraPos, cameraPos + dir, Vector3.UnitY ) * tiltMatrix; - } - - public override bool IsThirdPerson { - get { return true; } - } - - public override Vector3 GetCameraPos( Vector3 eyePos ) { - return eyePos + Utils.GetDirVector( player.YawRadians, player.PitchRadians ) * distance; - } - } }