Fixed OuyaMainMenuState.

This commit is contained in:
2014-02-06 22:34:37 -04:30
parent e88305f0ff
commit 39426cd2a6
9 changed files with 1356 additions and 1384 deletions

View File

@@ -128,6 +128,10 @@ public class NxtARCore extends Game implements NetworkConnectionListener{
states[game_states_t.IN_GAME.getValue()] = new InGameState(this);
states[game_states_t.PAUSED.getValue()] = new PauseState(this);
for(BaseState state : states){
Controllers.addListener(state);
}
// Set up fields.
batch = new SpriteBatch();
@@ -180,15 +184,14 @@ public class NxtARCore extends Game implements NetworkConnectionListener{
// If the current state set a value for nextState then switch to that state.
if(nextState != null){
// Invalidate all input processors.
Gdx.input.setInputProcessor(null);
Controllers.removeListener(states[currState.getValue()]);
states[currState.getValue()].onStateUnset();
// Swap the pointers and set the new screen.
currState = nextState;
nextState = null;
setScreen(states[currState.getValue()]);
states[currState.getValue()].onStateSet();
setScreen(states[currState.getValue()]);
}
if(ProjectConstants.DEBUG){

View File

@@ -26,9 +26,11 @@ import com.badlogic.gdx.math.Vector3;
public abstract class BaseState implements Screen, ControllerListener, InputProcessor {
protected NxtARCore core;
protected boolean stateActive;
/* STATE METHODS */
public abstract void onStateSet();
public abstract void onStateUnset();
/* SCREEN METHODS*/
@Override

View File

@@ -213,10 +213,16 @@ public class InGameState extends BaseState{
@Override
public void onStateSet(){
Controllers.addListener(this);
stateActive = true;
Gdx.input.setInputProcessor(this);
}
@Override
public void onStateUnset(){
stateActive = false;
Gdx.input.setInputProcessor(null);
}
private void setUpButtons(){
buttonTexture = new Texture(Gdx.files.internal("data/gfx/gui/PBCrichton_Flat_Button.png"));
buttonTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
@@ -363,6 +369,43 @@ public class InGameState extends BaseState{
; BEGIN CONTROLLER LISTENER METHODS ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;*/
@Override
public boolean buttonDown(Controller controller, int buttonCode) {
if(stateActive){
Gdx.app.log(TAG, CLASS_NAME + ".buttonDown() :: " + controller.getName() + " :: " + Integer.toString(buttonCode));
return true;
}else{
return false;
}
}
@Override
public boolean buttonUp(Controller controller, int buttonCode) {
if(stateActive){
Gdx.app.log(TAG, CLASS_NAME + ".buttonDown() :: " + controller.getName() + " :: " + Integer.toString(buttonCode));
return true;
}else{
return false;
}
}
@Override
public boolean axisMoved(Controller controller, int axisCode, float value) {
if(stateActive){
if(value >= Ouya.STICK_DEADZONE){
if(axisCode == Ouya.AXIS_LEFT_TRIGGER){
Gdx.app.log(TAG, CLASS_NAME + ".axisMoved() :: LEFT TRIGGER pressed.");
}
if(axisCode == Ouya.AXIS_RIGHT_TRIGGER){
Gdx.app.log(TAG, CLASS_NAME + ".axisMoved() :: RIGHT TRIGGER pressed.");
}
}
return true;
}else{
return false;
}
}
@Override
public boolean scrolled(int amount) {
// TODO Auto-generated method stub
@@ -381,40 +424,6 @@ public class InGameState extends BaseState{
}
@Override
public boolean buttonDown(Controller controller, int buttonCode) {
if(buttonCode == Ouya.BUTTON_L1){
// Start right motor.
}
if(buttonCode == Ouya.BUTTON_L2){
// Start left motor.
}
if(buttonCode == Ouya.BUTTON_DPAD_LEFT){
// Look left.
}
if(buttonCode == Ouya.BUTTON_DPAD_RIGHT){
// Look right;
}
return false;
}
@Override
public boolean buttonUp(Controller controller, int buttonCode) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean axisMoved(Controller controller, int axisCode, float value) {
if(axisCode == Ouya.AXIS_LEFT_TRIGGER){
}
if(axisCode == Ouya.AXIS_RIGHT_TRIGGER){
// Start
}
return false;
}
@Override
public boolean povMoved(Controller controller, int povCode,
PovDirection value) {

View File

@@ -18,7 +18,8 @@ package ve.ucv.ciens.ccg.nxtar.states;
import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.controllers.Controllers;
import com.badlogic.gdx.controllers.Controller;
import com.badlogic.gdx.controllers.PovDirection;
import com.badlogic.gdx.controllers.mappings.Ouya;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture;
@@ -28,6 +29,7 @@ import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle;
import com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable;
@@ -97,6 +99,8 @@ public abstract class MainMenuStateBase extends BaseState{
clientConnectedLedOff = new Sprite(region);
clientConnected = false;
stateActive = false;
}
@Override
@@ -128,12 +132,103 @@ public abstract class MainMenuStateBase extends BaseState{
@Override
public void onStateSet(){
Controllers.addListener(this);
stateActive = true;
Gdx.input.setInputProcessor(this);
}
@Override
public void onStateUnset(){
stateActive = false;
Gdx.input.setInputProcessor(null);
}
public void onClientConnected(){
clientConnected = true;
startButton.setDisabled(false);
}
/*;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; INPUT LISTENER METHOD STUBS ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;*/
@Override
public boolean keyDown(int keycode){
return false;
}
@Override
public boolean keyUp(int keycode){
return false;
}
@Override
public boolean keyTyped(char character){
return false;
}
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button){
return false;
}
@Override
public boolean touchUp(int screenX, int screenY, int pointer, int button){
return false;
}
@Override
public boolean touchDragged(int screenX, int screenY, int pointer){
return false;
}
@Override
public boolean mouseMoved(int screenX, int screenY){
return false;
}
@Override
public boolean scrolled(int amount){
return false;
}
@Override
public void connected(Controller controller){ }
@Override
public void disconnected(Controller controller){ }
@Override
public boolean buttonDown(Controller controller, int buttonCode){
return false;
}
@Override
public boolean buttonUp(Controller controller, int buttonCode){
return false;
}
@Override
public boolean axisMoved(Controller controller, int axisCode, float value){
return false;
}
@Override
public boolean povMoved(Controller controller, int povCode, PovDirection value){
return false;
}
@Override
public boolean xSliderMoved(Controller controller, int sliderCode, boolean value){
return false;
}
@Override
public boolean ySliderMoved(Controller controller, int sliderCode, boolean value){
return false;
}
@Override
public boolean accelerometerMoved(Controller controller, int accelerometerCode, Vector3 value){
return false;
}
}

View File

@@ -16,21 +16,46 @@
package ve.ucv.ciens.ccg.nxtar.states;
import ve.ucv.ciens.ccg.nxtar.NxtARCore;
import ve.ucv.ciens.ccg.nxtar.NxtARCore.game_states_t;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.controllers.Controller;
import com.badlogic.gdx.controllers.Controllers;
import com.badlogic.gdx.controllers.PovDirection;
import com.badlogic.gdx.controllers.mappings.Ouya;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
public class OuyaMainMenuState extends MainMenuStateBase{
private static final String CLASS_NAME = OuyaMainMenuState.class.getSimpleName();
private OrthographicCamera pixelPerfectCamera;
private Texture ouyaOButtonTexture;
private Sprite ouyaOButton;
private boolean oButtonPressed;
public OuyaMainMenuState(final NxtARCore core){
this.core = core;
this.pixelPerfectCamera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
startButton.setPosition(-(startButton.getWidth() / 2), -(startButton.getHeight() / 2));
startButtonBBox.setPosition(startButton.getX(), startButton.getY());
float ledYPos = (-(Gdx.graphics.getHeight() / 2) * 0.5f) + (startButton.getY() * 0.5f);
clientConnectedLedOn.setSize(clientConnectedLedOn.getWidth() * 0.5f, clientConnectedLedOn.getHeight() * 0.5f);
clientConnectedLedOn.setPosition(-(clientConnectedLedOn.getWidth() / 2), ledYPos);
clientConnectedLedOff.setSize(clientConnectedLedOff.getWidth() * 0.5f, clientConnectedLedOff.getHeight() * 0.5f);
clientConnectedLedOff.setPosition(-(clientConnectedLedOff.getWidth() / 2), ledYPos);
ouyaOButtonTexture = new Texture("data/gfx/gui/OUYA_O.png");
TextureRegion region = new TextureRegion(ouyaOButtonTexture, ouyaOButtonTexture.getWidth(), ouyaOButtonTexture.getHeight());
ouyaOButton = new Sprite(region);
ouyaOButton.setSize(ouyaOButton.getWidth() * 0.6f, ouyaOButton.getHeight() * 0.6f);
ouyaOButton.setPosition(startButton.getX() - ouyaOButton.getWidth() - 20, startButton.getY());
oButtonPressed = false;
}
@Override
@@ -40,7 +65,13 @@ public class OuyaMainMenuState extends MainMenuStateBase{
core.batch.setProjectionMatrix(pixelPerfectCamera.combined);
core.batch.begin();{
this.startButton.draw(core.batch, 1.0f);
if(clientConnected){
clientConnectedLedOn.draw(core.batch);
}else{
clientConnectedLedOff.draw(core.batch);
}
startButton.draw(core.batch, 1.0f);
ouyaOButton.draw(core.batch);
}core.batch.end();
}
@@ -77,128 +108,48 @@ public class OuyaMainMenuState extends MainMenuStateBase{
@Override
public void dispose(){
super.dispose();
}
/*;;;;;;;;;;;;;;;;;;
; HELPER METHODS ;
;;;;;;;;;;;;;;;;;;*/
@Override
public void onStateSet(){
super.onStateSet();
}
/*;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; BEGIN INPUT PROCESSOR METHODS ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;*/
@Override
public boolean keyDown(int keycode) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean keyUp(int keycode) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean keyTyped(char character) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean touchDragged(int screenX, int screenY, int pointer) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean mouseMoved(int screenX, int screenY) {
// TODO Auto-generated method stub
return false;
ouyaOButtonTexture.dispose();
}
/*;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; BEGIN CONTROLLER LISTENER METHODS ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;*/
@Override
public boolean scrolled(int amount) {
// TODO Auto-generated method stub
return false;
}
@Override
public void connected(Controller controller) {
// TODO Auto-generated method stub
}
@Override
public void disconnected(Controller controller) {
// TODO Auto-generated method stub
}
@Override
public boolean buttonDown(Controller controller, int buttonCode) {
// TODO Auto-generated method stub
if(stateActive){
if(buttonCode == Ouya.BUTTON_O){
if(!clientConnected){
core.toast("Can't start the game. No client is connected.", true);
}else{
oButtonPressed = true;
startButton.setChecked(true);
}
}
return true;
}else{
return false;
}
}
@Override
public boolean buttonUp(Controller controller, int buttonCode) {
// TODO Auto-generated method stub
return false;
if(stateActive){
if(buttonCode == Ouya.BUTTON_O){
if(oButtonPressed){
oButtonPressed = false;
startButton.setChecked(false);
core.nextState = game_states_t.IN_GAME;
Gdx.app.log(TAG, CLASS_NAME + ".touchDown() :: Start button released.");
}
}
@Override
public boolean axisMoved(Controller controller, int axisCode, float value) {
// TODO Auto-generated method stub
return false;
}
return true;
@Override
public boolean povMoved(Controller controller, int povCode,
PovDirection value) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean xSliderMoved(Controller controller, int sliderCode,
boolean value) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean ySliderMoved(Controller controller, int sliderCode,
boolean value) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean accelerometerMoved(Controller controller,
int accelerometerCode, Vector3 value) {
// TODO Auto-generated method stub
}else{
return false;
}
}
}

View File

@@ -17,7 +17,9 @@ package ve.ucv.ciens.ccg.nxtar.states;
import ve.ucv.ciens.ccg.nxtar.NxtARCore;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.controllers.Controller;
import com.badlogic.gdx.controllers.Controllers;
import com.badlogic.gdx.controllers.PovDirection;
import com.badlogic.gdx.math.Vector3;
@@ -77,6 +79,10 @@ public class PauseState extends BaseState {
public void onStateSet(){
}
@Override
public void onStateUnset(){
}
/*;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; BEGIN INPUT PROCESSOR METHODS ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;*/

View File

@@ -19,15 +19,13 @@ import ve.ucv.ciens.ccg.nxtar.NxtARCore;
import ve.ucv.ciens.ccg.nxtar.NxtARCore.game_states_t;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.controllers.Controller;
import com.badlogic.gdx.controllers.PovDirection;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3;
public class TabletMainMenuState extends MainMenuStateBase{
protected static final String CLASS_NAME = TabletMainMenuState.class.getSimpleName();
private static final String CLASS_NAME = TabletMainMenuState.class.getSimpleName();
private OrthographicCamera pixelPerfectCamera;
@@ -97,11 +95,6 @@ public class TabletMainMenuState extends MainMenuStateBase{
; HELPER METHODS ;
;;;;;;;;;;;;;;;;;;*/
@Override
public void onStateSet(){
super.onStateSet();
}
private void unprojectTouch(int screenX, int screenY){
win2world.set(screenX, screenY, 0.0f);
pixelPerfectCamera.unproject(win2world);
@@ -109,7 +102,7 @@ public class TabletMainMenuState extends MainMenuStateBase{
}
/*;;;;;;;;;;;;;;;;;;;;;;;;;;;
; INPUT PROCESSOR METHODS ;
; INPUT LISTENER METHODS ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;*/
@Override
@@ -123,7 +116,6 @@ public class TabletMainMenuState extends MainMenuStateBase{
startButton.setChecked(true);
startButtonTouched = true;
startButtonTouchPointer = pointer;
core.nextState = game_states_t.IN_GAME;
Gdx.app.log(TAG, CLASS_NAME + ".touchDown() :: Start button pressed.");
}
@@ -141,6 +133,7 @@ public class TabletMainMenuState extends MainMenuStateBase{
startButton.setChecked(false);
startButtonTouched = false;
startButtonTouchPointer = -1;
core.nextState = game_states_t.IN_GAME;
Gdx.app.log(TAG, CLASS_NAME + ".touchDown() :: Start button released.");
}
@@ -160,91 +153,4 @@ public class TabletMainMenuState extends MainMenuStateBase{
return true;
}
/*;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; UNUSED CONTROLLER LISTENER METHODS ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;*/
@Override
public boolean keyDown(int keycode){
// Unused.
return false;
}
@Override
public boolean keyUp(int keycode){
// Unused.
return false;
}
@Override
public boolean keyTyped(char character){
// Unused.
return false;
}
@Override
public boolean mouseMoved(int screenX, int screenY){
// Unused.
return false;
}
@Override
public boolean scrolled(int amount){
// Unused.
return false;
}
@Override
public void connected(Controller controller){
// Unused.
}
@Override
public void disconnected(Controller controller){
// Unused.
}
@Override
public boolean buttonDown(Controller controller, int buttonCode){
// Unused.
return false;
}
@Override
public boolean buttonUp(Controller controller, int buttonCode){
// Unused.
return false;
}
@Override
public boolean axisMoved(Controller controller, int axisCode, float value){
// Unused.
return false;
}
@Override
public boolean povMoved(Controller controller, int povCode, PovDirection value){
// Unused.
return false;
}
@Override
public boolean xSliderMoved(Controller controller, int sliderCode, boolean value){
// Unused.
return false;
}
@Override
public boolean ySliderMoved(Controller controller, int sliderCode, boolean value){
// Unused.
return false;
}
@Override
public boolean accelerometerMoved(Controller controller, int accelerometerCode, Vector3 value){
// Unused.
return false;
}
}

View File

@@ -31,7 +31,7 @@ public abstract class ProjectConstants {
public static final float OVERSCAN;
public static final String FONT_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890.,:;!<EFBFBD>?<3F>";
public static final String FONT_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890.,:;!?";
static{
OVERSCAN = Ouya.runningOnOuya ? 0.9f : 1.0f;