Search in sources :

Example 11 with UIWidget

use of org.terasology.nui.UIWidget in project Terasology by MovingBlocks.

the class NUIManagerInternal method createScreen.

@Override
public <T extends CoreScreenLayer> T createScreen(ResourceUrn screenUri, Class<T> expectedType) {
    boolean existsAlready = !screenUri.isInstance() && assetManager.isLoaded(screenUri, UIElement.class);
    Optional<UIElement> opt = Assets.get(screenUri, UIElement.class);
    if (!opt.isPresent()) {
        logger.error("Can't find screen '{}'", screenUri);
    } else {
        UIElement element = opt.get();
        UIWidget root = element.getRootWidget();
        if (expectedType.isInstance(root)) {
            T screen = expectedType.cast(root);
            if (!existsAlready) {
                initialiseScreen(screen, screenUri);
            }
            return screen;
        } else {
            logger.error("Screen '{}' is a '{}' and not a '{}'", screenUri, root.getClass(), expectedType);
        }
    }
    return null;
}
Also used : UIElement(org.terasology.nui.asset.UIElement) UIWidget(org.terasology.nui.UIWidget)

Example 12 with UIWidget

use of org.terasology.nui.UIWidget in project Terasology by MovingBlocks.

the class NUIManagerInternal method addOverlay.

@Override
public <T extends ControlWidget> T addOverlay(ResourceUrn overlayUri, Class<T> expectedType) {
    boolean existsAlready = assetManager.isLoaded(overlayUri, UIElement.class);
    Optional<UIElement> opt = Assets.get(overlayUri, UIElement.class);
    if (!opt.isPresent()) {
        logger.error("Can't find overlay '{}'", overlayUri);
    } else {
        UIElement element = opt.get();
        UIWidget root = element.getRootWidget();
        if (expectedType.isInstance(root)) {
            T overlay = expectedType.cast(root);
            if (!existsAlready) {
                initialiseControlWidget(overlay, overlayUri);
            }
            addOverlay(overlay, overlayUri);
            return overlay;
        } else {
            logger.error("Screen '{}' is a '{}' and not a '{}'", overlayUri, root.getClass(), expectedType);
        }
    }
    return null;
}
Also used : UIElement(org.terasology.nui.asset.UIElement) UIWidget(org.terasology.nui.UIWidget)

Example 13 with UIWidget

use of org.terasology.nui.UIWidget in project Terasology by MovingBlocks.

the class CoreScreenLayer method update.

@Override
public void update(float delta) {
    if (contents != null) {
        if (!TabbingManager.isInitialized()) {
            TabbingManager.init();
            // TODO: Tabbing
            // TabbingManager.setOpenScreen(this);
            Iterator<UIWidget> widgets = contents.iterator();
            iterateThrough(widgets);
        }
        // TODO: Tabbing
        /*if (TabbingManager.getOpenScreen() == null) {
                TabbingManager.setOpenScreen(this);

                Iterator<UIWidget> widgets = contents.iterator();
                iterateThrough(widgets);

            }*/
        contents.update(delta);
        animationSystem.update(delta);
        if (depth == SortOrderSystem.DEFAULT_DEPTH) {
            setDepthAuto();
        }
        if (activateBindEvent) {
            onBindEvent(new NUIBindButtonEvent(null, null, "engine:tabbingUI", ButtonState.DOWN));
        }
    }
}
Also used : NUIBindButtonEvent(org.terasology.nui.events.NUIBindButtonEvent) UIWidget(org.terasology.nui.UIWidget)

Example 14 with UIWidget

use of org.terasology.nui.UIWidget 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

UIWidget (org.terasology.nui.UIWidget)14 UIElement (org.terasology.nui.asset.UIElement)4 UILabel (org.terasology.nui.widgets.UILabel)3 JsonTree (org.terasology.nui.widgets.treeView.JsonTree)3 JsonElement (com.google.gson.JsonElement)2 Optional (java.util.Optional)2 UIFormat (org.terasology.engine.rendering.nui.asset.UIFormat)2 DefaultBinding (org.terasology.nui.databinding.DefaultBinding)2 ColumnLayout (org.terasology.nui.layouts.ColumnLayout)2 UIButton (org.terasology.nui.widgets.UIButton)2 UIDropdownScrollable (org.terasology.nui.widgets.UIDropdownScrollable)2 Defaults (com.google.common.base.Defaults)1 JsonParser (com.google.gson.JsonParser)1 JsonReader (com.google.gson.stream.JsonReader)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStreamReader (java.io.InputStreamReader)1 Constructor (java.lang.reflect.Constructor)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Parameter (java.lang.reflect.Parameter)1 ArrayList (java.util.ArrayList)1