mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2025-02-04 02:24:00 +00:00
Allow editing repeat scale via editor, and save this in map files.
I chose to add an extra XML tag storing only the needed data in order to preserve compatibility with older versions that expect the specific layout of the <SE k="..." /> tag, which can't be changed. Adding a new tag like <SE m="..." /> with an updated layout is also not an option, because older versions would not load these, and maps would be empty as a result.
This commit is contained in:
parent
817d4beb1c
commit
d95b5cccdd
3 changed files with 71 additions and 12 deletions
|
@ -4886,11 +4886,14 @@ bool Game::loadSceneXML(std::string scene)
|
||||||
boxElement = boxElement->NextSiblingElement("BoxElement");
|
boxElement = boxElement->NextSiblingElement("BoxElement");
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
std::vector<Element*> loadedElements;
|
||||||
|
loadedElements.reserve(200);
|
||||||
XMLElement *simpleElements = doc.FirstChildElement("SE");
|
XMLElement *simpleElements = doc.FirstChildElement("SE");
|
||||||
while (simpleElements)
|
while (simpleElements)
|
||||||
{
|
{
|
||||||
int idx, x, y, rot;
|
int idx, x, y, rot;
|
||||||
float sz,sz2;
|
float sz,sz2;
|
||||||
|
loadedElements.clear();
|
||||||
if (simpleElements->Attribute("d"))
|
if (simpleElements->Attribute("d"))
|
||||||
{
|
{
|
||||||
SimpleIStringStream is(simpleElements->Attribute("d"));
|
SimpleIStringStream is(simpleElements->Attribute("d"));
|
||||||
|
@ -4899,6 +4902,7 @@ bool Game::loadSceneXML(std::string scene)
|
||||||
is >> x >> y >> rot;
|
is >> x >> y >> rot;
|
||||||
Element *e = createElement(idx, Vector(x,y), 4);
|
Element *e = createElement(idx, Vector(x,y), 4);
|
||||||
e->rotation.z = rot;
|
e->rotation.z = rot;
|
||||||
|
loadedElements.push_back(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (simpleElements->Attribute("e"))
|
if (simpleElements->Attribute("e"))
|
||||||
|
@ -4910,6 +4914,7 @@ bool Game::loadSceneXML(std::string scene)
|
||||||
is2 >> x >> y >> rot;
|
is2 >> x >> y >> rot;
|
||||||
Element *e = createElement(idx, Vector(x,y), l);
|
Element *e = createElement(idx, Vector(x,y), l);
|
||||||
e->rotation.z = rot;
|
e->rotation.z = rot;
|
||||||
|
loadedElements.push_back(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (simpleElements->Attribute("f"))
|
if (simpleElements->Attribute("f"))
|
||||||
|
@ -4922,6 +4927,7 @@ bool Game::loadSceneXML(std::string scene)
|
||||||
Element *e = createElement(idx, Vector(x,y), l);
|
Element *e = createElement(idx, Vector(x,y), l);
|
||||||
e->scale = Vector(sz,sz);
|
e->scale = Vector(sz,sz);
|
||||||
e->rotation.z = rot;
|
e->rotation.z = rot;
|
||||||
|
loadedElements.push_back(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (simpleElements->Attribute("g"))
|
if (simpleElements->Attribute("g"))
|
||||||
|
@ -4939,6 +4945,7 @@ bool Game::loadSceneXML(std::string scene)
|
||||||
e->flipVertical();
|
e->flipVertical();
|
||||||
e->scale = Vector(sz,sz);
|
e->scale = Vector(sz,sz);
|
||||||
e->rotation.z = rot;
|
e->rotation.z = rot;
|
||||||
|
loadedElements.push_back(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (simpleElements->Attribute("h"))
|
if (simpleElements->Attribute("h"))
|
||||||
|
@ -4960,6 +4967,7 @@ bool Game::loadSceneXML(std::string scene)
|
||||||
e->flipVertical();
|
e->flipVertical();
|
||||||
e->scale = Vector(sz,sz);
|
e->scale = Vector(sz,sz);
|
||||||
e->rotation.z = rot;
|
e->rotation.z = rot;
|
||||||
|
loadedElements.push_back(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (simpleElements->Attribute("i"))
|
if (simpleElements->Attribute("i"))
|
||||||
|
@ -4984,6 +4992,7 @@ bool Game::loadSceneXML(std::string scene)
|
||||||
e->scale = Vector(sz,sz);
|
e->scale = Vector(sz,sz);
|
||||||
e->rotation.z = rot;
|
e->rotation.z = rot;
|
||||||
e->setElementEffectByIndex(efxIdx);
|
e->setElementEffectByIndex(efxIdx);
|
||||||
|
loadedElements.push_back(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (simpleElements->Attribute("j"))
|
if (simpleElements->Attribute("j"))
|
||||||
|
@ -5011,6 +5020,7 @@ bool Game::loadSceneXML(std::string scene)
|
||||||
e->setElementEffectByIndex(efxIdx);
|
e->setElementEffectByIndex(efxIdx);
|
||||||
if (repeat)
|
if (repeat)
|
||||||
e->repeatTextureToFill(true);
|
e->repeatTextureToFill(true);
|
||||||
|
loadedElements.push_back(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (simpleElements->Attribute("k"))
|
if (simpleElements->Attribute("k"))
|
||||||
|
@ -5048,6 +5058,25 @@ bool Game::loadSceneXML(std::string scene)
|
||||||
c=0;
|
c=0;
|
||||||
addProgress();
|
addProgress();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
loadedElements.push_back(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (simpleElements->Attribute("repeatScale"))
|
||||||
|
{
|
||||||
|
SimpleIStringStream is2(simpleElements->Attribute("repeatScale"));
|
||||||
|
for(size_t i = 0; i < loadedElements.size(); ++i)
|
||||||
|
{
|
||||||
|
Element *e = loadedElements[i];
|
||||||
|
if(e->isRepeatingTextureToFill())
|
||||||
|
{
|
||||||
|
float repeatScaleX = 1, repeatScaleY = 1;
|
||||||
|
if(!(is2 >> repeatScaleX >> repeatScaleY))
|
||||||
|
break;
|
||||||
|
e->repeatToFillScale.x = repeatScaleX;
|
||||||
|
e->repeatToFillScale.y = repeatScaleY;
|
||||||
|
e->refreshRepeatTextureToFill();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
simpleElements = simpleElements->NextSiblingElement("SE");
|
simpleElements = simpleElements->NextSiblingElement("SE");
|
||||||
|
@ -5431,12 +5460,31 @@ bool Game::saveScene(std::string scene)
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ostringstream simpleElements[LR_MAX];
|
std::ostringstream simpleElements[LR_MAX];
|
||||||
|
std::ostringstream simpleElements_repeatScale[LR_MAX];
|
||||||
|
|
||||||
|
|
||||||
for (i = 0; i < dsq->getNumElements(); i++)
|
for (i = 0; i < dsq->getNumElements(); i++)
|
||||||
{
|
{
|
||||||
Element *e = dsq->getElement(i);
|
Element *e = dsq->getElement(i);
|
||||||
simpleElements[e->bgLayer] << e->templateIdx << " " << int(e->position.x) << " " << int(e->position.y) << " " << int(e->rotation.z) << " " << e->scale.x << " " << e->scale.y << " " << int(e->isfh()) << " " << int(e->isfv()) << " " << e->elementFlag << " " << e->getElementEffectIndex() << " " << e->isRepeatingTextureToFill() << " ";
|
std::ostringstream& SE = simpleElements[e->bgLayer];
|
||||||
|
SE << e->templateIdx << " "
|
||||||
|
<< int(e->position.x) << " "
|
||||||
|
<< int(e->position.y) << " "
|
||||||
|
<< int(e->rotation.z) << " "
|
||||||
|
<< e->scale.x << " "
|
||||||
|
<< e->scale.y << " "
|
||||||
|
<< int(e->isfh()) << " "
|
||||||
|
<< int(e->isfv()) << " "
|
||||||
|
<< e->elementFlag << " "
|
||||||
|
<< e->getElementEffectIndex()<< " "
|
||||||
|
<< e->isRepeatingTextureToFill() << " ";
|
||||||
|
|
||||||
|
if(e->isRepeatingTextureToFill())
|
||||||
|
{
|
||||||
|
std::ostringstream& SE_rs = simpleElements_repeatScale[e->bgLayer];
|
||||||
|
SE_rs << e->repeatToFillScale.x << " "
|
||||||
|
<< e->repeatToFillScale.y << " ";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dsq->game->entitySaveData.size() > 0)
|
if (dsq->game->entitySaveData.size() > 0)
|
||||||
|
@ -5471,6 +5519,9 @@ bool Game::saveScene(std::string scene)
|
||||||
XMLElement *simpleElementsXML = saveFile.NewElement("SE");
|
XMLElement *simpleElementsXML = saveFile.NewElement("SE");
|
||||||
simpleElementsXML->SetAttribute("k", s.c_str());
|
simpleElementsXML->SetAttribute("k", s.c_str());
|
||||||
simpleElementsXML->SetAttribute("l", i);
|
simpleElementsXML->SetAttribute("l", i);
|
||||||
|
std::string repeatScaleStr = simpleElements_repeatScale[i].str();
|
||||||
|
if(!repeatScaleStr.empty())
|
||||||
|
simpleElementsXML->SetAttribute("repeatScale", repeatScaleStr.c_str());
|
||||||
saveFile.InsertEndChild(simpleElementsXML);
|
saveFile.InsertEndChild(simpleElementsXML);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -520,7 +520,7 @@ protected:
|
||||||
void enterRotateState();
|
void enterRotateState();
|
||||||
void enterMoveState();
|
void enterMoveState();
|
||||||
|
|
||||||
Vector oldPosition, oldRotation, oldScale, cursorOffset;
|
Vector oldPosition, oldRotation, oldScale, cursorOffset, oldRepeatScale;
|
||||||
|
|
||||||
Entity *movingEntity;
|
Entity *movingEntity;
|
||||||
void updateDrawingWarpArea(char c, int k);
|
void updateDrawingWarpArea(char c, int k);
|
||||||
|
|
|
@ -980,7 +980,7 @@ void SceneEditor::setGridPattern9()
|
||||||
|
|
||||||
void SceneEditor::moveToFront()
|
void SceneEditor::moveToFront()
|
||||||
{
|
{
|
||||||
if (editingElement)
|
if (editingElement && !core->getShiftState())
|
||||||
{
|
{
|
||||||
std::vector<Element*> copy = dsq->getElementsCopy();
|
std::vector<Element*> copy = dsq->getElementsCopy();
|
||||||
dsq->clearElements();
|
dsq->clearElements();
|
||||||
|
@ -999,7 +999,7 @@ void SceneEditor::moveToFront()
|
||||||
|
|
||||||
void SceneEditor::moveToBack()
|
void SceneEditor::moveToBack()
|
||||||
{
|
{
|
||||||
if (editingElement)
|
if (editingElement && !core->getShiftState())
|
||||||
{
|
{
|
||||||
std::vector<Element*> copy = dsq->getElementsCopy();
|
std::vector<Element*> copy = dsq->getElementsCopy();
|
||||||
dsq->clearElements();
|
dsq->clearElements();
|
||||||
|
@ -1328,6 +1328,7 @@ void SceneEditor::enterScaleState()
|
||||||
dummy.rotation = Vector(0,0,0);
|
dummy.rotation = Vector(0,0,0);
|
||||||
dummy.scale = Vector(1,1,1);
|
dummy.scale = Vector(1,1,1);
|
||||||
oldScale = dummy.scale;
|
oldScale = dummy.scale;
|
||||||
|
oldRepeatScale = Vector(1, 1); // not handled for multi-selection
|
||||||
cursorOffset = dsq->getGameCursorPosition();
|
cursorOffset = dsq->getGameCursorPosition();
|
||||||
groupCenter = getSelectedElementsCenter();
|
groupCenter = getSelectedElementsCenter();
|
||||||
for (int i = 0; i < selectedElements.size(); i++)
|
for (int i = 0; i < selectedElements.size(); i++)
|
||||||
|
@ -1344,6 +1345,7 @@ void SceneEditor::enterScaleState()
|
||||||
oldPosition = editingElement->position;
|
oldPosition = editingElement->position;
|
||||||
state = ES_SCALING;
|
state = ES_SCALING;
|
||||||
oldScale = editingElement->scale;
|
oldScale = editingElement->scale;
|
||||||
|
oldRepeatScale = editingElement->repeatToFillScale;
|
||||||
cursorOffset = dsq->getGameCursorPosition();
|
cursorOffset = dsq->getGameCursorPosition();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3377,7 +3379,7 @@ void SceneEditor::update(float dt)
|
||||||
break;
|
break;
|
||||||
case ES_SCALING:
|
case ES_SCALING:
|
||||||
{
|
{
|
||||||
bool right=false, middle=false, down=false, uni=false;
|
bool right=false, middle=false, down=false, uni=false, repeatScale=false;
|
||||||
bool noSide = 0;
|
bool noSide = 0;
|
||||||
if (cursorOffset.x > oldPosition.x+10)
|
if (cursorOffset.x > oldPosition.x+10)
|
||||||
right = true;
|
right = true;
|
||||||
|
@ -3416,6 +3418,10 @@ void SceneEditor::update(float dt)
|
||||||
add.y = add.x;
|
add.y = add.x;
|
||||||
uni = true;
|
uni = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
repeatScale = core->getKeyState(KEY_X);
|
||||||
|
if(repeatScale)
|
||||||
|
add *= 0.1f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!selectedElements.empty())
|
if (!selectedElements.empty())
|
||||||
|
@ -3438,14 +3444,16 @@ void SceneEditor::update(float dt)
|
||||||
}
|
}
|
||||||
else if (editingElement)
|
else if (editingElement)
|
||||||
{
|
{
|
||||||
|
Vector& editVec = repeatScale ? editingElement->repeatToFillScale : editingElement->scale;
|
||||||
if (core->getCtrlState())
|
if (core->getCtrlState())
|
||||||
{
|
{
|
||||||
editingElement->scale = Vector(1,1);
|
editVec = Vector(1,1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
editingElement->scale=oldScale + add;
|
//editingElement->scale=oldScale + add;
|
||||||
if (!uni)
|
editVec = (repeatScale ? oldRepeatScale : oldScale) + add;
|
||||||
|
if (!uni && !repeatScale)
|
||||||
{
|
{
|
||||||
if (!middle)
|
if (!middle)
|
||||||
{
|
{
|
||||||
|
@ -3466,10 +3474,10 @@ void SceneEditor::update(float dt)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (editingElement->scale.x < MIN_SIZE)
|
if (editVec.x < MIN_SIZE)
|
||||||
editingElement->scale.x = MIN_SIZE;
|
editVec.x = MIN_SIZE;
|
||||||
if (editingElement->scale.y < MIN_SIZE)
|
if (editVec.y < MIN_SIZE)
|
||||||
editingElement->scale.y = MIN_SIZE;
|
editVec.y = MIN_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
editingElement->refreshRepeatTextureToFill();
|
editingElement->refreshRepeatTextureToFill();
|
||||||
|
|
Loading…
Add table
Reference in a new issue