commit
37f0a6aa08
7
.vscode/settings.json
vendored
7
.vscode/settings.json
vendored
@ -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"
|
||||
}
|
||||
}
|
||||
@ -114,6 +114,12 @@ void GameObjectManager::initialize() {
|
||||
|
||||
roomTexturePtr = rooms[current_room_index].roomTexture;
|
||||
|
||||
AddItemToInventory("book1", std::make_shared<Texture>(CreateTextureDataFromBmp24("./Kitchen_ceramics.bmp")), objects_in_inventory+1);
|
||||
objects_in_inventory++;
|
||||
AddItemToInventory("book2", std::make_shared<Texture>(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...
|
||||
}
|
||||
}
|
||||
|
||||
@ -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<std::string, InventoryItem>& ReturnInventory()
|
||||
{
|
||||
return gInventoryMap;
|
||||
|
||||
@ -17,7 +17,7 @@ namespace ZL
|
||||
};
|
||||
|
||||
// Глобальное хранилище предметов
|
||||
extern std::unordered_map<std::string, InventoryItem> gInventory;
|
||||
extern std::unordered_map<std::string, InventoryItem> gInventoryMap; // Changed from gInventory
|
||||
|
||||
// Добавить предмет в инвентарь
|
||||
void AddItemToInventory(const std::string& name, std::shared_ptr<Texture> tex, int hot_key);
|
||||
@ -32,4 +32,8 @@ namespace ZL
|
||||
void PrintInventory();
|
||||
|
||||
const std::unordered_map<std::string, InventoryItem>& ReturnInventory();
|
||||
|
||||
// Add these new functions
|
||||
void UnselectAllItems();
|
||||
InventoryItem* GetItemByHotkey(int hotkey);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user