mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2025-02-03 18:14:01 +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");
|
||||
}
|
||||
*/
|
||||
std::vector<Element*> loadedElements;
|
||||
loadedElements.reserve(200);
|
||||
XMLElement *simpleElements = doc.FirstChildElement("SE");
|
||||
while (simpleElements)
|
||||
{
|
||||
int idx, x, y, rot;
|
||||
float sz,sz2;
|
||||
loadedElements.clear();
|
||||
if (simpleElements->Attribute("d"))
|
||||
{
|
||||
SimpleIStringStream is(simpleElements->Attribute("d"));
|
||||
|
@ -4899,6 +4902,7 @@ bool Game::loadSceneXML(std::string scene)
|
|||
is >> x >> y >> rot;
|
||||
Element *e = createElement(idx, Vector(x,y), 4);
|
||||
e->rotation.z = rot;
|
||||
loadedElements.push_back(e);
|
||||
}
|
||||
}
|
||||
if (simpleElements->Attribute("e"))
|
||||
|
@ -4910,6 +4914,7 @@ bool Game::loadSceneXML(std::string scene)
|
|||
is2 >> x >> y >> rot;
|
||||
Element *e = createElement(idx, Vector(x,y), l);
|
||||
e->rotation.z = rot;
|
||||
loadedElements.push_back(e);
|
||||
}
|
||||
}
|
||||
if (simpleElements->Attribute("f"))
|
||||
|
@ -4922,6 +4927,7 @@ bool Game::loadSceneXML(std::string scene)
|
|||
Element *e = createElement(idx, Vector(x,y), l);
|
||||
e->scale = Vector(sz,sz);
|
||||
e->rotation.z = rot;
|
||||
loadedElements.push_back(e);
|
||||
}
|
||||
}
|
||||
if (simpleElements->Attribute("g"))
|
||||
|
@ -4939,6 +4945,7 @@ bool Game::loadSceneXML(std::string scene)
|
|||
e->flipVertical();
|
||||
e->scale = Vector(sz,sz);
|
||||
e->rotation.z = rot;
|
||||
loadedElements.push_back(e);
|
||||
}
|
||||
}
|
||||
if (simpleElements->Attribute("h"))
|
||||
|
@ -4960,6 +4967,7 @@ bool Game::loadSceneXML(std::string scene)
|
|||
e->flipVertical();
|
||||
e->scale = Vector(sz,sz);
|
||||
e->rotation.z = rot;
|
||||
loadedElements.push_back(e);
|
||||
}
|
||||
}
|
||||
if (simpleElements->Attribute("i"))
|
||||
|
@ -4984,6 +4992,7 @@ bool Game::loadSceneXML(std::string scene)
|
|||
e->scale = Vector(sz,sz);
|
||||
e->rotation.z = rot;
|
||||
e->setElementEffectByIndex(efxIdx);
|
||||
loadedElements.push_back(e);
|
||||
}
|
||||
}
|
||||
if (simpleElements->Attribute("j"))
|
||||
|
@ -5011,6 +5020,7 @@ bool Game::loadSceneXML(std::string scene)
|
|||
e->setElementEffectByIndex(efxIdx);
|
||||
if (repeat)
|
||||
e->repeatTextureToFill(true);
|
||||
loadedElements.push_back(e);
|
||||
}
|
||||
}
|
||||
if (simpleElements->Attribute("k"))
|
||||
|
@ -5048,6 +5058,25 @@ bool Game::loadSceneXML(std::string scene)
|
|||
c=0;
|
||||
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");
|
||||
|
@ -5431,12 +5460,31 @@ bool Game::saveScene(std::string scene)
|
|||
}
|
||||
|
||||
std::ostringstream simpleElements[LR_MAX];
|
||||
std::ostringstream simpleElements_repeatScale[LR_MAX];
|
||||
|
||||
|
||||
for (i = 0; i < dsq->getNumElements(); 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)
|
||||
|
@ -5471,6 +5519,9 @@ bool Game::saveScene(std::string scene)
|
|||
XMLElement *simpleElementsXML = saveFile.NewElement("SE");
|
||||
simpleElementsXML->SetAttribute("k", s.c_str());
|
||||
simpleElementsXML->SetAttribute("l", i);
|
||||
std::string repeatScaleStr = simpleElements_repeatScale[i].str();
|
||||
if(!repeatScaleStr.empty())
|
||||
simpleElementsXML->SetAttribute("repeatScale", repeatScaleStr.c_str());
|
||||
saveFile.InsertEndChild(simpleElementsXML);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -520,7 +520,7 @@ protected:
|
|||
void enterRotateState();
|
||||
void enterMoveState();
|
||||
|
||||
Vector oldPosition, oldRotation, oldScale, cursorOffset;
|
||||
Vector oldPosition, oldRotation, oldScale, cursorOffset, oldRepeatScale;
|
||||
|
||||
Entity *movingEntity;
|
||||
void updateDrawingWarpArea(char c, int k);
|
||||
|
|
|
@ -980,7 +980,7 @@ void SceneEditor::setGridPattern9()
|
|||
|
||||
void SceneEditor::moveToFront()
|
||||
{
|
||||
if (editingElement)
|
||||
if (editingElement && !core->getShiftState())
|
||||
{
|
||||
std::vector<Element*> copy = dsq->getElementsCopy();
|
||||
dsq->clearElements();
|
||||
|
@ -999,7 +999,7 @@ void SceneEditor::moveToFront()
|
|||
|
||||
void SceneEditor::moveToBack()
|
||||
{
|
||||
if (editingElement)
|
||||
if (editingElement && !core->getShiftState())
|
||||
{
|
||||
std::vector<Element*> copy = dsq->getElementsCopy();
|
||||
dsq->clearElements();
|
||||
|
@ -1328,6 +1328,7 @@ void SceneEditor::enterScaleState()
|
|||
dummy.rotation = Vector(0,0,0);
|
||||
dummy.scale = Vector(1,1,1);
|
||||
oldScale = dummy.scale;
|
||||
oldRepeatScale = Vector(1, 1); // not handled for multi-selection
|
||||
cursorOffset = dsq->getGameCursorPosition();
|
||||
groupCenter = getSelectedElementsCenter();
|
||||
for (int i = 0; i < selectedElements.size(); i++)
|
||||
|
@ -1344,6 +1345,7 @@ void SceneEditor::enterScaleState()
|
|||
oldPosition = editingElement->position;
|
||||
state = ES_SCALING;
|
||||
oldScale = editingElement->scale;
|
||||
oldRepeatScale = editingElement->repeatToFillScale;
|
||||
cursorOffset = dsq->getGameCursorPosition();
|
||||
}
|
||||
}
|
||||
|
@ -3377,7 +3379,7 @@ void SceneEditor::update(float dt)
|
|||
break;
|
||||
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;
|
||||
if (cursorOffset.x > oldPosition.x+10)
|
||||
right = true;
|
||||
|
@ -3416,6 +3418,10 @@ void SceneEditor::update(float dt)
|
|||
add.y = add.x;
|
||||
uni = true;
|
||||
}
|
||||
|
||||
repeatScale = core->getKeyState(KEY_X);
|
||||
if(repeatScale)
|
||||
add *= 0.1f;
|
||||
}
|
||||
}
|
||||
if (!selectedElements.empty())
|
||||
|
@ -3438,14 +3444,16 @@ void SceneEditor::update(float dt)
|
|||
}
|
||||
else if (editingElement)
|
||||
{
|
||||
Vector& editVec = repeatScale ? editingElement->repeatToFillScale : editingElement->scale;
|
||||
if (core->getCtrlState())
|
||||
{
|
||||
editingElement->scale = Vector(1,1);
|
||||
editVec = Vector(1,1);
|
||||
}
|
||||
else
|
||||
{
|
||||
editingElement->scale=oldScale + add;
|
||||
if (!uni)
|
||||
//editingElement->scale=oldScale + add;
|
||||
editVec = (repeatScale ? oldRepeatScale : oldScale) + add;
|
||||
if (!uni && !repeatScale)
|
||||
{
|
||||
if (!middle)
|
||||
{
|
||||
|
@ -3466,10 +3474,10 @@ void SceneEditor::update(float dt)
|
|||
}
|
||||
}
|
||||
}
|
||||
if (editingElement->scale.x < MIN_SIZE)
|
||||
editingElement->scale.x = MIN_SIZE;
|
||||
if (editingElement->scale.y < MIN_SIZE)
|
||||
editingElement->scale.y = MIN_SIZE;
|
||||
if (editVec.x < MIN_SIZE)
|
||||
editVec.x = MIN_SIZE;
|
||||
if (editVec.y < MIN_SIZE)
|
||||
editVec.y = MIN_SIZE;
|
||||
}
|
||||
|
||||
editingElement->refreshRepeatTextureToFill();
|
||||
|
|
Loading…
Add table
Reference in a new issue