mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-25 06:35:30 +00:00
Merge branch 'copy-that' into 'master'
Feat(CS): Implement Instance Cloning See merge request OpenMW/openmw!3654
This commit is contained in:
commit
36b61d7074
@ -410,6 +410,7 @@ void CSMPrefs::State::declare()
|
||||
declareShortcut("scene-edit-abort", "Abort", QKeySequence(Qt::Key_Escape));
|
||||
declareShortcut("scene-focus-toolbar", "Toggle Toolbar Focus", QKeySequence(Qt::Key_T));
|
||||
declareShortcut("scene-render-stats", "Debug Rendering Stats", QKeySequence(Qt::Key_F3));
|
||||
declareShortcut("scene-duplicate", "Duplicate Instance", QKeySequence(Qt::ShiftModifier | Qt::Key_C));
|
||||
|
||||
declareSubcategory("1st/Free Camera");
|
||||
declareShortcut("free-forward", "Forward", QKeySequence(Qt::Key_W));
|
||||
|
@ -464,6 +464,7 @@ namespace CSMPrefs
|
||||
"scene-instance-drop-terrain-separately", "" };
|
||||
Settings::SettingValue<std::string> mSceneInstanceDropCollisionSeparately{ mIndex, sName,
|
||||
"scene-instance-drop-collision-separately", "" };
|
||||
Settings::SettingValue<std::string> mSceneDuplicate{ mIndex, sName, "scene-duplicate", "Shift+C" };
|
||||
Settings::SettingValue<std::string> mSceneLoadCamCell{ mIndex, sName, "scene-load-cam-cell", "Keypad+5" };
|
||||
Settings::SettingValue<std::string> mSceneLoadCamEastcell{ mIndex, sName, "scene-load-cam-eastcell",
|
||||
"Keypad+6" };
|
||||
|
@ -297,6 +297,7 @@ void CSMWorld::RefCollection::cloneRecord(
|
||||
const ESM::RefId& origin, const ESM::RefId& destination, const UniversalId::Type type)
|
||||
{
|
||||
auto copy = std::make_unique<Record<CellRef>>();
|
||||
int index = getAppendIndex(ESM::RefId(), type);
|
||||
|
||||
copy->mModified = getRecord(origin).get();
|
||||
copy->mState = RecordBase::State_ModifiedOnly;
|
||||
@ -304,6 +305,15 @@ void CSMWorld::RefCollection::cloneRecord(
|
||||
copy->get().mId = destination;
|
||||
copy->get().mIdNum = extractIdNum(destination.getRefIdString());
|
||||
|
||||
if (copy->get().mRefNum.mContentFile != 0)
|
||||
{
|
||||
mRefIndex.insert(std::make_pair(static_cast<Record<CellRef>*>(copy.get())->get().mIdNum, index));
|
||||
copy->get().mRefNum.mContentFile = 0;
|
||||
copy->get().mRefNum.mIndex = index;
|
||||
}
|
||||
else
|
||||
copy->get().mRefNum.mIndex = copy->get().mIdNum;
|
||||
|
||||
insertRecord(std::move(copy), getAppendIndex(destination, type)); // call RefCollection::insertRecord()
|
||||
}
|
||||
|
||||
|
@ -202,15 +202,21 @@ CSVRender::InstanceMode::InstanceMode(
|
||||
connect(this, &InstanceMode::requestFocus, worldspaceWidget, &WorldspaceWidget::requestFocus);
|
||||
|
||||
CSMPrefs::Shortcut* deleteShortcut = new CSMPrefs::Shortcut("scene-delete", worldspaceWidget);
|
||||
connect(deleteShortcut, qOverload<>(&CSMPrefs::Shortcut::activated), this, &InstanceMode::deleteSelectedInstances);
|
||||
|
||||
CSMPrefs::Shortcut* duplicateShortcut = new CSMPrefs::Shortcut("scene-duplicate", worldspaceWidget);
|
||||
|
||||
connect(
|
||||
deleteShortcut, qOverload<bool>(&CSMPrefs::Shortcut::activated), this, &InstanceMode::deleteSelectedInstances);
|
||||
duplicateShortcut, qOverload<>(&CSMPrefs::Shortcut::activated), this, &InstanceMode::cloneSelectedInstances);
|
||||
|
||||
// Following classes could be simplified by using QSignalMapper, which is obsolete in Qt5.10, but not in Qt4.8 and
|
||||
// Qt5.14
|
||||
CSMPrefs::Shortcut* dropToCollisionShortcut
|
||||
= new CSMPrefs::Shortcut("scene-instance-drop-collision", worldspaceWidget);
|
||||
|
||||
connect(dropToCollisionShortcut, qOverload<>(&CSMPrefs::Shortcut::activated), this,
|
||||
&InstanceMode::dropSelectedInstancesToCollision);
|
||||
|
||||
CSMPrefs::Shortcut* dropToTerrainLevelShortcut
|
||||
= new CSMPrefs::Shortcut("scene-instance-drop-terrain", worldspaceWidget);
|
||||
connect(dropToTerrainLevelShortcut, qOverload<>(&CSMPrefs::Shortcut::activated), this,
|
||||
@ -1068,7 +1074,7 @@ void CSVRender::InstanceMode::handleSelectDrag(const QPoint& pos)
|
||||
mDragMode = DragMode_None;
|
||||
}
|
||||
|
||||
void CSVRender::InstanceMode::deleteSelectedInstances(bool active)
|
||||
void CSVRender::InstanceMode::deleteSelectedInstances()
|
||||
{
|
||||
std::vector<osg::ref_ptr<TagBase>> selection = getWorldspaceWidget().getSelection(Mask_Reference);
|
||||
if (selection.empty())
|
||||
@ -1087,6 +1093,27 @@ void CSVRender::InstanceMode::deleteSelectedInstances(bool active)
|
||||
getWorldspaceWidget().clearSelection(Mask_Reference);
|
||||
}
|
||||
|
||||
void CSVRender::InstanceMode::cloneSelectedInstances()
|
||||
{
|
||||
std::vector<osg::ref_ptr<TagBase>> selection = getWorldspaceWidget().getSelection(Mask_Reference);
|
||||
if (selection.empty())
|
||||
return;
|
||||
|
||||
CSMDoc::Document& document = getWorldspaceWidget().getDocument();
|
||||
CSMWorld::IdTable& referencesTable
|
||||
= dynamic_cast<CSMWorld::IdTable&>(*document.getData().getTableModel(CSMWorld::UniversalId::Type_References));
|
||||
QUndoStack& undoStack = document.getUndoStack();
|
||||
|
||||
CSMWorld::CommandMacro macro(undoStack, "Clone Instances");
|
||||
for (osg::ref_ptr<TagBase> tag : selection)
|
||||
if (CSVRender::ObjectTag* objectTag = dynamic_cast<CSVRender::ObjectTag*>(tag.get()))
|
||||
{
|
||||
macro.push(new CSMWorld::CloneCommand(referencesTable, objectTag->mObject->getReferenceId(),
|
||||
"ref#" + std::to_string(referencesTable.rowCount()), CSMWorld::UniversalId::Type_Reference));
|
||||
}
|
||||
// getWorldspaceWidget().clearSelection(Mask_Reference);
|
||||
}
|
||||
|
||||
void CSVRender::InstanceMode::dropInstance(CSVRender::Object* object, float dropHeight)
|
||||
{
|
||||
object->setEdited(Object::Override_Position);
|
||||
|
@ -131,7 +131,8 @@ namespace CSVRender
|
||||
private slots:
|
||||
|
||||
void subModeChanged(const std::string& id);
|
||||
void deleteSelectedInstances(bool active);
|
||||
void deleteSelectedInstances();
|
||||
void cloneSelectedInstances();
|
||||
void dropSelectedInstancesToCollision();
|
||||
void dropSelectedInstancesToTerrain();
|
||||
void dropSelectedInstancesToCollisionSeparately();
|
||||
|
Loading…
x
Reference in New Issue
Block a user