mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-16 19:15:14 -04:00
Add zoom option to client.
This commit is contained in:
parent
f8e19afe65
commit
d51f3572b6
@ -11,7 +11,7 @@ namespace ClassicalSharp {
|
|||||||
|
|
||||||
static string[] normDescriptions = new [] { "Speed", "Toggle noclip", "Toggle fly",
|
static string[] normDescriptions = new [] { "Speed", "Toggle noclip", "Toggle fly",
|
||||||
"Fly up", "Fly down", "Toggle extended input", "Hide FPS", "Take screenshot",
|
"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() {
|
public override void Init() {
|
||||||
base.Init();
|
base.Init();
|
||||||
@ -19,7 +19,7 @@ namespace ClassicalSharp {
|
|||||||
originKey = KeyBinding.Speed;
|
originKey = KeyBinding.Speed;
|
||||||
buttons = new ButtonWidget[descriptions.Length + 2];
|
buttons = new ButtonWidget[descriptions.Length + 2];
|
||||||
MakeKeys( KeyBinding.Speed, 0, 6, -150 );
|
MakeKeys( KeyBinding.Speed, 0, 6, -150 );
|
||||||
MakeKeys( KeyBinding.HideFps, 6, 6, 150 );
|
MakeKeys( KeyBinding.HideFps, 6, 7, 150 );
|
||||||
buttons[index++] = MakeBack( false, titleFont,
|
buttons[index++] = MakeBack( false, titleFont,
|
||||||
(g, w) => g.SetNewScreen( new PauseScreen( g ) ) );
|
(g, w) => g.SetNewScreen( new PauseScreen( g ) ) );
|
||||||
buttons[index++] = ButtonWidget.Create(
|
buttons[index++] = ButtonWidget.Create(
|
||||||
|
@ -107,16 +107,17 @@ namespace ClassicalSharp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool speeding, noclip, fly;
|
bool speeding, noclip, fly;
|
||||||
Camera lastCam;
|
int lastZoomFov;
|
||||||
void UpdateHackState( bool force ) {
|
void UpdateHackState( bool force ) {
|
||||||
LocalPlayer p = game.LocalPlayer;
|
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;
|
speeding = p.speeding; noclip = p.noClip; fly = p.flying;
|
||||||
lastCam = game.Camera;
|
lastZoomFov = game.ZoomFieldOfView;
|
||||||
int index = 0;
|
int index = 0;
|
||||||
text.Clear();
|
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( fly ) text.Append( ref index, "Fly ON " );
|
||||||
if( speeding ) text.Append( ref index, "Speed ON " );
|
if( speeding ) text.Append( ref index, "Speed ON " );
|
||||||
if( noclip ) text.Append( ref index, "Noclip ON " );
|
if( noclip ) text.Append( ref index, "Noclip ON " );
|
||||||
|
@ -19,18 +19,11 @@ namespace ClassicalSharp {
|
|||||||
Options.Set( OptionsKey.ShowBlockInHand, v == "yes" );
|
Options.Set( OptionsKey.ShowBlockInHand, v == "yes" );
|
||||||
} ),
|
} ),
|
||||||
|
|
||||||
Make( -140, -100, "Field of view", OnWidgetClick,
|
Make( -140, -100, "Show FPS", 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,
|
|
||||||
g => g.ShowFPS ? "yes" : "no",
|
g => g.ShowFPS ? "yes" : "no",
|
||||||
(g, v) => g.ShowFPS = v == "yes" ),
|
(g, v) => g.ShowFPS = v == "yes" ),
|
||||||
|
|
||||||
Make( -140, 0, "Hud scale", OnWidgetClick,
|
Make( -140, -50, "Hud scale", OnWidgetClick,
|
||||||
g => g.HudScale.ToString(),
|
g => g.HudScale.ToString(),
|
||||||
(g, v) => { g.HudScale = Single.Parse( v );
|
(g, v) => { g.HudScale = Single.Parse( v );
|
||||||
Options.Set( OptionsKey.HudScale, v );
|
Options.Set( OptionsKey.HudScale, v );
|
||||||
@ -75,7 +68,6 @@ namespace ClassicalSharp {
|
|||||||
};
|
};
|
||||||
validators = new MenuInputValidator[] {
|
validators = new MenuInputValidator[] {
|
||||||
new BooleanValidator(),
|
new BooleanValidator(),
|
||||||
new IntegerValidator( 1, 179 ),
|
|
||||||
new BooleanValidator(),
|
new BooleanValidator(),
|
||||||
new RealValidator( 0.25f, 5f ),
|
new RealValidator( 0.25f, 5f ),
|
||||||
|
|
||||||
|
@ -53,6 +53,13 @@ namespace ClassicalSharp {
|
|||||||
(g, v) => { g.LocalPlayer.NoclipSlide = v == "yes";
|
(g, v) => { g.LocalPlayer.NoclipSlide = v == "yes";
|
||||||
Options.Set( OptionsKey.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,
|
MakeBack( false, titleFont,
|
||||||
(g, w) => g.SetNewScreen( new PauseScreen( g ) ) ),
|
(g, w) => g.SetNewScreen( new PauseScreen( g ) ) ),
|
||||||
null,
|
null,
|
||||||
@ -66,6 +73,7 @@ namespace ClassicalSharp {
|
|||||||
new BooleanValidator(),
|
new BooleanValidator(),
|
||||||
new BooleanValidator(),
|
new BooleanValidator(),
|
||||||
new BooleanValidator(),
|
new BooleanValidator(),
|
||||||
|
new IntegerValidator( 1, 179 ),
|
||||||
};
|
};
|
||||||
okayIndex = buttons.Length - 1;
|
okayIndex = buttons.Length - 1;
|
||||||
}
|
}
|
||||||
|
@ -249,6 +249,11 @@ namespace ClassicalSharp {
|
|||||||
|
|
||||||
if( !CanUseThirdPersonCamera || !HacksEnabled )
|
if( !CanUseThirdPersonCamera || !HacksEnabled )
|
||||||
game.CycleCamera();
|
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,
|
/// <summary> Sets the user type of this user. This is used to control permissions for grass,
|
||||||
|
@ -40,7 +40,7 @@ namespace ClassicalSharp {
|
|||||||
/// <summary> Current camera the player is using to view the world with. </summary>
|
/// <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>
|
/// <remarks> e.g. first person, thid person, forward third person, etc. </remarks>
|
||||||
public Camera Camera;
|
public Camera Camera;
|
||||||
Camera firstPersonCam, firstPersonZoomCam, thirdPersonCam, forwardThirdPersonCam;
|
Camera firstPersonCam, thirdPersonCam, forwardThirdPersonCam;
|
||||||
|
|
||||||
/// <summary> Contains the metadata about each currently defined block. </summary>
|
/// <summary> Contains the metadata about each currently defined block. </summary>
|
||||||
/// <remarks> e.g. blocks light, height, texture IDs, etc. </remarks>
|
/// <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>
|
/// <summary> Field of view for the current camera in degrees. </summary>
|
||||||
public int FieldOfView = 70;
|
public int FieldOfView = 70;
|
||||||
|
internal int ZoomFieldOfView = -1;
|
||||||
|
|
||||||
/// <summary> Strategy used to limit how many frames should be displayed at most each second. </summary>
|
/// <summary> Strategy used to limit how many frames should be displayed at most each second. </summary>
|
||||||
public FpsLimitMethod FpsLimit;
|
public FpsLimitMethod FpsLimit;
|
||||||
|
@ -94,7 +94,6 @@ namespace ClassicalSharp {
|
|||||||
Graphics.LostContextFunction = Network.Tick;
|
Graphics.LostContextFunction = Network.Tick;
|
||||||
|
|
||||||
firstPersonCam = new FirstPersonCamera( this );
|
firstPersonCam = new FirstPersonCamera( this );
|
||||||
firstPersonZoomCam = new FirstPersonZoomCamera( this );
|
|
||||||
thirdPersonCam = new ThirdPersonCamera( this );
|
thirdPersonCam = new ThirdPersonCamera( this );
|
||||||
forwardThirdPersonCam = new ForwardThirdPersonCamera( this );
|
forwardThirdPersonCam = new ForwardThirdPersonCamera( this );
|
||||||
Camera = firstPersonCam;
|
Camera = firstPersonCam;
|
||||||
|
@ -292,10 +292,8 @@ namespace ClassicalSharp {
|
|||||||
} else if( key == Keys[KeyBinding.Screenshot] ) {
|
} else if( key == Keys[KeyBinding.Screenshot] ) {
|
||||||
game.screenshotRequested = true;
|
game.screenshotRequested = true;
|
||||||
} else if( !game.GetActiveScreen.HandlesKeyDown( key ) ) {
|
} else if( !game.GetActiveScreen.HandlesKeyDown( key ) ) {
|
||||||
|
if( !HandleBuiltinKey( key ) && !game.LocalPlayer.HandleKeyDown( key ) )
|
||||||
if( !HandleBuiltinKey( key ) && !game.LocalPlayer.HandleKeyDown( key ) ) {
|
|
||||||
HandleHotkey( key );
|
HandleHotkey( key );
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -354,6 +352,8 @@ namespace ClassicalSharp {
|
|||||||
game.SetNewScreen( new PauseScreen( game ) );
|
game.SetNewScreen( new PauseScreen( game ) );
|
||||||
} else if( key == Keys[KeyBinding.OpenInventory] ) {
|
} else if( key == Keys[KeyBinding.OpenInventory] ) {
|
||||||
game.SetNewScreen( new BlockSelectScreen( game ) );
|
game.SetNewScreen( new BlockSelectScreen( game ) );
|
||||||
|
} else if( key == Keys[KeyBinding.CycleZoom] ) {
|
||||||
|
CycleZoom();
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -379,6 +379,22 @@ namespace ClassicalSharp {
|
|||||||
}
|
}
|
||||||
game.SetViewDistance( viewDistances[viewDistances.Length - 1] );
|
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
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -8,6 +8,7 @@ namespace ClassicalSharp {
|
|||||||
SendChat, PauseOrExit, OpenInventory, ViewDistance, PlayerList,
|
SendChat, PauseOrExit, OpenInventory, ViewDistance, PlayerList,
|
||||||
Speed, NoClip, Fly, FlyUp, FlyDown, ExtendedInput, HideFps,
|
Speed, NoClip, Fly, FlyUp, FlyDown, ExtendedInput, HideFps,
|
||||||
Screenshot, Fullscreen, ThirdPersonCamera, HideGui, ShowAxisLines,
|
Screenshot, Fullscreen, ThirdPersonCamera, HideGui, ShowAxisLines,
|
||||||
|
CycleZoom,
|
||||||
}
|
}
|
||||||
|
|
||||||
public class KeyMap {
|
public class KeyMap {
|
||||||
@ -40,7 +41,7 @@ namespace ClassicalSharp {
|
|||||||
|
|
||||||
public KeyMap() {
|
public KeyMap() {
|
||||||
// See comment in Game() constructor
|
// 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[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[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;
|
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[14] = Key.X; Keys[15] = Key.Z; Keys[16] = Key.Q;
|
||||||
Keys[17] = Key.E; Keys[18] = Key.AltLeft; 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[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();
|
LoadKeyBindings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,8 +20,6 @@ namespace ClassicalSharp {
|
|||||||
/// <remarks> This causes the local player to be renderered if true. </remarks>
|
/// <remarks> This causes the local player to be renderered if true. </remarks>
|
||||||
public abstract bool IsThirdPerson { get; }
|
public abstract bool IsThirdPerson { get; }
|
||||||
|
|
||||||
public virtual bool IsZoomCamera { get { return false; } }
|
|
||||||
|
|
||||||
public virtual void Tick( double elapsed ) {
|
public virtual void Tick( double elapsed ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -216,36 +214,4 @@ namespace ClassicalSharp {
|
|||||||
return eyePos;
|
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user