Debug map toggle configuration paramater added. Added in tiled and scaled versions of interface 9-patch patterning.

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
pull/28/head
parent 17838ffb8b
commit bff7eabef5
  1. 60
      Crawler/Crawler.cpp
  2. 1
      Crawler/Crawler.h
  3. 79
      Crawler/Menu.cpp
  4. 6
      Crawler/Menu.h
  5. 13
      Crawler/TMXParser.h
  6. 11
      Crawler/TSXParser.h
  7. 3
      Crawler/assets/config/configuration.txt

@ -21,6 +21,7 @@
INCLUDE_EMITTER_LIST
bool _DEBUG_MAP_LOAD_INFO = false;
//360x240
vi2d WINDOW_SIZE={24*15,24*10};
safemap<std::string,Animate2D::FrameSequence>ANIMATION_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<Warrior>();
//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+"..."<<std::endl;
GFX[imgFile];
if(GFX[imgFile].Load("GFX_Prefix"_S+imgFile,nullptr,false,false)!=rcode::OK){
std::cout<<" WARNING! Failed to load "+imgFile+"!";
throw;
}
}
GFX.SetInitialized();
std::cout<<GFX.size()<<" images have been loaded."<<std::endl;
InitializeGraphics();
Menu::InitializeMenus();
@ -1680,4 +1666,42 @@ void Crawler::RenderMenu(){
if(Menu::stack.size()>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+"..."<<std::endl;
if(GFX[imgFile].Load("GFX_Prefix"_S+imgFile,nullptr,false,false)!=rcode::OK){
std::cout<<" WARNING! Failed to load "+imgFile+"!";
throw;
}
}
//Specifically split up the 9 patch image into multiple pieces.
Renderable&patchImg=GFX["GFX_Prefix"_S+"Images.GFX_9Patch"_S];
Pixel::Mode prevMode=GetPixelMode();
SetPixelMode(Pixel::Mode::MASK);
for(int x=0;x<3;x++){
for(int y=0;y<3;y++){
std::string patchKey="9patch_"+std::to_string(x)+std::to_string(y)+".png";
GFX[patchKey].Create("Interface.9PatchSize"_i[0],"Interface.9PatchSize"_i[1],false,false);
SetDrawTarget(GFX[patchKey].Sprite());
Clear(BLANK);
DrawPartialSprite({0,0},patchImg.Sprite(),{x*"Interface.9PatchSize"_i[0],y*"Interface.9PatchSize"_i[1]},{"Interface.9PatchSize"_i[0],"Interface.9PatchSize"_i[1]});
GFX[patchKey].Decal()->Update();
SetDrawTarget(nullptr);
}
}
SetPixelMode(prevMode);
GFX.SetInitialized();
std::cout<<GFX.size()<<" images have been loaded."<<std::endl;
}

@ -130,6 +130,7 @@ public:
void DisplayBossEncounterInfo();
void BossDamageDealt(int damage);
void ReduceBossEncounterMobCount();
void InitializeGraphics();
struct TileGroupData{
vi2d tilePos;

@ -75,26 +75,11 @@ void Menu::Update(Crawler*game){
void Menu::Draw(Crawler*game){
vf2d upperLeftPos=game->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"];
}

@ -16,12 +16,14 @@ class Menu{
std::map<int/*Y*/,std::vector<MenuComponent*>>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::vector<Menu*>stack;
@ -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);
};

@ -72,6 +72,7 @@ typedef std::map<std::string,std::vector<geom2d::rect<int>>> ZoneData;
#ifdef TMX_PARSER_SETUP
#undef TMX_PARSER_SETUP
extern bool _DEBUG_MAP_LOAD_INFO;
const std::string XMLTag::FormatTagData(std::map<std::string,std::string>tiles){
std::string displayStr="";
for (std::map<std::string,std::string>::iterator it=data.begin();it!=data.end();it++) {
@ -192,7 +193,7 @@ typedef std::map<std::string,std::vector<geom2d::rect<int>>> 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: "<<newTag.tag<<"\n";
if(_DEBUG_MAP_LOAD_INFO)std::cout<<"Tag: "<<newTag.tag<<"\n";
} else {
std::string key = data.substr(0,data.find("="));
std::string value = data.substr(data.find("=")+1,std::string::npos);
@ -202,7 +203,7 @@ typedef std::map<std::string,std::vector<geom2d::rect<int>>> ZoneData;
value = value.substr(0,value.length()-1);
newTag.data[key]=value;
std::cout<<" "<<key<<":"<<newTag.data[key]<<"\n";
if(_DEBUG_MAP_LOAD_INFO)std::cout<<" "<<key<<":"<<newTag.data[key]<<"\n";
}
}
}
@ -267,9 +268,9 @@ typedef std::map<std::string,std::vector<geom2d::rect<int>>> 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<std::string,std::vector<geom2d::rect<int>>> ZoneData;
}
if(infiniteMap){
std::cout<<"Infinite map detected. Parsing stopped early."<<std::endl;
if(_DEBUG_MAP_LOAD_INFO)std::cout<<"Infinite map detected. Parsing stopped early."<<std::endl;
}
for(XMLTag&monster:accumulatedMonsterTags){
@ -340,6 +341,6 @@ typedef std::map<std::string,std::vector<geom2d::rect<int>>> ZoneData;
std::sort(parsedMapInfo.TilesetData.begin(),parsedMapInfo.TilesetData.end(),[](XMLTag&t1,XMLTag&t2){return t1.GetInteger("firstgid")<t2.GetInteger("firstgid");});
std::cout<<"Parsed Map Data:\n"<<parsedMapInfo<<"\n";
if(_DEBUG_MAP_LOAD_INFO)std::cout<<"Parsed Map Data:\n"<<parsedMapInfo<<"\n";
}
#endif

@ -34,6 +34,7 @@ class TSXParser{
#ifdef TSX_PARSER_SETUP
#undef TSX_PARSER_SETUP
extern bool _DEBUG_MAP_LOAD_INFO;
Tileset&TSXParser::GetData() {
return parsedTilesetInfo;
}
@ -73,7 +74,7 @@ class TSXParser{
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: "<<newTag.tag<<"\n";
if(_DEBUG_MAP_LOAD_INFO)std::cout<<"Tag: "<<newTag.tag<<"\n";
} else {
std::string key = data.substr(0,data.find("="));
std::string value = data.substr(data.find("=")+1,std::string::npos);
@ -83,7 +84,7 @@ class TSXParser{
value = value.substr(0,value.length()-1);
newTag.data[key]=value;
std::cout<<" "<<key<<":"<<newTag.data[key]<<"\n";
if(_DEBUG_MAP_LOAD_INFO)std::cout<<" "<<key<<":"<<newTag.data[key]<<"\n";
}
}
}
@ -129,12 +130,12 @@ class TSXParser{
TileCollisionData data;
data.collision=geom2d::rect<int>{{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 "<<previousTagID<<"!"<<std::endl;
if(_DEBUG_MAP_LOAD_INFO)std::cout<<"WARNING! There was already collision data defined for tile "<<previousTagID<<"!"<<std::endl;
throw;
}
parsedTilesetInfo.CollisionData[previousTagID]=data;
}
std::cout<<"\n"<<"=============\n";
if(_DEBUG_MAP_LOAD_INFO)std::cout<<"\n"<<"=============\n";
}
TSXParser::TSXParser(std::string file)
:previousTagID(-1){
@ -167,6 +168,6 @@ class TSXParser{
}
}
std::cout<<"Parsed Tileset Data:\n"<<parsedTilesetInfo<<"\n";
if(_DEBUG_MAP_LOAD_INFO)std::cout<<"Parsed Tileset Data:\n"<<parsedTilesetInfo<<"\n";
}
#endif

@ -36,6 +36,9 @@ class_list = Warrior, Thief, Ranger, Trapper, Wizard, Witch
# Whether or not to show individual data accesses from config data structure.
debug_access_options = 0
# Shows map loading output
debug_map_load_info = 0
# Shows extra info about the player on the HUD
debug_player_info = 0

Loading…
Cancel
Save