diff --git a/.vscode/settings.json b/.vscode/settings.json index 3b515bf..e350b3f 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -21,6 +21,11 @@ "string": "cpp", "unordered_map": "cpp", "unordered_set": "cpp", - "vector": "cpp" + "vector": "cpp", + "chrono": "cpp", + "text_encoding": "cpp", + "typeindex": "cpp", + "typeinfo": "cpp", + "*.inc": "cpp" } } \ No newline at end of file diff --git a/GameObjectManager.cpp b/GameObjectManager.cpp index 2759a92..b6d8120 100644 --- a/GameObjectManager.cpp +++ b/GameObjectManager.cpp @@ -114,6 +114,12 @@ void GameObjectManager::initialize() { roomTexturePtr = rooms[current_room_index].roomTexture; + AddItemToInventory("book1", std::make_shared(CreateTextureDataFromBmp24("./Kitchen_ceramics.bmp")), objects_in_inventory+1); + objects_in_inventory++; + AddItemToInventory("book2", std::make_shared(CreateTextureDataFromBmp24("./Kitchen_ceramics.bmp")), objects_in_inventory+1); + objects_in_inventory++; + + //SDL_ShowCursor(SDL_DISABLE); SDL_SetRelativeMouseMode(SDL_TRUE); } @@ -243,28 +249,15 @@ void GameObjectManager::handleEvent(const SDL_Event& event) { 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; + case SDLK_2: + { + int hot_key = (event.key.keysym.sym == SDLK_1) ? 1 : 2; + UnselectAllItems(); + if (InventoryItem* item = GetItemByHotkey(hot_key)) { + item->isSelected = true; + } + } + break; // ...handle other keys... } } diff --git a/Inventory.cpp b/Inventory.cpp index 6ad1767..292cfb0 100644 --- a/Inventory.cpp +++ b/Inventory.cpp @@ -35,6 +35,16 @@ namespace ZL return nullptr; } + InventoryItem* GetItemByHotkey(int hotkey) + { + for (auto& [_, item] : gInventoryMap) { + if (item.hot_key == hotkey) { + return &item; + } + } + return nullptr; + } + void PrintInventory() { std::cout << "Inventory contents:\n"; @@ -44,6 +54,13 @@ namespace ZL } } + void UnselectAllItems() + { + for (auto& [_, item] : gInventoryMap) { + item.isSelected = false; + } + } + const std::unordered_map& ReturnInventory() { return gInventoryMap; diff --git a/Inventory.h b/Inventory.h index 20bc5c7..655bcc7 100644 --- a/Inventory.h +++ b/Inventory.h @@ -17,7 +17,7 @@ namespace ZL }; // Глобальное хранилище предметов - extern std::unordered_map gInventory; + extern std::unordered_map gInventoryMap; // Changed from gInventory // Добавить предмет в инвентарь void AddItemToInventory(const std::string& name, std::shared_ptr tex, int hot_key); @@ -32,4 +32,8 @@ namespace ZL void PrintInventory(); const std::unordered_map& ReturnInventory(); + + // Add these new functions + void UnselectAllItems(); + InventoryItem* GetItemByHotkey(int hotkey); }