Android Open Source - CircleWorldGDX Hud Screen






From Project

Back to project page CircleWorldGDX.

License

The source code is released under:

MIT License

If you think the Android project CircleWorldGDX listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.fdangelo.circleworld.gui;
/*from w w  w.  j av  a 2 s .  co m*/
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.badlogic.gdx.utils.StringBuilder;
import com.esotericsoftware.tablelayout.Value;
import com.fdangelo.circleworld.GameLogic;
import com.fdangelo.circleworld.gui.core.Screen;
import com.fdangelo.circleworld.universeengine.Universe;
import com.fdangelo.circleworld.universeengine.objects.UniverseObject;
import com.fdangelo.circleworld.universeview.objects.AvatarInputMode;
import com.fdangelo.circleworld.universeview.objects.AvatarViewInput;

public class HudScreen extends Screen {

  private Label performance;
  private StringBuilder sb;
  private TextButton boardShipButton;
  private TextButton editButton;
  
  private AvatarMoveControlScreen avatarMoveControlScreen;
  private AvatarEditControlScreen avatarEditControlScreen;
  
  @Override
  protected void initScreen() {

    getScreenTable().left().top();
    
    Table top = new Table();
    
    getScreenTable().add(top).width(Value.percentWidth(1));

    performance = new Label("", getDefaultSkin());
    top.add(performance).top().left();

    boardShipButton = new TextButton("BOARD SHIP", getDefaultSkin());
    boardShipButton.addListener(new ChangeListener() {
      @Override
      public void changed(final ChangeEvent event, final Actor actor) {
        onBoardShipButtonClicked();
      }
    });
    
    editButton = new TextButton("EDIT", getDefaultSkin());
    editButton.addListener(new ChangeListener() {
      @Override
      public void changed(ChangeEvent event, Actor actor) {
        onEditButtonClicked();
      }
    });
    
    top.add(editButton).top().right().width(200).height(100).expandX();
    top.add(boardShipButton).top().right().width(200).height(100);
    
    avatarMoveControlScreen = new AvatarMoveControlScreen();
    addSubscreen(avatarMoveControlScreen);

    avatarEditControlScreen = new AvatarEditControlScreen();
    addSubscreen(avatarEditControlScreen);
    
    avatarMoveControlScreen.setVisible(true);
    avatarEditControlScreen.setVisible(false);
    
    sb = new StringBuilder();
  }
  
  private void onEditButtonClicked() {
    if (AvatarViewInput.mode == AvatarInputMode.Edit) {
      AvatarViewInput.mode = AvatarInputMode.Move;
      
      avatarMoveControlScreen.setVisible(true);
      avatarEditControlScreen.setVisible(false);
      editButton.setText("EDIT");
    } else {
      AvatarViewInput.mode = AvatarInputMode.Edit;
      
      avatarMoveControlScreen.setVisible(false);
      avatarEditControlScreen.setVisible(true);
      editButton.setText("EXIT EDIT");
    }
  }

  private void onBoardShipButtonClicked() {

    UniverseObject ship = GameLogic.getInstace().getUniverseView().getShipView().getUniverseObject();
    Universe universe = GameLogic.getInstace().getUniverseView().getUniverse();

    switch (GameLogic.getInstace().getState()) {
      case PlayingAvatar:
        boardShipButton.setText("LEAVE SHIP");
        GameLogic.getInstace().playerBoardShip();
        break;

      case PlayingShip:
        final int clickedThingIndex = universe.findClosestRenderedThing(ship.getPositionX(), ship.getPositionY(), 30.0f);

        if (clickedThingIndex >= 0) {
          boardShipButton.setText("BOARD SHIP");
          GameLogic.getInstace().playerLeaveShip(universe.getPlanet((short) clickedThingIndex));
        }
        break;

      default:
        // Nothing
        break;
    }
  }

  @Override
  protected void onUpdate(final float deltaTime) {
    updatePerformance();
  }

  private final void updatePerformance() {
    // int totalRenderCalls = guistage.getSpriteBatch().renderCalls +
    // gamelogic.getStage().getSpriteBatch().renderCalls;
    final int totalRenderCalls = -1;

    sb.length = 0;
    sb.append("FPS: ").append(Gdx.graphics.getFramesPerSecond()).append(" Used Memory: ").append(Gdx.app.getJavaHeap() / 1024).append("kb Used Native: ")
        .append(Gdx.app.getNativeHeap() / 1024).append("kb Render Calls: ").append(totalRenderCalls);

    performance.setText(sb);
  }
}




Java Source Code List

.AssetsUpdater.java
com.fdangelo.circleworld.GameLogicState.java
com.fdangelo.circleworld.GameLogic.java
com.fdangelo.circleworld.MainActivity.java
com.fdangelo.circleworld.Main.java
com.fdangelo.circleworld.MyGdxGame.java
com.fdangelo.circleworld.RobovmLauncher.java
com.fdangelo.circleworld.client.GwtLauncher.java
com.fdangelo.circleworld.gui.AvatarEditControlScreen.java
com.fdangelo.circleworld.gui.AvatarMoveControlScreen.java
com.fdangelo.circleworld.gui.HudScreen.java
com.fdangelo.circleworld.gui.core.Gui.java
com.fdangelo.circleworld.gui.core.ScreenTable.java
com.fdangelo.circleworld.gui.core.Screen.java
com.fdangelo.circleworld.universeengine.IUniverseListener.java
com.fdangelo.circleworld.universeengine.ThingPosition.java
com.fdangelo.circleworld.universeengine.ThingType.java
com.fdangelo.circleworld.universeengine.Thing.java
com.fdangelo.circleworld.universeengine.UniverseFactory.java
com.fdangelo.circleworld.universeengine.UniverseGeneratorDefault.java
com.fdangelo.circleworld.universeengine.UniverseGenerator.java
com.fdangelo.circleworld.universeengine.Universe.java
com.fdangelo.circleworld.universeengine.objects.AvatarInput.java
com.fdangelo.circleworld.universeengine.objects.Avatar.java
com.fdangelo.circleworld.universeengine.objects.FollowParentParameters.java
com.fdangelo.circleworld.universeengine.objects.IUniverseObjectListener.java
com.fdangelo.circleworld.universeengine.objects.ShipInput.java
com.fdangelo.circleworld.universeengine.objects.Ship.java
com.fdangelo.circleworld.universeengine.objects.UniverseObject.java
com.fdangelo.circleworld.universeengine.tilemap.ITilemapCircleListener.java
com.fdangelo.circleworld.universeengine.tilemap.PlanetType.java
com.fdangelo.circleworld.universeengine.tilemap.PlanetTypes.java
com.fdangelo.circleworld.universeengine.tilemap.Planet.java
com.fdangelo.circleworld.universeengine.tilemap.TileDirection.java
com.fdangelo.circleworld.universeengine.tilemap.TileHitFlags.java
com.fdangelo.circleworld.universeengine.tilemap.TileHitInfo.java
com.fdangelo.circleworld.universeengine.tilemap.TileSubtype.java
com.fdangelo.circleworld.universeengine.tilemap.TileType.java
com.fdangelo.circleworld.universeengine.tilemap.TileTypes.java
com.fdangelo.circleworld.universeengine.tilemap.TilemapCircle.java
com.fdangelo.circleworld.universeengine.utils.DataPools.java
com.fdangelo.circleworld.universeengine.utils.PoolByte.java
com.fdangelo.circleworld.universeengine.utils.PoolColor.java
com.fdangelo.circleworld.universeengine.utils.PoolFloat.java
com.fdangelo.circleworld.universeengine.utils.PoolInt.java
com.fdangelo.circleworld.universeengine.utils.PoolVector2.java
com.fdangelo.circleworld.universeengine.utils.PoolVector3.java
com.fdangelo.circleworld.universeengine.utils.UEProfilerSample.java
com.fdangelo.circleworld.universeengine.utils.UEProfiler.java
com.fdangelo.circleworld.universeview.FollowCameraParameters.java
com.fdangelo.circleworld.universeview.UniverseViewCamera.java
com.fdangelo.circleworld.universeview.UniverseViewFactory.java
com.fdangelo.circleworld.universeview.UniverseView.java
com.fdangelo.circleworld.universeview.objects.AvatarInputEditTool.java
com.fdangelo.circleworld.universeview.objects.AvatarInputMode.java
com.fdangelo.circleworld.universeview.objects.AvatarViewInput.java
com.fdangelo.circleworld.universeview.objects.AvatarView.java
com.fdangelo.circleworld.universeview.objects.InputAreas.java
com.fdangelo.circleworld.universeview.objects.ShipInputMode.java
com.fdangelo.circleworld.universeview.objects.ShipViewInput.java
com.fdangelo.circleworld.universeview.objects.ShipView.java
com.fdangelo.circleworld.universeview.objects.UniverseObjectView.java
com.fdangelo.circleworld.universeview.tilemap.PlanetView.java
com.fdangelo.circleworld.universeview.tilemap.TilemapCircleViewBackgroundRenderer.java
com.fdangelo.circleworld.universeview.tilemap.TilemapCircleViewRenderer.java
com.fdangelo.circleworld.universeview.tilemap.TilemapCircleView.java
com.fdangelo.circleworld.utils.Mathf.java
com.fdangelo.circleworld.utils.Vector2I.java