|
|
|
@ -16,7 +16,8 @@ class TiledCollisionEditor : public olc::PixelGameEngine |
|
|
|
|
Quadrilateral*editingQuad=nullptr; |
|
|
|
|
Quadrilateral originalQuad; |
|
|
|
|
std::string selectedObj=""; |
|
|
|
|
int editingPoint=4; //Which point we are editing (0-3.)
|
|
|
|
|
int editingPoint=4; //0-3 for the index we are editing within editingQuad.
|
|
|
|
|
bool dragging=false; |
|
|
|
|
|
|
|
|
|
TransformedView view; |
|
|
|
|
|
|
|
|
@ -98,7 +99,7 @@ public: |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const TilesetObject&obj=tileset.objects.at(selectedObj); |
|
|
|
|
const bool EditingQuad=editingPoint<4&&editingQuad!=nullptr; |
|
|
|
|
const bool EditingQuad=(editingPoint<4||dragging)&&editingQuad!=nullptr; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto GetSnapPoint=[&](){ |
|
|
|
@ -109,29 +110,47 @@ public: |
|
|
|
|
return vf2d{round(worldCoords.x/(tileset.tilewidth/4))*tileset.tilewidth/4,round(worldCoords.y/(tileset.tileheight/4))*tileset.tileheight/4}; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
if(EditingQuad){ |
|
|
|
|
if(EditingQuad&&!dragging){ |
|
|
|
|
(*editingQuad)[editingPoint]=GetSnapPoint(); |
|
|
|
|
}else |
|
|
|
|
if(EditingQuad&&dragging){ |
|
|
|
|
vf2d cursorPos=GetSnapPoint(); |
|
|
|
|
vf2d initialPoint=(*editingQuad)[0]; |
|
|
|
|
(*editingQuad)[1]=vf2d{cursorPos.x,initialPoint.y}; |
|
|
|
|
(*editingQuad)[2]=GetSnapPoint(); |
|
|
|
|
(*editingQuad)[3]=vf2d{initialPoint.x,cursorPos.y}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(GetMouse(Mouse::LEFT).bPressed){ |
|
|
|
|
if(EditingQuad){ |
|
|
|
|
if(EditingQuad&&!dragging){ |
|
|
|
|
(*editingQuad)[editingPoint]=GetSnapPoint(); |
|
|
|
|
editingPoint++; |
|
|
|
|
}else{ |
|
|
|
|
if(obj.collisionTiles.size()==0){ |
|
|
|
|
Quadrilateral newQuad; |
|
|
|
|
newQuad.fill(obj.bounds.middle()); |
|
|
|
|
Quadrilateral newQuad{GetSnapPoint()}; |
|
|
|
|
tilesets[activeTileset].objects[selectedObj].collisionTiles.push_back(newQuad); |
|
|
|
|
} |
|
|
|
|
editingPoint=0; |
|
|
|
|
dragging=true; |
|
|
|
|
editingQuad=const_cast<Quadrilateral*>(&obj.collisionTiles.back());
|
|
|
|
|
originalQuad=*editingQuad; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(GetMouse(Mouse::LEFT).bReleased){ |
|
|
|
|
if(EditingQuad&&dragging){ |
|
|
|
|
vf2d cursorPos=GetSnapPoint(); |
|
|
|
|
vf2d initialPoint=(*editingQuad)[0]; |
|
|
|
|
(*editingQuad)[1]=vf2d{cursorPos.x,initialPoint.y}; |
|
|
|
|
(*editingQuad)[2]=GetSnapPoint(); |
|
|
|
|
(*editingQuad)[3]=vf2d{initialPoint.x,cursorPos.y}; |
|
|
|
|
dragging=false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(GetMouse(Mouse::RIGHT).bPressed||GetKey(ESCAPE).bPressed){ |
|
|
|
|
if(EditingQuad){ |
|
|
|
|
editingPoint=4; |
|
|
|
|
dragging=false; |
|
|
|
|
*editingQuad=originalQuad; |
|
|
|
|
editingQuad=nullptr; |
|
|
|
|
} |
|
|
|
|