From 49ce83671d8238f72dd2429ee1328495819d3e9e Mon Sep 17 00:00:00 2001 From: Oliver1337 <104810162+OliverLesen@users.noreply.github.com> Date: Mon, 9 Mar 2026 19:03:59 -0300 Subject: [PATCH] Update UIControl_PlayerSkinPreview.cpp Update UIControl_PlayerSkinPreview.cpp This file now makes each UI preview build its own HumanoidModel, according to the skin of that specific slot. Steve 64x32 preview shows Steve 64x32 Standard 64x64 preview shows Skin 64x64 Slim 64x64 preview shows Slim 64x64 --- .../Common/UI/UIControl_PlayerSkinPreview.cpp | 198 +++++++----------- 1 file changed, 77 insertions(+), 121 deletions(-) diff --git a/Minecraft.Client/Common/UI/UIControl_PlayerSkinPreview.cpp b/Minecraft.Client/Common/UI/UIControl_PlayerSkinPreview.cpp index d74bd185c..8d17dc137 100644 --- a/Minecraft.Client/Common/UI/UIControl_PlayerSkinPreview.cpp +++ b/Minecraft.Client/Common/UI/UIControl_PlayerSkinPreview.cpp @@ -13,6 +13,9 @@ //#define SKIN_PREVIEW_BOB_ANIM #define SKIN_PREVIEW_WALKING_ANIM +static const unsigned int ANIM_64x64_CLASSIC_SKIN = 0x00040000; +static const unsigned int ANIM_64x64_ALEX_SLIM_SKIN = 0x00080000; + UIControl_PlayerSkinPreview::UIControl_PlayerSkinPreview() { UIControl::setControlType(UIControl::ePlayerSkinPreview); @@ -57,6 +60,59 @@ UIControl_PlayerSkinPreview::UIControl_PlayerSkinPreview() m_bAnimatingToFacing = false; m_pvAdditionalModelParts=NULL; m_uiAnimOverrideBitmask=0L; + + m_pPreviewModel = NULL; + m_iPreviewModelType = HumanoidModel::ePlayerModel_Steve; + m_iPreviewTexWidth = 64; + m_iPreviewTexHeight = 32; +} + +UIControl_PlayerSkinPreview::~UIControl_PlayerSkinPreview() +{ + DestroyPreviewModel(); +} + +void UIControl_PlayerSkinPreview::DestroyPreviewModel() +{ + if (m_pPreviewModel != NULL) + { + delete m_pPreviewModel; + m_pPreviewModel = NULL; + } +} + +void UIControl_PlayerSkinPreview::RebuildPreviewModel() +{ + int iWantedModelType = HumanoidModel::ePlayerModel_Steve; + int iWantedTexWidth = 64; + int iWantedTexHeight = 32; + + if ((m_uiAnimOverrideBitmask & ANIM_64x64_ALEX_SLIM_SKIN) != 0) + { + iWantedModelType = HumanoidModel::ePlayerModel_Alex; + iWantedTexHeight = 64; + } + else if ((m_uiAnimOverrideBitmask & ANIM_64x64_CLASSIC_SKIN) != 0) + { + iWantedModelType = HumanoidModel::ePlayerModel_Steve; + iWantedTexHeight = 64; + } + + if (m_pPreviewModel != NULL && + m_iPreviewModelType == iWantedModelType && + m_iPreviewTexWidth == iWantedTexWidth && + m_iPreviewTexHeight == iWantedTexHeight) + { + return; + } + + DestroyPreviewModel(); + + bool bSlim = (iWantedModelType == HumanoidModel::ePlayerModel_Alex); + m_pPreviewModel = new HumanoidModel(0.0f, 0.0f, iWantedTexWidth, iWantedTexHeight, bSlim); + m_iPreviewModelType = iWantedModelType; + m_iPreviewTexWidth = iWantedTexWidth; + m_iPreviewTexHeight = iWantedTexHeight; } void UIControl_PlayerSkinPreview::tick() @@ -67,8 +123,6 @@ void UIControl_PlayerSkinPreview::tick() { ++m_framesAnimatingRotation; m_yRot = m_fOriginalRotation + m_framesAnimatingRotation * ( (m_fTargetRotation - m_fOriginalRotation) / CHANGING_SKIN_FRAMES ); - - //if(m_framesAnimatingRotation == CHANGING_SKIN_FRAMES) m_bAnimatingToFacing = false; } else { @@ -114,9 +168,6 @@ void UIControl_PlayerSkinPreview::SetTexture(const wstring &url, TEXTURE_NAME ba if(app.GetGameSettings(eGameSetting_CustomSkinAnim)==0 ) { - // We have a force animation for some skins (claptrap) - // 4J-PB - treat all the eAnim_Disable flags as a force anim - if((uiAnimOverrideBitmask & HumanoidModel::m_staticBitmaskIgnorePlayerCustomAnimSetting)!=0) { m_uiAnimOverrideBitmask=uiAnimOverrideBitmask; @@ -132,6 +183,7 @@ void UIControl_PlayerSkinPreview::SetTexture(const wstring &url, TEXTURE_NAME ba } m_pvAdditionalModelParts=app.GetAdditionalModelParts(app.getSkinIdFromPath(m_customTextureUrl)); + RebuildPreviewModel(); } void UIControl_PlayerSkinPreview::SetFacing(ESkinPreviewFacing facing, bool bAnimate /*= false*/) @@ -195,34 +247,22 @@ void UIControl_PlayerSkinPreview::render(IggyCustomDrawCallbackRegion *region) float yo = height; glTranslatef(xo, yo - 3.5f, 50.0f); - //glTranslatef(120.0f, 294, 0.0f); float ss; - - // Base scale on height of this control - // Potentially we might want separate x & y scales here ss = width / (m_fScreenWidth / m_fScreenHeight); glScalef(-ss, ss, ss); glRotatef(180, 0, 0, 1); - //glRotatef(45 + 90, 0, 1, 0); Lighting::turnOn(); - //glRotatef(-45 - 90, 0, 1, 0); - glRotatef(-(float)m_xRot, 1, 0, 0); - // 4J Stu - Turning on hideGui while we do this stops the name rendering in split-screen bool wasHidingGui = pMinecraft->options->hideGui; pMinecraft->options->hideGui = true; - //EntityRenderDispatcher::instance->render(pMinecraft->localplayers[0], 0, 0, 0, 0, 1); EntityRenderer *renderer = EntityRenderDispatcher::instance->getRenderer(eTYPE_LOCALPLAYER); if (renderer != NULL) { - // 4J-PB - any additional parts to turn on for this player (skin dependent) - //vector *pAdditionalModelParts=mob->GetAdditionalModelParts(); - if(m_pvAdditionalModelParts && m_pvAdditionalModelParts->size()!=0) { for(auto& pModelPart : *m_pvAdditionalModelParts) @@ -232,9 +272,7 @@ void UIControl_PlayerSkinPreview::render(IggyCustomDrawCallbackRegion *region) } render(renderer,0,0,0,0,1); - //renderer->postRender(entity, x, y, z, rot, a); - // hide the additional parts if(m_pvAdditionalModelParts && m_pvAdditionalModelParts->size()!=0) { for(auto& pModelPart : *m_pvAdditionalModelParts) @@ -251,20 +289,25 @@ void UIControl_PlayerSkinPreview::render(IggyCustomDrawCallbackRegion *region) glDisable(GL_RESCALE_NORMAL); } -// 4J Stu - Modified version of MobRenderer::render that does not require an actual entity void UIControl_PlayerSkinPreview::render(EntityRenderer *renderer, double x, double y, double z, float rot, float a) { glPushMatrix(); glDisable(GL_CULL_FACE); - HumanoidModel *model = (HumanoidModel *)renderer->getModel(); + HumanoidModel *model = m_pPreviewModel; + if (model == NULL) + { + RebuildPreviewModel(); + model = m_pPreviewModel; + } - //getAttackAnim(mob, a); - //if (armor != NULL) armor->attackTime = model->attackTime; - //model->riding = mob->isRiding(); - //if (armor != NULL) armor->riding = model->riding; + if (model == NULL) + { + glEnable(GL_CULL_FACE); + glPopMatrix(); + return; + } - // 4J Stu - Remember to reset these values once the rendering is done if you add another one model->attackTime = 0; model->sneaking = false; model->holdingRightHand = false; @@ -275,7 +318,6 @@ void UIControl_PlayerSkinPreview::render(EntityRenderer *renderer, double x, dou model->eating_t = 0; model->young = false; model->riding = false; - model->m_uiAnimOverrideBitmask = m_uiAnimOverrideBitmask; if( !m_bAnimatingToFacing ) @@ -299,39 +341,29 @@ void UIControl_PlayerSkinPreview::render(EntityRenderer *renderer, double x, dou }; } + float bodyRot = m_yRot; + float headRot = m_yRot; + float headRotx = 0; - float bodyRot = m_yRot; //(mob->yBodyRotO + (mob->yBodyRot - mob->yBodyRotO) * a); - float headRot = m_yRot; //(mob->yRotO + (mob->yRot - mob->yRotO) * a); - float headRotx = 0; //(mob->xRotO + (mob->xRot - mob->xRotO) * a); - - //setupPosition(mob, x, y, z); - // is equivalent to glTranslatef((float) x, (float) y, (float) z); - //float bob = getBob(mob, a); #ifdef SKIN_PREVIEW_BOB_ANIM float bob = (m_bobTick + a)/2; - ++m_bobTick; if(m_bobTick>=360*2) m_bobTick = 0; #else float bob = 0.0f; #endif - //setupRotations(mob, bob, bodyRot, a); - // is equivalent to glRotatef(180 - bodyRot, 0, 1, 0); float _scale = 1 / 16.0f; glEnable(GL_RESCALE_NORMAL); glScalef(-1, -1, 1); - //scale(mob, a); - // is equivalent to float s = 15 / 16.0f; glScalef(s, s, s); - // 4J - TomK - pull up character a bit more to make sure extra geo around feet doesn't cause rendering problems on PSVita #ifdef __PSVITA__ glTranslatef(0, -24 * _scale - 1.0f / 16.0f, 0); #else @@ -356,29 +388,18 @@ void UIControl_PlayerSkinPreview::render(EntityRenderer *renderer, double x, dou MemSect(0); glEnable(GL_ALPHA_TEST); - //model->prepareMobModel(mob, wp, ws, a); model->render(nullptr, wp, ws, bob, headRot - bodyRot, headRotx, _scale, true); - /*for (int i = 0; i < MAX_ARMOR_LAYERS; i++) - { - if (prepareArmor(mob, i, a)) - { - armor->render(wp, ws, bob, headRot - bodyRot, headRotx, _scale, true); - glDisable(GL_BLEND); - glEnable(GL_ALPHA_TEST); - } - }*/ - //additionalRendering(mob, a); if (bindTexture(m_capeTextureUrl, L"" )) { glPushMatrix(); glTranslatef(0, 0, 2 / 16.0f); - double xd = 0;//(mob->xCloakO + (mob->xCloak - mob->xCloakO) * a) - (mob->xo + (mob->x - mob->xo) * a); - double yd = 0;//(mob->yCloakO + (mob->yCloak - mob->yCloakO) * a) - (mob->yo + (mob->y - mob->yo) * a); - double zd = 0;//(mob->zCloakO + (mob->zCloak - mob->zCloakO) * a) - (mob->zo + (mob->z - mob->zo) * a); + double xd = 0; + double yd = 0; + double zd = 0; - float yr = 1;//mob->yBodyRotO + (mob->yBodyRot - mob->yBodyRotO) * a; + float yr = 1; double xa = sin(yr * PI / 180); double za = -cos(yr * PI / 180); @@ -390,9 +411,7 @@ void UIControl_PlayerSkinPreview::render(EntityRenderer *renderer, double x, dou float lean2 = (float) (xd * za - zd * xa) * 100; if (lean < 0) lean = 0; - //float pow = 1;//mob->oBob + (bob - mob->oBob) * a; - - flap += 1;//sin((mob->walkDistO + (mob->walkDist - mob->walkDistO) * a) * 6) * 32 * pow; + flap += 1; if (model->sneaking) { flap += 25; @@ -405,69 +424,14 @@ void UIControl_PlayerSkinPreview::render(EntityRenderer *renderer, double x, dou model->renderCloak(1 / 16.0f,true); glPopMatrix(); } - /* - float br = mob->getBrightness(a); - int overlayColor = getOverlayColor(mob, br, a); - if (((overlayColor >> 24) & 0xff) > 0 || mob->hurtTime > 0 || mob->deathTime > 0) - { - glDisable(GL_TEXTURE_2D); - glDisable(GL_ALPHA_TEST); - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glDepthFunc(GL_EQUAL); - - // 4J - changed these renders to not use the compiled version of their models, because otherwise the render states set - // about (in particular the depth & alpha test) don't work with our command buffer versions - if (mob->hurtTime > 0 || mob->deathTime > 0) - { - glColor4f(br, 0, 0, 0.4f); - model->render(wp, ws, bob, headRot - bodyRot, headRotx, _scale, false); - for (int i = 0; i < MAX_ARMOR_LAYERS; i++) - { - if (prepareArmorOverlay(mob, i, a)) - { - glColor4f(br, 0, 0, 0.4f); - armor->render(wp, ws, bob, headRot - bodyRot, headRotx, _scale, false); - } - } - } - - if (((overlayColor >> 24) & 0xff) > 0) - { - float r = ((overlayColor >> 16) & 0xff) / 255.0f; - float g = ((overlayColor >> 8) & 0xff) / 255.0f; - float b = ((overlayColor) & 0xff) / 255.0f; - float aa = ((overlayColor >> 24) & 0xff) / 255.0f; - glColor4f(r, g, b, aa); - model->render(wp, ws, bob, headRot - bodyRot, headRotx, _scale, false); - for (int i = 0; i < MAX_ARMOR_LAYERS; i++) - { - if (prepareArmorOverlay(mob, i, a)) - { - glColor4f(r, g, b, aa); - armor->render(wp, ws, bob, headRot - bodyRot, headRotx, _scale, false); - } - } - } - - glDepthFunc(GL_LEQUAL); - glDisable(GL_BLEND); - glEnable(GL_ALPHA_TEST); - glEnable(GL_TEXTURE_2D); - } - */ glDisable(GL_RESCALE_NORMAL); - glEnable(GL_CULL_FACE); - glPopMatrix(); MemSect(31); - //renderName(mob, x, y, z); MemSect(0); - // Reset the model values to stop the changes we made here affecting anything in game (like the player hand render) model->attackTime = 0; model->sneaking = false; model->holdingRightHand = false; @@ -477,10 +441,6 @@ void UIControl_PlayerSkinPreview::render(EntityRenderer *renderer, double x, dou bool UIControl_PlayerSkinPreview::bindTexture(const wstring& urlTexture, int backupTexture) { Textures *t = Minecraft::GetInstance()->textures; - - // 4J-PB - no http textures on the xbox, mem textures instead - - //int id = t->loadHttpTexture(urlTexture, backupTexture); int id = t->loadMemTexture(urlTexture, backupTexture); if (id >= 0) @@ -497,10 +457,6 @@ bool UIControl_PlayerSkinPreview::bindTexture(const wstring& urlTexture, int bac bool UIControl_PlayerSkinPreview::bindTexture(const wstring& urlTexture, const wstring& backupTexture) { Textures *t = Minecraft::GetInstance()->textures; - - // 4J-PB - no http textures on the xbox, mem textures instead - - //int id = t->loadHttpTexture(urlTexture, backupTexture); int id = t->loadMemTexture(urlTexture, backupTexture); if (id >= 0)