Search in sources :

Example 31 with ResourceUrn

use of org.terasology.gestalt.assets.ResourceUrn in project Terasology by MovingBlocks.

the class LocalPlayerSystem method onFrobButton.

@ReceiveEvent(components = CharacterComponent.class)
public void onFrobButton(FrobButton event, EntityRef character) {
    if (event.getState() != ButtonState.DOWN) {
        return;
    }
    ResourceUrn activeInteractionScreenUri = InteractionUtil.getActiveInteractionScreenUri(character);
    if (activeInteractionScreenUri != null) {
        InteractionUtil.cancelInteractionAsClient(character);
        return;
    }
    boolean activeRequestSent = localPlayer.activateTargetAsClient();
    if (activeRequestSent) {
        event.consume();
    }
}
Also used : ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 32 with ResourceUrn

use of org.terasology.gestalt.assets.ResourceUrn in project Terasology by MovingBlocks.

the class NUIManagerInternal method closeScreen.

@Override
public void closeScreen(UIScreenLayer screen) {
    if (screens.remove(screen)) {
        ResourceUrn screenUri = screenLookup.inverse().remove(screen);
        onCloseScreen(screen, screenUri, true);
    }
}
Also used : ResourceUrn(org.terasology.gestalt.assets.ResourceUrn)

Example 33 with ResourceUrn

use of org.terasology.gestalt.assets.ResourceUrn in project Terasology by MovingBlocks.

the class NUIManagerInternal method refreshWidgetsLibrary.

public void refreshWidgetsLibrary() {
    widgetsLibrary = new WidgetLibrary(context.get(ModuleManager.class).getEnvironment(), context.get(ReflectFactory.class), context.get(CopyStrategyLibrary.class));
    ModuleEnvironment environment = context.get(ModuleManager.class).getEnvironment();
    for (Class<? extends UIWidget> type : environment.getSubtypesOf(UIWidget.class)) {
        Name module = verifyNotNull(environment.getModuleProviding(type), "No module provides %s", type);
        widgetsLibrary.register(new ResourceUrn(module.toString(), type.getSimpleName()), type);
    }
}
Also used : ModuleEnvironment(org.terasology.gestalt.module.ModuleEnvironment) WidgetLibrary(org.terasology.nui.reflection.WidgetLibrary) TypeWidgetLibrary(org.terasology.nui.widgets.types.TypeWidgetLibrary) ModuleManager(org.terasology.engine.core.module.ModuleManager) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) Name(org.terasology.gestalt.naming.Name)

Example 34 with ResourceUrn

use of org.terasology.gestalt.assets.ResourceUrn in project Terasology by MovingBlocks.

the class NUIEditorScreen method resetStateInternal.

/**
 * {@inheritDoc}
 */
@Override
protected void resetStateInternal(JsonTree node) {
    getEditor().setTreeViewModel(node, true);
    resetPreviewWidget();
    getEditor().clearHistory();
    updateConfig();
    selectedAsset = selectedAssetPending;
    try {
        ResourceUrn urn = new ResourceUrn(selectedAsset);
        setSelectedAssetPath(urn);
    } catch (InvalidUrnException ignored) {
    }
}
Also used : InvalidUrnException(org.terasology.gestalt.assets.exceptions.InvalidUrnException) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn)

Example 35 with ResourceUrn

use of org.terasology.gestalt.assets.ResourceUrn in project Terasology by MovingBlocks.

the class NUIEditorScreen method initialise.

@Override
public void initialise() {
    // Retrieve the widgets based on their identifiers.
    UIDropdownScrollable<String> availableAssetDropdown = find(AVAILABLE_ASSETS_ID, UIDropdownScrollable.class);
    JsonEditorTreeView editor = find(EDITOR_TREE_VIEW_ID, JsonEditorTreeView.class);
    selectedScreenBox = find(SELECTED_SCREEN_ID, UIBox.class);
    super.setEditorSystem(nuiEditorSystem);
    super.setEditor(editor);
    // Populate the list of screens.
    List<String> availableAssetList = Lists.newArrayList();
    availableAssetList.add(CREATE_NEW_SCREEN);
    availableAssetList.addAll(assetManager.getAvailableAssets(UIElement.class).stream().map(Object::toString).collect(Collectors.toList()));
    Collections.sort(availableAssetList);
    if (availableAssetDropdown != null) {
        availableAssetDropdown.setOptions(availableAssetList);
        availableAssetDropdown.bindSelection(new Binding<String>() {

            @Override
            public String get() {
                return selectedAsset;
            }

            @Override
            public void set(String value) {
                // Construct a new screen tree (or de-serialize from an existing asset)
                selectedAssetPending = value;
                if (CREATE_NEW_SCREEN.equals(value)) {
                    selectedAssetPath = null;
                    resetState(NUIEditorNodeUtils.createNewScreen());
                } else {
                    selectAsset(new ResourceUrn(value));
                }
            }
        });
    }
    if (editor != null) {
        editor.subscribeTreeViewUpdate(() -> {
            getEditor().addToHistory();
            resetPreviewWidget();
            updateConfig();
            setUnsavedChangesPresent(true);
            updateAutosave();
        });
        editor.setContextMenuTreeProducer(node -> {
            NUIEditorMenuTreeBuilder nuiEditorMenuTreeBuilder = new NUIEditorMenuTreeBuilder();
            nuiEditorMenuTreeBuilder.setManager(getManager());
            nuiEditorMenuTreeBuilder.putConsumer(NUIEditorMenuTreeBuilder.OPTION_COPY, getEditor()::copyNode);
            nuiEditorMenuTreeBuilder.putConsumer(NUIEditorMenuTreeBuilder.OPTION_PASTE, getEditor()::pasteNode);
            nuiEditorMenuTreeBuilder.putConsumer(NUIEditorMenuTreeBuilder.OPTION_EDIT, this::editNode);
            nuiEditorMenuTreeBuilder.putConsumer(NUIEditorMenuTreeBuilder.OPTION_DELETE, getEditor()::deleteNode);
            nuiEditorMenuTreeBuilder.putConsumer(NUIEditorMenuTreeBuilder.OPTION_ADD_WIDGET, this::addWidget);
            nuiEditorMenuTreeBuilder.subscribeAddContextMenu(n -> {
                getEditor().fireUpdateListeners();
                // Automatically edit a node that's been added.
                if (n.getValue().getType() == JsonTreeValue.Type.KEY_VALUE_PAIR) {
                    getEditor().getModel().getNode(getEditor().getSelectedIndex()).setExpanded(true);
                    getEditor().getModel().resetNodes();
                    getEditor().setSelectedIndex(getEditor().getModel().indexOf(n));
                    editNode(n);
                }
            });
            return nuiEditorMenuTreeBuilder.createPrimaryContextMenu(node);
        });
        editor.setEditor(this::editNode, getManager());
    }
    UIButton save = find("save", UIButton.class);
    save.bindEnabled(new ReadOnlyBinding<Boolean>() {

        @Override
        public Boolean get() {
            return CREATE_NEW_SCREEN.equals(selectedAsset) || areUnsavedChangesPresent();
        }
    });
    save.subscribe(button -> {
        // Save the current look and feel.
        LookAndFeel currentLookAndFeel = UIManager.getLookAndFeel();
        // (Temporarily) set the look and feel to the system default.
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (ClassNotFoundException | IllegalAccessException | InstantiationException | UnsupportedLookAndFeelException ignored) {
        }
        // Configure the file chooser.
        JFileChooser fileChooser = new JFileChooser() {

            @Override
            protected JDialog createDialog(Component parent) {
                JDialog dialog = super.createDialog(parent);
                dialog.setLocationByPlatform(true);
                dialog.setAlwaysOnTop(true);
                return dialog;
            }
        };
        fileChooser.setSelectedFile(new File(CREATE_NEW_SCREEN.equals(selectedAsset) ? "untitled.ui" : selectedAsset.split(":")[1] + ".ui"));
        fileChooser.setFileFilter(new FileNameExtensionFilter("UI asset file (*.ui)", "ui"));
        if (fileChooser.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) {
            saveToFile(fileChooser.getSelectedFile());
            deleteAutosave();
        }
        // Reload the look and feel.
        try {
            UIManager.setLookAndFeel(currentLookAndFeel);
        } catch (UnsupportedLookAndFeelException ignored) {
        }
    });
    UIButton override = find("override", UIButton.class);
    override.bindEnabled(new ReadOnlyBinding<Boolean>() {

        @Override
        public Boolean get() {
            return selectedAssetPath != null && areUnsavedChangesPresent();
        }
    });
    override.subscribe(button -> {
        saveToFile(selectedAssetPath);
        deleteAutosave();
    });
    // Set the handlers for the editor buttons.
    WidgetUtil.trySubscribe(this, "settings", button -> getManager().pushScreen(NUIEditorSettingsScreen.ASSET_URI, NUIEditorSettingsScreen.class));
    WidgetUtil.trySubscribe(this, "copy", button -> copyJson());
    WidgetUtil.trySubscribe(this, "paste", button -> pasteJson());
    WidgetUtil.trySubscribe(this, "undo", button -> undo());
    WidgetUtil.trySubscribe(this, "redo", button -> redo());
    WidgetUtil.trySubscribe(this, "close", button -> nuiEditorSystem.toggleEditor());
    updateConfig();
}
Also used : UIBox(org.terasology.nui.widgets.UIBox) LookAndFeel(javax.swing.LookAndFeel) UIButton(org.terasology.nui.widgets.UIButton) JsonEditorTreeView(org.terasology.engine.rendering.nui.widgets.JsonEditorTreeView) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) Component(java.awt.Component) NUIEditorMenuTreeBuilder(org.terasology.engine.rendering.nui.editor.utils.NUIEditorMenuTreeBuilder) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) UnsupportedLookAndFeelException(javax.swing.UnsupportedLookAndFeelException) JFileChooser(javax.swing.JFileChooser) AssetDataFile(org.terasology.gestalt.assets.format.AssetDataFile) File(java.io.File) JDialog(javax.swing.JDialog)

Aggregations

ResourceUrn (org.terasology.gestalt.assets.ResourceUrn)90 Test (org.junit.jupiter.api.Test)19 Name (org.terasology.gestalt.naming.Name)12 BeforeEach (org.junit.jupiter.api.BeforeEach)11 BlockFamilyDefinitionData (org.terasology.engine.world.block.loader.BlockFamilyDefinitionData)10 IOException (java.io.IOException)9 AssetManager (org.terasology.gestalt.assets.management.AssetManager)9 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)8 Prefab (org.terasology.engine.entitySystem.prefab.Prefab)8 PrefabData (org.terasology.engine.entitySystem.prefab.PrefabData)7 Command (org.terasology.engine.logic.console.commandSystem.annotations.Command)7 BlockUri (org.terasology.engine.world.block.BlockUri)7 AssetDataFile (org.terasology.gestalt.assets.format.AssetDataFile)7 Texture (org.terasology.engine.rendering.assets.texture.Texture)5 BlockManagerImpl (org.terasology.engine.world.block.internal.BlockManagerImpl)5 BlockFamilyDefinition (org.terasology.engine.world.block.loader.BlockFamilyDefinition)5 NullWorldAtlas (org.terasology.engine.world.block.tiles.NullWorldAtlas)5 ExtraBlockDataManager (org.terasology.engine.world.chunks.blockdata.ExtraBlockDataManager)5 StringComponent (org.terasology.unittest.stubs.StringComponent)5 ByteBuffer (java.nio.ByteBuffer)4