From bff7eabef59fcf36d0e620d5308419976b7a820f Mon Sep 17 00:00:00 2001 From: "sigonasr2, Sig, Sigo" Date: Mon, 2 Oct 2023 19:54:21 +0000 Subject: [PATCH] Debug map toggle configuration paramater added. Added in tiled and scaled versions of interface 9-patch patterning. Co-authored-by: sigonasr2 --- Crawler/Crawler.cpp | 60 +++++++++++++------ Crawler/Crawler.h | 1 + Crawler/Menu.cpp | 79 ++++++++++++++++++------- Crawler/Menu.h | 6 ++ Crawler/TMXParser.h | 13 ++-- Crawler/TSXParser.h | 11 ++-- Crawler/assets/config/configuration.txt | 3 + 7 files changed, 124 insertions(+), 49 deletions(-) diff --git a/Crawler/Crawler.cpp b/Crawler/Crawler.cpp index a4fca346..5365149d 100644 --- a/Crawler/Crawler.cpp +++ b/Crawler/Crawler.cpp @@ -21,6 +21,7 @@ INCLUDE_EMITTER_LIST +bool _DEBUG_MAP_LOAD_INFO = false; //360x240 vi2d WINDOW_SIZE={24*15,24*10}; safemapANIMATION_DATA; @@ -47,6 +48,8 @@ Crawler::Crawler() utils::datafile::Read(DATA,"assets/config/configuration.txt"); + _DEBUG_MAP_LOAD_INFO=bool("debug_map_load_info"_I); + std::string CONFIG_PATH = "config_path"_S; std::string GFX_CONFIG = CONFIG_PATH + "gfx_config"_S; @@ -78,12 +81,6 @@ bool Crawler::OnUserCreate(){ InitializeDefaultKeybinds(); InitializeLevels(); - circleCooldownPoints.push_back({0,0}); - for(int i=0;i<=360;i+=4){ - float angle=util::degToRad(i)-PI/2; - circleCooldownPoints.push_back(vf2d{cos(angle),sin(angle)}); - } - player=std::make_unique(); //Initialize Camera. @@ -93,18 +90,7 @@ bool Crawler::OnUserCreate(){ camera.SetWorldBoundary({0,0},WORLD_SIZE*24); camera.EnableWorldBoundary(false); - for(auto&val:DATA["Images"].GetKeys()){ - std::string key=val.first; - std::string imgFile=DATA["Images"][key].GetString(); - std::cout<<"Loading image "+imgFile+"..."<0){ Menu::stack.back()->Draw(this); } +} + +void Crawler::InitializeGraphics(){ + circleCooldownPoints.push_back({0,0}); + for(int i=0;i<=360;i+=4){ + float angle=util::degToRad(i)-PI/2; + circleCooldownPoints.push_back(vf2d{cos(angle),sin(angle)}); + } + + for(auto&val:DATA["Images"].GetKeys()){ + std::string key=val.first; + std::string imgFile=DATA["Images"][key].GetString(); + std::cout<<"Loading image "+imgFile+"..."<Update(); + SetDrawTarget(nullptr); + } + } + SetPixelMode(prevMode); + + GFX.SetInitialized(); + std::cout<GetScreenSize()/2-size/2; - vf2d patchSize=vf2d{float("Interface.9PatchSize"_i[0]),float("Interface.9PatchSize"_i[1])}; - - //Upper-Left - game->DrawPartialDecal(upperLeftPos-patchSize,patchSize,GFX["9patch.png"].Decal(),{patchSize.x*0,patchSize.y*0},patchSize); - //Upper-Right - game->DrawPartialDecal(upperLeftPos+vf2d{size.x,-patchSize.y},patchSize,GFX["9patch.png"].Decal(),{patchSize.x*2,patchSize.y*0},patchSize); - //Bottom-Left - game->DrawPartialDecal(upperLeftPos+vf2d{-patchSize.x,size.y},patchSize,GFX["9patch.png"].Decal(),{patchSize.x*0,patchSize.y*2},patchSize); - //Bottom-Right - game->DrawPartialDecal(upperLeftPos+vf2d{size.x,size.y},patchSize,GFX["9patch.png"].Decal(),{patchSize.x*2,patchSize.y*2},patchSize); - //Top - game->DrawPartialDecal(upperLeftPos+vf2d{0,-patchSize.y},patchSize+vf2d{size.x,0},GFX["9patch.png"].Decal(),{patchSize.x*1,patchSize.y*0},patchSize); - //Left - game->DrawPartialDecal(upperLeftPos+vf2d{-patchSize.x,0},patchSize+vf2d{0,size.y},GFX["9patch.png"].Decal(),{patchSize.x*0,patchSize.y*1},patchSize); - //Right - game->DrawPartialDecal(upperLeftPos+vf2d{size.x,0},patchSize+vf2d{0,size.y},GFX["9patch.png"].Decal(),{patchSize.x*2,patchSize.y*1},patchSize); - //Bottom - game->DrawPartialDecal(upperLeftPos+vf2d{0,size.y},patchSize+vf2d{size.x,0},GFX["9patch.png"].Decal(),{patchSize.x*1,patchSize.y*2},patchSize); - //Center - game->DrawPartialDecal(upperLeftPos,patchSize+size,GFX["9patch.png"].Decal(),{patchSize.x*1,patchSize.y*1},patchSize); + if(scaled){ + DrawScaledWindow(game,upperLeftPos); + }else{ + DrawTiledWindow(game,upperLeftPos); + } for(auto&key:buttons){ for(auto&button:key.second){ @@ -234,4 +219,58 @@ void Menu::KeyboardButtonNavigation(Crawler*game,vf2d menuPos){ MenuSelect(game); } } +} + +void Menu::SetScaledPatchBorder(bool scaled){ + this->scaled=scaled; +} + +void Menu::DrawScaledWindow(Crawler*game,vf2d menuPos){ + vf2d patchSize={"Interface.9PatchSize"_f[0],"Interface.9PatchSize"_f[1]}; + + //Upper-Left + game->DrawPartialDecal(menuPos-patchSize,patchSize,GFX["9patch.png"].Decal(),{patchSize.x*0,patchSize.y*0},patchSize); + //Upper-Right + game->DrawPartialDecal(menuPos+vf2d{size.x,-patchSize.y},patchSize,GFX["9patch.png"].Decal(),{patchSize.x*2,patchSize.y*0},patchSize); + //Bottom-Left + game->DrawPartialDecal(menuPos+vf2d{-patchSize.x,size.y},patchSize,GFX["9patch.png"].Decal(),{patchSize.x*0,patchSize.y*2},patchSize); + //Bottom-Right + game->DrawPartialDecal(menuPos+vf2d{size.x,size.y},patchSize,GFX["9patch.png"].Decal(),{patchSize.x*2,patchSize.y*2},patchSize); + //Top + game->DrawPartialDecal(menuPos+vf2d{0,-patchSize.y},vf2d{size.x,patchSize.y},GFX["9patch.png"].Decal(),{patchSize.x*1,patchSize.y*0},patchSize); + //Left + game->DrawPartialDecal(menuPos+vf2d{-patchSize.x,0},vf2d{patchSize.x,size.y},GFX["9patch.png"].Decal(),{patchSize.x*0,patchSize.y*1},patchSize); + //Right + game->DrawPartialDecal(menuPos+vf2d{size.x,0},vf2d{patchSize.x,size.y},GFX["9patch.png"].Decal(),{patchSize.x*2,patchSize.y*1},patchSize); + //Bottom + game->DrawPartialDecal(menuPos+vf2d{0,size.y},vf2d{size.x,patchSize.y},GFX["9patch.png"].Decal(),{patchSize.x*1,patchSize.y*2},patchSize); + //Center + game->DrawPartialDecal(menuPos,size,GFX["9patch.png"].Decal(),{patchSize.x*1,patchSize.y*1},patchSize); +} + +void Menu::DrawTiledWindow(Crawler*game,vf2d menuPos){ + vf2d patchSize={"Interface.9PatchSize"_f[0],"Interface.9PatchSize"_f[1]}; + + //Upper-Left + game->DrawPartialDecal(menuPos-patchSize,patchSize,GetPatchPart(0,0).Decal(),{0,0},patchSize); + //Upper-Right + game->DrawPartialDecal(menuPos+vf2d{size.x,-patchSize.y},patchSize,GetPatchPart(2,0).Decal(),{0,0},patchSize); + //Bottom-Left + game->DrawPartialDecal(menuPos+vf2d{-patchSize.x,size.y},patchSize,GetPatchPart(0,2).Decal(),{0,0},patchSize); + //Bottom-Right + game->DrawPartialDecal(menuPos+vf2d{size.x,size.y},patchSize,GetPatchPart(2,2).Decal(),{0,0},patchSize); + //Top + game->DrawPartialDecal(menuPos+vf2d{0,-patchSize.y},vf2d{size.x,patchSize.y},GetPatchPart(1,0).Decal(),{0,0},vf2d{size.x,patchSize.y}); + //Left + game->DrawPartialDecal(menuPos+vf2d{-patchSize.x,0},vf2d{patchSize.x,size.y},GetPatchPart(0,1).Decal(),{0,0},vf2d{patchSize.x,size.y}); + //Right + game->DrawPartialDecal(menuPos+vf2d{size.x,0},vf2d{patchSize.x,size.y},GetPatchPart(2,1).Decal(),{0,0},vf2d{patchSize.x,size.y}); + //Bottom + game->DrawPartialDecal(menuPos+vf2d{0,size.y},vf2d{size.x,patchSize.y},GetPatchPart(1,2).Decal(),{0,0},vf2d{size.x,patchSize.y}); + //Center + game->DrawPartialDecal(menuPos,size,GetPatchPart(1,1).Decal(),{0,0},patchSize); +} + +Renderable&Menu::GetPatchPart(int x,int y){ + return GFX["9patch_"+std::to_string(x)+std::to_string(y)+".png"]; } \ No newline at end of file diff --git a/Crawler/Menu.h b/Crawler/Menu.h index d30acf05..8b2626cb 100644 --- a/Crawler/Menu.h +++ b/Crawler/Menu.h @@ -16,12 +16,14 @@ class Menu{ std::map>buttons; //Buttons are stored in rows followed by their column order. vi2d selection={-1,-1}; vf2d size; //Size in tiles (24x24), every menu will be tile-based + bool scaled=false; //Whether or not the patch border is supposed to be scaled or tiled. public: Menu(); Menu(vf2d size); void AddComponent(MenuComponent*button); void Update(Crawler*game); void Draw(Crawler*game); + void SetScaledPatchBorder(bool scaled); static void InitializeMenus(); static void OpenMenu(MenuType menu); static std::vectorstack; @@ -29,7 +31,11 @@ private: void MenuSelect(Crawler*game); static const Menu InitializeTestMenu(); static const Menu InitializeTestSubMenu(); + //X (0-3), Y (0-2) for specific 9-patch tile (tiled version). + static Renderable&GetPatchPart(int x,int y); void KeyboardButtonNavigation(Crawler*game,vf2d menuPos); + void DrawScaledWindow(Crawler*game,vf2d menuPos); + void DrawTiledWindow(Crawler*game,vf2d menuPos); }; diff --git a/Crawler/TMXParser.h b/Crawler/TMXParser.h index 9834fdb4..e47d9ddc 100644 --- a/Crawler/TMXParser.h +++ b/Crawler/TMXParser.h @@ -72,6 +72,7 @@ typedef std::map>> ZoneData; #ifdef TMX_PARSER_SETUP #undef TMX_PARSER_SETUP + extern bool _DEBUG_MAP_LOAD_INFO; const std::string XMLTag::FormatTagData(std::maptiles){ std::string displayStr=""; for (std::map::iterator it=data.begin();it!=data.end();it++) { @@ -192,7 +193,7 @@ typedef std::map>> ZoneData; if(valid&&data.length()>0){ if (newTag.tag.length()==0) { //Tag's empty, so first line is the tag. newTag.tag=data; - std::cout<<"Tag: "<>> ZoneData; value = value.substr(0,value.length()-1); newTag.data[key]=value; - std::cout<<" "<>> ZoneData; accumulatedMonsterTags.push_back(monsterTag); monsterPropertyTagCount=-1; } else { - std::cout<<"Unsupported tag format! Ignoring."<<"\n"; + if(_DEBUG_MAP_LOAD_INFO)std::cout<<"Unsupported tag format! Ignoring."<<"\n"; } - std::cout<<"\n"<<"=============\n"; + if(_DEBUG_MAP_LOAD_INFO)std::cout<<"\n"<<"=============\n"; } TMXParser::TMXParser(std::string file){ std::ifstream f(file,std::ios::in); @@ -314,7 +315,7 @@ typedef std::map>> ZoneData; } if(infiniteMap){ - std::cout<<"Infinite map detected. Parsing stopped early."<>> ZoneData; std::sort(parsedMapInfo.TilesetData.begin(),parsedMapInfo.TilesetData.end(),[](XMLTag&t1,XMLTag&t2){return t1.GetInteger("firstgid")0){ if (newTag.tag.length()==0) { //Tag's empty, so first line is the tag. newTag.tag=data; - std::cout<<"Tag: "<{{newTag.GetInteger("x"),newTag.GetInteger("y")},{newTag.GetInteger("width"),newTag.GetInteger("height")}}; if(parsedTilesetInfo.CollisionData.count(previousTagID)){ - std::cout<<"WARNING! There was already collision data defined for tile "<