the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
1#include "stdafx.h"
2#include "..\..\Minecraft.h"
3#include "..\..\ScreenSizeCalculator.h"
4#include "..\..\EntityRenderDispatcher.h"
5#include "..\..\PlayerRenderer.h"
6#include "..\..\HumanoidModel.h"
7#include "..\..\Lighting.h"
8#include "..\..\..\Minecraft.World\Class.h"
9#include "..\..\..\Minecraft.World\net.minecraft.world.entity.player.h"
10#include "XUI_Ctrl_MinecraftSkinPreview.h"
11#include "XUI_Scene_AbstractContainer.h"
12#include "XUI_Scene_Inventory.h"
13#include "..\..\Options.h"
14#include "..\..\stubs.h"
15#include "..\..\ModelPart.h"
16
17//#define SKIN_PREVIEW_BOB_ANIM
18#define SKIN_PREVIEW_WALKING_ANIM
19
20//-----------------------------------------------------------------------------
21// CXuiCtrlMinecraftSkinPreview class
22//-----------------------------------------------------------------------------
23
24//-----------------------------------------------------------------------------
25CXuiCtrlMinecraftSkinPreview::CXuiCtrlMinecraftSkinPreview() :
26 m_bDirty(FALSE),
27 m_fScale(1.0f),
28 m_fAlpha(1.0f)
29{
30 Minecraft *pMinecraft=Minecraft::GetInstance();
31
32 ScreenSizeCalculator ssc(pMinecraft->options, pMinecraft->width_phys, pMinecraft->height_phys);
33 m_fScreenWidth=(float)pMinecraft->width_phys;
34 m_fRawWidth=(float)ssc.rawWidth;
35 m_fScreenHeight=(float)pMinecraft->height_phys;
36 m_fRawHeight=(float)ssc.rawHeight;
37
38 m_customTextureUrl = L"default";
39 m_backupTexture = TN_MOB_CHAR;
40 m_capeTextureUrl = L"";
41
42 m_yRot = 0;
43 m_xRot = 0;
44
45 m_swingTime = 0.0f;
46 m_bobTick = 0.0f;
47 m_walkAnimSpeedO = 0.0f;
48 m_walkAnimSpeed = 0.0f;
49 m_walkAnimPos = 0.0f;
50
51 m_bAutoRotate = false;
52 m_bRotatingLeft = false;
53
54 m_incXRot = false;
55 m_decXRot = false;
56 m_incYRot = false;
57 m_decYRot = false;
58
59 m_currentAnimation = e_SkinPreviewAnimation_Walking;
60
61 m_fTargetRotation = 0.0f;
62 m_fOriginalRotation = 0.0f;
63 m_framesAnimatingRotation = 0;
64 m_bAnimatingToFacing = false;
65 m_pvAdditionalModelParts=NULL;
66 m_uiAnimOverrideBitmask=0L;
67}
68
69//-----------------------------------------------------------------------------
70HRESULT CXuiCtrlMinecraftSkinPreview::OnInit(XUIMessageInit* pInitData, BOOL& rfHandled)
71{
72 HRESULT hr=S_OK;
73
74 return hr;
75}
76
77void CXuiCtrlMinecraftSkinPreview::SetTexture(const wstring &url, TEXTURE_NAME backupTexture)
78{
79 m_customTextureUrl = url;
80 m_backupTexture = backupTexture;
81
82 unsigned int uiAnimOverrideBitmask = Player::getSkinAnimOverrideBitmask( app.getSkinIdFromPath(m_customTextureUrl) );
83
84 if(app.GetGameSettings(eGameSetting_CustomSkinAnim)==0 )
85 {
86 // We have a force animation for some skins (claptrap)
87 // 4J-PB - treat all the eAnim_Disable flags as a force anim
88
89 if((uiAnimOverrideBitmask & HumanoidModel::m_staticBitmaskIgnorePlayerCustomAnimSetting)!=0)
90 {
91 m_uiAnimOverrideBitmask=uiAnimOverrideBitmask;
92 }
93 else
94 {
95 m_uiAnimOverrideBitmask=0;
96 }
97 }
98 else
99 {
100 m_uiAnimOverrideBitmask = uiAnimOverrideBitmask;
101 }
102
103 app.DebugPrintf("+++ SetTexture - %d, %8x\n",app.getSkinIdFromPath(m_customTextureUrl)&0xFFFFFFF,m_uiAnimOverrideBitmask);
104 m_pvAdditionalModelParts=app.GetAdditionalModelParts(app.getSkinIdFromPath(m_customTextureUrl));
105}
106
107void CXuiCtrlMinecraftSkinPreview::SetFacing(ESkinPreviewFacing facing, bool bAnimate /*= false*/)
108{
109 switch(facing)
110 {
111 case e_SkinPreviewFacing_Forward:
112 m_fTargetRotation = 0;
113 m_bRotatingLeft = true;
114 break;
115 case e_SkinPreviewFacing_Left:
116 m_fTargetRotation = LOOK_LEFT_EXTENT;
117 m_bRotatingLeft = false;
118 break;
119 case e_SkinPreviewFacing_Right:
120 m_fTargetRotation = LOOK_RIGHT_EXTENT;
121 m_bRotatingLeft = true;
122 break;
123 }
124
125 if(!bAnimate)
126 {
127 m_yRot = m_fTargetRotation;
128 m_bAnimatingToFacing = false;
129 }
130 else
131 {
132 m_fOriginalRotation = m_yRot;
133 m_bAnimatingToFacing = true;
134 m_framesAnimatingRotation = 0;
135 }
136}
137
138void CXuiCtrlMinecraftSkinPreview::CycleNextAnimation()
139{
140 m_currentAnimation = (ESkinPreviewAnimations)(m_currentAnimation + 1);
141 if(m_currentAnimation >= e_SkinPreviewAnimation_Count) m_currentAnimation = e_SkinPreviewAnimation_Walking;
142
143 m_swingTime = 0.0f;
144}
145
146void CXuiCtrlMinecraftSkinPreview::CyclePreviousAnimation()
147{
148 m_currentAnimation = (ESkinPreviewAnimations)(m_currentAnimation - 1);
149 if(m_currentAnimation < e_SkinPreviewAnimation_Walking) m_currentAnimation = (ESkinPreviewAnimations)(e_SkinPreviewAnimation_Count - 1);
150
151 m_swingTime = 0.0f;
152}
153
154HRESULT CXuiCtrlMinecraftSkinPreview::OnRender(XUIMessageRender *pRenderData, BOOL &bHandled )
155{
156 if( m_bAnimatingToFacing )
157 {
158 ++m_framesAnimatingRotation;
159 m_yRot = m_fOriginalRotation + m_framesAnimatingRotation * ( (m_fTargetRotation - m_fOriginalRotation) / CHANGING_SKIN_FRAMES );
160
161 //if(m_framesAnimatingRotation == CHANGING_SKIN_FRAMES) m_bAnimatingToFacing = false;
162 }
163 else
164 {
165 if( m_incXRot ) IncrementXRotation();
166 if( m_decXRot ) DecrementXRotation();
167 if( m_incYRot ) IncrementYRotation();
168 if( m_decYRot ) DecrementYRotation();
169
170 if(m_bAutoRotate)
171 {
172 ++m_rotateTick;
173
174 if(m_rotateTick%4==0)
175 {
176 if(m_yRot >= LOOK_LEFT_EXTENT)
177 {
178 m_bRotatingLeft = false;
179 }
180 else if(m_yRot <= LOOK_RIGHT_EXTENT)
181 {
182 m_bRotatingLeft = true;
183 }
184
185 if(m_bRotatingLeft)
186 {
187 IncrementYRotation();
188 }
189 else
190 {
191 DecrementYRotation();
192 }
193 }
194 }
195 }
196
197 HXUIDC hDC = pRenderData->hDC;
198
199 // build and render with the game call
200
201 RenderManager.Set_matrixDirty();
202
203 Minecraft *pMinecraft=Minecraft::GetInstance();
204
205 float alpha = 1.0f;
206 //GetOpacity( &alpha );
207
208 glColor4f(1, 1, 1, alpha);
209 glClear(GL_DEPTH_BUFFER_BIT);
210 glMatrixMode(GL_PROJECTION);
211 glLoadIdentity();
212 glOrtho(0, m_fRawWidth, m_fRawHeight, 0, 1000, 3000);
213 glMatrixMode(GL_MODELVIEW);
214 glLoadIdentity();
215 glTranslatef(0, 0, -2000);
216
217
218 D3DXMATRIX matrix;
219 GetFullXForm(&matrix);
220 float bwidth,bheight;
221 GetBounds(&bwidth,&bheight);
222
223 float xo = ( (matrix._41 + ( (bwidth*matrix._11)/2) ) / m_fScreenWidth ) * m_fRawWidth;
224 float yo = ( (matrix._42 + (bheight*matrix._22) ) / m_fScreenHeight ) * m_fRawHeight;
225
226 glEnable(GL_RESCALE_NORMAL);
227 glEnable(GL_COLOR_MATERIAL);
228
229 glPushMatrix();
230 glTranslatef(xo, yo - 3.5f, 50.0f);
231 float ss;
232
233 // Base scale on height of this control
234 // Potentially we might want separate x & y scales here
235 ss = ( ( (bheight*matrix._22) / m_fScreenHeight ) * m_fRawHeight )/2;
236
237 glScalef(-ss, ss, ss);
238 glRotatef(180, 0, 0, 1);
239
240 //glRotatef(45 + 90, 0, 1, 0);
241 Lighting::turnOn();
242 //glRotatef(-45 - 90, 0, 1, 0);
243
244 glRotatef(-(float)m_xRot, 1, 0, 0);
245
246 // 4J Stu - Turning on hideGui while we do this stops the name rendering in split-screen
247 bool wasHidingGui = pMinecraft->options->hideGui;
248 pMinecraft->options->hideGui = true;
249
250 //EntityRenderDispatcher::instance->render(pMinecraft->localplayers[0], 0, 0, 0, 0, 1);
251 EntityRenderer *renderer = EntityRenderDispatcher::instance->getRenderer(eTYPE_PLAYER);
252 if (renderer != NULL)
253 {
254 // 4J-PB - any additional parts to turn on for this player (skin dependent)
255 //vector<ModelPart *> *pAdditionalModelParts=mob->GetAdditionalModelParts();
256
257 if(m_pvAdditionalModelParts && m_pvAdditionalModelParts->size()!=0)
258 {
259 for(AUTO_VAR(it, m_pvAdditionalModelParts->begin()); it != m_pvAdditionalModelParts->end(); ++it)
260 {
261 ModelPart *pModelPart=*it;
262
263 pModelPart->visible=true;
264 }
265 }
266
267 render(renderer,0,0,0,0,1);
268 //renderer->postRender(entity, x, y, z, rot, a);
269
270 // hide the additional parts
271 if(m_pvAdditionalModelParts && m_pvAdditionalModelParts->size()!=0)
272 {
273 for(AUTO_VAR(it, m_pvAdditionalModelParts->begin()); it != m_pvAdditionalModelParts->end(); ++it)
274 {
275 ModelPart *pModelPart=*it;
276
277 pModelPart->visible=false;
278 }
279 }
280 }
281
282 pMinecraft->options->hideGui = wasHidingGui;
283
284 glPopMatrix();
285 Lighting::turnOff();
286 glDisable(GL_RESCALE_NORMAL);
287
288 XuiRenderRestoreState(hDC);
289
290 bHandled = TRUE;
291
292 return S_OK;
293}
294
295// 4J Stu - Modified version of MobRenderer::render that does not require an actual entity
296void CXuiCtrlMinecraftSkinPreview::render(EntityRenderer *renderer, double x, double y, double z, float rot, float a)
297{
298 glPushMatrix();
299 glDisable(GL_CULL_FACE);
300
301 HumanoidModel *model = (HumanoidModel *)renderer->getModel();
302
303 //getAttackAnim(mob, a);
304 //if (armor != NULL) armor->attackTime = model->attackTime;
305 //model->riding = mob->isRiding();
306 //if (armor != NULL) armor->riding = model->riding;
307
308 // 4J Stu - Remember to reset these values once the rendering is done if you add another one
309 model->attackTime = 0;
310 model->sneaking = false;
311 model->holdingRightHand = false;
312 model->holdingLeftHand = false;
313 model->idle = false;
314 model->eating = false;
315 model->eating_swing = 0;
316 model->eating_t = 0;
317 model->young = false;
318 model->riding = false;
319
320 model->m_uiAnimOverrideBitmask = m_uiAnimOverrideBitmask;
321
322 if( !m_bAnimatingToFacing )
323 {
324 switch( m_currentAnimation )
325 {
326 case e_SkinPreviewAnimation_Sneaking:
327 model->sneaking = true;
328 break;
329 case e_SkinPreviewAnimation_Attacking:
330 model->holdingRightHand = true;
331 m_swingTime++;
332 if (m_swingTime >= (Player::SWING_DURATION * 3) )
333 {
334 m_swingTime = 0;
335 }
336 model->attackTime = m_swingTime / (float) (Player::SWING_DURATION * 3);
337 break;
338 default:
339 break;
340 };
341 }
342
343
344 float bodyRot = m_yRot; //(mob->yBodyRotO + (mob->yBodyRot - mob->yBodyRotO) * a);
345 float headRot = m_yRot; //(mob->yRotO + (mob->yRot - mob->yRotO) * a);
346 float headRotx = 0; //(mob->xRotO + (mob->xRot - mob->xRotO) * a);
347
348 //setupPosition(mob, x, y, z);
349 // is equivalent to
350 glTranslatef((float) x, (float) y, (float) z);
351
352 //float bob = getBob(mob, a);
353#ifdef SKIN_PREVIEW_BOB_ANIM
354 float bob = (m_bobTick + a)/2;
355
356 ++m_bobTick;
357 if(m_bobTick>=360*2) m_bobTick = 0;
358#else
359 float bob = 0.0f;
360#endif
361
362 //setupRotations(mob, bob, bodyRot, a);
363 // is equivalent to
364 glRotatef(180 - bodyRot, 0, 1, 0);
365
366 float _scale = 1 / 16.0f;
367 glEnable(GL_RESCALE_NORMAL);
368 glScalef(-1, -1, 1);
369
370 //scale(mob, a);
371 // is equivalent to
372 float s = 15 / 16.0f;
373 glScalef(s, s, s);
374
375 glTranslatef(0, -24 * _scale - 0.125f / 16.0f, 0);
376
377#ifdef SKIN_PREVIEW_WALKING_ANIM
378 m_walkAnimSpeedO = m_walkAnimSpeed;
379 m_walkAnimSpeed += (0.1f - m_walkAnimSpeed) * 0.4f;
380 m_walkAnimPos += m_walkAnimSpeed;
381 float ws = m_walkAnimSpeedO + (m_walkAnimSpeed - m_walkAnimSpeedO) * a;
382 float wp = m_walkAnimPos - m_walkAnimSpeed * (1 - a);
383#else
384 float ws = 0;
385 float wp = 0;
386#endif
387
388 if (ws > 1) ws = 1;
389
390 MemSect(31);
391 bindTexture(m_customTextureUrl, m_backupTexture);
392 MemSect(0);
393 glEnable(GL_ALPHA_TEST);
394
395 //model->prepareMobModel(mob, wp, ws, a);
396 model->render(nullptr, wp, ws, bob, headRot - bodyRot, headRotx, _scale, true);
397 /*for (int i = 0; i < MAX_ARMOR_LAYERS; i++)
398 {
399 if (prepareArmor(mob, i, a))
400 {
401 armor->render(wp, ws, bob, headRot - bodyRot, headRotx, _scale, true);
402 glDisable(GL_BLEND);
403 glEnable(GL_ALPHA_TEST);
404 }
405 }*/
406
407 //additionalRendering(mob, a);
408 if (bindTexture(m_capeTextureUrl, L"" ))
409 {
410 glPushMatrix();
411 glTranslatef(0, 0, 2 / 16.0f);
412
413 double xd = 0;//(mob->xCloakO + (mob->xCloak - mob->xCloakO) * a) - (mob->xo + (mob->x - mob->xo) * a);
414 double yd = 0;//(mob->yCloakO + (mob->yCloak - mob->yCloakO) * a) - (mob->yo + (mob->y - mob->yo) * a);
415 double zd = 0;//(mob->zCloakO + (mob->zCloak - mob->zCloakO) * a) - (mob->zo + (mob->z - mob->zo) * a);
416
417 float yr = 1;//mob->yBodyRotO + (mob->yBodyRot - mob->yBodyRotO) * a;
418
419 double xa = sin(yr * PI / 180);
420 double za = -cos(yr * PI / 180);
421
422 float flap = (float) yd * 10;
423 if (flap < -6) flap = -6;
424 if (flap > 32) flap = 32;
425 float lean = (float) (xd * xa + zd * za) * 100;
426 float lean2 = (float) (xd * za - zd * xa) * 100;
427 if (lean < 0) lean = 0;
428
429 //float pow = 1;//mob->oBob + (bob - mob->oBob) * a;
430
431 flap += 1;//sin((mob->walkDistO + (mob->walkDist - mob->walkDistO) * a) * 6) * 32 * pow;
432 if (model->sneaking)
433 {
434 flap += 25;
435 }
436
437 glRotatef(6.0f + lean / 2 + flap, 1, 0, 0);
438 glRotatef(lean2 / 2, 0, 0, 1);
439 glRotatef(-lean2 / 2, 0, 1, 0);
440 glRotatef(180, 0, 1, 0);
441 model->renderCloak(1 / 16.0f,true);
442 glPopMatrix();
443 }
444 /*
445 float br = mob->getBrightness(a);
446 int overlayColor = getOverlayColor(mob, br, a);
447
448 if (((overlayColor >> 24) & 0xff) > 0 || mob->hurtTime > 0 || mob->deathTime > 0)
449 {
450 glDisable(GL_TEXTURE_2D);
451 glDisable(GL_ALPHA_TEST);
452 glEnable(GL_BLEND);
453 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
454 glDepthFunc(GL_EQUAL);
455
456 // 4J - changed these renders to not use the compiled version of their models, because otherwise the render states set
457 // about (in particular the depth & alpha test) don't work with our command buffer versions
458 if (mob->hurtTime > 0 || mob->deathTime > 0)
459 {
460 glColor4f(br, 0, 0, 0.4f);
461 model->render(wp, ws, bob, headRot - bodyRot, headRotx, _scale, false);
462 for (int i = 0; i < MAX_ARMOR_LAYERS; i++)
463 {
464 if (prepareArmorOverlay(mob, i, a))
465 {
466 glColor4f(br, 0, 0, 0.4f);
467 armor->render(wp, ws, bob, headRot - bodyRot, headRotx, _scale, false);
468 }
469 }
470 }
471
472 if (((overlayColor >> 24) & 0xff) > 0)
473 {
474 float r = ((overlayColor >> 16) & 0xff) / 255.0f;
475 float g = ((overlayColor >> 8) & 0xff) / 255.0f;
476 float b = ((overlayColor) & 0xff) / 255.0f;
477 float aa = ((overlayColor >> 24) & 0xff) / 255.0f;
478 glColor4f(r, g, b, aa);
479 model->render(wp, ws, bob, headRot - bodyRot, headRotx, _scale, false);
480 for (int i = 0; i < MAX_ARMOR_LAYERS; i++)
481 {
482 if (prepareArmorOverlay(mob, i, a))
483 {
484 glColor4f(r, g, b, aa);
485 armor->render(wp, ws, bob, headRot - bodyRot, headRotx, _scale, false);
486 }
487 }
488 }
489
490 glDepthFunc(GL_LEQUAL);
491 glDisable(GL_BLEND);
492 glEnable(GL_ALPHA_TEST);
493 glEnable(GL_TEXTURE_2D);
494 }
495 */
496 glDisable(GL_RESCALE_NORMAL);
497
498 glEnable(GL_CULL_FACE);
499
500 glPopMatrix();
501
502 MemSect(31);
503 //renderName(mob, x, y, z);
504 MemSect(0);
505
506 // Reset the model values to stop the changes we made here affecting anything in game (like the player hand render)
507 model->attackTime = 0;
508 model->sneaking = false;
509 model->holdingRightHand = false;
510 model->holdingLeftHand = false;
511}
512
513bool CXuiCtrlMinecraftSkinPreview::bindTexture(const wstring& urlTexture, int backupTexture)
514{
515 Textures *t = Minecraft::GetInstance()->textures;
516
517 // 4J-PB - no http textures on the xbox, mem textures instead
518
519 //int id = t->loadHttpTexture(urlTexture, backupTexture);
520 int id = t->loadMemTexture(urlTexture, backupTexture);
521
522 if (id >= 0)
523 {
524 t->bind(id);
525 return true;
526 }
527 else
528 {
529 return false;
530 }
531}
532
533bool CXuiCtrlMinecraftSkinPreview::bindTexture(const wstring& urlTexture, const wstring& backupTexture)
534{
535 Textures *t = Minecraft::GetInstance()->textures;
536
537 // 4J-PB - no http textures on the xbox, mem textures instead
538
539 //int id = t->loadHttpTexture(urlTexture, backupTexture);
540 int id = t->loadMemTexture(urlTexture, backupTexture);
541
542 if (id >= 0)
543 {
544 t->bind(id);
545 return true;
546 }
547 else
548 {
549 return false;
550 }
551}