Search in sources :

Example 1 with ScrollableArea

use of org.terasology.rendering.nui.layouts.ScrollableArea in project Terasology by MovingBlocks.

the class ChatScreen method initialise.

@Override
public void initialise() {
    final ScrollableArea scrollArea = find("scrollArea", ScrollableArea.class);
    scrollArea.moveToBottom();
    commandLine = find("commandLine", UIText.class);
    getManager().setFocus(commandLine);
    commandLine.subscribe(widget -> {
        String text = commandLine.getText();
        if (StringUtils.isNotBlank(text)) {
            String command = "say";
            List<String> params = Collections.singletonList(text);
            // TODO: move command execution to separate class
            console.execute(new Name(command), params, localPlayer.getClientEntity());
            commandLine.setText("");
            scrollArea.moveToBottom();
            NotificationOverlay overlay = nuiManager.addOverlay(NotificationOverlay.ASSET_URI, NotificationOverlay.class);
            overlay.setVisible(true);
            nuiManager.closeScreen(this);
        } else {
            commandLine.setText("");
            nuiManager.closeScreen(this);
        }
    });
    final UILabel history = find("messageHistory", UILabel.class);
    history.bindText(new ReadOnlyBinding<String>() {

        @Override
        public String get() {
            Iterable<Message> messageIterable = console.getMessages(CoreMessageType.CHAT, CoreMessageType.NOTIFICATION);
            Stream<Message> messageStream = StreamSupport.stream(messageIterable.spliterator(), false);
            return messageStream.map(Message::getMessage).collect(Collectors.joining(Console.NEW_LINE));
        }
    });
}
Also used : UILabel(org.terasology.rendering.nui.widgets.UILabel) Message(org.terasology.logic.console.Message) ScrollableArea(org.terasology.rendering.nui.layouts.ScrollableArea) UIText(org.terasology.rendering.nui.widgets.UIText) Stream(java.util.stream.Stream) Name(org.terasology.naming.Name)

Example 2 with ScrollableArea

use of org.terasology.rendering.nui.layouts.ScrollableArea in project Terasology by MovingBlocks.

the class TelemetryScreen method refreshContent.

private void refreshContent() {
    ColumnLayout mainLayout = new ColumnLayout();
    mainLayout.setHorizontalSpacing(8);
    mainLayout.setVerticalSpacing(8);
    fetchTelemetryCategoriesFromEnvironment();
    for (Map.Entry<TelemetryCategory, Class> telemetryCategory : telemetryCategories.entrySet()) {
        Class metricClass = telemetryCategory.getValue();
        Optional<Metric> optional = metrics.getMetric(metricClass);
        if (optional.isPresent()) {
            Metric metric = optional.get();
            Map<String, ?> map = metric.createTelemetryFieldToValue();
            if (map != null) {
                addTelemetrySection(telemetryCategory.getKey(), mainLayout, map);
            }
        }
    }
    ScrollableArea area = find("area", ScrollableArea.class);
    if (area != null) {
        area.setContent(mainLayout);
    }
}
Also used : ScrollableArea(org.terasology.rendering.nui.layouts.ScrollableArea) ColumnLayout(org.terasology.rendering.nui.layouts.ColumnLayout) Metric(org.terasology.telemetry.metrics.Metric) Map(java.util.Map)

Example 3 with ScrollableArea

use of org.terasology.rendering.nui.layouts.ScrollableArea in project Terasology by MovingBlocks.

the class InputSettingsScreen method initialise.

@Override
public void initialise() {
    setAnimationSystem(MenuAnimationSystems.createDefaultSwipeAnimation());
    ColumnLayout mainLayout = new ColumnLayout();
    mainLayout.setHorizontalSpacing(8);
    mainLayout.setVerticalSpacing(8);
    mainLayout.setFamily("option-grid");
    UISlider mouseSensitivity = new UISlider("mouseSensitivity");
    mouseSensitivity.bindValue(BindHelper.bindBeanProperty("mouseSensitivity", inputDeviceConfiguration, Float.TYPE));
    mouseSensitivity.setIncrement(0.025f);
    mouseSensitivity.setPrecision(3);
    UICheckbox mouseInverted = new UICheckbox("mouseYAxisInverted");
    mouseInverted.bindChecked(BindHelper.bindBeanProperty("mouseYAxisInverted", inputDeviceConfiguration, Boolean.TYPE));
    mainLayout.addWidget(new UILabel("mouseLabel", "subheading", translationSystem.translate("${engine:menu#category-mouse}")));
    mainLayout.addWidget(new RowLayout(new UILabel(translationSystem.translate("${engine:menu#mouse-sensitivity}") + ":"), mouseSensitivity).setColumnRatios(0.4f).setHorizontalSpacing(horizontalSpacing));
    mainLayout.addWidget(new RowLayout(new UILabel(translationSystem.translate("${engine:menu#invert-mouse}") + ":"), mouseInverted).setColumnRatios(0.4f).setHorizontalSpacing(horizontalSpacing));
    Map<String, InputCategory> inputCategories = Maps.newHashMap();
    Map<SimpleUri, RegisterBindButton> inputsById = Maps.newHashMap();
    DependencyResolver resolver = new DependencyResolver(moduleManager.getRegistry());
    for (Name moduleId : moduleManager.getRegistry().getModuleIds()) {
        Module module = moduleManager.getRegistry().getLatestModuleVersion(moduleId);
        if (module.isCodeModule()) {
            ResolutionResult result = resolver.resolve(moduleId);
            if (result.isSuccess()) {
                try (ModuleEnvironment environment = moduleManager.loadEnvironment(result.getModules(), false)) {
                    for (Class<?> holdingType : environment.getTypesAnnotatedWith(InputCategory.class, new FromModule(environment, moduleId))) {
                        InputCategory inputCategory = holdingType.getAnnotation(InputCategory.class);
                        inputCategories.put(module.getId() + ":" + inputCategory.id(), inputCategory);
                    }
                    for (Class<?> bindEvent : environment.getTypesAnnotatedWith(RegisterBindButton.class, new FromModule(environment, moduleId))) {
                        if (BindButtonEvent.class.isAssignableFrom(bindEvent)) {
                            RegisterBindButton bindRegister = bindEvent.getAnnotation(RegisterBindButton.class);
                            inputsById.put(new SimpleUri(module.getId(), bindRegister.id()), bindRegister);
                        }
                    }
                }
            }
        }
    }
    addInputSection(inputCategories.remove("engine:movement"), mainLayout, inputsById);
    addInputSection(inputCategories.remove("engine:interaction"), mainLayout, inputsById);
    addInputSection(inputCategories.remove("engine:inventory"), mainLayout, inputsById);
    addInputSection(inputCategories.remove("engine:general"), mainLayout, inputsById);
    for (InputCategory category : inputCategories.values()) {
        addInputSection(category, mainLayout, inputsById);
    }
    mainLayout.addWidget(new UISpace(new Vector2i(1, 16)));
    List<String> controllers = inputSystem.getControllerDevice().getControllers();
    for (String name : controllers) {
        ControllerInfo cfg = inputDeviceConfiguration.getController(name);
        addInputSection(mainLayout, name, cfg);
    }
    ScrollableArea area = find("area", ScrollableArea.class);
    area.setContent(mainLayout);
    WidgetUtil.trySubscribe(this, "reset", button -> {
        inputDeviceConfiguration.reset();
        bindsManager.getBindsConfig().setBinds(bindsManager.getDefaultBindsConfig());
    });
    WidgetUtil.trySubscribe(this, "back", button -> triggerBackAnimation());
}
Also used : UILabel(org.terasology.rendering.nui.widgets.UILabel) UISlider(org.terasology.rendering.nui.widgets.UISlider) RegisterBindButton(org.terasology.input.RegisterBindButton) ResolutionResult(org.terasology.module.ResolutionResult) SimpleUri(org.terasology.engine.SimpleUri) UICheckbox(org.terasology.rendering.nui.widgets.UICheckbox) DependencyResolver(org.terasology.module.DependencyResolver) Name(org.terasology.naming.Name) ModuleEnvironment(org.terasology.module.ModuleEnvironment) ScrollableArea(org.terasology.rendering.nui.layouts.ScrollableArea) ColumnLayout(org.terasology.rendering.nui.layouts.ColumnLayout) RowLayout(org.terasology.rendering.nui.layouts.RowLayout) InputCategory(org.terasology.input.InputCategory) UISpace(org.terasology.rendering.nui.widgets.UISpace) Vector2i(org.terasology.math.geom.Vector2i) FromModule(org.terasology.module.predicates.FromModule) Module(org.terasology.module.Module) FromModule(org.terasology.module.predicates.FromModule) ControllerInfo(org.terasology.config.ControllerConfig.ControllerInfo)

Example 4 with ScrollableArea

use of org.terasology.rendering.nui.layouts.ScrollableArea in project Terasology by MovingBlocks.

the class ConsoleScreen method initialise.

@Override
public void initialise() {
    setAnimationSystem(new SwipeMenuAnimationSystem(0.2f, Direction.TOP_TO_BOTTOM));
    final ScrollableArea scrollArea = find("scrollArea", ScrollableArea.class);
    scrollArea.moveToBottom();
    commandLine = find("commandLine", UICommandEntry.class);
    getManager().setFocus(commandLine);
    commandLine.setTabCompletionEngine(new CyclingTabCompletionEngine(console, localPlayer));
    commandLine.bindCommandHistory(new ReadOnlyBinding<List<String>>() {

        @Override
        public List<String> get() {
            return console.getPreviousCommands();
        }
    });
    commandLine.subscribe(widget -> {
        String text = commandLine.getText();
        if (StringUtils.isNotBlank(text)) {
            console.execute(text, localPlayer.getClientEntity());
        }
        scrollArea.moveToBottom();
    });
    final UIText history = find("messageHistory", UIText.class);
    history.bindText(new ReadOnlyBinding<String>() {

        @Override
        public String get() {
            StringBuilder messageList = new StringBuilder();
            for (Message message : console.getMessages()) {
                messageList.append(FontColor.getColored(message.getMessage(), message.getType().getColor()));
                if (message.hasNewLine()) {
                    messageList.append(Console.NEW_LINE);
                }
            }
            return messageList.toString();
        }
    });
}
Also used : SwipeMenuAnimationSystem(org.terasology.rendering.nui.animation.SwipeMenuAnimationSystem) Message(org.terasology.logic.console.Message) ScrollableArea(org.terasology.rendering.nui.layouts.ScrollableArea) UIText(org.terasology.rendering.nui.widgets.UIText) List(java.util.List)

Aggregations

ScrollableArea (org.terasology.rendering.nui.layouts.ScrollableArea)4 Message (org.terasology.logic.console.Message)2 Name (org.terasology.naming.Name)2 ColumnLayout (org.terasology.rendering.nui.layouts.ColumnLayout)2 UILabel (org.terasology.rendering.nui.widgets.UILabel)2 UIText (org.terasology.rendering.nui.widgets.UIText)2 List (java.util.List)1 Map (java.util.Map)1 Stream (java.util.stream.Stream)1 ControllerInfo (org.terasology.config.ControllerConfig.ControllerInfo)1 SimpleUri (org.terasology.engine.SimpleUri)1 InputCategory (org.terasology.input.InputCategory)1 RegisterBindButton (org.terasology.input.RegisterBindButton)1 Vector2i (org.terasology.math.geom.Vector2i)1 DependencyResolver (org.terasology.module.DependencyResolver)1 Module (org.terasology.module.Module)1 ModuleEnvironment (org.terasology.module.ModuleEnvironment)1 ResolutionResult (org.terasology.module.ResolutionResult)1 FromModule (org.terasology.module.predicates.FromModule)1 SwipeMenuAnimationSystem (org.terasology.rendering.nui.animation.SwipeMenuAnimationSystem)1