|
|
|
@ -18,6 +18,8 @@ class TiledCollisionEditor : public olc::PixelGameEngine |
|
|
|
|
std::string selectedObj=""; |
|
|
|
|
int editingPoint=4; //Which point we are editing (0-3.)
|
|
|
|
|
|
|
|
|
|
TransformedView view; |
|
|
|
|
|
|
|
|
|
public: |
|
|
|
|
TiledCollisionEditor() |
|
|
|
|
{ |
|
|
|
@ -43,13 +45,15 @@ public: |
|
|
|
|
{ |
|
|
|
|
Clear(VERY_DARK_BLUE); |
|
|
|
|
|
|
|
|
|
view.HandlePanAndZoom(); |
|
|
|
|
|
|
|
|
|
const Tileset&tileset=tilesets[activeTileset]; |
|
|
|
|
|
|
|
|
|
DrawDecal({0,0},images[activeTileset].Decal()); |
|
|
|
|
view.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); |
|
|
|
|
view.DrawRectDecal(vf2d{float(x),float(y)}*tileset.tilewidth,vf2d{float(tileset.tilewidth),float(tileset.tileheight)},GREY); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -58,15 +62,15 @@ public: |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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); |
|
|
|
|
view.FillRectDecal(obj.bounds.pos,vf2d{2.f,float(obj.bounds.size.y)},YELLOW); |
|
|
|
|
view.FillRectDecal(obj.bounds.pos,vf2d{float(obj.bounds.size.x),2},YELLOW); |
|
|
|
|
view.FillRectDecal(obj.bounds.pos+obj.bounds.size,vf2d{-2.f,-float(obj.bounds.size.y)},YELLOW); |
|
|
|
|
view.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}); |
|
|
|
|
view.GradientFillRectDecal(obj.bounds.pos,nameTextSize+vf2d{2,2},RED,{255,0,0,64},{255,0,0,64},RED); |
|
|
|
|
view.DrawStringPropDecal(obj.bounds.pos+vf2d{1.25f,1.25f},objName,BLACK,vf2d{0.25f,0.25f}); |
|
|
|
|
view.DrawStringPropDecal(obj.bounds.pos+vf2d{1,1},objName,WHITE,vf2d{0.25f,0.25f}); |
|
|
|
|
|
|
|
|
|
if(geom2d::contains(obj.bounds,GetMousePos())){ |
|
|
|
|
selectedObj=objName; |
|
|
|
@ -77,7 +81,7 @@ public: |
|
|
|
|
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}); |
|
|
|
|
view.FillRectDecal(vf2d{float(x),float(y)}*tileset.tilewidth,vf2d{float(tileset.tilewidth),float(tileset.tileheight)},{0,0,0,128}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -86,12 +90,12 @@ public: |
|
|
|
|
const bool EditingQuad=editingPoint<4&&editingQuad!=nullptr; |
|
|
|
|
|
|
|
|
|
if(EditingQuad){ |
|
|
|
|
(*editingQuad)[editingPoint]=GetMousePos(); |
|
|
|
|
(*editingQuad)[editingPoint]=view.ScreenToWorld(GetMousePos()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(GetMouse(Mouse::LEFT).bPressed){ |
|
|
|
|
if(EditingQuad){ |
|
|
|
|
(*editingQuad)[editingPoint]=GetMousePos(); |
|
|
|
|
(*editingQuad)[editingPoint]=view.ScreenToWorld(GetMousePos()); |
|
|
|
|
editingPoint++; |
|
|
|
|
}else{ |
|
|
|
|
if(obj.collisionTiles.size()==0){ |
|
|
|
@ -120,7 +124,7 @@ public: |
|
|
|
|
points.assign(quad.begin(),quad.end()); |
|
|
|
|
uvs.assign(4,{0.f,0.f}); |
|
|
|
|
cols.assign(4,{255,40,40,128}); |
|
|
|
|
DrawPolygonDecal(nullptr,points,uvs,cols); |
|
|
|
|
view.DrawPolygonDecal(nullptr,points,uvs,cols); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|