Added Merchant/Buy/Sell Menu windows. Added sorted item callbacks for traveling merchant inventory modifications.

This commit is contained in:
2023-12-19 17:10:04 -06:00
parent d9e1a1ebaf
commit 71fe49162d
23 changed files with 434 additions and 31 deletions
+33
View File
@@ -49,6 +49,7 @@ std::map<MenuType,Menu*>Menu::menus;
std::string Menu::themeSelection="BlueDefault";
safeunorderedmap<std::string,Theme>Menu::themes;
safemap<ITCategory,std::vector<MenuComponent*>>Menu::inventoryListeners;
safemap<ITCategory,std::vector<MenuComponent*>>Menu::merchantInventoryListeners;
std::vector<MenuComponent*>Menu::equipStatListeners;
const vf2d Menu::CENTERED = {-456,-456};
std::vector<MenuComponent*>Menu::unhandledComponents;
@@ -97,6 +98,9 @@ void Menu::InitializeMenus(){
InitializeOverworldMenuWindow();
InitializeCharacterMenuWindow();
InitializeInventoryWindow();
InitializeMerchantWindow();
InitializeBuyItemWindow();
InitializeSellItemWindow();
for(MenuType type=MenuType(int(MenuType::ENUM_START)+1);type<MenuType::ENUM_END;type=MenuType(int(type+1))){
if(menus.count(type)==0){
@@ -573,6 +577,13 @@ void Menu::InventorySlotsUpdated(ITCategory cat){
}
}
void Menu::MerchantInventorySlotsUpdated(ITCategory cat){
//Update the inventory with a new inventory slot, since there's one additional item to interact with now.
for(MenuComponent*component:merchantInventoryListeners.at(cat)){
component->OnInventorySlotsUpdate(cat);
}
}
void Menu::AddInventoryListener(MenuComponent*component,ITCategory category){
if(inventoryListeners.count(category)){
std::vector<MenuComponent*>&listenerList=inventoryListeners.at(category);
@@ -585,6 +596,23 @@ void Menu::AddInventoryListener(MenuComponent*component,ITCategory category){
}
}
void Menu::InitializeMenuListenerCategory(const std::string&category){
inventoryListeners[category];
merchantInventoryListeners[category];
}
void Menu::AddMerchantInventoryListener(MenuComponent*component,ITCategory category){
if(merchantInventoryListeners.count(category)){
std::vector<MenuComponent*>&listenerList=merchantInventoryListeners.at(category);
if(std::find(listenerList.begin(),listenerList.end(),component)!=listenerList.end()){
ERR("WARNING! Component "<<component->name<<" has already been added to the "<<category<<" merchant listener list! There should not be any duplicates!!")
}
listenerList.push_back(component);
}else{
ERR("WARNING! Inventory category "<<category<<" does not exist!")
}
}
void Menu::AddEquipStatListener(MenuComponent*component){
if(std::find(equipStatListeners.begin(),equipStatListeners.end(),component)!=equipStatListeners.end()){
ERR("WARNING! Component "<<component->name<<" has already been added to the Equip Stat listener list! There should not be any duplicates!!")
@@ -654,4 +682,9 @@ void Menu::RecalculateComponentCount(){
MenuType Menu::GetType(){
return type;
}
void Menu::LockInListeners(){
inventoryListeners.SetInitialized();
merchantInventoryListeners.SetInitialized();
}