the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 162 lines 5.4 kB view raw
1#include "stdafx.h" 2 3#include "..\..\..\Minecraft.World\Container.h" 4#include "..\..\..\Minecraft.World\ContainerMenu.h" 5#include "..\..\MultiplayerLocalPlayer.h" 6#include "XUI_Ctrl_SlotList.h" 7#include "XUI_Scene_Container.h" 8#include "XUI_Ctrl_SlotItemListItem.h" 9#include "XUI_Ctrl_SlotItem.h" 10#include "..\..\Common\Tutorial\Tutorial.h" 11#include "..\..\Common\Tutorial\TutorialMode.h" 12#include "..\..\Common\Tutorial\TutorialEnum.h" 13 14// The height of one row of slots 15//#define ROW_HEIGHT 42.0f - comes from the pointer height in the xui 16 17// The number of container rows that are visible in the Xui file at it's default size 18#define CONTAINER_DEFAULT_ROWS 3 19 20 21//-------------------------------------------------------------------------------------- 22// Name: CXuiSceneContainer::OnInit 23// Desc: Message handler for XM_INIT 24//-------------------------------------------------------------------------------------- 25HRESULT CXuiSceneContainer::OnInit( XUIMessageInit* pInitData, BOOL& bHandled ) 26{ 27 D3DXVECTOR3 vec; 28 MapChildControls(); 29 30 Minecraft *pMinecraft = Minecraft::GetInstance(); 31 32 ContainerScreenInput* initData = (ContainerScreenInput*)pInitData->pvInitData; 33 34 XuiControlSetText(m_ChestText,app.GetString(initData->container->getName())); 35 36 ContainerMenu* menu = new ContainerMenu( initData->inventory, initData->container ); 37 38 shared_ptr<Container> container = initData->container; 39 m_iPad=initData->iPad; 40 m_bSplitscreen=initData->bSplitscreen; 41 42#ifdef _XBOX 43 if( pMinecraft->localgameModes[initData->iPad] != NULL ) 44 { 45 TutorialMode *gameMode = (TutorialMode *)pMinecraft->localgameModes[initData->iPad]; 46 m_previousTutorialState = gameMode->getTutorial()->getCurrentState(); 47 gameMode->getTutorial()->changeTutorialState(e_Tutorial_State_Container_Menu, this); 48 } 49#endif 50 51 // if we are in splitscreen, then we need to figure out if we want to move this scene 52 int rows = container->getContainerSize() / 9; 53 // use the pointer size in the xui to set the row height 54 float fPointerWidth,fPointerHeight; 55 56 if(m_bSplitscreen) 57 { 58 app.AdjustSplitscreenScene(m_hObj,&m_OriginalPosition,m_iPad); 59 } 60 m_pointerControl->GetBounds(&fPointerWidth, &fPointerHeight); 61 62 // Adjust the height to show the correct number of container rows 63 float height, width; 64 this->GetBounds( &width, &height ); 65 int rowDiff = CONTAINER_DEFAULT_ROWS - rows; 66 //height = height - (rowDiff * ROW_HEIGHT); 67 height = height - (rowDiff * fPointerHeight); 68 this->SetBounds( width, height ); 69 70 // Update the position after the height change so that we are still centred 71 D3DXVECTOR3 vPos; 72 this->GetPosition( &vPos ); 73 vPos.y = vPos.y + ( (rowDiff * fPointerHeight) / 2 ); 74 // Make sure that the y offset is even for SD modes, as the y in xui coordinates will end up being scaled by a factor of 1.5 75 // to get it into actual back buffer coordinates, and we need those to remain whole numbers to avoid issues with point sampling 76 if(!RenderManager.IsHiDef()) 77 { 78 int iY = (int)(vPos.y); 79 iY &= 0xfffffffe; 80 vPos.y = (float)iY; 81 } 82 this->SetPosition( &vPos ); 83 84 InitDataAssociations(initData->iPad, menu); 85 86 CXuiSceneAbstractContainer::Initialize( initData->iPad, menu, true, container->getContainerSize(), eSectionContainerUsing, eSectionContainerMax ); 87 88 delete initData; 89 90 return S_OK; 91} 92 93HRESULT CXuiSceneContainer::OnDestroy() 94{ 95 Minecraft *pMinecraft = Minecraft::GetInstance(); 96 97#ifdef _XBOX 98 if( pMinecraft->localgameModes[m_iPad] != NULL ) 99 { 100 TutorialMode *gameMode = (TutorialMode *)pMinecraft->localgameModes[m_iPad]; 101 if(gameMode != NULL) gameMode->getTutorial()->changeTutorialState(m_previousTutorialState); 102 } 103#endif 104 105 // 4J Stu - Fix for #11302 - TCR 001: Network Connectivity: Host crashed after being killed by the client while accessing a chest during burst packet loss. 106 // We need to make sure that we call closeContainer() anytime this menu is closed, even if it is forced to close by some other reason (like the player dying) 107 if(Minecraft::GetInstance()->localplayers[m_iPad] != NULL) Minecraft::GetInstance()->localplayers[m_iPad]->closeContainer(); 108 return S_OK; 109} 110 111CXuiControl* CXuiSceneContainer::GetSectionControl( ESceneSection eSection ) 112{ 113 switch( eSection ) 114 { 115 case eSectionContainerChest: 116 return (CXuiControl *)m_containerControl; 117 break; 118 case eSectionContainerInventory: 119 return (CXuiControl *)m_inventoryControl; 120 break; 121 case eSectionContainerUsing: 122 return (CXuiControl *)m_useRowControl; 123 break; 124 default: 125 assert( false ); 126 break; 127 } 128 return NULL; 129} 130 131CXuiCtrlSlotList* CXuiSceneContainer::GetSectionSlotList( ESceneSection eSection ) 132{ 133 switch( eSection ) 134 { 135 case eSectionContainerChest: 136 return m_containerControl; 137 break; 138 case eSectionContainerInventory: 139 return m_inventoryControl; 140 break; 141 case eSectionContainerUsing: 142 return m_useRowControl; 143 break; 144 default: 145 assert( false ); 146 break; 147 } 148 return NULL; 149} 150 151// 4J Stu - Added to support auto-save. Need to re-associate on a navigate back 152void CXuiSceneContainer::InitDataAssociations(int iPad, AbstractContainerMenu *menu, int startIndex /*= 0*/) 153{ 154 int containerSize = menu->getSize() - (27 + 9); 155 int rows = containerSize / 9; 156 157 // TODO Inventory dimensions need defined as constants 158 m_containerControl->SetData( iPad, menu, rows, 9, 0 ); 159 160 CXuiSceneAbstractContainer::InitDataAssociations(iPad, menu, containerSize); 161} 162