diff --git a/ClassicalSharp/2D/Screens/BlockSelectScreen.cs b/ClassicalSharp/2D/Screens/BlockSelectScreen.cs index f0e733a80..6f78dc45c 100644 --- a/ClassicalSharp/2D/Screens/BlockSelectScreen.cs +++ b/ClassicalSharp/2D/Screens/BlockSelectScreen.cs @@ -66,8 +66,8 @@ namespace ClassicalSharp { } public override void OnResize( int oldWidth, int oldHeight, int width, int height ) { - blockSize = (int)(50 * Math.Sqrt(game.GuiScale())); - selBlockExpand = (float)(25 * Math.Sqrt(game.GuiScale())); + blockSize = (int)(50 * Math.Sqrt(game.GuiScale)); + selBlockExpand = (float)(25 * Math.Sqrt(game.GuiScale)); startX = game.Width / 2 - (blockSize * blocksPerRow) / 2; startY = game.Height / 2 - (rows * blockSize) / 2; @@ -76,8 +76,8 @@ namespace ClassicalSharp { } public override void Init() { - blockSize = (int)(50 * Math.Sqrt(game.GuiScale())); - selBlockExpand = (float)(25 * Math.Sqrt(game.GuiScale())); + blockSize = (int)(50 * Math.Sqrt(game.GuiScale)); + selBlockExpand = (float)(25 * Math.Sqrt(game.GuiScale)); game.Events.BlockPermissionsChanged += BlockPermissionsChanged; RecreateBlockTextures(); } diff --git a/ClassicalSharp/2D/Screens/ChatScreen.cs b/ClassicalSharp/2D/Screens/ChatScreen.cs index 2dbf0f705..06ec9583c 100644 --- a/ClassicalSharp/2D/Screens/ChatScreen.cs +++ b/ClassicalSharp/2D/Screens/ChatScreen.cs @@ -79,16 +79,16 @@ namespace ClassicalSharp { Font chatFont, chatInputFont, chatUnderlineFont, announcementFont; public override void Init() { - int fontSize = (int)(12 * game.GuiScale() * game.ChatScale); + int fontSize = (int)(12 * game.GuiScale * game.ChatScale); Utils.Clamp( ref fontSize, 8, 60 ); chatFont = new Font( "Arial", fontSize ); chatInputFont = new Font( "Arial", fontSize, FontStyle.Bold ); chatUnderlineFont = new Font( "Arial", fontSize, FontStyle.Underline ); - fontSize = (int)(14 * game.GuiScale()); + fontSize = (int)(14 * game.GuiScale); Utils.Clamp( ref fontSize, 8, 60 ); announcementFont = new Font( "Arial", fontSize ); - blockSize = (int)(40 * game.GuiScale()); + blockSize = (int)(40 * game.GuiScale); textInput = new TextInputWidget( game, chatFont, chatInputFont ); textInput.YOffset = blockSize + 5; @@ -182,7 +182,7 @@ namespace ClassicalSharp { public override void OnResize( int oldWidth, int oldHeight, int width, int height ) { announcementTex.X1 += (width - oldWidth) / 2; announcementTex.Y1 += (height - oldHeight) / 2; - blockSize = (int)(40 * game.GuiScale()); + blockSize = (int)(40 * game.GuiScale); textInput.YOffset = blockSize + 5; bottomRight.YOffset = blockSize * 3 / 2; diff --git a/ClassicalSharp/2D/Widgets/BlockHotbarWidget.cs b/ClassicalSharp/2D/Widgets/BlockHotbarWidget.cs index 7cc1f8423..fbc2ebb52 100644 --- a/ClassicalSharp/2D/Widgets/BlockHotbarWidget.cs +++ b/ClassicalSharp/2D/Widgets/BlockHotbarWidget.cs @@ -29,8 +29,8 @@ namespace ClassicalSharp { static FastColour outlineCol = new FastColour( 151, 120, 180 ); static FastColour selCol = new FastColour( 213, 200, 223 ); public override void Init() { - blockSize = (int)(38 * game.GuiScale()); - borderSize = (int)(3 * game.GuiScale()); + blockSize = (int)(38 * game.GuiScale); + borderSize = (int)(3 * game.GuiScale); int width = blockSize * hotbarCount; X = game.Width / 2 - width / 2; Y = game.Height - blockSize; diff --git a/ClassicalSharp/ClassicalSharp.csproj b/ClassicalSharp/ClassicalSharp.csproj index 7578b6f25..e9be496bf 100644 --- a/ClassicalSharp/ClassicalSharp.csproj +++ b/ClassicalSharp/ClassicalSharp.csproj @@ -139,6 +139,7 @@ + diff --git a/ClassicalSharp/Entities/LocalPlayer.cs b/ClassicalSharp/Entities/LocalPlayer.cs index e3c63dc47..4f26e5d13 100644 --- a/ClassicalSharp/Entities/LocalPlayer.cs +++ b/ClassicalSharp/Entities/LocalPlayer.cs @@ -16,6 +16,9 @@ namespace ClassicalSharp { public byte UserType; public bool PushbackBlockPlacing; + /// Whether the player is allowed to use the types of cameras that use third person. + public bool CanUseThirdPersonCamera = true; + /// Whether the player is allowed to increase its speed beyond the normal walking speed. public bool CanSpeed = true; @@ -228,10 +231,10 @@ namespace ClassicalSharp { string joined = name + motd; if( joined.Contains( "-hax" ) ) { CanFly = CanNoclip = CanRespawn = CanSpeed = - CanPushbackBlocks = game.CanUseThirdPersonCamera = false; + CanPushbackBlocks = CanUseThirdPersonCamera = false; } else { // By default (this is also the case with WoM), we can use hacks. CanFly = CanNoclip = CanRespawn = CanSpeed = - CanPushbackBlocks = game.CanUseThirdPersonCamera = true; + CanPushbackBlocks = CanUseThirdPersonCamera = true; } ParseFlag( b => CanFly = b, joined, "fly" ); @@ -260,7 +263,7 @@ namespace ClassicalSharp { if( !CanSpeed) speeding = false; if( !CanPushbackBlocks ) PushbackBlockPlacing = false; - if( !game.CanUseThirdPersonCamera ) + if( !CanUseThirdPersonCamera ) game.SetCamera( false ); } diff --git a/ClassicalSharp/Game/Game.Properties.cs b/ClassicalSharp/Game/Game.Properties.cs new file mode 100644 index 000000000..4c62f9b91 --- /dev/null +++ b/ClassicalSharp/Game/Game.Properties.cs @@ -0,0 +1,147 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.IO; +using System.Net; +using ClassicalSharp.Audio; +using ClassicalSharp.Commands; +using ClassicalSharp.GraphicsAPI; +using ClassicalSharp.Model; +using ClassicalSharp.Network; +using ClassicalSharp.Particles; +using ClassicalSharp.Renderers; +using ClassicalSharp.Selections; +using ClassicalSharp.TexturePack; +using OpenTK; + +namespace ClassicalSharp { + + public partial class Game : GameWindow { + + /// Abstracts the underlying 3D graphics rendering API. + public IGraphicsApi Graphics; + + /// Contains the block data and metadata of the player's current world. + public Map Map; + + /// Represents a connection to a multiplayer or a singleplayer server. + public INetworkProcessor Network; + + /// List of all entities in the current map, including the player. + public EntityList Players; + + /// Entity representing the player. + public LocalPlayer LocalPlayer; + + /// Contains extended player listing information for each player in the current world. + /// Only used if CPE extension ExtPlayerList is enabled. + public CpeListInfo[] CpePlayersList = new CpeListInfo[256]; + + /// 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, thirdPersonCam, forwardThirdPersonCam; + + /// Contains the metadata about each currently defined block. + /// e.g. blocks light, height, texture IDs, etc. + public BlockInfo BlockInfo; + + /// Total rendering time(in seconds) elapsed since the client was started. + public double accumulator; + public TerrainAtlas2D TerrainAtlas; + public TerrainAtlas1D TerrainAtlas1D; + public SkinType DefaultPlayerSkinType; + + /// Accumulator for the number of chunk updates performed. Reset every second. + public int ChunkUpdates; + + public MapRenderer MapRenderer; + public MapBordersRenderer MapBordersRenderer; + public EnvRenderer EnvRenderer; + public WeatherRenderer WeatherRenderer; + public Inventory Inventory; + public IDrawer2D Drawer2D; + + public CommandManager CommandManager; + public SelectionManager SelectionManager; + public ParticleManager ParticleManager; + public PickingRenderer Picking; + public PickedPos SelectedPos = new PickedPos(); + public ModelCache ModelCache; + internal string skinServer, chatInInputBuffer = null; + internal int defaultIb; + FpsScreen fpsScreen; + internal HudScreen hudScreen; + public Events Events = new Events(); + public InputHandler InputHandler; + public ChatLog Chat; + public BlockHandRenderer BlockHandRenderer; + public AudioManager AudioManager; + + /// Account username of the player. + public string Username; + + /// Verification key used for multiplayer, unique for the username and individual server. + public string Mppass; + + /// IP address of multiplayer server connected to, null if singleplayer. + public IPAddress IPAddress; + + /// Port of multiplayer server connected to, 0 if singleplayer. + public int Port; + + /// Radius of the sphere the player can see around the position of the current camera. + public int ViewDistance = 512; + + /// Field of view for the current camera in degrees. + public int FieldOfView = 70; + + /// Strategy used to limit how many frames should be displayed at most each second. + public FpsLimitMethod FpsLimit; + + public long Vertices; + public FrustumCulling Culling; + int width, height; + public AsyncDownloader AsyncDownloader; + public Matrix4 View, Projection, HeldBlockProjection; + + /// How sensitive the client is to changes in the player's mouse position. + public int MouseSensitivity = 30; + + public int ChatLines = 12; + public bool ClickableChat, HideGui, ShowFPS = true; + internal float HudScale = 1.0f, ChatScale = 1.0f; + public bool ViewBobbing, UseGuiPng; + public bool UseSound, UseMusic; + + public Animations Animations; + internal int CloudsTextureId, RainTextureId, SnowTextureId; + internal bool screenshotRequested; + internal List WarningScreens = new List(); + internal AcceptedUrls AcceptedUrls = new AcceptedUrls(); + + /// Calculates the amount that 2D widgets should be scaled by when rendered. + /// Affected by both the current resolution of the window, as well as the + /// scaling specified by the user (field HudScale). + public float GuiScale { + get { + float scaleX = Width / 640f, scaleY = Height / 480f; + return Math.Min( scaleX, scaleY ) * HudScale; + } + } + + string defTexturePack = "default.zip"; + /// Gets or sets the path of the default texture pack that should be used by the client. + /// If the custom default texture pack specified by the user could not be found, + /// this method returns "default.zip". + public string DefaultTexturePack { + get { + return File.Exists( defTexturePack ) + ? defTexturePack : "default.zip"; } + set { + defTexturePack = value; + Options.Set( OptionsKey.DefaultTexturePack, value ); + } + } + } +} \ No newline at end of file diff --git a/ClassicalSharp/Game/Game.cs b/ClassicalSharp/Game/Game.cs index 3b9eaf9bd..bc9e9289e 100644 --- a/ClassicalSharp/Game/Game.cs +++ b/ClassicalSharp/Game/Game.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Drawing; using System.IO; using System.Net; @@ -20,90 +19,7 @@ using OpenTK.Input; namespace ClassicalSharp { public partial class Game : GameWindow { - - public IGraphicsApi Graphics; - public Map Map; - public INetworkProcessor Network; - - public EntityList Players; - public CpeListInfo[] CpePlayersList = new CpeListInfo[256]; - public LocalPlayer LocalPlayer; - public Camera Camera; - Camera firstPersonCam, thirdPersonCam, forwardThirdPersonCam; - public BlockInfo BlockInfo; - public double accumulator; - public TerrainAtlas2D TerrainAtlas; - public TerrainAtlas1D TerrainAtlas1D; - public SkinType DefaultPlayerSkinType; - public int ChunkUpdates; - - public MapRenderer MapRenderer; - public MapBordersRenderer MapBordersRenderer; - public EnvRenderer EnvRenderer; - public WeatherRenderer WeatherRenderer; - public Inventory Inventory; - public IDrawer2D Drawer2D; - - public CommandManager CommandManager; - public SelectionManager SelectionManager; - public ParticleManager ParticleManager; - public PickingRenderer Picking; - public PickedPos SelectedPos = new PickedPos(); - public ModelCache ModelCache; - internal string skinServer, chatInInputBuffer = null; - internal int defaultIb; - public bool CanUseThirdPersonCamera = true; - FpsScreen fpsScreen; - internal HudScreen hudScreen; - public Events Events = new Events(); - public InputHandler InputHandler; - public ChatLog Chat; - public BlockHandRenderer BlockHandRenderer; - public AudioManager AudioManager; - - public IPAddress IPAddress; - public string Username; - public string Mppass; - public int Port; - public int ViewDistance = 512; - public int FieldOfView = 70; - public FpsLimitMethod FpsLimit; - - public long Vertices; - public FrustumCulling Culling; - int width, height; - public AsyncDownloader AsyncDownloader; - public Matrix4 View, Projection, HeldBlockProjection; - public int MouseSensitivity = 30; - public int ChatLines = 12; - public bool ClickableChat, HideGui, ShowFPS = true; - internal float HudScale = 1.0f, ChatScale = 1.0f; - public bool ViewBobbing, UseGuiPng; - public bool UseSound, UseMusic; - - public Animations Animations; - internal int CloudsTextureId, RainTextureId, SnowTextureId; - internal bool screenshotRequested; - public Bitmap FontBitmap; - internal List WarningScreens = new List(); - internal AcceptedUrls AcceptedUrls = new AcceptedUrls(); - - public float GuiScale() { - float scaleX = Width / 640f, scaleY = Height / 480f; - return Math.Min( scaleX, scaleY ) * HudScale; - } - - string defTexturePack = "default.zip"; - public string DefaultTexturePack { - get { - return File.Exists( defTexturePack ) - ? defTexturePack : "default.zip"; } - set { - defTexturePack = value; - Options.Set( OptionsKey.DefaultTexturePack, value ); - } - } - + void LoadAtlas( Bitmap bmp ) { TerrainAtlas1D.Dispose(); TerrainAtlas.Dispose(); @@ -411,9 +327,11 @@ namespace ClassicalSharp { public void SetCamera( bool thirdPerson ) { PerspectiveCamera oldCam = (PerspectiveCamera)Camera; - Camera = (thirdPerson && CanUseThirdPersonCamera) ? + bool canUseThird = LocalPlayer.CanUseThirdPersonCamera; + Camera = (thirdPerson && canUseThird) ? (Camera is FirstPersonCamera ? thirdPersonCam : forwardThirdPersonCam ) : firstPersonCam; + PerspectiveCamera newCam = (PerspectiveCamera)Camera; newCam.delta = oldCam.delta; newCam.previous = oldCam.previous; diff --git a/ClassicalSharp/Network/NetworkProcessor.CPE.cs b/ClassicalSharp/Network/NetworkProcessor.CPE.cs index 6ffe3cc11..584b664ed 100644 --- a/ClassicalSharp/Network/NetworkProcessor.CPE.cs +++ b/ClassicalSharp/Network/NetworkProcessor.CPE.cs @@ -348,16 +348,17 @@ namespace ClassicalSharp { } void HandleCpeHackControl() { - game.LocalPlayer.CanFly = reader.ReadUInt8() != 0; - game.LocalPlayer.CanNoclip = reader.ReadUInt8() != 0; - game.LocalPlayer.CanSpeed = reader.ReadUInt8() != 0; - game.LocalPlayer.CanRespawn = reader.ReadUInt8() != 0; - game.CanUseThirdPersonCamera = reader.ReadUInt8() != 0; - game.LocalPlayer.CheckHacksConsistency(); + LocalPlayer p = game.LocalPlayer; + p.CanFly = reader.ReadUInt8() != 0; + p.CanNoclip = reader.ReadUInt8() != 0; + p.CanSpeed = reader.ReadUInt8() != 0; + p.CanRespawn = reader.ReadUInt8() != 0; + p.CanUseThirdPersonCamera = reader.ReadUInt8() != 0; + p.CheckHacksConsistency(); float jumpHeight = reader.ReadInt16() / 32f; if( jumpHeight < 0 ) jumpHeight = 1.4f; - game.LocalPlayer.CalculateJumpVelocity( jumpHeight ); + p.CalculateJumpVelocity( jumpHeight ); } void HandleCpeExtAddEntity2() { diff --git a/ClassicalSharp/TexturePack/TexturePackExtractor.cs b/ClassicalSharp/TexturePack/TexturePackExtractor.cs index f082a6d44..df85d1f5c 100644 --- a/ClassicalSharp/TexturePack/TexturePackExtractor.cs +++ b/ClassicalSharp/TexturePack/TexturePackExtractor.cs @@ -88,8 +88,8 @@ namespace ClassicalSharp.TexturePack { } void SetFontBitmap( Game game, Stream stream ) { - game.FontBitmap = new Bitmap( stream ); - game.Drawer2D.SetFontBitmap( game.FontBitmap ); + Bitmap bmp = new Bitmap( stream ); + game.Drawer2D.SetFontBitmap( bmp ); game.Events.RaiseChatFontChanged(); }