diff --git a/NEWS.md b/NEWS.md index 0dd47ee0ac..84f375d8f7 100644 --- a/NEWS.md +++ b/NEWS.md @@ -9,6 +9,7 @@ * Scripting: Added 'tiled.cell' function, 'cell.flags' property and 'TileLayerEdit.setCell' function (#4538) * Scripting: Added MapObject.resolvedClassName() (by MatusGuy, #4529) * Fixed crash when the selection becomes empty while starting a move (#4536) +* Fixed Properties view update on 'Reset Template Instance' and 'Replace With Template' actions * Linux: Added file associations for .tmj, .tsj, .tiled-project and .world files (by miffe, #4550) * macOS: Declared UTIs and file associations for all supported Tiled formats (with Jyotish, #4469) * snap: Updated to Qt 6 diff --git a/docs/reference/json-map-format.rst b/docs/reference/json-map-format.rst index dbb2824ba2..7815304263 100644 --- a/docs/reference/json-map-format.rst +++ b/docs/reference/json-map-format.rst @@ -753,10 +753,44 @@ Property :widths: 1, 1, 4 name, string, "Name of the property" - type, string, "Type of the property (``string`` (default), ``int``, ``float``, ``bool``, ``color``, ``file``, ``object`` or ``class`` (since 0.16, with ``color`` and ``file`` added in 0.17, ``object`` added in 1.4 and ``class`` added in 1.8))" + type, string, "Type of the property (``string`` (default), ``int``, ``float``, ``bool``, ``color``, ``file``, ``object``, ``class`` or ``list`` (since 0.16, with ``color`` and ``file`` added in 0.17, ``object`` added in 1.4, ``class`` added in 1.8 and ``list`` added in 1.12))" propertytype, string, "Name of the :ref:`custom property type `, when applicable (since 1.8)" value, value, "Value of the property" +When the type is ``list``, the ``value`` is an array storing each item of the +list as an object with ``type``, ``value`` and (when applicable) +``propertytype`` fields, like a property without a name. Class items store +their set members as a JSON object, and list items store their values as a +nested array. + +Example of a list property with a nested list: + +.. code:: json + + { + "name":"list property", + "type":"list", + "value":[ + { + "type":"int", + "value":10 + }, + { + "type":"string", + "value":"text" + }, + { + "type":"list", + "value":[ + { + "type":"bool", + "value":true + } + ] + } + ] + } + .. _json-point: Point @@ -784,6 +818,10 @@ Tiled 1.12 * Added ``opacity`` property to :ref:`json-object`. +* Added ``list`` as a possible type of :ref:`json-property`. The ``value`` of + a list property is an array storing each item as an object with ``type``, + ``propertytype`` and ``value`` fields. + Tiled 1.11.1 ~~~~~~~~~~~~ diff --git a/docs/reference/tmx-changelog.rst b/docs/reference/tmx-changelog.rst index e9df9a678c..075ef7341f 100644 --- a/docs/reference/tmx-changelog.rst +++ b/docs/reference/tmx-changelog.rst @@ -7,7 +7,7 @@ Below are described the changes/additions that were made to the Tiled 1.12 ---------- -- Added ``mode`` attribute on :ref:`tmx-layer` to specific its blend mode. +- Added ``mode`` attribute on :ref:`tmx-layer` to specify its blend mode. - Added ``oblique`` to the supported values for the ``orientation`` attribute on the :ref:`tmx-map` element, along with the ``skewx`` and ``skewy`` @@ -22,7 +22,11 @@ Tiled 1.12 -- Added ``opacity`` attribute to :ref:`tmx-object` to specificy its opacity. +- Added ``opacity`` attribute to :ref:`tmx-object` to specify its opacity. + +- Added ``list`` to the supported values for the ``type`` attribute on the + :ref:`tmx-property` element. Each value of a list property is stored in a + nested :ref:`item ` element. Tiled 1.10 diff --git a/docs/reference/tmx-map-format.rst b/docs/reference/tmx-map-format.rst index a5c64c2453..0fb25d46e0 100644 --- a/docs/reference/tmx-map-format.rst +++ b/docs/reference/tmx-map-format.rst @@ -755,9 +755,9 @@ Can contain any number: :ref:`tmx-property` - **name:** The name of the property. - **type:** The type of the property. Can be ``string`` (default), ``int``, - ``float``, ``bool``, ``color``, ``file``, ``object`` or ``class`` (since - 0.16, with ``color`` and ``file`` added in 0.17, ``object`` added in 1.4 and - ``class`` added in 1.8). + ``float``, ``bool``, ``color``, ``file``, ``object``, ``class`` or ``list`` + (since 0.16, with ``color`` and ``file`` added in 0.17, ``object`` added in + 1.4, ``class`` added in 1.8 and ``list`` added in 1.12). - **propertytype:** The name of the :ref:`custom property type `, when applicable (since 1.8). @@ -781,6 +781,9 @@ Class properties will have their member values stored in a nested :ref:`tmx-properties` element. Only the actually set members are saved. When no members have been set the ``properties`` element is left out entirely. +List properties store each of their values in a nested :ref:`tmx-item` +element and have no ``value`` attribute of their own. + When a string property contains newlines, the current version of Tiled will write out the value as characters contained inside the ``property`` element rather than as the ``value`` attribute. It is possible that a @@ -789,6 +792,41 @@ values inside the element rather than as an attribute. Can contain at most one: :ref:`tmx-properties` (since 1.8) +Can contain any number: :ref:`tmx-item` (since 1.12) + +.. _tmx-item: + + +~~~~~~ + +- **type:** The type of the value. Same as the ``type`` attribute on the + :ref:`tmx-property` element (default ``string``). +- **propertytype:** The name of the + :ref:`custom property type `, when applicable. +- **value:** The value of this item. + +Stores one value of a ``list`` property (since 1.12). Apart from having no +``name`` attribute, an item is structured like a :ref:`tmx-property` element: +``class`` items store their set members in a nested :ref:`tmx-properties` +element, ``list`` items contain their own ``item`` elements and multiline +strings are written as characters contained inside the ``item`` element. + +Example of a list property with a nested list: + +.. code:: xml + + + + + + + + + +Can contain at most one: :ref:`tmx-properties` + +Can contain any number: :ref:`tmx-item` + .. _tmx-template-files: Template Files diff --git a/src/tiled/changemapobject.cpp b/src/tiled/changemapobject.cpp index c2803a6f35..eb80cb7434 100644 --- a/src/tiled/changemapobject.cpp +++ b/src/tiled/changemapobject.cpp @@ -256,7 +256,8 @@ void ResetInstances::redo() for (auto object : mMapObjects) { // Template instances initially don't hold any custom properties - object->clearProperties(); + if (!object->properties().isEmpty()) + mDocument->setProperties(object, Properties()); affectedProperties |= object->changedProperties(); @@ -266,9 +267,6 @@ void ResetInstances::redo() } emit mDocument->changed(MapObjectsChangeEvent(mMapObjects, affectedProperties)); - - // This signal forces updating custom properties in the properties dock -// emit mMapDocument->selectedObjectsChanged(); } void ResetInstances::undo() @@ -276,8 +274,14 @@ void ResetInstances::undo() MapObject::ChangedProperties affectedProperties = MapObject::CustomProperties; for (int i = 0; i < mMapObjects.size(); ++i) { - mMapObjects.at(i)->copyPropertiesFrom(mOldMapObjects.at(i)); - affectedProperties |= mOldMapObjects.at(i)->changedProperties(); + MapObject *object = mMapObjects.at(i); + const MapObject *oldObject = mOldMapObjects.at(i); + + object->copyPropertiesFrom(oldObject); + affectedProperties |= oldObject->changedProperties(); + + if (!oldObject->properties().isEmpty()) + emit mDocument->propertiesChanged(object); } emit mDocument->changed(MapObjectsChangeEvent(mMapObjects, affectedProperties)); @@ -314,6 +318,9 @@ void ReplaceObjectsWithTemplate::redo() } emit mDocument->changed(MapObjectsChangeEvent(mMapObjects, MapObject::AllProperties)); + + for (MapObject *object : std::as_const(mMapObjects)) + emit mDocument->propertiesChanged(object); } void ReplaceObjectsWithTemplate::undo() @@ -322,4 +329,7 @@ void ReplaceObjectsWithTemplate::undo() mMapObjects.at(i)->copyPropertiesFrom(mOldMapObjects.at(i)); emit mDocument->changed(MapObjectsChangeEvent(mMapObjects, MapObject::AllProperties)); + + for (MapObject *object : std::as_const(mMapObjects)) + emit mDocument->propertiesChanged(object); }