diff --git a/Adventures in Lestoria/AdventuresInLestoria.cpp b/Adventures in Lestoria/AdventuresInLestoria.cpp index 2f8bd0dc..a7cf7a92 100644 --- a/Adventures in Lestoria/AdventuresInLestoria.cpp +++ b/Adventures in Lestoria/AdventuresInLestoria.cpp @@ -81,6 +81,7 @@ All rights reserved. #include "Tutorial.h" #include "SteamKeyboardCallbackHandler.h" #include "SteamStatsReceivedHandler.h" +#include "StageMaskPolygon.h" INCLUDE_EMITTER_LIST INCLUDE_ITEM_CATEGORIES @@ -970,6 +971,19 @@ void AiL::RenderWorld(float fElapsedTime){ PopulateRenderLists(); auto RenderPlayer=[&](vf2d pos,vf2d scale){ + SetWorldColor(PixelLerp(DARK_BLUE,BLACK,sin(geom2d::pi*GetRunTime()*2))); + if(GetCurrentMapData().provideOptimization&&!LoadingScreen::loading){ + StageMaskPolygon poly{ + { + view.ScreenToWorld(GetMousePos()-vf2d{50,50}), + view.ScreenToWorld(GetMousePos()+vf2d{100,-20}), + view.ScreenToWorld(GetMousePos()+vf2d{200,200}), + view.ScreenToWorld(GetMousePos()+vf2d{-50,150}), + view.ScreenToWorld(GetMousePos()+vf2d{-120,90}), + },"safeIndicatorGradient.png",PixelLerp(VERY_DARK_BLUE,BLACK,sin(geom2d::pi*GetRunTime()*2)) + }; + poly.Draw(); + } if(player->IsInvisible())return; vf2d playerScale=vf2d(player->GetSizeMult(),player->GetSizeMult()); int count=0; diff --git a/Adventures in Lestoria/StageMaskPolygon.cpp b/Adventures in Lestoria/StageMaskPolygon.cpp index c133687d..b4af9031 100644 --- a/Adventures in Lestoria/StageMaskPolygon.cpp +++ b/Adventures in Lestoria/StageMaskPolygon.cpp @@ -40,35 +40,64 @@ All rights reserved. #include "AdventuresInLestoria.h" #include "DEFINES.h" #include "LoadingScreen.h" +#include "util.h" INCLUDE_game +INCLUDE_GFX -StageMaskPolygon::StageMaskPolygon(const std::vector&points,const std::optionalstageMaskOverlay) -:polygon(geom2d::polygon{points}),overlay{stageMaskOverlay}{ +StageMaskPolygon::StageMaskPolygon(const std::vector&points,const std::string&texture,const Pixel overlayCol) +:polygon(geom2d::polygon{points}){ if(LoadingScreen::loading)ERR("WARNING! A stage mask overlay attempted to initialize itself before the stage finished! THIS IS NOT ALLOWED!"); if(!game->MAP_DATA.at(game->GetCurrentMapName()).GetOptimizedMap())ERR(std::format("WARNING! No optimized map found for stage {} while trying to create a Stage Polygon! THIS IS NOT ALLOWED!",game->GetCurrentMapName())); - std::transform(points.begin(),points.end(),std::back_inserter(uvs),[&](const vf2d&point){return game->view.ScreenToWorld(point)/game->GetCurrentMap().GetOptimizedMap()->Sprite()->Size();}); + if(texture.length()>0)overlay=StageMaskPolygon::StageMaskOverlay{points,texture,overlayCol}; + + std::transform(points.begin(),points.end(),std::back_inserter(uvs.pos),[&](const vf2d&point){return point/game->GetCurrentMap().GetOptimizedMap()->Sprite()->Size();}); } -StageMaskOverlay::StageMaskOverlay(const std::vector&points,const Pixel overlayCol,const float blendScale) -:overlayPolygon(geom2d::polygon{points}),overlayCol(overlayCol),blendScale(blendScale){ - std::transform(points.begin(),points.end(),std::back_inserter(overlayUVs),[&](const vf2d&point){return game->view.ScreenToWorld(point)/game->GetCurrentMap().GetOptimizedMap()->Sprite()->Size();}); +StageMaskPolygon::StageMaskOverlay::StageMaskOverlay(const std::vector&points,const std::string&texture,const Pixel overlayCol) +:overlayPolygon(geom2d::polygon{points}),texture(texture),overlayCol(overlayCol){ + if(!GFX.count(texture))ERR(std::format("WARNING! Texture {} does not exist while trying to initialize Stage Mask Overlay!",texture)); + + overlayPolygon.pos.insert(overlayPolygon.pos.begin(),overlayPolygon.middle()); //Insert the middle point to the front of the overlay polygon's point list. + //Copy the first point provided from the original polygon to the end of the new overlay polygon since we have to fully connect the polygon for the texture to show up correctly. + overlayPolygon.pos.push_back(points[0]); + bool first=false; + std::transform(overlayPolygon.pos.begin(),overlayPolygon.pos.end(),std::back_inserter(overlayUVs.pos),[&](const vf2d&point){ + if(!first){ + first=true; + return vf2d{0.f,0.f}; + }else{ + return vf2d{1.f,1.f}; + } + }); } -const Pixel StageMaskOverlay::GetColor()const{ +const Pixel StageMaskPolygon::StageMaskOverlay::GetColor()const{ return overlayCol; } -const float StageMaskOverlay::GetScale()const{ - return blendScale; -} -const geom2d::polygon&StageMaskOverlay::GetPolygon()const{ +const geom2d::polygon&StageMaskPolygon::StageMaskOverlay::GetPolygon()const{ return overlayPolygon; } +void StageMaskPolygon::StageMaskOverlay::Draw()const{ + game->view.DrawPolygonDecal(GFX.at(texture).Decal(),overlayPolygon.pos,overlayUVs.pos,GetColor()); +} + +const bool StageMaskPolygon::HasOverlay()const{ + return overlay.has_value(); +} + +void StageMaskPolygon::SetBlendColor(const Pixel overlayCol){ + if(!HasOverlay())ERR("WARNING! Trying to set the blend color when there is no overlay on this stage mask polygon! THIS IS NOT ALLOWED!"); + overlay.value().overlayCol=overlayCol; +} + +const StageMaskPolygon::StageMaskOverlay&StageMaskPolygon::GetOverlay()const{ + return overlay.value(); +} + void StageMaskPolygon::Draw()const{ - game->DrawPolygonDecal(game->GetCurrentMap().GetOptimizedMap()->Decal(),points,uvs); - game->SetDecalMode(DecalMode::WIREFRAME); - game->DrawPolygonDecal(nullptr,points,uvs,RED); - game->SetDecalMode(DecalMode::NORMAL); + game->view.DrawPolygonDecal(game->GetCurrentMap().GetOptimizedMap()->Decal(),polygon.pos,uvs.pos); + if(HasOverlay())GetOverlay().Draw(); } \ No newline at end of file diff --git a/Adventures in Lestoria/StageMaskPolygon.h b/Adventures in Lestoria/StageMaskPolygon.h index d67446a5..bb38cde2 100644 --- a/Adventures in Lestoria/StageMaskPolygon.h +++ b/Adventures in Lestoria/StageMaskPolygon.h @@ -40,24 +40,25 @@ All rights reserved. #include "Pixel.h" #include "olcUTIL_Geometry2D.h" -class StageMaskOverlay{ - friend class StageMaskPolygon; -private: - StageMaskOverlay(const std::vector&points,const Pixel overlayCol=BLANK,const float blendScale=0.f); - const Pixel GetColor()const; - const float GetScale()const; - const geom2d::polygon&GetPolygon()const; - geom2d::polygonoverlayPolygon; - geom2d::polygonoverlayUVs; - Pixel overlayCol; - //The entire overlay is replicated to also be at a smaller (or larger) blend scale size that interpolates from 1.0 on the outer edge towards 0.0 of the overlayCol to the blendScale. - //As an example, if blendScale is 0.6, then from 1.0 to 0.6x size of the shape from the outer edge the overlayCol will be lerped from 1.0 to 0.0 to the 0.6x size version of the shape. - float blendScale; -}; - class StageMaskPolygon{ + class StageMaskOverlay{ + friend class StageMaskPolygon; + private: + //The stage mask overlay auto-forms a UV mapping where the center is {0,0} and the edges are {1,1}. Use this to shape a texture with the desired outline you want. + StageMaskOverlay(const std::vector&points,const std::string&texture,const Pixel overlayCol=BLANK); + const Pixel GetColor()const; + const geom2d::polygon&GetPolygon()const; + void Draw()const; + std::string texture; + geom2d::polygonoverlayPolygon; //The overlay polygon uses a middle point so that a texture can fade in towards the center. + geom2d::polygonoverlayUVs; + Pixel overlayCol; + }; public: - StageMaskPolygon(const std::vector&points,const std::optionalstageMaskOverlay={}); + StageMaskPolygon(const std::vector&points,const std::string&texture="",const Pixel overlayCol=BLANK); + void SetBlendColor(const Pixel overlayCol); + const bool HasOverlay()const; + const StageMaskOverlay&GetOverlay()const; void Draw()const; private: geom2d::polygonpolygon; diff --git a/Adventures in Lestoria/Version.h b/Adventures in Lestoria/Version.h index ce746c7d..0bb93c6e 100644 --- a/Adventures in Lestoria/Version.h +++ b/Adventures in Lestoria/Version.h @@ -39,7 +39,7 @@ All rights reserved. #define VERSION_MAJOR 1 #define VERSION_MINOR 2 #define VERSION_PATCH 3 -#define VERSION_BUILD 9561 +#define VERSION_BUILD 9572 #define stringify(a) stringify_(a) #define stringify_(a) #a diff --git a/Adventures in Lestoria/assets/config/gfx/gfx.txt b/Adventures in Lestoria/assets/config/gfx/gfx.txt index 573ca531..063e7490 100644 --- a/Adventures in Lestoria/assets/config/gfx/gfx.txt +++ b/Adventures in Lestoria/assets/config/gfx/gfx.txt @@ -104,6 +104,7 @@ Images GFX_Wind2 = wind2.png GFX_WindObjects = commercial_assets/wind_solid_objects.png GFX_LargeTornado = large_tornado.png + GFX_SafeAreaIndicator = safeIndicatorGradient.png # Ability Icons GFX_Warrior_BattleCry_Icon = Ability Icons/battlecry.png diff --git a/Adventures in Lestoria/assets/gamepack.pak b/Adventures in Lestoria/assets/gamepack.pak index b6a2da21..7c9abd65 100644 Binary files a/Adventures in Lestoria/assets/gamepack.pak and b/Adventures in Lestoria/assets/gamepack.pak differ diff --git a/Adventures in Lestoria/assets/safeIndicatorGradient.png b/Adventures in Lestoria/assets/safeIndicatorGradient.png new file mode 100644 index 00000000..d107442c Binary files /dev/null and b/Adventures in Lestoria/assets/safeIndicatorGradient.png differ diff --git a/Adventures in Lestoria/olcUTIL_Geometry2D.h b/Adventures in Lestoria/olcUTIL_Geometry2D.h index 70823457..8b05b2e8 100644 --- a/Adventures in Lestoria/olcUTIL_Geometry2D.h +++ b/Adventures in Lestoria/olcUTIL_Geometry2D.h @@ -190,6 +190,7 @@ #include #include #include +#include #ifndef OLC_V2D_TYPE #define OLC_V2D_TYPE @@ -784,6 +785,11 @@ namespace olc::utils::geom2d struct polygon { std::vector> pos; + + inline constexpr olc::v_2dmiddle()const{ + vf2d total=std::accumulate(pos.begin(),pos.end(),olc::v_2d{},[](const olc::v_2d&middle,const olc::v_2d&point){return std::move(middle)+point;}); + return total/pos.size(); + } }; diff --git a/x64/Release/Adventures in Lestoria.exe b/x64/Release/Adventures in Lestoria.exe index c85230ed..799d0f9e 100644 Binary files a/x64/Release/Adventures in Lestoria.exe and b/x64/Release/Adventures in Lestoria.exe differ