コード例 #1
0
ファイル: StageTest.java プロジェクト: norain2050/daima111
 private void fillGroup(Group group, Texture texture) {
   float advance = 32 + SPACING;
   for (int y = 0; y < NUM_SPRITES * advance; y += advance)
     for (int x = 0; x < NUM_SPRITES * advance; x += advance) {
       Image img = new Image(new TextureRegion(texture));
       img.setAlign(Align.center);
       img.setScaling(Scaling.none);
       img.setBounds(x, y, 32, 32);
       img.setOrigin(16, 16);
       group.addActor(img);
       images.add(img);
     }
 }
コード例 #2
0
ファイル: StageTest.java プロジェクト: norain2050/daima111
  @Override
  public void create() {
    texture = new Texture(Gdx.files.internal("data/badlogicsmall.jpg"));
    texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
    font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false);

    stage = new Stage();

    float loc = (NUM_SPRITES * (32 + SPACING) - SPACING) / 2;
    for (int i = 0; i < NUM_GROUPS; i++) {
      Group group = new Group();
      group.setX((float) Math.random() * (stage.getWidth() - NUM_SPRITES * (32 + SPACING)));
      group.setY((float) Math.random() * (stage.getHeight() - NUM_SPRITES * (32 + SPACING)));
      group.setOrigin(loc, loc);

      fillGroup(group, texture);
      stage.addActor(group);
    }

    uiTexture = new Texture(Gdx.files.internal("data/ui.png"));
    uiTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
    ui = new Stage();

    Image blend = new Image(new TextureRegion(uiTexture, 0, 0, 64, 32));
    blend.setAlign(Align.center);
    blend.setScaling(Scaling.none);
    blend.addListener(
        new InputListener() {
          public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            if (stage.getSpriteBatch().isBlendingEnabled())
              stage.getSpriteBatch().disableBlending();
            else stage.getSpriteBatch().enableBlending();
            return true;
          }
        });
    blend.setY(ui.getHeight() - 64);

    Image rotate = new Image(new TextureRegion(uiTexture, 64, 0, 64, 32));
    rotate.setAlign(Align.center);
    rotate.setScaling(Scaling.none);
    rotate.addListener(
        new InputListener() {
          public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            rotateSprites = !rotateSprites;
            return true;
          }
        });
    rotate.setPosition(64, blend.getY());

    Image scale = new Image(new TextureRegion(uiTexture, 64, 32, 64, 32));
    scale.setAlign(Align.center);
    scale.setScaling(Scaling.none);
    scale.addListener(
        new InputListener() {
          public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            scaleSprites = !scaleSprites;
            return true;
          }
        });
    scale.setPosition(128, blend.getY());

    ui.addActor(blend);
    ui.addActor(rotate);
    ui.addActor(scale);

    fps = new Label("fps: 0", new Label.LabelStyle(font, Color.WHITE));
    fps.setPosition(10, 30);
    fps.setColor(0, 1, 0, 1);
    ui.addActor(fps);

    renderer = new ShapeRenderer();
    Gdx.input.setInputProcessor(this);
  }
コード例 #3
0
  // constructor --------------------------------------------------------------------------
  public ScoreBoardScreen(EndMissionReport missionData) {
    super();

    // table setup
    // *******************************************************************************************************
    int score = 0;
    boolean success = missionData.isSuccess();

    // -- title *******************************************************
    final Label title = new Label(success ? "Success" : "Failure", menuSkin, "title");
    table.add(title).padTop(50).padBottom(40).padLeft(10).padRight(10).center().colspan(2);

    // -- team summary ************************************************
    table.row().padBottom(10);
    final Label teamHeader = new Label("Team", menuSkin, "subTitle");
    table.add(teamHeader).padLeft(20).spaceRight(40).left();

    HorizontalGroup teammates = new HorizontalGroup();
    teammates.space(10);

    int index = 0;
    for (int i = 0; i < missionData.safeMates.size; i++) {
      Image image =
          new Image(menuSkin.getDrawable(missionData.safeMates.get(i).getItemRegionName(false)));
      teammates.addActorAt(index, image);
      index++;
    }

    for (int i = 0; i < missionData.lostMates.size; i++) {
      Image image =
          new Image(menuSkin.getDrawable(missionData.lostMates.get(i).getItemRegionName(true)));
      teammates.addActorAt(index, image);
      score += LOST_MATE_SCORE;
      index++;
    }
    teammates.pack();
    table.add(teammates).padRight(20).center();

    // -- substance summary ************************************************

    table.row().padBottom(10);
    final Label harvestHeader = new Label("Harvest", menuSkin, "subTitle");
    table.add(harvestHeader).padLeft(20).spaceRight(40).left();
    HorizontalGroup substances = new HorizontalGroup();
    substances.space(10);

    if (missionData.collectedSubstance > 0) {

      Image banner = new Image(menuSkin.getDrawable("banner" + missionData.collectedSubstance));
      banner.setScaling(Scaling.none);
      banner.setAlign(Align.bottomRight);

      Stack stack = new Stack();
      stack.addActor(new Image(menuSkin.getDrawable("item_substance")));
      stack.addActor(banner);
      score += SUBSTANCE_SCORE * missionData.collectedSubstance;

      substances.addActor(stack);
    }

    if (missionData.targetSubstance - missionData.collectedSubstance > 0) {
      Image banner =
          new Image(
              menuSkin.getDrawable(
                  "banner" + (missionData.targetSubstance - missionData.collectedSubstance)));
      banner.setScaling(Scaling.none);
      banner.setAlign(Align.bottomRight);

      Stack stack = new Stack();
      stack.addActor(new Image(menuSkin.getDrawable("item_outSubstance")));
      stack.addActor(banner);

      substances.addActor(stack);
    }

    table.add(substances).padRight(20).center();

    // consumption summary ************************************************
    table.row().padBottom(10);
    final Label usedHeader = new Label("Used", menuSkin, "subTitle");
    table.add(usedHeader).padLeft(20).spaceRight(40).left();

    HorizontalGroup collectibles = new HorizontalGroup();
    collectibles.space(10);

    score += USED_SUPPLY_SCORE * missionData.usedSupply;
    int itemCount = missionData.usedSupply / 10;

    // supplies *******
    for (int i = 0; i < itemCount; i++) {
      Image banner = new Image(menuSkin.getDrawable("banner10"));
      banner.setScaling(Scaling.none);
      banner.setAlign(Align.bottomRight);

      Stack stack = new Stack();
      stack.addActor(new Image(menuSkin.getDrawable("item_supply")));
      stack.addActor(banner);
      collectibles.addActor(stack);
    }

    int extraItems = missionData.usedSupply % 10;
    if (extraItems > 0) {
      Image banner = new Image(menuSkin.getDrawable("banner" + extraItems));
      banner.setScaling(Scaling.none);
      banner.setAlign(Align.bottomRight);

      Stack stack = new Stack();
      stack.addActor(new Image(menuSkin.getDrawable("item_supply")));
      stack.addActor(banner);
      collectibles.addActor(stack);
    }

    // materials *******
    score += USED_MATERIAL_SCORE * missionData.usedMaterial;
    itemCount = missionData.usedMaterial / 10;

    for (int i = 0; i < itemCount; i++) {
      Image banner = new Image(menuSkin.getDrawable("banner10"));
      banner.setScaling(Scaling.none);
      banner.setAlign(Align.bottomRight);

      Stack stack = new Stack();
      stack.addActor(new Image(menuSkin.getDrawable("item_material")));
      stack.addActor(banner);
      collectibles.addActor(stack);
    }

    extraItems = missionData.usedMaterial % 10;
    if (extraItems > 0) {
      Image banner = new Image(menuSkin.getDrawable("banner" + extraItems));
      banner.setScaling(Scaling.none);
      banner.setAlign(Align.bottomRight);

      Stack stack = new Stack();
      stack.addActor(new Image(menuSkin.getDrawable("item_material")));
      stack.addActor(banner);
      collectibles.addActor(stack);
    }

    collectibles.pack();

    // -- time bonus summary ************************************************
    table.add(collectibles).padRight(20).center();
    table.row().padBottom(10);
    final Label timeHeader = new Label("Time Bonus", menuSkin, "subTitle");
    table.add(timeHeader).padLeft(20).spaceRight(40).left();

    float timeBonus;

    if (missionData.missionTimeLeft <= 0f) {
      timeBonus = TIMEUP_SCOREMULT;
    } else if (missionData.missionTimeLeft <= 60f) {
      timeBonus = ONTIME_SCOREMULT;
    } else if (missionData.missionTimeLeft <= 120f) {
      timeBonus = GOODTIME_SCOREMULT;
    } else timeBonus = GREATTIME_SCOREMULT;

    table.add(new Label("x" + timeBonus, menuSkin, "title")).padRight(10).center();

    // -- score summary *****************************************************
    table.row().padTop(10).padBottom(50);
    final Label scoreHeader = new Label("Score", menuSkin, "subTitle");
    table.add(scoreHeader).padLeft(20).spaceRight(40).left();

    if (score > 0) score = Math.round(timeBonus * (float) score);
    float maxScore =
        GREATTIME_SCOREMULT
            * Math.min(missionData.targetSubstance, missionData.targetSubstance + 2)
            * SUBSTANCE_SCORE;
    int star_count = Math.max(1, MathUtils.floor(4f * score / maxScore));
    star_count = (!success || missionData.lostMates.size > 0 ? 1 : star_count);

    HorizontalGroup scoreStars = new HorizontalGroup();
    scoreStars.space(5);
    for (int i = 0; i < star_count; i++) {
      Image image = new Image(menuSkin.getDrawable(success ? "goldStar" : "silverStar"));
      scoreStars.addActorAt(i, image);
    }

    table.add(scoreStars).padRight(10).center();
  }
コード例 #4
0
  @Override
  public void create() {
    skin = new Skin(Gdx.files.internal(SKIN));

    EditorLogger.setDebug();
    EditorLogger.debug("CREATE");
    Ctx.project = new Project();
    Ctx.msg = new Message(skin);
    Ctx.assetManager = new EditorAssetManager();

    scnEditor = new ScnEditor(skin);
    skin.getFont("default-font").getData().markupEnabled = true;

    /** * STAGE SETUP ** */
    stage = new Stage(new ScreenViewport());
    Gdx.input.setInputProcessor(stage);

    // RIGHT PANEL
    ScenePanel scenePanel = new ScenePanel(skin);
    ActorPanel actorPanel = new ActorPanel(skin);

    Table rightPanel = new Table();
    rightPanel.top().left();
    //		rightPanel.add(scenePanel).expand().fill();
    //		rightPanel.row();
    rightPanel.add(actorPanel).expand().fill();

    SplitPane splitPaneRight = new SplitPane(scnEditor, rightPanel, false, skin);

    // LEFT PANEL
    ProjectPanel projectPanel = new ProjectPanel(skin);
    //		AssetPanel assetPanel = new AssetPanel(skin);
    Image img = new Image(Ctx.assetManager.getIcon("title"));
    img.setScaling(Scaling.none);
    img.setAlign(Align.left);

    Table leftPanel = new Table();
    leftPanel.top().left().padLeft(10);
    leftPanel.add(img).expand().fill().padBottom(20).padTop(20).padLeft(20);
    leftPanel.row();
    leftPanel.add(new ProjectToolbar(skin)).expandX().fill();
    leftPanel.row();
    leftPanel.add(projectPanel).expand().fill();
    leftPanel.row();
    leftPanel.add(scenePanel).expand().fill();

    SplitPane splitPaneLeft = new SplitPane(leftPanel, splitPaneRight, false, skin);
    splitPaneLeft.setFillParent(true);
    splitPaneLeft.setSplitAmount(0.3f);
    stage.addActor(splitPaneLeft);

    // LOAD LAST OPEN PROJECT
    String lastProject = Ctx.project.getEditorConfig().getProperty(Project.LAST_PROJECT_PROP, "");

    if (!lastProject.isEmpty() && new File(lastProject).exists()) {
      try {
        EditorLogger.debug("Loading last project: " + lastProject);
        Ctx.project.loadProject(new File(lastProject));
      } catch (Exception e) {
        EditorLogger.debug("Error loading last project: " + e.getMessage());
        Ctx.project.closeProject();
        e.printStackTrace();
      }
    }

    stage.setScrollFocus(scnEditor.getScnWidget());
    stage.setKeyboardFocus(scnEditor.getScnWidget());
  }