Added menu transition to calibration state.
This commit is contained in:
@@ -23,6 +23,7 @@ import ve.ucv.ciens.ccg.nxtar.network.SensorReportThread;
|
|||||||
import ve.ucv.ciens.ccg.nxtar.network.ServiceDiscoveryThread;
|
import ve.ucv.ciens.ccg.nxtar.network.ServiceDiscoveryThread;
|
||||||
import ve.ucv.ciens.ccg.nxtar.network.VideoStreamingThread;
|
import ve.ucv.ciens.ccg.nxtar.network.VideoStreamingThread;
|
||||||
import ve.ucv.ciens.ccg.nxtar.states.BaseState;
|
import ve.ucv.ciens.ccg.nxtar.states.BaseState;
|
||||||
|
import ve.ucv.ciens.ccg.nxtar.states.CameraCalibrationState;
|
||||||
import ve.ucv.ciens.ccg.nxtar.states.InGameState;
|
import ve.ucv.ciens.ccg.nxtar.states.InGameState;
|
||||||
import ve.ucv.ciens.ccg.nxtar.states.MainMenuStateBase;
|
import ve.ucv.ciens.ccg.nxtar.states.MainMenuStateBase;
|
||||||
import ve.ucv.ciens.ccg.nxtar.states.OuyaMainMenuState;
|
import ve.ucv.ciens.ccg.nxtar.states.OuyaMainMenuState;
|
||||||
@@ -64,7 +65,7 @@ public class NxtARCore extends Game implements NetworkConnectionListener{
|
|||||||
* Valid game states.
|
* Valid game states.
|
||||||
*/
|
*/
|
||||||
public enum game_states_t {
|
public enum game_states_t {
|
||||||
MAIN_MENU(0), IN_GAME(1), PAUSED(2);
|
MAIN_MENU(0), IN_GAME(1), PAUSED(2), CALIBRATION(3);
|
||||||
|
|
||||||
private int value;
|
private int value;
|
||||||
|
|
||||||
@@ -75,6 +76,10 @@ public class NxtARCore extends Game implements NetworkConnectionListener{
|
|||||||
public int getValue(){
|
public int getValue(){
|
||||||
return this.value;
|
return this.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int getNumStates(){
|
||||||
|
return 4;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -138,13 +143,14 @@ public class NxtARCore extends Game implements NetworkConnectionListener{
|
|||||||
|
|
||||||
public void create(){
|
public void create(){
|
||||||
// Create the state objects.
|
// Create the state objects.
|
||||||
states = new BaseState[3];
|
states = new BaseState[game_states_t.getNumStates()];
|
||||||
if(Ouya.runningOnOuya)
|
if(Ouya.runningOnOuya)
|
||||||
states[game_states_t.MAIN_MENU.getValue()] = new OuyaMainMenuState(this);
|
states[game_states_t.MAIN_MENU.getValue()] = new OuyaMainMenuState(this);
|
||||||
else
|
else
|
||||||
states[game_states_t.MAIN_MENU.getValue()] = new TabletMainMenuState(this);
|
states[game_states_t.MAIN_MENU.getValue()] = new TabletMainMenuState(this);
|
||||||
states[game_states_t.IN_GAME.getValue()] = new InGameState(this);
|
states[game_states_t.IN_GAME.getValue()] = new InGameState(this);
|
||||||
states[game_states_t.PAUSED.getValue()] = new PauseState(this);
|
states[game_states_t.PAUSED.getValue()] = new PauseState(this);
|
||||||
|
states[game_states_t.CALIBRATION.getValue()] = new CameraCalibrationState(this);
|
||||||
|
|
||||||
for(BaseState state : states){
|
for(BaseState state : states){
|
||||||
Controllers.addListener(state);
|
Controllers.addListener(state);
|
||||||
@@ -213,10 +219,12 @@ public class NxtARCore extends Game implements NetworkConnectionListener{
|
|||||||
Gdx.input.setInputProcessor(states[currState.getValue()]);
|
Gdx.input.setInputProcessor(states[currState.getValue()]);
|
||||||
Controllers.addListener(states[currState.getValue()]);
|
Controllers.addListener(states[currState.getValue()]);
|
||||||
|
|
||||||
// Anything else.
|
// Set log level
|
||||||
//Gdx.app.setLogLevel(Application.LOG_INFO);
|
if(ProjectConstants.DEBUG){
|
||||||
//Gdx.app.setLogLevel(Application.LOG_DEBUG);
|
Gdx.app.setLogLevel(Application.LOG_DEBUG);
|
||||||
Gdx.app.setLogLevel(Application.LOG_NONE);
|
}else{
|
||||||
|
Gdx.app.setLogLevel(Application.LOG_NONE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void render(){
|
public void render(){
|
||||||
|
@@ -15,7 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package ve.ucv.ciens.ccg.nxtar.interfaces;
|
package ve.ucv.ciens.ccg.nxtar.interfaces;
|
||||||
|
|
||||||
public interface CVProcessor {
|
public interface CVProcessor{
|
||||||
public class CVMarkerData{
|
public class CVMarkerData{
|
||||||
public byte[] outFrame;
|
public byte[] outFrame;
|
||||||
public int[] markerCodes;
|
public int[] markerCodes;
|
||||||
@@ -26,9 +26,10 @@ public interface CVProcessor {
|
|||||||
public byte[] outFrame;
|
public byte[] outFrame;
|
||||||
public float[] calibrationPoints;
|
public float[] calibrationPoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CVMarkerData findMarkersInFrame(byte[] frame);
|
public CVMarkerData findMarkersInFrame(byte[] frame);
|
||||||
public CVCalibrationData findCalibrationPattern(byte[] frame);
|
public CVCalibrationData findCalibrationPattern(byte[] frame);
|
||||||
public void calibrateCamera(float[][] calibrationSamples, byte[] frame);
|
public void calibrateCamera(float[][] calibrationSamples, byte[] frame);
|
||||||
public byte[] undistortFrame(byte[] frame);
|
public byte[] undistortFrame(byte[] frame);
|
||||||
|
public boolean cameraIsCalibrated();
|
||||||
}
|
}
|
||||||
|
@@ -18,12 +18,14 @@ package ve.ucv.ciens.ccg.nxtar.states;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import ve.ucv.ciens.ccg.nxtar.NxtARCore;
|
import ve.ucv.ciens.ccg.nxtar.NxtARCore;
|
||||||
|
import ve.ucv.ciens.ccg.nxtar.NxtARCore.game_states_t;
|
||||||
import ve.ucv.ciens.ccg.nxtar.interfaces.CVProcessor.CVCalibrationData;
|
import ve.ucv.ciens.ccg.nxtar.interfaces.CVProcessor.CVCalibrationData;
|
||||||
import ve.ucv.ciens.ccg.nxtar.network.monitors.VideoFrameMonitor;
|
import ve.ucv.ciens.ccg.nxtar.network.monitors.VideoFrameMonitor;
|
||||||
import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
|
import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
|
||||||
import ve.ucv.ciens.ccg.nxtar.utils.Size;
|
import ve.ucv.ciens.ccg.nxtar.utils.Size;
|
||||||
|
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
|
import com.badlogic.gdx.Input;
|
||||||
import com.badlogic.gdx.controllers.Controller;
|
import com.badlogic.gdx.controllers.Controller;
|
||||||
import com.badlogic.gdx.controllers.mappings.Ouya;
|
import com.badlogic.gdx.controllers.mappings.Ouya;
|
||||||
import com.badlogic.gdx.graphics.GL20;
|
import com.badlogic.gdx.graphics.GL20;
|
||||||
@@ -109,6 +111,10 @@ public class CameraCalibrationState extends BaseState{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStateSet(){
|
public void onStateSet(){
|
||||||
|
Gdx.input.setInputProcessor(this);
|
||||||
|
Gdx.input.setCatchBackKey(true);
|
||||||
|
Gdx.input.setCatchMenuKey(true);
|
||||||
|
|
||||||
for(int i = 0; i < calibrationSamples.length; i++){
|
for(int i = 0; i < calibrationSamples.length; i++){
|
||||||
for(int j = 0; j < calibrationSamples[i].length; j++){
|
for(int j = 0; j < calibrationSamples[i].length; j++){
|
||||||
calibrationSamples[i][j] = 0.0f;
|
calibrationSamples[i][j] = 0.0f;
|
||||||
@@ -145,7 +151,7 @@ public class CameraCalibrationState extends BaseState{
|
|||||||
// Fetch the current video frame and find the calibration pattern in it.
|
// Fetch the current video frame and find the calibration pattern in it.
|
||||||
frame = frameMonitor.getCurrentFrame();
|
frame = frameMonitor.getCurrentFrame();
|
||||||
CVCalibrationData data = core.cvProc.findCalibrationPattern(frame);
|
CVCalibrationData data = core.cvProc.findCalibrationPattern(frame);
|
||||||
|
|
||||||
if(frame != null && data != null && data.outFrame != null && !Arrays.equals(frame, prevFrame)){
|
if(frame != null && data != null && data.outFrame != null && !Arrays.equals(frame, prevFrame)){
|
||||||
// If the received frame is valid and is different from the previous frame.
|
// If the received frame is valid and is different from the previous frame.
|
||||||
// Make a texture from the frame.
|
// Make a texture from the frame.
|
||||||
@@ -218,7 +224,21 @@ public class CameraCalibrationState extends BaseState{
|
|||||||
public void resume(){ }
|
public void resume(){ }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void dispose(){ }
|
public void dispose(){
|
||||||
|
if(videoFrameTexture != null)
|
||||||
|
videoFrameTexture.dispose();
|
||||||
|
backgroundTexture.dispose();
|
||||||
|
if(backgroundShader != null) backgroundShader.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean keyDown(int keycode){
|
||||||
|
if(keycode == Input.Keys.BACK){
|
||||||
|
core.nextState = game_states_t.MAIN_MENU;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean touchDown(int screenX, int screenY, int pointer, int button){
|
public boolean touchDown(int screenX, int screenY, int pointer, int button){
|
||||||
|
@@ -46,7 +46,6 @@ import com.badlogic.gdx.math.Vector3;
|
|||||||
public class InGameState extends BaseState{
|
public class InGameState extends BaseState{
|
||||||
private static final String TAG = "IN_GAME_STATE";
|
private static final String TAG = "IN_GAME_STATE";
|
||||||
private static final String CLASS_NAME = InGameState.class.getSimpleName();
|
private static final String CLASS_NAME = InGameState.class.getSimpleName();
|
||||||
|
|
||||||
private static final String SHADER_PATH = "shaders/bckg/bckg";
|
private static final String SHADER_PATH = "shaders/bckg/bckg";
|
||||||
|
|
||||||
private NxtARCore core;
|
private NxtARCore core;
|
||||||
|
@@ -20,7 +20,6 @@ import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
|
|||||||
|
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
import com.badlogic.gdx.Input;
|
import com.badlogic.gdx.Input;
|
||||||
import com.badlogic.gdx.controllers.mappings.Ouya;
|
|
||||||
import com.badlogic.gdx.graphics.Color;
|
import com.badlogic.gdx.graphics.Color;
|
||||||
import com.badlogic.gdx.graphics.OrthographicCamera;
|
import com.badlogic.gdx.graphics.OrthographicCamera;
|
||||||
import com.badlogic.gdx.graphics.Texture;
|
import com.badlogic.gdx.graphics.Texture;
|
||||||
@@ -43,9 +42,10 @@ import com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable;
|
|||||||
public abstract class MainMenuStateBase extends BaseState{
|
public abstract class MainMenuStateBase extends BaseState{
|
||||||
protected static final String TAG = "MAIN_MENU";
|
protected static final String TAG = "MAIN_MENU";
|
||||||
private static final String CLASS_NAME = MainMenuStateBase.class.getSimpleName();
|
private static final String CLASS_NAME = MainMenuStateBase.class.getSimpleName();
|
||||||
|
|
||||||
private static final String SHADER_PATH = "shaders/bckg/bckg";
|
private static final String SHADER_PATH = "shaders/bckg/bckg";
|
||||||
|
|
||||||
|
protected final int NUM_MENU_BUTTONS = 2;
|
||||||
|
|
||||||
// Helper fields.
|
// Helper fields.
|
||||||
protected boolean clientConnected;
|
protected boolean clientConnected;
|
||||||
private float u_scaling[];
|
private float u_scaling[];
|
||||||
@@ -56,18 +56,26 @@ public abstract class MainMenuStateBase extends BaseState{
|
|||||||
protected Rectangle startButtonBBox;
|
protected Rectangle startButtonBBox;
|
||||||
protected Sprite clientConnectedLedOn;
|
protected Sprite clientConnectedLedOn;
|
||||||
protected Sprite clientConnectedLedOff;
|
protected Sprite clientConnectedLedOff;
|
||||||
|
|
||||||
|
protected TextButton calibrationButton;
|
||||||
|
protected Rectangle calibrationButtonBBox;
|
||||||
|
protected Sprite cameraCalibratedLedOn;
|
||||||
|
protected Sprite cameraCalibratedLedOff;
|
||||||
|
|
||||||
protected Sprite background;
|
protected Sprite background;
|
||||||
|
|
||||||
// Graphic data for the start button.
|
// Graphic data for the start button.
|
||||||
private Texture startButtonEnabledTexture;
|
private Texture startButtonEnabledTexture;
|
||||||
private Texture startButtonDisabledTexture;
|
private Texture startButtonDisabledTexture;
|
||||||
private Texture startButtonPressedTexture;
|
private Texture startButtonPressedTexture;
|
||||||
private NinePatch startButtonEnabled9p;
|
private NinePatch menuButtonEnabled9p;
|
||||||
private NinePatch startButtonDisabled9p;
|
private NinePatch menuButtonDisabled9p;
|
||||||
private NinePatch startButtonPressed9p;
|
private NinePatch menuButtonPressed9p;
|
||||||
private BitmapFont font;
|
private BitmapFont font;
|
||||||
|
|
||||||
// Other graphics.
|
// Other graphics.
|
||||||
|
private Texture cameraCalibratedLedOffTexture;
|
||||||
|
private Texture cameraCalibratedLedOnTexture;
|
||||||
private Texture clientConnectedLedOffTexture;
|
private Texture clientConnectedLedOffTexture;
|
||||||
private Texture clientConnectedLedOnTexture;
|
private Texture clientConnectedLedOnTexture;
|
||||||
private Texture backgroundTexture;
|
private Texture backgroundTexture;
|
||||||
@@ -78,39 +86,49 @@ public abstract class MainMenuStateBase extends BaseState{
|
|||||||
protected Vector2 touchPointWorldCoords;
|
protected Vector2 touchPointWorldCoords;
|
||||||
protected boolean startButtonTouched;
|
protected boolean startButtonTouched;
|
||||||
protected int startButtonTouchPointer;
|
protected int startButtonTouchPointer;
|
||||||
|
protected boolean calibrationButtonTouched;
|
||||||
|
protected int calibrationButtonTouchPointer;
|
||||||
|
|
||||||
public MainMenuStateBase(){
|
public MainMenuStateBase(){
|
||||||
TextureRegion region;
|
TextureRegion region;
|
||||||
|
TextButtonStyle tbs;
|
||||||
|
|
||||||
this.pixelPerfectCamera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
this.pixelPerfectCamera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
||||||
|
|
||||||
// Create the start button background.
|
// Create the start button background.
|
||||||
startButtonEnabledTexture = new Texture(Gdx.files.internal("data/gfx/gui/Anonymous_Pill_Button_Yellow.png"));
|
startButtonEnabledTexture = new Texture(Gdx.files.internal("data/gfx/gui/Anonymous_Pill_Button_Yellow.png"));
|
||||||
startButtonEnabled9p = new NinePatch(new TextureRegion(startButtonEnabledTexture, 0, 0, startButtonEnabledTexture.getWidth(), startButtonEnabledTexture.getHeight()), 49, 49, 45, 45);
|
menuButtonEnabled9p = new NinePatch(new TextureRegion(startButtonEnabledTexture, 0, 0, startButtonEnabledTexture.getWidth(), startButtonEnabledTexture.getHeight()), 49, 49, 45, 45);
|
||||||
|
|
||||||
startButtonDisabledTexture = new Texture(Gdx.files.internal("data/gfx/gui/Anonymous_Pill_Button_Cyan.png"));
|
startButtonDisabledTexture = new Texture(Gdx.files.internal("data/gfx/gui/Anonymous_Pill_Button_Cyan.png"));
|
||||||
startButtonDisabled9p = new NinePatch(new TextureRegion(startButtonDisabledTexture, 0, 0, startButtonDisabledTexture.getWidth(), startButtonDisabledTexture.getHeight()), 49, 49, 45, 45);
|
menuButtonDisabled9p = new NinePatch(new TextureRegion(startButtonDisabledTexture, 0, 0, startButtonDisabledTexture.getWidth(), startButtonDisabledTexture.getHeight()), 49, 49, 45, 45);
|
||||||
|
|
||||||
startButtonPressedTexture = new Texture(Gdx.files.internal("data/gfx/gui/Anonymous_Pill_Button_Blue.png"));
|
startButtonPressedTexture = new Texture(Gdx.files.internal("data/gfx/gui/Anonymous_Pill_Button_Blue.png"));
|
||||||
startButtonPressed9p = new NinePatch(new TextureRegion(startButtonPressedTexture, 0, 0, startButtonPressedTexture.getWidth(), startButtonPressedTexture.getHeight()), 49, 49, 45, 45);
|
menuButtonPressed9p = new NinePatch(new TextureRegion(startButtonPressedTexture, 0, 0, startButtonPressedTexture.getWidth(), startButtonPressedTexture.getHeight()), 49, 49, 45, 45);
|
||||||
|
|
||||||
// Create the start button font.
|
// Create the start button font.
|
||||||
FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("data/fonts/d-puntillas-B-to-tiptoe.ttf"));
|
FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("data/fonts/d-puntillas-B-to-tiptoe.ttf"));
|
||||||
font = generator.generateFont(Ouya.runningOnOuya ? 60 : 40, ProjectConstants.FONT_CHARS, false);
|
font = generator.generateFont(ProjectConstants.MENU_BUTTON_FONT_SIZE, ProjectConstants.FONT_CHARS, false);
|
||||||
generator.dispose();
|
generator.dispose();
|
||||||
|
|
||||||
// Create the start button itself.
|
// Create the start button.
|
||||||
TextButtonStyle tbs = new TextButtonStyle();
|
tbs = new TextButtonStyle();
|
||||||
tbs.font = font;
|
tbs.font = font;
|
||||||
tbs.up = new NinePatchDrawable(startButtonEnabled9p);
|
tbs.up = new NinePatchDrawable(menuButtonEnabled9p);
|
||||||
tbs.checked = new NinePatchDrawable(startButtonPressed9p);
|
tbs.checked = new NinePatchDrawable(menuButtonPressed9p);
|
||||||
tbs.disabled = new NinePatchDrawable(startButtonDisabled9p);
|
tbs.disabled = new NinePatchDrawable(menuButtonDisabled9p);
|
||||||
tbs.disabledFontColor = new Color(0, 0, 0, 1);
|
tbs.disabledFontColor = new Color(0, 0, 0, 1);
|
||||||
|
|
||||||
startButton = new TextButton("Start server", tbs);
|
startButton = new TextButton("Start server", tbs);
|
||||||
startButton.setText("Start game");
|
startButton.setText("Start game");
|
||||||
startButton.setDisabled(true);
|
startButton.setDisabled(true);
|
||||||
startButtonBBox = new Rectangle(0, 0, startButton.getWidth(), startButton.getHeight());
|
startButtonBBox = new Rectangle(0, 0, startButton.getWidth(), startButton.getHeight());
|
||||||
|
|
||||||
|
// Create the calibration button.
|
||||||
|
calibrationButton = new TextButton("Calibrate camera", tbs);
|
||||||
|
calibrationButton.setText("Calibrate camera");
|
||||||
|
calibrationButton.setDisabled(true);
|
||||||
|
calibrationButtonBBox = new Rectangle(0, 0, calibrationButton.getWidth(), calibrationButton.getHeight());
|
||||||
|
|
||||||
// Create the connection leds.
|
// Create the connection leds.
|
||||||
clientConnectedLedOnTexture = new Texture("data/gfx/gui/Anonymous_Button_Green.png");
|
clientConnectedLedOnTexture = new Texture("data/gfx/gui/Anonymous_Button_Green.png");
|
||||||
region = new TextureRegion(clientConnectedLedOnTexture);
|
region = new TextureRegion(clientConnectedLedOnTexture);
|
||||||
@@ -120,6 +138,14 @@ public abstract class MainMenuStateBase extends BaseState{
|
|||||||
region = new TextureRegion(clientConnectedLedOffTexture);
|
region = new TextureRegion(clientConnectedLedOffTexture);
|
||||||
clientConnectedLedOff = new Sprite(region);
|
clientConnectedLedOff = new Sprite(region);
|
||||||
|
|
||||||
|
cameraCalibratedLedOnTexture = new Texture("data/gfx/gui/Anonymous_Button_Green.png");
|
||||||
|
region = new TextureRegion(cameraCalibratedLedOnTexture);
|
||||||
|
cameraCalibratedLedOn = new Sprite(region);
|
||||||
|
|
||||||
|
cameraCalibratedLedOffTexture = new Texture("data/gfx/gui/Anonymous_Button_Red.png");
|
||||||
|
region = new TextureRegion(cameraCalibratedLedOffTexture);
|
||||||
|
cameraCalibratedLedOff = new Sprite(region);
|
||||||
|
|
||||||
// Set up the background.
|
// Set up the background.
|
||||||
backgroundTexture = new Texture(Gdx.files.internal("data/gfx/textures/tile_aqua.png"));
|
backgroundTexture = new Texture(Gdx.files.internal("data/gfx/textures/tile_aqua.png"));
|
||||||
backgroundTexture.setWrap(TextureWrap.Repeat, TextureWrap.Repeat);
|
backgroundTexture.setWrap(TextureWrap.Repeat, TextureWrap.Repeat);
|
||||||
@@ -145,6 +171,8 @@ public abstract class MainMenuStateBase extends BaseState{
|
|||||||
touchPointWorldCoords = new Vector2();
|
touchPointWorldCoords = new Vector2();
|
||||||
startButtonTouched = false;
|
startButtonTouched = false;
|
||||||
startButtonTouchPointer = -1;
|
startButtonTouchPointer = -1;
|
||||||
|
calibrationButtonTouched = false;
|
||||||
|
calibrationButtonTouchPointer = -1;
|
||||||
|
|
||||||
clientConnected = false;
|
clientConnected = false;
|
||||||
stateActive = false;
|
stateActive = false;
|
||||||
@@ -174,6 +202,8 @@ public abstract class MainMenuStateBase extends BaseState{
|
|||||||
startButtonPressedTexture.dispose();
|
startButtonPressedTexture.dispose();
|
||||||
clientConnectedLedOnTexture.dispose();
|
clientConnectedLedOnTexture.dispose();
|
||||||
clientConnectedLedOffTexture.dispose();
|
clientConnectedLedOffTexture.dispose();
|
||||||
|
cameraCalibratedLedOnTexture.dispose();
|
||||||
|
cameraCalibratedLedOffTexture.dispose();
|
||||||
backgroundTexture.dispose();
|
backgroundTexture.dispose();
|
||||||
if(backgroundShader != null) backgroundShader.dispose();
|
if(backgroundShader != null) backgroundShader.dispose();
|
||||||
font.dispose();
|
font.dispose();
|
||||||
@@ -207,6 +237,7 @@ public abstract class MainMenuStateBase extends BaseState{
|
|||||||
public void onClientConnected(){
|
public void onClientConnected(){
|
||||||
clientConnected = true;
|
clientConnected = true;
|
||||||
startButton.setDisabled(false);
|
startButton.setDisabled(false);
|
||||||
|
calibrationButton.setDisabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*;;;;;;;;;;;;;;;;;;
|
/*;;;;;;;;;;;;;;;;;;
|
||||||
@@ -230,11 +261,16 @@ public abstract class MainMenuStateBase extends BaseState{
|
|||||||
Gdx.app.log(TAG, CLASS_NAME + String.format(".touchDown(%d, %d, %d, %d)", screenX, screenY, pointer, button));
|
Gdx.app.log(TAG, CLASS_NAME + String.format(".touchDown(%d, %d, %d, %d)", screenX, screenY, pointer, button));
|
||||||
Gdx.app.log(TAG, CLASS_NAME + String.format(".touchDown() :: Unprojected touch point: (%f, %f)", touchPointWorldCoords.x, touchPointWorldCoords.y));
|
Gdx.app.log(TAG, CLASS_NAME + String.format(".touchDown() :: Unprojected touch point: (%f, %f)", touchPointWorldCoords.x, touchPointWorldCoords.y));
|
||||||
|
|
||||||
if(!startButton.isDisabled() && startButtonBBox.contains(touchPointWorldCoords)){
|
if(!startButton.isDisabled() && startButtonBBox.contains(touchPointWorldCoords) && !calibrationButtonTouched){
|
||||||
startButton.setChecked(true);
|
startButton.setChecked(true);
|
||||||
startButtonTouched = true;
|
startButtonTouched = true;
|
||||||
startButtonTouchPointer = pointer;
|
startButtonTouchPointer = pointer;
|
||||||
Gdx.app.log(TAG, CLASS_NAME + ".touchDown() :: Start button pressed.");
|
Gdx.app.log(TAG, CLASS_NAME + ".touchDown() :: Start button pressed.");
|
||||||
|
}else if(!calibrationButton.isDisabled() && calibrationButtonBBox.contains(touchPointWorldCoords) && !startButtonTouched){
|
||||||
|
calibrationButton.setChecked(true);
|
||||||
|
calibrationButtonTouched = true;
|
||||||
|
calibrationButtonTouchPointer = pointer;
|
||||||
|
Gdx.app.log(TAG, CLASS_NAME + ".touchDown() :: Calibration button pressed.");
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -247,12 +283,18 @@ public abstract class MainMenuStateBase extends BaseState{
|
|||||||
Gdx.app.log(TAG, CLASS_NAME + String.format(".touchUp(%d, %d, %d, %d)", screenX, screenY, pointer, button));
|
Gdx.app.log(TAG, CLASS_NAME + String.format(".touchUp(%d, %d, %d, %d)", screenX, screenY, pointer, button));
|
||||||
Gdx.app.log(TAG, CLASS_NAME + String.format(".touchUp() :: Unprojected touch point: (%f, %f)", touchPointWorldCoords.x, touchPointWorldCoords.y));
|
Gdx.app.log(TAG, CLASS_NAME + String.format(".touchUp() :: Unprojected touch point: (%f, %f)", touchPointWorldCoords.x, touchPointWorldCoords.y));
|
||||||
|
|
||||||
if(!startButton.isDisabled() && startButtonBBox.contains(touchPointWorldCoords)){
|
if(!startButton.isDisabled() && startButtonBBox.contains(touchPointWorldCoords) && startButtonTouched){
|
||||||
startButton.setChecked(false);
|
startButton.setChecked(false);
|
||||||
startButtonTouched = false;
|
startButtonTouched = false;
|
||||||
startButtonTouchPointer = -1;
|
startButtonTouchPointer = -1;
|
||||||
core.nextState = game_states_t.IN_GAME;
|
core.nextState = game_states_t.IN_GAME;
|
||||||
Gdx.app.log(TAG, CLASS_NAME + ".touchDown() :: Start button released.");
|
Gdx.app.log(TAG, CLASS_NAME + ".touchDown() :: Start button released.");
|
||||||
|
}else if(!calibrationButton.isDisabled() && calibrationButtonBBox.contains(touchPointWorldCoords) && calibrationButtonTouched){
|
||||||
|
calibrationButton.setChecked(false);
|
||||||
|
calibrationButtonTouched = false;
|
||||||
|
calibrationButtonTouchPointer = -1;
|
||||||
|
core.nextState = game_states_t.CALIBRATION;
|
||||||
|
Gdx.app.log(TAG, CLASS_NAME + ".touchDown() :: Calibration button released.");
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -267,6 +309,11 @@ public abstract class MainMenuStateBase extends BaseState{
|
|||||||
startButtonTouched = false;
|
startButtonTouched = false;
|
||||||
startButton.setChecked(false);
|
startButton.setChecked(false);
|
||||||
Gdx.app.log(TAG, CLASS_NAME + ".touchDragged() :: Start button released.");
|
Gdx.app.log(TAG, CLASS_NAME + ".touchDragged() :: Start button released.");
|
||||||
|
}else if(!calibrationButton.isDisabled() && calibrationButtonTouched && pointer == calibrationButtonTouchPointer && !calibrationButtonBBox.contains(touchPointWorldCoords)){
|
||||||
|
calibrationButtonTouchPointer = -1;
|
||||||
|
calibrationButtonTouched = false;
|
||||||
|
calibrationButton.setChecked(false);
|
||||||
|
Gdx.app.log(TAG, CLASS_NAME + ".touchDragged() :: Start button released.");
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@@ -32,14 +32,20 @@ public class OuyaMainMenuState extends MainMenuStateBase{
|
|||||||
private Texture ouyaOButtonTexture;
|
private Texture ouyaOButtonTexture;
|
||||||
private Sprite ouyaOButton;
|
private Sprite ouyaOButton;
|
||||||
private boolean oButtonPressed;
|
private boolean oButtonPressed;
|
||||||
|
private int oButtonSelection;
|
||||||
|
|
||||||
public OuyaMainMenuState(final NxtARCore core){
|
public OuyaMainMenuState(final NxtARCore core){
|
||||||
|
super();
|
||||||
|
|
||||||
this.core = core;
|
this.core = core;
|
||||||
|
|
||||||
startButton.setPosition(-(startButton.getWidth() / 2), -(startButton.getHeight() / 2));
|
startButton.setPosition(-(startButton.getWidth() / 2), -(startButton.getHeight() / 2));
|
||||||
startButtonBBox.setPosition(startButton.getX(), startButton.getY());
|
startButtonBBox.setPosition(startButton.getX(), startButton.getY());
|
||||||
|
|
||||||
float ledYPos = (-(Gdx.graphics.getHeight() / 2) * 0.5f) + (startButton.getY() * 0.5f);
|
calibrationButton.setPosition(-(calibrationButton.getWidth() / 2), (startButton.getY() + startButton.getHeight()) + 10);
|
||||||
|
calibrationButtonBBox.setPosition(calibrationButton.getX(), calibrationButton.getY());
|
||||||
|
|
||||||
|
float ledYPos = (-(Gdx.graphics.getHeight() / 2) * 0.5f) + (calibrationButton.getY() * 0.5f);
|
||||||
clientConnectedLedOn.setSize(clientConnectedLedOn.getWidth() * 0.5f, clientConnectedLedOn.getHeight() * 0.5f);
|
clientConnectedLedOn.setSize(clientConnectedLedOn.getWidth() * 0.5f, clientConnectedLedOn.getHeight() * 0.5f);
|
||||||
clientConnectedLedOn.setPosition(-(clientConnectedLedOn.getWidth() / 2), ledYPos);
|
clientConnectedLedOn.setPosition(-(clientConnectedLedOn.getWidth() / 2), ledYPos);
|
||||||
|
|
||||||
@@ -50,8 +56,8 @@ public class OuyaMainMenuState extends MainMenuStateBase{
|
|||||||
TextureRegion region = new TextureRegion(ouyaOButtonTexture, ouyaOButtonTexture.getWidth(), ouyaOButtonTexture.getHeight());
|
TextureRegion region = new TextureRegion(ouyaOButtonTexture, ouyaOButtonTexture.getWidth(), ouyaOButtonTexture.getHeight());
|
||||||
ouyaOButton = new Sprite(region);
|
ouyaOButton = new Sprite(region);
|
||||||
ouyaOButton.setSize(ouyaOButton.getWidth() * 0.6f, ouyaOButton.getHeight() * 0.6f);
|
ouyaOButton.setSize(ouyaOButton.getWidth() * 0.6f, ouyaOButton.getHeight() * 0.6f);
|
||||||
ouyaOButton.setPosition(startButton.getX() - ouyaOButton.getWidth() - 20, startButton.getY() + (ouyaOButton.getHeight() / 2));
|
|
||||||
|
|
||||||
|
oButtonSelection = 0;
|
||||||
oButtonPressed = false;
|
oButtonPressed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,13 +71,23 @@ public class OuyaMainMenuState extends MainMenuStateBase{
|
|||||||
core.batch.disableBlending();
|
core.batch.disableBlending();
|
||||||
drawBackground(core.batch);
|
drawBackground(core.batch);
|
||||||
core.batch.enableBlending();
|
core.batch.enableBlending();
|
||||||
|
|
||||||
if(clientConnected){
|
if(clientConnected){
|
||||||
clientConnectedLedOn.draw(core.batch);
|
clientConnectedLedOn.draw(core.batch);
|
||||||
}else{
|
}else{
|
||||||
clientConnectedLedOff.draw(core.batch);
|
clientConnectedLedOff.draw(core.batch);
|
||||||
}
|
}
|
||||||
|
|
||||||
startButton.draw(core.batch, 1.0f);
|
startButton.draw(core.batch, 1.0f);
|
||||||
|
calibrationButton.draw(core.batch, 1.0f);
|
||||||
|
|
||||||
|
if(oButtonSelection == 0){
|
||||||
|
ouyaOButton.setPosition(startButton.getX() - ouyaOButton.getWidth() - 20, startButton.getY() + (ouyaOButton.getHeight() / 2));
|
||||||
|
}else if(oButtonSelection == 1){
|
||||||
|
ouyaOButton.setPosition(calibrationButton.getX() - ouyaOButton.getWidth() - 20, calibrationButton.getY() + (ouyaOButton.getHeight() / 2));
|
||||||
|
}
|
||||||
ouyaOButton.draw(core.batch);
|
ouyaOButton.draw(core.batch);
|
||||||
|
|
||||||
}core.batch.end();
|
}core.batch.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,16 +105,32 @@ public class OuyaMainMenuState extends MainMenuStateBase{
|
|||||||
public boolean buttonDown(Controller controller, int buttonCode) {
|
public boolean buttonDown(Controller controller, int buttonCode) {
|
||||||
if(stateActive){
|
if(stateActive){
|
||||||
if(buttonCode == Ouya.BUTTON_O){
|
if(buttonCode == Ouya.BUTTON_O){
|
||||||
if(!clientConnected){
|
Gdx.app.log(TAG, CLASS_NAME + ".buttonDown(): O button pressed.");
|
||||||
core.toast("Can't start the game. No client is connected.", true);
|
|
||||||
}else{
|
if(oButtonSelection == 0){
|
||||||
oButtonPressed = true;
|
if(!clientConnected){
|
||||||
startButton.setChecked(true);
|
core.toast("Can't start the game. No client is connected.", true);
|
||||||
|
}else{
|
||||||
|
oButtonPressed = true;
|
||||||
|
startButton.setChecked(true);
|
||||||
|
}
|
||||||
|
}else if(oButtonSelection == 1){
|
||||||
|
if(!clientConnected){
|
||||||
|
core.toast("Can't calibrate the camera. No client is connected.", true);
|
||||||
|
}else{
|
||||||
|
oButtonPressed = true;
|
||||||
|
calibrationButton.setChecked(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}else if(buttonCode == Ouya.BUTTON_DPAD_UP){
|
||||||
|
Gdx.app.log(TAG, CLASS_NAME + ".buttonDown(): Dpad up button pressed.");
|
||||||
|
oButtonSelection = oButtonSelection - 1 < 0 ? NUM_MENU_BUTTONS - 1 : oButtonSelection - 1;
|
||||||
|
}else if(buttonCode == Ouya.BUTTON_DPAD_DOWN){
|
||||||
|
Gdx.app.log(TAG, CLASS_NAME + ".buttonDown(): Dpad down button pressed.");
|
||||||
|
oButtonSelection = (oButtonSelection + 1) % NUM_MENU_BUTTONS;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -108,16 +140,22 @@ public class OuyaMainMenuState extends MainMenuStateBase{
|
|||||||
public boolean buttonUp(Controller controller, int buttonCode) {
|
public boolean buttonUp(Controller controller, int buttonCode) {
|
||||||
if(stateActive){
|
if(stateActive){
|
||||||
if(buttonCode == Ouya.BUTTON_O){
|
if(buttonCode == Ouya.BUTTON_O){
|
||||||
|
Gdx.app.log(TAG, CLASS_NAME + ".buttonDown(): O button released.");
|
||||||
|
|
||||||
if(oButtonPressed){
|
if(oButtonPressed){
|
||||||
oButtonPressed = false;
|
oButtonPressed = false;
|
||||||
startButton.setChecked(false);
|
|
||||||
core.nextState = game_states_t.IN_GAME;
|
if(oButtonSelection == 0){
|
||||||
Gdx.app.log(TAG, CLASS_NAME + ".touchDown() :: Start button released.");
|
startButton.setChecked(false);
|
||||||
|
core.nextState = game_states_t.IN_GAME;
|
||||||
|
}else if(oButtonSelection == 1){
|
||||||
|
calibrationButton.setChecked(false);
|
||||||
|
core.nextState = game_states_t.IN_GAME;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@@ -21,12 +21,19 @@ import com.badlogic.gdx.Gdx;
|
|||||||
import com.badlogic.gdx.graphics.GL10;
|
import com.badlogic.gdx.graphics.GL10;
|
||||||
|
|
||||||
public class TabletMainMenuState extends MainMenuStateBase{
|
public class TabletMainMenuState extends MainMenuStateBase{
|
||||||
|
|
||||||
public TabletMainMenuState(final NxtARCore core){
|
public TabletMainMenuState(final NxtARCore core){
|
||||||
|
super();
|
||||||
|
|
||||||
this.core = core;
|
this.core = core;
|
||||||
|
|
||||||
startButton.setPosition(-(startButton.getWidth() / 2), -(startButton.getHeight() / 2));
|
startButton.setPosition(-(startButton.getWidth() / 2), -(startButton.getHeight() / 2));
|
||||||
startButtonBBox.setPosition(startButton.getX(), startButton.getY());
|
startButtonBBox.setPosition(startButton.getX(), startButton.getY());
|
||||||
|
|
||||||
float ledYPos = (-(Gdx.graphics.getHeight() / 2) * 0.5f) + (startButton.getY() * 0.5f);
|
calibrationButton.setPosition(-(calibrationButton.getWidth() / 2), (startButton.getY() + startButton.getHeight()) + 10);
|
||||||
|
calibrationButtonBBox.setPosition(calibrationButton.getX(), calibrationButton.getY());
|
||||||
|
|
||||||
|
float ledYPos = (-(Gdx.graphics.getHeight() / 2) * 0.5f) + (calibrationButton.getY() * 0.5f);
|
||||||
clientConnectedLedOn.setSize(clientConnectedLedOn.getWidth() * 0.5f, clientConnectedLedOn.getHeight() * 0.5f);
|
clientConnectedLedOn.setSize(clientConnectedLedOn.getWidth() * 0.5f, clientConnectedLedOn.getHeight() * 0.5f);
|
||||||
clientConnectedLedOn.setPosition(-(clientConnectedLedOn.getWidth() / 2), ledYPos);
|
clientConnectedLedOn.setPosition(-(clientConnectedLedOn.getWidth() / 2), ledYPos);
|
||||||
|
|
||||||
@@ -41,6 +48,7 @@ public class TabletMainMenuState extends MainMenuStateBase{
|
|||||||
|
|
||||||
core.batch.setProjectionMatrix(pixelPerfectCamera.combined);
|
core.batch.setProjectionMatrix(pixelPerfectCamera.combined);
|
||||||
core.batch.begin();{
|
core.batch.begin();{
|
||||||
|
|
||||||
core.batch.disableBlending();
|
core.batch.disableBlending();
|
||||||
drawBackground(core.batch);
|
drawBackground(core.batch);
|
||||||
core.batch.enableBlending();
|
core.batch.enableBlending();
|
||||||
@@ -50,7 +58,10 @@ public class TabletMainMenuState extends MainMenuStateBase{
|
|||||||
}else{
|
}else{
|
||||||
clientConnectedLedOff.draw(core.batch);
|
clientConnectedLedOff.draw(core.batch);
|
||||||
}
|
}
|
||||||
|
|
||||||
startButton.draw(core.batch, 1.0f);
|
startButton.draw(core.batch, 1.0f);
|
||||||
|
calibrationButton.draw(core.batch, 1.0f);
|
||||||
|
|
||||||
}core.batch.end();
|
}core.batch.end();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -34,6 +34,7 @@ public abstract class ProjectConstants{
|
|||||||
public static final int[] POWERS_OF_2 = {64, 128, 256, 512, 1024, 2048};
|
public static final int[] POWERS_OF_2 = {64, 128, 256, 512, 1024, 2048};
|
||||||
|
|
||||||
public static final float OVERSCAN;
|
public static final float OVERSCAN;
|
||||||
|
public static final int MENU_BUTTON_FONT_SIZE;
|
||||||
|
|
||||||
public static final String FONT_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
|
public static final String FONT_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
|
||||||
|
|
||||||
@@ -42,5 +43,6 @@ public abstract class ProjectConstants{
|
|||||||
|
|
||||||
static{
|
static{
|
||||||
OVERSCAN = Ouya.runningOnOuya ? 0.9f : 1.0f;
|
OVERSCAN = Ouya.runningOnOuya ? 0.9f : 1.0f;
|
||||||
|
MENU_BUTTON_FONT_SIZE = Ouya.runningOnOuya ? 60 : 40;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user