From 70f30b8b3a03cc4e3d050acbdbab88fe160eb143 Mon Sep 17 00:00:00 2001 From: maka70vv <25.makarovv@gmail.com> Date: Sun, 2 Mar 2025 16:48:31 +0600 Subject: [PATCH] not worked version of inventory choosing --- GameObjectManager.cpp | 28 +++++++++++++++++++++++++++- GameObjectManager.h | 1 + Inventory.cpp | 3 ++- Inventory.h | 4 +++- 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/GameObjectManager.cpp b/GameObjectManager.cpp index f14465b..e1651e2 100644 --- a/GameObjectManager.cpp +++ b/GameObjectManager.cpp @@ -13,6 +13,7 @@ const float GameObjectManager::INVENTORY_MARGIN = 10.0f; void GameObjectManager::initialize() { current_room_index = 0; + objects_in_inventory = 0; coneTexturePtr = std::make_shared(CreateTextureDataFromBmp24("./conus.bmp")); @@ -145,7 +146,8 @@ void GameObjectManager::handleEvent(const SDL_Event& event) { continue; } - AddItemToInventory(ao->name, ao->activeObjectTexturePtr); + AddItemToInventory(ao->name, ao->activeObjectTexturePtr, objects_in_inventory+1); + objects_in_inventory++; aoMgr.removeByName(ao->name); } @@ -234,6 +236,30 @@ void GameObjectManager::handleEvent(const SDL_Event& event) { Environment::violaLastWalkFrame = -1; } break; + + case SDLK_1: + { + int hot_key = 1; + std::string keyStr = std::to_string(hot_key); + + auto it = gInventory.find(keyStr); + if (it != gInventory.end()) { + it->second.isSelected = true; + } + std::cout << keyStr << std::endl; + + } break; + + case SDLK_2: + { + int hot_key = 2; + std::string keyStr = std::to_string(hot_key); + + auto it = gInventory.find(keyStr); + if (it != gInventory.end()) { + it->second.isSelected = true; + } + } break; // ...handle other keys... } } diff --git a/GameObjectManager.h b/GameObjectManager.h index 440a6b5..cae553e 100644 --- a/GameObjectManager.h +++ b/GameObjectManager.h @@ -55,6 +55,7 @@ public: static const float INVENTORY_ICON_SIZE; static const float INVENTORY_MARGIN; ActiveObjectManager aoMgr; + int objects_in_inventory; private: //int animationCounter = 0; diff --git a/Inventory.cpp b/Inventory.cpp index 7bd79fd..6ad1767 100644 --- a/Inventory.cpp +++ b/Inventory.cpp @@ -5,11 +5,12 @@ namespace ZL // Определяем глобальную переменную std::unordered_map gInventoryMap; - void AddItemToInventory(const std::string& name, std::shared_ptr tex) + void AddItemToInventory(const std::string& name, std::shared_ptr tex, int hot_key) { InventoryItem item; item.name = name; item.texture = tex; + item.hot_key = hot_key; // Вставляем или перезаписываем (operator[] так сделает). gInventoryMap[name] = item; diff --git a/Inventory.h b/Inventory.h index 1935fdb..20bc5c7 100644 --- a/Inventory.h +++ b/Inventory.h @@ -12,13 +12,15 @@ namespace ZL { std::string name; std::shared_ptr texture; + bool isSelected = false; + int hot_key; }; // Глобальное хранилище предметов extern std::unordered_map gInventory; // Добавить предмет в инвентарь - void AddItemToInventory(const std::string& name, std::shared_ptr tex); + void AddItemToInventory(const std::string& name, std::shared_ptr tex, int hot_key); // Удалить предмет из инвентаря void RemoveItemFromInventory(const std::string& name);