Files
neoLegacy/Minecraft.Client/Common/UI/IUIScene_CraftingMenu.cpp
T
Tranqlmao 9abd52985e TU53 + Bug Fixes (Many)
Patch Notes:
Blocks
+ Colored shulker boxes
+ Concrete powder
+ Concrete
+ Glazed terracotta
Items
+ Shulker shell
+ Iron nugget
UI Changes
+ Added Custom Controls to Keyboard & Mouse, as well as Controller
+ Added Custom SuperFlat
+ Added Edit Server Menu
+ Added Firework Crafting
Feature Changes
+ Host Options
+ Added Pick Block
+ Added off-hand slot for maps and arrows.
Bug Fixes & changes
+ TU47: Banner hitbox wrong (and inventory model fixed)
+ TU47/48: Ice not melting properly
+ TU48: Dead bushes not dropping sticks
+ TU48: Guardians and polar bears not dropping cooked fish when on fire
+ TU48: Bonus chest missing saplings and seeds
+ TU48: Frosted ice obtainable
+ TU48: Hoppers not collecting items
+ TU48: Wither skeletons spawning in 2-high gaps
+ TU48: End crystals exploding with “TNT Explodes” off
+ TU48: Tamed ocelots staying hostile
+ TU48: Signs not placing on tall grass
+ TU51: Skeleton hitbox wrong
+ TU53: Fall damage in shallow water
+ TU53: Squids not spawning in man-made pools
+ Elytra has been improved to be more accurate to the source material
+ Removed Spectral Arrow from crafting
+ Fixed several broken item descriptions
+ You can no longer cook Pufferfish or Clownfish
+ Fixed scaling issue with paperdoll and chat
+ Iron and gold armor can now be smelted into nuggets.
+ More items can now be used as fuel in a furnace.
+ Using a firework rocket while gliding with elytra will now give the player a boost.
+ Changed the color of dyes, wool, carpets, and banners.
+ Reordered all colored blocks and items in the Creative inventory. Banners now have the same order of colors as all other colored blocks and items.
+ Fishing rods can now hook on entities without causing knockback or pseudo-damage.
+ Fixed banner crafting
+ Fixed Map colors for certain blocks
+ Fixed Path block height
+ Fixed String block issues
+ Fixed Item frame culling.
+ Fixed Tutorial world NBT/Block State issues
+ Fixed World Slider
+ Fixed Enderman AI
+ Fixed Player animation bug
+ HUD Flash text changes
+ Generation accuracy changes
+ Many other small accuracy changes and fixes
2026-11-24 13:44:06 -05:00

1077 lines
29 KiB
C++

#include "stdafx.h"
#include "../../../Minecraft.World/net.minecraft.world.item.crafting.h"
#include "../../../Minecraft.World/net.minecraft.world.level.tile.h"
#include "../../../Minecraft.World/net.minecraft.stats.h"
#include "../../LocalPlayer.h"
#include "IUIScene_CraftingMenu.h"
#include "UI.h"
Recipy::_eGroupType IUIScene_CraftingMenu::m_GroupTypeMapping4GridA[IUIScene_CraftingMenu::m_iMaxGroupH2x2]=
{
Recipy::eGroupType_Structure,
Recipy::eGroupType_Tool,
Recipy::eGroupType_Food,
Recipy::eGroupType_Mechanism,
Recipy::eGroupType_Transport,
Recipy::eGroupType_Decoration,
};
Recipy::_eGroupType IUIScene_CraftingMenu::m_GroupTypeMapping9GridA[IUIScene_CraftingMenu::m_iMaxGroupH3x3]=
{
Recipy::eGroupType_Structure,
Recipy::eGroupType_Tool,
Recipy::eGroupType_Food,
Recipy::eGroupType_Armour,
Recipy::eGroupType_Mechanism,
Recipy::eGroupType_Transport,
Recipy::eGroupType_Decoration,
};
LPCWSTR IUIScene_CraftingMenu::m_GroupIconNameA[m_iMaxGroupH3x3]=
{
L"Structures",
L"Tools",
L"Food",
L"Armour",
L"Mechanisms",
L"Transport",
L"Decoration",
};
IUIScene_CraftingMenu::_eGroupTab IUIScene_CraftingMenu::m_GroupTabBkgMapping2x2A[m_iMaxGroupH2x2]=
{
eGroupTab_Left,
eGroupTab_Middle,
eGroupTab_Middle,
eGroupTab_Middle,
eGroupTab_Middle,
eGroupTab_Right,
};
IUIScene_CraftingMenu::_eGroupTab IUIScene_CraftingMenu::m_GroupTabBkgMapping3x3A[m_iMaxGroupH3x3]=
{
eGroupTab_Left,
eGroupTab_Middle,
eGroupTab_Middle,
eGroupTab_Middle,
eGroupTab_Middle,
eGroupTab_Middle,
eGroupTab_Right,
};
IUIScene_CraftingMenu::IUIScene_CraftingMenu()
{
m_iCurrentSlotHIndex=0;
m_iCurrentSlotVIndex=1;
memset(CanBeMadeA,0,sizeof(CANBEMADE)*m_iMaxHSlotC);
m_iRecipeC=0;
m_iGroupHIndex = 0;
m_iGroupVIndex = 0;
m_pGroupA = nullptr;
for(int i=0;i<m_iMaxDisplayedVSlotC;i++)
{
iVSlotIndexA[i]=i;
}
for (int i = 0; i < 7; i++)
{
iHSlotState[i] = 1;
}
m_iDisplayDescription=DISPLAY_INVENTORY;
m_iIngredientsC=0;
m_iSpecialColumnC = 0;
m_iSpecialHSlotC = 0;
m_iSpecialGroupC = 0;
m_iBaseCreateRecipe = -1;
m_iBaseCopySlot = -1;
m_bBaseFromInventory = false;
for (int i = 0; i < 3; i++) m_customRecipeSlots[i] = 0;
m_customRecipeValid = false;
m_hasGunpowder = false;
m_iSpecialIngredientCount = 0;
}
LPCWSTR IUIScene_CraftingMenu::GetGroupNameText(int iGroupType)
{
if (isSpecialTab())
return getSpecialGroupName(m_iGroupHIndex);
switch(iGroupType)
{
case ShapedRecipy::eGroupType_Tool:
return app.GetString( IDS_GROUPNAME_TOOLS );
case ShapedRecipy::eGroupType_Food:
return app.GetString( IDS_GROUPNAME_FOOD);
case ShapedRecipy::eGroupType_Structure:
return app.GetString( IDS_GROUPNAME_STRUCTURES );
case ShapedRecipy::eGroupType_Armour:
return app.GetString( IDS_GROUPNAME_ARMOUR );
case ShapedRecipy::eGroupType_Mechanism:
return app.GetString( IDS_GROUPNAME_MECHANISMS );
case ShapedRecipy::eGroupType_Transport:
return app.GetString( IDS_GROUPNAME_TRANSPORT );
case ShapedRecipy::eGroupType_Decoration:
return app.GetString( IDS_GROUPNAME_DECORATIONS );
default:
return L"";
}
}
bool IUIScene_CraftingMenu::isCraftAnything() const
{
return app.DebugSettingsOn() && (app.GetGameSettingsDebugMask(ProfileManager.GetPrimaryPad()) & (1L << eDebugSetting_CraftAnything));
}
bool IUIScene_CraftingMenu::handleKeyDown(int iPad, int iAction, bool bRepeat)
{
bool bHandled = false;
if(m_bIgnoreKeyPresses) return bHandled;
if(bRepeat &&(iAction==ACTION_MENU_X))
{
return S_OK;
}
Minecraft *pMinecraft = Minecraft::GetInstance();
if( pMinecraft->localgameModes[getPad()] != nullptr )
{
Tutorial *tutorial = pMinecraft->localgameModes[getPad()]->getTutorial();
if(tutorial != nullptr)
{
tutorial->handleUIInput(iAction);
if(ui.IsTutorialVisible(getPad()) && !tutorial->isInputAllowed(iAction))
{
return S_OK;
}
}
}
if (iAction == ACTION_MENU_PAGEUP || iAction == ACTION_MENU_PAGEDOWN)
{
if (iAction == ACTION_MENU_PAGEUP)
{
m_iGroupVIndex = (m_iGroupVIndex == 0) ? getMaxVGroups() - 1 : m_iGroupVIndex - 1;
}
else
{
m_iGroupVIndex++;
if (m_iGroupVIndex >= getMaxVGroups()) m_iGroupVIndex = 0;
}
m_iGroupHIndex = 0;
m_iCurrentSlotHIndex = 0;
m_iCurrentSlotVIndex = 1;
ui.PlayUISFX(eSFX_Focus);
if (isSpecialTab())
{
Special_EnterTab();
}
else
{
m_iDisplayDescription = DISPLAY_INVENTORY;
setVGroupHighlight(m_iGroupVIndex);
UpdateCraftingPanels();
CheckRecipesAvailable();
iVSlotIndexA[0] = CanBeMadeA[m_iCurrentSlotHIndex].iCount - 1;
iVSlotIndexA[1] = 0;
iVSlotIndexA[2] = 1;
UpdateVerticalSlots();
UpdateHighlight();
setGroupText(GetGroupNameText(m_pGroupA[m_iGroupHIndex]));
UpdateTooltips();
}
return true;
}
if (isSpecialTab())
{
return Special_HandleKeyDown(iPad, iAction, bRepeat);
}
switch(iAction)
{
case ACTION_MENU_X:
m_iDisplayDescription++;
if (m_iDisplayDescription == DISPLAY_PREVIEW) m_iDisplayDescription++;
if(m_iDisplayDescription>=DISPLAY_MAX) m_iDisplayDescription=DISPLAY_INVENTORY;
ui.PlayUISFX(eSFX_Focus);
UpdateMultiPanel();
UpdateTooltips();
break;
case ACTION_MENU_PAUSEMENU:
case ACTION_MENU_B:
ui.ShowTooltip( iPad, eToolTipButtonX, false );
ui.ShowTooltip( iPad, eToolTipButtonB, false );
ui.ShowTooltip( iPad, eToolTipButtonA, false );
ui.ShowTooltip( iPad, eToolTipButtonRB, false );
ui.CloseUIScenes(iPad);
bHandled = true;
break;
case ACTION_MENU_A:
#ifdef __ORBIS__
case ACTION_MENU_TOUCHPAD_PRESS:
#endif
if(m_pPlayer && m_pPlayer->inventory)
{
Recipy::INGREDIENTS_REQUIRED *pRecipeIngredientsRequired=Recipes::getInstance()->getRecipeIngredientsArray();
if(isCraftAnything())
{
if(CanBeMadeA[m_iCurrentSlotHIndex].iCount!=0)
{
int iSlot=iVSlotIndexA[m_iCurrentSlotVIndex];
int iRecipe= CanBeMadeA[m_iCurrentSlotHIndex].iRecipeA[iSlot];
shared_ptr<ItemInstance> pTempItemInst=pRecipeIngredientsRequired[iRecipe].pRecipy->assemble(nullptr);
if( pMinecraft->localgameModes[iPad] != nullptr)
{
Tutorial *tutorial = pMinecraft->localgameModes[iPad]->getTutorial();
if(tutorial != nullptr)
{
tutorial->onCrafted(pTempItemInst);
}
}
pMinecraft->localgameModes[iPad]->handleCraftItem(iRecipe,m_pPlayer);
if(m_pPlayer->inventory->add(pTempItemInst)==false)
{
m_pPlayer->drop(pTempItemInst);
}
ui.PlayUISFX(eSFX_Craft);
}
}
else if(CanBeMadeA[m_iCurrentSlotHIndex].iCount!=0)
{
int iSlot = (CanBeMadeA[m_iCurrentSlotHIndex].iCount>1) ? iVSlotIndexA[m_iCurrentSlotVIndex] : 0;
int iRecipe= CanBeMadeA[m_iCurrentSlotHIndex].iRecipeA[iSlot];
shared_ptr<ItemInstance> pTempItemInst=pRecipeIngredientsRequired[iRecipe].pRecipy->assemble(nullptr);
if( pMinecraft->localgameModes[iPad] != nullptr )
{
Tutorial *tutorial = pMinecraft->localgameModes[iPad]->getTutorial();
if(tutorial != nullptr)
{
tutorial->createItemSelected(pTempItemInst, pRecipeIngredientsRequired[iRecipe].bCanMake[iPad]);
}
}
if(pRecipeIngredientsRequired[iRecipe].bCanMake[iPad])
{
pTempItemInst->onCraftedBy(m_pPlayer->level, dynamic_pointer_cast<Player>( m_pPlayer->shared_from_this() ), pTempItemInst->count );
pMinecraft->localgameModes[iPad]->handleCraftItem(iRecipe,m_pPlayer);
ui.PlayUISFX(eSFX_Craft);
for(int i=0;i<pRecipeIngredientsRequired[iRecipe].iIngC;i++)
{
for(int j=0;j<pRecipeIngredientsRequired[iRecipe].iIngValA[i];j++)
{
shared_ptr<ItemInstance> ingItemInst = nullptr;
if(pRecipeIngredientsRequired[iRecipe].iIngAuxValA[i]!=Recipes::ANY_AUX_VALUE)
{
ingItemInst = m_pPlayer->inventory->getResourceItem( pRecipeIngredientsRequired[iRecipe].iIngIDA[i],pRecipeIngredientsRequired[iRecipe].iIngAuxValA[i] );
m_pPlayer->inventory->removeResource(pRecipeIngredientsRequired[iRecipe].iIngIDA[i],pRecipeIngredientsRequired[iRecipe].iIngAuxValA[i]);
}
else
{
ingItemInst = m_pPlayer->inventory->getResourceItem( pRecipeIngredientsRequired[iRecipe].iIngIDA[i] );
m_pPlayer->inventory->removeResource(pRecipeIngredientsRequired[iRecipe].iIngIDA[i]);
}
if (ingItemInst != nullptr)
{
if (ingItemInst->getItem()->hasCraftingRemainingItem())
{
m_pPlayer->inventory->add(std::make_shared<ItemInstance>(ingItemInst->getItem()->getCraftingRemainingItem()));
}
}
}
}
if(m_pPlayer->inventory->add(pTempItemInst)==false )
{
m_pPlayer->drop(pTempItemInst);
}
switch(pTempItemInst->id )
{
case Tile::crafting_table_Id: m_pPlayer->awardStat(GenericStats::buildWorkbench(), GenericStats::param_buildWorkbench()); break;
case Item::wooden_pickaxe_Id: m_pPlayer->awardStat(GenericStats::buildPickaxe(), GenericStats::param_buildPickaxe()); break;
case Tile::furnace_Id: m_pPlayer->awardStat(GenericStats::buildFurnace(), GenericStats::param_buildFurnace()); break;
case Item::bread_Id: m_pPlayer->awardStat(GenericStats::makeBread(), GenericStats::param_makeBread()); break;
case Item::cake_Id: m_pPlayer->awardStat(GenericStats::bakeCake(), GenericStats::param_bakeCake()); break;
case Item::stone_pickaxe_Id: m_pPlayer->awardStat(GenericStats::buildBetterPickaxe(), GenericStats::param_buildBetterPickaxe()); break;
case Tile::dispenser_Id: m_pPlayer->awardStat(GenericStats::dispenseWithThis(), GenericStats::param_dispenseWithThis()); break;
case Tile::enchanting_table_Id: m_pPlayer->awardStat(GenericStats::enchantments(), GenericStats::param_enchantments()); break;
case Tile::bookshelf_Id: m_pPlayer->awardStat(GenericStats::bookcase(), GenericStats::param_bookcase()); break;
}
switch (pTempItemInst->getItem()->getBaseItemType()) {
case Item::eBaseItemType_hoe: m_pPlayer->awardStat(GenericStats::buildHoe(), GenericStats::param_buildHoe()); break;
case Item::eBaseItemType_sword: m_pPlayer->awardStat(GenericStats::buildSword(), GenericStats::param_buildSword()); break;
}
CheckRecipesAvailable();
UpdateVerticalSlots();
UpdateHighlight();
}
else
{
ui.PlayUISFX(eSFX_CraftFail);
}
}
}
break;
case ACTION_MENU_LEFT_SCROLL:
case ACTION_MENU_RIGHT_SCROLL:
{
int groupCount = (m_iContainerType == RECIPE_TYPE_3x3 ? m_iMaxGroupH3x3 : m_iMaxGroupH2x2);
if (iAction == ACTION_MENU_LEFT_SCROLL)
{
m_iGroupHIndex = (m_iGroupHIndex == 0) ? groupCount - 1 : m_iGroupHIndex - 1;
}
else
{
m_iGroupHIndex++;
if (m_iGroupHIndex >= groupCount) m_iGroupHIndex = 0;
}
setHGroupHighlight(m_iGroupHIndex);
m_iCurrentSlotHIndex=0;
m_iCurrentSlotVIndex=1;
UpdateCraftingPanels();
CheckRecipesAvailable();
iVSlotIndexA[0] = CanBeMadeA[m_iCurrentSlotHIndex].iCount - 1;
iVSlotIndexA[1] = 0;
iVSlotIndexA[2] = 1;
ui.PlayUISFX(eSFX_Focus);
UpdateVerticalSlots();
UpdateHighlight();
setGroupText(GetGroupNameText(m_pGroupA[m_iGroupHIndex]));
}
break;
}
bool bNoScrollSlots = false;
if(m_bSplitscreen ||(!RenderManager.IsHiDef() && !RenderManager.IsWidescreen()))
{
bNoScrollSlots = true;
}
#ifdef __PSVITA__
bNoScrollSlots = true;
#endif
switch(iAction)
{
case ACTION_MENU_OTHER_STICK_UP:
scrollDescriptionUp();
break;
case ACTION_MENU_OTHER_STICK_DOWN:
scrollDescriptionDown();
break;
case ACTION_MENU_RIGHT:
{
int iOldHSlot=m_iCurrentSlotHIndex;
m_iCurrentSlotHIndex++;
if(m_iCurrentSlotHIndex>=m_iCraftablesMaxHSlotC) m_iCurrentSlotHIndex=0;
m_iCurrentSlotVIndex=1;
iVSlotIndexA[0] = CanBeMadeA[m_iCurrentSlotHIndex].iCount - 1;
iVSlotIndexA[1] = 0;
iVSlotIndexA[2] = 1;
UpdateVerticalSlots();
UpdateHighlight();
setShowCraftHSlot(iOldHSlot,true);
ui.PlayUISFX(eSFX_Focus);
bHandled = true;
}
break;
case ACTION_MENU_LEFT:
{
if(m_iCraftablesMaxHSlotC!=0)
{
int iOldHSlot=m_iCurrentSlotHIndex;
if(m_iCurrentSlotHIndex==0) m_iCurrentSlotHIndex=m_iCraftablesMaxHSlotC-1;
else m_iCurrentSlotHIndex--;
m_iCurrentSlotVIndex=1;
iVSlotIndexA[0] = CanBeMadeA[m_iCurrentSlotHIndex].iCount - 1;
iVSlotIndexA[1] = 0;
iVSlotIndexA[2] = 1;
UpdateVerticalSlots();
UpdateHighlight();
setShowCraftHSlot(iOldHSlot,true);
ui.PlayUISFX(eSFX_Focus);
}
bHandled = true;
}
break;
case ACTION_MENU_UP:
{
if(CanBeMadeA[m_iCurrentSlotHIndex].iCount>1)
{
if(bNoScrollSlots)
{
if(iVSlotIndexA[1]==0)
{
iVSlotIndexA[1]=CanBeMadeA[m_iCurrentSlotHIndex].iCount-1;
}
else
{
iVSlotIndexA[1]--;
}
ui.PlayUISFX(eSFX_Focus);
}
else
{
if(CanBeMadeA[m_iCurrentSlotHIndex].iCount>2)
{
if(m_iCurrentSlotVIndex!=0)
{
m_iCurrentSlotVIndex--;
ui.PlayUISFX(eSFX_Focus);
}
else
{
iVSlotIndexA[2]=iVSlotIndexA[1];
iVSlotIndexA[1]=iVSlotIndexA[0];
if(iVSlotIndexA[0]==0)
{
iVSlotIndexA[0]=CanBeMadeA[m_iCurrentSlotHIndex].iCount-1;
}
else
{
iVSlotIndexA[0]--;
}
ui.PlayUISFX(eSFX_Focus);
}
}
else
{
if(m_iCurrentSlotVIndex!=1)
{
m_iCurrentSlotVIndex--;
ui.PlayUISFX(eSFX_Focus);
}
}
UpdateVerticalSlots();
UpdateHighlight();
}
}
}
break;
case ACTION_MENU_DOWN:
{
if(CanBeMadeA[m_iCurrentSlotHIndex].iCount>1)
{
if(bNoScrollSlots)
{
if(iVSlotIndexA[1]==(CanBeMadeA[m_iCurrentSlotHIndex].iCount-1))
{
iVSlotIndexA[1]=0;
}
else
{
iVSlotIndexA[1]++;
}
ui.PlayUISFX(eSFX_Focus);
}
else
{
if (CanBeMadeA[m_iCurrentSlotHIndex].iCount > 2)
{
if (m_iCurrentSlotVIndex != 2)
{
m_iCurrentSlotVIndex++;
ui.PlayUISFX(eSFX_Focus);
}
else
{
iVSlotIndexA[0] = iVSlotIndexA[1];
iVSlotIndexA[1] = iVSlotIndexA[2];
if (iVSlotIndexA[m_iCurrentSlotVIndex] == (CanBeMadeA[m_iCurrentSlotHIndex].iCount - 1))
{
iVSlotIndexA[2] = 0;
}
else
{
iVSlotIndexA[2]++;
}
ui.PlayUISFX(eSFX_Focus);
}
}
else
{
if (m_iCurrentSlotVIndex != (CanBeMadeA[m_iCurrentSlotHIndex].iCount))
{
m_iCurrentSlotVIndex++;
ui.PlayUISFX(eSFX_Focus);
}
}
UpdateVerticalSlots();
UpdateHighlight();
}
}
}
break;
}
return bHandled;
}
void IUIScene_CraftingMenu::CheckRecipesAvailable()
{
if (isSpecialTab())
{
Special_CheckRecipesAvailable();
return;
}
int iHSlotBrushControl=0;
memset(CanBeMadeA,0,sizeof(CANBEMADE)*m_iCraftablesMaxHSlotC);
hideAllHSlots();
if(m_pPlayer && m_pPlayer->inventory)
{
RecipyList *recipes = ((Recipes *)Recipes::getInstance())->getRecipies();
Recipy::INGREDIENTS_REQUIRED *pRecipeIngredientsRequired=Recipes::getInstance()->getRecipeIngredientsArray();
int iRecipeC=static_cast<int>(recipes->size());
auto itRecipe = recipes->begin();
for(int i=0;i<iRecipeC;i++)
{
Recipy *r = *itRecipe;
if(r->getGroup()!=m_pGroupA[m_iGroupHIndex])
{
itRecipe++;
pRecipeIngredientsRequired[i].bCanMake[getPad()]=false;
continue;
}
if((m_iContainerType==RECIPE_TYPE_2x2) && (pRecipeIngredientsRequired[i].iType==RECIPE_TYPE_3x3))
{
itRecipe++;
pRecipeIngredientsRequired[i].bCanMake[getPad()]=false;
continue;
}
pRecipeIngredientsRequired[i].usBitmaskMissingGridIngredients[getPad()]=0;
bool *bFoundA= new bool [pRecipeIngredientsRequired[i].iIngC];
for(int j=0;j<pRecipeIngredientsRequired[i].iIngC;j++)
{
bFoundA[j]=false;
int iTotalCount=0;
for (unsigned int k = 0; k < m_pPlayer->inventory->items.length; k++)
{
if (m_pPlayer->inventory->items[k] != nullptr)
{
if((m_pPlayer->inventory->items[k]->id == pRecipeIngredientsRequired[i].iIngIDA[j]) &&
((pRecipeIngredientsRequired[i].iIngAuxValA[j]==Recipes::ANY_AUX_VALUE) || (pRecipeIngredientsRequired[i].iIngAuxValA[j]==m_pPlayer->inventory->items[k]->getAuxValue()))
)
{
if(m_pPlayer->inventory->items[k]->GetCount()>=pRecipeIngredientsRequired[i].iIngValA[j])
{
bFoundA[j]=true;
}
else
{
for(unsigned int l=0;l<m_pPlayer->inventory->items.length;l++)
{
if (m_pPlayer->inventory->items[l] != nullptr)
{
if(
(m_pPlayer->inventory->items[l]->id == pRecipeIngredientsRequired[i].iIngIDA[j]) &&
( (pRecipeIngredientsRequired[i].iIngAuxValA[j]==Recipes::ANY_AUX_VALUE) || (pRecipeIngredientsRequired[i].iIngAuxValA[j]==m_pPlayer->inventory->items[l]->getAuxValue() ))
)
{
iTotalCount+=m_pPlayer->inventory->items[l]->GetCount();
}
}
}
if(iTotalCount>=pRecipeIngredientsRequired[i].iIngValA[j])
{
bFoundA[j]=true;
}
}
break;
}
}
}
if(bFoundA[j]==false)
{
int iMissing = pRecipeIngredientsRequired[i].iIngValA[j]-iTotalCount;
int iGridIndex=0;
while(iMissing!=0 && iGridIndex<9)
{
if(((pRecipeIngredientsRequired[i].uiGridA[iGridIndex]&0x00FFFFFF)==pRecipeIngredientsRequired[i].iIngIDA[j]) &&
((pRecipeIngredientsRequired[i].iIngAuxValA[j]==Recipes::ANY_AUX_VALUE) ||((pRecipeIngredientsRequired[i].iIngAuxValA[j]&0xFF)== ((pRecipeIngredientsRequired[i].uiGridA[iGridIndex]&0xFF000000)>>24))) )
{
pRecipeIngredientsRequired[i].usBitmaskMissingGridIngredients[getPad()]|=1<<iGridIndex;
iMissing--;
}
iGridIndex++;
}
}
}
bool bCanMake=true;
for(int j=0;j<pRecipeIngredientsRequired[i].iIngC;j++)
{
if(bFoundA[j]==false)
{
bCanMake=false;
break;
}
}
pRecipeIngredientsRequired[i].bCanMake[getPad()]=bCanMake;
if(iHSlotBrushControl<=m_iCraftablesMaxHSlotC)
{
bool bFound=false;
shared_ptr<ItemInstance> pTempItemInst=pRecipeIngredientsRequired[i].pRecipy->assemble(nullptr);
int iID=pTempItemInst->getItem()->id;
int iBaseType;
if(iID<256)
{
iBaseType=Tile::tiles[iID]->getBaseItemType();
}
else
{
iBaseType=pTempItemInst->getItem()->getBaseItemType();
}
if(iBaseType!=Item::eBaseItemType_undefined)
{
for(int k=0;k<iHSlotBrushControl;k++)
{
if(CanBeMadeA[k].iItemBaseType==iBaseType)
{
bFound=true;
if(CanBeMadeA[k].iCount<m_iMaxVSlotC)
{
CanBeMadeA[k].iRecipeA[CanBeMadeA[k].iCount++]=i;
}
break;
}
}
}
if(!bFound)
{
if(iHSlotBrushControl<m_iCraftablesMaxHSlotC)
{
CanBeMadeA[iHSlotBrushControl].iItemBaseType=iBaseType;
CanBeMadeA[iHSlotBrushControl].iRecipeA[CanBeMadeA[iHSlotBrushControl].iCount++]=i;
iHSlotBrushControl++;
}
}
}
delete [] bFoundA;
itRecipe++;
}
}
int iIndex=0;
Recipy::INGREDIENTS_REQUIRED *pRecipeIngredientsRequired=Recipes::getInstance()->getRecipeIngredientsArray();
while((iIndex<m_iCraftablesMaxHSlotC) && CanBeMadeA[iIndex].iCount!=0)
{
shared_ptr<ItemInstance> pTempItemInst=pRecipeIngredientsRequired[CanBeMadeA[iIndex].iRecipeA[0]].pRecipy->assemble(nullptr);
unsigned int uiAlpha;
if(isCraftAnything())
{
uiAlpha = 31;
}
else
{
uiAlpha = pRecipeIngredientsRequired[CanBeMadeA[iIndex].iRecipeA[0]].bCanMake[getPad()] ? 31 : 16;
}
if( pTempItemInst->id == Item::clock_Id || pTempItemInst->id == Item::compass_Id )
{
pTempItemInst->setAuxValue( 255 );
}
setCraftHSlotItem(getPad(),iIndex,pTempItemInst,uiAlpha);
iIndex++;
}
}
void IUIScene_CraftingMenu::UpdateHighlight()
{
if (isSpecialTab())
{
Special_UpdateHighlight();
return;
}
updateHighlightAndScrollPositions();
bool bCanBeMade = CanBeMadeA[m_iCurrentSlotHIndex].iCount != 0;
if (bCanBeMade)
{
Recipy::INGREDIENTS_REQUIRED* pRecipeIngredientsRequired = Recipes::getInstance()->getRecipeIngredientsArray();
int iSlot = (CanBeMadeA[m_iCurrentSlotHIndex].iCount > 1) ? iVSlotIndexA[m_iCurrentSlotVIndex] : 0;
shared_ptr<ItemInstance> pTempItemInstAdditional = pRecipeIngredientsRequired[CanBeMadeA[m_iCurrentSlotHIndex].iRecipeA[iSlot]].pRecipy->assemble(nullptr);
int id = pTempItemInstAdditional->getDescriptionId();
wstring itemstring;
switch (id)
{
case IDS_TILE_TORCH:
if (pRecipeIngredientsRequired[CanBeMadeA[m_iCurrentSlotHIndex].iRecipeA[iSlot]].iIngAuxValA[0] == 1)
itemstring = app.GetString(IDS_TILE_TORCHCHARCOAL);
else
itemstring = app.GetString(IDS_TILE_TORCHCOAL);
break;
case IDS_ITEM_FIREBALL:
if (pRecipeIngredientsRequired[CanBeMadeA[m_iCurrentSlotHIndex].iRecipeA[iSlot]].iIngAuxValA[2] == 1)
itemstring = app.GetString(IDS_ITEM_FIREBALLCHARCOAL);
else
itemstring = app.GetString(IDS_ITEM_FIREBALLCOAL);
break;
default:
if (pTempItemInstAdditional->hasCustomHoverName())
itemstring = pTempItemInstAdditional->getHoverName();
else
itemstring = app.GetString(id);
break;
}
setItemText(itemstring.c_str());
}
else
{
setItemText(L"");
}
UpdateDescriptionText(bCanBeMade);
DisplayIngredients();
UpdateMultiPanel();
UpdateTooltips();
}
void IUIScene_CraftingMenu::UpdateVerticalSlots()
{
if (isSpecialTab())
{
Special_UpdateVerticalSlots();
return;
}
Recipy::INGREDIENTS_REQUIRED *pRecipeIngredientsRequired=Recipes::getInstance()->getRecipeIngredientsArray();
hideAllVSlots();
if(CanBeMadeA[m_iCurrentSlotHIndex].iCount>1)
{
setShowCraftHSlot(m_iCurrentSlotHIndex,false);
int iSlots=(CanBeMadeA[m_iCurrentSlotHIndex].iCount>2)?3:2;
bool bNoScrollSlots = false;
if(m_bSplitscreen ||(!RenderManager.IsHiDef() && !RenderManager.IsWidescreen()))
{
bNoScrollSlots = true;
}
#ifdef __PSVITA__
bNoScrollSlots = true;
#endif
for(int i=0;i<iSlots;i++)
{
if(bNoScrollSlots && i!=1) continue;
shared_ptr<ItemInstance> pTempItemInstAdditional=pRecipeIngredientsRequired[CanBeMadeA[m_iCurrentSlotHIndex].iRecipeA[iVSlotIndexA[i]]].pRecipy->assemble(nullptr);
unsigned int uiAlpha;
if(isCraftAnything())
{
uiAlpha = 31;
}
else
{
uiAlpha = pRecipeIngredientsRequired[CanBeMadeA[m_iCurrentSlotHIndex].iRecipeA[iVSlotIndexA[i]]].bCanMake[getPad()] ? 31 : 16;
}
if( pTempItemInstAdditional->id == Item::clock_Id || pTempItemInstAdditional->id == Item::compass_Id )
{
pTempItemInstAdditional->setAuxValue( 255 );
}
setCraftVSlotItem(getPad(),i,pTempItemInstAdditional,uiAlpha);
updateVSlotPositions(iSlots, i);
}
}
}
void IUIScene_CraftingMenu::DisplayIngredients()
{
if (isSpecialTab())
{
Special_DisplayIngredients();
return;
}
Recipy::INGREDIENTS_REQUIRED *pRecipeIngredientsRequired=Recipes::getInstance()->getRecipeIngredientsArray();
hideAllIngredientsSlots();
if(CanBeMadeA[m_iCurrentSlotHIndex].iCount!=0)
{
int iSlot = (CanBeMadeA[m_iCurrentSlotHIndex].iCount>1) ? iVSlotIndexA[m_iCurrentSlotVIndex] : 0;
int iRecipy = CanBeMadeA[m_iCurrentSlotHIndex].iRecipeA[iSlot];
int iBoxWidth=(m_iContainerType==RECIPE_TYPE_2x2)?2:3;
int iRecipe=iRecipy;
bool bCanMakeRecipe = pRecipeIngredientsRequired[iRecipe].bCanMake[getPad()];
shared_ptr<ItemInstance> pTempItemInst=pRecipeIngredientsRequired[iRecipe].pRecipy->assemble(nullptr);
m_iIngredientsC=pRecipeIngredientsRequired[iRecipe].iIngC;
for(int i=0;i<pRecipeIngredientsRequired[iRecipe].iIngC;i++)
{
int id=pRecipeIngredientsRequired[iRecipe].iIngIDA[i];
int iAuxVal=pRecipeIngredientsRequired[iRecipe].iIngAuxValA[i];
Item *item = Item::items[id];
shared_ptr<ItemInstance> itemInst= std::make_shared<ItemInstance>(item, pRecipeIngredientsRequired[iRecipe].iIngValA[i], iAuxVal);
int idescID;
if( ((pTempItemInst->id==Item::bed_Id) &&(id==Tile::wool_Id)) ||
((pTempItemInst->id==Item::painting_Id) &&(id==Tile::wool_Id)) )
{
idescID=IDS_ANY_WOOL;
}
else if((pTempItemInst->id==Item::firework_charge_Id) && (id==Item::dye_Id))
{
idescID=IDS_ITEM_DYE_POWDER;
iAuxVal = 1;
}
else
{
idescID=itemInst->getDescriptionId();
}
setIngredientDescriptionText(i,app.GetString(idescID));
if( (iAuxVal & 0xFF) == 0xFF)
iAuxVal = 0;
if( id == Item::clock_Id || id == Item::compass_Id )
{
iAuxVal = 0xFF;
}
itemInst->setAuxValue(iAuxVal);
setIngredientDescriptionItem(getPad(),i,itemInst);
setIngredientDescriptionRedBox(i,false);
}
if( pTempItemInst->id == Item::clock_Id || pTempItemInst->id == Item::compass_Id )
{
pTempItemInst->setAuxValue( 255 );
}
setCraftingOutputSlotItem(getPad(), pTempItemInst);
setCraftingOutputSlotRedBox(isCraftAnything() ? false : !bCanMakeRecipe);
for (int x = 0; x < iBoxWidth; x++)
{
for (int y = 0; y < iBoxWidth; y++)
{
int index = x+y*iBoxWidth;
if(pRecipeIngredientsRequired[iRecipy].uiGridA[x+y*3]!=0)
{
int id=pRecipeIngredientsRequired[iRecipy].uiGridA[x+y*3]&0x00FFFFFF;
int iAuxVal=(pRecipeIngredientsRequired[iRecipy].uiGridA[x+y*3]&0xFF000000)>>24;
for (int k = 0; k < pRecipeIngredientsRequired[iRecipy].iIngC; k++)
{
int fullAux = pRecipeIngredientsRequired[iRecipy].iIngAuxValA[k];
if (pRecipeIngredientsRequired[iRecipy].iIngIDA[k] == id && fullAux != Recipes::ANY_AUX_VALUE && (fullAux & 0xFF) == iAuxVal)
{
iAuxVal = fullAux;
break;
}
}
if( id == Item::clock_Id || id == Item::compass_Id )
{
iAuxVal = 0xFF;
}
else if( pTempItemInst->id==Item::firework_charge_Id && id == Item::dye_Id)
{
iAuxVal = 1;
}
shared_ptr<ItemInstance> itemInst= std::make_shared<ItemInstance>(id, 1, iAuxVal);
setIngredientSlotItem(getPad(),index,itemInst);
if(isCraftAnything())
{
setIngredientSlotRedBox(index, false);
}
else
{
setIngredientSlotRedBox(index, (pRecipeIngredientsRequired[iRecipy].usBitmaskMissingGridIngredients[getPad()]&(1<<(x+y*3)))!=0);
}
}
else
{
setIngredientSlotRedBox(index, false);
setIngredientSlotItem(getPad(),index,nullptr);
}
}
}
}
else
{
setCraftingOutputSlotItem(getPad(), nullptr);
setCraftingOutputSlotRedBox(false);
m_iIngredientsC=0;
int iIngredientsSlots = (m_iContainerType==RECIPE_TYPE_2x2) ? 4 : m_iIngredients3x3SlotC;
for(int i=0;i<iIngredientsSlots;i++)
{
setIngredientSlotRedBox(i, false);
setIngredientSlotItem(getPad(),i,nullptr);
}
}
}
void IUIScene_CraftingMenu::UpdateDescriptionText(bool bCanBeMade)
{
if (isSpecialTab())
{
Special_UpdateDescriptionText();
return;
}
int iIDSString=0;
Recipy::INGREDIENTS_REQUIRED *pRecipeIngredientsRequired=Recipes::getInstance()->getRecipeIngredientsArray();
if(bCanBeMade)
{
int iSlot = (CanBeMadeA[m_iCurrentSlotHIndex].iCount>1) ? iVSlotIndexA[m_iCurrentSlotVIndex] : 0;
shared_ptr<ItemInstance> pTempItemInst=pRecipeIngredientsRequired[CanBeMadeA[m_iCurrentSlotHIndex].iRecipeA[iSlot]].pRecipy->assemble(nullptr);
int iID=pTempItemInst->getItem()->id;
int iAuxVal=pTempItemInst->getAuxValue();
int iBaseType;
if(iID<256)
{
iBaseType=Tile::tiles[iID]->getBaseItemType();
iIDSString = Tile::tiles[iID]->getUseDescriptionId();
}
else
{
iBaseType=pTempItemInst->getItem()->getBaseItemType();
iIDSString = pTempItemInst->getUseDescriptionId();
}
if(iBaseType==Item::eBaseItemType_cloth && iAuxVal==0)
{
iIDSString=IDS_DESC_WOOLSTRING;
}
if(iIDSString>=0)
{
wstring wsText=app.FormatHTMLString(getPad(),app.GetString(iIDSString));
wchar_t startTags[64];
swprintf(startTags,64,L"<font color=\"#%08x\"><P ALIGN=LEFT>",app.GetHTMLColour(eHTMLColor_Black));
wsText= startTags + wsText + L"</P>";
setDescriptionText(wsText.c_str());
}
else
{
setDescriptionText(L"");
}
}
else
{
setDescriptionText(L"");
}
}
void IUIScene_CraftingMenu::UpdateTooltips()
{
if (isSpecialTab())
{
Special_UpdateTooltips();
return;
}
Recipy::INGREDIENTS_REQUIRED *pRecipeIngredientsRequired=Recipes::getInstance()->getRecipeIngredientsArray();
bool bDisplayCreate = false;
if(CanBeMadeA[m_iCurrentSlotHIndex].iCount!=0)
{
int iSlot = (CanBeMadeA[m_iCurrentSlotHIndex].iCount>1) ? iVSlotIndexA[m_iCurrentSlotVIndex] : 0;
bDisplayCreate = pRecipeIngredientsRequired[CanBeMadeA[m_iCurrentSlotHIndex].iRecipeA[iSlot]].bCanMake[getPad()];
}
int showNext = IDS_TOOLTIPS_SHOW_DESCRIPTION;
if (m_iDisplayDescription == DISPLAY_DESCRIPTION) showNext = IDS_TOOLTIPS_SHOW_INGREDIENTS;
else if (m_iDisplayDescription == DISPLAY_INGREDIENTS) showNext = IDS_TOOLTIPS_SHOW_INVENTORY;
ui.SetTooltips( getPad(), bDisplayCreate?IDS_TOOLTIPS_CREATE:-1,IDS_TOOLTIPS_EXIT, showNext,-1, -2, IDS_TOOLTIPS_CHANGE_TYPE, -2, IDS_TOOLTIPS_CHANGE_GROUP);
}
void IUIScene_CraftingMenu::HandleInventoryUpdated()
{
if (isSpecialTab())
{
Special_RefreshBaseItemSlots(nullptr);
}
CheckRecipesAvailable();
UpdateVerticalSlots();
UpdateHighlight();
UpdateTooltips();
}
bool IUIScene_CraftingMenu::isItemSelected(int itemId)
{
if (isSpecialTab())
{
int recipe = Special_GetSelectedRecipe();
if (recipe < 0) return false;
shared_ptr<ItemInstance> result = m_specialRecipes[recipe].result;
return result != nullptr && result->id == itemId;
}
bool isSelected = false;
if(m_pPlayer && m_pPlayer->inventory)
{
Recipy::INGREDIENTS_REQUIRED *pRecipeIngredientsRequired=Recipes::getInstance()->getRecipeIngredientsArray();
if(CanBeMadeA[m_iCurrentSlotHIndex].iCount!=0)
{
int iSlot = (CanBeMadeA[m_iCurrentSlotHIndex].iCount>1) ? iVSlotIndexA[m_iCurrentSlotVIndex] : 0;
int iRecipe= CanBeMadeA[m_iCurrentSlotHIndex].iRecipeA[iSlot];
ItemInstance *pTempItemInst = (ItemInstance *)pRecipeIngredientsRequired[iRecipe].pRecipy->getResultItem();
if(pTempItemInst->id == itemId)
{
isSelected = true;
}
}
}
return isSelected;
}