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);
}
}
}
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);
}
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();
}
}
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";
}
}
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);
}
}
Aggregations