update touch controls

This commit is contained in:
Anthony Calosa
2022-02-26 11:58:51 +08:00
parent 14d71ad278
commit 9c72cd2279
9 changed files with 86 additions and 46 deletions

View File

@@ -1023,7 +1023,7 @@ public class Forge implements ApplicationListener {
return fling(0,1000);
}
if(keyCode == Keys.BACK){
if (destroyThis)
if ((destroyThis && !isMobileAdventureMode)||(splashScreen != null && splashScreen.isShowModeSelector()))
exitAnimation(false);
else if(onHomeScreen() && isLandscapeMode())
back();

View File

@@ -74,7 +74,7 @@ public class DeckSelectScene extends UIScene {
@Override
public boolean keyPressed(int keycode) {
if (keycode == Input.Keys.ESCAPE) {
if (keycode == Input.Keys.ESCAPE || keycode == Input.Keys.BACK) {
back();
}
return true;

View File

@@ -59,7 +59,7 @@ public class InnScene extends UIScene {
@Override
public boolean keyPressed(int keycode) {
if (keycode == Input.Keys.ESCAPE) {
if (keycode == Input.Keys.ESCAPE || keycode == Input.Keys.BACK) {
done();
}
return true;

View File

@@ -41,7 +41,7 @@ public class PlayerStatisticScene extends UIScene {
@Override
public boolean keyPressed(int keycode) {
if (keycode == Input.Keys.ESCAPE) {
if (keycode == Input.Keys.ESCAPE || keycode == Input.Keys.BACK) {
back();
}
return true;
@@ -92,7 +92,7 @@ public class PlayerStatisticScene extends UIScene {
enemiesGroup.add((data.name)).fillX().align(Align.center).fillX().space(3, 10, 3, 10);
enemiesGroup.add((entry.getValue().getLeft().toString())).space(3, 2, 3, 2);
enemiesGroup.add(("/")).align(Align.center).space(3, 2, 3, 2);
enemiesGroup.add((entry.getValue().getRight().toString())).align(Align.center).space(0, 2, 0, 2);
enemiesGroup.add((entry.getValue().getRight().toString())).align(Align.center).space(3, 2, 3, 2);
enemiesGroup.row().space(8);
}

View File

@@ -104,7 +104,7 @@ public class RewardScene extends UIScene {
@Override
public boolean keyPressed(int keycode) {
if (keycode == Input.Keys.ESCAPE) {
if (keycode == Input.Keys.ESCAPE || keycode == Input.Keys.BACK) {
done();
}
return true;

View File

@@ -60,7 +60,7 @@ public class SaveLoadScene extends UIScene {
@Override
public void clicked(InputEvent event, float x, float y) {
try {
if(!button.isDisabled())
if (!button.isDisabled())
select(i);
} catch (Exception e) {
e.printStackTrace();
@@ -126,7 +126,7 @@ public class SaveLoadScene extends UIScene {
@Override
public boolean keyPressed(int keycode) {
if (keycode == Input.Keys.ESCAPE) {
if (keycode == Input.Keys.ESCAPE || keycode == Input.Keys.BACK) {
back();
}
return true;

View File

@@ -65,7 +65,7 @@ public class SettingsScene extends UIScene {
@Override
public boolean keyPressed(int keycode) {
if (keycode == Input.Keys.ESCAPE) {
if (keycode == Input.Keys.ESCAPE || keycode == Input.Keys.BACK) {
back();
}
return true;
@@ -157,7 +157,7 @@ public class SettingsScene extends UIScene {
void addLabel(String name) {
Label label = new Label(name, Controls.GetSkin().get("white", Label.LabelStyle.class));
settingGroup.row().space(5);
settingGroup.add(label).align(Align.left).pad(2,2, 2, 5);
settingGroup.add(label).align(Align.left).pad(2, 2, 2, 5);
}
@Override

View File

@@ -16,11 +16,11 @@ public class StartScene extends UIScene {
Actor saveButton;
Actor resumeButton;
public StartScene()
{
public StartScene() {
super(GuiBase.isAndroid() ? "ui/start_menu_mobile.json" : "ui/start_menu.json");
}
public boolean NewGame() {
Forge.switchScene(SceneType.NewGameScene.instance);
return true;
@@ -57,9 +57,9 @@ public class StartScene extends UIScene {
@Override
public void enter() {
boolean hasSaveButton=WorldSave.getCurrentSave().getWorld().getData() != null;
if(hasSaveButton)
hasSaveButton=!((TileMapScene)SceneType.TileMapScene.instance).currentMap().isInMap();
boolean hasSaveButton = WorldSave.getCurrentSave().getWorld().getData() != null;
if (hasSaveButton)
hasSaveButton = !((TileMapScene) SceneType.TileMapScene.instance).currentMap().isInMap();
saveButton.setVisible(hasSaveButton);
resumeButton.setVisible(WorldSave.getCurrentSave().getWorld().getData() != null);
Gdx.input.setInputProcessor(stage); //Start taking input from the ui
@@ -72,15 +72,14 @@ public class StartScene extends UIScene {
}
@Override
public boolean keyPressed(int keycode)
{
if (keycode == Input.Keys.ESCAPE)
{
if(WorldSave.getCurrentSave().getWorld().getData() != null)
public boolean keyPressed(int keycode) {
if (keycode == Input.Keys.ESCAPE || keycode == Input.Keys.BACK) {
if (WorldSave.getCurrentSave().getWorld().getData() != null)
Resume();
}
return true;
}
@Override
public void resLoaded() {
super.resLoaded();

View File

@@ -4,15 +4,19 @@ import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.EventListener;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.Touchpad;
import com.badlogic.gdx.scenes.scene2d.ui.Touchpad.TouchpadStyle;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.scenes.scene2d.utils.Drawable;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.Scaling;
import com.badlogic.gdx.utils.viewport.ScalingViewport;
import forge.Forge;
@@ -36,6 +40,10 @@ public class GameHUD extends Stage {
private final Label lifePoints;
private final Label money;
private Image miniMap;
private TextButton deckActor, menuActor, statsActor;
private boolean deckPressed = false;
private boolean menuPressed = false;
private boolean statsPressed = false;
private UIActor ui;
private Touchpad touchpad;
private TouchpadStyle touchpadStyle;
@@ -52,7 +60,9 @@ public class GameHUD extends Stage {
ui = new UIActor(Config.instance().getFile(GuiBase.isAndroid() ? "ui/hud_mobile.json" : "ui/hud.json"));
miniMap = ui.findActor("map");
deckActor = ui.findActor("deck");
menuActor = ui.findActor("menu");
statsActor = ui.findActor("statistic");
miniMapPlayer = new Image(new Texture(Config.instance().getFile("ui/minimap_player.png")));
//create touchpad skin
@@ -148,6 +158,13 @@ public class GameHUD extends Stage {
touchpad.setVisible(false);
MapStage.getInstance().GetPlayer().setMovementDirection(Vector2.Zero);
WorldStage.getInstance().GetPlayer().setMovementDirection(Vector2.Zero);
//simulate button
checkButtonState(deckActor, pointer);
checkButtonState(menuActor, pointer);
checkButtonState(statsActor, pointer);
deckPressed = false;
menuPressed = false;
statsPressed = false;
return super.touchUp(screenX, screenY, pointer, button);
}
@@ -181,7 +198,6 @@ public class GameHUD extends Stage {
boolean setPosition(int screenX, int screenY, int pointer, int button) {
Vector2 c=new Vector2();
Vector2 c2=new Vector2();
Vector2 touch =new Vector2();
screenToStageCoordinates(touch.set(screenX, screenY));
screenToStageCoordinates(c.set(screenX, screenY));
@@ -189,40 +205,40 @@ public class GameHUD extends Stage {
float x=(c.x-miniMap.getX())/miniMap.getWidth();
float y=(c.y-miniMap.getY())/miniMap.getHeight();
float deckX = ui.findActor("deck").getX();
float deckY = ui.findActor("deck").getY();
float deckR = ui.findActor("deck").getRight();
float deckT = ui.findActor("deck").getTop();
float deckOriginX = ui.findActor("deck").getOriginX();
float deckX = deckActor.getX();
float deckY = deckActor.getY();
float deckR = deckActor.getRight();
float deckT = deckActor.getTop();
float deckOriginX = deckActor.getOriginX();
//deck button bounds
if (c.x>=deckX&&c.x<=deckR&&c.y>=deckY&&c.y<=deckT) {
openDeck();
stageToScreenCoordinates(c2.set(deckOriginX, deckY));
return super.touchDown((int)c2.x, (int)c2.y, pointer, button);
if (pointer < 1)
deckPressed = true;
return true;
}
float menuX = ui.findActor("menu").getX();
float menuY = ui.findActor("menu").getY();
float menuR = ui.findActor("menu").getRight();
float menuT = ui.findActor("menu").getTop();
float menuOriginX = ui.findActor("menu").getOriginX();
float menuX = menuActor.getX();
float menuY = menuActor.getY();
float menuR = menuActor.getRight();
float menuT = menuActor.getTop();
float menuOriginX = menuActor.getOriginX();
//menu button bounds
if (c.x>=menuX&&c.x<=menuR&&c.y>=menuY&&c.y<=menuT) {
menu();
stageToScreenCoordinates(c2.set(menuOriginX, menuY));
return super.touchDown((int)c2.x, (int)c2.y, pointer, button);
if (pointer < 1)
menuPressed = true;
return true;
}
float statsX = ui.findActor("statistic").getX();
float statsY = ui.findActor("statistic").getY();
float statsR = ui.findActor("statistic").getRight();
float statsT = ui.findActor("statistic").getTop();
float statsOriginX = ui.findActor("statistic").getOriginX();
float statsX = statsActor.getX();
float statsY = statsActor.getY();
float statsR = statsActor.getRight();
float statsT = statsActor.getTop();
float statsOriginX = statsActor.getOriginX();
//stats button bounds
if (c.x>=statsX&&c.x<=statsR&&c.y>=statsY&&c.y<=statsT) {
statistic();
stageToScreenCoordinates(c2.set(statsOriginX, statsY));
return super.touchDown((int)c2.x, (int)c2.y, pointer, button);
if (pointer < 1)
statsPressed = true;
return true;
}
float uiX = ui.findActor("gamehud").getX();
@@ -264,6 +280,28 @@ public class GameHUD extends Stage {
}
return super.touchDown(screenX, screenY, pointer, button);
}
void checkButtonState(Actor actor, int pointer) {
Array<EventListener> listeners = actor.getListeners();
for(int i=0;i<listeners.size;i++)
{
if(listeners.get(i) instanceof ClickListener){
if (((ClickListener)listeners.get(i)).isVisualPressed()) {
((ClickListener)listeners.get(i)).setVisualPressed(false);
((ClickListener)listeners.get(i)).clicked(null, 0, 0);
}
}
}
}
void updateVisualState(Actor actor, boolean state) {
Array<EventListener> listeners = actor.getListeners();
for(int i=0;i<listeners.size;i++)
{
if(listeners.get(i) instanceof ClickListener){
((ClickListener)listeners.get(i)).setVisualPressed(state);
}
}
}
@Override
public void draw() {
int yPos = (int) gameStage.player.getY();
@@ -273,6 +311,9 @@ public class GameHUD extends Stage {
int xPosMini = (int) (((float) xPos / (float) WorldSave.getCurrentSave().getWorld().getTileSize() / (float) WorldSave.getCurrentSave().getWorld().getWidthInTiles()) * miniMap.getWidth());
int yPosMini = (int) (((float) yPos / (float) WorldSave.getCurrentSave().getWorld().getTileSize() / (float) WorldSave.getCurrentSave().getWorld().getHeightInTiles()) * miniMap.getHeight());
miniMapPlayer.setPosition(miniMap.getX() + xPosMini - miniMapPlayer.getWidth()/2, miniMap.getY() + yPosMini - miniMapPlayer.getHeight()/2);
updateVisualState(statsActor, statsPressed);
updateVisualState(menuActor, menuPressed);
updateVisualState(deckActor, deckPressed);
}
Texture miniMapTexture;