Java Code Examples for com.badlogic.gdx.scenes.scene2d.Group#findActor()

The following examples show how to use com.badlogic.gdx.scenes.scene2d.Group#findActor() . 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: 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 2
Source File: CCPageViewTest.java    From cocos-ui-libgdx with Apache License 2.0 6 votes vote down vote up
@Test
@NeedGL
public void shouldParsePageView() throws Exception {
    FileHandle defaultFont = Gdx.files.internal("share/MLFZS.ttf");

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

    Group group = editor.createGroup();
    PageView pageView = group.findActor("PageView_SelectPage");
    assertThat(pageView.getChildren().get(0).getX(), is(0f));
    pageView.nextView();
    pageView.act(1000f);
    assertThat(pageView.getChildren().get(0).getX(), is(-492f));
    assertThat(pageView.getChildren().get(1).getX(), is(0f));
    pageView.previousView();
    pageView.act(1000f);
    assertThat(pageView.getChildren().get(0).getX(), is(0f));
    assertThat(pageView.getChildren().get(1).getX(), is(492f));
}
 
Example 3
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 4
Source File: CCSliderTest.java    From cocos-ui-libgdx with Apache License 2.0 6 votes vote down vote up
@Test
@NeedGL
public void shouldParseSliderBar() throws Exception {
    CocoStudioUIEditor editor = new CocoStudioUIEditor(
        Gdx.files.internal("slideBar/MainScene.json"), null, null, null, null);

    Group group = editor.createGroup();
    Slider slider = group.findActor("Slider_1");
    assertThat(slider.getWidth(), is(200f));
    assertThat(slider.getHeight(), is(14f));
    assertThat(slider.getValue(), is(50f));
    Slider.SliderStyle style = slider.getStyle();
    assertThat(style.knob, instanceOf(TextureRegionDrawable.class));
    assertThat(style.background, instanceOf(TextureRegionDrawable.class));
    assertThat(style.knobBefore, instanceOf(TextureRegionDrawable.class));
    //assertThat(style.disabledKnob, instanceOf(TextureRegionDrawable.class));
   // assertThat(style.knobDown, instanceOf(TextureRegionDrawable.class));
}
 
Example 5
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 6
Source File: CCSpriteViewTest.java    From cocos-ui-libgdx with Apache License 2.0 6 votes vote down vote up
@Test
@NeedGL
public void shouldParseSpriteView() throws Exception {
    CocoStudioUIEditor editor = new CocoStudioUIEditor(
        Gdx.files.internal("animation/MainScene.json"), null, null, null, null);

    Group group = editor.createGroup();
    Image image = group.findActor("st_2");
    Array<Action> actions = image.getActions();
    assertThat(actions.size, is(1));
    RepeatAction repeatAction = (RepeatAction) actions.get(0);
    ParallelAction parallelAction = (ParallelAction) repeatAction.getAction();
    assertThat(parallelAction.getActions().size, is(3));
    assertThat(parallelAction.getActions(), (Matcher) everyItem(instanceOf(SequenceAction.class)));
    SequenceAction moveAction = (SequenceAction) parallelAction.getActions().get(0);
    SequenceAction scaleAction = (SequenceAction) parallelAction.getActions().get(1);
    assertThat(moveAction.getActions().size, is(4));
    assertThat(moveAction.getActions(), (Matcher) everyItem(instanceOf(MoveToAction.class)));
    assertThat(scaleAction.getActions().size, is(4));
    assertThat(scaleAction.getActions(), (Matcher) everyItem(instanceOf(ScaleToAction.class)));
}
 
Example 7
Source File: InfoPanel.java    From gdx-texture-packer-gui with Apache License 2.0 6 votes vote down vote up
public InfoPanel(LmlParser parser) {
    align(Align.top);
    fillX();

    // Workaround of parser's only single parsing operation limitation
    LmlParser localParser = new DefaultLmlParser(parser.getData());
    localParser.setSyntax(parser.getSyntax());
    Group root = (Group) (localParser.parseTemplate(Gdx.files.internal("lml/canvasInfoPanel.lml")).first());
    setActor(root);

    lblPages = root.findActor("lblPages");
    lblZoom = root.findActor("lblZoom");
    lblPageDimens = root.findActor("lblPageDimens");
    lblFileSize = root.findActor("lblFileSize");

    updatePagesText();
    setZoomLevel(100f);
}
 
Example 8
Source File: GroupLayout.java    From libgdx-snippets with MIT License 6 votes vote down vote up
@Override
protected Actor create(Skin skin, StageLayoutListener listener) {
	Group group = (Group)super.create(skin, listener);

	for(int i=0; i<actors.size; i++){
		ActorLayout layout = actors.get(i);

		group.addActor(layout.create(skin, listener));
	}

	if(sizeToActor != null){
		Actor actor = group.findActor(sizeToActor);
		if(actor != null){
			group.setWidth(actor.getWidth());
			group.setHeight(actor.getHeight());
		}
	}
	else {
		if(layout.width > 0)
			group.setWidth(layout.width);
		if(layout.height > 0)
			group.setHeight(layout.height);
	}

	return group;
}
 
Example 9
Source File: StatisticPanelViewController.java    From gdx-vfx with Apache License 2.0 5 votes vote down vote up
@Override
public void onViewCreated(Group sceneRoot) {
    super.onViewCreated(sceneRoot);
    processLmlFields(this);

    VfxWidgetGroup vfxGroup = sceneRoot.findActor("vfxGroup");
    vfxManager = vfxGroup.getVfxManager();
}
 
Example 10
Source File: Scene2dUtils.java    From gdx-vfx 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 11
Source File: CCProjectNodeTest.java    From cocos-ui-libgdx with Apache License 2.0 5 votes vote down vote up
@Test
@NeedGL
public void shouldEnableParseProjectNode() 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();
    Actor button = group.findActor("Bnss_2");
    assertThat(button, not(nullValue()));
}
 
Example 12
Source File: CCPanelTest.java    From cocos-ui-libgdx with Apache License 2.0 5 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("levelSelection/MainScene.json"), null, null, defaultFont, null);

    Group group = editor.createGroup();
    Table table = group.findActor("Panel_7");
    assertThat(table.getBackground(), is(nullValue()));
}
 
Example 13
Source File: CCTextAtlasTest.java    From cocos-ui-libgdx with Apache License 2.0 5 votes vote down vote up
@Test
@NeedGL
public void shouldParseTextAtlas() throws Exception {
    CocoStudioUIEditor editor = new CocoStudioUIEditor(
        Gdx.files.internal("levelSelection/MainScene.json"), null, null, null, null);

    Group group = editor.createGroup();
    LabelAtlas labelAtlas = group.findActor("LabelAtlas_CurrentScene");
    assertThat(labelAtlas.getChildren().size, is(3));
    assertThat(labelAtlas.getChildren(), (Matcher) everyItem(instanceOf(Image.class)));
    labelAtlas.setText("0/1");
    assertThat(labelAtlas.getChildren().size, is(3));
    assertThat(labelAtlas.getChildren(), (Matcher) everyItem(instanceOf(Image.class)));
}
 
Example 14
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 15
Source File: ProcessingNodeListViewItem.java    From gdx-texture-packer-gui with Apache License 2.0 4 votes vote down vote up
public RegularMetadataItemViewHolder(LmlParser parser) {
    root = (Group) parser.parseTemplate(Gdx.files.internal("lml/dialogPackingMetaRegularItem.lml")).first();
    this.parser = parser;
    lblContent = root.findActor("lblContent");
    imgIcon = root.findActor("imgIcon");
}
 
Example 16
Source File: InitialUpdateCheckService.java    From gdx-texture-packer-gui with Apache License 2.0 4 votes vote down vote up
private void showUpdateNotification(VersionData version) {
    // Check if current version should be ignored
    try {
        String ignoreVersionSt = prefs.getString(PREF_KEY_IGNORE_NOTIFICATION, null);
        if (ignoreVersionSt != null) {
            Version ignoreVersion = new Version(ignoreVersionSt);
            if (ignoreVersion.equals(version.version)) {
                Gdx.app.log(TAG, "Update is available " + version.version + ", but notification is muted for that version.");
                return;
            }
        }
    } catch (IllegalArgumentException e) {
        // If something went wrong during ignore version checking, we simply ignore it
        e.printStackTrace();
    }

    LmlParser parser = interfaceService.getParser();
    ToastActions toastActions = new ToastActions(prefs, version);

    parser.getData().addArgument("newVersionCode", version.getVersion().toString());
    parser.getData().addArgument("newVersionUrl", version.getUrl());
    parser.getData().addActionContainer(ToastActions.class.getSimpleName(), toastActions);
    Group content = (Group)parser.parseTemplate(
            Gdx.files.internal("lml/toastNewVersionAvailable.lml")).first();
    parser.getData().removeActionContainer(ToastActions.class.getSimpleName());

    Actor imgLogo = content.findActor("imgLogo");
    imgLogo.addAction(Actions.forever(Actions.sequence(
            Actions.delay(0.5f),
            Actions.scaleTo(0.8f, 1.2f, 0.1f, Interpolation.exp10Out),
            Actions.scaleTo(1.1f, 0.9f, 0.1f, Interpolation.exp10Out),
            Actions.scaleTo(1.0f, 1.0f, 0.5f, Interpolation.exp10Out)
    )));

    ToastTable toastTable = new ToastTable();
    toastTable.add(content).grow();
    toastActions.setToastTable(toastTable);

    eventDispatcher.postEvent(new ShowToastEvent()
            .content(toastTable)
            .duration(ShowToastEvent.DURATION_INDEFINITELY));
}