aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.Client/Gui.cpp
diff options
context:
space:
mode:
authorModMaker101 <119018978+ModMaker101@users.noreply.github.com>2026-03-08 19:08:36 -0400
committerGitHub <noreply@github.com>2026-03-08 18:08:36 -0500
commit28614b922fb77149a54da1a87bebfbc98736f296 (patch)
tree7f828ba86a4ee18d0a80d29de64f6199a5412512 /Minecraft.Client/Gui.cpp
parent88798b501d0cf6287b6f87acb2592676e3cec58d (diff)
Modernize project codebase (#906)
* Fixed boats falling and a TP glitch #266 * Replaced every C-style cast with C++ ones * Replaced every C-style cast with C++ ones * Fixed boats falling and a TP glitch #266 * Updated NULL to nullptr and fixing some type issues * Modernized and fixed a few bugs - Replaced most instances of `NULL` with `nullptr`. - Replaced most `shared_ptr(new ...)` with `make_shared`. - Removed the `nullptr` macro as it was interfering with the actual nullptr keyword in some instances. * Fixing more conflicts * Replace int loops with size_t and start work on overrides * Add safety checks and fix a issue with vector going OOR
Diffstat (limited to 'Minecraft.Client/Gui.cpp')
-rw-r--r--Minecraft.Client/Gui.cpp93
1 files changed, 50 insertions, 43 deletions
diff --git a/Minecraft.Client/Gui.cpp b/Minecraft.Client/Gui.cpp
index 8a3e84db..d3bcda9b 100644
--- a/Minecraft.Client/Gui.cpp
+++ b/Minecraft.Client/Gui.cpp
@@ -28,6 +28,7 @@
#include "..\Minecraft.World\net.minecraft.world.h"
#include "..\Minecraft.World\LevelChunk.h"
#include "..\Minecraft.World\Biome.h"
+#include <Common/UI/UI.h>
ResourceLocation Gui::PUMPKIN_BLUR_LOCATION = ResourceLocation(TN__BLUR__MISC_PUMPKINBLUR);
@@ -62,6 +63,12 @@ void Gui::render(float a, bool mouseFree, int xMouse, int yMouse)
// 4J Stu - I have copied this code for XUI_BaseScene. If/when it gets changed it should be broken out
// 4J - altered to force full screen mode to 3X scaling, and any split screen modes to 2X scaling. This is so that the further scaling by 0.5 that
// happens in split screen modes results in a final scaling of 1 rather than 1.5.
+
+ if (minecraft->player == nullptr)
+ {
+ return;
+ }
+
int splitYOffset;// = 20; // This offset is applied when doing the 2X scaling above to move the gui out of the way of the tool tips
int guiScale;// = ( minecraft->player->m_iScreenSection == C4JRender::VIEWPORT_TYPE_FULLSCREEN ? 3 : 2 );
int iPad=minecraft->player->GetXboxPad();
@@ -87,7 +94,7 @@ void Gui::render(float a, bool mouseFree, int xMouse, int yMouse)
int quickSelectHeight=22;
float fScaleFactorWidth=1.0f,fScaleFactorHeight=1.0f;
bool bTwoPlayerSplitscreen=false;
- currentGuiScaleFactor = (float) guiScale; // Keep static copy of scale so we know how gui coordinates map to physical pixels - this is also affected by the viewport
+ currentGuiScaleFactor = static_cast<float>(guiScale); // Keep static copy of scale so we know how gui coordinates map to physical pixels - this is also affected by the viewport
switch(guiScale)
{
@@ -117,7 +124,7 @@ void Gui::render(float a, bool mouseFree, int xMouse, int yMouse)
iSafezoneYHalf = splitYOffset;
iSafezoneTopYHalf = screenHeight/10;
fScaleFactorWidth=0.5f;
- iWidthOffset=(int)((float)screenWidth*(1.0f - fScaleFactorWidth));
+ iWidthOffset=static_cast<int>((float)screenWidth * (1.0f - fScaleFactorWidth));
iTooltipsYOffset=44;
bTwoPlayerSplitscreen=true;
currentGuiScaleFactor *= 0.5f;
@@ -127,7 +134,7 @@ void Gui::render(float a, bool mouseFree, int xMouse, int yMouse)
iSafezoneYHalf = splitYOffset + screenHeight/10;// 5% (need to treat the whole screen is 2x this screen)
iSafezoneTopYHalf = 0;
fScaleFactorWidth=0.5f;
- iWidthOffset=(int)((float)screenWidth*(1.0f - fScaleFactorWidth));
+ iWidthOffset=static_cast<int>((float)screenWidth * (1.0f - fScaleFactorWidth));
iTooltipsYOffset=44;
bTwoPlayerSplitscreen=true;
currentGuiScaleFactor *= 0.5f;
@@ -697,7 +704,7 @@ void Gui::render(float a, bool mouseFree, int xMouse, int yMouse)
#endif
glPushMatrix();
- glTranslatef((float)xo, (float)yo, 50);
+ glTranslatef(static_cast<float>(xo), static_cast<float>(yo), 50);
float ss = 12;
glScalef(-ss, ss, ss);
glRotatef(180, 0, 0, 1);
@@ -806,14 +813,14 @@ void Gui::render(float a, bool mouseFree, int xMouse, int yMouse)
glDisable(GL_DEPTH_TEST);
glDisable(GL_ALPHA_TEST);
int timer = minecraft->player->getSleepTimer();
- float amount = (float) timer / (float) Player::SLEEP_DURATION;
+ float amount = static_cast<float>(timer) / static_cast<float>(Player::SLEEP_DURATION);
if (amount > 1)
{
// waking up
- amount = 1.0f - ((float) (timer - Player::SLEEP_DURATION) / (float) Player::WAKE_UP_DURATION);
+ amount = 1.0f - (static_cast<float>(timer - Player::SLEEP_DURATION) / static_cast<float>(Player::WAKE_UP_DURATION));
}
- int color = (int) (220.0f * amount) << 24 | (0x101020);
+ int color = static_cast<int>(220.0f * amount) << 24 | (0x101020);
fill(0, 0, screenWidth/fScaleFactorWidth, screenHeight/fScaleFactorHeight, color);
glEnable(GL_ALPHA_TEST);
glEnable(GL_DEPTH_TEST);
@@ -825,9 +832,9 @@ void Gui::render(float a, bool mouseFree, int xMouse, int yMouse)
glDisable(GL_DEPTH_TEST);
glDisable(GL_ALPHA_TEST);
int timer = minecraft->player->getDeathFadeTimer();
- float amount = (float) timer / (float) Player::DEATHFADE_DURATION;
+ float amount = static_cast<float>(timer) / static_cast<float>(Player::DEATHFADE_DURATION);
- int color = (int) (220.0f * amount) << 24 | (0x200000);
+ int color = static_cast<int>(220.0f * amount) << 24 | (0x200000);
fill(0, 0, screenWidth/fScaleFactorWidth, screenHeight/fScaleFactorHeight, color);
glEnable(GL_ALPHA_TEST);
glEnable(GL_DEPTH_TEST);
@@ -844,21 +851,21 @@ void Gui::render(float a, bool mouseFree, int xMouse, int yMouse)
#ifndef _FINAL_BUILD
MemSect(31);
- if (minecraft->options->renderDebug)
+ if (minecraft->options->renderDebug && minecraft->player != nullptr && minecraft->level != nullptr)
{
const int debugLeft = 1;
const int debugTop = 1;
const float maxContentWidth = 1200.f;
const float maxContentHeight = 420.f;
- float scale = (float)(screenWidth - debugLeft - 8) / maxContentWidth;
- float scaleV = (float)(screenHeight - debugTop - 80) / maxContentHeight;
+ float scale = static_cast<float>(screenWidth - debugLeft - 8) / maxContentWidth;
+ float scaleV = static_cast<float>(screenHeight - debugTop - 80) / maxContentHeight;
if (scaleV < scale) scale = scaleV;
if (scale > 1.f) scale = 1.f;
if (scale < 0.5f) scale = 0.5f;
glPushMatrix();
- glTranslatef((float)debugLeft, (float)debugTop, 0.f);
+ glTranslatef(static_cast<float>(debugLeft), static_cast<float>(debugTop), 0.f);
glScalef(scale, scale, 1.f);
- glTranslatef((float)-debugLeft, (float)-debugTop, 0.f);
+ glTranslatef(static_cast<float>(-debugLeft), static_cast<float>(-debugTop), 0.f);
vector<wstring> lines;
@@ -986,11 +993,11 @@ void Gui::render(float a, bool mouseFree, int xMouse, int yMouse)
wfeature[eTerrainFeature_Village] = L"Village: ";
wfeature[eTerrainFeature_Ravine] = L"Ravine: ";
- float maxW = (float)(screenWidth - debugLeft - 8) / scale;
- float maxWForContent = maxW - (float)font->width(L"...");
+ float maxW = static_cast<float>(screenWidth - debugLeft - 8) / scale;
+ float maxWForContent = maxW - static_cast<float>(font->width(L"..."));
bool truncated[eTerrainFeature_Count] = {};
- for (int i = 0; i < (int)app.m_vTerrainFeatures.size(); i++)
+ for (size_t i = 0; i < app.m_vTerrainFeatures.size(); i++)
{
FEATURE_DATA *pFeatureData = app.m_vTerrainFeatures[i];
int type = pFeatureData->eTerrainFeature;
@@ -1016,7 +1023,7 @@ void Gui::render(float a, bool mouseFree, int xMouse, int yMouse)
}
lines.push_back(L""); // Add a spacer line
- for (int i = eTerrainFeature_Stronghold; i <= (int)eTerrainFeature_Ravine; i++)
+ for (int i = eTerrainFeature_Stronghold; i <= static_cast<int>(eTerrainFeature_Ravine); i++)
{
lines.push_back(wfeature[i]);
}
@@ -1243,10 +1250,10 @@ void Gui::renderPumpkin(int w, int h)
MemSect(0);
Tesselator *t = Tesselator::getInstance();
t->begin();
- t->vertexUV((float)(0), (float)( h), (float)( -90), (float)( 0), (float)( 1));
- t->vertexUV((float)(w), (float)( h), (float)( -90), (float)( 1), (float)( 1));
- t->vertexUV((float)(w), (float)( 0), (float)( -90), (float)( 1), (float)( 0));
- t->vertexUV((float)(0), (float)( 0), (float)( -90), (float)( 0), (float)( 0));
+ t->vertexUV(static_cast<float>(0), static_cast<float>(h), static_cast<float>(-90), static_cast<float>(0), static_cast<float>(1));
+ t->vertexUV(static_cast<float>(w), static_cast<float>(h), static_cast<float>(-90), static_cast<float>(1), static_cast<float>(1));
+ t->vertexUV(static_cast<float>(w), static_cast<float>(0), static_cast<float>(-90), static_cast<float>(1), static_cast<float>(0));
+ t->vertexUV(static_cast<float>(0), static_cast<float>(0), static_cast<float>(-90), static_cast<float>(0), static_cast<float>(0));
t->end();
glDepthMask(true);
glEnable(GL_DEPTH_TEST);
@@ -1307,10 +1314,10 @@ void Gui::renderTp(float br, int w, int h)
float v1 = slot->getV1();
Tesselator *t = Tesselator::getInstance();
t->begin();
- t->vertexUV((float)(0), (float)( h), (float)( -90), (float)( u0), (float)( v1));
- t->vertexUV((float)(w), (float)( h), (float)( -90), (float)( u1), (float)( v1));
- t->vertexUV((float)(w), (float)( 0), (float)( -90), (float)( u1), (float)( v0));
- t->vertexUV((float)(0), (float)( 0), (float)( -90), (float)( u0), (float)( v0));
+ t->vertexUV(static_cast<float>(0), static_cast<float>(h), static_cast<float>(-90), (float)( u0), (float)( v1));
+ t->vertexUV(static_cast<float>(w), static_cast<float>(h), static_cast<float>(-90), (float)( u1), (float)( v1));
+ t->vertexUV(static_cast<float>(w), static_cast<float>(0), static_cast<float>(-90), (float)( u1), (float)( v0));
+ t->vertexUV(static_cast<float>(0), static_cast<float>(0), static_cast<float>(-90), (float)( u0), (float)( v0));
t->end();
glDepthMask(true);
glEnable(GL_DEPTH_TEST);
@@ -1328,10 +1335,10 @@ void Gui::renderSlot(int slot, int x, int y, float a)
if (pop > 0)
{
glPushMatrix();
- float squeeze = 1 + pop / (float) Inventory::POP_TIME_DURATION;
- glTranslatef((float)(x + 8), (float)(y + 12), 0);
+ float squeeze = 1 + pop / static_cast<float>(Inventory::POP_TIME_DURATION);
+ glTranslatef(static_cast<float>(x + 8), static_cast<float>(y + 12), 0);
glScalef(1 / squeeze, (squeeze + 1) / 2, 1);
- glTranslatef((float)-(x + 8), (float)-(y + 12), 0);
+ glTranslatef(static_cast<float>(-(x + 8)), static_cast<float>(-(y + 12)), 0);
}
itemRenderer->renderAndDecorateItem(minecraft->font, minecraft->textures, item, x, y);
@@ -1470,7 +1477,7 @@ void Gui::addMessage(const wstring& _string,int iPad,bool bIsDeathMessage)
{
i++;
}
- int iLast=(int)string.find_last_of(L" ",i);
+ size_t iLast=string.find_last_of(L" ",i);
switch(XGetLanguage())
{
case XC_LANGUAGE_JAPANESE:
@@ -1479,7 +1486,7 @@ void Gui::addMessage(const wstring& _string,int iPad,bool bIsDeathMessage)
iLast = maximumChars;
break;
default:
- iLast=(int)string.find_last_of(L" ",i);
+ iLast=string.find_last_of(L" ",i);
break;
}
@@ -1539,7 +1546,7 @@ float Gui::getOpacity(int iPad, DWORD index)
float Gui::getJukeboxOpacity(int iPad)
{
float t = overlayMessageTime - lastTickA;
- int alpha = (int) (t * 256 / 20);
+ int alpha = static_cast<int>(t * 256 / 20);
if (alpha > 255) alpha = 255;
alpha /= 255;
@@ -1573,7 +1580,7 @@ void Gui::renderGraph(int dataLength, int dataPos, int64_t *dataA, float dataASc
glClear(GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
- glOrtho(0, (float)minecraft->width, (float)height, 0, 1000, 3000);
+ glOrtho(0, static_cast<float>(minecraft->width), static_cast<float>(height), 0, 1000, 3000);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0, 0, -2000);
@@ -1604,8 +1611,8 @@ void Gui::renderGraph(int dataLength, int dataPos, int64_t *dataA, float dataASc
int64_t aVal = dataA[i] / dataAScale;
- t->vertex((float)(xScale*i + 0.5f), (float)( height - aVal + 0.5f), (float)( 0));
- t->vertex((float)(xScale*i + 0.5f), (float)( height + 0.5f), (float)( 0));
+ t->vertex((float)(xScale*i + 0.5f), (float)( height - aVal + 0.5f), static_cast<float>(0));
+ t->vertex((float)(xScale*i + 0.5f), (float)( height + 0.5f), static_cast<float>(0));
}
if( dataB != NULL )
@@ -1621,8 +1628,8 @@ void Gui::renderGraph(int dataLength, int dataPos, int64_t *dataA, float dataASc
int64_t bVal = dataB[i] / dataBScale;
- t->vertex((float)(xScale*i + (xScale - 1) + 0.5f), (float)( height - bVal + 0.5f), (float)( 0));
- t->vertex((float)(xScale*i + (xScale - 1) + 0.5f), (float)( height + 0.5f), (float)( 0));
+ t->vertex((float)(xScale*i + (xScale - 1) + 0.5f), (float)( height - bVal + 0.5f), static_cast<float>(0));
+ t->vertex((float)(xScale*i + (xScale - 1) + 0.5f), (float)( height + 0.5f), static_cast<float>(0));
}
}
t->end();
@@ -1637,7 +1644,7 @@ void Gui::renderStackedGraph(int dataPos, int dataLength, int dataSources, int64
glClear(GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
- glOrtho(0, (float)minecraft->width, (float)height, 0, 1000, 3000);
+ glOrtho(0, static_cast<float>(minecraft->width), static_cast<float>(height), 0, 1000, 3000);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0, 0, -2000);
@@ -1666,15 +1673,15 @@ void Gui::renderStackedGraph(int dataPos, int dataLength, int dataSources, int64
if( thisVal > 0 )
{
- float vary = (float)source/dataSources;
+ float vary = static_cast<float>(source)/dataSources;
int fColour = floor(vary * 0xffffff);
int colour = 0xff000000 + fColour;
//printf("Colour is %x\n", colour);
t->color(colour);
- t->vertex((float)(i + 0.5f), (float)( height - topVal - thisVal + 0.5f), (float)( 0));
- t->vertex((float)(i + 0.5f), (float)( height - topVal + 0.5f), (float)( 0));
+ t->vertex((float)(i + 0.5f), (float)( height - topVal - thisVal + 0.5f), static_cast<float>(0));
+ t->vertex((float)(i + 0.5f), (float)( height - topVal + 0.5f), static_cast<float>(0));
topVal += thisVal;
}
@@ -1685,8 +1692,8 @@ void Gui::renderStackedGraph(int dataPos, int dataLength, int dataSources, int64
{
t->color(0xff000000);
- t->vertex((float)(0 + 0.5f), (float)( height - (horiz*100) + 0.5f), (float)( 0));
- t->vertex((float)(dataLength + 0.5f), (float)( height - (horiz*100) + 0.5f), (float)( 0));
+ t->vertex((float)(0 + 0.5f), (float)( height - (horiz*100) + 0.5f), static_cast<float>(0));
+ t->vertex((float)(dataLength + 0.5f), (float)( height - (horiz*100) + 0.5f), static_cast<float>(0));
}
}
t->end();