Search in sources :

Example 1 with Actionable

use of com.b3dgs.lionengine.game.feature.Actionable in project lionengine by b3dgs.

the class Hud method createMenu.

/**
 * Create menu from action and add to active menus.
 *
 * @param action The action used.
 * @return The created menu.
 */
private Actionable createMenu(ActionRef action) {
    Actionable menu = menus.get(action);
    if (menu == null) {
        final Featurable featurable = factory.create(Medias.create(PATH.split(action.getPath())));
        handler.add(featurable);
        menu = featurable.getFeature(Actionable.class);
        menus.put(action, menu);
    }
    menu.setEnabled(true);
    active.add(menu);
    return menu;
}
Also used : Actionable(com.b3dgs.lionengine.game.feature.Actionable) Featurable(com.b3dgs.lionengine.game.feature.Featurable)

Example 2 with Actionable

use of com.b3dgs.lionengine.game.feature.Actionable in project lionengine by b3dgs.

the class HudTest method testListenerCancel.

/**
 * Test cancel with listener.
 */
@Test
void testListenerCancel() {
    final AtomicBoolean canceled = new AtomicBoolean();
    final HudListener listener = new HudListener() {

        @Override
        public void notifyCreated(List<Selectable> selection, Actionable actionable) {
        // Nothing to do
        }

        @Override
        public void notifyCanceled() {
            canceled.set(true);
        }
    };
    final Hud hud = new Hud(services, setup);
    hud.addListener(listener);
    final AtomicBoolean cancel = new AtomicBoolean();
    hud.setCancelShortcut(cancel::get);
    hud.getFeature(Refreshable.class).update(1.0);
    assertFalse(canceled.get());
    cancel.set(true);
    hud.getFeature(Refreshable.class).update(1.0);
    assertTrue(canceled.get());
    assertEquals(0, hud.getActive().size());
    hud.removeListener(listener);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Actionable(com.b3dgs.lionengine.game.feature.Actionable) List(java.util.List) Refreshable(com.b3dgs.lionengine.game.feature.Refreshable) Test(org.junit.jupiter.api.Test)

Aggregations

Actionable (com.b3dgs.lionengine.game.feature.Actionable)2 Featurable (com.b3dgs.lionengine.game.feature.Featurable)1 Refreshable (com.b3dgs.lionengine.game.feature.Refreshable)1 List (java.util.List)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Test (org.junit.jupiter.api.Test)1