aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.Client/Common/UI/IUIScene_TradingMenu.cpp
diff options
context:
space:
mode:
authorModMaker101 <119018978+ModMaker101@users.noreply.github.com>2026-03-08 19:08:36 -0400
committerGitHub <noreply@github.com>2026-03-08 18:08:36 -0500
commit28614b922fb77149a54da1a87bebfbc98736f296 (patch)
tree7f828ba86a4ee18d0a80d29de64f6199a5412512 /Minecraft.Client/Common/UI/IUIScene_TradingMenu.cpp
parent88798b501d0cf6287b6f87acb2592676e3cec58d (diff)
Modernize project codebase (#906)
* 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 * Add safety checks and fix a issue with vector going OOR
Diffstat (limited to 'Minecraft.Client/Common/UI/IUIScene_TradingMenu.cpp')
-rw-r--r--Minecraft.Client/Common/UI/IUIScene_TradingMenu.cpp38
1 files changed, 20 insertions, 18 deletions
diff --git a/Minecraft.Client/Common/UI/IUIScene_TradingMenu.cpp b/Minecraft.Client/Common/UI/IUIScene_TradingMenu.cpp
index 059f9b75..0b1e0df2 100644
--- a/Minecraft.Client/Common/UI/IUIScene_TradingMenu.cpp
+++ b/Minecraft.Client/Common/UI/IUIScene_TradingMenu.cpp
@@ -8,12 +8,14 @@
#include "..\..\ClientConnection.h"
#include "IUIScene_TradingMenu.h"
+#include "UI.h"
+
IUIScene_TradingMenu::IUIScene_TradingMenu()
{
m_validOffersCount = 0;
m_selectedSlot = 0;
m_offersStartIndex = 0;
- m_menu = NULL;
+ m_menu = nullptr;
m_bHasUpdatedOnce = false;
}
@@ -31,10 +33,10 @@ bool IUIScene_TradingMenu::handleKeyDown(int iPad, int iAction, bool bRepeat)
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))
@@ -76,7 +78,7 @@ bool IUIScene_TradingMenu::handleKeyDown(int iPad, int iAction, bool bRepeat)
shared_ptr<MultiplayerLocalPlayer> player = Minecraft::GetInstance()->localplayers[getPad()];
int buyAMatches = player->inventory->countMatches(buyAItem);
int buyBMatches = player->inventory->countMatches(buyBItem);
- if( (buyAItem != NULL && buyAMatches >= buyAItem->count) && (buyBItem == NULL || buyBMatches >= buyBItem->count) )
+ if( (buyAItem != nullptr && buyAMatches >= buyAItem->count) && (buyBItem == nullptr || buyBMatches >= buyBItem->count) )
{
// 4J-JEV: Fix for PS4 #7111: [PATCH 1.12] Trading Librarian villagers for multiple �Enchanted Books� will cause the title to crash.
int actualShopItem = m_activeOffers.at(selectedShopItem).second;
@@ -95,7 +97,7 @@ bool IUIScene_TradingMenu::handleKeyDown(int iPad, int iAction, bool bRepeat)
}
// Send a packet to the server
- player->connection->send( shared_ptr<TradeItemPacket>( new TradeItemPacket(m_menu->containerId, actualShopItem) ) );
+ player->connection->send(std::make_shared<TradeItemPacket>(m_menu->containerId, actualShopItem));
updateDisplay();
}
@@ -152,7 +154,7 @@ bool IUIScene_TradingMenu::handleKeyDown(int iPad, int iAction, bool bRepeat)
ByteArrayOutputStream rawOutput;
DataOutputStream output(&rawOutput);
output.writeInt(actualShopItem);
- Minecraft::GetInstance()->getConnection(getPad())->send(shared_ptr<CustomPayloadPacket>( new CustomPayloadPacket(CustomPayloadPacket::TRADER_SELECTION_PACKET, rawOutput.toByteArray())));
+ Minecraft::GetInstance()->getConnection(getPad())->send(std::make_shared<CustomPayloadPacket>(CustomPayloadPacket::TRADER_SELECTION_PACKET, rawOutput.toByteArray()));
}
}
return handled;
@@ -162,7 +164,7 @@ void IUIScene_TradingMenu::handleTick()
{
int offerCount = 0;
MerchantRecipeList *offers = m_merchant->getOffers(Minecraft::GetInstance()->localplayers[getPad()]);
- if (offers != NULL)
+ if (offers != nullptr)
{
offerCount = offers->size();
@@ -181,7 +183,7 @@ void IUIScene_TradingMenu::updateDisplay()
int iA = -1;
MerchantRecipeList *unfilteredOffers = m_merchant->getOffers(Minecraft::GetInstance()->localplayers[getPad()]);
- if (unfilteredOffers != NULL)
+ if (unfilteredOffers != nullptr)
{
m_activeOffers.clear();
int unfilteredIndex = 0;
@@ -205,7 +207,7 @@ void IUIScene_TradingMenu::updateDisplay()
ByteArrayOutputStream rawOutput;
DataOutputStream output(&rawOutput);
output.writeInt(firstValidTrade);
- Minecraft::GetInstance()->getConnection(getPad())->send(shared_ptr<CustomPayloadPacket>( new CustomPayloadPacket(CustomPayloadPacket::TRADER_SELECTION_PACKET, rawOutput.toByteArray())));
+ Minecraft::GetInstance()->getConnection(getPad())->send(std::make_shared<CustomPayloadPacket>(CustomPayloadPacket::TRADER_SELECTION_PACKET, rawOutput.toByteArray()));
}
}
@@ -241,7 +243,7 @@ void IUIScene_TradingMenu::updateDisplay()
// 4J-PB - need to get the villager type here
wsTemp = app.GetString(IDS_VILLAGER_OFFERS_ITEM);
wsTemp = replaceAll(wsTemp,L"{*VILLAGER_TYPE*}",m_merchant->getDisplayName());
- int iPos=wsTemp.find(L"%s");
+ size_t iPos=wsTemp.find(L"%s");
wsTemp.replace(iPos,2,activeRecipe->getSellItem()->getHoverName());
setTitle(wsTemp.c_str());
@@ -255,10 +257,10 @@ void IUIScene_TradingMenu::updateDisplay()
setRequest1Item(buyAItem);
setRequest2Item(buyBItem);
- if(buyAItem != NULL) setRequest1Name(buyAItem->getHoverName());
+ if(buyAItem != nullptr) setRequest1Name(buyAItem->getHoverName());
else setRequest1Name(L"");
- if(buyBItem != NULL) setRequest2Name(buyBItem->getHoverName());
+ if(buyBItem != nullptr) setRequest2Name(buyBItem->getHoverName());
else setRequest2Name(L"");
bool canMake = true;
@@ -284,15 +286,15 @@ void IUIScene_TradingMenu::updateDisplay()
}
else
{
- if(buyBItem!=NULL)
+ if(buyBItem!=nullptr)
{
setRequest2RedBox(true);
canMake = false;
}
else
{
- setRequest2RedBox(buyBItem != NULL);
- canMake = canMake && buyBItem == NULL;
+ setRequest2RedBox(buyBItem != nullptr);
+ canMake = canMake && buyBItem == nullptr;
}
}
@@ -320,7 +322,7 @@ void IUIScene_TradingMenu::updateDisplay()
bool IUIScene_TradingMenu::canMake(MerchantRecipe *recipe)
{
bool canMake = false;
- if (recipe != NULL)
+ if (recipe != nullptr)
{
if(recipe->isDeprecated()) return false;
@@ -335,7 +337,7 @@ bool IUIScene_TradingMenu::canMake(MerchantRecipe *recipe)
}
else
{
- canMake = buyAItem == NULL;
+ canMake = buyAItem == nullptr;
}
int buyBMatches = player->inventory->countMatches(buyBItem);
@@ -345,7 +347,7 @@ bool IUIScene_TradingMenu::canMake(MerchantRecipe *recipe)
}
else
{
- canMake = canMake && buyBItem == NULL;
+ canMake = canMake && buyBItem == nullptr;
}
}
return canMake;