From 330ceefc5beec50865c75053ccbbb8a8bdde38b4 Mon Sep 17 00:00:00 2001 From: Nic0Nic0Nii <89110903+Nic0Nic0Nii@users.noreply.github.com> Date: Tue, 30 Jan 2024 21:08:55 +0000 Subject: [PATCH] Add in inventory quantity checks for equipment we don't have when crafting items Co-authored-by: sigonasr2 --- .../BlacksmithCraftingWindow.cpp | 25 +++++++++++++------ Adventures in Lestoria/CraftItemWindow.cpp | 9 +++++-- .../EnhancementStatsLabel.h | 23 +++++++++++------ 3 files changed, 41 insertions(+), 16 deletions(-) diff --git a/Adventures in Lestoria/BlacksmithCraftingWindow.cpp b/Adventures in Lestoria/BlacksmithCraftingWindow.cpp index 8016a0da..889a3c29 100644 --- a/Adventures in Lestoria/BlacksmithCraftingWindow.cpp +++ b/Adventures in Lestoria/BlacksmithCraftingWindow.cpp @@ -97,14 +97,25 @@ void Menu::InitializeBlacksmithCraftingWindow(){ const std::weak_ptritem=comp.lock()->GetItem(); std::string label=""; - if(item.lock()->EnhancementIsPossible()&&item.lock()->GetEnhancementInfo().size()>item.lock()->EnhancementLevel()+1){ - label=std::format("Level {} ->#00AA00 {}",item.lock()->EnhancementLevel(),item.lock()->EnhancementLevel()+1); + if(Inventory::GetItemCount(item.lock()->ActualName)==0){ //If we don't own the item we have to create it first. + if(item.lock()->EnhancementIsPossible()&&item.lock()->GetEnhancementInfo().size()>item.lock()->EnhancementLevel()+1){ + label=std::format("#00FF00Craft {}",item.lock()->GetDisplayName()); + } + Component(CRAFT_ITEM,"Enhancement Level Header")->SetLabel(label); + Component(CRAFT_ITEM,"Item Name Header")->SetLabel(std::format("Crafting {}",item.lock()->DisplayName())); + Component(CRAFT_ITEM,"Enhancement Stats Label")->SetItem(item); + Component(CRAFT_ITEM,"Required Materials List")->SetItem(item); + Component(CRAFT_ITEM,"Craft Button")->SetGrayedOut(!item.lock()->CanEnhanceItem()); + }else{ //We will open the menu that lets us enhance by one level. + if(item.lock()->EnhancementIsPossible()&&item.lock()->GetEnhancementInfo().size()>item.lock()->EnhancementLevel()+1){ + label=std::format("Level {} ->#00AA00 {}",item.lock()->EnhancementLevel(),item.lock()->EnhancementLevel()+1); + } + Component(CRAFT_ITEM,"Enhancement Level Header")->SetLabel(label); + Component(CRAFT_ITEM,"Item Name Header")->SetLabel(std::format("Crafting {}",item.lock()->DisplayName())); + Component(CRAFT_ITEM,"Enhancement Stats Label")->SetItem(item); + Component(CRAFT_ITEM,"Required Materials List")->SetItem(item); + Component(CRAFT_ITEM,"Craft Button")->SetGrayedOut(!item.lock()->CanEnhanceItem()); } - Component(CRAFT_ITEM,"Enhancement Level Header")->SetLabel(label); - Component(CRAFT_ITEM,"Item Name Header")->SetLabel(std::format("Crafting {}",item.lock()->DisplayName())); - Component(CRAFT_ITEM,"Enhancement Stats Label")->SetItem(item); - Component(CRAFT_ITEM,"Required Materials List")->SetItem(item); - Component(CRAFT_ITEM,"Craft Button")->SetGrayedOut(!item.lock()->CanEnhanceItem()); Menu::OpenMenu(CRAFT_ITEM); return true; }, diff --git a/Adventures in Lestoria/CraftItemWindow.cpp b/Adventures in Lestoria/CraftItemWindow.cpp index 2d5dffcc..f1546f14 100644 --- a/Adventures in Lestoria/CraftItemWindow.cpp +++ b/Adventures in Lestoria/CraftItemWindow.cpp @@ -30,7 +30,7 @@ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -Portions of this software are copyright © 2023 The FreeType +Portions of this software are copyright � 2023 The FreeType Project (www.freetype.org). Please see LICENSE_FT.txt for more information. All rights reserved. */ @@ -58,7 +58,12 @@ void Menu::InitializeCraftItemWindow(){ craftItemWindow->ADD("Craft Button",MenuComponent)(geom2d::rect{{craftItemWindow->size.x-84,116},{48,12}},"Craft",[](MenuFuncData data){ const std::weak_ptritem=Component(data.menu.GetType(),"Enhancement Stats Label")->GetItem(); if(item.lock()->CanEnhanceItem()){ - item.lock()->EnhanceItem(); + if(Inventory::GetItemCount(item.lock()->ActualName())==0){ //We don't own this item, so we need to give the player this item and refresh the blacksmith's inventory. + Inventory::AddItem(item.lock()->ActualName()); + Inventory::UpdateBlacksmithInventoryLists(); + }else{ //Since we already own this equipment, just enhance it. + item.lock()->EnhanceItem(); + } } std::string label=""; if(item.lock()->EnhancementIsPossible()&&item.lock()->GetEnhancementInfo().size()>item.lock()->EnhancementLevel()+1){ diff --git a/Adventures in Lestoria/EnhancementStatsLabel.h b/Adventures in Lestoria/EnhancementStatsLabel.h index 4a0c6197..eda66391 100644 --- a/Adventures in Lestoria/EnhancementStatsLabel.h +++ b/Adventures in Lestoria/EnhancementStatsLabel.h @@ -30,7 +30,7 @@ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -Portions of this software are copyright © 2023 The FreeType +Portions of this software are copyright � 2023 The FreeType Project (www.freetype.org). Please see LICENSE_FT.txt for more information. All rights reserved. */ @@ -89,12 +89,21 @@ protected: std::string percentageSign=attr.DisplayAsPercent()?"%":""; - window.DrawShadowStringDecal(drawPos+vf2d{maxAttributeLabelSize+4+24,yOffset},std::format("{:>5} ->#00AA00 {:<5}", - attr.ShowAsDecimal()?std::format("{:>4.2f}{}",value,percentageSign):std::format("{}{}",value,percentageSign), - nextStageValue!=0? - attr.ShowAsDecimal()?std::format("{:<4.2f}{}",nextStageValue,percentageSign):std::format("{}{}",nextStageValue,percentageSign) - :"MAX"), - WHITE,BLACK,adjustedScale,fitToLabel?std::numeric_limits::max():rect.size.x,1.0f); + if(Inventory::GetItemCount(itemRef.lock()->ActualName())==0){ //This item hasn't been created yet, so just show that we are developing the item first. + window.DrawShadowStringDecal(drawPos+vf2d{maxAttributeLabelSize+4+24,yOffset},std::format("{:<5}", + attr.ShowAsDecimal()?std::format("{:>4.2f}{}",value,percentageSign):std::format("{}{}",value,percentageSign), + nextStageValue!=0? + attr.ShowAsDecimal()?std::format("{:<4.2f}{}",nextStageValue,percentageSign):std::format("{}{}",nextStageValue,percentageSign) + :"MAX"), + WHITE,BLACK,adjustedScale,fitToLabel?std::numeric_limits::max():rect.size.x,1.0f); + }else{ //This item is getting enhanced to the next level. + window.DrawShadowStringDecal(drawPos+vf2d{maxAttributeLabelSize+4+24,yOffset},std::format("{:>5} ->#00AA00 {:<5}", + attr.ShowAsDecimal()?std::format("{:>4.2f}{}",value,percentageSign):std::format("{}{}",value,percentageSign), + nextStageValue!=0? + attr.ShowAsDecimal()?std::format("{:<4.2f}{}",nextStageValue,percentageSign):std::format("{}{}",nextStageValue,percentageSign) + :"MAX"), + WHITE,BLACK,adjustedScale,fitToLabel?std::numeric_limits::max():rect.size.x,1.0f); + } yOffset+=16; } }else{