Skip to content

Commit

Permalink
Add CinematicGui 'gui' class to Player
Browse files Browse the repository at this point in the history
This makes it easier to change individual elements while keeping others persistent across a session
  • Loading branch information
Goodlyay committed Aug 24, 2024
1 parent 37f1ba6 commit 7ab681a
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 4 deletions.
1 change: 1 addition & 0 deletions MCGalaxy/MCGalaxy_.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,7 @@
<Compile Include="Player\Player.Handlers.cs" />
<Compile Include="Player\Player.Login.cs" />
<Compile Include="Player\PlayerActions.cs" />
<Compile Include="Player\CinematicGui.cs" />
<Compile Include="Player\PlayerIgnores.cs" />
<Compile Include="Player\PlayerInfo.cs" />
<Compile Include="Player\PlayerOperations.cs" />
Expand Down
8 changes: 8 additions & 0 deletions MCGalaxy/Network/ClassicProtocol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}
}
}
2 changes: 2 additions & 0 deletions MCGalaxy/Network/IGameSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,5 +148,7 @@ public virtual BlockID ConvertBlock(BlockID block) {
if (!hasCustomBlocks) raw = fallback[(byte)raw];
return raw;
}

public abstract void SendCinematicGui(CinematicGui gui);
}
}
6 changes: 3 additions & 3 deletions MCGalaxy/Network/Packets/Packet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down
23 changes: 23 additions & 0 deletions MCGalaxy/Player/CinematicGui.cs
Original file line number Diff line number Diff line change
@@ -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;

/// <summary>
/// From 0 to 1 where 0 is not visible and 1 is screen fully covered
/// </summary>
public void SetBarSize(Player p, float size) { barSize = size; p.Session.SendCinematicGui(this); }
public float barSize;
}
}
3 changes: 2 additions & 1 deletion MCGalaxy/Player/Player.Fields.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";
Expand Down

0 comments on commit 7ab681a

Please sign in to comment.