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