mirror of
https://github.com/devZoGok/PlanetFleet.git
synced 2026-08-26 19:43:29 +00:00
moved main minimap functionality to dedicated Minimap class
This commit is contained in:
@@ -18,104 +18,6 @@ namespace battleship{
|
||||
using namespace vb01;
|
||||
using namespace std;
|
||||
|
||||
MinimapButton::MinimapButton(Vector3 pos, Vector2 size, string ip) : Button(pos, size, "minimap", "", -1, true, ip){}
|
||||
|
||||
MinimapButton::~MinimapButton(){}
|
||||
|
||||
void MinimapButton::update(){
|
||||
Button::update();
|
||||
|
||||
Material *mat = rectNode->getMesh(0)->getMaterial();
|
||||
Texture *tex = ((Material::TextureUniform*)mat->getUniform("diffuseMap"))->value;
|
||||
ImageAsset *asset = (ImageAsset*)AssetManager::getSingleton()->getAsset(imagePath);
|
||||
int width = asset->width, height = asset->height, numChannels = asset->numChannels;
|
||||
|
||||
Map *map = Map::getSingleton();
|
||||
Vector3 mapSize = map->getMapSize();
|
||||
vector<pair<Unit*, Vector2>> unitMinimapPos;
|
||||
|
||||
for(Player *pl : Game::getSingleton()->getPlayers())
|
||||
for(Unit *un : pl->getUnits()){
|
||||
Vector2 coords = Vector2(
|
||||
int(un->getPos().x / mapSize.x * width),
|
||||
int(un->getPos().z / mapSize.z * height)
|
||||
);
|
||||
|
||||
unitMinimapPos.push_back(make_pair(un, coords));
|
||||
}
|
||||
|
||||
ActiveGameState *activeState = (ActiveGameState*)GameManager::getSingleton()->getStateManager()->getAppStateByType(AppStateType::ACTIVE_STATE);
|
||||
Player *mainPlayer = activeState->getPlayer();
|
||||
vector<Unit*> units = mainPlayer->getUnits();
|
||||
|
||||
int size = width * height * numChannels;
|
||||
int pxId = 0, numIter = 0;
|
||||
|
||||
u8 *oldImageData = map->getOldMinimapImage();
|
||||
int unitPxRadius = 1;
|
||||
|
||||
for(u8 *p = asset->image; p != asset->image + size; p += numChannels, pxId += numChannels, numIter++){
|
||||
Vector2 coords = Vector2(
|
||||
-(numIter % asset->width - .5 * asset->width),
|
||||
numIter / asset->width - .5 * asset->height
|
||||
);
|
||||
float losFactor = .6, pxCol[3]{
|
||||
losFactor * oldImageData[pxId + 0],
|
||||
losFactor * oldImageData[pxId + 1],
|
||||
losFactor * oldImageData[pxId + 2]
|
||||
};
|
||||
|
||||
for(pair<Unit*, Vector2> unitPair : unitMinimapPos){
|
||||
Vector2 coordDiff = unitPair.second - coords;
|
||||
|
||||
if(unitPair.first->getPlayer() == mainPlayer && fabs(coordDiff.x) <= unitPxRadius && fabs(coordDiff.y) <= unitPxRadius){
|
||||
Vector3 plCol = mainPlayer->getColor();
|
||||
pxCol[0] = plCol.x * 255;
|
||||
pxCol[1] = plCol.y * 255;
|
||||
pxCol[2] = plCol.z * 255;
|
||||
break;
|
||||
}
|
||||
|
||||
float minimapLos = unitPair.first->getLineOfSight() / mapSize.x * width;
|
||||
|
||||
if(unitPair.first->getPlayer() == mainPlayer && coords.getDistanceFrom(unitPair.second) < minimapLos){
|
||||
bool foreignUnit = false;
|
||||
Player *pl = nullptr;
|
||||
|
||||
for(pair<Unit*, Vector2> up : unitMinimapPos){
|
||||
Vector2 coordDiff = up.second - coords;
|
||||
|
||||
if(up.first->getPlayer() != mainPlayer && fabs(coordDiff.x) <= unitPxRadius && fabs(coordDiff.y) <= unitPxRadius){
|
||||
foreignUnit = true;
|
||||
pl = up.first->getPlayer();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(foreignUnit){
|
||||
Vector3 plCol = pl->getColor();
|
||||
pxCol[0] = plCol.x * 255;
|
||||
pxCol[1] = plCol.y * 255;
|
||||
pxCol[2] = plCol.z * 255;
|
||||
}
|
||||
else{
|
||||
pxCol[0] = oldImageData[pxId + 0];
|
||||
pxCol[1] = oldImageData[pxId + 1];
|
||||
pxCol[2] = oldImageData[pxId + 2];
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
*p = pxCol[0];
|
||||
*(p + 1) = pxCol[1];
|
||||
*(p + 2) = pxCol[2];
|
||||
}
|
||||
|
||||
tex->loadImageData(asset);
|
||||
}
|
||||
|
||||
void MinimapButton::onClick(){
|
||||
Vector2 clickPos = getCursorPos();
|
||||
float posXRatio = 1. - (clickPos.x - pos.x) / size.x;
|
||||
|
||||
Reference in New Issue
Block a user