Merge pull request #18 from mephi1984/pavel

Pavel
This commit is contained in:
Pavel Makarov 2025-03-02 16:49:50 +06:00 committed by GitHub
commit ebc63e6663
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 35 additions and 5 deletions

View File

@ -7,12 +7,13 @@
namespace ZL { namespace ZL {
const float GameObjectManager::INVENTORY_ICON_SIZE = 32.0f; const float GameObjectManager::INVENTORY_ICON_SIZE = 64.0f;
const float GameObjectManager::INVENTORY_MARGIN = 10.0f; const float GameObjectManager::INVENTORY_MARGIN = 10.0f;
void GameObjectManager::initialize() { void GameObjectManager::initialize() {
current_room_index = 0; current_room_index = 0;
objects_in_inventory = 0;
coneTexturePtr = std::make_shared<Texture>(CreateTextureDataFromBmp24("./conus.bmp")); coneTexturePtr = std::make_shared<Texture>(CreateTextureDataFromBmp24("./conus.bmp"));
@ -104,7 +105,7 @@ void GameObjectManager::initialize() {
// Initialize inventory // Initialize inventory
inventoryIconMesh = CreateRect2D( inventoryIconMesh = CreateRect2D(
{0.0f, 0.0f}, {0.0f, 40.0f},
{INVENTORY_ICON_SIZE/2, INVENTORY_ICON_SIZE/2}, {INVENTORY_ICON_SIZE/2, INVENTORY_ICON_SIZE/2},
0.5f 0.5f
); );
@ -150,7 +151,8 @@ void GameObjectManager::handleEvent(const SDL_Event& event) {
continue; continue;
} }
AddItemToInventory(ao->name, ao->activeObjectTexturePtr); AddItemToInventory(ao->name, ao->activeObjectTexturePtr, objects_in_inventory+1);
objects_in_inventory++;
aoMgr.removeByName(ao->name); aoMgr.removeByName(ao->name);
} }
@ -239,6 +241,30 @@ void GameObjectManager::handleEvent(const SDL_Event& event) {
Environment::violaLastWalkFrame = -1; Environment::violaLastWalkFrame = -1;
} }
break; 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... // ...handle other keys...
} }
} }

View File

@ -55,6 +55,7 @@ public:
static const float INVENTORY_ICON_SIZE; static const float INVENTORY_ICON_SIZE;
static const float INVENTORY_MARGIN; static const float INVENTORY_MARGIN;
ActiveObjectManager aoMgr; ActiveObjectManager aoMgr;
int objects_in_inventory;
private: private:
//int animationCounter = 0; //int animationCounter = 0;

View File

@ -5,11 +5,12 @@ namespace ZL
// Определяем глобальную переменную // Определяем глобальную переменную
std::unordered_map<std::string, InventoryItem> gInventoryMap; std::unordered_map<std::string, InventoryItem> gInventoryMap;
void AddItemToInventory(const std::string& name, std::shared_ptr<Texture> tex) void AddItemToInventory(const std::string& name, std::shared_ptr<Texture> tex, int hot_key)
{ {
InventoryItem item; InventoryItem item;
item.name = name; item.name = name;
item.texture = tex; item.texture = tex;
item.hot_key = hot_key;
// Вставляем или перезаписываем (operator[] так сделает). // Вставляем или перезаписываем (operator[] так сделает).
gInventoryMap[name] = item; gInventoryMap[name] = item;

View File

@ -12,13 +12,15 @@ namespace ZL
{ {
std::string name; std::string name;
std::shared_ptr<Texture> texture; std::shared_ptr<Texture> texture;
bool isSelected = false;
int hot_key;
}; };
// Глобальное хранилище предметов // Глобальное хранилище предметов
extern std::unordered_map<std::string, InventoryItem> gInventory; extern std::unordered_map<std::string, InventoryItem> gInventory;
// Добавить предмет в инвентарь // Добавить предмет в инвентарь
void AddItemToInventory(const std::string& name, std::shared_ptr<Texture> tex); void AddItemToInventory(const std::string& name, std::shared_ptr<Texture> tex, int hot_key);
// Удалить предмет из инвентаря // Удалить предмет из инвентаря
void RemoveItemFromInventory(const std::string& name); void RemoveItemFromInventory(const std::string& name);