diff options
| author | ModMaker101 <119018978+ModMaker101@users.noreply.github.com> | 2026-03-07 21:56:03 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-03-08 09:56:03 +0700 |
| commit | a9be52c41a02d207233199e98898fe7483d7e817 (patch) | |
| tree | 71dfaec3a86b05e9ca409b97d8eb9d7f993bfdd0 /Minecraft.Client/Common/UI/IUIScene_AbstractContainerMenu.cpp | |
| parent | 1be5faaea781402e7de06b263eeca4c688b7712c (diff) | |
Project modernization (#630)
* Fixed boats falling and a TP glitch #266
* Replaced every C-style cast with C++ ones
* Replaced every C-style cast with C++ ones
* Fixed boats falling and a TP glitch #266
* Updated NULL to nullptr and fixing some type issues
* Modernized and fixed a few bugs
- Replaced most instances of `NULL` with `nullptr`.
- Replaced most `shared_ptr(new ...)` with `make_shared`.
- Removed the `nullptr` macro as it was interfering with the actual nullptr keyword in some instances.
* Fixing more conflicts
* Replace int loops with size_t and start work on overrides
Diffstat (limited to 'Minecraft.Client/Common/UI/IUIScene_AbstractContainerMenu.cpp')
| -rw-r--r-- | Minecraft.Client/Common/UI/IUIScene_AbstractContainerMenu.cpp | 73 |
1 files changed, 37 insertions, 36 deletions
diff --git a/Minecraft.Client/Common/UI/IUIScene_AbstractContainerMenu.cpp b/Minecraft.Client/Common/UI/IUIScene_AbstractContainerMenu.cpp index e55f207d..21f21627 100644 --- a/Minecraft.Client/Common/UI/IUIScene_AbstractContainerMenu.cpp +++ b/Minecraft.Client/Common/UI/IUIScene_AbstractContainerMenu.cpp @@ -2,6 +2,7 @@ #include "IUIScene_AbstractContainerMenu.h" +#include "UI.h" #include "..\..\..\Minecraft.World\net.minecraft.world.inventory.h" #include "..\..\..\Minecraft.World\net.minecraft.world.item.h" #include "..\..\..\Minecraft.World\net.minecraft.world.item.crafting.h" @@ -21,9 +22,9 @@ SavedInventoryCursorPos g_savedInventoryCursorPos = { 0.0f, 0.0f, false }; IUIScene_AbstractContainerMenu::IUIScene_AbstractContainerMenu() { - m_menu = NULL; + m_menu = nullptr; m_autoDeleteMenu = false; - m_lastPointerLabelSlot = NULL; + m_lastPointerLabelSlot = nullptr; m_pointerPos.x = 0.0f; m_pointerPos.y = 0.0f; @@ -41,7 +42,7 @@ IUIScene_AbstractContainerMenu::~IUIScene_AbstractContainerMenu() void IUIScene_AbstractContainerMenu::Initialize(int iPad, AbstractContainerMenu* menu, bool autoDeleteMenu, int startIndex,ESceneSection firstSection,ESceneSection maxSection, bool bNavigateBack) { - assert( menu != NULL ); + assert( menu != nullptr ); m_menu = menu; m_autoDeleteMenu = autoDeleteMenu; @@ -267,10 +268,10 @@ void IUIScene_AbstractContainerMenu::UpdateTooltips() void IUIScene_AbstractContainerMenu::onMouseTick() { Minecraft *pMinecraft = Minecraft::GetInstance(); - if( pMinecraft->localgameModes[getPad()] != NULL) + if( pMinecraft->localgameModes[getPad()] != nullptr) { Tutorial *tutorial = pMinecraft->localgameModes[getPad()]->getTutorial(); - if(tutorial != NULL) + if(tutorial != nullptr) { if(ui.IsTutorialVisible(getPad()) && !tutorial->isInputAllowed(ACTION_MENU_UP)) { @@ -296,8 +297,8 @@ void IUIScene_AbstractContainerMenu::onMouseTick() int iPad = getPad(); bool bStickInput = false; - float fInputX = InputManager.GetJoypadStick_LX( iPad, false )*((float)app.GetGameSettings(iPad,eGameSetting_Sensitivity_InMenu)/100.0f); // apply the sensitivity - float fInputY = InputManager.GetJoypadStick_LY( iPad, false )*((float)app.GetGameSettings(iPad,eGameSetting_Sensitivity_InMenu)/100.0f); // apply the sensitivity + float fInputX = InputManager.GetJoypadStick_LX( iPad, false )*(static_cast<float>(app.GetGameSettings(iPad, eGameSetting_Sensitivity_InMenu))/100.0f); // apply the sensitivity + float fInputY = InputManager.GetJoypadStick_LY( iPad, false )*(static_cast<float>(app.GetGameSettings(iPad, eGameSetting_Sensitivity_InMenu))/100.0f); // apply the sensitivity #ifdef __ORBIS__ // should have sensitivity for the touchpad @@ -406,7 +407,7 @@ void IUIScene_AbstractContainerMenu::onMouseTick() if ( m_iConsectiveInputTicks < MAX_INPUT_TICKS_FOR_SCALING ) { ++m_iConsectiveInputTicks; - fInputScale = ( (float)( m_iConsectiveInputTicks) / (float)(MAX_INPUT_TICKS_FOR_SCALING) ); + fInputScale = ( static_cast<float>(m_iConsectiveInputTicks) / static_cast<float>((MAX_INPUT_TICKS_FOR_SCALING)) ); } #ifdef TAP_DETECTION else if ( m_iConsectiveInputTicks < MAX_INPUT_TICKS_FOR_TAPPING ) @@ -494,11 +495,11 @@ void IUIScene_AbstractContainerMenu::onMouseTick() if (winW > 0 && winH > 0) { - float scaleX = (float)getMovieWidth() / (float)winW; - float scaleY = (float)getMovieHeight() / (float)winH; + float scaleX = static_cast<float>(getMovieWidth()) / static_cast<float>(winW); + float scaleY = static_cast<float>(getMovieHeight()) / static_cast<float>(winH); - vPointerPos.x += (float)deltaX * scaleX; - vPointerPos.y += (float)deltaY * scaleY; + vPointerPos.x += static_cast<float>(deltaX) * scaleX; + vPointerPos.y += static_cast<float>(deltaY) * scaleY; } if (deltaX != 0 || deltaY != 0) @@ -527,7 +528,7 @@ void IUIScene_AbstractContainerMenu::onMouseTick() } else if ( eSectionUnderPointer == eSectionNone ) { - ESceneSection eSection = ( ESceneSection )( iSection ); + ESceneSection eSection = static_cast<ESceneSection>(iSection); // Get position of this section. UIVec2D sectionPos; @@ -758,17 +759,17 @@ void IUIScene_AbstractContainerMenu::onMouseTick() // What are we carrying on pointer. shared_ptr<LocalPlayer> player = Minecraft::GetInstance()->localplayers[getPad()]; shared_ptr<ItemInstance> carriedItem = nullptr; - if(player != NULL) carriedItem = player->inventory->getCarried(); + if(player != nullptr) carriedItem = player->inventory->getCarried(); shared_ptr<ItemInstance> slotItem = nullptr; - Slot *slot = NULL; + Slot *slot = nullptr; int slotIndex = 0; if(bPointerIsOverSlot) { slotIndex = iNewSlotIndex + getSectionStartOffset( eSectionUnderPointer ); slot = m_menu->getSlot(slotIndex); } - bool bIsItemCarried = carriedItem != NULL; + bool bIsItemCarried = carriedItem != nullptr; int iCarriedCount = 0; bool bCarriedIsSameAsSlot = false; // Indicates if same item is carried on pointer as is in slot under pointer. if ( bIsItemCarried ) @@ -788,7 +789,7 @@ void IUIScene_AbstractContainerMenu::onMouseTick() if ( bPointerIsOverSlot ) { slotItem = slot->getItem(); - bSlotHasItem = slotItem != NULL; + bSlotHasItem = slotItem != nullptr; if ( bSlotHasItem ) { iSlotCount = slotItem->GetCount(); @@ -829,13 +830,13 @@ void IUIScene_AbstractContainerMenu::onMouseTick() { vector<HtmlString> *desc = GetSectionHoverText(eSectionUnderPointer); SetPointerText(desc, false); - m_lastPointerLabelSlot = NULL; + m_lastPointerLabelSlot = nullptr; delete desc; } else { - SetPointerText(NULL, false); - m_lastPointerLabelSlot = NULL; + SetPointerText(nullptr, false); + m_lastPointerLabelSlot = nullptr; } EToolTipItem buttonA, buttonX, buttonY, buttonRT, buttonBack; @@ -1021,7 +1022,7 @@ void IUIScene_AbstractContainerMenu::onMouseTick() // Get the info on this item. shared_ptr<ItemInstance> item = getSlotItem(eSectionUnderPointer, iNewSlotIndex); bool bValidFuel = FurnaceTileEntity::isFuel(item); - bool bValidIngredient = FurnaceRecipes::getInstance()->getResult(item->getItem()->id) != NULL; + bool bValidIngredient = FurnaceRecipes::getInstance()->getResult(item->getItem()->id) != nullptr; if(bValidIngredient) { @@ -1036,7 +1037,7 @@ void IUIScene_AbstractContainerMenu::onMouseTick() } else { - if(FurnaceRecipes::getInstance()->getResult(item->id)==NULL) + if(FurnaceRecipes::getInstance()->getResult(item->id)==nullptr) { buttonY = eToolTipQuickMove; } @@ -1076,7 +1077,7 @@ void IUIScene_AbstractContainerMenu::onMouseTick() } else { - if(FurnaceRecipes::getInstance()->getResult(item->id)==NULL) + if(FurnaceRecipes::getInstance()->getResult(item->id)==nullptr) { buttonY = eToolTipQuickMove; } @@ -1309,9 +1310,9 @@ void IUIScene_AbstractContainerMenu::onMouseTick() } vPointerPos.x = floor(vPointerPos.x); - vPointerPos.x += ( (int)vPointerPos.x%2); + vPointerPos.x += ( static_cast<int>(vPointerPos.x)%2); vPointerPos.y = floor(vPointerPos.y); - vPointerPos.y += ( (int)vPointerPos.y%2); + vPointerPos.y += ( static_cast<int>(vPointerPos.y)%2); m_pointerPos = vPointerPos; adjustPointerForSafeZone(); @@ -1322,10 +1323,10 @@ bool IUIScene_AbstractContainerMenu::handleKeyDown(int iPad, int iAction, bool b bool bHandled = false; Minecraft *pMinecraft = Minecraft::GetInstance(); - if( pMinecraft->localgameModes[getPad()] != NULL ) + if( pMinecraft->localgameModes[getPad()] != nullptr ) { Tutorial *tutorial = pMinecraft->localgameModes[getPad()]->getTutorial(); - if(tutorial != NULL) + if(tutorial != nullptr) { tutorial->handleUIInput(iAction); if(ui.IsTutorialVisible(getPad()) && !tutorial->isInputAllowed(iAction)) @@ -1527,20 +1528,20 @@ bool IUIScene_AbstractContainerMenu::handleKeyDown(int iPad, int iAction, bool b if ( bSlotHasItem ) { shared_ptr<ItemInstance> item = getSlotItem(m_eCurrSection, currentIndex); - if( Minecraft::GetInstance()->localgameModes[iPad] != NULL ) + if( Minecraft::GetInstance()->localgameModes[iPad] != nullptr ) { Tutorial::PopupMessageDetails *message = new Tutorial::PopupMessageDetails; message->m_messageId = item->getUseDescriptionId(); - if(Item::items[item->id] != NULL) message->m_titleString = Item::items[item->id]->getHoverName(item); + if(Item::items[item->id] != nullptr) message->m_titleString = Item::items[item->id]->getHoverName(item); message->m_titleId = item->getDescriptionId(); message->m_icon = item->id; message->m_iAuxVal = item->getAuxValue(); message->m_forceDisplay = true; - TutorialMode *gameMode = (TutorialMode *)Minecraft::GetInstance()->localgameModes[iPad]; - gameMode->getTutorial()->setMessage(NULL, message); + TutorialMode *gameMode = static_cast<TutorialMode *>(Minecraft::GetInstance()->localgameModes[iPad]); + gameMode->getTutorial()->setMessage(nullptr, message); ui.PlayUISFX(eSFX_Press); } } @@ -1642,7 +1643,7 @@ void IUIScene_AbstractContainerMenu::handleSlotListClicked(ESceneSection eSectio void IUIScene_AbstractContainerMenu::slotClicked(int slotId, int buttonNum, bool quickKey) { // 4J Stu - Removed this line as unused - //if (slot != NULL) slotId = slot->index; + //if (slot != nullptr) slotId = slot->index; Minecraft *pMinecraft = Minecraft::GetInstance(); pMinecraft->localgameModes[getPad()]->handleInventoryMouseClick(m_menu->containerId, slotId, buttonNum, quickKey, pMinecraft->localplayers[getPad()] ); @@ -1659,7 +1660,7 @@ int IUIScene_AbstractContainerMenu::getCurrentIndex(ESceneSection eSection) bool IUIScene_AbstractContainerMenu::IsSameItemAs(shared_ptr<ItemInstance> itemA, shared_ptr<ItemInstance> itemB) { - if(itemA == NULL || itemB == NULL) return false; + if(itemA == nullptr || itemB == nullptr) return false; return (itemA->id == itemB->id && (!itemB->isStackedByData() || itemB->getAuxValue() == itemA->getAuxValue()) && ItemInstance::tagMatches(itemB, itemA) ); } @@ -1668,7 +1669,7 @@ int IUIScene_AbstractContainerMenu::GetEmptyStackSpace(Slot *slot) { int iResult = 0; - if(slot != NULL && slot->hasItem()) + if(slot != nullptr && slot->hasItem()) { shared_ptr<ItemInstance> item = slot->getItem(); if ( item->isStackable() ) @@ -1687,7 +1688,7 @@ int IUIScene_AbstractContainerMenu::GetEmptyStackSpace(Slot *slot) vector<HtmlString> *IUIScene_AbstractContainerMenu::GetItemDescription(Slot *slot) { - if(slot == NULL) return NULL; + if(slot == nullptr) return nullptr; vector<HtmlString> *lines = slot->getItem()->getHoverText(nullptr, false); @@ -1707,5 +1708,5 @@ vector<HtmlString> *IUIScene_AbstractContainerMenu::GetItemDescription(Slot *slo vector<HtmlString> *IUIScene_AbstractContainerMenu::GetSectionHoverText(ESceneSection eSection) { - return NULL; + return nullptr; } |
