Search in sources :

Example 1 with CardLayout

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

the class CardLayoutTest method setup.

@BeforeEach
public void setup() {
    cardLayout = new CardLayout();
    widget1 = mock(UIWidget.class);
    widget2 = mock(UIWidget.class);
    widget3 = mock(UIWidget.class);
    canvas = mock(Canvas.class);
    // +-----------------------------------+  +---+  +-------+
    // |                                   |  |1x2|  |       |
    // |               1x1                 |  +---+  |       |
    // |                                   |         |  1x3  |
    // +-----------------------------------+         |       |
    // |       |
    // +-------+
    when(widget1.getPreferredContentSize(eq(canvas), any(Vector2i.class))).thenReturn(new Vector2i(50, 10));
    when(widget2.getPreferredContentSize(eq(canvas), any(Vector2i.class))).thenReturn(new Vector2i(5, 5));
    when(widget3.getPreferredContentSize(eq(canvas), any(Vector2i.class))).thenReturn(new Vector2i(10, 15));
    when(widget1.getId()).thenReturn("widget1");
    when(widget2.getId()).thenReturn("widget2");
    when(widget3.getId()).thenReturn("widget3");
    Vector2i availableSize = new Vector2i(200, 200);
    when(canvas.size()).thenReturn(availableSize);
    cardLayout.addWidget(widget1);
    cardLayout.addWidget(widget2);
    cardLayout.addWidget(widget3);
}
Also used : CardLayout(org.terasology.nui.layouts.CardLayout) Canvas(org.terasology.nui.Canvas) Vector2i(org.joml.Vector2i) UIWidget(org.terasology.nui.UIWidget) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with CardLayout

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

the class JoinGameScreen method initialise.

@Override
public void initialise() {
    setAnimationSystem(MenuAnimationSystems.createDefaultSwipeAnimation());
    downloader = new ServerListDownloader(config.getNetwork().getMasterServer());
    CardLayout cards = find("cards", CardLayout.class);
    UIList<ServerInfo> customServerList = find("customServerList", UIList.class);
    if (customServerList != null) {
        customServerList.setList(config.getNetwork().getServerInfos());
        configureServerList(customServerList);
    }
    UIList<ServerInfo> onlineServerList = find("onlineServerList", UIList.class);
    if (onlineServerList != null) {
        onlineServerList.setList(listedServers);
        configureServerList(onlineServerList);
    }
    ActivateEventListener activateCustom = e -> {
        cards.setDisplayedCard("customServerListScrollArea");
        find("customButton", UIButton.class).setFamily("highlight");
        find("onlineButton", UIButton.class).setFamily("default");
        visibleList = customServerList;
        refresh();
    };
    WidgetUtil.trySubscribe(this, "customButton", activateCustom);
    ActivateEventListener activateOnline = e -> {
        cards.setDisplayedCard("onlineServerListScrollArea");
        find("customButton", UIButton.class).setFamily("default");
        find("onlineButton", UIButton.class).setFamily("highlight");
        visibleList = onlineServerList;
        refresh();
    };
    WidgetUtil.trySubscribe(this, "onlineButton", activateOnline);
    bindCustomButtons();
    bindInfoLabels();
    WidgetUtil.trySubscribe(this, "close", button -> {
        config.save();
        triggerBackAnimation();
    });
    activateOnline.onActivated(null);
}
Also used : BindHelper(org.terasology.nui.databinding.BindHelper) In(org.terasology.engine.registry.In) Color(org.terasology.nui.Color) LoggerFactory(org.slf4j.LoggerFactory) StorageServiceWorker(org.terasology.engine.identity.storageServiceClient.StorageServiceWorker) Collections2(com.google.common.collect.Collections2) WidgetUtil(org.terasology.nui.WidgetUtil) WorldInfo(org.terasology.engine.world.internal.WorldInfo) Future(java.util.concurrent.Future) FontColor(org.terasology.nui.FontColor) Map(java.util.Map) StateLoading(org.terasology.engine.core.modes.StateLoading) ReadOnlyBinding(org.terasology.nui.databinding.ReadOnlyBinding) TranslationSystem(org.terasology.engine.i18n.TranslationSystem) StringTextRenderer(org.terasology.nui.itemRendering.StringTextRenderer) GameEngine(org.terasology.engine.core.GameEngine) CardLayout(org.terasology.nui.layouts.CardLayout) GameThread(org.terasology.engine.core.GameThread) List(java.util.List) Predicate(com.google.common.base.Predicate) NameVersion(org.terasology.gestalt.naming.NameVersion) UIList(org.terasology.nui.widgets.UIList) ServerInfoService(org.terasology.engine.network.ServerInfoService) PlayerConfig(org.terasology.engine.config.PlayerConfig) Joiner(com.google.common.base.Joiner) MenuAnimationSystems(org.terasology.engine.rendering.nui.animation.MenuAnimationSystems) ModuleManager(org.terasology.engine.core.module.ModuleManager) ServerInfoMessage(org.terasology.engine.network.ServerInfoMessage) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) ServerInfo(org.terasology.engine.config.ServerInfo) IntToStringBinding(org.terasology.nui.databinding.IntToStringBinding) ArrayList(java.util.ArrayList) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) ModuleRegistry(org.terasology.gestalt.module.ModuleRegistry) NUIKeyEvent(org.terasology.nui.events.NUIKeyEvent) WorldTime(org.terasology.engine.world.time.WorldTime) PingService(org.terasology.engine.network.PingService) ActivateEventListener(org.terasology.nui.widgets.ActivateEventListener) Logger(org.slf4j.Logger) UILabel(org.terasology.nui.widgets.UILabel) Keyboard(org.terasology.input.Keyboard) IOException(java.io.IOException) CoreScreenLayer(org.terasology.engine.rendering.nui.CoreScreenLayer) ExecutionException(java.util.concurrent.ExecutionException) Config(org.terasology.engine.config.Config) UIButton(org.terasology.nui.widgets.UIButton) JoinStatus(org.terasology.engine.network.JoinStatus) NetworkSystem(org.terasology.engine.network.NetworkSystem) Collections(java.util.Collections) CardLayout(org.terasology.nui.layouts.CardLayout) ActivateEventListener(org.terasology.nui.widgets.ActivateEventListener) ServerInfo(org.terasology.engine.config.ServerInfo)

Aggregations

CardLayout (org.terasology.nui.layouts.CardLayout)2 Joiner (com.google.common.base.Joiner)1 Predicate (com.google.common.base.Predicate)1 Collections2 (com.google.common.collect.Collections2)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Callable (java.util.concurrent.Callable)1 ExecutionException (java.util.concurrent.ExecutionException)1 Future (java.util.concurrent.Future)1 Vector2i (org.joml.Vector2i)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 Config (org.terasology.engine.config.Config)1 PlayerConfig (org.terasology.engine.config.PlayerConfig)1 ServerInfo (org.terasology.engine.config.ServerInfo)1