the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 231 lines 5.2 kB view raw
1#include "stdafx.h" 2 3#include "..\..\..\Minecraft.World\AbstractContainerMenu.h" 4 5#include "XUI_Ctrl_SlotItemListItem.h" 6#include "XUI_Ctrl_SlotList.h" 7 8 9//-------------------------------------------------------------------------------------- 10// Name: CXuiCtrlSlotList::OnInit 11// Desc: Message handler for XM_INIT 12//-------------------------------------------------------------------------------------- 13HRESULT CXuiCtrlSlotList::OnInit( XUIMessageInit* pInitData, BOOL& bHandled ) 14{ 15 slotCount = 0; 16 17 return S_OK; 18} 19 20HRESULT CXuiCtrlSlotList::OnDestroy() 21{ 22 return S_OK; 23} 24 25HRESULT CXuiCtrlSlotList::OnKeyDown(XUIMessageInput *pInputData, BOOL& bHandled) 26{ 27 if( pInputData->dwKeyCode == VK_PAD_DPAD_LEFT || 28 pInputData->dwKeyCode == VK_PAD_DPAD_RIGHT || 29 pInputData->dwKeyCode == VK_PAD_DPAD_UP || 30 pInputData->dwKeyCode == VK_PAD_DPAD_DOWN || 31 pInputData->dwKeyCode == VK_PAD_LTRIGGER || 32 pInputData->dwKeyCode == VK_PAD_RTRIGGER) 33 { 34 HXUIOBJ parent; 35 HRESULT hr; 36 hr = XuiElementGetParent( m_hObj, &parent ); 37 38 XUIMessage message; 39 XUIMessageInput messageInput; 40 41 XuiMessageInput( &message, &messageInput, XUI_KEYDOWN, pInputData->dwKeyCode, pInputData->wch, pInputData->dwFlags, pInputData->UserIndex ); 42 43 if (HRESULT_SUCCEEDED(hr)) 44 { 45 hr = XuiBubbleMessage(parent, &message); 46 47 if (message.bHandled) 48 { 49 bHandled = TRUE; 50 } 51 } 52 } 53 54 return S_OK; 55} 56 57void CXuiCtrlSlotList::SetData(int m_iPad, AbstractContainerMenu* menu, int rows, int columns, int startIndex /*= 0*/, int endIndex /*= 0*/) 58{ 59 assert( startIndex >= 0 && startIndex < menu->getSize() ); 60 assert( endIndex <= menu->getSize() ); 61 62 if( startIndex < 0 ) 63 { 64 startIndex = 0; 65 } 66 else if( startIndex > menu->getSize() ) 67 { 68 startIndex = menu->getSize(); 69 } 70 71 if( endIndex == 0 ) 72 { 73 endIndex = startIndex + (rows * columns); 74 } 75 76 if( endIndex > menu->getSize() ) 77 { 78 endIndex = menu->getSize(); 79 } 80 81 if( startIndex > endIndex ) 82 { 83 endIndex = startIndex; 84 } 85 86 assert( (rows * columns) == (endIndex - startIndex) ); 87 88 this->rows = rows; 89 this->columns = columns; 90 91 this->startIndex = startIndex; 92 93 this->slotCount = rows * columns; 94 95 InsertItems( 0, slotCount ); 96 97 for(int i = 0; i < slotCount; i++) 98 { 99 CXuiCtrlSlotItemListItem* slotControl; 100 GetCXuiCtrlSlotItem(i, &slotControl); 101 102 slotControl->SetSlot( slotControl->m_hObj, menu->getSlot( i + startIndex ) ); 103 104 slotControl->SetUserIndex( slotControl->m_hObj, m_iPad ); 105 106 slotControl = NULL; 107 } 108} 109 110HRESULT CXuiCtrlSlotList::OnGetItemCountAll( XUIMessageGetItemCount *pGetItemCountData, BOOL& bHandled ) 111{ 112 // We don't need to look at the type of request. The message map 113 // has already filtered out a request to retrieve all items. 114 pGetItemCountData->cItems = slotCount; 115 bHandled = TRUE; 116 117 return( S_OK ); 118} 119 120HRESULT CXuiCtrlSlotList::OnGetItemCountMaxLines( XUIMessageGetItemCount *pGetItemCountData, BOOL& bHandled ) 121{ 122 // We don't need to look at the type of request. The message map 123 // has already filtered out a request to retrieve max lines. 124 pGetItemCountData->cItems = rows; 125 bHandled = TRUE; 126 127 return( S_OK ); 128} 129 130HRESULT CXuiCtrlSlotList::OnGetItemCountMaxPerLine( XUIMessageGetItemCount *pGetItemCountData, BOOL& bHandled ) 131{ 132 // We don't need to look at the type of request. The message map 133 // has already filtered out a request to retrieve max per line. 134 pGetItemCountData->cItems = columns; 135 bHandled = TRUE; 136 137 return( S_OK ); 138} 139 140int CXuiCtrlSlotList::GetCurrentColumn() 141{ 142 int currentItemIndex = GetCurSel(); 143 144 return currentItemIndex % columns; 145} 146 147int CXuiCtrlSlotList::GetCurrentRow() 148{ 149 int currentItemIndex = GetCurSel(); 150 151 return (currentItemIndex/columns) % rows; 152} 153 154// Return the index in the menu object 155int CXuiCtrlSlotList::GetCurrentIndex() 156{ 157 int currentSelected = GetCurSel(); 158 return currentSelected + this->startIndex; 159} 160 161void CXuiCtrlSlotList::SetCurrentSlot(int row, int column) 162{ 163 if( row >= rows ) 164 { 165 row = rows - 1; 166 } 167 else if ( row < 0 ) 168 { 169 row = 0; 170 } 171 if( column >= columns ) 172 { 173 column = columns - 1; 174 } 175 else if ( column < 0 ) 176 { 177 column = 0; 178 } 179 int newSlot = ( row * columns ) + column; 180 SetCurSel( newSlot ); 181} 182 183void CXuiCtrlSlotList::SetEntrySlot(int row, int column, XUI_CONTROL_NAVIGATE direction) 184{ 185 // The direction is the direction in which we are leaving the previous control to get to here 186 // So a Navigate up means we want to start at the bottom of ourself 187 switch( direction ) 188 { 189 case XUI_CONTROL_NAVIGATE_UP: 190 { 191 row = rows - 1; 192 break; 193 } 194 case XUI_CONTROL_NAVIGATE_DOWN: 195 { 196 row = 0; 197 break; 198 } 199 case XUI_CONTROL_NAVIGATE_LEFT: 200 case XUI_CONTROL_NAVIGATE_TABBACKWARD: 201 { 202 column = columns - 1; 203 break; 204 } 205 case XUI_CONTROL_NAVIGATE_RIGHT: 206 case XUI_CONTROL_NAVIGATE_TABFORWARD: 207 { 208 column = 0; 209 break; 210 } 211 } 212 SetCurrentSlot( row, column ); 213} 214 215void CXuiCtrlSlotList::Clicked() 216{ 217 CXuiCtrlSlotItemListItem* slot; 218 GetCXuiCtrlSlotItem( GetCurSel() , &slot); 219 220 // To get the press animation 221 slot->Press(); 222} 223 224void CXuiCtrlSlotList::GetCXuiCtrlSlotItem(int itemIndex, CXuiCtrlSlotItemListItem** CXuiCtrlSlotItem) 225{ 226 HXUIOBJ itemControl = this->GetItemControl(itemIndex); 227 VOID *pObj; 228 XuiObjectFromHandle( itemControl, &pObj ); 229 *CXuiCtrlSlotItem = (CXuiCtrlSlotItemListItem *)pObj; 230} 231