package com.badlogic.gdx.ingenuity.test.screen;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.ingenuity.GdxData;
import com.badlogic.gdx.ingenuity.GdxGame;
import com.badlogic.gdx.ingenuity.helper.PixmapHelper;
import com.badlogic.gdx.ingenuity.scene2d.SimpleScreen;
import com.badlogic.gdx.ingenuity.screen.SimpleLoadingScreen.ILoadingComplete;
import com.badlogic.gdx.ingenuity.test.Asset;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.Touchable;
import com.badlogic.gdx.scenes.scene2d.ui.ButtonGroup;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.scenes.scene2d.utils.Drawable;
import com.badlogic.gdx.utils.Align;

import net.mwplay.nativefont.NativeButton;

/**
 * @作者 mitkey
 * @时间 2017年5月20日 下午12:14:45
 * @类说明 BaseTestScreen.java <br/>
 * @版本 0.0.1
 */
public abstract class BaseTestScreen extends SimpleScreen {

	public static final List<Class<? extends SimpleScreen>> tests = new ArrayList<Class<? extends SimpleScreen>>(
			Arrays.asList(LoginScreen.class, HallScreen.class, RoomScreen.class, TestScreen.class));

	protected Drawable dabUp = PixmapHelper.getInstance().newRectangleDrawable(new Color(51 / 255f, 122 / 255f, 183 / 255f, 1), 150, 50);
	protected Drawable dabDown = PixmapHelper.getInstance().newRectangleDrawable(new Color(40 / 255f, 96 / 255f, 144 / 255f, 1), 150, 50);
	protected Drawable dabChecked = PixmapHelper.getInstance().newRectangleDrawable(new Color(39 / 255f, 72 / 255f, 100 / 255f, 1), 150, 50);

	@Override
	public void show() {
		super.show();

		// 按钮组
		final ButtonGroup<NativeButton> buttonGroup = new ButtonGroup<NativeButton>();
		// 垂直容器
		Table table = new Table();
		table.pad(10).center().defaults().align(Align.center).top().space(10);
		for (final Class<? extends SimpleScreen> clazz : tests) {
			NativeButton button = newNativeButton(clazz.getSimpleName(), dabUp, dabDown, dabChecked, 20);
			table.add(button).size(150, 50).row();
			boolean checkCurChecked = checkCurChecked(button);
			if (checkCurChecked) {
				button.setDisabled(true);
				button.setTouchable(Touchable.disabled);
			}
			buttonGroup.add(button);
			button.addListener(new ClickListener() {
				@Override
				public void clicked(InputEvent event, float x, float y) {
					super.clicked(event, x, y);
					game().updateScreen(new LoadingScreen(new ILoadingComplete() {
						@Override
						public boolean complete() {
							try {
								game().updateScreen(clazz.newInstance());
							} catch (InstantiationException | IllegalAccessException e) {
								e.printStackTrace();
							}
							return true;
						}
					}, Asset.none));
				}
			});
		}
		table.pack();
		table.setPosition(0, GdxData.HEIGHT - table.getHeight());
		stage().addActor(table);

		// 选中当前的
		buttonGroup.uncheckAll();
		for (NativeButton temp : buttonGroup.getButtons()) {
			if (checkCurChecked(temp)) {
				temp.setChecked(true);
			}
		}
	}

	@Override
	public void dispose() {
		super.dispose();
	}

	public GdxGame game() {
		return (GdxGame) Gdx.app.getApplicationListener();
	}

	public Class<? extends SimpleScreen> getCurScreenClazz() {
		return getClass();
	}

	private boolean checkCurChecked(NativeButton temp) {
		return getCurScreenClazz().getSimpleName().equals(temp.getText().toString());
	}

}

@@ -123,37 +123,8 @@
 t;%0A%0A
-import com.badlogic.gdx.Gdx;%0A
 impo
@@ -206,51 +206,8 @@
 ta;%0A
-import com.badlogic.gdx.ingenuity.GdxGame;%0A
 impo
@@ -2408,24 +2408,30 @@
 , y);%0A%09%09%09%09%09g
+etAppG
 ame().update
@@ -2552,16 +2552,22 @@
 %09%09%09%09%09%09%09g
+etAppG
 ame().up
@@ -3106,90 +3106,8 @@
 %09%7D%0A%0A
-%09public GdxGame game() %7B%0A%09%09return (GdxGame) Gdx.app.getApplicationListener();%0A%09%7D%0A%0A
 %09pub

fix test