Search in sources :

Example 21 with ResourceUrn

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

the class EntitySystemSetupUtil method registerComponents.

static void registerComponents(ComponentLibrary library, ModuleEnvironment environment) {
    for (Class<? extends Component> componentType : environment.getSubtypesOf(Component.class)) {
        if (componentType.getAnnotation(DoNotAutoRegister.class) == null && !componentType.isInterface() && !Modifier.isAbstract(componentType.getModifiers())) {
            String componentName = MetadataUtil.getComponentClassName(componentType);
            Name componentModuleName = verifyNotNull(environment.getModuleProviding(componentType), "Could not find module for %s %s", componentName, componentType);
            library.register(new ResourceUrn(componentModuleName.toString(), componentName), componentType);
        }
    }
}
Also used : DoNotAutoRegister(org.terasology.engine.entitySystem.systems.internal.DoNotAutoRegister) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) Name(org.terasology.gestalt.naming.Name)

Example 22 with ResourceUrn

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

the class LocaleConstraintWidgetFactory method buildWidget.

@Override
protected Optional<UIWidget> buildWidget() {
    Setting<Locale> setting = getSetting();
    Binding<Locale> binding = new Binding<Locale>() {

        @Override
        public Locale get() {
            return setting.get();
        }

        @Override
        public void set(Locale value) {
            setting.set(value);
        }
    };
    UIDropdownScrollable<Locale> dropdownScrollable = new UIDropdownScrollable<>();
    ResourceUrn menuUrn = new ResourceUrn("engine:menu");
    TranslationProject menuProject = translationSystem.getProject(menuUrn);
    List<Locale> locales = new ArrayList<>(menuProject.getAvailableLocales());
    for (Locale languageExcluded : languagesExcluded) {
        locales.remove(languageExcluded);
    }
    Collections.sort(locales, (Comparator.comparing((Function<Object, String>) Object::toString)));
    dropdownScrollable.setOptions(Lists.newArrayList(locales));
    // Set maximum number of options visible for scrolling
    dropdownScrollable.setVisibleOptions(5);
    dropdownScrollable.bindSelection(binding);
    dropdownScrollable.setOptionRenderer(new LocaleRenderer(translationSystem));
    return Optional.of(dropdownScrollable);
}
Also used : Locale(java.util.Locale) Binding(org.terasology.nui.databinding.Binding) LocaleRenderer(org.terasology.engine.rendering.nui.layers.mainMenu.settings.LocaleRenderer) UIDropdownScrollable(org.terasology.nui.widgets.UIDropdownScrollable) ArrayList(java.util.ArrayList) TranslationProject(org.terasology.engine.i18n.TranslationProject) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn)

Example 23 with ResourceUrn

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

the class CoreCommands method setLanguage.

/**
 * Change the UI language
 *
 * @param langTag String containing language code to change
 * @return String containing language or if not recognized error message
 */
@Command(shortDescription = "Changes the UI language")
public String setLanguage(@CommandParam("language-tag") String langTag) {
    Locale locale = Locale.forLanguageTag(langTag);
    TranslationProject proj = translationSystem.getProject(new ResourceUrn("engine:menu"));
    // Try if language exists
    if (proj.getAvailableLocales().contains(locale)) {
        systemConfig.locale.set(locale);
        nuiManager.invalidate();
        String nat = translationSystem.translate("${engine:menu#this-language-native}", locale);
        String eng = translationSystem.translate("${engine:menu#this-language-English}", locale);
        return String.format("Language set to %s (%s)", nat, eng);
    } else {
        return "Unrecognized locale! Try one of: " + proj.getAvailableLocales();
    }
}
Also used : Locale(java.util.Locale) TranslationProject(org.terasology.engine.i18n.TranslationProject) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) Command(org.terasology.engine.logic.console.commandSystem.annotations.Command) ConsoleCommand(org.terasology.engine.logic.console.commandSystem.ConsoleCommand)

Example 24 with ResourceUrn

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

the class CoreCommands method reloadScreen.

/**
 * Reloads ui screen
 *
 * @param ui String containing ui screen name
 * @return String containing Success if UI was reloaded or No unique resource found if more screens were found
 */
@Command(shortDescription = "Reloads a ui screen")
public String reloadScreen(@CommandParam("ui") String ui) {
    Set<ResourceUrn> urns = assetManager.resolve(ui, UIElement.class);
    if (urns.size() == 1) {
        ResourceUrn urn = urns.iterator().next();
        boolean wasOpen = nuiManager.isOpen(urn);
        if (wasOpen) {
            nuiManager.closeScreen(urn);
        }
        if (wasOpen) {
            nuiManager.pushScreen(urn);
        }
        return "Success";
    } else {
        return "No unique resource found";
    }
}
Also used : ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) Command(org.terasology.engine.logic.console.commandSystem.annotations.Command) ConsoleCommand(org.terasology.engine.logic.console.commandSystem.ConsoleCommand)

Example 25 with ResourceUrn

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

the class InteractionSystem method onScreenLayerClosed.

/**
 * The method listens for the event that the user closes the screen of the current interaction target.
 * <p>
 * When it happens then it cancels the interaction.
 */
@ReceiveEvent(components = ClientComponent.class)
public void onScreenLayerClosed(ScreenLayerClosedEvent event, EntityRef container, ClientComponent clientComponent) {
    EntityRef character = clientComponent.character;
    ResourceUrn activeInteractionScreenUri = InteractionUtil.getActiveInteractionScreenUri(character);
    if ((activeInteractionScreenUri != null) && (activeInteractionScreenUri.equals(event.getClosedScreenUri()))) {
        InteractionUtil.cancelInteractionAsClient(clientComponent.character);
    }
}
Also used : ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

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