diff --git a/.gitignore b/.gitignore index 11cb6fc..d0e92d4 100755 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,8 @@ ## ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore +.vscode/ + # User-specific files *.rsuser *.suo diff --git a/GameObjectManager.cpp b/GameObjectManager.cpp index b1d53bf..81e5914 100644 --- a/GameObjectManager.cpp +++ b/GameObjectManager.cpp @@ -28,7 +28,7 @@ void GameObjectManager::initialize() { testObjMeshMutable.data = testObjMesh; testObjMeshMutable.RefreshVBO(); - textMesh = ZL::LoadFromTextFile("./textures/mesh_first_room.txt"); // Add ZL:: namespace + textMesh = ZL::LoadFromTextFile("./textures/mesh_first_room.txt"); textMesh.Scale(10); textMesh.SwapZandY(); textMesh.RotateByMatrix(QuatToMatrix(QuatFromRotateAroundX(M_PI * 0.5))); @@ -92,7 +92,7 @@ void GameObjectManager::initialize() { Room room_2; room_2.roomTexture = std::make_shared(CreateTextureDataFromBmp24("./background.bmp")); room_2.sound_name = "Symphony No.6 (1st movement).ogg"; - room_2.roomLogic = createRoom1Logic(); + room_2.roomLogic = createRoom2Logic(); rooms.push_back(room_2); activeObjects = rooms[current_room_index].objects; @@ -150,6 +150,10 @@ void GameObjectManager::handleEvent(const SDL_Event& event) { switch_room(1); } else if (event.type == SDL_MOUSEBUTTONDOWN) { + if (InventoryItem* item = GetItemSelected(true)) { + + } + else { const auto highlightedObjects = aoMgr.findByHighlighted(true); for (auto* ao : highlightedObjects) { @@ -162,6 +166,7 @@ void GameObjectManager::handleEvent(const SDL_Event& event) { aoMgr.removeByName(ao->name); } + } // bx.Interpolate(animationCounter); // animationCounter += 2; } @@ -254,14 +259,23 @@ void GameObjectManager::handleEvent(const SDL_Event& event) { case SDLK_1: case SDLK_2: - { - int hot_key = (event.key.keysym.sym == SDLK_1) ? 1 : 2; + case SDLK_3: + case SDLK_4: + case SDLK_5: + case SDLK_6: + case SDLK_7: + case SDLK_8: + case SDLK_9: + { + UnselectAllItems(); - if (InventoryItem* item = GetItemByHotkey(hot_key)) { + if (InventoryItem* item = GetItemByHotkey(event.key.keysym.sym - SDLK_1 + 1)) { item->isSelected = true; } } + break; + // ...handle other keys... } } @@ -454,12 +468,14 @@ void GameObjectManager::updateScene(size_t ms) { } bool GameObjectManager::isPointInObject(int screenX, int screenY, int objectScreenX, int objectScreenY) const { - // Простая проверка попадания точки в квадрат 64x64 вокруг центра объекта - const int objectSize = 32; // Половина размера области выделения - return (screenX >= objectScreenX - objectSize && - screenX <= objectScreenX + objectSize && - screenY >= objectScreenY - objectSize && - screenY <= objectScreenY + objectSize); + const int baseObjectSize = 32; // Base half-size + const float scale = 1.0f; // Get scale from item if needed + const int scaledObjectSize = static_cast(baseObjectSize * scale); + + return (screenX >= objectScreenX - scaledObjectSize && + screenX <= objectScreenX + scaledObjectSize && + screenY >= objectScreenY - scaledObjectSize && + screenY <= objectScreenY + scaledObjectSize); } void GameObjectManager::checkMouseIntersection(int mouseX, int mouseY, const Matrix4f& projectionModelView) { diff --git a/Inventory.cpp b/Inventory.cpp index 292cfb0..71af814 100644 --- a/Inventory.cpp +++ b/Inventory.cpp @@ -2,18 +2,22 @@ namespace ZL { - // Определяем глобальную переменную std::unordered_map gInventoryMap; - void AddItemToInventory(const std::string& name, std::shared_ptr tex, int hot_key) + void AddItemToInventory(const std::string& name, std::shared_ptr tex, int slot_index) { + if (slot_index > MAX_INVENTORY_SLOTS || slot_index < 1) { + return; + } + InventoryItem item; item.name = name; item.texture = tex; - item.hot_key = hot_key; + item.hot_key = slot_index; + item.scale = 1.0f; - // Вставляем или перезаписываем (operator[] так сделает). gInventoryMap[name] = item; + std::cout << "Added item to slot " << slot_index << std::endl; } void RemoveItemFromInventory(const std::string& name) @@ -22,7 +26,8 @@ namespace ZL gInventoryMap.erase(name); } - InventoryItem* GetItemByName(const std::string& name) + + InventoryItem* GetItemByName(const std::string name) { // Пытаемся найти элемент по ключу auto it = gInventoryMap.find(name); @@ -45,6 +50,16 @@ namespace ZL return nullptr; } + InventoryItem* GetItemSelected(bool selected) + { + for (auto& [_, item] : gInventoryMap) { + if (item.isSelected == selected) { + return &item; + } + } + return nullptr; + } + void PrintInventory() { std::cout << "Inventory contents:\n"; @@ -58,6 +73,7 @@ namespace ZL { for (auto& [_, item] : gInventoryMap) { item.isSelected = false; + item.scale = 1.0f; // Reset scale when unselected } } diff --git a/Inventory.h b/Inventory.h index 655bcc7..adea97e 100644 --- a/Inventory.h +++ b/Inventory.h @@ -8,25 +8,31 @@ namespace ZL { + static const int MAX_INVENTORY_SLOTS = 9; + static const float SELECTED_ITEM_SCALE = 1.2f; // Scale factor for selected items + struct InventoryItem { std::string name; std::shared_ptr texture; bool isSelected = false; int hot_key; + float scale = 1.0f; // Add scale property }; // Глобальное хранилище предметов - extern std::unordered_map gInventoryMap; // Changed from gInventory + extern std::unordered_map gInventoryMap; // Changed key type from string to int // Добавить предмет в инвентарь - void AddItemToInventory(const std::string& name, std::shared_ptr tex, int hot_key); + void AddItemToInventory(const std::string& name, std::shared_ptr tex, int slot_index); // Удалить предмет из инвентаря - void RemoveItemFromInventory(const std::string& name); + void RemoveItemFromInventory(int slot_index); - // Поиск предмета по имени (возвращает указатель или nullptr) - InventoryItem* GetItemByName(const std::string& name); + // Поиск предмета по индексу (возвращает указатель или nullptr) + InventoryItem* GetItemByHotkey(int hot_key); + InventoryItem* GetItemSelected(bool isSelected); + InventoryItem* GetItemByName(std::string name); // Вывести весь инвентарь в консоль void PrintInventory(); @@ -35,5 +41,4 @@ namespace ZL // Add these new functions void UnselectAllItems(); - InventoryItem* GetItemByHotkey(int hotkey); } diff --git a/QuestScripts.cpp b/QuestScripts.cpp index 321a6ff..7f9a009 100644 --- a/QuestScripts.cpp +++ b/QuestScripts.cpp @@ -19,4 +19,13 @@ namespace ZL }; } + std::function createRoom2Logic() + { + return [](GameObjectManager& gom, size_t ms) +// Simple test logic + { + + }; + } + } diff --git a/QuestScripts.h b/QuestScripts.h index bf7205b..dcdd1d0 100644 --- a/QuestScripts.h +++ b/QuestScripts.h @@ -5,5 +5,6 @@ namespace ZL { class GameObjectManager; std::function createRoom1Logic(); + std::function createRoom2Logic(); } diff --git a/RenderSystem.cpp b/RenderSystem.cpp index cc3c633..d53e6eb 100644 --- a/RenderSystem.cpp +++ b/RenderSystem.cpp @@ -234,15 +234,29 @@ void RenderSystem::drawUI(const GameObjectManager& gameObjects) { for (const auto& [name, item] : inventoryMap) { renderer.PushMatrix(); + if (item.isSelected) { + float xPos = Environment::width + - gameObjects.INVENTORY_MARGIN + - gameObjects.INVENTORY_ICON_SIZE+25; + float yPos = gameObjects.INVENTORY_MARGIN + + i * (gameObjects.INVENTORY_ICON_SIZE+25 + + gameObjects.INVENTORY_MARGIN); + renderer.TranslateMatrix(Vector3f{xPos, yPos, 0.0f}); + glBindTexture(GL_TEXTURE_2D, item.texture->getTexID()); + } + else { + float xPos = Environment::width - gameObjects.INVENTORY_MARGIN - gameObjects.INVENTORY_ICON_SIZE; float yPos = gameObjects.INVENTORY_MARGIN + i * (gameObjects.INVENTORY_ICON_SIZE + gameObjects.INVENTORY_MARGIN); - renderer.TranslateMatrix(Vector3f{xPos, yPos, 0.0f}); glBindTexture(GL_TEXTURE_2D, item.texture->getTexID()); + } + + renderer.DrawVertexRenderStruct(gameObjects.inventoryIconMeshMutable); renderer.PopMatrix(); diff --git a/defaultHideCam.fragment b/defaultHideCam.fragment index 06b9181..a10a442 100644 --- a/defaultHideCam.fragment +++ b/defaultHideCam.fragment @@ -7,33 +7,7 @@ uniform vec3 targetPos; // Цель камеры void main() { -/* - float maxDistance = 2000; - float alpha = 0.0; - vec4 color = texture2D(Texture, texCoord); - - vec3 dir = targetPos - eyePos; - float dirLengthSq = dot(dir, dir); - - if (dirLengthSq > 0.0) - { - vec3 objToEye = vWorldPos - eyePos; - float t = dot(objToEye, dir) / dirLengthSq; - - if (t >= 0.0 && t <= 1.0) - { - vec3 projection = eyePos + t * dir; - vec3 delta = vWorldPos - projection; - float distSq = dot(delta, delta); - - if (distSq < maxDistance * maxDistance) - { - //color.a *= alpha; // Применяем прозрачность - color.rgb = vec3(1,0,0); - } - } - } - */ + vec4 color; vec3 dirToCamera = normalize(eyePos - targetPos);