the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 356 lines 11 kB view raw
1#include "stdafx.h" 2 3#include "..\..\ItemRenderer.h" 4#include "..\..\GameRenderer.h" 5#include "..\..\TileRenderer.h" 6#include "..\..\Lighting.h" 7#include "..\..\ScreenSizeCalculator.h" 8#include "..\..\LocalPlayer.h" 9#include "..\..\..\Minecraft.World\ItemInstance.h" 10#include "..\..\..\Minecraft.World\Item.h" 11#include "..\..\..\Minecraft.World\Tile.h" 12#include "XUI_Ctrl_MinecraftSlot.h" 13 14//----------------------------------------------------------------------------- 15// CXuiCtrlMinecraftSlot class 16//----------------------------------------------------------------------------- 17 18// The xzp path icons for the leaderboard 19 20LPCWSTR CXuiCtrlMinecraftSlot::xzpIcons[15]= 21{ 22 L"Graphics\\Leaderboard\\LeaderBoard_Icon_Skeleton.png", 23 L"Graphics\\Leaderboard\\LeaderBoard_Icon_Creeper.png", 24 L"Graphics\\Leaderboard\\LeaderBoard_Icon_SpiderJockey.png", 25 L"Graphics\\Leaderboard\\LeaderBoard_Icon_Spider.png", 26 L"Graphics\\Leaderboard\\LeaderBoard_Icon_Zombie.png", 27 L"Graphics\\Leaderboard\\LeaderBoard_Icon_ZombiePigman.png", 28 L"Graphics\\Leaderboard\\LeaderBoard_Icon_Swam.png", 29 L"Graphics\\Leaderboard\\LeaderBoard_Icon_Walked.png", 30 L"Graphics\\Leaderboard\\LeaderBoard_Icon_Fallen.png", 31 L"Graphics\\Leaderboard\\LeaderBoard_Icon_Portal.png", 32 L"Graphics\\Leaderboard\\LeaderBoard_Icon_Climbed.png", 33 L"Graphics\\Leaderboard\\LeaderBoard_Icon_Ghast.png", 34 L"Graphics\\Leaderboard\\LeaderBoard_Icon_Slime.png", 35 L"Graphics\\CraftIcons\\icon_structures.png", 36 L"Graphics\\CraftIcons\\icon_tools.png", 37}; 38 39 40 41//----------------------------------------------------------------------------- 42CXuiCtrlMinecraftSlot::CXuiCtrlMinecraftSlot() : 43 //m_hBrush(NULL), 44 m_bDirty(FALSE), 45 m_iPassThroughDataAssociation(0), 46 m_iPassThroughIdAssociation(0), 47 m_fScale(1.0f), 48 m_fAlpha(1.0f), 49 m_iID(0), 50 m_iCount(0), 51 m_iAuxVal(0), 52 m_bDecorations(false), 53 m_isFoil(false), 54 m_popTime(0) 55{ 56 m_pItemRenderer = new ItemRenderer(); 57 m_item = nullptr; 58 59 m_bScreenWidthSetup = false; 60 61 Minecraft *pMinecraft=Minecraft::GetInstance(); 62 63 if(pMinecraft != NULL) 64 { 65 m_fScreenWidth=(float)pMinecraft->width_phys; 66 m_fScreenHeight=(float)pMinecraft->height_phys; 67 m_bScreenWidthSetup = true; 68 } 69} 70 71CXuiCtrlMinecraftSlot::~CXuiCtrlMinecraftSlot() 72{ 73 delete m_pItemRenderer; 74} 75 76VOID CXuiCtrlMinecraftSlot::SetPassThroughDataAssociation(unsigned int iID, unsigned int iData) 77{ 78 m_item = nullptr; 79 m_iPassThroughIdAssociation = iID; 80 m_iPassThroughDataAssociation = iData; 81} 82 83//----------------------------------------------------------------------------- 84HRESULT CXuiCtrlMinecraftSlot::OnGetSourceImage(XUIMessageGetSourceImage* pData, BOOL& rfHandled) 85{ 86 XUIMessage Message; 87 CustomMessage_GetSlotItem_Struct MsgGetSlotItem; 88 HRESULT hr; 89 HXUIOBJ hObj; 90 91 CustomMessage_GetSlotItem(&Message, &MsgGetSlotItem, m_iPassThroughIdAssociation, m_iPassThroughDataAssociation); 92 93 hr = GetParent(&hObj); 94 95 if (HRESULT_SUCCEEDED(hr)) 96 { 97 hr = XuiBubbleMessage(hObj, &Message); 98 99 if(hr == XUI_ERR_SOURCEDATA_ITEM) 100 { 101 // Go up the parent chain one more 102 HXUIOBJ hParent; 103 hr = XuiElementGetParent(hObj,&hParent); 104 hr = XuiBubbleMessage(hParent, &Message); 105 } 106 107 if (Message.bHandled) 108 { 109 pData->szPath = MsgGetSlotItem.szPath; 110 pData->bDirty = MsgGetSlotItem.bDirty; 111 112 if(MsgGetSlotItem.item != NULL) 113 { 114 m_item = MsgGetSlotItem.item; 115 m_iID = m_item->id; 116 m_iPad = GET_SLOTDISPLAY_USERINDEX_FROM_DATA_BITMASK(MsgGetSlotItem.iDataBitField); 117 m_fAlpha = ((float)GET_SLOTDISPLAY_ALPHA_FROM_DATA_BITMASK(MsgGetSlotItem.iDataBitField))/31.0f; 118 m_bDecorations = GET_SLOTDISPLAY_DECORATIONS_FROM_DATA_BITMASK(MsgGetSlotItem.iDataBitField); 119 m_fScale = ((float)GET_SLOTDISPLAY_SCALE_FROM_DATA_BITMASK(MsgGetSlotItem.iDataBitField))/10.0f; 120 } 121 else 122 { 123 m_iID = GET_SLOTDISPLAY_ID_FROM_ITEM_BITMASK(MsgGetSlotItem.iItemBitField); 124 125 // if the id is greater than or equal to 32000, then it's an xzp icon, not a game icon 126 if(m_iID<32000) 127 { 128 // 4J Stu - Some parent controls may overide this, others will leave it as what we passed in 129 130 m_iPad = GET_SLOTDISPLAY_USERINDEX_FROM_DATA_BITMASK(MsgGetSlotItem.iDataBitField); 131 m_fAlpha = ((float)GET_SLOTDISPLAY_ALPHA_FROM_DATA_BITMASK(MsgGetSlotItem.iDataBitField))/31.0f; 132 m_bDecorations = GET_SLOTDISPLAY_DECORATIONS_FROM_DATA_BITMASK(MsgGetSlotItem.iDataBitField); 133 m_iCount = GET_SLOTDISPLAY_COUNT_FROM_DATA_BITMASK(MsgGetSlotItem.iDataBitField); 134 m_fScale = ((float)GET_SLOTDISPLAY_SCALE_FROM_DATA_BITMASK(MsgGetSlotItem.iDataBitField))/10.0f; 135 m_popTime = GET_SLOTDISPLAY_POPTIME_FROM_DATA_BITMASK(MsgGetSlotItem.iDataBitField); 136 137 m_iAuxVal = GET_SLOTDISPLAY_AUXVAL_FROM_ITEM_BITMASK(MsgGetSlotItem.iItemBitField); 138 139 //m_iID = iID; 140 141 m_isFoil = GET_SLOTDISPLAY_FOIL_FROM_ITEM_BITMASK(MsgGetSlotItem.iItemBitField); 142 } 143 else 144 { 145 pData->szPath = xzpIcons[m_iID-32000]; 146 } 147 148 if(m_item != NULL && (m_item->id != m_iID || m_item->getAuxValue() != m_iAuxVal || m_item->GetCount() != m_iCount) ) m_item = nullptr; 149 } 150 151 152 rfHandled = TRUE; 153 return hr; 154 } 155 else 156 { 157 pData->szPath = L""; 158 } 159 } 160 161 pData->bDirty = m_bDirty; 162 m_bDirty = FALSE; 163 rfHandled = TRUE; 164 return S_OK; 165} 166 167//----------------------------------------------------------------------------- 168HRESULT CXuiCtrlMinecraftSlot::OnInit(XUIMessageInit* pInitData, BOOL& rfHandled) 169{ 170 //DWORD dwPropId; 171 HRESULT hr=S_OK; 172 return hr; 173} 174 175//----------------------------------------------------------------------------- 176 177HRESULT CXuiCtrlMinecraftSlot::OnRender(XUIMessageRender *pRenderData, BOOL &bHandled ) 178{ 179 // Force an update of the id 180 XUIMessage Message; 181 XUIMessageGetSourceImage MsgGetImage; 182 HRESULT hr; 183 XuiMessageGetSourceImage(&Message, &MsgGetImage, m_iPassThroughIdAssociation, m_iPassThroughDataAssociation, FALSE); 184 hr = XuiSendMessage(m_hObj, &Message); 185 186 // We cannot have an Item with id 0 187 if(m_item != NULL || (m_iID > 0 && m_iID<32000) ) 188 { 189 HXUIDC hDC = pRenderData->hDC; 190 CXuiControl xuiControl(m_hObj); 191 if(m_item == NULL) m_item = shared_ptr<ItemInstance>( new ItemInstance(m_iID, m_iCount, m_iAuxVal) ); 192 193 // build and render with the game call 194 195 RenderManager.Set_matrixDirty(); 196 197 Minecraft *pMinecraft=Minecraft::GetInstance(); 198 199 D3DXMATRIX matrix; 200 xuiControl.GetFullXForm(&matrix); 201 float bwidth,bheight; 202 xuiControl.GetBounds(&bwidth,&bheight); 203 204 float x = matrix._41; 205 float y = matrix._42; 206 207 // Base scale on height of this control, compared to height of what the item renderer normally renders (16 pixels high). Potentially 208 // we might want separate x & y scales here 209 210 float scaleX = bwidth / 16.0f; 211 float scaleY = bheight / 16.0f; 212 213 // apply any scale in the matrix too 214 scaleX *= matrix._11; 215 scaleY *= matrix._22; 216 217 // Annoyingly, XUI renders everything to a z of 0 so if we want to render anything that needs the z-buffer on top of it, then we need to clear it. 218 // Clear just the region required for this control. 219 D3DRECT clearRect; 220 clearRect.x1 = (int)(matrix._41) - 2; 221 clearRect.y1 = (int)(matrix._42) - 2; 222 clearRect.x2 = (int)(matrix._41 + ( bwidth * matrix._11 )) + 2; 223 clearRect.y2 = (int)(matrix._42 + ( bheight * matrix._22 )) + 2; 224 225 if(!m_bScreenWidthSetup) 226 { 227 Minecraft *pMinecraft=Minecraft::GetInstance(); 228 if(pMinecraft != NULL) 229 { 230 m_fScreenWidth=(float)pMinecraft->width_phys; 231 m_fScreenHeight=(float)pMinecraft->height_phys; 232 m_bScreenWidthSetup = true; 233 } 234 } 235 236 RenderManager.Clear(GL_DEPTH_BUFFER_BIT, &clearRect); 237 // glClear(GL_DEPTH_BUFFER_BIT); 238 glMatrixMode(GL_PROJECTION); 239 glLoadIdentity(); 240 glOrtho(0, m_fScreenWidth, m_fScreenHeight, 0, 1000, 3000); 241 glMatrixMode(GL_MODELVIEW); 242 glLoadIdentity(); 243 glTranslatef(0, 0, -2000); 244 245 246 glEnable(GL_RESCALE_NORMAL); 247 glPushMatrix(); 248 glRotatef(120, 1, 0, 0); 249 Lighting::turnOn(); 250 glPopMatrix(); 251 252 253 254 //Make sure that pMinecraft->player is the correct player so that player specific rendering 255 // eg clock and compass, are rendered correctly 256 shared_ptr<MultiplayerLocalPlayer> oldPlayer = pMinecraft->player; 257 258 if( m_iPad >= 0 && m_iPad < XUSER_MAX_COUNT ) pMinecraft->player = pMinecraft->localplayers[m_iPad]; 259 260 float pop = m_popTime; 261 if (pop > 0) 262 { 263 glPushMatrix(); 264 float squeeze = 1 + pop / (float) Inventory::POP_TIME_DURATION; 265 float sx = x; 266 float sy = y; 267 float sxoffs = 8 * scaleX; 268 float syoffs = 12 * scaleY; 269 glTranslatef((float)(sx + sxoffs), (float)(sy + syoffs), 0); 270 glScalef(1 / squeeze, (squeeze + 1) / 2, 1); 271 glTranslatef((float)-(sx + sxoffs), (float)-(sy + syoffs), 0); 272 } 273 274 m_pItemRenderer->renderAndDecorateItem(pMinecraft->font, pMinecraft->textures, m_item, x, y,scaleX,scaleY,m_fAlpha,m_isFoil,false); 275 276 if (pop > 0) 277 { 278 glPopMatrix(); 279 } 280 281 if(m_bDecorations) 282 { 283 if((scaleX!=1.0f) ||(scaleY!=1.0f)) 284 { 285 glPushMatrix(); 286 glScalef(scaleX, scaleY, 1.0f); 287 int iX= (int)(0.5f+((float)x)/scaleX); 288 int iY= (int)(0.5f+((float)y)/scaleY); 289 290 m_pItemRenderer->renderGuiItemDecorations(pMinecraft->font, pMinecraft->textures, m_item, iX, iY, m_fAlpha); 291 glPopMatrix(); 292 } 293 else 294 { 295 m_pItemRenderer->renderGuiItemDecorations(pMinecraft->font, pMinecraft->textures, m_item, (int)x, (int)y, m_fAlpha); 296 } 297 } 298 299 pMinecraft->player = oldPlayer; 300 301 Lighting::turnOff(); 302 glDisable(GL_RESCALE_NORMAL); 303 304 XuiRenderRestoreState(hDC); 305 306 bHandled = TRUE; 307 } 308 return S_OK; 309} 310 311 312void CXuiCtrlMinecraftSlot::SetIcon(int iPad, int iId,int iAuxVal, int iCount, int iScale, unsigned int uiAlpha,bool bDecorations,BOOL bShow, bool isFoil) 313{ 314 m_item = nullptr; 315 m_iID=iId; 316 m_iAuxVal=iAuxVal; 317 318 // aux value for diggers can go as high as 1561 319 //const _Tier *_Tier::DIAMOND = new _Tier(3, 1561, 8, 3); // 320 // setMaxDamage(tier->getUses()); 321 322 // int ItemInstance::getDamageValue() 323 // { 324 // return auxValue; 325 // } 326 327 328 if( (m_iAuxVal & 0xFF) == 0xFF) // 4J Stu - If the aux value is set to match any 329 m_iAuxVal = 0; 330 331 m_iCount=iCount; 332 m_fScale = (float)(iScale)/10.0f; 333 //m_uiAlpha=uiAlpha; 334 m_fAlpha =((float)(uiAlpha)) / 255.0f; 335 m_bDecorations = bDecorations; 336 // mif(bDecorations) m_iDecorations=1; 337 // else m_iDecorations=0; 338 339 m_iPad = iPad; 340 341 m_isFoil = isFoil; 342 343 XuiElementSetShow(m_hObj,bShow); 344} 345 346void CXuiCtrlMinecraftSlot::SetIcon(int iPad, shared_ptr<ItemInstance> item, int iScale, unsigned int uiAlpha,bool bDecorations, BOOL bShow) 347{ 348 m_item = item; 349 m_isFoil = item->isFoil(); 350 m_iPad = iPad; 351 m_fScale = (float)(iScale)/10.0f; 352 m_fAlpha =((float)(uiAlpha)) / 31; 353 m_bDecorations = bDecorations; 354 m_bDirty = TRUE; 355 XuiElementSetShow(m_hObj,bShow); 356}