void cMiniMap::draw(EE::Vec2 &pos) {
if (!guiLoaded) loadGui();
if (hidden) return;
if ((*minusButton)()) {
radius *= 1 + Time.d();
if (radius > 150) radius = 150;
}
if ((*plusButton)()) {
radius /= 1 + Time.d();
if (radius < 10) radius = 10;
}
_time32(&time);
_localtime32_s(&newtime, &time);
EE::Str t = S + newtime.tm_hour + ":";
if (newtime.tm_min < 10) {
t += "0";
}
t += S + newtime.tm_min;
timeText->set(t);
Vec2 worldMin = pos - radius,
worldMax = pos + radius;
Vec2 imageMin = Game::World.mini_map.worldToImage(worldMin),
imageMax = Game::World.mini_map.worldToImage(worldMax),
imageCenter = Game::World.mini_map.worldToImage(pos );
VecI2 imageMini = Floor(imageMin),
imageMaxi = Floor(imageMax);
Vec2 imageSize = rect.size() / (imageMax - imageMin);
// iterate through all image maps to be displayed
for (Int y = imageMini.y; y <= imageMaxi.y; y++) {
for (Int x = imageMini.x; x <= imageMaxi.x; x++) {
// calculate screen position of the (x,y) image map
Vec2 imagePos = rect.center() - imageCenter * imageSize;
imagePos.x += x * imageSize.x;
imagePos.y += y * imageSize.y;
// prepare the screen rectangle of the (x, y) image map
Rect_LD map_image_rect(imagePos, imageSize.x, imageSize.y);
// draw image
Image &image = Game::World.mini_map(VecI2(x, y));
if (image.is()) {
image.drawMask(WHITE, Color(0, 0, 0, 0), map_image_rect, *Images("gfx/mini map alpha.gfx"), rect);
}
}
}
Flt angle = 0.0;
if (Peers.elms()) {
Peers.lock();
// show other players
for (int x = 0; x < Peers.elms(); x++) {
Vec2 pos2d = Peers.lockedData(x).pos().xz();
// only draw if within range
if (Dist(pos, pos2d) < (radius * 0.8)) {
// set overlay color
Color add = Peers.lockedData(x).color;
add.a = 0;
// maximum distance on screen in pixels
VecI2 lu = D.screenToPixel(rect.lu());
VecI2 ru = D.screenToPixel(rect.ru());
VecI2 ld = D.screenToPixel(rect.ld());
VecI2 maxDist;
maxDist.x = Abs(ru.x - lu.x) * 0.5;
maxDist.y = Abs(ld.y - lu.y) * 0.5;
// peer position towards player
Vec2 peerPos = pos2d - pos;
// normalize with radius and maximum screen distance
peerPos /= radius;
peerPos *= maxDist;
// reverse y position for screen coördinates
peerPos.y = -peerPos.y;
// get center of rectangle in pixels
VecI2 center;
center = D.screenToPixel(rect.center());
// offset to minimap center
peerPos += center;
// convert back to screen position format
Vec2 p2 = D.pixelToScreen(peerPos);
Peers.lockedData(x).mapDot.drawCenter(Peers.lockedData(x).color, add, p2.x, p2.y, 0.03, 0.03);
}
}
Peers.unlock();
}
if (Players.elms()) {
// show player direction on top
angle = Players[0].angle.x;
pointer.drawRotate(rect.center(), 0.05 ,0.05, angle);
}
}