Search in sources :

Example 1 with ScrollableArea

use of org.terasology.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);
    fetchTelemetryCategoriesFromEngineOnlyEnvironment();
    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.nui.layouts.ScrollableArea) ColumnLayout(org.terasology.nui.layouts.ColumnLayout) Metric(org.terasology.engine.telemetry.metrics.Metric) Map(java.util.Map)

Example 2 with ScrollableArea

use of org.terasology.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.nui.widgets.UILabel) Message(org.terasology.engine.logic.console.Message) ScrollableArea(org.terasology.nui.layouts.ScrollableArea) UIText(org.terasology.nui.widgets.UIText) Stream(java.util.stream.Stream) Name(org.terasology.gestalt.naming.Name)

Example 3 with ScrollableArea

use of org.terasology.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.engine.rendering.nui.animation.SwipeMenuAnimationSystem) Message(org.terasology.engine.logic.console.Message) ScrollableArea(org.terasology.nui.layouts.ScrollableArea) UIText(org.terasology.nui.widgets.UIText) List(java.util.List)

Example 4 with ScrollableArea

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

the class CoreScreenLayer method iterateThrough.

private void iterateThrough(Iterator<UIWidget> widgets) {
    modifyingList = true;
    while (widgets.hasNext()) {
        UIWidget next = widgets.next();
        boolean setParent = false;
        if (next instanceof ScrollableArea) {
            parentToSet = (ScrollableArea) next;
        }
        if (next instanceof WidgetWithOrder) {
            TabbingManager.addToWidgetsList((WidgetWithOrder) next);
            TabbingManager.addToUsedNums(((WidgetWithOrder) next).getOrder());
            ((WidgetWithOrder) next).setParent(parentToSet);
        }
        if (next.iterator().hasNext()) {
            iterateThrough(next.iterator());
        } else if (next instanceof UIRadialRing) {
            Iterator<UIRadialSection> iter = ((UIRadialRing) next).getSections().iterator();
            while (iter.hasNext()) {
                next = iter.next();
                TabbingManager.addToWidgetsList((WidgetWithOrder) next);
                TabbingManager.addToUsedNums(((WidgetWithOrder) next).getOrder());
                if (setParent) {
                    ((WidgetWithOrder) next).setParent(parentToSet);
                }
            }
        }
    }
    modifyingList = false;
}
Also used : ScrollableArea(org.terasology.nui.layouts.ScrollableArea) Iterator(java.util.Iterator) UIRadialRing(org.terasology.nui.widgets.UIRadialRing) WidgetWithOrder(org.terasology.nui.WidgetWithOrder) UIWidget(org.terasology.nui.UIWidget)

Aggregations

ScrollableArea (org.terasology.nui.layouts.ScrollableArea)4 Message (org.terasology.engine.logic.console.Message)2 UIText (org.terasology.nui.widgets.UIText)2 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 Stream (java.util.stream.Stream)1 SwipeMenuAnimationSystem (org.terasology.engine.rendering.nui.animation.SwipeMenuAnimationSystem)1 Metric (org.terasology.engine.telemetry.metrics.Metric)1 Name (org.terasology.gestalt.naming.Name)1 UIWidget (org.terasology.nui.UIWidget)1 WidgetWithOrder (org.terasology.nui.WidgetWithOrder)1 ColumnLayout (org.terasology.nui.layouts.ColumnLayout)1 UILabel (org.terasology.nui.widgets.UILabel)1 UIRadialRing (org.terasology.nui.widgets.UIRadialRing)1