mirror of
https://git.neolegacy.dev/neoStudiosLCE/neoLegacy.git
synced 2026-11-25 18:12:41 +01:00
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
1985 lines
60 KiB
C++
1985 lines
60 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.world.item.h"
|
|
#include "../../../Minecraft.World/CraftingContainer.h"
|
|
#include "../../../Minecraft.World/FireworksRecipe.h"
|
|
#include "../../../Minecraft.World/FireworksItem.h"
|
|
#include "../../../Minecraft.World/DyePowderItem.h"
|
|
#include "../../../Minecraft.World/BannerPatternRecipe.h"
|
|
#include "../../../Minecraft.World/Rose.h"
|
|
#include "../../../Minecraft.World/HtmlString.h"
|
|
#include "../../LocalPlayer.h"
|
|
#include "IUIScene_CraftingMenu.h"
|
|
|
|
#include "UI.h"
|
|
|
|
namespace
|
|
{
|
|
struct BannerTabPattern
|
|
{
|
|
const wchar_t* id;
|
|
int group;
|
|
const char* rows[3];
|
|
};
|
|
|
|
const BannerTabPattern s_bannerTabPatterns[] =
|
|
{
|
|
{ L"cr", 1, { "# #", " # ", "#*#" } },
|
|
{ L"ss", 1, { "# #", "#*#", " " } },
|
|
{ L"sc", 1, { " # ", "###", "*# " } },
|
|
{ L"bs", 1, { " ", " * ", "###" } },
|
|
{ L"cs", 1, { " # ", " #*", " # " } },
|
|
{ L"dls", 1, { " #", " #*", "# " } },
|
|
{ L"drs", 1, { "# ", " #*", " #" } },
|
|
{ L"ls", 1, { "# ", "#* ", "# " } },
|
|
{ L"ms", 1, { " ", "###", " * " } },
|
|
{ L"rs", 1, { " #", " *#", " #" } },
|
|
{ L"ts", 1, { "###", " * ", " " } },
|
|
{ L"ld", 2, { "## ", "#* ", " " } },
|
|
{ L"rud", 2, { " ##", " *#", " " } },
|
|
{ L"lud", 2, { " ", "#* ", "## " } },
|
|
{ L"rd", 2, { " ", " *#", " ##" } },
|
|
{ L"hh", 2, { "###", "###", " * " } },
|
|
{ L"hhb", 2, { " * ", "###", "###" } },
|
|
{ L"vh", 2, { "## ", "##*", "## " } },
|
|
{ L"vhr", 2, { " ##", "*##", " ##" } },
|
|
{ L"mc", 3, { " ", " # ", " * " } },
|
|
{ L"mr", 3, { " # ", "#*#", " # " } },
|
|
{ L"bl", 3, { " ", " * ", "# " } },
|
|
{ L"br", 3, { " ", " * ", " #" } },
|
|
{ L"tl", 3, { "# ", " * ", " " } },
|
|
{ L"tr", 3, { " #", " * ", " " } },
|
|
{ L"bt", 3, { " * ", " # ", "# #" } },
|
|
{ L"tt", 3, { "# #", " # ", " * " } },
|
|
{ L"bts", 3, { " ", "#*#", " # " } },
|
|
{ L"tts", 3, { " # ", "#*#", " " } },
|
|
{ L"bo", 4, { "###", "#*#", "###" } },
|
|
{ L"bri", 4, { nullptr, nullptr, nullptr } },
|
|
{ L"cbo", 4, { nullptr, nullptr, nullptr } },
|
|
{ L"gra", 4, { "#*#", " # ", " # " } },
|
|
{ L"gru", 4, { " # ", " # ", "#*#" } },
|
|
{ L"cre", 5, { nullptr, nullptr, nullptr } },
|
|
{ L"flo", 5, { nullptr, nullptr, nullptr } },
|
|
{ L"moj", 5, { nullptr, nullptr, nullptr } },
|
|
{ L"sku", 5, { nullptr, nullptr, nullptr } },
|
|
};
|
|
|
|
const int s_bannerTabPatternC = static_cast<int>(sizeof(s_bannerTabPatterns) / sizeof(s_bannerTabPatterns[0]));
|
|
|
|
const wchar_t* s_bannerGroupNames[6] = { L"", L"Stripes", L"Halves", L"Shapes", L"Borders, Backgrounds and Gradients", L"Symbols" };
|
|
|
|
int findPatternIndex(const wchar_t* id)
|
|
{
|
|
for (int i = 0; i < BannerPatternRecipe::PATTERN_COUNT; i++)
|
|
{
|
|
if (wcscmp(BannerPatternRecipe::PATTERNS[i].id, id) == 0) return i;
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
unsigned int gridEntry(int id, int aux)
|
|
{
|
|
return static_cast<unsigned int>(id) | (static_cast<unsigned int>(aux & 0xFF) << 24);
|
|
}
|
|
|
|
bool sameIngredient(shared_ptr<ItemInstance> a, shared_ptr<ItemInstance> b)
|
|
{
|
|
if (a == nullptr || b == nullptr) return false;
|
|
if (a->id != b->id || a->getAuxValue() != b->getAuxValue()) return false;
|
|
return ItemInstance::tagMatches(a, b);
|
|
}
|
|
|
|
const int s_fireworkGroupForRecipe[3] = { 0, 1, 2 };
|
|
}
|
|
|
|
bool IUIScene_CraftingMenu::isSpinnerGroup() const
|
|
{
|
|
if (m_iGroupVIndex == eGroupVType_Banner) return m_iGroupHIndex == 0;
|
|
return m_iGroupVIndex == eGroupVType_Firework;
|
|
}
|
|
|
|
bool IUIScene_CraftingMenu::isInventoryItem() const
|
|
{
|
|
return m_iGroupVIndex == eGroupVType_Banner && m_iGroupHIndex == 0 && m_iCurrentSlotHIndex == (m_iContainerType == RECIPE_TYPE_3x3 ? 1 : 0);
|
|
}
|
|
|
|
bool IUIScene_CraftingMenu::isDuplicateItem() const
|
|
{
|
|
return m_iGroupVIndex == eGroupVType_Banner && m_iGroupHIndex == 0 && m_iCurrentSlotHIndex == (m_iContainerType == RECIPE_TYPE_3x3 ? 2 : 1);
|
|
}
|
|
|
|
int IUIScene_CraftingMenu::getNumSpinnerSlots() const
|
|
{
|
|
if (!isSpinnerGroup()) return 0;
|
|
if (m_iGroupVIndex == eGroupVType_Banner) return m_iContainerType == RECIPE_TYPE_3x3 ? 3 : 2;
|
|
return m_iGroupHIndex == 0 ? 3 : 2;
|
|
}
|
|
|
|
int IUIScene_CraftingMenu::getSpecialGroupCount() const
|
|
{
|
|
if (m_iGroupVIndex == eGroupVType_Banner) return m_iContainerType == RECIPE_TYPE_3x3 ? 6 : 3;
|
|
if (m_iGroupVIndex == eGroupVType_Firework) return 3;
|
|
return 0;
|
|
}
|
|
|
|
const wchar_t* IUIScene_CraftingMenu::getSpecialGroupName(int group) const
|
|
{
|
|
if (m_iGroupVIndex != eGroupVType_Banner) return L"";
|
|
if (m_iContainerType == RECIPE_TYPE_2x2)
|
|
{
|
|
if (group == 1) return s_bannerGroupNames[4];
|
|
if (group == 2) return s_bannerGroupNames[5];
|
|
return L"";
|
|
}
|
|
if (group < 0 || group > 5) return L"";
|
|
return s_bannerGroupNames[group];
|
|
}
|
|
|
|
const wchar_t* IUIScene_CraftingMenu::getSpinnerTitle() const
|
|
{
|
|
if (m_iGroupVIndex == eGroupVType_Banner)
|
|
{
|
|
if (isInventoryItem()) return L"Select Banner";
|
|
if (isDuplicateItem()) return L"Copy Banner";
|
|
return L"Create Banner";
|
|
}
|
|
if (m_iGroupVIndex == eGroupVType_Firework)
|
|
{
|
|
if (m_iGroupHIndex == 0)
|
|
{
|
|
if (m_iCurrentSlotHIndex == 0) return L"Color";
|
|
if (m_iCurrentSlotHIndex == 1) return L"Shape";
|
|
return L"Effect";
|
|
}
|
|
if (m_iGroupHIndex == 1) return m_iCurrentSlotHIndex == 0 ? L"Firework Star" : L"Fade Color";
|
|
return m_iCurrentSlotHIndex == 0 ? L"Gunpowder" : L"Firework Star";
|
|
}
|
|
return L"";
|
|
}
|
|
|
|
int IUIScene_CraftingMenu::Special_GetInventoryCount(int id, int aux) const
|
|
{
|
|
if (!m_pPlayer || !m_pPlayer->inventory) return 0;
|
|
int count = 0;
|
|
for (unsigned int i = 0; i < m_pPlayer->inventory->items.length; i++)
|
|
{
|
|
shared_ptr<ItemInstance> item = m_pPlayer->inventory->items[i];
|
|
if (item == nullptr || item->id != id) continue;
|
|
if (aux != Recipes::ANY_AUX_VALUE && item->getAuxValue() != aux) continue;
|
|
count += item->count;
|
|
}
|
|
return count;
|
|
}
|
|
|
|
int IUIScene_CraftingMenu::Special_GetUsedCount(int id, int aux) const
|
|
{
|
|
if (m_iGroupVIndex != eGroupVType_Banner) return 0;
|
|
int used = 0;
|
|
for (size_t s = 0; s < m_stackedRecipes.size(); s++)
|
|
{
|
|
const SpecialRecipe& recipe = m_specialRecipes[m_stackedRecipes[s]];
|
|
for (int i = 0; i < recipe.ingC; i++)
|
|
{
|
|
if (recipe.ingId[i] != id) continue;
|
|
if (aux != Recipes::ANY_AUX_VALUE && recipe.ingAux[i] != Recipes::ANY_AUX_VALUE && recipe.ingAux[i] != aux) continue;
|
|
used += recipe.ingCount[i];
|
|
}
|
|
}
|
|
if (m_iBaseCreateRecipe >= 0)
|
|
{
|
|
const SpecialRecipe& recipe = m_specialRecipes[m_iBaseCreateRecipe];
|
|
for (int i = 0; i < recipe.ingC; i++)
|
|
{
|
|
if (recipe.ingId[i] != id) continue;
|
|
if (aux != Recipes::ANY_AUX_VALUE && recipe.ingAux[i] != Recipes::ANY_AUX_VALUE && recipe.ingAux[i] != aux) continue;
|
|
used += recipe.ingCount[i];
|
|
}
|
|
}
|
|
return used;
|
|
}
|
|
|
|
void IUIScene_CraftingMenu::Special_ComputeAvailability(SpecialRecipe& recipe) const
|
|
{
|
|
recipe.missingMask = 0;
|
|
recipe.available = true;
|
|
if (recipe.needs3x3 && m_iContainerType == RECIPE_TYPE_2x2)
|
|
{
|
|
recipe.available = false;
|
|
return;
|
|
}
|
|
if (isCraftAnything()) return;
|
|
|
|
for (int i = 0; i < recipe.ingC; i++)
|
|
{
|
|
int have = Special_GetInventoryCount(recipe.ingId[i], recipe.ingAux[i]) - Special_GetUsedCount(recipe.ingId[i], recipe.ingAux[i]);
|
|
if (have >= recipe.ingCount[i]) continue;
|
|
recipe.available = false;
|
|
int missing = recipe.ingCount[i] - (have > 0 ? have : 0);
|
|
for (int slot = 0; slot < 9 && missing > 0; slot++)
|
|
{
|
|
unsigned int entry = recipe.grid[slot];
|
|
if (entry == 0) continue;
|
|
if (static_cast<int>(entry & 0x00FFFFFF) != recipe.ingId[i]) continue;
|
|
if (recipe.ingAux[i] != Recipes::ANY_AUX_VALUE && static_cast<int>((entry >> 24) & 0xFF) != (recipe.ingAux[i] & 0xFF)) continue;
|
|
recipe.missingMask |= 1 << slot;
|
|
missing--;
|
|
}
|
|
}
|
|
}
|
|
|
|
int IUIScene_CraftingMenu::Special_GetBannerPatternCount(shared_ptr<ItemInstance> banner) const
|
|
{
|
|
if (banner == nullptr) return 0;
|
|
return BannerPatternRecipe::getBannerPatternCount(banner);
|
|
}
|
|
|
|
bool IUIScene_CraftingMenu::Special_CanAddMoreStacks() const
|
|
{
|
|
if (m_accumulatedItem == nullptr) return false;
|
|
return Special_GetBannerPatternCount(m_accumulatedItem) < m_iMaxBannerPatterns;
|
|
}
|
|
|
|
void IUIScene_CraftingMenu::Special_BuildBannerRecipes()
|
|
{
|
|
m_specialRecipes.clear();
|
|
|
|
Recipy::INGREDIENTS_REQUIRED* required = Recipes::getInstance()->getRecipeIngredientsArray();
|
|
RecipyList* recipes = Recipes::getInstance()->getRecipies();
|
|
int index = 0;
|
|
for (auto it = recipes->begin(); it != recipes->end(); ++it, ++index)
|
|
{
|
|
Recipy* r = *it;
|
|
if (r->getGroup() != Recipy::eGroupType_Banner_CustomLogic) continue;
|
|
shared_ptr<ItemInstance> result = required[index].pRecipy->assemble(nullptr);
|
|
if (result == nullptr || result->id != Tile::standing_banner_Id) continue;
|
|
|
|
SpecialRecipe recipe = {};
|
|
recipe.group = 0;
|
|
recipe.key = 0;
|
|
recipe.patternIndex = -1;
|
|
recipe.dye = -1;
|
|
recipe.recipeIndex = index;
|
|
recipe.needs3x3 = required[index].iType == RECIPE_TYPE_3x3;
|
|
for (int g = 0; g < 9; g++) recipe.grid[g] = required[index].uiGridA[g];
|
|
recipe.ingC = required[index].iIngC < m_iMaxSpecialRecipeIngredients ? required[index].iIngC : m_iMaxSpecialRecipeIngredients;
|
|
for (int i = 0; i < recipe.ingC; i++)
|
|
{
|
|
recipe.ingId[i] = required[index].iIngIDA[i];
|
|
recipe.ingAux[i] = required[index].iIngAuxValA[i];
|
|
recipe.ingCount[i] = required[index].iIngValA[i];
|
|
}
|
|
recipe.result = result;
|
|
m_specialRecipes.push_back(recipe);
|
|
}
|
|
|
|
for (int p = 0; p < s_bannerTabPatternC; p++)
|
|
{
|
|
const BannerTabPattern& tabPattern = s_bannerTabPatterns[p];
|
|
int patternIndex = findPatternIndex(tabPattern.id);
|
|
if (patternIndex < 0) continue;
|
|
const BannerPatternRecipe::PatternInfo& info = BannerPatternRecipe::PATTERNS[patternIndex];
|
|
bool itemPattern = info.specialItemId != 0;
|
|
|
|
int group = tabPattern.group;
|
|
if (m_iContainerType == RECIPE_TYPE_2x2)
|
|
{
|
|
if (!itemPattern) continue;
|
|
if (group == 4) group = 1;
|
|
else if (group == 5) group = 2;
|
|
else continue;
|
|
}
|
|
|
|
for (int dye = 0; dye < 16; dye++)
|
|
{
|
|
SpecialRecipe recipe = {};
|
|
recipe.group = group;
|
|
recipe.key = patternIndex;
|
|
recipe.patternIndex = patternIndex;
|
|
recipe.dye = dye;
|
|
recipe.recipeIndex = -1;
|
|
recipe.needs3x3 = !itemPattern;
|
|
|
|
if (itemPattern)
|
|
{
|
|
int specialAux = info.specialItemAux == -1 ? 0 : info.specialItemAux;
|
|
recipe.grid[0] = gridEntry(Tile::standing_banner_Id, 0);
|
|
recipe.grid[1] = gridEntry(info.specialItemId, specialAux);
|
|
recipe.grid[3] = gridEntry(Item::dye_Id, dye);
|
|
recipe.ingC = 2;
|
|
recipe.ingId[0] = info.specialItemId;
|
|
recipe.ingAux[0] = info.specialItemAux;
|
|
recipe.ingCount[0] = 1;
|
|
recipe.ingId[1] = Item::dye_Id;
|
|
recipe.ingAux[1] = dye;
|
|
recipe.ingCount[1] = 1;
|
|
}
|
|
else
|
|
{
|
|
int dyeCount = 0;
|
|
for (int row = 0; row < 3; row++)
|
|
{
|
|
const char* line = BannerPatternRecipe::getCraftRow(patternIndex, row);
|
|
if (line == nullptr) continue;
|
|
for (int col = 0; col < 3; col++)
|
|
{
|
|
char c = line[col];
|
|
if (c == '#')
|
|
{
|
|
recipe.grid[col + row * 3] = gridEntry(Item::dye_Id, dye);
|
|
dyeCount++;
|
|
}
|
|
else if (c == '*')
|
|
{
|
|
recipe.grid[col + row * 3] = gridEntry(Tile::standing_banner_Id, 0);
|
|
}
|
|
}
|
|
}
|
|
recipe.ingC = 1;
|
|
recipe.ingId[0] = Item::dye_Id;
|
|
recipe.ingAux[0] = dye;
|
|
recipe.ingCount[0] = dyeCount;
|
|
}
|
|
|
|
recipe.result = BannerPatternRecipe::createBannerWithPattern(info.id, static_cast<char>(dye), BannerItem::eBannerColor_White);
|
|
m_specialRecipes.push_back(recipe);
|
|
}
|
|
}
|
|
}
|
|
|
|
void IUIScene_CraftingMenu::Special_BuildFireworkRecipes()
|
|
{
|
|
m_specialRecipes.clear();
|
|
|
|
Recipy::INGREDIENTS_REQUIRED* required = Recipes::getInstance()->getRecipeIngredientsArray();
|
|
RecipyList* recipes = Recipes::getInstance()->getRecipies();
|
|
|
|
SpecialRecipe found[3] = {};
|
|
bool haveFound[3] = { false, false, false };
|
|
|
|
int index = 0;
|
|
for (auto it = recipes->begin(); it != recipes->end(); ++it, ++index)
|
|
{
|
|
Recipy* r = *it;
|
|
if (r->getGroup() != Recipy::eGroupType_Fireworks) continue;
|
|
shared_ptr<ItemInstance> result = required[index].pRecipy->assemble(nullptr);
|
|
if (result == nullptr) continue;
|
|
|
|
int group = -1;
|
|
if (result->id == Item::fireworks_Id)
|
|
{
|
|
group = 2;
|
|
}
|
|
else if (result->id == Item::firework_charge_Id)
|
|
{
|
|
bool usesCharge = false;
|
|
for (int i = 0; i < required[index].iIngC; i++)
|
|
{
|
|
if (required[index].iIngIDA[i] == Item::firework_charge_Id) usesCharge = true;
|
|
}
|
|
group = usesCharge ? 1 : 0;
|
|
}
|
|
if (group < 0 || haveFound[group]) continue;
|
|
|
|
SpecialRecipe recipe = {};
|
|
recipe.group = group;
|
|
recipe.key = group;
|
|
recipe.patternIndex = -1;
|
|
recipe.dye = -1;
|
|
recipe.recipeIndex = index;
|
|
recipe.needs3x3 = false;
|
|
for (int g = 0; g < 9; g++) recipe.grid[g] = required[index].uiGridA[g];
|
|
recipe.ingC = required[index].iIngC < m_iMaxSpecialRecipeIngredients ? required[index].iIngC : m_iMaxSpecialRecipeIngredients;
|
|
for (int i = 0; i < recipe.ingC; i++)
|
|
{
|
|
recipe.ingId[i] = required[index].iIngIDA[i];
|
|
recipe.ingAux[i] = required[index].iIngAuxValA[i];
|
|
recipe.ingCount[i] = required[index].iIngValA[i];
|
|
}
|
|
recipe.result = result;
|
|
found[group] = recipe;
|
|
haveFound[group] = true;
|
|
}
|
|
|
|
for (int g = 0; g < 3; g++)
|
|
{
|
|
if (haveFound[s_fireworkGroupForRecipe[g]]) m_specialRecipes.push_back(found[s_fireworkGroupForRecipe[g]]);
|
|
}
|
|
}
|
|
|
|
void IUIScene_CraftingMenu::Special_BuildRecipes()
|
|
{
|
|
if (m_iGroupVIndex == eGroupVType_Banner) Special_BuildBannerRecipes();
|
|
else if (m_iGroupVIndex == eGroupVType_Firework) Special_BuildFireworkRecipes();
|
|
else m_specialRecipes.clear();
|
|
}
|
|
|
|
void IUIScene_CraftingMenu::Special_RefreshBaseItemSlots(shared_ptr<ItemInstance> keepSelected)
|
|
{
|
|
m_baseItemSlots.clear();
|
|
m_duplicateItemSlots.clear();
|
|
if (!m_pPlayer || !m_pPlayer->inventory) return;
|
|
|
|
auto& items = m_pPlayer->inventory->items;
|
|
|
|
if (m_iGroupVIndex == eGroupVType_Banner)
|
|
{
|
|
for (unsigned int slot = 0; slot < items.length; slot++)
|
|
{
|
|
shared_ptr<ItemInstance> item = items[slot];
|
|
if (item == nullptr || item->id != Tile::standing_banner_Id) continue;
|
|
|
|
int patterns = Special_GetBannerPatternCount(item);
|
|
if (patterns < m_iMaxBannerPatterns) m_baseItemSlots.push_back(static_cast<int>(slot));
|
|
if (patterns > 0)
|
|
{
|
|
bool hasBlank = false;
|
|
for (unsigned int other = 0; other < items.length; other++)
|
|
{
|
|
shared_ptr<ItemInstance> o = items[other];
|
|
if (other == slot || o == nullptr || o->id != Tile::standing_banner_Id) continue;
|
|
if (Special_GetBannerPatternCount(o) != 0) continue;
|
|
if (o->getAuxValue() != item->getAuxValue()) continue;
|
|
hasBlank = true;
|
|
break;
|
|
}
|
|
m_duplicateItemSlots.push_back(make_pair(static_cast<int>(slot), hasBlank || isCraftAnything()));
|
|
}
|
|
}
|
|
return;
|
|
}
|
|
|
|
if (m_iGroupVIndex != eGroupVType_Firework) return;
|
|
|
|
shared_ptr<ItemInstance> selected = nullptr;
|
|
if ((m_iGroupHIndex == 1 || m_iGroupHIndex == 2) && !m_recipeIngredients.empty())
|
|
selected = keepSelected;
|
|
|
|
m_customRecipes[0].clear();
|
|
m_customRecipes[1].clear();
|
|
m_customRecipes[2].clear();
|
|
m_recipeIngredients.clear();
|
|
|
|
for (unsigned int slot = 0; slot < items.length; slot++)
|
|
{
|
|
shared_ptr<ItemInstance> item = items[slot];
|
|
if (item == nullptr || item->id != Item::firework_charge_Id) continue;
|
|
shared_ptr<ItemInstance> ingredient = ItemInstance::clone(item);
|
|
ingredient->count = 1;
|
|
bool listed = false;
|
|
for (size_t i = 0; i < m_recipeIngredients.size(); i++)
|
|
{
|
|
if (ingredient->sameItemWithTags(m_recipeIngredients[i]))
|
|
{
|
|
listed = true;
|
|
break;
|
|
}
|
|
}
|
|
if (!listed) m_recipeIngredients.push_back(ingredient);
|
|
}
|
|
|
|
if (m_iGroupHIndex == 1 || m_iGroupHIndex == 2)
|
|
{
|
|
int& customSlot = m_customRecipeSlots[m_iGroupHIndex != 1 ? 1 : 0];
|
|
int starSpinner = m_iGroupHIndex == 1 ? 0 : 1;
|
|
bool found = false;
|
|
if (selected != nullptr)
|
|
{
|
|
for (size_t i = 0; i < m_recipeIngredients.size(); i++)
|
|
{
|
|
if (selected->sameItemWithTags(m_recipeIngredients[i]))
|
|
{
|
|
customSlot = static_cast<int>(i);
|
|
if (m_iCurrentSlotHIndex == starSpinner) iVSlotIndexA[1] = static_cast<int>(i);
|
|
found = true;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
if (!found && customSlot >= static_cast<int>(m_recipeIngredients.size()))
|
|
{
|
|
customSlot = m_recipeIngredients.empty() ? 0 : static_cast<int>(m_recipeIngredients.size()) - 1;
|
|
if (m_iCurrentSlotHIndex == starSpinner) iVSlotIndexA[1] = customSlot;
|
|
}
|
|
}
|
|
|
|
for (int i = 15; i >= 0; i--)
|
|
{
|
|
shared_ptr<ItemInstance> dye = std::make_shared<ItemInstance>(Item::dye_Id, 1, i);
|
|
m_customRecipes[0].push_back(make_pair(dye, Special_GetInventoryCount(Item::dye_Id, i) > 0 || isCraftAnything()));
|
|
}
|
|
|
|
const int shapeIds[9] = { Item::fire_charge_Id, Item::gold_nugget_Id, Item::skull_Id, Item::skull_Id, Item::skull_Id, Item::skull_Id, Item::skull_Id, Item::skull_Id, Item::feather_Id };
|
|
const int shapeAux[9] = { 0, 0, 0, 1, 2, 3, 4, 5, 0 };
|
|
for (int i = 0; i < 9; i++)
|
|
{
|
|
if (Item::items[shapeIds[i]] == nullptr) continue;
|
|
shared_ptr<ItemInstance> shape = std::make_shared<ItemInstance>(shapeIds[i], 1, shapeAux[i]);
|
|
m_customRecipes[1].push_back(make_pair(shape, Special_GetInventoryCount(shapeIds[i], shapeAux[i]) > 0 || isCraftAnything()));
|
|
}
|
|
|
|
const int effectIds[2] = { Item::glowstone_dust_Id, Item::diamond_Id };
|
|
for (int i = 0; i < 2; i++)
|
|
{
|
|
shared_ptr<ItemInstance> effect = std::make_shared<ItemInstance>(effectIds[i], 1, 0);
|
|
m_customRecipes[2].push_back(make_pair(effect, Special_GetInventoryCount(effectIds[i], Recipes::ANY_AUX_VALUE) > 0 || isCraftAnything()));
|
|
}
|
|
|
|
m_hasGunpowder = Special_GetInventoryCount(Item::gunpowder_Id, Recipes::ANY_AUX_VALUE) > 0 || isCraftAnything();
|
|
}
|
|
|
|
int IUIScene_CraftingMenu::getSpecialVSlotCount() const
|
|
{
|
|
if (m_iGroupVIndex == eGroupVType_Banner)
|
|
{
|
|
if (isInventoryItem()) return static_cast<int>(m_baseItemSlots.size());
|
|
if (isDuplicateItem()) return static_cast<int>(m_duplicateItemSlots.size());
|
|
if (m_iCurrentSlotHIndex < m_iSpecialColumnC) return m_specialColumns[m_iCurrentSlotHIndex].count;
|
|
return 0;
|
|
}
|
|
if (m_iGroupVIndex == eGroupVType_Firework)
|
|
{
|
|
if (m_iGroupHIndex == 0)
|
|
{
|
|
if (m_iCurrentSlotHIndex >= 0 && m_iCurrentSlotHIndex < 3) return static_cast<int>(m_customRecipes[m_iCurrentSlotHIndex].size());
|
|
return 0;
|
|
}
|
|
if (m_iGroupHIndex == 1)
|
|
{
|
|
return m_iCurrentSlotHIndex == 0 ? static_cast<int>(m_recipeIngredients.size()) : static_cast<int>(m_customRecipes[0].size());
|
|
}
|
|
return m_iCurrentSlotHIndex == 0 ? 1 : static_cast<int>(m_recipeIngredients.size());
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int IUIScene_CraftingMenu::getSpecialSelection() const
|
|
{
|
|
int count = getSpecialVSlotCount();
|
|
if (count <= 0) return 0;
|
|
int selection;
|
|
if (isSpinnerGroup()) selection = iVSlotIndexA[1];
|
|
else selection = count > 1 ? iVSlotIndexA[m_iCurrentSlotVIndex] : 0;
|
|
if (selection < 0) selection = 0;
|
|
if (selection >= count) selection = count - 1;
|
|
return selection;
|
|
}
|
|
|
|
int IUIScene_CraftingMenu::Special_GetSelectedRecipe() const
|
|
{
|
|
if (m_iGroupVIndex == eGroupVType_Firework)
|
|
{
|
|
for (size_t i = 0; i < m_specialRecipes.size(); i++)
|
|
{
|
|
if (m_specialRecipes[i].group == m_iGroupHIndex) return static_cast<int>(i);
|
|
}
|
|
return -1;
|
|
}
|
|
if (m_iGroupVIndex == eGroupVType_Banner)
|
|
{
|
|
if (isInventoryItem() || isDuplicateItem()) return -1;
|
|
if (m_iCurrentSlotHIndex >= m_iSpecialColumnC) return -1;
|
|
const SpecialColumn& column = m_specialColumns[m_iCurrentSlotHIndex];
|
|
if (column.count == 0) return -1;
|
|
int selection = getSpecialSelection();
|
|
return column.recipes[selection];
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
shared_ptr<ItemInstance> IUIScene_CraftingMenu::Special_GetBaseItemSlot(int column, int slot, bool& enabled) const
|
|
{
|
|
enabled = false;
|
|
if (column < 0 || column >= 3) return nullptr;
|
|
if (slot < 0 || slot >= static_cast<int>(m_customRecipes[column].size())) return nullptr;
|
|
enabled = m_customRecipes[column][slot].second;
|
|
return m_customRecipes[column][slot].first;
|
|
}
|
|
|
|
shared_ptr<ItemInstance> IUIScene_CraftingMenu::Special_GetSpinnerItem(int spinner, int slot, bool& enabled) const
|
|
{
|
|
enabled = false;
|
|
if (m_iGroupVIndex == eGroupVType_Banner)
|
|
{
|
|
if (!m_pPlayer || !m_pPlayer->inventory) return nullptr;
|
|
int createSlot = m_iContainerType == RECIPE_TYPE_3x3 ? 0 : -1;
|
|
int selectSlot = m_iContainerType == RECIPE_TYPE_3x3 ? 1 : 0;
|
|
int copySlot = selectSlot + 1;
|
|
if (spinner == createSlot)
|
|
{
|
|
if (m_iSpecialColumnC == 0 || m_specialColumns[0].count == 0) return nullptr;
|
|
if (slot < 0 || slot >= m_specialColumns[0].count) slot = 0;
|
|
const SpecialRecipe& recipe = m_specialRecipes[m_specialColumns[0].recipes[slot]];
|
|
enabled = recipe.available;
|
|
return recipe.result;
|
|
}
|
|
if (spinner == selectSlot)
|
|
{
|
|
if (m_baseItemSlots.empty()) return nullptr;
|
|
if (slot < 0 || slot >= static_cast<int>(m_baseItemSlots.size())) slot = 0;
|
|
enabled = true;
|
|
return m_pPlayer->inventory->items[m_baseItemSlots[slot]];
|
|
}
|
|
if (spinner == copySlot)
|
|
{
|
|
if (m_duplicateItemSlots.empty()) return nullptr;
|
|
if (slot < 0 || slot >= static_cast<int>(m_duplicateItemSlots.size())) slot = 0;
|
|
enabled = m_duplicateItemSlots[slot].second;
|
|
return m_pPlayer->inventory->items[m_duplicateItemSlots[slot].first];
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
if (m_iGroupVIndex != eGroupVType_Firework) return nullptr;
|
|
|
|
if (m_iGroupHIndex == 0)
|
|
{
|
|
return Special_GetBaseItemSlot(spinner, slot, enabled);
|
|
}
|
|
if (m_iGroupHIndex == 1)
|
|
{
|
|
if (spinner == 0)
|
|
{
|
|
if (m_recipeIngredients.empty()) return nullptr;
|
|
if (slot < 0 || slot >= static_cast<int>(m_recipeIngredients.size())) slot = 0;
|
|
enabled = true;
|
|
return m_recipeIngredients[slot];
|
|
}
|
|
return Special_GetBaseItemSlot(0, slot, enabled);
|
|
}
|
|
if (spinner == 0)
|
|
{
|
|
enabled = m_hasGunpowder;
|
|
return std::make_shared<ItemInstance>(Item::gunpowder_Id, 1, 0);
|
|
}
|
|
if (m_recipeIngredients.empty()) return nullptr;
|
|
if (slot < 0 || slot >= static_cast<int>(m_recipeIngredients.size())) slot = 0;
|
|
enabled = true;
|
|
return m_recipeIngredients[slot];
|
|
}
|
|
|
|
int IUIScene_CraftingMenu::Special_GetCustomIngredientCount(shared_ptr<ItemInstance> item) const
|
|
{
|
|
if (item == nullptr || !m_pPlayer || !m_pPlayer->inventory) return 0;
|
|
if (isCraftAnything()) return 64;
|
|
int count = 0;
|
|
for (unsigned int i = 0; i < m_pPlayer->inventory->items.length; i++)
|
|
{
|
|
shared_ptr<ItemInstance> inv = m_pPlayer->inventory->items[i];
|
|
if (inv == nullptr || inv->id != item->id || inv->getAuxValue() != item->getAuxValue()) continue;
|
|
if (inv->hasTag() && item->hasTag() && !ItemInstance::tagMatches(inv, item)) continue;
|
|
count += inv->count;
|
|
}
|
|
return count;
|
|
}
|
|
|
|
bool IUIScene_CraftingMenu::Special_IsValidCustomIngredient(int index, shared_ptr<ItemInstance> item) const
|
|
{
|
|
if (item == nullptr) return false;
|
|
if (m_iGroupVIndex != eGroupVType_Firework) return true;
|
|
|
|
int itemId = item->id;
|
|
if (m_iGroupHIndex == 1 && itemId == Item::firework_charge_Id) return false;
|
|
|
|
bool isShape = itemId == Item::feather_Id || itemId == Item::gold_nugget_Id || itemId == Item::fire_charge_Id || itemId == Item::skull_Id;
|
|
if (isShape)
|
|
{
|
|
for (size_t i = 0; i < m_customIngredientSlots.size(); i++)
|
|
{
|
|
int slot = m_customIngredientSlots[i];
|
|
if (slot == index || m_customGridItems[slot] == nullptr) continue;
|
|
int slotId = m_customGridItems[slot]->id;
|
|
if (slotId == Item::feather_Id || slotId == Item::gold_nugget_Id || slotId == Item::fire_charge_Id || slotId == Item::skull_Id) return false;
|
|
}
|
|
}
|
|
|
|
if (itemId == Item::gunpowder_Id)
|
|
{
|
|
int gridSlots = m_iContainerType == RECIPE_TYPE_2x2 ? 4 : 9;
|
|
int gunpowder = 0;
|
|
for (int slot = 0; slot < gridSlots; slot++)
|
|
{
|
|
if (slot == index || m_customGridItems[slot] == nullptr) continue;
|
|
if (m_customGridItems[slot]->id == Item::gunpowder_Id)
|
|
{
|
|
gunpowder++;
|
|
if (gunpowder >= 3) return false;
|
|
}
|
|
}
|
|
}
|
|
|
|
int needed = 1;
|
|
int gridSlots = m_iContainerType == RECIPE_TYPE_2x2 ? 4 : 9;
|
|
for (int slot = 0; slot < gridSlots; slot++)
|
|
{
|
|
if (slot == index) continue;
|
|
if (sameIngredient(m_customGridItems[slot], item)) needed++;
|
|
}
|
|
return Special_GetCustomIngredientCount(item) >= needed;
|
|
}
|
|
|
|
bool IUIScene_CraftingMenu::Special_CanAddCustomIngredient(shared_ptr<ItemInstance> item) const
|
|
{
|
|
if (item == nullptr) return false;
|
|
if (!m_customRecipeValid) return false;
|
|
if (m_iGroupHIndex == 1 && m_iCurrentSlotHIndex == 0) return false;
|
|
int gridSlots = m_iContainerType == RECIPE_TYPE_2x2 ? 4 : 9;
|
|
return static_cast<int>(m_customIngredientSlots.size()) + m_iSpecialIngredientCount < gridSlots;
|
|
}
|
|
|
|
void IUIScene_CraftingMenu::Special_ClearCustomIngredients()
|
|
{
|
|
m_customIngredientSlots.clear();
|
|
for (int i = 0; i < 9; i++) m_customGridItems[i] = nullptr;
|
|
}
|
|
|
|
shared_ptr<ItemInstance> IUIScene_CraftingMenu::Special_GetFireworkResult()
|
|
{
|
|
if (m_craftingContainer == nullptr || !m_pPlayer) return nullptr;
|
|
if (Recipes::pFireworksRecipes == nullptr) return nullptr;
|
|
if (!Recipes::pFireworksRecipes->matches(m_craftingContainer, m_pPlayer->level)) return nullptr;
|
|
shared_ptr<ItemInstance> result = Recipes::pFireworksRecipes->assemble(m_craftingContainer);
|
|
return result != nullptr ? ItemInstance::clone(result) : nullptr;
|
|
}
|
|
|
|
void IUIScene_CraftingMenu::Special_DisplayCustomRecipeIngredients()
|
|
{
|
|
int recipeIndex = Special_GetSelectedRecipe();
|
|
int gridSize = m_iContainerType == RECIPE_TYPE_2x2 ? 2 : 3;
|
|
int gridSlots = gridSize * gridSize;
|
|
|
|
if (m_craftingContainer == nullptr) m_craftingContainer = std::make_shared<CraftingContainer>(nullptr, 3, 3);
|
|
for (int i = 0; i < 9; i++) m_craftingContainer->setItem(i, nullptr);
|
|
|
|
if (recipeIndex < 0)
|
|
{
|
|
m_customRecipeValid = false;
|
|
for (int slot = 0; slot < gridSlots; slot++)
|
|
{
|
|
setIngredientSlotItem(getPad(), slot, nullptr);
|
|
setIngredientSlotRedBox(slot, false);
|
|
}
|
|
setCraftingOutputSlotRedBox(true);
|
|
return;
|
|
}
|
|
|
|
SpecialRecipe& recipe = m_specialRecipes[recipeIndex];
|
|
Special_ComputeAvailability(recipe);
|
|
|
|
m_iSpecialIngredientCount = 0;
|
|
for (int g = 0; g < 9; g++)
|
|
{
|
|
if (recipe.grid[g] != 0) m_iSpecialIngredientCount++;
|
|
}
|
|
|
|
m_customRecipeValid = true;
|
|
|
|
for (int x = 0; x < gridSize; x++)
|
|
{
|
|
for (int y = 0; y < gridSize; y++)
|
|
{
|
|
int gridIndex = x + y * 3;
|
|
int slot = x + y * gridSize;
|
|
unsigned int entry = recipe.grid[gridIndex];
|
|
if (entry != 0)
|
|
{
|
|
shared_ptr<ItemInstance> item = nullptr;
|
|
bool missing = !isCraftAnything() && (recipe.missingMask & (1 << gridIndex)) != 0;
|
|
setIngredientSlotRedBox(slot, missing);
|
|
if (missing) m_customRecipeValid = false;
|
|
|
|
int itemId = static_cast<int>(entry & 0x00FFFFFF);
|
|
int itemAux = static_cast<int>((entry >> 24) & 0xFF);
|
|
if (itemAux == 0xFF) itemAux = 0;
|
|
|
|
if (recipe.result != nullptr && recipe.result->id == Item::firework_charge_Id && m_customIngredientSlots.empty())
|
|
{
|
|
if (itemId == Item::dye_Id)
|
|
{
|
|
if (m_iGroupHIndex == 0 || m_iGroupHIndex == 1)
|
|
{
|
|
bool enabled = false;
|
|
item = Special_GetBaseItemSlot(0, m_customRecipeSlots[m_iGroupHIndex != 0 ? 1 : 0], enabled);
|
|
setIngredientSlotRedBox(slot, !enabled);
|
|
m_customRecipeValid = m_customRecipeValid && enabled;
|
|
}
|
|
}
|
|
else if (itemId == Item::firework_charge_Id && !m_recipeIngredients.empty() && (m_iGroupHIndex == 1 || m_iGroupHIndex == 2))
|
|
{
|
|
int starIndex = m_customRecipeSlots[m_iGroupHIndex != 1 ? 1 : 0];
|
|
if (starIndex < 0 || starIndex >= static_cast<int>(m_recipeIngredients.size())) starIndex = 0;
|
|
item = ItemInstance::clone(m_recipeIngredients[starIndex]);
|
|
item->count = 1;
|
|
setIngredientSlotRedBox(slot, false);
|
|
}
|
|
else if (itemId == Item::firework_charge_Id && m_recipeIngredients.empty())
|
|
{
|
|
setIngredientSlotRedBox(slot, true);
|
|
m_customRecipeValid = false;
|
|
}
|
|
}
|
|
|
|
if (item == nullptr)
|
|
{
|
|
if (m_customIngredientSlots.empty() || m_customGridItems[slot] == nullptr)
|
|
item = std::make_shared<ItemInstance>(itemId, 1, itemAux);
|
|
else
|
|
item = m_customGridItems[slot];
|
|
}
|
|
m_customGridItems[slot] = item;
|
|
setIngredientSlotItem(getPad(), slot, item);
|
|
m_craftingContainer->setItem(slot, item);
|
|
}
|
|
else
|
|
{
|
|
bool isCustomSlot = false;
|
|
for (size_t i = 0; i < m_customIngredientSlots.size(); i++)
|
|
{
|
|
if (m_customIngredientSlots[i] == slot)
|
|
{
|
|
isCustomSlot = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (isCustomSlot)
|
|
{
|
|
shared_ptr<ItemInstance> item = nullptr;
|
|
bool enabled = false;
|
|
shared_ptr<ItemInstance> spinnerItem = Special_GetSpinnerItem(m_iCurrentSlotHIndex, m_customRecipeSlots[m_iCurrentSlotHIndex], enabled);
|
|
if (m_customIngredientSlots.back() == slot && spinnerItem != nullptr)
|
|
{
|
|
item = ItemInstance::clone(spinnerItem);
|
|
item->count = 1;
|
|
bool valid = Special_IsValidCustomIngredient(slot, item);
|
|
if (valid)
|
|
{
|
|
setIngredientSlotRedBox(slot, !enabled);
|
|
m_customRecipeValid = m_customRecipeValid && enabled;
|
|
m_customGridItems[slot] = item;
|
|
setIngredientSlotItem(getPad(), slot, item);
|
|
}
|
|
else
|
|
{
|
|
setIngredientSlotRedBox(slot, true);
|
|
m_customRecipeValid = false;
|
|
m_customGridItems[slot] = item;
|
|
setIngredientSlotItem(getPad(), slot, item);
|
|
item = nullptr;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
item = m_customGridItems[slot];
|
|
bool valid = item != nullptr && Special_IsValidCustomIngredient(slot, item);
|
|
setIngredientSlotRedBox(slot, item != nullptr && !valid);
|
|
if (item != nullptr && !valid) m_customRecipeValid = false;
|
|
setIngredientSlotItem(getPad(), slot, item);
|
|
}
|
|
m_craftingContainer->setItem(slot, item);
|
|
}
|
|
else
|
|
{
|
|
setIngredientSlotRedBox(slot, false);
|
|
setIngredientSlotItem(getPad(), slot, nullptr);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (m_customRecipeValid)
|
|
{
|
|
bool fireworkPossible = false;
|
|
bool chargePossible = false;
|
|
bool fadePossible = false;
|
|
FireworksRecipe::updatePossibleRecipes(m_craftingContainer, &fireworkPossible, &chargePossible, &fadePossible);
|
|
if (!fireworkPossible && !chargePossible && !fadePossible) m_customRecipeValid = false;
|
|
else if (Special_GetFireworkResult() == nullptr) m_customRecipeValid = false;
|
|
}
|
|
|
|
if (isCraftAnything()) m_customRecipeValid = Special_GetFireworkResult() != nullptr;
|
|
setCraftingOutputSlotRedBox(!m_customRecipeValid);
|
|
}
|
|
|
|
void IUIScene_CraftingMenu::Special_UpdateAccumulatedItem()
|
|
{
|
|
if (m_baseRecipeItem == nullptr)
|
|
{
|
|
m_accumulatedItem = nullptr;
|
|
setPreviewSlotItem(nullptr);
|
|
return;
|
|
}
|
|
m_accumulatedItem = ItemInstance::clone(m_baseRecipeItem);
|
|
m_accumulatedItem->count = 1;
|
|
for (size_t i = 0; i < m_stackedRecipes.size(); i++)
|
|
{
|
|
const SpecialRecipe& recipe = m_specialRecipes[m_stackedRecipes[i]];
|
|
if (recipe.patternIndex < 0) continue;
|
|
BannerPatternRecipe::addBannerPattern(m_accumulatedItem, BannerPatternRecipe::PATTERNS[recipe.patternIndex].id, static_cast<char>(recipe.dye));
|
|
}
|
|
setPreviewSlotItem(m_accumulatedItem);
|
|
}
|
|
|
|
void IUIScene_CraftingMenu::Special_ClearBase()
|
|
{
|
|
m_baseRecipeItem = nullptr;
|
|
m_accumulatedItem = nullptr;
|
|
m_stackedRecipes.clear();
|
|
m_iBaseCreateRecipe = -1;
|
|
m_iBaseCopySlot = -1;
|
|
m_bBaseFromInventory = false;
|
|
setPreviewSlotItem(nullptr);
|
|
}
|
|
|
|
void IUIScene_CraftingMenu::Special_ResetVerticalSlots()
|
|
{
|
|
m_iCurrentSlotVIndex = 1;
|
|
int count = getSpecialVSlotCount();
|
|
iVSlotIndexA[0] = count > 0 ? count - 1 : 0;
|
|
iVSlotIndexA[1] = 0;
|
|
iVSlotIndexA[2] = count > 1 ? 1 : 0;
|
|
if (m_iGroupVIndex == eGroupVType_Firework)
|
|
{
|
|
int current = m_customRecipeSlots[m_iCurrentSlotHIndex >= 0 && m_iCurrentSlotHIndex < 3 ? m_iCurrentSlotHIndex : 0];
|
|
if (count > 0 && current >= count) current = count - 1;
|
|
iVSlotIndexA[1] = current < 0 ? 0 : current;
|
|
}
|
|
}
|
|
|
|
void IUIScene_CraftingMenu::Special_UpdateTabs()
|
|
{
|
|
m_iSpecialGroupC = getSpecialGroupCount();
|
|
if (isSpinnerGroup())
|
|
{
|
|
m_iSpecialHSlotC = getNumSpinnerSlots();
|
|
m_iDisplayDescription = DISPLAY_INVENTORY;
|
|
}
|
|
else
|
|
{
|
|
m_iSpecialHSlotC = m_iMaxHSlot;
|
|
m_iDisplayDescription = DISPLAY_PREVIEW;
|
|
}
|
|
|
|
for (int group = 0; group < m_iSpecialGroupC; group++)
|
|
{
|
|
shared_ptr<ItemInstance> tabItem = nullptr;
|
|
if (m_iGroupVIndex == eGroupVType_Banner)
|
|
{
|
|
const wchar_t* pattern = nullptr;
|
|
if (m_iContainerType == RECIPE_TYPE_2x2)
|
|
{
|
|
if (group == 1) pattern = L"bo";
|
|
else if (group == 2) pattern = L"cre";
|
|
}
|
|
else
|
|
{
|
|
switch (group)
|
|
{
|
|
case 1: pattern = L"cr"; break;
|
|
case 2: pattern = L"ld"; break;
|
|
case 3: pattern = L"mc"; break;
|
|
case 4: pattern = L"bo"; break;
|
|
case 5: pattern = L"cre"; break;
|
|
}
|
|
}
|
|
if (pattern != nullptr) tabItem = BannerPatternRecipe::createBannerWithPattern(pattern, DyePowderItem::BLACK, BannerItem::eBannerColor_White);
|
|
else tabItem = std::make_shared<ItemInstance>(Tile::standing_banner_Id, 1, 0);
|
|
}
|
|
else if (m_iGroupVIndex == eGroupVType_Firework)
|
|
{
|
|
if (group == 0)
|
|
{
|
|
tabItem = std::make_shared<ItemInstance>(Item::firework_charge_Id, 1, 0);
|
|
}
|
|
else if (group == 1)
|
|
{
|
|
tabItem = std::make_shared<ItemInstance>(Item::firework_charge_Id, 1, 0);
|
|
CompoundTag* tag = new CompoundTag();
|
|
CompoundTag* explosion = new CompoundTag(FireworksItem::TAG_EXPLOSION);
|
|
intArray colors(1);
|
|
colors[0] = DyePowderItem::COLOR_RGB[DyePowderItem::RED];
|
|
explosion->putIntArray(FireworksItem::TAG_E_COLORS, colors);
|
|
tag->put(FireworksItem::TAG_EXPLOSION, explosion);
|
|
tabItem->setTag(tag);
|
|
}
|
|
else
|
|
{
|
|
tabItem = std::make_shared<ItemInstance>(Item::fireworks_Id, 1, 0);
|
|
}
|
|
}
|
|
setHTabItem(group, tabItem);
|
|
}
|
|
|
|
SetCraftingMenu();
|
|
|
|
for (int group = 0; group < m_iSpecialGroupC; group++)
|
|
{
|
|
bool enabled = true;
|
|
if (m_iGroupVIndex == eGroupVType_Banner)
|
|
{
|
|
enabled = (m_iGroupHIndex == 0) ? (group == 0) : (group > 0);
|
|
}
|
|
EnableTab(group, enabled);
|
|
}
|
|
for (int group = m_iSpecialGroupC; group < m_iMaxGroupH3x3; group++)
|
|
{
|
|
EnableTab(group, false);
|
|
}
|
|
|
|
setHGroupHighlight(m_iGroupHIndex);
|
|
ShowSuperCraftingSlots(getNumSpinnerSlots());
|
|
ShowDescriptionPanel(isSpinnerGroup());
|
|
setSpinnerTitle(isSpinnerGroup() ? getSpinnerTitle() : L"");
|
|
UpdateMultiPanel();
|
|
}
|
|
|
|
void IUIScene_CraftingMenu::Special_EnterTab()
|
|
{
|
|
Special_ClearBase();
|
|
Special_ClearCustomIngredients();
|
|
for (int i = 0; i < 3; i++) m_customRecipeSlots[i] = 0;
|
|
m_iGroupHIndex = 0;
|
|
m_iCurrentSlotHIndex = 0;
|
|
m_iCurrentSlotVIndex = 1;
|
|
Special_BuildRecipes();
|
|
setVGroupHighlight(m_iGroupVIndex);
|
|
Special_EnterGroup();
|
|
}
|
|
|
|
void IUIScene_CraftingMenu::Special_EnterGroup()
|
|
{
|
|
if (m_iGroupVIndex == eGroupVType_Firework)
|
|
{
|
|
for (int i = 0; i < 3; i++) m_customRecipeSlots[i] = 0;
|
|
Special_ClearCustomIngredients();
|
|
}
|
|
m_iCurrentSlotHIndex = 0;
|
|
m_iCurrentSlotVIndex = 1;
|
|
Special_RefreshBaseItemSlots(nullptr);
|
|
Special_UpdateTabs();
|
|
Special_CheckRecipesAvailable();
|
|
Special_ResetVerticalSlots();
|
|
UpdateCraftingPanels();
|
|
Special_UpdateVerticalSlots();
|
|
Special_UpdateHighlight();
|
|
setGroupText(getSpecialGroupName(m_iGroupHIndex));
|
|
Special_UpdateTooltips();
|
|
}
|
|
|
|
void IUIScene_CraftingMenu::Special_CheckRecipesAvailable()
|
|
{
|
|
hideAllHSlots();
|
|
m_iSpecialColumnC = 0;
|
|
memset(m_specialColumns, 0, sizeof(m_specialColumns));
|
|
|
|
for (size_t i = 0; i < m_specialRecipes.size(); i++)
|
|
{
|
|
SpecialRecipe& recipe = m_specialRecipes[i];
|
|
Special_ComputeAvailability(recipe);
|
|
if (recipe.group != m_iGroupHIndex) continue;
|
|
|
|
int column = -1;
|
|
for (int c = 0; c < m_iSpecialColumnC; c++)
|
|
{
|
|
if (m_specialColumns[c].key == recipe.key)
|
|
{
|
|
column = c;
|
|
break;
|
|
}
|
|
}
|
|
if (column < 0)
|
|
{
|
|
if (m_iSpecialColumnC >= m_iMaxHSlot) continue;
|
|
column = m_iSpecialColumnC++;
|
|
m_specialColumns[column].key = recipe.key;
|
|
m_specialColumns[column].count = 0;
|
|
}
|
|
if (m_specialColumns[column].count < m_iMaxSpecialColumnRecipes)
|
|
m_specialColumns[column].recipes[m_specialColumns[column].count++] = static_cast<int>(i);
|
|
}
|
|
|
|
Special_UpdateHorizontalSlots();
|
|
}
|
|
|
|
void IUIScene_CraftingMenu::Special_UpdateHorizontalSlots()
|
|
{
|
|
if (isSpinnerGroup())
|
|
{
|
|
clearSpecialSlots();
|
|
int spinners = getNumSpinnerSlots();
|
|
for (int spinner = 0; spinner < spinners; spinner++)
|
|
{
|
|
bool enabled = false;
|
|
int slot = (spinner == m_iCurrentSlotHIndex) ? getSpecialSelection() : (m_iGroupVIndex == eGroupVType_Firework ? m_customRecipeSlots[spinner] : 0);
|
|
shared_ptr<ItemInstance> item = Special_GetSpinnerItem(spinner, slot, enabled);
|
|
if (item == nullptr) continue;
|
|
if (m_iGroupVIndex == eGroupVType_Firework && m_iGroupHIndex == 0 && spinner == 1 && !Special_IsValidCustomIngredient(8, item)) enabled = false;
|
|
setSpecialSlotItem(spinner, item, enabled ? 31 : 16);
|
|
}
|
|
return;
|
|
}
|
|
|
|
for (int column = 0; column < m_iSpecialColumnC; column++)
|
|
{
|
|
const SpecialRecipe& recipe = m_specialRecipes[m_specialColumns[column].recipes[0]];
|
|
bool usable = recipe.available && Special_CanAddMoreStacks();
|
|
setCraftHSlotItem(getPad(), column, recipe.result, usable ? 31 : 16);
|
|
}
|
|
}
|
|
|
|
void IUIScene_CraftingMenu::Special_UpdateVerticalSlots()
|
|
{
|
|
hideAllVSlots();
|
|
|
|
if (isSpinnerGroup())
|
|
{
|
|
if (m_iGroupVIndex == eGroupVType_Firework)
|
|
{
|
|
int sel = getSpecialSelection();
|
|
if (m_iCurrentSlotHIndex >= 0 && m_iCurrentSlotHIndex < 3) m_customRecipeSlots[m_iCurrentSlotHIndex] = sel;
|
|
}
|
|
setSpinnerTitle(getSpinnerTitle());
|
|
Special_UpdateHorizontalSlots();
|
|
return;
|
|
}
|
|
|
|
if (m_iCurrentSlotHIndex >= m_iSpecialColumnC) return;
|
|
const SpecialColumn& column = m_specialColumns[m_iCurrentSlotHIndex];
|
|
if (column.count < 2) return;
|
|
|
|
setShowCraftHSlot(m_iCurrentSlotHIndex, false);
|
|
int slots = column.count > 2 ? 3 : 2;
|
|
|
|
bool noScrollSlots = m_bSplitscreen || (!RenderManager.IsHiDef() && !RenderManager.IsWidescreen());
|
|
#ifdef __PSVITA__
|
|
noScrollSlots = true;
|
|
#endif
|
|
|
|
for (int i = 0; i < slots; i++)
|
|
{
|
|
if (noScrollSlots && i != 1) continue;
|
|
int index = iVSlotIndexA[i];
|
|
if (index < 0 || index >= column.count) continue;
|
|
const SpecialRecipe& recipe = m_specialRecipes[column.recipes[index]];
|
|
bool usable = recipe.available && Special_CanAddMoreStacks();
|
|
setCraftVSlotItem(getPad(), i, recipe.result, usable ? 31 : 16);
|
|
updateVSlotPositions(slots, i);
|
|
}
|
|
}
|
|
|
|
void IUIScene_CraftingMenu::Special_DisplayIngredients()
|
|
{
|
|
hideAllIngredientsSlots();
|
|
|
|
int gridSize = m_iContainerType == RECIPE_TYPE_2x2 ? 2 : 3;
|
|
int gridSlots = gridSize * gridSize;
|
|
|
|
if (m_iGroupVIndex == eGroupVType_Firework)
|
|
{
|
|
Special_DisplayCustomRecipeIngredients();
|
|
int recipeIndex = Special_GetSelectedRecipe();
|
|
shared_ptr<ItemInstance> result = Special_GetFireworkResult();
|
|
if (result == nullptr && recipeIndex >= 0) result = m_specialRecipes[recipeIndex].result;
|
|
setCraftingOutputSlotItem(getPad(), result);
|
|
setCraftingOutputSlotRedBox(!m_customRecipeValid);
|
|
m_iIngredientsC = 0;
|
|
return;
|
|
}
|
|
|
|
if (isInventoryItem() || isDuplicateItem())
|
|
{
|
|
for (int slot = 0; slot < gridSlots; slot++)
|
|
{
|
|
setIngredientSlotRedBox(slot, false);
|
|
setIngredientSlotItem(getPad(), slot, nullptr);
|
|
}
|
|
m_iIngredientsC = 0;
|
|
|
|
bool enabled = false;
|
|
shared_ptr<ItemInstance> item = Special_GetSpinnerItem(m_iCurrentSlotHIndex, getSpecialSelection(), enabled);
|
|
if (item == nullptr)
|
|
{
|
|
setCraftingOutputSlotItem(getPad(), nullptr);
|
|
setCraftingOutputSlotRedBox(false);
|
|
return;
|
|
}
|
|
|
|
shared_ptr<ItemInstance> display = ItemInstance::clone(item);
|
|
display->count = 1;
|
|
setIngredientSlotItem(getPad(), gridSize + 1, display);
|
|
setCraftingOutputSlotItem(getPad(), display);
|
|
|
|
if (isDuplicateItem())
|
|
{
|
|
shared_ptr<ItemInstance> blank = std::make_shared<ItemInstance>(Tile::standing_banner_Id, 1, item->getAuxValue());
|
|
setIngredientSlotItem(getPad(), gridSize, blank);
|
|
setIngredientSlotRedBox(gridSize, !enabled);
|
|
setCraftingOutputSlotRedBox(!enabled);
|
|
}
|
|
else
|
|
{
|
|
setCraftingOutputSlotRedBox(false);
|
|
}
|
|
return;
|
|
}
|
|
|
|
int recipeIndex = Special_GetSelectedRecipe();
|
|
if (recipeIndex < 0)
|
|
{
|
|
setCraftingOutputSlotItem(getPad(), nullptr);
|
|
setCraftingOutputSlotRedBox(false);
|
|
m_iIngredientsC = 0;
|
|
for (int slot = 0; slot < gridSlots; slot++)
|
|
{
|
|
setIngredientSlotRedBox(slot, false);
|
|
setIngredientSlotItem(getPad(), slot, nullptr);
|
|
}
|
|
return;
|
|
}
|
|
|
|
SpecialRecipe& recipe = m_specialRecipes[recipeIndex];
|
|
bool available = recipe.available;
|
|
|
|
m_iIngredientsC = recipe.ingC;
|
|
for (int i = 0; i < recipe.ingC; i++)
|
|
{
|
|
int aux = recipe.ingAux[i] == Recipes::ANY_AUX_VALUE ? 0 : recipe.ingAux[i];
|
|
shared_ptr<ItemInstance> item = std::make_shared<ItemInstance>(recipe.ingId[i], recipe.ingCount[i], aux);
|
|
int descId = item->getDescriptionId();
|
|
if (recipe.ingId[i] == Tile::wool_Id && recipe.ingAux[i] == Recipes::ANY_AUX_VALUE) descId = IDS_ANY_WOOL;
|
|
setIngredientDescriptionText(i, app.GetString(descId));
|
|
setIngredientDescriptionItem(getPad(), i, item);
|
|
setIngredientDescriptionRedBox(i, false);
|
|
}
|
|
|
|
for (int x = 0; x < gridSize; x++)
|
|
{
|
|
for (int y = 0; y < gridSize; y++)
|
|
{
|
|
int gridIndex = x + y * 3;
|
|
int slot = x + y * gridSize;
|
|
unsigned int entry = recipe.grid[gridIndex];
|
|
if (entry == 0)
|
|
{
|
|
setIngredientSlotRedBox(slot, false);
|
|
setIngredientSlotItem(getPad(), slot, nullptr);
|
|
continue;
|
|
}
|
|
int itemId = static_cast<int>(entry & 0x00FFFFFF);
|
|
int itemAux = static_cast<int>((entry >> 24) & 0xFF);
|
|
shared_ptr<ItemInstance> item;
|
|
if (itemId == Tile::standing_banner_Id && m_accumulatedItem != nullptr && recipe.patternIndex >= 0)
|
|
item = m_accumulatedItem;
|
|
else
|
|
item = std::make_shared<ItemInstance>(itemId, 1, itemAux);
|
|
setIngredientSlotItem(getPad(), slot, item);
|
|
setIngredientSlotRedBox(slot, !isCraftAnything() && (recipe.missingMask & (1 << gridIndex)) != 0);
|
|
}
|
|
}
|
|
|
|
shared_ptr<ItemInstance> result = recipe.result;
|
|
if (recipe.patternIndex >= 0)
|
|
{
|
|
if (!Special_CanAddMoreStacks())
|
|
{
|
|
available = false;
|
|
result = m_accumulatedItem;
|
|
}
|
|
else
|
|
{
|
|
result = ItemInstance::clone(m_accumulatedItem);
|
|
BannerPatternRecipe::addBannerPattern(result, BannerPatternRecipe::PATTERNS[recipe.patternIndex].id, static_cast<char>(recipe.dye));
|
|
}
|
|
}
|
|
setCraftingOutputSlotItem(getPad(), result);
|
|
setCraftingOutputSlotRedBox(isCraftAnything() ? false : !available);
|
|
}
|
|
|
|
void IUIScene_CraftingMenu::Special_UpdateDescriptionText()
|
|
{
|
|
if (!isSpinnerGroup())
|
|
{
|
|
setDescriptionTextTop(L"");
|
|
setDescriptionText(L"");
|
|
return;
|
|
}
|
|
|
|
shared_ptr<ItemInstance> item = nullptr;
|
|
if (m_iGroupVIndex == eGroupVType_Banner)
|
|
{
|
|
bool enabled = false;
|
|
item = Special_GetSpinnerItem(m_iCurrentSlotHIndex, getSpecialSelection(), enabled);
|
|
}
|
|
else
|
|
{
|
|
item = Special_GetFireworkResult();
|
|
if (item == nullptr)
|
|
{
|
|
int recipeIndex = Special_GetSelectedRecipe();
|
|
if (recipeIndex >= 0) item = m_specialRecipes[recipeIndex].result;
|
|
}
|
|
}
|
|
|
|
if (item == nullptr)
|
|
{
|
|
setDescriptionTextTop(L"");
|
|
return;
|
|
}
|
|
|
|
vector<HtmlString>* lines = item->getHoverText(m_pPlayer, false);
|
|
wstring text;
|
|
if (lines != nullptr)
|
|
{
|
|
for (size_t i = 0; i < lines->size(); i++)
|
|
(*lines)[i].color = eHTMLColor_Black;
|
|
text = HtmlString::Compose(lines);
|
|
delete lines;
|
|
}
|
|
|
|
wchar_t startTags[64];
|
|
swprintf(startTags, 64, L"<font color=\"#%08x\"><P ALIGN=LEFT>", app.GetHTMLColour(eHTMLColor_Black));
|
|
text = wstring(startTags) + text + L"</P>";
|
|
setDescriptionTextTop(text.c_str());
|
|
}
|
|
|
|
void IUIScene_CraftingMenu::Special_UpdateHighlight()
|
|
{
|
|
updateHighlightAndScrollPositions();
|
|
|
|
shared_ptr<ItemInstance> item = nullptr;
|
|
if (isSpinnerGroup())
|
|
{
|
|
bool enabled = false;
|
|
if (m_iGroupVIndex == eGroupVType_Banner)
|
|
{
|
|
item = Special_GetSpinnerItem(m_iCurrentSlotHIndex, getSpecialSelection(), enabled);
|
|
}
|
|
else
|
|
{
|
|
item = Special_GetSpinnerItem(m_iCurrentSlotHIndex, getSpecialSelection(), enabled);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
int recipeIndex = Special_GetSelectedRecipe();
|
|
if (recipeIndex >= 0) item = m_specialRecipes[recipeIndex].result;
|
|
}
|
|
|
|
if (item == nullptr)
|
|
{
|
|
setItemText(L"");
|
|
}
|
|
else
|
|
{
|
|
wstring name = item->getHoverName();
|
|
if (!isSpinnerGroup() && m_iGroupVIndex == eGroupVType_Banner)
|
|
{
|
|
vector<HtmlString>* lines = item->getHoverText(m_pPlayer, false);
|
|
if (lines != nullptr)
|
|
{
|
|
if (lines->size() > 1) name = (*lines)[1].text;
|
|
delete lines;
|
|
}
|
|
}
|
|
setItemText(name.c_str());
|
|
}
|
|
|
|
Special_DisplayIngredients();
|
|
UpdateMultiPanel();
|
|
Special_UpdateTooltips();
|
|
Special_UpdateDescriptionText();
|
|
}
|
|
|
|
void IUIScene_CraftingMenu::Special_UpdateTooltips()
|
|
{
|
|
int groupTip = IDS_TOOLTIPS_CHANGE_GROUP;
|
|
int groupHint = -2;
|
|
|
|
if (m_iGroupVIndex == eGroupVType_Firework)
|
|
{
|
|
bool enabled = false;
|
|
shared_ptr<ItemInstance> item = Special_GetSpinnerItem(m_iCurrentSlotHIndex, m_customRecipeSlots[m_iCurrentSlotHIndex], enabled);
|
|
bool canAdd = Special_CanAddCustomIngredient(item) && enabled;
|
|
int craftTip = m_customRecipeValid ? IDS_TOOLTIPS_CREATE : -1;
|
|
int removeTip = m_customIngredientSlots.empty() ? -1 : IDS_TOOLTIPS_REMOVE;
|
|
int addTip = canAdd ? IDS_TOOLTIPS_ADD : -1;
|
|
ui.SetTooltips(getPad(), craftTip, IDS_TOOLTIPS_EXIT, removeTip, addTip, -2, IDS_TOOLTIPS_CHANGE_TYPE, groupHint, groupTip);
|
|
return;
|
|
}
|
|
|
|
if (m_iGroupHIndex != 0)
|
|
{
|
|
int recipeIndex = Special_GetSelectedRecipe();
|
|
bool available = recipeIndex >= 0 && m_specialRecipes[recipeIndex].available;
|
|
int craftTip = m_stackedRecipes.empty() ? -1 : IDS_TOOLTIPS_CREATE;
|
|
int addTip = (available && Special_CanAddMoreStacks()) ? IDS_TOOLTIPS_ADD : -1;
|
|
ui.SetTooltips(getPad(), craftTip, IDS_TOOLTIPS_EXIT, IDS_TOOLTIPS_REMOVE, addTip, -2, IDS_TOOLTIPS_CHANGE_TYPE, groupHint, groupTip);
|
|
return;
|
|
}
|
|
|
|
bool enabled = false;
|
|
shared_ptr<ItemInstance> item = Special_GetSpinnerItem(m_iCurrentSlotHIndex, getSpecialSelection(), enabled);
|
|
int craftTip = -1;
|
|
int selectTip = -1;
|
|
if (item != nullptr)
|
|
{
|
|
if (isInventoryItem())
|
|
{
|
|
selectTip = IDS_TOOLTIPS_SELECT;
|
|
}
|
|
else if (isDuplicateItem())
|
|
{
|
|
if (enabled)
|
|
{
|
|
craftTip = IDS_TOOLTIPS_CREATE;
|
|
if (Special_GetBannerPatternCount(item) < m_iMaxBannerPatterns) selectTip = IDS_TOOLTIPS_SELECT;
|
|
}
|
|
}
|
|
else if (enabled)
|
|
{
|
|
craftTip = IDS_TOOLTIPS_CREATE;
|
|
selectTip = IDS_TOOLTIPS_ADD;
|
|
}
|
|
}
|
|
ui.SetTooltips(getPad(), craftTip, IDS_TOOLTIPS_EXIT, -1, selectTip, -2, IDS_TOOLTIPS_CHANGE_TYPE, -1, -1);
|
|
}
|
|
|
|
void IUIScene_CraftingMenu::Special_RemoveFromLocalInventory(int id, int aux, int count)
|
|
{
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
if (aux == Recipes::ANY_AUX_VALUE) m_pPlayer->inventory->removeResource(id);
|
|
else m_pPlayer->inventory->removeResource(id, aux);
|
|
}
|
|
}
|
|
|
|
bool IUIScene_CraftingMenu::Special_RemoveMatchingFromLocalInventory(shared_ptr<ItemInstance> item)
|
|
{
|
|
if (item == nullptr) return false;
|
|
for (unsigned int i = 0; i < m_pPlayer->inventory->items.length; i++)
|
|
{
|
|
shared_ptr<ItemInstance>& inv = m_pPlayer->inventory->items[i];
|
|
if (!sameIngredient(inv, item)) continue;
|
|
inv->count--;
|
|
if (inv->count <= 0) inv = nullptr;
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
void IUIScene_CraftingMenu::Special_GiveLocalItem(shared_ptr<ItemInstance> item)
|
|
{
|
|
if (item == nullptr) return;
|
|
if (!m_pPlayer->inventory->add(item)) m_pPlayer->drop(item);
|
|
}
|
|
|
|
bool IUIScene_CraftingMenu::Special_AddStackedRecipe()
|
|
{
|
|
Minecraft* pMinecraft = Minecraft::GetInstance();
|
|
if (m_iGroupHIndex == 0)
|
|
{
|
|
bool enabled = false;
|
|
shared_ptr<ItemInstance> item = Special_GetSpinnerItem(m_iCurrentSlotHIndex, getSpecialSelection(), enabled);
|
|
if (item == nullptr || !enabled)
|
|
{
|
|
ui.PlayUISFX(eSFX_CraftFail);
|
|
return false;
|
|
}
|
|
|
|
Special_ClearBase();
|
|
if (isInventoryItem())
|
|
{
|
|
m_baseRecipeItem = ItemInstance::clone(item);
|
|
m_baseRecipeItem->count = 1;
|
|
m_bBaseFromInventory = true;
|
|
}
|
|
else if (isDuplicateItem())
|
|
{
|
|
if (Special_GetBannerPatternCount(item) >= m_iMaxBannerPatterns)
|
|
{
|
|
ui.PlayUISFX(eSFX_CraftFail);
|
|
return false;
|
|
}
|
|
m_baseRecipeItem = ItemInstance::clone(item);
|
|
m_baseRecipeItem->count = 1;
|
|
m_iBaseCopySlot = m_duplicateItemSlots[getSpecialSelection()].first;
|
|
}
|
|
else
|
|
{
|
|
int recipeIndex = m_specialColumns[0].recipes[getSpecialSelection()];
|
|
m_baseRecipeItem = ItemInstance::clone(m_specialRecipes[recipeIndex].result);
|
|
m_baseRecipeItem->count = 1;
|
|
m_iBaseCreateRecipe = recipeIndex;
|
|
}
|
|
ui.PlayUISFX(eSFX_Focus);
|
|
Special_UpdateAccumulatedItem();
|
|
m_iGroupHIndex = 1;
|
|
Special_EnterGroup();
|
|
return true;
|
|
}
|
|
|
|
if (!Special_CanAddMoreStacks())
|
|
{
|
|
ui.PlayUISFX(eSFX_CraftFail);
|
|
return false;
|
|
}
|
|
|
|
int recipeIndex = Special_GetSelectedRecipe();
|
|
if (recipeIndex < 0 || !m_specialRecipes[recipeIndex].available)
|
|
{
|
|
if (recipeIndex >= 0 && pMinecraft->localgameModes[getPad()] != nullptr)
|
|
{
|
|
Tutorial* tutorial = pMinecraft->localgameModes[getPad()]->getTutorial();
|
|
if (tutorial != nullptr) tutorial->createItemSelected(m_specialRecipes[recipeIndex].result, false);
|
|
}
|
|
ui.PlayUISFX(eSFX_CraftFail);
|
|
return false;
|
|
}
|
|
|
|
m_stackedRecipes.push_back(recipeIndex);
|
|
Special_UpdateAccumulatedItem();
|
|
ui.PlayUISFX(eSFX_Focus);
|
|
Special_CheckRecipesAvailable();
|
|
Special_UpdateVerticalSlots();
|
|
Special_UpdateHighlight();
|
|
return true;
|
|
}
|
|
|
|
void IUIScene_CraftingMenu::Special_RemoveStackedRecipe()
|
|
{
|
|
if (!m_stackedRecipes.empty())
|
|
{
|
|
m_stackedRecipes.pop_back();
|
|
Special_UpdateAccumulatedItem();
|
|
ui.PlayUISFX(eSFX_Focus);
|
|
if (!m_stackedRecipes.empty() || m_bBaseFromInventory)
|
|
{
|
|
Special_CheckRecipesAvailable();
|
|
Special_UpdateVerticalSlots();
|
|
Special_UpdateHighlight();
|
|
return;
|
|
}
|
|
}
|
|
|
|
Special_ClearBase();
|
|
m_iGroupHIndex = 0;
|
|
ui.PlayUISFX(eSFX_Focus);
|
|
Special_EnterGroup();
|
|
}
|
|
|
|
void IUIScene_CraftingMenu::Special_AddCustomIngredient(shared_ptr<ItemInstance> item)
|
|
{
|
|
int gridSize = m_iContainerType == RECIPE_TYPE_2x2 ? 2 : 3;
|
|
bool placed = false;
|
|
for (int y = 0; y < gridSize && !placed; y++)
|
|
{
|
|
for (int x = 0; x < gridSize && !placed; x++)
|
|
{
|
|
int slot = y * gridSize + x;
|
|
if (m_craftingContainer->getItem(slot) != nullptr) continue;
|
|
item->count = 1;
|
|
m_craftingContainer->setItem(slot, item);
|
|
m_customGridItems[slot] = item;
|
|
m_customIngredientSlots.push_back(slot);
|
|
placed = true;
|
|
}
|
|
}
|
|
ui.PlayUISFX(placed ? eSFX_Focus : eSFX_CraftFail);
|
|
Special_UpdateHighlight();
|
|
}
|
|
|
|
void IUIScene_CraftingMenu::Special_RemoveLastCustomIngredient()
|
|
{
|
|
if (!m_customIngredientSlots.empty())
|
|
{
|
|
m_customGridItems[m_customIngredientSlots.back()] = nullptr;
|
|
m_customIngredientSlots.pop_back();
|
|
ui.PlayUISFX(eSFX_Focus);
|
|
}
|
|
Special_RefreshBaseItemSlots(nullptr);
|
|
Special_CheckRecipesAvailable();
|
|
Special_UpdateVerticalSlots();
|
|
Special_UpdateHighlight();
|
|
}
|
|
|
|
void IUIScene_CraftingMenu::Special_Craft()
|
|
{
|
|
Minecraft* pMinecraft = Minecraft::GetInstance();
|
|
if (!m_pPlayer || !m_pPlayer->inventory) return;
|
|
MultiPlayerGameMode* gameMode = pMinecraft->localgameModes[getPad()];
|
|
if (gameMode == nullptr) return;
|
|
bool craftAnything = isCraftAnything();
|
|
|
|
if (m_iGroupVIndex == eGroupVType_Firework)
|
|
{
|
|
Special_DisplayCustomRecipeIngredients();
|
|
shared_ptr<ItemInstance> result = Special_GetFireworkResult();
|
|
if ((!m_customRecipeValid && !craftAnything) || result == nullptr)
|
|
{
|
|
ui.PlayUISFX(eSFX_CraftFail);
|
|
return;
|
|
}
|
|
|
|
vector<shared_ptr<ItemInstance> > ingredients;
|
|
for (unsigned int slot = 0; slot < m_craftingContainer->getContainerSize(); slot++)
|
|
{
|
|
shared_ptr<ItemInstance> item = m_craftingContainer->getItem(slot);
|
|
if (item == nullptr) continue;
|
|
shared_ptr<ItemInstance> single = ItemInstance::clone(item);
|
|
single->count = 1;
|
|
ingredients.push_back(single);
|
|
}
|
|
|
|
Tutorial* tutorial = gameMode->getTutorial();
|
|
if (tutorial != nullptr) tutorial->onCrafted(result);
|
|
|
|
int starSlot = -1;
|
|
if (result->id == Item::firework_charge_Id)
|
|
{
|
|
for (size_t i = 0; i < ingredients.size() && starSlot < 0; i++)
|
|
{
|
|
if (ingredients[i]->id != Item::firework_charge_Id) continue;
|
|
for (unsigned int s = 0; s < m_pPlayer->inventory->items.length; s++)
|
|
{
|
|
if (sameIngredient(m_pPlayer->inventory->items[s], ingredients[i]))
|
|
{
|
|
starSlot = static_cast<int>(s);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
gameMode->handleCraftCustom(ingredients, m_pPlayer);
|
|
if (!craftAnything)
|
|
{
|
|
for (size_t i = 0; i < ingredients.size(); i++)
|
|
Special_RemoveMatchingFromLocalInventory(ingredients[i]);
|
|
}
|
|
result->onCraftedBy(m_pPlayer->level, dynamic_pointer_cast<Player>(m_pPlayer->shared_from_this()), result->count);
|
|
shared_ptr<ItemInstance> selected = ItemInstance::clone(result);
|
|
selected->count = 1;
|
|
if (starSlot >= 0 && m_pPlayer->inventory->items[starSlot] == nullptr)
|
|
m_pPlayer->inventory->items[starSlot] = result;
|
|
else
|
|
Special_GiveLocalItem(result);
|
|
ui.PlayUISFX(eSFX_Craft);
|
|
|
|
if (m_iGroupHIndex == 1) Special_ClearCustomIngredients();
|
|
Special_RefreshBaseItemSlots(selected);
|
|
Special_CheckRecipesAvailable();
|
|
Special_UpdateVerticalSlots();
|
|
Special_UpdateHighlight();
|
|
return;
|
|
}
|
|
|
|
if (m_iGroupHIndex == 0)
|
|
{
|
|
bool enabled = false;
|
|
shared_ptr<ItemInstance> item = Special_GetSpinnerItem(m_iCurrentSlotHIndex, getSpecialSelection(), enabled);
|
|
if (item == nullptr) return;
|
|
|
|
if (isInventoryItem())
|
|
{
|
|
Special_AddStackedRecipe();
|
|
return;
|
|
}
|
|
|
|
if (isDuplicateItem())
|
|
{
|
|
if (!enabled)
|
|
{
|
|
ui.PlayUISFX(eSFX_CraftFail);
|
|
return;
|
|
}
|
|
gameMode->handleCopyBanner(item, m_pPlayer);
|
|
if (!craftAnything)
|
|
{
|
|
shared_ptr<ItemInstance> blank = std::make_shared<ItemInstance>(Tile::standing_banner_Id, 1, item->getAuxValue());
|
|
for (unsigned int i = 0; i < m_pPlayer->inventory->items.length; i++)
|
|
{
|
|
shared_ptr<ItemInstance>& inv = m_pPlayer->inventory->items[i];
|
|
if (inv == nullptr || inv->id != Tile::standing_banner_Id || inv->getAuxValue() != item->getAuxValue()) continue;
|
|
if (Special_GetBannerPatternCount(inv) != 0) continue;
|
|
inv->count--;
|
|
if (inv->count <= 0) inv = nullptr;
|
|
break;
|
|
}
|
|
}
|
|
shared_ptr<ItemInstance> copy = ItemInstance::clone(item);
|
|
copy->count = 1;
|
|
Special_GiveLocalItem(copy);
|
|
ui.PlayUISFX(eSFX_Craft);
|
|
Special_EnterGroup();
|
|
return;
|
|
}
|
|
|
|
int recipeIndex = m_specialColumns[0].recipes[getSpecialSelection()];
|
|
SpecialRecipe& recipe = m_specialRecipes[recipeIndex];
|
|
if (!recipe.available && !craftAnything)
|
|
{
|
|
Tutorial* tutorial = gameMode->getTutorial();
|
|
if (tutorial != nullptr) tutorial->createItemSelected(recipe.result, false);
|
|
ui.PlayUISFX(eSFX_CraftFail);
|
|
return;
|
|
}
|
|
shared_ptr<ItemInstance> result = ItemInstance::clone(recipe.result);
|
|
Tutorial* tutorial = gameMode->getTutorial();
|
|
if (tutorial != nullptr) tutorial->onCrafted(result);
|
|
gameMode->handleCraftItem(recipe.recipeIndex, m_pPlayer);
|
|
if (!craftAnything)
|
|
{
|
|
for (int i = 0; i < recipe.ingC; i++)
|
|
Special_RemoveFromLocalInventory(recipe.ingId[i], recipe.ingAux[i], recipe.ingCount[i]);
|
|
}
|
|
result->onCraftedBy(m_pPlayer->level, dynamic_pointer_cast<Player>(m_pPlayer->shared_from_this()), result->count);
|
|
Special_GiveLocalItem(result);
|
|
ui.PlayUISFX(eSFX_Craft);
|
|
Special_EnterGroup();
|
|
return;
|
|
}
|
|
|
|
if (m_stackedRecipes.empty() || m_baseRecipeItem == nullptr)
|
|
{
|
|
ui.PlayUISFX(eSFX_CraftFail);
|
|
return;
|
|
}
|
|
|
|
shared_ptr<ItemInstance> findBanner = ItemInstance::clone(m_baseRecipeItem);
|
|
findBanner->count = 1;
|
|
|
|
if (m_iBaseCreateRecipe >= 0)
|
|
{
|
|
SpecialRecipe& baseRecipe = m_specialRecipes[m_iBaseCreateRecipe];
|
|
gameMode->handleCraftItem(baseRecipe.recipeIndex, m_pPlayer);
|
|
if (!craftAnything)
|
|
{
|
|
for (int i = 0; i < baseRecipe.ingC; i++)
|
|
Special_RemoveFromLocalInventory(baseRecipe.ingId[i], baseRecipe.ingAux[i], baseRecipe.ingCount[i]);
|
|
}
|
|
}
|
|
else if (m_iBaseCopySlot >= 0)
|
|
{
|
|
gameMode->handleCopyBanner(findBanner, m_pPlayer);
|
|
if (!craftAnything)
|
|
{
|
|
for (unsigned int i = 0; i < m_pPlayer->inventory->items.length; i++)
|
|
{
|
|
shared_ptr<ItemInstance>& inv = m_pPlayer->inventory->items[i];
|
|
if (inv == nullptr || inv->id != Tile::standing_banner_Id || inv->getAuxValue() != findBanner->getAuxValue()) continue;
|
|
if (Special_GetBannerPatternCount(inv) != 0) continue;
|
|
inv->count--;
|
|
if (inv->count <= 0) inv = nullptr;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
vector<PreviewBannerData> patterns;
|
|
for (size_t i = 0; i < m_stackedRecipes.size(); i++)
|
|
{
|
|
const SpecialRecipe& recipe = m_specialRecipes[m_stackedRecipes[i]];
|
|
patterns.push_back(PreviewBannerData(static_cast<char>(recipe.patternIndex), static_cast<char>(recipe.dye)));
|
|
}
|
|
gameMode->handleCraftBanner(findBanner, patterns, m_pPlayer);
|
|
|
|
if (!craftAnything)
|
|
{
|
|
for (size_t i = 0; i < m_stackedRecipes.size(); i++)
|
|
{
|
|
const SpecialRecipe& recipe = m_specialRecipes[m_stackedRecipes[i]];
|
|
for (int j = 0; j < recipe.ingC; j++)
|
|
Special_RemoveFromLocalInventory(recipe.ingId[j], recipe.ingAux[j], recipe.ingCount[j]);
|
|
}
|
|
if (m_bBaseFromInventory) Special_RemoveMatchingFromLocalInventory(findBanner);
|
|
}
|
|
|
|
shared_ptr<ItemInstance> result = ItemInstance::clone(m_accumulatedItem);
|
|
result->count = 1;
|
|
Tutorial* tutorial = gameMode->getTutorial();
|
|
if (tutorial != nullptr) tutorial->onCrafted(result);
|
|
Special_GiveLocalItem(result);
|
|
ui.PlayUISFX(eSFX_Craft);
|
|
|
|
Special_ClearBase();
|
|
m_iGroupHIndex = 0;
|
|
Special_EnterGroup();
|
|
}
|
|
|
|
void IUIScene_CraftingMenu::Special_ChangeGroup(int direction)
|
|
{
|
|
int groups = getSpecialGroupCount();
|
|
if (groups <= 0) return;
|
|
|
|
if (m_iGroupVIndex == eGroupVType_Banner)
|
|
{
|
|
if (m_baseRecipeItem == nullptr) return;
|
|
m_iGroupHIndex += direction;
|
|
if (m_iGroupHIndex >= groups) m_iGroupHIndex = 1;
|
|
if (m_iGroupHIndex < 1) m_iGroupHIndex = groups - 1;
|
|
}
|
|
else
|
|
{
|
|
m_iGroupHIndex += direction;
|
|
if (m_iGroupHIndex >= groups) m_iGroupHIndex = 0;
|
|
if (m_iGroupHIndex < 0) m_iGroupHIndex = groups - 1;
|
|
}
|
|
ui.PlayUISFX(eSFX_Focus);
|
|
Special_EnterGroup();
|
|
}
|
|
|
|
void IUIScene_CraftingMenu::Special_ScrollHorizontal(int direction)
|
|
{
|
|
int slots = isSpinnerGroup() ? getNumSpinnerSlots() : m_iSpecialHSlotC;
|
|
if (slots <= 0) return;
|
|
int oldSlot = m_iCurrentSlotHIndex;
|
|
m_iCurrentSlotHIndex += direction;
|
|
if (m_iCurrentSlotHIndex >= slots) m_iCurrentSlotHIndex = 0;
|
|
if (m_iCurrentSlotHIndex < 0) m_iCurrentSlotHIndex = slots - 1;
|
|
Special_ResetVerticalSlots();
|
|
if (!isSpinnerGroup()) setShowCraftHSlot(oldSlot, true);
|
|
ui.PlayUISFX(eSFX_Focus);
|
|
UpdateCraftingPanels();
|
|
Special_UpdateVerticalSlots();
|
|
Special_UpdateHighlight();
|
|
}
|
|
|
|
void IUIScene_CraftingMenu::Special_ScrollVertical(int direction)
|
|
{
|
|
int count = getSpecialVSlotCount();
|
|
if (count <= 1) return;
|
|
|
|
bool singleColumn = isSpinnerGroup() || m_bSplitscreen || (!RenderManager.IsHiDef() && !RenderManager.IsWidescreen());
|
|
#ifdef __PSVITA__
|
|
singleColumn = true;
|
|
#endif
|
|
|
|
if (singleColumn)
|
|
{
|
|
iVSlotIndexA[1] += direction;
|
|
if (iVSlotIndexA[1] >= count) iVSlotIndexA[1] = 0;
|
|
if (iVSlotIndexA[1] < 0) iVSlotIndexA[1] = count - 1;
|
|
m_iCurrentSlotVIndex = 1;
|
|
}
|
|
else if (direction < 0)
|
|
{
|
|
if (count > 2)
|
|
{
|
|
if (m_iCurrentSlotVIndex != 0)
|
|
{
|
|
m_iCurrentSlotVIndex--;
|
|
}
|
|
else
|
|
{
|
|
iVSlotIndexA[2] = iVSlotIndexA[1];
|
|
iVSlotIndexA[1] = iVSlotIndexA[0];
|
|
iVSlotIndexA[0] = (iVSlotIndexA[0] == 0) ? count - 1 : iVSlotIndexA[0] - 1;
|
|
}
|
|
}
|
|
else if (m_iCurrentSlotVIndex != 1)
|
|
{
|
|
m_iCurrentSlotVIndex--;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (count > 2)
|
|
{
|
|
if (m_iCurrentSlotVIndex != 2)
|
|
{
|
|
m_iCurrentSlotVIndex++;
|
|
}
|
|
else
|
|
{
|
|
iVSlotIndexA[0] = iVSlotIndexA[1];
|
|
iVSlotIndexA[1] = iVSlotIndexA[2];
|
|
iVSlotIndexA[2] = (iVSlotIndexA[2] == count - 1) ? 0 : iVSlotIndexA[2] + 1;
|
|
}
|
|
}
|
|
else if (m_iCurrentSlotVIndex != count)
|
|
{
|
|
m_iCurrentSlotVIndex++;
|
|
}
|
|
}
|
|
|
|
ui.PlayUISFX(eSFX_Focus);
|
|
Special_UpdateVerticalSlots();
|
|
Special_UpdateHighlight();
|
|
}
|
|
|
|
bool IUIScene_CraftingMenu::Special_HandleKeyDown(int iPad, int iAction, bool bRepeat)
|
|
{
|
|
bool handled = false;
|
|
|
|
switch (iAction)
|
|
{
|
|
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);
|
|
return true;
|
|
case ACTION_MENU_A:
|
|
#ifdef __ORBIS__
|
|
case ACTION_MENU_TOUCHPAD_PRESS:
|
|
#endif
|
|
Special_Craft();
|
|
Special_UpdateTooltips();
|
|
return true;
|
|
case ACTION_MENU_X:
|
|
if (bRepeat) return true;
|
|
if (m_iGroupVIndex == eGroupVType_Firework) Special_RemoveLastCustomIngredient();
|
|
else if (m_iGroupHIndex > 0) Special_RemoveStackedRecipe();
|
|
Special_UpdateTooltips();
|
|
return true;
|
|
case ACTION_MENU_Y:
|
|
if (m_iGroupVIndex == eGroupVType_Firework)
|
|
{
|
|
bool enabled = false;
|
|
shared_ptr<ItemInstance> item = Special_GetSpinnerItem(m_iCurrentSlotHIndex, m_customRecipeSlots[m_iCurrentSlotHIndex], enabled);
|
|
if (Special_CanAddCustomIngredient(item) && enabled && Special_IsValidCustomIngredient(-1, item))
|
|
Special_AddCustomIngredient(ItemInstance::clone(item));
|
|
else
|
|
ui.PlayUISFX(eSFX_CraftFail);
|
|
}
|
|
else
|
|
{
|
|
Special_AddStackedRecipe();
|
|
}
|
|
Special_UpdateTooltips();
|
|
return true;
|
|
case ACTION_MENU_LEFT_SCROLL:
|
|
Special_ChangeGroup(-1);
|
|
return true;
|
|
case ACTION_MENU_RIGHT_SCROLL:
|
|
Special_ChangeGroup(1);
|
|
return true;
|
|
case ACTION_MENU_OTHER_STICK_UP:
|
|
scrollDescriptionUp();
|
|
break;
|
|
case ACTION_MENU_OTHER_STICK_DOWN:
|
|
scrollDescriptionDown();
|
|
break;
|
|
case ACTION_MENU_RIGHT:
|
|
Special_ScrollHorizontal(1);
|
|
handled = true;
|
|
break;
|
|
case ACTION_MENU_LEFT:
|
|
Special_ScrollHorizontal(-1);
|
|
handled = true;
|
|
break;
|
|
case ACTION_MENU_UP:
|
|
Special_ScrollVertical(-1);
|
|
handled = true;
|
|
break;
|
|
case ACTION_MENU_DOWN:
|
|
Special_ScrollVertical(1);
|
|
handled = true;
|
|
break;
|
|
}
|
|
return handled;
|
|
}
|