From 7ab681ab0d006532af750afff3d1fe72add24cb3 Mon Sep 17 00:00:00 2001 From: Goodlyay Date: Fri, 23 Aug 2024 20:47:41 -0700 Subject: [PATCH] Add CinematicGui 'gui' class to Player This makes it easier to change individual elements while keeping others persistent across a session --- MCGalaxy/MCGalaxy_.csproj | 1 + MCGalaxy/Network/ClassicProtocol.cs | 8 ++++++++ MCGalaxy/Network/IGameSession.cs | 2 ++ MCGalaxy/Network/Packets/Packet.cs | 6 +++--- MCGalaxy/Player/CinematicGui.cs | 23 +++++++++++++++++++++++ MCGalaxy/Player/Player.Fields.cs | 3 ++- 6 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 MCGalaxy/Player/CinematicGui.cs diff --git a/MCGalaxy/MCGalaxy_.csproj b/MCGalaxy/MCGalaxy_.csproj index cc3c5db54..10bd0fa7a 100644 --- a/MCGalaxy/MCGalaxy_.csproj +++ b/MCGalaxy/MCGalaxy_.csproj @@ -639,6 +639,7 @@ + diff --git a/MCGalaxy/Network/ClassicProtocol.cs b/MCGalaxy/Network/ClassicProtocol.cs index 52f8b646c..43e774971 100644 --- a/MCGalaxy/Network/ClassicProtocol.cs +++ b/MCGalaxy/Network/ClassicProtocol.cs @@ -727,5 +727,13 @@ static byte FlippedPitch(byte pitch) { if (pitch > 64 && pitch < 192) return pitch; else return 128; } + + public override void SendCinematicGui(CinematicGui gui) { + float barSize = gui.barSize; + barSize = Math.Max(0, Math.Min(1, barSize)); + Send(Packet.SetCinematicGui( + gui.hideHand, gui.hideHotbar, gui.barColor.R, gui.barColor.G, gui.barColor.B, gui.barColor.A, + (ushort)(barSize * ushort.MaxValue))); + } } } diff --git a/MCGalaxy/Network/IGameSession.cs b/MCGalaxy/Network/IGameSession.cs index 88f853304..21128e61b 100644 --- a/MCGalaxy/Network/IGameSession.cs +++ b/MCGalaxy/Network/IGameSession.cs @@ -148,5 +148,7 @@ public virtual BlockID ConvertBlock(BlockID block) { if (!hasCustomBlocks) raw = fallback[(byte)raw]; return raw; } + + public abstract void SendCinematicGui(CinematicGui gui); } } diff --git a/MCGalaxy/Network/Packets/Packet.cs b/MCGalaxy/Network/Packets/Packet.cs index 7df93f91f..5d7a944a4 100644 --- a/MCGalaxy/Network/Packets/Packet.cs +++ b/MCGalaxy/Network/Packets/Packet.cs @@ -691,9 +691,9 @@ public static byte[] SetLightingMode(LightingMode mode, bool locked) { return buffer; } - public static byte[] SetCinematicGui(bool hideHand, bool hideHotbar, byte r, byte g, byte b, byte opacity, byte apertureSize) + public static byte[] SetCinematicGui(bool hideHand, bool hideHotbar, byte r, byte g, byte b, byte opacity, ushort barSize) { - byte[] buffer = new byte[8]; + byte[] buffer = new byte[9]; buffer[0] = Opcode.CpeCinematicGui; buffer[1] = (byte)(hideHand ? 1 : 0); buffer[2] = (byte)(hideHotbar ? 1 : 0); @@ -703,7 +703,7 @@ public static byte[] SetCinematicGui(bool hideHand, bool hideHotbar, byte r, byt buffer[5] = b; buffer[6] = opacity; - buffer[7] = apertureSize; + NetUtils.WriteU16(barSize, buffer, 7); return buffer; } #endregion diff --git a/MCGalaxy/Player/CinematicGui.cs b/MCGalaxy/Player/CinematicGui.cs new file mode 100644 index 000000000..a49c30424 --- /dev/null +++ b/MCGalaxy/Player/CinematicGui.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace MCGalaxy { + public class CinematicGui { + public void HideHand(Player p, bool hidden) { hideHand = hidden; p.Session.SendCinematicGui(this); } + public bool hideHand; + + public void HideHotbar(Player p, bool hidden) { hideHotbar = hidden; p.Session.SendCinematicGui(this); } + public bool hideHotbar; + + public void SetBarColor(Player p, ColorDesc color) { barColor = color; p.Session.SendCinematicGui(this); } + public ColorDesc barColor; + + /// + /// From 0 to 1 where 0 is not visible and 1 is screen fully covered + /// + public void SetBarSize(Player p, float size) { barSize = size; p.Session.SendCinematicGui(this); } + public float barSize; + } +} diff --git a/MCGalaxy/Player/Player.Fields.cs b/MCGalaxy/Player/Player.Fields.cs index dc0b74578..c093bdf8d 100644 --- a/MCGalaxy/Player/Player.Fields.cs +++ b/MCGalaxy/Player/Player.Fields.cs @@ -35,7 +35,8 @@ public partial class Player : IDisposable { public static string lastMSG = ""; internal PersistentMessages persistentMessages = new PersistentMessages(); public Zone ZoneIn; - + public CinematicGui gui = new CinematicGui(); + //TpA internal bool Request; internal string senderName = "";