Example usage for com.badlogic.gdx.scenes.scene2d.ui Container getActor

List of usage examples for com.badlogic.gdx.scenes.scene2d.ui Container getActor

Introduction

In this page you can find the example usage for com.badlogic.gdx.scenes.scene2d.ui Container getActor.

Prototype

public T getActor() 

Source Link

Usage

From source file:org.anism.lotw.LOTW.java

License:Open Source License

public void initEverything() {
    Color fullAnti = new Color(G.getAntiColor());
    fullAnti.a = 1;/*w  w w .  j  a  v a2  s.c o m*/

    Texture upTexture = new Texture(Gdx.files.internal("images/grey_button_up.png"));
    Texture downTexture = new Texture(Gdx.files.internal("images/grey_button_down.png"));
    NinePatch buttonPatchUp = new NinePatch(upTexture, 11, 11, 11, 11);
    NinePatch buttonPatchDown = new NinePatch(downTexture, 11, 11, 11, 11);

    NinePatchDrawable npdUp = new NinePatchDrawable(buttonPatchUp);
    NinePatchDrawable npdDown = new NinePatchDrawable(buttonPatchDown);
    textButtonStyle = new TextButton.TextButtonStyle(npdUp, npdDown, npdUp, G.roboto16);
    textButtonStyle.fontColor = new Color(G.getAntiColor());
    textButtonStyle.fontColor.a = 1;
    buttonStyle = new ButtonStyle(npdUp, npdDown, npdUp);

    labelStyle = new Label.LabelStyle(G.roboto24, G.getAntiColor());
    labelStyleSmall = new Label.LabelStyle(G.roboto16, G.getAntiColor());
    resumeButton = addIconButton(game, G.playIcon, new ClickListener() {
        @Override
        public void clicked(InputEvent e, float x, float y) {
            if (!G.pausing) {
                G.pause();
            }
        }
    }, buttonWidth / dpi / 2 + 4 * dpi, -48, buttonWidth / dpi, 88);
    resumeButton.setColor(G.colors.green);
    exitButton = addIconButton(game, G.backIcon, new ClickListener() {
        @Override
        public void clicked(InputEvent e, float x, float y) {
            if (!G.pausing) {
                G.gameOver();
            }
        }
    }, -buttonWidth / dpi / 2 - 4 * dpi, -48, buttonWidth / dpi, 88);
    exitButton.setColor(G.colors.red);
    togglePauseButtons();

    //intro.addActor(logo);
    //putLogo(settings);
    putLogo(instructions);
    //putLogo(statistics);

    /*
    // intro screen:
    addButton(intro, game, "Start Game", 0, 0, 200f, 40f);
    addButton(intro, settings, "Settings", 0, -70, 100f, 40f);
    addButton(intro, instructions, "How to Play", 0, -120, 100f, 40f);
    */

    // settings screen:

    ImageTextButton.ImageTextButtonStyle lbs = new ImageTextButton.ImageTextButtonStyle(textButtonStyle);
    TextureRegionDrawable gamepadDrawable = new TextureRegionDrawable(new TextureRegion(G.controllerIcon));
    lbs.imageChecked = gamepadDrawable;
    lbs.imageCheckedOver = gamepadDrawable;
    lbs.imageDisabled = gamepadDrawable;
    lbs.imageDown = gamepadDrawable;
    lbs.imageOver = gamepadDrawable;
    lbs.imageUp = gamepadDrawable;

    logButton = new ImageTextButton("Sign In", lbs);
    if (actionResolver.getSignedInGPGS()) {
        logButton.setText("Sign Out");
    }
    logButton.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent e, float x, float y) {
            if (actionResolver.getSignedInGPGS()) {
                actionResolver.logoutGPGS();
            } else {
                actionResolver.loginGPGS();
            }
            G.toggleAutologin();
        }
    });
    logButton.setWidth(184 * dpi);
    logButton.setHeight(88 * dpi);
    logButton.setColor(G.colors.grey);
    logButton.getImage().setColor(fullAnti);
    //settings.addActor(logButton);

    TextureRegionDrawable cbOn = new TextureRegionDrawable(new TextureRegion(G.dashIcon));
    TextureRegionDrawable cbOff = new TextureRegionDrawable(new TextureRegion(G.circleIcon));
    CheckBoxStyle cbs = new CheckBoxStyle(cbOff, cbOn, G.roboto16, fullAnti);
    cbs.checked = npdUp;
    cbs.checkedOver = npdUp;
    cbs.down = npdDown;
    cbs.over = npdUp;
    cbs.up = npdUp;

    // colorblind settings:
    CheckBox colorButton = new CheckBox("", cbs);
    colorButton.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent e, float x, float y) {
            G.toggleColorblind();
        }
    });
    colorButton.setWidth(88 * dpi);
    colorButton.setHeight(88 * dpi);
    /*
    colorButton.setPosition(G.width/2 - 188 * dpi,
    G.height/2 + 100*dpi);
    */
    Table colorTable = makeSettingsTable("Display");
    colorButton.setColor(Math.random() > 0.5 ? G.colors.green : G.colors.red);
    colorButton.getImage().setColor(fullAnti);
    colorButton.setChecked(G.settings.colorblind);
    ListStyle listStyle = new ListStyle(G.roboto16, G.getAntiColor(), G.getAntiColor(), npdDown);
    listStyle.background = npdUp;
    SelectBoxStyle sbs = new SelectBoxStyle(G.roboto16, new Color(0x00000000), npdUp,
            new ScrollPane.ScrollPaneStyle(), listStyle);
    final SelectBox<Season> seasonPicker = new SelectBox(sbs);
    seasonPicker.setItems((Season[]) G.settings.getUnlockedSeasons());
    if (G.settings.unlock) {
        seasonPicker.setSelected(G.settings.unlockSeason);
    } else {
        seasonPicker.setSelected(G.settings.getSeason());
    }
    seasonPicker.setColor(G.colors.grey);
    seasonPicker.getList().setColor(G.colors.grey);
    Stack seasonStack = new Stack();
    final Container seasonImage = new Container(new Image(seasonPicker.getSelected().getIcon()));
    seasonImage.setSize(32, 32);
    seasonImage.setTouchable(Touchable.disabled);
    seasonImage.getActor().setColor(G.getAntiColor());
    seasonStack.add(seasonPicker);
    seasonStack.add(seasonImage);
    seasonPicker.addListener(new ChangeListener() {
        @Override
        public void changed(ChangeEvent e, Actor a) {
            Season s = seasonPicker.getSelected();
            if (s.getName().toUpperCase().equals("UNLOCK")) {
                G.glider.score = 0;
                G.settings.unlock = true;
                G.settings.setSeason(G.settings.getSeasons()[0]);
                G.updateBgColor();
                G.lotw.resetEverything();
            } else {
                G.settings.unlock = false;
                G.changeSeason(s);
            }
        }
    });
    putSettingsButton(colorTable, seasonStack, "Season.");
    CheckBox ninjaButton = new CheckBox("", cbs);
    ninjaButton.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent e, float x, float y) {
            G.toggleNinja();
        }
    });
    ninjaButton.setColor(G.colors.grey);
    ninjaButton.getImage().setColor(fullAnti);
    ninjaButton.setChecked(G.settings.ninjaMode);
    putSettingsButton(colorTable, colorButton, "Add markings to distinguish red and green orbs.");
    putSettingsButton(colorTable, ninjaButton, "Ninja mode.");

    // advanced settings:
    CheckBox bottomButton = new CheckBox("", cbs);
    bottomButton.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent e, float x, float y) {
            G.toggleBottomOut();
        }
    });
    bottomButton.setChecked(G.settings.bottomOut);
    bottomButton.setColor(G.colors.grey);
    bottomButton.getImage().setColor(fullAnti);
    Table bottomTable = makeSettingsTable("Advanced");
    putSettingsButton(bottomTable, bottomButton,
            "The glider respawns if it falls too far. Experienced players may wish to turn this off.");
    ImageButton statsButton = addIconButton(null, G.image("icons/stats.png"), new ClickListener() {
        @Override
        public void clicked(InputEvent e, float x, float y) {
            seeStats();
        }
    }, 96, -48, 88, 88);
    statsButton.setColor(G.colors.grey);
    putSettingsButton(bottomTable, statsButton, "View aggregate and record statistics.");
    ImageButton aboutButton = addIconButton(null, G.infoIcon, new ClickListener() {
        @Override
        public void clicked(InputEvent e, float x, float y) {
            setStage(about);
        }
    }, 0, 0, 0, 0);
    aboutButton.setColor(G.colors.grey);
    putSettingsButton(bottomTable, aboutButton, "About.");

    // online settings:
    ImageButton leaderButton = addIconButton(null, G.leaderIcon, new ClickListener() {
        @Override
        public void clicked(InputEvent e, float x, float y) {
            actionResolver.getLeaderboardGPGS(G.constants.scoreBoard);
        }
    }, 48, -G.height / 2 / dpi + 48, 88, 88);
    leaderButton.setColor(G.colors.gold);
    ImageButton achieveButton = addIconButton(null, G.achieveIcon, new ClickListener() {
        @Override
        public void clicked(InputEvent e, float x, float y) {
            actionResolver.getAchievementsGPGS();
        }
    }, -48, -G.height / 2 / dpi + 48, 88, 88);
    achieveButton.setColor(G.colors.blue);
    Table loginTable = makeSettingsTable("Online");
    putSettingsButton(loginTable, achieveButton, "View achievements.");
    putSettingsButton(loginTable, leaderButton, "Access leaderboards.");
    loginTable.add(logButton).width(182 * dpi).pad(4 * dpi).colspan(2).center();

    // control settings:
    Table controlTable = makeSettingsTable("Controls");
    CheckBox twoTouchControls = new CheckBox("", cbs);
    twoTouchControls.setColor(G.colors.grey);
    twoTouchControls.getImage().setColor(fullAnti);
    twoTouchControls.setChecked(G.settings.twoTouch());
    twoTouchControls.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent e, float x, float y) {
            G.settings.setControl("TWO_TOUCH");
        }
    });
    CheckBox tiltControls = new CheckBox("", cbs);
    tiltControls.setColor(G.colors.grey);
    tiltControls.getImage().setColor(fullAnti);
    tiltControls.setChecked(G.settings.tilt());
    tiltControls.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent e, float x, float y) {
            G.settings.setControl("TILT");
        }
    });
    CheckBox dragControls = new CheckBox("", cbs);
    dragControls.setColor(G.colors.grey);
    dragControls.getImage().setColor(fullAnti);
    dragControls.setChecked(G.settings.oneTouch());
    dragControls.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent e, float x, float y) {
            G.settings.setControl("ONE_TOUCH");
        }
    });
    ButtonGroup controlGroup = new ButtonGroup(twoTouchControls, tiltControls, dragControls);
    controlGroup.setMaxCheckCount(1);
    controlGroup.setMinCheckCount(1);
    controlGroup.setUncheckLast(true);
    putSettingsButton(controlTable, twoTouchControls, "Touch on the left or right.");
    putSettingsButton(controlTable, tiltControls, "Tilt your device.");
    putSettingsButton(controlTable, dragControls, "Touch and drag.");

    // mode settings:
    Table modeTable = makeSettingsTable("Mode");
    CheckBox hellMode = new CheckBox("", cbs);
    hellMode.setColor(G.colors.red);
    hellMode.getImage().setColor(fullAnti);
    hellMode.setChecked(G.settings.hell());
    hellMode.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent e, float x, float y) {
            G.settings.setMode(-1);
        }
    });
    CheckBox normalMode = new CheckBox("", cbs);
    normalMode.setColor(G.colors.grey);
    normalMode.getImage().setColor(fullAnti);
    normalMode.setChecked(G.settings.normal());
    normalMode.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent e, float x, float y) {
            G.settings.setMode(0);
        }
    });
    ButtonGroup modeGroup = new ButtonGroup(hellMode, normalMode);
    modeGroup.setMaxCheckCount(1);
    modeGroup.setMinCheckCount(1);
    modeGroup.setUncheckLast(true);
    putSettingsButton(modeTable, normalMode, "Normal mode: catch orbs for points.");
    putSettingsButton(modeTable, hellMode, "Hell mode: dodge red orbs.");

    putActionBar(settings);
    putActionBar(colorSettings);
    putActionBar(controlSettings);
    putActionBar(modeSettings);
    putActionBar(loginSettings);
    putActionBar(bottomSettings);

    putSettingsMenu(settings);
    putSettingsMenu(colorSettings);
    colorSettings.addActor(colorTable);
    putSettingsMenu(controlSettings);
    controlSettings.addActor(controlTable);
    putSettingsMenu(loginSettings);
    loginSettings.addActor(loginTable);
    putSettingsMenu(modeSettings);
    modeSettings.addActor(modeTable);
    putSettingsMenu(bottomSettings);
    bottomSettings.addActor(bottomTable);

    Table aboutTable = new Table();
    aboutTable.setSize(G.width, G.height - 88 * dpi);
    aboutTable.setPosition(0, 88 * dpi);
    aboutTable.add(new Label("About", labelStyle));
    aboutTable.row();
    Label aboutTextLabel = new Label(
            "Leaf on the Wind copyright 2014 Ethan Goldberg, all rights reserved.\n\nIcons made by Google and licensed under CC BY 4.0.\n\n\nThank you for playing!",
            labelStyleSmall);
    aboutTextLabel.setWrap(true);
    aboutTextLabel.setAlignment(Align.center, Align.center);
    aboutTable.add(aboutTextLabel).width(G.width / 2);
    ImageButton aboutBackButton = addIconButton(about, G.backIcon, new ClickListener() {
        @Override
        public void clicked(InputEvent e, float x, float y) {
            setStage(bottomSettings);
        }
    }, 0, -G.height / 2 / dpi + 48, buttonWidth / dpi, 88);
    aboutBackButton.setColor(G.colors.red);
    about.addActor(aboutTable);
    about.addActor(aboutBackButton);

    // instructions:

    //delay
    float d = 0f;
    addLabel(instructions, "This is your glider.", 0, G.height / 2 / dpi - 96, 8, tr)
            .addAction(Actions.delay(d, Actions.fadeIn(fadeDur)));
    // wait two seconds:
    d += 2.5;
    addLabel(instructions, "Touch the screen", 0, G.height / 2 / dpi - 136, 8, tr)
            .addAction(Actions.delay(d, Actions.fadeIn(fadeDur)));
    d += 1;
    addLabel(instructions, "on the left,", -G.width / 4 / dpi, G.height / 2 / dpi - 166, 8, tr)
            .addAction(Actions.delay(d, Actions.fadeIn(fadeDur)));
    d += 1.5;
    addLabel(instructions, "or the right.", G.width / 4 / dpi, G.height / 2 / dpi - 166, 8, tr)
            .addAction(Actions.delay(d, Actions.fadeIn(fadeDur)));

    d += 3;
    int pickUpOffset = G.size * 2;
    addLabel(instructions, "Catch these,", -G.width / 4 / dpi, -G.height / 6 / dpi, G.size * 2 / dpi, tr)
            .addAction(Actions.delay(d, Actions.fadeIn(fadeDur)));
    Goody i;
    d += 1.5;

    Color r = new Color(G.colors.goodyRed);
    r.a = 0;
    Color gr = new Color(G.colors.goodyGreen);
    gr.a = 0;
    Color go = new Color(G.colors.goodyGold);
    go.a = 0;
    Color b = new Color(G.colors.goodyBlue);
    b.a = 0;

    i = addDumbGoody(instructions, b, -G.width / 4 / dpi - (G.size * 2) / dpi,
            -G.height / 6 / dpi + pickUpOffset);
    i.addAction(Actions.delay(d, Actions.alpha(1)));
    //bounce(i, 0, 8, 0.33f, 8);
    bounce(i, 0, 8, 0.33f, 4);
    d += .5;
    i = addDumbGoody(instructions, gr, -G.width / 4 / dpi, -G.height / 6 / dpi + pickUpOffset);
    i.addAction(Actions.delay(d, Actions.alpha(1)));
    //bounce(i, 0.25f, 8, 0.33f, 8);
    bounce(i, 0.25f, 8, 0.33f, 4);
    d += .5;
    i = addDumbGoody(instructions, go, -G.width / 4 / dpi + (G.size * 2) / dpi,
            -G.height / 6 / dpi + pickUpOffset);
    i.addAction(Actions.delay(d, Actions.alpha(1)));
    //bounce(i, 0.5f, 8, 0.33f, 8);
    bounce(i, 0.5f, 8, 0.33f, 4);

    d += 1.5;
    addLabel(instructions, "not these.", G.width / 4 / dpi, -G.height / 6 / dpi, G.size * 2 / dpi, tr)
            .addAction(Actions.delay(d, Actions.fadeIn(fadeDur)));
    d += 2;
    i = addDumbBaddy(instructions, r, G.width / 4 / dpi, -G.height / 6 / dpi + pickUpOffset);
    i.addAction(Actions.delay(d, Actions.alpha(1)));
    //bounce(i, 0.75f, 8, 0.33f, 8);
    bounce(i, 0.75f, 8, 0.33f, 4);

    d += 2;

    addIconButton(instructions, G.playIcon, new ClickListener() {
        @Override
        public void clicked(InputEvent e, float x, float y) {
            setStage(game);
        }
    }, G.width / 2 / dpi - buttonWidth / dpi / 2 - 4, -G.height / 2 / dpi + 48, buttonWidth / dpi, 88)
            .setColor(G.colors.green);
    addIconButton(instructions, G.image("icons/settings.png"), new ClickListener() {
        @Override
        public void clicked(InputEvent e, float x, float y) {
            setStage(settings);
        }
    }, -G.width / 2 / dpi + buttonWidth / 2 / dpi + 4, -G.height / 2 / dpi + 48, buttonWidth / dpi, 88)
            .setColor(G.colors.grey);

    d += 2;

    Color c = new Color(G.getAntiColor());
    c.a = 0;
    addImage(instructions, G.playWrite, c, G.width / 2 / dpi - 3 * buttonWidth / 2 / dpi - 8,
            -G.height / 2 / dpi + 48, buttonWidth / 2 / dpi, 48)
                    .addAction(Actions.delay(d, Actions
                            .forever(Actions.sequence(Actions.fadeOut(fadeDur), Actions.fadeIn(fadeDur)))));

    /*
    TextButton b1 = addButton(instructions, game, "Start", 
    0, -G.height/2/dpi + 88f, 192, 40f);
    TextButton b2 = addButton(instructions, settings, "Settings", 
    0, -G.height/2/dpi + 40f, 192, 40f);
    b1.addAction(Actions.alpha(.5f));
    b2.addAction(Actions.alpha(.25f));
    b1.addAction(Actions.delay(d, Actions.fadeIn(fadeDur)));
    b2.addAction(Actions.delay(d, Actions.fadeIn(fadeDur)));
    */
}