Increase network precision of cinematic bar size

This commit is contained in:
Goodlyay 2024-08-23 20:42:27 -07:00
parent e19ca19e34
commit 5ba6d841e1
3 changed files with 13 additions and 13 deletions

View File

@ -313,16 +313,16 @@ void Gui_ShowCinematicBars() {
int screenWidth = Window_Main.Width; int screenWidth = Window_Main.Width;
int screenHeight = Window_Main.Height; int screenHeight = Window_Main.Height;
// Ensure aperture size is clamped between 0 and 1 // Ensure bar size is clamped between 0 and 1
if (Gui.ApertureSize < 0.0f) Gui.ApertureSize = 0.0f; if (Gui.BarSize < 0.0f) Gui.BarSize = 0.0f;
if (Gui.ApertureSize > 1.0f) Gui.ApertureSize = 1.0f; if (Gui.BarSize > 1.0f) Gui.BarSize = 1.0f;
// If aperture size is 1, just draw 1 rectangle instead of 2 // If bar size is 1, just draw 1 rectangle instead of 2
if (Gui.ApertureSize == 1.0f) { if (Gui.BarSize == 1.0f) {
Gfx_Draw2DGradient(0, 0, screenWidth, screenHeight, Gui.CinematicBarColor, Gui.CinematicBarColor); Gfx_Draw2DGradient(0, 0, screenWidth, screenHeight, Gui.CinematicBarColor, Gui.CinematicBarColor);
} else { } else {
// Calculate the height of each bar based on the aperture size // Calculate the height of each bar based on the bar size
int barHeight = (int)(screenHeight * Gui.ApertureSize / 2.0f); int barHeight = (int)(screenHeight * Gui.BarSize / 2.0f);
Gfx_Draw2DGradient(0, 0, screenWidth, barHeight, Gui.CinematicBarColor, Gui.CinematicBarColor); Gfx_Draw2DGradient(0, 0, screenWidth, barHeight, Gui.CinematicBarColor, Gui.CinematicBarColor);
Gfx_Draw2DGradient(0, screenHeight - barHeight, screenWidth, barHeight, Gui.CinematicBarColor, Gui.CinematicBarColor); Gfx_Draw2DGradient(0, screenHeight - barHeight, screenWidth, barHeight, Gui.CinematicBarColor, Gui.CinematicBarColor);
@ -338,7 +338,7 @@ void Gui_RenderGui(float delta) {
Texture_Render(&touchBgTex); Texture_Render(&touchBgTex);
#endif #endif
if (Gui.ApertureSize > 0) Gui_ShowCinematicBars(); if (Gui.BarSize > 0) Gui_ShowCinematicBars();
/* Draw back to front so highest priority screen is on top */ /* Draw back to front so highest priority screen is on top */
for (i = Gui.ScreensCount - 1; i >= 0; i--) for (i = Gui.ScreensCount - 1; i >= 0; i--)

View File

@ -62,8 +62,8 @@ CC_VAR extern struct _GuiData {
cc_bool HideHand; cc_bool HideHand;
/* Whether the hotbar should be hidden. */ /* Whether the hotbar should be hidden. */
cc_bool HideHotbar; cc_bool HideHotbar;
/* The height of the cinematic black bars. */ /* The height of the cinematic bars, where 0 = no bars visible and 1 = bars completely cover the screen. */
float ApertureSize; float BarSize;
/* The color of the cinematic bars, if enabled. */ /* The color of the cinematic bars, if enabled. */
PackedCol CinematicBarColor; PackedCol CinematicBarColor;
} Gui; } Gui;

View File

@ -1562,12 +1562,12 @@ static void CPE_LightingMode(cc_uint8* data) {
static void CPE_CinematicGui(cc_uint8* data) { static void CPE_CinematicGui(cc_uint8* data) {
cc_bool hideHand = data[0]; cc_bool hideHand = data[0];
cc_bool hideHotbar = data[1]; cc_bool hideHotbar = data[1];
cc_uint8 apertureSize = data[6]; cc_uint16 barSize = Stream_GetU16_BE(data + 6);
HeldBlockRenderer_Show = !hideHand && Options_GetBool(OPT_SHOW_BLOCK_IN_HAND, true); HeldBlockRenderer_Show = !hideHand && Options_GetBool(OPT_SHOW_BLOCK_IN_HAND, true);
Gui.HideHotbar = hideHotbar; Gui.HideHotbar = hideHotbar;
Gui.CinematicBarColor = PackedCol_Make(data[2], data[3], data[4], data[5]); Gui.CinematicBarColor = PackedCol_Make(data[2], data[3], data[4], data[5]);
Gui.ApertureSize = (float)apertureSize / 255.0; Gui.BarSize = (float)barSize / UInt16_MaxValue;
} }
static void CPE_Reset(void) { static void CPE_Reset(void) {
@ -1613,7 +1613,7 @@ static void CPE_Reset(void) {
Net_Set(OPCODE_PLUGIN_MESSAGE, CPE_PluginMessage, 66); Net_Set(OPCODE_PLUGIN_MESSAGE, CPE_PluginMessage, 66);
Net_Set(OPCODE_ENTITY_TELEPORT_EXT, CPE_ExtEntityTeleport, 11); Net_Set(OPCODE_ENTITY_TELEPORT_EXT, CPE_ExtEntityTeleport, 11);
Net_Set(OPCODE_LIGHTING_MODE, CPE_LightingMode, 3); Net_Set(OPCODE_LIGHTING_MODE, CPE_LightingMode, 3);
Net_Set(OPCODE_CINEMATIC_GUI, CPE_CinematicGui, 8); Net_Set(OPCODE_CINEMATIC_GUI, CPE_CinematicGui, 9);
} }
static cc_uint8* CPE_Tick(cc_uint8* data) { static cc_uint8* CPE_Tick(cc_uint8* data) {