added inventory logic
This commit is contained in:
parent
64ec35415c
commit
f5cf579115
39
Inventory.cpp
Normal file
39
Inventory.cpp
Normal file
@ -0,0 +1,39 @@
|
||||
#include "Inventory.h"
|
||||
#include <algorithm> // Для std::remove_if
|
||||
|
||||
namespace ZL
|
||||
{
|
||||
// Определяем глобальный инвентарь
|
||||
std::vector<InventoryItem> gInventory;
|
||||
|
||||
void AddItemToInventory(const std::string& name, std::shared_ptr<Texture> tex)
|
||||
{
|
||||
gInventory.push_back({ name, tex });
|
||||
}
|
||||
|
||||
void RemoveItemFromInventory(const std::string& name)
|
||||
{
|
||||
gInventory.erase(
|
||||
std::remove_if(gInventory.begin(), gInventory.end(),
|
||||
[&name](const InventoryItem& item) {
|
||||
return item.name == name;
|
||||
}),
|
||||
gInventory.end());
|
||||
}
|
||||
|
||||
void PrintInventory()
|
||||
{
|
||||
for (const auto& item : gInventory)
|
||||
{
|
||||
std::cout << "Item: " << item.name
|
||||
<< ", texture ID = "
|
||||
<< (item.texture ? item.texture->getTexID() : 0)
|
||||
<< std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
const std::vector<InventoryItem>& ReturnInventory()
|
||||
{
|
||||
return gInventory;
|
||||
}
|
||||
}
|
||||
32
Inventory.h
Normal file
32
Inventory.h
Normal file
@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include "TextureManager.h"
|
||||
|
||||
namespace ZL
|
||||
{
|
||||
// Структура, описывающая элемент инвентаря
|
||||
struct InventoryItem
|
||||
{
|
||||
std::string name;
|
||||
std::shared_ptr<Texture> texture;
|
||||
};
|
||||
|
||||
// Глобальный список инвентаря
|
||||
extern std::vector<InventoryItem> gInventory;
|
||||
|
||||
// Добавить предмет в инвентарь
|
||||
void AddItemToInventory(const std::string& name, std::shared_ptr<Texture> tex);
|
||||
|
||||
// Удалить предмет из инвентаря
|
||||
void RemoveItemFromInventory(const std::string& name);
|
||||
|
||||
// Вывести все предметы в инвентаре
|
||||
void PrintInventory();
|
||||
|
||||
// Получить список предметов инвентаря
|
||||
const std::vector<InventoryItem>& ReturnInventory();
|
||||
}
|
||||
26
main.cpp
26
main.cpp
@ -17,6 +17,9 @@
|
||||
#include "BoneAnimatedModel.h"
|
||||
#include "TextModel.h"
|
||||
|
||||
#include "Inventory.h"
|
||||
#include <memory>
|
||||
|
||||
namespace ZL
|
||||
{
|
||||
|
||||
@ -339,6 +342,23 @@ namespace ZL
|
||||
|
||||
|
||||
std::cout << "Hello test 5x" << std::endl;
|
||||
|
||||
// ТЕСТИРУЕМ ВЗАИМОДЕЙСТВИЕ С ИНВЕНТАРЕМ
|
||||
auto roomTexturePtr = std::make_shared<ZL::Texture>(ZL::CreateTextureDataFromBmp24("./Kitchen_ceramics.bmp"));
|
||||
auto coneTexturePtr = std::make_shared<ZL::Texture>(ZL::CreateTextureDataFromBmp24("./conus.bmp"));
|
||||
|
||||
// Добавляем предметы в инвентарь
|
||||
ZL::AddItemToInventory("RoomCeramics", roomTexturePtr);
|
||||
ZL::AddItemToInventory("Cone", coneTexturePtr);
|
||||
|
||||
std::cout << "Before removal:\n";
|
||||
ZL::PrintInventory();
|
||||
|
||||
// Удаляем "Cone" из инвентаря
|
||||
ZL::RemoveItemFromInventory("Cone");
|
||||
|
||||
std::cout << "\nAfter removal:\n";
|
||||
ZL::PrintInventory();
|
||||
}
|
||||
|
||||
void render() {
|
||||
@ -373,14 +393,14 @@ namespace ZL
|
||||
|
||||
static const float zoomstep = 1.0f;
|
||||
if (event.wheel.y > 0) {
|
||||
// Прокрутка вверх - увеличиваем zoom
|
||||
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> zoom
|
||||
Env::zoom -= zoomstep;
|
||||
}
|
||||
else if (event.wheel.y < 0) {
|
||||
// Прокрутка вниз - уменьшаем zoom
|
||||
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> zoom
|
||||
Env::zoom += zoomstep;
|
||||
}
|
||||
// Ограничиваем zoom, чтобы он не стал отрицательным
|
||||
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> zoom, <20><><EFBFBD><EFBFBD><EFBFBD> <20><> <20><> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if (Env::zoom < zoomstep) {
|
||||
Env::zoom = zoomstep;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user