From c41d9f863fb49315e0adf45022ec3ec00db2c457 Mon Sep 17 00:00:00 2001 From: devZoGok Date: Wed, 25 Sep 2024 20:37:41 +0300 Subject: [PATCH] resource deposit icon placement on the minimap --- Assets/Scripts/Gui/activeGameState.lua | 3 +- map.cpp | 55 ++++++++++++++++++++------ map.h | 3 +- 3 files changed, 47 insertions(+), 14 deletions(-) diff --git a/Assets/Scripts/Gui/activeGameState.lua b/Assets/Scripts/Gui/activeGameState.lua index 9e7ce9d..ea65374 100644 --- a/Assets/Scripts/Gui/activeGameState.lua +++ b/Assets/Scripts/Gui/activeGameState.lua @@ -3,6 +3,7 @@ Size = {x = 70, y = 70} sz = 210 s = 40 minimapSize = {x = 200, y = 200} +minimapPos = {x = res.x - minimapSize.x, y = 0, z = .9} resTextScale = {x = .5, y = .5} resIconBasePath = 'Icons/Resources/' pointerTex = 'pointer.png' @@ -14,7 +15,7 @@ gui = { guiType = GuiType.BUTTON, buttonType = ButtonType.MINIMAP, name = 'minimap', - pos = {x = res.x - minimapSize.x, y = 0, z = .9}, + pos = minimapPos, size = minimapSize, color = {x = .5, y = .5, z = .5, w = 1} }, diff --git a/map.cpp b/map.cpp index bbe16ec..086e45c 100755 --- a/map.cpp +++ b/map.cpp @@ -18,6 +18,7 @@ #include "pathfinder.h" #include "gameManager.h" #include "defConfigs.h" +#include "resourceDeposit.h" #include "activeGameState.h" #include "concreteGuiManager.h" #include "gameObjectFactory.h" @@ -39,21 +40,50 @@ namespace battleship{ return minimap; } + //TODO remove icon path literal Map::Minimap::Minimap(){ Root *root = Root::getSingleton(); + string path = GameManager::getSingleton()->getPath(), iconPath = path + "Textures/Icons/Resources/refinedsMinimap.png", p[]{iconPath}; + ImageAsset *asset = (ImageAsset*)AssetManager::getSingleton()->getAsset(iconPath); + Vector3 iconSize = Vector3(asset->width, asset->height, 0); + Texture *tex = new Texture(p, 1, false); + Material *mat = new Material(root->getLibPath() + "gui"); - mat->addBoolUniform("lightingEnabled", false); - mat->addBoolUniform("texturingEnabled", false); - mat->addVec4Uniform("diffuseColor", Vector4(0, 0, 0, 1)); + mat->addBoolUniform("texturingEnabled", true); + mat->addTexUniform("diffuseMap", tex, false); - Quad *mesh = new Quad(Vector3(50, 50, 0), false); - mesh->setMaterial(mat); - mesh->setWireframe(true); + sol::state_view SOL_LUA_VIEW = generateView(); + SOL_LUA_VIEW.script_file(path + "Scripts/Gui/activeGameState.lua"); + sol::table posTbl = SOL_LUA_VIEW["minimapPos"], sizeTbl = SOL_LUA_VIEW["minimapSize"]; + Vector2 minimapSize = Vector2(sizeTbl["x"], sizeTbl["y"]); + Vector3 minimapPos = Vector3(posTbl["x"], posTbl["y"], posTbl["z"]); - camFrame = new Node(); - camFrame->attachMesh(mesh); - root->getGuiNode()->attachChild(camFrame); + for(Player *pl : Game::getSingleton()->getPlayers()) + for(ResourceDeposit *rd : pl->getResourceDeposits()){ + Vector3 pos = rd->getPos(), mapSize = Map::getSingleton()->getMapSize(); + Vector2 iconPos = Vector2( + minimapSize.x * (pos.x + .5 * mapSize.x) / mapSize.x, + minimapSize.y * (pos.z + .5 * mapSize.z) / mapSize.z + ); + + Quad *quad = new Quad(iconSize, false); + quad->setMaterial(mat); + + Node *node = new Node(minimapPos + Vector3(iconPos.x, iconPos.y, .1) - .5 * iconSize); + node->attachMesh(quad); + depositIcons.push_back(node); + root->getGuiNode()->attachChild(node); + } + } + + Map::Minimap::~Minimap(){ + for(Node *node : depositIcons){ + Root::getSingleton()->getGuiNode()->dettachChild(node); + delete node; + } + + depositIcons.clear(); } void Map::Minimap::updateImage(Button *minimapButton){ @@ -152,7 +182,6 @@ namespace battleship{ void Map::Minimap::update(){ Button *mb = ConcreteGuiManager::getSingleton()->getButton("minimap"); updateImage(mb); - updateCamFrame(mb); } void Map::Minimap::load(){ @@ -331,6 +360,7 @@ namespace battleship{ } } + //TODO move minimap loading elsewhere void Map::loadPlayerGameObjects(){ AssetManager *assetManager = AssetManager::getSingleton(); string path = GameManager::getSingleton()->getPath(); @@ -340,7 +370,6 @@ namespace battleship{ string vfxPrefix = SOL_LUA_VIEW["vfxPrefix"], gameObjPrefix = SOL_LUA_VIEW["gameObjPrefix"]; assetManager->load(path + vfxPrefix, true); assetManager->load(path + gameObjPrefix, true); - assetManager->load(path + "Textures/", true); string playerInd = "players"; SOL_LUA_VIEW.script("numPlayers = #" + mapTable + "." + playerInd); @@ -385,6 +414,8 @@ namespace battleship{ player->addUnit(GameObjectFactory::createUnit(player, id, pos, rot, buildStatus)); } } + + Minimap::getSingleton()->load(); } void Map::preprareScene(bool empty){ @@ -465,12 +496,12 @@ namespace battleship{ Pathfinder::getSingleton()->setImpassibleNodeVal(u16(0 - 1)); string path = GameManager::getSingleton()->getPath(); + AssetManager::getSingleton()->load(path + "Textures/", true); sol::state_view SOL_LUA_STATE = generateView(); SOL_LUA_STATE.script_file(path + "Models/Maps/" + mapName + "/" + mapName + ".lua"); preprareScene(false); - Minimap::getSingleton()->load(); loadSpawnPoints(); loadSkybox(); loadCells(); diff --git a/map.h b/map.h index 7bf7329..e48a88f 100755 --- a/map.h +++ b/map.h @@ -48,7 +48,7 @@ namespace battleship{ class Minimap{ public: static Minimap* getSingleton(); - ~Minimap(){} + ~Minimap(); void update(); void load(); void unload(); @@ -60,6 +60,7 @@ namespace battleship{ vb01::u8 *oldImageData = nullptr; vb01::Node *camFrame = nullptr; + std::vector depositIcons; }; static Map* getSingleton();