getting selected inventory items

This commit is contained in:
maka70vv 2025-03-02 17:16:22 +06:00
parent 37f0a6aa08
commit 4ff416757f
3 changed files with 17 additions and 0 deletions

View File

@ -150,6 +150,10 @@ void GameObjectManager::handleEvent(const SDL_Event& event) {
switch_room(1);
}
else if (event.type == SDL_MOUSEBUTTONDOWN) {
if (InventoryItem* item = GetItemSelected(true)) {
}
else {
const auto highlightedObjects = aoMgr.findByHighlighted(true);
for (auto* ao : highlightedObjects) {
@ -162,6 +166,7 @@ void GameObjectManager::handleEvent(const SDL_Event& event) {
aoMgr.removeByName(ao->name);
}
}
// bx.Interpolate(animationCounter);
// animationCounter += 2;
}
@ -255,6 +260,7 @@ void GameObjectManager::handleEvent(const SDL_Event& event) {
UnselectAllItems();
if (InventoryItem* item = GetItemByHotkey(hot_key)) {
item->isSelected = true;
std:: cout << item->name << std::endl;
}
}
break;

View File

@ -45,6 +45,16 @@ namespace ZL
return nullptr;
}
InventoryItem* GetItemSelected(bool selected)
{
for (auto& [_, item] : gInventoryMap) {
if (item.isSelected == selected) {
return &item;
}
}
return nullptr;
}
void PrintInventory()
{
std::cout << "Inventory contents:\n";

View File

@ -36,4 +36,5 @@ namespace ZL
// Add these new functions
void UnselectAllItems();
InventoryItem* GetItemByHotkey(int hotkey);
InventoryItem* GetItemSelected(bool isSelected);
}