1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2025-01-26 02:07:26 +00:00

editor: fix multi-select, scaling, sideways-scaling, texcoords

This commit is contained in:
fgenesis 2023-10-21 00:33:49 +02:00
parent eaa1746f4e
commit 0a2965e26b
4 changed files with 114 additions and 58 deletions

View file

@ -111,11 +111,12 @@ static void tileToQuad(Quad *q, const TileData& t)
{ {
q->setRepeatScale(Vector(t.rep->texscaleX, t.rep->texscaleY)); q->setRepeatScale(Vector(t.rep->texscaleX, t.rep->texscaleY));
q->repeatTextureToFill(true); q->repeatTextureToFill(true);
q->setOverrideTexCoords(t.getTexcoords());
} }
q->texcoords = t.getTexcoords();
q->renderBorder = true; q->renderBorder = true;
q->renderBorderColor = TileRender::GetTagColor(t.tag); q->renderBorderColor = TileRender::GetTagColor(t.tag);
q->borderAlpha = 1.0f; q->borderAlpha = 1.0f;
q->update(0); // to prevent 1 frame of lag when setting
} }
static void quadToTile(TileData& t, const Quad *q) static void quadToTile(TileData& t, const Quad *q)
@ -134,6 +135,7 @@ class MultiTileHelper : public Quad
TileStorage& _ts; TileStorage& _ts;
std::vector<size_t> _indices; std::vector<size_t> _indices;
std::vector<Quad*> _quads; std::vector<Quad*> _quads;
Vector lastScale;
MultiTileHelper(TileStorage& ts, const size_t *indices, size_t n) MultiTileHelper(TileStorage& ts, const size_t *indices, size_t n)
: Quad() : Quad()
@ -191,10 +193,50 @@ public:
{ {
} }
void onUpdate(float dt) void changeRepeatScale(const Vector& rs)
{
size_t n = _indices.size();
assert(n == 1);
TileData& t = _ts.tiles[_indices[0]];
if((t.flags & TILEFLAG_REPEAT) && t.rep)
{
this->setRepeatScale(rs);
t.rep->texscaleX = rs.x;
t.rep->texscaleY = rs.y;
t.refreshRepeat();
this->setOverrideTexCoords(t.getTexcoords());
}
}
virtual void onUpdate(float dt) OVERRIDE
{ {
//for(size_t i = 0; i < _quads.size(); ++i) if(scale != lastScale)
// _quads[i]->refreshRepeatTextureToFill(); {
lastScale = scale;
if(_indices.size() == 1)
{
TileData& t = _ts.tiles[_indices[0]];
t.scalex = scale.x;
t.scaley = scale.y;
t.refreshRepeat();
this->setOverrideTexCoords(t.getTexcoords());
}
else
{
for(size_t i = 0; i < _quads.size(); ++i)
{
TileData& t = _ts.tiles[_indices[i]];
Quad *q = _quads[i];
Vector s = q->getRealScale();
t.scalex = s.x;
t.scaley = s.y;
t.refreshRepeat();
q->setOverrideTexCoords(t.getTexcoords());
}
}
}
Quad::onUpdate(dt);
} }
void finish() void finish()
@ -218,6 +260,7 @@ public:
} }
alphaMod = 0; alphaMod = 0;
this->safeKill(); // also deletes all children this->safeKill(); // also deletes all children
_ts.refreshAll();
} }
}; };
@ -1078,17 +1121,14 @@ void SceneEditor::enterAnyStateHelper(EditorStates newstate)
state = newstate; state = newstate;
if (editType == ET_ELEMENTS) if (editType == ET_ELEMENTS)
{ {
oldRepeatScale = Vector(1, 1); // not handled for multi-selection
if(selectedTiles.size() == 1) if(selectedTiles.size() == 1)
{ {
const TileData& t = getCurrentLayerTiles().tiles[selectedTiles[0]]; const TileData& t = getCurrentLayerTiles().tiles[selectedTiles[0]];
oldRepeatScale = Vector(1,1); if(t.flags & TILEFLAG_REPEAT && t.rep)
if(t.flags & TILEFLAG_REPEAT)
oldRepeatScale = Vector(t.rep->texscaleX, t.rep->texscaleY); oldRepeatScale = Vector(t.rep->texscaleX, t.rep->texscaleY);
} }
else
{
oldRepeatScale = Vector(1, 1); // not handled for multi-selection
}
MultiTileHelper *m = createMultiTileHelperFromSelection(); MultiTileHelper *m = createMultiTileHelperFromSelection();
oldScale = m->scale; oldScale = m->scale;
@ -1676,13 +1716,18 @@ void SceneEditor::updateMultiSelect()
clearSelection(); clearSelection();
const TileStorage& ts = getCurrentLayerTiles(); TileStorage& ts = getCurrentLayerTiles();
for(size_t i = 0; i < ts.tiles.size(); ++i) for(size_t i = 0; i < ts.tiles.size(); ++i)
{ {
const TileData& t = ts.tiles[i]; const TileData& t = ts.tiles[i];
if(t.isVisible() && t.x >= p1.x && t.y >= p1.y && t.x <= p2.x && t.y <= p2.y) if(t.isVisible() && t.x >= p1.x && t.y >= p1.y && t.x <= p2.x && t.y <= p2.y)
{
selectedTiles.push_back(i); selectedTiles.push_back(i);
}
} }
if(size_t N = selectedTiles.size())
ts.select(&selectedTiles[0], N);
} }
} }
@ -1762,9 +1807,12 @@ void SceneEditor::action(int id, int state, int source, InputDevice device)
{ {
if (state) if (state)
{ {
if (!multiSelecting) if (!multiSelecting)
{
multiSelecting = true;
clearSelection(); clearSelection();
multiSelecting = true; }
multiSelectPoint = dsq->getGameCursorPosition(); multiSelectPoint = dsq->getGameCursorPosition();
} }
else else
@ -2431,16 +2479,16 @@ void SceneEditor::update(float dt)
if (state == ES_SELECTING && !ismulti) if (state == ES_SELECTING && !ismulti)
{ {
sel = this->getTileAtCursor(); sel = this->getTileAtCursor();
//if(sel < 0 || (selectedTiles.size() == 1 && selectedTiles[0] != (size_t)sel)) if(selectedTiles.empty() || (selectedTiles.size() == 1 && selectedTiles[0] != sel))
{ {
selectedTiles.clear(); if(!selectedTiles.empty())
getCurrentLayerTiles().clearSelection(); clearSelection();
} if(sel >= 0)
if(sel >= 0) {
{ selectedTiles.push_back(sel);
selectedTiles.push_back(sel); const size_t idx = sel;
const size_t idx = sel; getCurrentLayerTiles().select(&idx, 1);
getCurrentLayerTiles().select(&idx, 1); }
} }
} }
@ -2679,60 +2727,46 @@ void SceneEditor::update(float dt)
repeatScale = core->getKeyState(KEY_X); repeatScale = core->getKeyState(KEY_X);
if(repeatScale) if(repeatScale)
add *= 0.1f; add *= 0.3f;
} }
if (!selectedTiles.empty()) if (!selectedTiles.empty())
{ {
if (!core->getCtrlState()) if (!core->getCtrlState())
{ {
multi->scale=oldScale + add; if(repeatScale)
if (multi->scale.x < MIN_SIZE) {
multi->scale.x = MIN_SIZE; if(selectedTiles.size() == 1)
if (multi->scale.y < MIN_SIZE) multi->changeRepeatScale(oldRepeatScale + add);
multi->scale.y = MIN_SIZE; }
} else
}
// FIXME: scaling
/*else if (editingElement)
{
Vector& editVec = repeatScale ? editingElement->repeatToFillScale : editingElement->scale;
if (core->getCtrlState())
{
editVec = Vector(1,1);
}
else
{
editVec = (repeatScale ? oldRepeatScale : oldScale) + add;
if (!uni && !repeatScale)
{ {
if (!middle) multi->scale=oldScale + add;
if (multi->scale.x < MIN_SIZE)
multi->scale.x = MIN_SIZE;
if (multi->scale.y < MIN_SIZE)
multi->scale.y = MIN_SIZE;
if(!middle && !uni && selectedTiles.size() == 1)
{ {
Vector offsetChange = (add*Vector(editingElement->getWidth(), editingElement->getHeight()))*0.5f; Vector offsetChange = (add*Vector(multi->getWidth(), multi->getHeight()))*0.5f;
if (add.y == 0) if (add.y == 0)
{ {
if (right) if (right)
editingElement->beforeScaleOffset = offsetChange; multi->offset = offsetChange;
else else
editingElement->beforeScaleOffset = -offsetChange; multi->offset = -offsetChange;
} }
else else
{ {
if (down) if (down)
editingElement->beforeScaleOffset = offsetChange; multi->offset = offsetChange;
else else
editingElement->beforeScaleOffset = -offsetChange; multi->offset = -offsetChange;
} }
} }
} }
if (editVec.x < MIN_SIZE)
editVec.x = MIN_SIZE;
if (editVec.y < MIN_SIZE)
editVec.y = MIN_SIZE;
} }
}
editingElement->refreshRepeatTextureToFill();
}*/
} }
break; break;
case ES_MAX: case ES_MAX:

View file

@ -274,7 +274,7 @@ TileDef::TileDef(unsigned lr, const TileData& t)
, sx(t.scalex), sy(t.scaley) , sx(t.scalex), sy(t.scaley)
, rsx(1), rsy(1) , rsx(1), rsy(1)
{ {
if(t.flags & TILEFLAG_REPEAT) if(t.flags & TILEFLAG_REPEAT && t.rep)
{ {
rsx = t.rep->texscaleX; rsx = t.rep->texscaleX;
rsy = t.rep->texscaleY; rsy = t.rep->texscaleY;

View file

@ -51,6 +51,7 @@ void Quad::initQuad()
renderBorder = false; renderBorder = false;
renderCenter = true; renderCenter = true;
texcoordOverride = false;
width = 2; height = 2; width = 2; height = 2;
texcoords.setStandard(); texcoords.setStandard();
@ -259,6 +260,9 @@ void Quad::onRender(const RenderState& rs) const
void Quad::updateTexCoords() void Quad::updateTexCoords()
{ {
if(texcoordOverride)
goto setgrid;
if (repeatTexture && texture) if (repeatTexture && texture)
{ {
texcoords.u1 = texOff.x; texcoords.u1 = texOff.x;
@ -266,6 +270,7 @@ void Quad::updateTexCoords()
texcoords.u2 = (width*scale.x*repeatToFillScale.x)/texture->width + texOff.x; texcoords.u2 = (width*scale.x*repeatToFillScale.x)/texture->width + texOff.x;
texcoords.v2 = (height*scale.y*repeatToFillScale.y)/texture->height + texOff.y; texcoords.v2 = (height*scale.y*repeatToFillScale.y)/texture->height + texOff.y;
setgrid:
if(!grid) if(!grid)
{ {
createGrid(2, 2)->gridType = GRID_UNDEFINED; createGrid(2, 2)->gridType = GRID_UNDEFINED;
@ -281,6 +286,19 @@ void Quad::updateTexCoords()
} }
} }
void Quad::setOverrideTexCoords(const TexCoordBox & tc)
{
texcoordOverride = true;
texcoords = tc;
updateTexCoords();
}
void Quad::clearOverrideTexCoords()
{
texcoordOverride = false;
updateTexCoords();
}
void Quad::reloadDevice() void Quad::reloadDevice()
{ {
RenderObject::reloadDevice(); RenderObject::reloadDevice();

View file

@ -77,18 +77,21 @@ public:
void setRepeatOffset(const Vector& repoffs); void setRepeatOffset(const Vector& repoffs);
inline const Vector& getRepeatOffset() const { return texOff; } inline const Vector& getRepeatOffset() const { return texOff; }
void setStripPoints(bool vert, const Vector *points, size_t n); void setStripPoints(bool vert, const Vector *points, size_t n);
DynamicRenderGrid *getGrid() { return grid; } DynamicRenderGrid *getGrid() { return grid; }
const DynamicRenderGrid *getGrid() const { return grid; } const DynamicRenderGrid *getGrid() const { return grid; }
void setOverrideTexCoords(const TexCoordBox& tc);
void clearOverrideTexCoords();
void reloadDevice() OVERRIDE; void reloadDevice() OVERRIDE;
void deleteGrid(); void deleteGrid();
TexCoordBox texcoords;
// TODO: this should be a bitmask // TODO: this should be a bitmask
bool renderQuad, renderCenter, renderBorder; bool renderQuad, renderCenter, renderBorder;
bool texcoordOverride; // urgh
float borderAlpha; float borderAlpha;
Vector renderBorderColor; Vector renderBorderColor;
@ -96,6 +99,7 @@ public:
protected: protected:
void updateTexCoords(); void updateTexCoords();
TexCoordBox texcoords;
Vector repeatToFillScale; Vector repeatToFillScale;
Vector texOff; Vector texOff;
DynamicRenderGrid *grid; DynamicRenderGrid *grid;