From 3410b5b92ba2430144565d6a3a61d891d3e2944e Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Wed, 27 Dec 2023 21:03:31 -0600 Subject: [PATCH] Fix overlapping sub-component mouse hover bug, populate blacksmith weapon and armor lists with player's equipment. --- Crawler/BlacksmithCraftingWindow.cpp | 23 ++++++++++++- Crawler/InventoryCreator.cpp | 48 ++++++++++------------------ Crawler/ScrollableWindowComponent.h | 3 +- Crawler/Version.h | 2 +- 4 files changed, 41 insertions(+), 35 deletions(-) diff --git a/Crawler/BlacksmithCraftingWindow.cpp b/Crawler/BlacksmithCraftingWindow.cpp index ab99cf61..17656fcd 100644 --- a/Crawler/BlacksmithCraftingWindow.cpp +++ b/Crawler/BlacksmithCraftingWindow.cpp @@ -72,6 +72,8 @@ void Menu::InitializeBlacksmithCraftingWindow(){ auto weaponTab=blacksmithWindow->ADD("Weapon Tab",MenuComponent)({{2,0},{blacksmithWindow->size.x/2-4,24}},"Weapon",[](MenuFuncData data){ Component(BLACKSMITH,"Armor Tab")->selected=false; + Component(BLACKSMITH,"Weapon Inventory Display")->Enable(true); + Component(BLACKSMITH,"Armor Inventory Display")->Enable(false); data.component->selected=true; return true; })END; @@ -79,12 +81,14 @@ void Menu::InitializeBlacksmithCraftingWindow(){ weaponTab->selectionType=SelectionType::HIGHLIGHT; auto armorTab=blacksmithWindow->ADD("Armor Tab",MenuComponent)({{blacksmithWindow->size.x/2+2,0},{blacksmithWindow->size.x/2-4,24}},"Armor",[](MenuFuncData data){ Component(BLACKSMITH,"Weapon Tab")->selected=false; + Component(BLACKSMITH,"Weapon Inventory Display")->Enable(false); + Component(BLACKSMITH,"Armor Inventory Display")->Enable(true); data.component->selected=true; return true; })END; armorTab->selectionType=SelectionType::HIGHLIGHT; - auto inventoryDisplay=blacksmithWindow->ADD("Weapon Inventory Display",RowInventoryScrollableWindowComponent)({{2,28},{220,blacksmithWindow->size.y-44}},"Item Name Label","Item Description Label", + auto weaponsDisplay=blacksmithWindow->ADD("Weapon Inventory Display",RowInventoryScrollableWindowComponent)({{2,28},{220,blacksmithWindow->size.y-44}},"Item Name Label","Item Description Label", [](MenuFuncData data){ return true; }, @@ -97,6 +101,23 @@ void Menu::InitializeBlacksmithCraftingWindow(){ InventoryCreator::RowPlayerWeapons_InventoryUpdate, {.padding=1,.size={207,28}} )END; + AddInventoryListener(weaponsDisplay,"Equipment"); + + auto armorDisplay=blacksmithWindow->ADD("Armor Inventory Display",RowInventoryScrollableWindowComponent)({{2,28},{220,blacksmithWindow->size.y-44}},"Item Name Label","Item Description Label", + [](MenuFuncData data){ + return true; + }, + [](MenuFuncData data){ + return true; + }, + [](MenuFuncData data){ + return true; + }, + InventoryCreator::RowPlayerArmor_InventoryUpdate, + {.padding=1,.size={207,28}} + )END; + AddInventoryListener(armorDisplay,"Equipment"); + armorDisplay->Enable(false); #pragma region Inventory Description float inventoryDescriptionWidth=blacksmithWindow->pos.x+blacksmithWindow->size.x-26-224; diff --git a/Crawler/InventoryCreator.cpp b/Crawler/InventoryCreator.cpp index 5dfaea0d..6f8106ba 100644 --- a/Crawler/InventoryCreator.cpp +++ b/Crawler/InventoryCreator.cpp @@ -141,16 +141,8 @@ std::function [](InventoryScrollableWindowComponent&component,ITCategory cat){ std::vector>weapons; std::copy_if(Inventory::get("Equipment").begin(),Inventory::get("Equipment").end(),std::back_inserter(weapons),[](std::shared_ptr item){return item.get()->IsWeapon();}); - //We only want to refresh the inventory slots if the component count no longer matches what's actually in our inventory. - if(component.components.size()weapons.size()){ //There are empty spots, so let's clean up. - component.RemoveAllComponents(); - for(std::weak_ptr item:Inventory::get(cat)){ - component.AddButtonOnSlotUpdate(cat); - } - } + component.RemoveAllComponents(); + component.AddButtonOnSlotUpdate(cat); }; std::function InventoryCreator::RowPlayerWeapons_AddButtonOnSlotUpdate= [](InventoryScrollableWindowComponent&component,ITCategory cat){ @@ -158,17 +150,17 @@ std::function std::copy_if(Inventory::get("Equipment").begin(),Inventory::get("Equipment").end(),std::back_inserter(weapons),[](std::shared_ptr item){return item.get()->IsWeapon();}); RowInventoryScrollableWindowComponent*c=DYNAMIC_CAST(&component); - size_t invSize=c->components.size()+1; - int invWidth=int(c->rect.size.x/(float(c->options.size.x)+c->options.padding)); - int x=int((invSize-1)%invWidth); - int y=int((invSize-1)/invWidth); - int itemIndex=y*invWidth+x; vf2d buttonSize=c->options.size; vf2d totalSpacing={c->options.padding+buttonSize.x,c->options.padding+buttonSize.y}; for(std::shared_ptr weapon:weapons){ - auto newItem=c->ADD("item_"+cat+"_"+std::to_string(itemIndex),RowItemDisplay)({totalSpacing*vf2d{float(x),float(y)},buttonSize},weapon,c->inventoryButtonClickAction,c->itemNameLabelName,c->itemDescriptionLabelName,c->inventoryButtonsActive?ButtonAttr::NONE:ButtonAttr::UNSELECTABLE)END; + size_t invSize=c->components.size()+1; + int invWidth=int(c->rect.size.x/(float(c->options.size.x)+c->options.padding)); + int x=int((invSize-1)%invWidth); + int y=int((invSize-1)/invWidth); + int itemIndex=y*invWidth+x; + auto newItem=c->ADD("item_Weapon_"+std::to_string(itemIndex),RowItemDisplay)({totalSpacing*vf2d{float(x),float(y)},buttonSize},weapon,c->inventoryButtonClickAction,c->itemNameLabelName,c->itemDescriptionLabelName,c->inventoryButtonsActive?ButtonAttr::NONE:ButtonAttr::UNSELECTABLE)END; newItem->SetCompactDescriptions(c->compact==COMPACT); newItem->SetPriceLabelType(c->priceLabel); newItem->SetHoverFunc(c->inventoryButtonHoverAction); @@ -182,16 +174,8 @@ std::function [](InventoryScrollableWindowComponent&component,ITCategory cat){ std::vector>armor; std::copy_if(Inventory::get("Equipment").begin(),Inventory::get("Equipment").end(),std::back_inserter(armor),[](std::shared_ptr item){return item.get()->IsArmor();}); - //We only want to refresh the inventory slots if the component count no longer matches what's actually in our inventory. - if(component.components.size()armor.size()){ //There are empty spots, so let's clean up. - component.RemoveAllComponents(); - for(std::weak_ptr item:Inventory::get(cat)){ - component.AddButtonOnSlotUpdate(cat); - } - } + component.RemoveAllComponents(); + component.AddButtonOnSlotUpdate(cat); }; std::function InventoryCreator::RowPlayerArmor_AddButtonOnSlotUpdate= [](InventoryScrollableWindowComponent&component,ITCategory cat){ @@ -199,17 +183,17 @@ std::function std::copy_if(Inventory::get("Equipment").begin(),Inventory::get("Equipment").end(),std::back_inserter(armor),[](std::shared_ptr item){return item.get()->IsArmor();}); RowInventoryScrollableWindowComponent*c=DYNAMIC_CAST(&component); - size_t invSize=c->components.size()+1; - int invWidth=int(c->rect.size.x/(float(c->options.size.x)+c->options.padding)); - int x=int((invSize-1)%invWidth); - int y=int((invSize-1)/invWidth); - int itemIndex=y*invWidth+x; vf2d buttonSize=c->options.size; vf2d totalSpacing={c->options.padding+buttonSize.x,c->options.padding+buttonSize.y}; for(std::shared_ptr armor:armor){ - auto newItem=c->ADD("item_"+cat+"_"+std::to_string(itemIndex),RowItemDisplay)({totalSpacing*vf2d{float(x),float(y)},buttonSize},armor,c->inventoryButtonClickAction,c->itemNameLabelName,c->itemDescriptionLabelName,c->inventoryButtonsActive?ButtonAttr::NONE:ButtonAttr::UNSELECTABLE)END; + size_t invSize=c->components.size()+1; + int invWidth=int(c->rect.size.x/(float(c->options.size.x)+c->options.padding)); + int x=int((invSize-1)%invWidth); + int y=int((invSize-1)/invWidth); + int itemIndex=y*invWidth+x; + auto newItem=c->ADD("item_Armor_"+std::to_string(itemIndex),RowItemDisplay)({totalSpacing*vf2d{float(x),float(y)},buttonSize},armor,c->inventoryButtonClickAction,c->itemNameLabelName,c->itemDescriptionLabelName,c->inventoryButtonsActive?ButtonAttr::NONE:ButtonAttr::UNSELECTABLE)END; newItem->SetCompactDescriptions(c->compact==COMPACT); newItem->SetPriceLabelType(c->priceLabel); newItem->SetHoverFunc(c->inventoryButtonHoverAction); diff --git a/Crawler/ScrollableWindowComponent.h b/Crawler/ScrollableWindowComponent.h index aea37643..43511964 100644 --- a/Crawler/ScrollableWindowComponent.h +++ b/Crawler/ScrollableWindowComponent.h @@ -204,7 +204,8 @@ protected: DrawScrollbar(window,{},focused); } virtual bool GetHoverState(Crawler*game,MenuComponent*child)override{ - return geom2d::overlaps(geom2d::rect{Menu::menus[parentMenu]->pos+rect.pos+child->rect.pos,child->rect.size},game->GetMousePos()); + return geom2d::overlaps(geom2d::rect{Menu::menus[parentMenu]->pos+rect.pos,rect.size},game->GetMousePos())&& //Make sure the mouse is inside the parent window component first.... + geom2d::overlaps(geom2d::rect{Menu::menus[parentMenu]->pos+rect.pos+child->rect.pos,child->rect.size},game->GetMousePos()); } //Calculates the bounds of all components. inline void CalculateBounds(){ diff --git a/Crawler/Version.h b/Crawler/Version.h index 749290fa..272c9cb4 100644 --- a/Crawler/Version.h +++ b/Crawler/Version.h @@ -39,7 +39,7 @@ All rights reserved. #define VERSION_MAJOR 0 #define VERSION_MINOR 2 #define VERSION_PATCH 1 -#define VERSION_BUILD 4919 +#define VERSION_BUILD 4930 #define stringify(a) stringify_(a) #define stringify_(a) #a