Search in sources :

Example 1 with InspectionToolComponent

use of org.terasology.logic.common.InspectionToolComponent in project Terasology by MovingBlocks.

the class InspectionScreen method updateFields.

private void updateFields(EntityRef interactionTarget) {
    InspectionToolComponent inspectorComponent = interactionTarget.getComponent(InspectionToolComponent.class);
    EntityRef inspectedEntity = inspectorComponent.inspectedEntity;
    entityIdField.setText(Long.toString(inspectedEntity.getId()));
    if (inspectedEntity.exists()) {
        if (inspectedEntity.isActive()) {
            fullDescriptionLabel.setText(inspectedEntity.toFullDescription());
        } else {
            fullDescriptionLabel.setText("not active: " + inspectedEntity.toFullDescription());
        }
    } else {
        fullDescriptionLabel.setText("Non existing entity with id " + inspectedEntity.getId());
    }
}
Also used : InspectionToolComponent(org.terasology.logic.common.InspectionToolComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef)

Example 2 with InspectionToolComponent

use of org.terasology.logic.common.InspectionToolComponent in project Terasology by MovingBlocks.

the class InspectionScreen method initialise.

@Override
public void initialise() {
    fullDescriptionLabel = find("fullDescriptionLabel", UIText.class);
    entityIdField = find("entityIdField", UIText.class);
    setEntityIdButton = find("setEntityIdButton", UIButton.class);
    setEntityIdButton.subscribe(widget -> {
        String text = entityIdField.getText();
        EntityRef interactionTarget = getInteractionTarget();
        InspectionToolComponent inspectorComponent = interactionTarget.getComponent(InspectionToolComponent.class);
        if (text.equals("this")) {
            inspectorComponent.inspectedEntity = interactionTarget;
        } else {
            try {
                int id1 = Integer.parseInt(text);
                inspectorComponent.inspectedEntity = CoreRegistry.get(EntityManager.class).getEntity(id1);
            } catch (NumberFormatException e) {
                fullDescriptionLabel.setText("Please specify a valid number");
            }
        }
        updateFields(interactionTarget);
    });
}
Also used : UIButton(org.terasology.rendering.nui.widgets.UIButton) InspectionToolComponent(org.terasology.logic.common.InspectionToolComponent) UIText(org.terasology.rendering.nui.widgets.UIText) EntityRef(org.terasology.entitySystem.entity.EntityRef)

Aggregations

EntityRef (org.terasology.entitySystem.entity.EntityRef)2 InspectionToolComponent (org.terasology.logic.common.InspectionToolComponent)2 UIButton (org.terasology.rendering.nui.widgets.UIButton)1 UIText (org.terasology.rendering.nui.widgets.UIText)1