Add zoom option to client.

This commit is contained in:
UnknownShadow200 2015-12-31 12:33:55 +11:00
parent f8e19afe65
commit d51f3572b6
10 changed files with 47 additions and 58 deletions

View File

@ -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(

View File

@ -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 " );

View File

@ -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 ),

View File

@ -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;
}

View File

@ -249,6 +249,11 @@ namespace ClassicalSharp {
if( !CanUseThirdPersonCamera || !HacksEnabled )
game.CycleCamera();
if( !HacksEnabled || !CanAnyHacks || !CanUseThirdPersonCamera ) {
game.FieldOfView = 70;
game.ZoomFieldOfView = -1;
game.UpdateProjection();
}
}
/// <summary> Sets the user type of this user. This is used to control permissions for grass,

View File

@ -40,7 +40,7 @@ namespace ClassicalSharp {
/// <summary> Current camera the player is using to view the world with. </summary>
/// <remarks> e.g. first person, thid person, forward third person, etc. </remarks>
public Camera Camera;
Camera firstPersonCam, firstPersonZoomCam, thirdPersonCam, forwardThirdPersonCam;
Camera firstPersonCam, thirdPersonCam, forwardThirdPersonCam;
/// <summary> Contains the metadata about each currently defined block. </summary>
/// <remarks> e.g. blocks light, height, texture IDs, etc. </remarks>
@ -101,6 +101,7 @@ namespace ClassicalSharp {
/// <summary> Field of view for the current camera in degrees. </summary>
public int FieldOfView = 70;
internal int ZoomFieldOfView = -1;
/// <summary> Strategy used to limit how many frames should be displayed at most each second. </summary>
public FpsLimitMethod FpsLimit;

View File

@ -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;

View File

@ -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
}
}

View File

@ -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();
}

View File

@ -20,8 +20,6 @@ namespace ClassicalSharp {
/// <remarks> This causes the local player to be renderered if true. </remarks>
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;
}
}
}