mirror of
https://github.com/ApfelTeeSaft/PlanetFleet.git
synced 2026-08-26 19:33:38 +00:00
camera icon on the minimap
This commit is contained in:
@@ -42,39 +42,14 @@ namespace battleship{
|
|||||||
|
|
||||||
//TODO remove icon path literal
|
//TODO remove icon path literal
|
||||||
Map::Minimap::Minimap(){
|
Map::Minimap::Minimap(){
|
||||||
Root *root = Root::getSingleton();
|
string basePath = GameManager::getSingleton()->getPath() + "Textures/Icons/";
|
||||||
|
string iconPath = basePath + "Resources/refinedsMinimap.png";
|
||||||
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("texturingEnabled", true);
|
|
||||||
mat->addTexUniform("diffuseMap", tex, false);
|
|
||||||
|
|
||||||
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"]);
|
|
||||||
|
|
||||||
for(Player *pl : Game::getSingleton()->getPlayers())
|
for(Player *pl : Game::getSingleton()->getPlayers())
|
||||||
for(ResourceDeposit *rd : pl->getResourceDeposits()){
|
for(ResourceDeposit *rd : pl->getResourceDeposits())
|
||||||
Vector3 pos = rd->getPos(), mapSize = Map::getSingleton()->getMapSize();
|
depositIcons.push_back(initIcon(rd->getPos(), basePath + "Resources/refinedsMinimap.png"));
|
||||||
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);
|
camIcon = initIcon(Root::getSingleton()->getCamera()->getPosition(), basePath + "Resources/refinedsMinimap.png");
|
||||||
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(){
|
Map::Minimap::~Minimap(){
|
||||||
@@ -84,6 +59,41 @@ namespace battleship{
|
|||||||
}
|
}
|
||||||
|
|
||||||
depositIcons.clear();
|
depositIcons.clear();
|
||||||
|
|
||||||
|
delete camIcon;
|
||||||
|
}
|
||||||
|
|
||||||
|
Node* Map::Minimap::initIcon(Vector3 posOnMap, string iconPath){
|
||||||
|
string p[]{iconPath};
|
||||||
|
ImageAsset *asset = (ImageAsset*)AssetManager::getSingleton()->getAsset(iconPath);
|
||||||
|
Vector3 iconSize = Vector3(asset->width, asset->height, 0);
|
||||||
|
Texture *tex = new Texture(p, 1, false);
|
||||||
|
|
||||||
|
Root *root = Root::getSingleton();
|
||||||
|
Material *mat = new Material(root->getLibPath() + "gui");
|
||||||
|
mat->addBoolUniform("texturingEnabled", true);
|
||||||
|
mat->addTexUniform("diffuseMap", tex, false);
|
||||||
|
|
||||||
|
sol::state_view SOL_LUA_VIEW = generateView();
|
||||||
|
SOL_LUA_VIEW.script_file(GameManager::getSingleton()->getPath() + "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"]);
|
||||||
|
|
||||||
|
Vector3 mapSize = Map::getSingleton()->getMapSize();
|
||||||
|
Vector2 iconPos = Vector2(
|
||||||
|
minimapSize.x * (posOnMap.x + .5 * mapSize.x) / mapSize.x,
|
||||||
|
minimapSize.y * (posOnMap.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);
|
||||||
|
root->getGuiNode()->attachChild(node);
|
||||||
|
|
||||||
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Map::Minimap::updateImage(Button *minimapButton){
|
void Map::Minimap::updateImage(Button *minimapButton){
|
||||||
@@ -177,11 +187,21 @@ namespace battleship{
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Map::Minimap::updateCamFrame(Button *minimapButton){
|
void Map::Minimap::updateCamFrame(Button *minimapButton){
|
||||||
|
Vector3 camPos = Root::getSingleton()->getCamera()->getPosition();
|
||||||
|
Vector3 mapSize = Map::getSingleton()->getMapSize();
|
||||||
|
Vector2 minimapSize = minimapButton->getSize();
|
||||||
|
Vector2 iconPos = Vector2(
|
||||||
|
minimapSize.x * (camPos.x + .5 * mapSize.x) / mapSize.x,
|
||||||
|
minimapSize.y * (camPos.z + .5 * mapSize.z) / mapSize.z
|
||||||
|
);
|
||||||
|
|
||||||
|
camIcon->setPosition(minimapButton->getPos() + Vector3(iconPos.x, iconPos.y, .1));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Map::Minimap::update(){
|
void Map::Minimap::update(){
|
||||||
Button *mb = ConcreteGuiManager::getSingleton()->getButton("minimap");
|
Button *mb = ConcreteGuiManager::getSingleton()->getButton("minimap");
|
||||||
updateImage(mb);
|
updateImage(mb);
|
||||||
|
updateCamFrame(mb);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Map::Minimap::load(){
|
void Map::Minimap::load(){
|
||||||
|
|||||||
@@ -55,12 +55,14 @@ namespace battleship{
|
|||||||
inline vb01::u8* getOldMinimapImage(){return oldImageData;}
|
inline vb01::u8* getOldMinimapImage(){return oldImageData;}
|
||||||
private:
|
private:
|
||||||
Minimap();
|
Minimap();
|
||||||
|
vb01::Node* initIcon(vb01::Vector3, std::string);
|
||||||
void updateCamFrame(vb01Gui::Button*);
|
void updateCamFrame(vb01Gui::Button*);
|
||||||
void updateImage(vb01Gui::Button*);
|
void updateImage(vb01Gui::Button*);
|
||||||
|
|
||||||
vb01::u8 *oldImageData = nullptr;
|
vb01::u8 *oldImageData = nullptr;
|
||||||
vb01::Node *camFrame = nullptr;
|
vb01::Node *camFrame = nullptr;
|
||||||
std::vector<vb01::Node*> depositIcons;
|
std::vector<vb01::Node*> depositIcons;
|
||||||
|
vb01::Node* camIcon = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
static Map* getSingleton();
|
static Map* getSingleton();
|
||||||
|
|||||||
Reference in New Issue
Block a user