Learn what Felgo offers to help your business succeed. Start your free evaluation today! Felgo for Your Business

Forums

OverviewFelgo 3 Support (Qt 5) › itemEditor

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #13875

    Alexander

    Hi all.

    How to separately edit in itemeditor new objects which were added by etitybuildbutton

     

    For example: i have an entity – “Wall”. I add some “wall” in level and I need change them height separately

    #13888

    Günther
    Felgo Team

    Hi Alexander!

    The EditableComponent type specifies the properties that will be displayed by the ItemEditor and links the editor settings with the entity. However, it is designed to balance general entity setting for different types of entities. For example, by changing general properties for all walls in the game.

    The only way to use the ItemEditor for modification of properties per instance is with a workaround:

    • Each instance of the entity must use an EditableComponent configuration with a custom editableType. In other words, each entity then has its own type instead of a shared one.

    The following example uses the dynamic entityId for that, which is created by the EntityManager. Whenever a new entity is created or destroyed, the relevant EditableComponent and ItemEditor setup is handled accordingly. Please note that this is not the intended usage: It is still possible that something does not work out as expected, so please thoroughly test everything if you use this solution.

    import Felgo 3.0
    import QtQuick 2.0
    
    GameWindow {
      Scene {
        id: scene
    
        EntityManager {
          id: entityManager
          entityContainer: scene
        }
    
        ItemEditor {
          id: itemEditor
          editableTypes: [] // no item is editable by default
        }
    
        // button to add entities
        ButtonVPlay {
          anchors.centerIn: parent
          text: "Add Entity"
          onClicked: {
            // create new entity
            var entityId = entityManager.createEntityFromComponent(entityComponent)
            var entity = entityManager.getEntityById(entityId)
    
            // allow editing of new entity for itemEditor
            // the unique entityId is used as the editableType to distinguish
            itemEditor.editableTypes.push(entityId)
    
            // dynamically create an EditableComponent to edit the new entity
            // we cannot put the EditableComponent within the EntityBase itself, because the id of the entity
            // (which we use as value for the editableType) is not yet available when the entity is created
            var editComp = perItemEditor.createObject(scene, { "editableType": entityId, "target": entity })
    
            // open the new entity for editing
            itemEditor.currentEditableType = entityId
          }
        }
    
        // the component for dynamic entity creation
        Component {
          id: entityComponent
          EntityBase {
            id: entity
            entityType: "wall"
    
            x: Math.random() * scene.width
            y: Math.random() * scene.height
            width: 30
            height: 30
    
            Rectangle {
              anchors.centerIn: parent
              width: parent.width
              height: parent.height
              color: Qt.hsla(Math.random(), 1.0, 0.5, 1.0)
            }
    
            // when the entity is clicked, we open it for editing
            MouseArea {
              anchors.fill: parent
              onClicked: itemEditor.currentEditableType = entity.entityId
            }
          }
        } // Entity Component
    
        // the component for dynamic creation of EditableComponent
        Component {
          id: perItemEditor
          EditableComponent {
            id: editComp
            targetEditor: itemEditor
            properties: {
              "Entity Properties" : {
                "height":  { "min": 25, "max": 200, "label": "Height" }
              }
            }
    
            // when the target entity is destroyed, we also destroy the object and remove it from the editable types
            Connections {
              target: editComp.target
              onEntityDestroyed: {
                editComp.targetEditor.editableTypes.pop(editComp.editableType) // remove destroyed entity from editable types
                editComp.destroy(); // destroy EditableComponent instance
              }
            }
          }
        } // Editor Component
      }
    }
    

     

     

    Cheers,
    Günther

Viewing 2 posts - 1 through 2 (of 2 total)

RSS feed for this thread

You must be logged in to reply to this topic.

Qt_Technology_Partner_RGB_475 Qt_Service_Partner_RGB_475_padded