Added basic interactive interface highlighting and object identifying.

master
sigonasr2 11 months ago
parent b5f89875a3
commit 25a798cf7e
  1. 1
      TiledCollisionEditor/TSXParser.h
  2. 1
      TiledCollisionEditor/Tileset.h
  3. 43
      TiledCollisionEditor/main.cpp

@ -101,6 +101,7 @@ class TSXParser{
} }
if (newTag.tag=="tileset") { if (newTag.tag=="tileset") {
parsedTilesetInfo.tilecount=stoi(newTag.data["tilecount"]);
parsedTilesetInfo.tilewidth=stoi(newTag.data["tilewidth"]); parsedTilesetInfo.tilewidth=stoi(newTag.data["tilewidth"]);
parsedTilesetInfo.tileheight=stoi(newTag.data["tileheight"]); parsedTilesetInfo.tileheight=stoi(newTag.data["tileheight"]);
parsedTilesetInfo.columns=stoi(newTag.data["columns"]); parsedTilesetInfo.columns=stoi(newTag.data["columns"]);

@ -45,6 +45,7 @@ struct Tileset{
std::string filename; std::string filename;
std::unordered_map<std::string,TilesetObject>objects; std::unordered_map<std::string,TilesetObject>objects;
XMLTag ImageData; XMLTag ImageData;
int tilecount=0;
int tilewidth=0,tileheight=0; int tilewidth=0,tileheight=0;
int imagewidth=0,imageheight=0; int imagewidth=0,imageheight=0;
int columns=0; int columns=0;

@ -12,6 +12,7 @@ class TiledCollisionEditor : public olc::PixelGameEngine
{ {
std::unordered_map<std::string,Tileset>tilesets; std::unordered_map<std::string,Tileset>tilesets;
std::unordered_map<std::string,Renderable>images; std::unordered_map<std::string,Renderable>images;
std::string activeTileset;
public: public:
TiledCollisionEditor() TiledCollisionEditor()
@ -27,15 +28,53 @@ public:
Renderable&tilesetImg=images[tilesetFilename]; Renderable&tilesetImg=images[tilesetFilename];
tilesetImg.Load(TILESET_DIR+tileset.filename); tilesetImg.Load(TILESET_DIR+tileset.filename);
if(tilesets.size()==1)activeTileset=tilesetFilename;
return true; return true;
} }
bool OnUserUpdate(float fElapsedTime) override bool OnUserUpdate(float fElapsedTime) override
{ {
Clear(VERY_DARK_BLUE); Clear(VERY_DARK_BLUE);
for(auto&[tilesetName,tileset]:tilesets){
DrawDecal({0,0},images[tilesetName].Decal()); const Tileset&tileset=tilesets[activeTileset];
DrawDecal({0,0},images[activeTileset].Decal());
for(int y=0;y<tileset.tilecount/tileset.columns;y++){
for(int x=0;x<tileset.columns;x++){
DrawRectDecal(vf2d{float(x),float(y)}*tileset.tilewidth,vf2d{float(tileset.tilewidth),float(tileset.tileheight)},GREY);
}
} }
std::string selectedObj="";
for(auto&[objName,obj]:tileset.objects){
FillRectDecal(obj.bounds.pos,vf2d{2.f,float(obj.bounds.size.y)},YELLOW);
FillRectDecal(obj.bounds.pos,vf2d{float(obj.bounds.size.x),2},YELLOW);
FillRectDecal(obj.bounds.pos+obj.bounds.size,vf2d{-2.f,-float(obj.bounds.size.y)},YELLOW);
FillRectDecal(obj.bounds.pos+obj.bounds.size,vf2d{-float(obj.bounds.size.x),-2.f},YELLOW);
vi2d nameTextSize=GetTextSizeProp(objName)*0.25f;
GradientFillRectDecal(obj.bounds.pos,nameTextSize+vf2d{2,2},RED,{255,0,0,64},{255,0,0,64},RED);
DrawStringPropDecal(obj.bounds.pos+vf2d{1.25f,1.25f},objName,BLACK,vf2d{0.25f,0.25f});
DrawStringPropDecal(obj.bounds.pos+vf2d{1,1},objName,WHITE,vf2d{0.25f,0.25f});
if(geom2d::contains(obj.bounds,GetMousePos())){
selectedObj=objName;
}
}
if(selectedObj.length()>0){
for(int y=0;y<tileset.tilecount/tileset.columns;y++){
for(int x=0;x<tileset.columns;x++){
if(!geom2d::contains(tileset.objects.at(selectedObj).bounds,vf2d{float(x*tileset.tilewidth)+tileset.tilewidth/2,float(y*tileset.tileheight)+tileset.tileheight/2})){
FillRectDecal(vf2d{float(x),float(y)}*tileset.tilewidth,vf2d{float(tileset.tilewidth),float(tileset.tileheight)},{0,0,0,128});
}
}
}
}
return true; return true;
} }
}; };

Loading…
Cancel
Save