com.badlogic.gdx.scenes.scene2d.Group Java Examples

The following examples show how to use com.badlogic.gdx.scenes.scene2d.Group. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DiePane.java    From dice-heroes with GNU General Public License v3.0 6 votes vote down vote up
public DiePane(Die die, UserData userData, Group diceWindowGroup) {
    this.die = die;
    this.userData = userData;
    this.diceWindowGroup = diceWindowGroup;
    shopComparator = Ability.shopComparator(die);
    setTransform(false);

    addActor(splitPane);
    splitPane.clearListeners();

    initInfoPanel();
    initParamsPanel();

    splitPane.setSplitAmount(1f);
    splitPane.setHeight(info.getPrefHeight());
    splitPane.layout();
    setSize(getPrefWidth(), splitPane.getHeight());
    params.setTouchable(Touchable.disabled);
}
 
Example #2
Source File: EffectRosterViewController.java    From gdx-vfx with Apache License 2.0 6 votes vote down vote up
private void addEffectToChain(final EffectEntryModel effectModel) {
    if (effectsChain.containsKey(effectModel)) {
        // If the effect is already in the chain, re-add it to the end of the list.
        removeEffectFromChain(effectModel);
    }

    EffectEntryViewController viewController = new EffectEntryViewController(lmlParser, effectModel);
    Group viewRoot = viewController.getViewRoot();
    vgEffectsChain.addActor(viewRoot);
    effectsChain.put(viewController.getModel(), viewController);
    vfxManager.addEffect(viewController.getModel().getEffect());

    viewRoot.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            removeEffectFromChain(effectModel);
        }
    });
}
 
Example #3
Source File: CocoStudioUIEditor.java    From cocos-ui-libgdx with Apache License 2.0 6 votes vote down vote up
/***
 * 解析节点,创建控件
 *
 * @param parent
 * @param widget
 * @return
 */
public Actor parseWidget(Group parent, ObjectData widget) {

    String className = widget.getCtype();
    BaseWidgetParser parser = parsers.get(className);

    if (parser == null) {
        debug(widget, "not support Widget:" + className);
        return null;
    }
    Actor actor = parser.parse(this, widget);

    actor = parser.commonParse(this, widget, parent, actor);

    return actor;
}
 
Example #4
Source File: CCScrollView.java    From cocos-ui-libgdx with Apache License 2.0 6 votes vote down vote up
@Override
public Group groupChildrenParse(CocoStudioUIEditor editor,
                                ObjectData widget, Group parent, Actor actor) {
    ScrollPane scrollPane = (ScrollPane) actor;
    Table table = new Table();
    for (ObjectData childrenWidget : widget.getChildren()) {
        Actor childrenActor = editor.parseWidget(table, childrenWidget);
        if (childrenActor == null) {
            continue;
        }

        table.setSize(Math.max(table.getWidth(), childrenActor.getRight()),
            Math.max(table.getHeight(), childrenActor.getTop()));
        table.addActor(childrenActor);
    }
    sort(widget, table);
    //

    scrollPane.setWidget(table);

    return scrollPane;
}
 
Example #5
Source File: DialogFreeTypeFont.java    From skin-composer with MIT License 6 votes vote down vote up
private void updateLabelHighlight(String requiredLabelName) {
    var normalStyle = skin.get(Label.LabelStyle.class);
    var requiredStyle = skin.get("dialog-required", Label.LabelStyle.class);
    var actors = new Array<Actor>();
    actors.addAll(getChildren());
    
    for (int i = 0; i < actors.size; i++) {
        var actor = actors.get(i);
        
        if (actor instanceof Group) {
            actors.addAll(((Group) actor).getChildren());
        }
        
        if (actor instanceof Label) {
            Label label = (Label) actor;
            
            if (label.getStyle().equals(requiredStyle)) {
                label.setStyle(normalStyle);
            }
            
            if (requiredLabelName != null && label.getName() != null && label.getName().equals(requiredLabelName)) {
                label.setStyle(requiredStyle);
            }
        }
    }
}
 
Example #6
Source File: CCParticleTest.java    From cocos-ui-libgdx with Apache License 2.0 6 votes vote down vote up
@Test
@NeedGL
public void shouldParseParticle() throws Exception {
    CocoStudioUIEditor editor = new CocoStudioUIEditor(
        Gdx.files.internal("particle/MainScene.json"), null, null, null, null);

    Group group = editor.createGroup();
    CCParticleActor particleActor = group.findActor("Particle_1");
    Object modeA = Whitebox.getInternalState(particleActor, "modeA");
    Float speedVar = (Float) Whitebox.getInternalState(modeA, "speedVar");
    Float tangentialAccel = (Float) Whitebox.getInternalState(modeA, "tangentialAccel");
    Float tangentialAccelVar = (Float) Whitebox.getInternalState(modeA, "tangentialAccelVar");
    assertThat(speedVar, is(190.79f));
    assertThat(tangentialAccel, is(-92.11f));
    assertThat(tangentialAccelVar, is(65.79f));

    Object modeB = Whitebox.getInternalState(particleActor, "modeB");
    Float startRadius = (Float) Whitebox.getInternalState(modeB, "startRadius");
    Float endRadius = (Float) Whitebox.getInternalState(modeB, "endRadius");
    Float rotatePerSecond = (Float) Whitebox.getInternalState(modeB, "rotatePerSecond");
    assertThat(startRadius, is(0f));
    assertThat(endRadius, is(0f));
    assertThat(rotatePerSecond, is(0f));
}
 
Example #7
Source File: DropVisualizer.java    From dice-heroes with GNU General Public License v3.0 6 votes vote down vote up
@Override public IFuture<Void> visualize(DroppedItem drop) {
    final Future<Void> future = new Future<Void>();

    Group group = new Group();
    Tile image = new Tile("item/" + drop.item.name);
    Label counter = new Label(String.valueOf(drop.count), Config.skin);
    counter.setSize(image.getWidth(), image.getHeight());
    counter.setAlignment(Align.right | Align.bottom);
    group.addActor(image);
    group.addActor(counter);
    group.setTransform(false);
    visualizer.viewController.notificationLayer.addActor(group);
    group.setPosition(drop.target.getX() * ViewController.CELL_SIZE, drop.target.getY() * ViewController.CELL_SIZE);
    group.addAction(Actions.parallel(
        Actions.moveBy(0, 30, 1f, Interpolation.fade),
        Actions.alpha(0, 1f, Interpolation.fade),
        Actions.delay(0.4f, Actions.run(new Runnable() {
            @Override public void run() {
                future.happen();
            }
        }))
    ));
    return future;
}
 
Example #8
Source File: CCTextFieldTest.java    From cocos-ui-libgdx with Apache License 2.0 6 votes vote down vote up
@Test
@NeedGL
public void shouldParseTextField() throws Exception {
    FileHandle defaultFont = Gdx.files.internal("share/MLFZS.ttf");
    CocoStudioUIEditor editor = new CocoStudioUIEditor(
        Gdx.files.internal("textField/MainScene.json"), null, null, defaultFont, null);

    Group group = editor.createGroup();
    TextField textField = group.findActor("TextField_1");
    assertThat(textField.getText(), is("Here is text"));
    assertThat(textField.getMessageText(), is("Place Holder"));
    assertThat(textField.getText(), is("Here is text"));
    assertThat(textField.getColor().toString(), is("008000ff"));
    assertThat(textField.getListeners().size, is(1));
    textField = group.findActor("TextField_2");
    assertThat(textField.getText(), is(""));
    assertThat(textField.getMessageText(), is("Place Holder"));
    assertThat(textField.getColor().toString(), is("ff0000ff"));
    assertThat(textField.getListeners().size, is(1));
}
 
Example #9
Source File: CCButtonTest.java    From cocos-ui-libgdx with Apache License 2.0 6 votes vote down vote up
@Test
@NeedGL
public void shouldParseSingleButtonWithImages() throws Exception {
    FileHandle defaultFont = Gdx.files.internal("share/MLFZS.ttf");

    CocoStudioUIEditor editor = new CocoStudioUIEditor(
        Gdx.files.internal("single-button/MainScene.json"), null, null, defaultFont, null);

    Group group = editor.createGroup();
    Actor actor = group.findActor("Button_1");

    assertThat(actor, not(nullValue()));
    assertThat(actor, instanceOf(ImageButton.class));
    ImageButton imageButton = (ImageButton) actor;
    assertThat(imageButton.getScaleX(), is(1.7958f));
    assertThat(imageButton.getScaleY(), is(1.8041f));
    ImageButton.ImageButtonStyle style = imageButton.getStyle();
    assertThat(style.imageDisabled, instanceOf(NinePatchDrawable.class));
    assertThat(style.up, instanceOf(NinePatchDrawable.class));
    assertThat(style.down, instanceOf(NinePatchDrawable.class));
}
 
Example #10
Source File: WindowManager.java    From dice-heroes with GNU General Public License v3.0 6 votes vote down vote up
void add(GameWindow window) {
    if (windows.contains(window, true))
        return;
    Group parent;
    if (window.getTargetParent() != null) {
        if (window.getTargetParent().getStage() == null)
            throw new IllegalStateException("no stage in target parent to show window!");
        parent = window.getTargetParent();
    } else {
        if (activeStage == null)
            throw new IllegalStateException("no active stage to show window!");
        parent = activeStage.getRoot();
    }
    windows.add(window);
    parent.addActor(window);
}
 
Example #11
Source File: CreatureInfoWindow.java    From dice-heroes with GNU General Public License v3.0 6 votes vote down vote up
private ClickListener createListener(final Group group, final Image selection, final LocLabel label, final CreatureEffect effect, final Creature creature) {
    return new ClickListener() {
        @Override public void clicked(InputEvent event, float x, float y) {
            group.addActor(selection);
            final int turnCount = effect.getTurnCount();
            if (turnCount > 1000) {
                //forever effect
                label.setKey("ui-creature-info-window-forever-effect-description");
                label.setParams(Thesaurus.params()
                        .with("desc", effect.locDescKey())
                        .with("die", creature.description.nameLocKey())
                );
            } else {
                label.setKey("ui-creature-info-window-effect-description");
                label.setParams(Thesaurus.params()
                        .with("desc", effect.locDescKey())
                        .with("turn-count", String.valueOf(turnCount))
                        .with("die", creature.description.nameLocKey())
                );
            }
        }
    };
}
 
Example #12
Source File: ViewController.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
public static Tile addTopRightCorner(int x, int y, String name, Group layer) {
    TextureAtlas.AtlasRegion region = Config.findRegions("tile/" + name + "-corner-top-right").random();
    if (region == null)
        return null;
    Tile image = new Tile(region);
    layer.addActor(image);
    image.setPosition(x * CELL_SIZE, y * CELL_SIZE);
    return image;
}
 
Example #13
Source File: DeckBuilderScreen.java    From Cardshifter with Apache License 2.0 5 votes vote down vote up
private TextButton addPageButton(Group table, String text, final int i, Skin skin) {
    TextButton button = new TextButton(text, skin);
    button.addListener(new ClickListener(){
        @Override
        public void clicked(InputEvent event, float x, float y) {
            displayPage(page + i);
        }
    });
    table.addActor(button);
    return button;
}
 
Example #14
Source File: ShowDragAbilityAnimation.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
@Override protected Group getTarget() {
    UserData userData = resources.get("userData");
    Die die = userData.findDieByName(dieName);

    GameMapState mapState = resources.get("map");
    return mapState.diceWindow.getPane(die).params;
}
 
Example #15
Source File: ViewController.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
public static Tile addTopLeftCorner(int x, int y, String name, Group layer) {
    TextureAtlas.AtlasRegion region = Config.findRegions("tile/" + name + "-corner-top-left").random();
    if (region == null)
        return null;
    Tile image = new Tile(region);
    layer.addActor(image);
    image.setPosition((x + 1) * CELL_SIZE - image.getWidth(), y * CELL_SIZE);
    return image;
}
 
Example #16
Source File: ShowActor.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
@Override public void start(Callback callback) {
    Actor actor = getActorToShow();
    Group target = getTarget();

    target.addActor(actor);
    resources.put(targetResourceName, actor);
    callback.taskEnded();
}
 
Example #17
Source File: CreatureInfoWindow.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
private ClickListener createListener(final Group abilityIconGroup, final Image selection, final LocLabel label, final Ability ability, final Creature creature) {
    return new ClickListener() {
        @Override public void clicked(InputEvent event, float x, float y) {
            abilityIconGroup.addActor(selection);
            label.setParams(
                ability.fillDescriptionParams(Thesaurus.params(), creature)
                    .with("name", ability.locNameKey())
                    .with("desc", ability.locDescKey())
            );
        }
    };
}
 
Example #18
Source File: SelectAbilityWindow.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
private ClickListener createListener(final Ability ability, final TextButton button, final Image itemSelection, final Group icon, final LocLabel itemDescriptionLabel) {
    return new ClickListener() {
        @Override public void clicked(InputEvent event, float x, float y) {
            selected = ability;
            icon.addActor(itemSelection);
            itemSelection.toBack();
            button.setDisabled(false);
            itemDescriptionLabel.setParams(Thesaurus.params().with("name", ability.locNameKey()).with("desc", ability.locDescKey()));
        }
    };
}
 
Example #19
Source File: DemoScreen.java    From cocos-ui-libgdx with Apache License 2.0 5 votes vote down vote up
private void changeDemo() {
    CocoStudioUIEditor editor = new CocoStudioUIEditor(
        Gdx.files.internal(demos.get(currentIndex) + File.separator + "MainScene.json"),
        null, null, defaultFont, null);
    stage.clear();
    Group group = editor.createGroup();
    stage.addActor(group);
}
 
Example #20
Source File: ViewController.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
public static Tile addBottomRightCorner(int x, int y, String name, Group layer) {
    TextureAtlas.AtlasRegion region = Config.findRegions("tile/" + name + "-corner-bottom-right").random();
    if (region == null)
        return null;
    Tile image = new Tile(region);
    layer.addActor(image);
    image.setPosition(x * CELL_SIZE, (y + 1) * CELL_SIZE - image.getHeight());
    return image;
}
 
Example #21
Source File: ViewController.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
public static Image addTopOutline(int x, int y, String name, Group layer) {
    TextureAtlas.AtlasRegion region = Config.findRegions("tile/" + name + "-outline").random();
    if (region == null)
        return null;
    Image image = new Image(region);
    image.setRotation(90);
    layer.addActor(image);
    image.setPosition((x + 1) * CELL_SIZE, (y + 1) * CELL_SIZE - image.getWidth());
    return image;
}
 
Example #22
Source File: ViewController.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
public static Image addBottomOutline(int x, int y, String name, Group layer) {
    TextureAtlas.AtlasRegion region = Config.findRegions("tile/" + name + "-outline").random();
    if (region == null)
        return null;
    Image image = new Image(region);
    image.setRotation(-90);
    layer.addActor(image);
    image.setPosition(x * CELL_SIZE, y * CELL_SIZE + image.getWidth());
    return image;
}
 
Example #23
Source File: ViewController.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
public static Image addLeftOutline(int x, int y, String name, Group layer) {
    TextureAtlas.AtlasRegion region = Config.findRegions("tile/" + name + "-outline").random();
    if (region == null)
        return null;
    Image image = new Image(region);
    image.setRotation(180);
    layer.addActor(image);
    image.setPosition(x * CELL_SIZE + image.getWidth(), (y + 1) * CELL_SIZE);
    return image;
}
 
Example #24
Source File: Scene2dUtils.java    From gdx-texture-packer-gui with Apache License 2.0 5 votes vote down vote up
/** Injects actors from group into target's fields annotated with {@link InjectActor} using reflection. */
public static void injectActorFields(Object target, Group group) {
    Class<?> handledClass = target.getClass();
    while (handledClass != null && !handledClass.equals(Object.class)) {
        for (final Field field : ClassReflection.getDeclaredFields(handledClass)) {
            if (field != null && field.isAnnotationPresent(InjectActor.class)) {
                try {
                    InjectActor annotation = field.getDeclaredAnnotation(InjectActor.class).getAnnotation(InjectActor.class);
                    String actorName = annotation.value();
                    if (actorName.length() == 0) {
                        actorName = field.getName();
                    }
                    Actor actor = group.findActor(actorName);
                    if (actor == null && actorName.equals(group.getName())) {
                        actor = group;
                    }
                    if (actor == null) {
                        Gdx.app.error(TAG_INJECT_FIELDS, "Can't find actor with name: " + actorName + " in group: " + group + " to inject into: " + target);
                    } else {
                        field.setAccessible(true);
                        field.set(target, actor);
                    }
                } catch (final ReflectionException exception) {
                    Gdx.app.error(TAG_INJECT_FIELDS, "Unable to set value into field: " + field + " of object: " + target, exception);
                }
            }
        }
        handledClass = handledClass.getSuperclass();
    }
}
 
Example #25
Source File: ViewController.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
public static Image addOverHang(int x, int y, String name, String type, Group layer) {
    TextureAtlas.AtlasRegion region = Config.findRegions("tile/" + name + "-overhang-" + type).random();
    if (region == null) {
        region = Config.findRegions("tile/" + name + "-overhang").random();
        if (region == null)
            return null;
    }
    Image image = new Image(region);
    layer.addActor(image);
    image.setPosition(x * CELL_SIZE, (y + 1) * CELL_SIZE - image.getHeight());
    return image;
}
 
Example #26
Source File: CCProjectNodeTest.java    From cocos-ui-libgdx with Apache License 2.0 5 votes vote down vote up
@Test
@NeedGL
public void shouldGetCorrectTouchableConfig() throws Exception {
    FileHandle defaultFont = Gdx.files.internal("share/MLFZS.ttf");

    CocoStudioUIEditor editor = new CocoStudioUIEditor(
        Gdx.files.internal("mainMenu/MainScene.json"), null, null, defaultFont, null);

    Group group = editor.createGroup();
    assertThat(group.getTouchable(), is(Touchable.childrenOnly));
    Group subGroup = (Group) group.getChildren().get(0);
    assertThat(subGroup.getTouchable(), is(Touchable.childrenOnly));
    assertThat(subGroup.getChildren(), (Matcher) everyItem(hasProperty("touchable", is(true))));
}
 
Example #27
Source File: CachePool.java    From TerraLegion with MIT License 5 votes vote down vote up
public static Group getGroup() {
	if (groupCache.size > 0) {
		Group group = groupCache.removeIndex(0);
		group.clear();
		return group;
	}
	return new Group();
}
 
Example #28
Source File: ViewController.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
public static Image addTopRightCornerTransition(String name, int x, int y, Group layer) {
    TextureAtlas.AtlasRegion region = Config.findRegions("transitions/" + name + "-corner").random();
    if (region == null)
        return null;
    Image image = new Image(region);
    layer.addActor(image);
    image.setRotation(-90);
    image.setPosition(x * CELL_SIZE, (y + 1) * CELL_SIZE);
    return image;
}
 
Example #29
Source File: ViewController.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
public static Image addTopLeftCornerTransition(String name, int x, int y, Group layer) {
    TextureAtlas.AtlasRegion region = Config.findRegions("transitions/" + name + "-corner").random();
    if (region == null)
        return null;
    Image image = new Image(region);
    layer.addActor(image);
    image.setPosition(x * CELL_SIZE, y * CELL_SIZE);
    return image;
}
 
Example #30
Source File: ScrollableTextArea.java    From vis-ui with Apache License 2.0 5 votes vote down vote up
@Override
protected void setParent (Group parent) {
	super.setParent(parent);
	if (parent instanceof ScrollPane) {
		calculateOffsets();
	}
}