@ -53,17 +53,27 @@ void Minimap::Initialize(){
}
}
mapCircleHud = ViewPort { enlargedCircle , vi2d { game - > ScreenWidth ( ) - " Minimap.Minimap HUD Size " _I - 4 , 4 } } ;
mapCircleHud = ViewPort { enlargedCircle , vi2d { game - > ScreenWidth ( ) - " Minimap.Minimap HUD Size " _I - 4 , 4 } } ;
enlargedCircle . clear ( ) ;
for ( int i = 360 ; i > = 0 ; i - = 4 ) {
float angle = util : : degToRad ( float ( i ) ) - PI / 2 ;
if ( i = = 360 ) { enlargedCircle . push_back ( vf2d { cos ( angle ) , sin ( angle ) } * game - > ScreenWidth ( ) / 3 + game - > ScreenWidth ( ) / 3 ) ; }
enlargedCircle . push_back ( vf2d { cos ( angle ) , sin ( angle ) } * game - > ScreenWidth ( ) / 3 + game - > ScreenWidth ( ) / 3 ) ;
}
mapCircleLargeHud = ViewPort { enlargedCircle , vi2d { game - > ScreenWidth ( ) / 2 - game - > ScreenWidth ( ) / 3 , game - > ScreenHeight ( ) / 2 - game - > ScreenWidth ( ) / 3 } } ;
}
}
void Minimap : : Reset ( ) {
void Minimap : : Reset ( ) {
if ( minimap . Sprite ( ) = = nullptr ) minimap . Create ( 1 , 1 ) ;
if ( minimap . Sprite ( ) = = nullptr ) minimap . Create ( 1 , 1 ) ;
if ( cover . Sprite ( ) = = nullptr ) cover . Create ( 1 , 1 ) ;
if ( cover . Sprite ( ) = = nullptr ) cover . Create ( 1 , 1 ) ;
if ( coverOutline . Sprite ( ) = = nullptr ) coverOutline . Create ( 1 , 1 ) ;
Sprite baseMinimap ;
Sprite baseMinimap ;
# pragma region Cleanup minimap and cover images
# pragma region Cleanup minimap and cover images
minimap . Sprite ( ) - > Resize ( game - > GetCurrentMapData ( ) . width , game - > GetCurrentMapData ( ) . height ) ;
minimap . Sprite ( ) - > Resize ( game - > GetCurrentMapData ( ) . width , game - > GetCurrentMapData ( ) . height ) ;
cover . Sprite ( ) - > Resize ( game - > GetCurrentMapData ( ) . width , game - > GetCurrentMapData ( ) . height ) ;
cover . Sprite ( ) - > Resize ( game - > GetCurrentMapData ( ) . width , game - > GetCurrentMapData ( ) . height ) ;
coverOutline . Sprite ( ) - > Resize ( game - > GetCurrentMapData ( ) . width , game - > GetCurrentMapData ( ) . height ) ;
baseMinimap . Resize ( game - > GetCurrentMapData ( ) . width , game - > GetCurrentMapData ( ) . height ) ;
baseMinimap . Resize ( game - > GetCurrentMapData ( ) . width , game - > GetCurrentMapData ( ) . height ) ;
game - > SetDrawTarget ( minimap . Sprite ( ) ) ;
game - > SetDrawTarget ( minimap . Sprite ( ) ) ;
game - > SetPixelMode ( Pixel : : ALPHA ) ;
game - > SetPixelMode ( Pixel : : ALPHA ) ;
@ -72,6 +82,8 @@ void Minimap::Reset(){
game - > Clear ( BLANK ) ;
game - > Clear ( BLANK ) ;
game - > SetDrawTarget ( cover . Sprite ( ) ) ;
game - > SetDrawTarget ( cover . Sprite ( ) ) ;
game - > Clear ( BLANK ) ;
game - > Clear ( BLANK ) ;
game - > SetDrawTarget ( coverOutline . Sprite ( ) ) ;
game - > Clear ( BLANK ) ;
game - > SetPixelMode ( Pixel : : NORMAL ) ;
game - > SetPixelMode ( Pixel : : NORMAL ) ;
//Will update the minimap decal at the end, since we are about to change it anyways.
//Will update the minimap decal at the end, since we are about to change it anyways.
cover . Decal ( ) - > Update ( ) ;
cover . Decal ( ) - > Update ( ) ;
@ -124,6 +136,19 @@ void Minimap::Reset(){
}
}
}
}
}
}
if ( game - > GetZones ( ) . count ( " EndZone " ) ) {
for ( const ZoneData & zone : game - > GetZones ( ) . at ( " EndZone " ) ) {
vf2d ringPos = zone . zone . pos / game - > GetCurrentMapData ( ) . TileSize ;
vf2d ringSize = zone . zone . size / game - > GetCurrentMapData ( ) . TileSize ;
for ( int y = 0 ; y < = ringSize . y ; y + + ) {
for ( int x = 0 ; x < = ringSize . x ; x + + ) {
minimap . Sprite ( ) - > SetPixel ( ringPos + vi2d { x , y } , GREEN ) ;
}
}
}
}
game - > SetDrawTarget ( nullptr ) ;
game - > SetDrawTarget ( nullptr ) ;
minimap . Decal ( ) - > Update ( ) ;
minimap . Decal ( ) - > Update ( ) ;
@ -137,7 +162,11 @@ void Minimap::Reset(){
}
}
void Minimap : : Update ( ) {
void Minimap : : Update ( ) {
if ( game - > KEY_TOGGLE_MAP . Pressed ( ) ) {
if ( displayMode = = MinimapMode : : SMALL ) displayMode = MinimapMode : : LARGE ;
else if ( displayMode = = MinimapMode : : LARGE ) displayMode = MinimapMode : : OFF ;
else if ( displayMode = = MinimapMode : : OFF ) displayMode = MinimapMode : : SMALL ;
}
}
}
void Minimap : : UpdateChunk ( const MapName map , const vi2d chunkPos ) {
void Minimap : : UpdateChunk ( const MapName map , const vi2d chunkPos ) {
@ -153,11 +182,15 @@ void Minimap::UpdateChunk(const MapName map,const vi2d chunkPos){
//We start twice the distance we are supposed to outwards.
//We start twice the distance we are supposed to outwards.
for ( int y = pixelPos . y ; y < chunkEndPixelPos . y ; y + + ) {
for ( int y = pixelPos . y ; y < chunkEndPixelPos . y ; y + + ) {
for ( int x = pixelPos . x ; x < chunkEndPixelPos . x ; x + + ) {
for ( int x = pixelPos . x ; x < chunkEndPixelPos . x ; x + + ) {
if ( cover . Sprite ( ) - > GetPixel ( x , y ) . a = = 255 | | minimap . Sprite ( ) - > GetPixel ( x , y ) . a = = 0 ) continue ; //Already revealed or invisible anyways.
Pixel sourceCol = minimap . Sprite ( ) - > GetPixel ( x , y ) ;
bool sourceWasBlack = sourceCol = = BLACK ;
if ( cover . Sprite ( ) - > GetPixel ( x , y ) . a = = 255 | | sourceCol . a = = 0 ) continue ; //Already revealed or invisible anyways.
vi2d chunk = vi2d { x , y } / " Minimap.Chunk Size " _I ;
vi2d chunk = vi2d { x , y } / " Minimap.Chunk Size " _I ;
if ( chunk = = chunkPos ) {
if ( chunk = = chunkPos ) {
cover . Sprite ( ) - > SetPixel ( x , y , minimap . Sprite ( ) - > GetPixel ( x , y ) ) ;
cover . Sprite ( ) - > SetPixel ( x , y , sourceCol ) ;
if ( sourceWasBlack ) coverOutline . Sprite ( ) - > SetPixel ( x , y , sourceCol ) ;
} else {
} else {
const vi2d chunkOffset = { " Minimap.Chunk Size " _I / 2 , " Minimap.Chunk Size " _I / 2 } ;
const vi2d chunkOffset = { " Minimap.Chunk Size " _I / 2 , " Minimap.Chunk Size " _I / 2 } ;
@ -166,21 +199,32 @@ void Minimap::UpdateChunk(const MapName map,const vi2d chunkPos){
if ( cover . Sprite ( ) - > GetPixel ( x , y ) . a > alpha ) continue ; //The distance was uncovered by another closer chunk, don't need to reveal it here.
if ( cover . Sprite ( ) - > GetPixel ( x , y ) . a > alpha ) continue ; //The distance was uncovered by another closer chunk, don't need to reveal it here.
Pixel sourceCol = minimap . Sprite ( ) - > GetPixel ( x , y ) ;
sourceCol . a = alpha ;
sourceCol . a = alpha ;
cover . Sprite ( ) - > SetPixel ( x , y , sourceCol ) ;
cover . Sprite ( ) - > SetPixel ( x , y , sourceCol ) ;
if ( sourceWasBlack ) coverOutline . Sprite ( ) - > SetPixel ( x , y , sourceCol ) ;
}
}
}
}
}
}
cover . Decal ( ) - > Update ( ) ;
cover . Decal ( ) - > Update ( ) ;
coverOutline . Decal ( ) - > Update ( ) ;
}
}
void Minimap : : Draw ( ) {
void Minimap : : Draw ( ) {
const vf2d minimapPos = vf2d { float ( " Minimap.Minimap HUD Size " _I ) , float ( " Minimap.Minimap HUD Size " _I ) } / 2 ;
const vf2d minimapPos = vf2d { float ( " Minimap.Minimap HUD Size " _I ) , float ( " Minimap.Minimap HUD Size " _I ) } / 2 ;
if ( ! game - > InBossEncounter ( ) ) mapCircleHud . DrawRotatedDecal ( minimapPos , cover . Decal ( ) , 0.f , game - > GetPlayer ( ) - > GetPos ( ) / game - > GetCurrentMapData ( ) . tilewidth , vf2d { 0.5f , 0.5f } ) ;
if ( ! game - > InBossEncounter ( ) ) {
game - > DrawRotatedDecal ( mapCircleHud . GetOffset ( ) + minimapPos , GFX [ " skill_overlay_icon.png " ] . Decal ( ) , 0.f , GFX [ " skill_overlay_icon.png " ] . Sprite ( ) - > Size ( ) / 2 , vf2d { float ( " Minimap.Minimap HUD Size " _I ) , float ( " Minimap.Minimap HUD Size " _I ) } / 24.f * 1.05f ) ;
switch ( displayMode ) {
game - > DrawRotatedDecal ( mapCircleHud . GetOffset ( ) + minimapPos , game - > GetPlayer ( ) - > GetMinimapImage ( ) . Decal ( ) , 0.f , vi2d { " Player.Minimap Image Size " _i [ 0 ] , " Player.Minimap Image Size " _i [ 1 ] } / 2 , { 0.5f , 0.5f } ) ;
case MinimapMode : : SMALL : {
mapCircleHud . DrawRotatedDecal ( minimapPos , cover . Decal ( ) , 0.f , game - > camera . GetPosition ( ) / game - > GetCurrentMapData ( ) . tilewidth , vf2d { 0.5f , 0.5f } ) ;
game - > DrawRotatedDecal ( mapCircleHud . GetOffset ( ) + minimapPos , GFX [ " skill_overlay_icon.png " ] . Decal ( ) , 0.f , GFX [ " skill_overlay_icon.png " ] . Sprite ( ) - > Size ( ) / 2 , vf2d { float ( " Minimap.Minimap HUD Size " _I ) , float ( " Minimap.Minimap HUD Size " _I ) } / 24.f * 1.05f ) ;
game - > DrawRotatedDecal ( mapCircleHud . GetOffset ( ) + minimapPos , game - > GetPlayer ( ) - > GetMinimapImage ( ) . Decal ( ) , 0.f , vi2d { " Player.Minimap Image Size " _i [ 0 ] , " Player.Minimap Image Size " _i [ 1 ] } / 2 , { 0.5f , 0.5f } ) ;
} break ;
case MinimapMode : : LARGE : {
mapCircleLargeHud . DrawRotatedDecal ( vf2d { game - > ScreenWidth ( ) / 3.f , game - > ScreenWidth ( ) / 3.f } , coverOutline . Decal ( ) , 0.f , game - > camera . GetPosition ( ) / game - > GetCurrentMapData ( ) . tilewidth , vf2d { 2.f , 2.f } , { 255 , 255 , 255 , 48 } ) ;
} break ;
case MinimapMode : : OFF : { } break ;
}
}
}
}
void Minimap : : EraseChunkData ( ) {
void Minimap : : EraseChunkData ( ) {
@ -189,4 +233,12 @@ void Minimap::EraseChunkData(){
const std : : unordered_map < MapName , std : : unordered_set < std : : string > > & Minimap : : GetChunkData ( ) {
const std : : unordered_map < MapName , std : : unordered_set < std : : string > > & Minimap : : GetChunkData ( ) {
return loadedChunks ;
return loadedChunks ;
}
const MinimapMode & Minimap : : GetMinimapMode ( ) const {
return displayMode ;
}
void Minimap : : SetMinimapMode ( MinimapMode newMode ) {
displayMode = newMode ;
}
}