Example #1
0
  @Override
  protected void update(float delta) {
    final List<LookData> lookDataList = sprite.getLookDataList();
    int lookDataListSize = lookDataList.size();

    if (lookDataListSize > 0 && sprite.look.getLookData() != null) {
      LookData currentLookData = sprite.look.getLookData();
      int newIndex = (lookDataList.indexOf(currentLookData) + 1) % lookDataListSize;
      sprite.look.setLookData(lookDataList.get(newIndex));
    }
  }
Example #2
0
 private Object interpretObjectSensor(Sensors sensor, Sprite sprite) {
   Object returnValue = 0d;
   LookData lookData = sprite.look.getLookData();
   List<LookData> lookDataList = sprite.getLookDataList();
   if (lookData == null && lookDataList.size() > 0) {
     lookData = lookDataList.get(0);
   }
   switch (sensor) {
     case OBJECT_BRIGHTNESS:
       returnValue = (double) sprite.look.getBrightnessInUserInterfaceDimensionUnit();
       break;
     case OBJECT_COLOR:
       returnValue = (double) sprite.look.getColorInUserInterfaceDimensionUnit();
       break;
     case OBJECT_TRANSPARENCY:
       returnValue = (double) sprite.look.getTransparencyInUserInterfaceDimensionUnit();
       break;
     case OBJECT_LAYER:
       returnValue = (double) sprite.look.getZIndex();
       break;
     case OBJECT_ROTATION:
       returnValue = (double) sprite.look.getDirectionInUserInterfaceDimensionUnit();
       break;
     case OBJECT_SIZE:
       returnValue = (double) sprite.look.getSizeInUserInterfaceDimensionUnit();
       break;
     case OBJECT_X:
       returnValue = (double) sprite.look.getXInUserInterfaceDimensionUnit();
       break;
     case OBJECT_Y:
       returnValue = (double) sprite.look.getYInUserInterfaceDimensionUnit();
       break;
     case OBJECT_ANGULAR_VELOCITY:
       returnValue = (double) sprite.look.getAngularVelocityInUserInterfaceDimensionUnit();
       break;
     case OBJECT_X_VELOCITY:
       returnValue = (double) sprite.look.getXVelocityInUserInterfaceDimensionUnit();
       break;
     case OBJECT_Y_VELOCITY:
       returnValue = (double) sprite.look.getYVelocityInUserInterfaceDimensionUnit();
       break;
     case OBJECT_LOOK_NUMBER:
     case OBJECT_BACKGROUND_NUMBER:
       returnValue = 1.0d + ((lookData != null) ? lookDataList.indexOf(lookData) : 0);
       break;
     case OBJECT_LOOK_NAME:
     case OBJECT_BACKGROUND_NAME:
       returnValue = (lookData != null) ? lookData.getLookName() : "";
       break;
     case OBJECT_DISTANCE_TO:
       returnValue = (double) sprite.look.getDistanceToTouchPositionInUserInterfaceDimensions();
   }
   return returnValue;
 }
Example #3
0
  private void cloneLooks(Sprite cloneSprite) {
    List<LookData> cloneLookList = new ArrayList<>();
    for (LookData element : this.lookList) {
      cloneLookList.add(element.clone());
    }
    cloneSprite.lookList = cloneLookList;

    cloneSprite.look = this.look.copyLookForSprite(cloneSprite);
    try {
      cloneSprite.look.setLookData(cloneSprite.getLookDataList().get(0));
    } catch (IndexOutOfBoundsException indexOutOfBoundsException) {
      Log.e(TAG, Log.getStackTraceString(indexOutOfBoundsException));
    }
  }
Example #4
0
  @Override
  public void render() {
    Gdx.gl.glClearColor(1f, 1f, 1f, 1f);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    if (reloadProject) {
      int spriteSize = sprites.size();
      for (int i = 0; i < spriteSize; i++) {
        sprites.get(i).pause();
      }
      stage.clear();
      SoundManager.getInstance().clear();

      Sprite sprite;
      if (spriteSize > 0) {
        sprites.get(0).look.setLookData(createWhiteBackgroundLookData());
      }
      for (int i = 0; i < spriteSize; i++) {
        sprite = sprites.get(i);
        sprite.resetSprite();
        sprite.look.createBrightnessContrastShader();
        stage.addActor(sprite.look);
        sprite.pause();
      }
      stage.addActor(passepartout);

      paused = true;
      firstStart = true;
      reloadProject = false;
      synchronized (stageDialog) {
        stageDialog.notify();
      }
    }

    batch.setProjectionMatrix(camera.combined);

    if (firstStart) {
      int spriteSize = sprites.size();
      if (spriteSize > 0) {
        sprites.get(0).look.setLookData(createWhiteBackgroundLookData());
      }
      Sprite sprite;
      for (int i = 0; i < spriteSize; i++) {
        sprite = sprites.get(i);
        sprite.createStartScriptActionSequence();
        if (!sprite.getLookDataList().isEmpty()) {
          sprite.look.setLookData(sprite.getLookDataList().get(0));
        }
      }
      firstStart = false;
    }
    if (!paused) {
      float deltaTime = Gdx.graphics.getDeltaTime();

      /*
       * Necessary for UiTests, when EMMA - code coverage is enabled.
       *
       * Without setting DYNAMIC_SAMPLING_RATE_FOR_ACTIONS to false(via reflection), before
       * the UiTest enters the stage, random segmentation faults(triggered by EMMA) will occur.
       *
       * Can be removed, when EMMA is replaced by an other code coverage tool, or when a
       * future EMMA - update will fix the bugs.
       */
      if (DYNAMIC_SAMPLING_RATE_FOR_ACTIONS == false) {
        stage.act(deltaTime);
      } else {
        float optimizedDeltaTime = deltaTime / deltaActionTimeDivisor;
        long timeBeforeActionsUpdate = SystemClock.uptimeMillis();
        while (deltaTime > 0f) {
          stage.act(optimizedDeltaTime);
          deltaTime -= optimizedDeltaTime;
        }
        long executionTimeOfActionsUpdate = SystemClock.uptimeMillis() - timeBeforeActionsUpdate;
        if (executionTimeOfActionsUpdate <= ACTIONS_COMPUTATION_TIME_MAXIMUM) {
          deltaActionTimeDivisor += 1f;
          deltaActionTimeDivisor = Math.min(DELTA_ACTIONS_DIVIDER_MAXIMUM, deltaActionTimeDivisor);
        } else {
          deltaActionTimeDivisor -= 1f;
          deltaActionTimeDivisor = Math.max(1f, deltaActionTimeDivisor);
        }
      }
    }

    if (!finished) {
      stage.draw();
    }

    if (makeAutomaticScreenshot) {
      if (skipFirstFrameForAutomaticScreenshot) {
        skipFirstFrameForAutomaticScreenshot = false;
      } else {
        thumbnail =
            ScreenUtils.getFrameBufferPixels(
                screenshotX, screenshotY, screenshotWidth, screenshotHeight, true);
        makeAutomaticScreenshot = false;
      }
    }

    if (makeScreenshot) {
      screenshot =
          ScreenUtils.getFrameBufferPixels(
              screenshotX, screenshotY, screenshotWidth, screenshotHeight, true);
      makeScreenshot = false;
    }

    if (axesOn && !finished) {
      drawAxes();
    }

    if (DEBUG) {
      fpsLogger.log();
    }

    if (makeTestPixels) {
      testPixels = ScreenUtils.getFrameBufferPixels(testX, testY, testWidth, testHeight, false);
      makeTestPixels = false;
    }
  }
  private boolean handleOkButton() {
    EditText editText = (EditText) dialogView.findViewById(R.id.dialog_new_object_name_edit_text);
    String newSpriteName;
    if (editText.length() == 0) {
      newSpriteName = editText.getHint().toString();
    } else {
      newSpriteName = editText.getText().toString().trim();
    }
    if (newSpriteName.contains(".")) {
      int fileExtensionPosition = newSpriteName.indexOf(".");
      newSpriteName = newSpriteName.substring(0, fileExtensionPosition);
    }

    ProjectManager projectManager = ProjectManager.getInstance();

    if (newSpriteName.equalsIgnoreCase("")) {
      Utils.showErrorDialog(getActivity(), R.string.spritename_invalid);
      return false;
    }

    if (projectManager.spriteExists(newSpriteName)) {
      Utils.showErrorDialog(getActivity(), R.string.spritename_already_exists);
      return false;
    }

    Sprite sprite = new Sprite(newSpriteName);
    projectManager.addSprite(sprite);

    LookData lookData;
    try {
      File newLookFile =
          StorageHandler.getInstance()
              .copyImage(projectManager.getCurrentProject().getName(), lookUri.getPath(), null);

      String imageFileName = newLookFile.getName();
      Utils.rewriteImageFileForStage(getActivity(), newLookFile);

      lookData = new LookData();
      lookData.setLookFilename(imageFileName);
      lookData.setLookName(newSpriteName);
    } catch (IOException exception) {
      Utils.showErrorDialog(getActivity(), R.string.error_load_image);
      exception.printStackTrace();

      return false;
    }

    sprite.getLookDataList().add(lookData);

    if (requestedAction == ActionAfterFinished.ACTION_UPDATE_SPINNER && spinnerAdapter != null) {
      Intent broadcastIntent;
      broadcastIntent = new Intent(ScriptActivity.ACTION_BRICK_LIST_CHANGED);
      getActivity().sendBroadcast(broadcastIntent);
      spinnerAdapter.refreshSpinnerAfterNewSprite(getActivity(), newSpriteName);
    } else {
      Intent broadcastIntent;
      broadcastIntent = new Intent(ScriptActivity.ACTION_SPRITES_LIST_CHANGED);
      getActivity().sendBroadcast(broadcastIntent);
    }

    if (requestedAction == ActionAfterFinished.ACTION_FORWARD_TO_NEW_OBJECT) {
      projectManager.setCurrentSprite(sprite);

      Intent intent = new Intent(getActivity(), ProgramMenuActivity.class);
      intent.putExtra(
          ProgramMenuActivity.FORWARD_TO_SCRIPT_ACTIVITY, ScriptActivity.FRAGMENT_SCRIPTS);
      startActivity(intent);
    }
    dismiss();
    return true;
  }
Example #6
0
  private void createProject() {
    ScreenValues.SCREEN_HEIGHT = SCREEN_HEIGHT;
    ScreenValues.SCREEN_WIDTH = SCREEN_WIDTH;

    project = new Project(null, UiTestUtils.DEFAULT_TEST_PROJECT_NAME);

    // yellow Sprite
    Sprite yellowSprite = new Sprite("yellowSprite");
    StartScript yellowStartScript = new StartScript();
    LookData yellowLookData = new LookData();
    String yellowImageName = "yellow_image.bmp";

    yellowLookData.setLookName(yellowImageName);

    yellowSprite.getLookDataList().add(yellowLookData);

    yellowStartScript.addBrick(new PlaceAtBrick(-21, 21));

    yellowSprite.addScript(yellowStartScript);

    WhenScript yellowWhenScript = new WhenScript();
    SetGhostEffectBrick yellowSetGhostEffectBrick = new SetGhostEffectBrick(100d);
    yellowWhenScript.addBrick(yellowSetGhostEffectBrick);

    yellowSprite.addScript(yellowWhenScript);

    // blue Sprite
    Sprite blueSprite = new Sprite("blueSprite");
    StartScript blueStartScript = new StartScript();
    LookData blueLookData = new LookData();
    String blueImageName = "blue_image.bmp";

    blueLookData.setLookName(blueImageName);

    blueSprite.getLookDataList().add(blueLookData);

    blueStartScript.addBrick(new PlaceAtBrick(21, 21));

    blueSprite.addScript(blueStartScript);

    WhenScript blueWhenScript = new WhenScript();
    SetSizeToBrick blueSetSizeToBrick = new SetSizeToBrick(200d);
    blueWhenScript.addBrick(blueSetSizeToBrick);

    blueSprite.addScript(blueWhenScript);

    // green Sprite
    Sprite greenSprite = new Sprite("greenSprite");
    StartScript greenStartScript = new StartScript();
    LookData greenLookData = new LookData();
    String greenImageName = "green_image.bmp";

    greenLookData.setLookName(greenImageName);

    greenSprite.getLookDataList().add(greenLookData);

    greenStartScript.addBrick(new PlaceAtBrick(21, -21));

    greenSprite.addScript(greenStartScript);

    WhenScript greenWhenScript = new WhenScript();
    ComeToFrontBrick greenComeToFrontBrick = new ComeToFrontBrick();
    greenWhenScript.addBrick(greenComeToFrontBrick);

    greenSprite.addScript(greenWhenScript);

    // red Sprite
    Sprite redSprite = new Sprite("redSprite");
    StartScript redStartScript = new StartScript();
    LookData redLookData = new LookData();
    String redImageName = "red_image.bmp";

    redLookData.setLookName(redImageName);

    redSprite.getLookDataList().add(redLookData);

    redStartScript.addBrick(new PlaceAtBrick(-21, -21));

    redSprite.addScript(redStartScript);

    WhenScript redWhenScript = new WhenScript();
    ComeToFrontBrick redComeToFrontBrick = new ComeToFrontBrick();
    SetBrightnessBrick redSetBrightnessBrick = new SetBrightnessBrick(50d);
    TurnLeftBrick redTurnLeftBrick = new TurnLeftBrick(45d);
    redWhenScript.addBrick(redComeToFrontBrick);
    redWhenScript.addBrick(redSetBrightnessBrick);
    redWhenScript.addBrick(redTurnLeftBrick);

    redSprite.addScript(redWhenScript);

    // black Sprite
    Sprite blackSprite = new Sprite("blackSprite");
    StartScript blackStartScript = new StartScript();
    LookData blackLookData = new LookData();
    String blackImageName = "black_image.bmp";

    blackLookData.setLookName(blackImageName);

    blackSprite.getLookDataList().add(blackLookData);

    blackStartScript.addBrick(new PlaceAtBrick(-50, 50));

    blackSprite.addScript(blackStartScript);

    WhenScript blackWhenScript = new WhenScript();
    ComeToFrontBrick blackComeToFrontBrick = new ComeToFrontBrick();
    SetBrightnessBrick blackSetBrightnessBrick = new SetBrightnessBrick(150d);
    blackWhenScript.addBrick(blackComeToFrontBrick);
    blackWhenScript.addBrick(blackSetBrightnessBrick);

    blackSprite.addScript(blackWhenScript);

    project.addSprite(blackSprite);
    project.addSprite(yellowSprite);
    project.addSprite(redSprite);
    project.addSprite(greenSprite);
    project.addSprite(blueSprite);

    StorageHandler.getInstance().saveProject(project);

    File yellowImageFile =
        UiTestUtils.saveFileToProject(
            project.getName(),
            yellowImageName,
            org.catrobat.catroid.test.R.raw.yellow_image,
            getInstrumentation().getContext(),
            UiTestUtils.FileTypes.IMAGE);
    File greenImageFile =
        UiTestUtils.saveFileToProject(
            project.getName(),
            greenImageName,
            org.catrobat.catroid.test.R.raw.green_image,
            getInstrumentation().getContext(),
            UiTestUtils.FileTypes.IMAGE);
    File blueImageFile =
        UiTestUtils.saveFileToProject(
            project.getName(),
            blueImageName,
            org.catrobat.catroid.test.R.raw.blue_image,
            getInstrumentation().getContext(),
            UiTestUtils.FileTypes.IMAGE);
    File redImageFile =
        UiTestUtils.saveFileToProject(
            project.getName(),
            redImageName,
            org.catrobat.catroid.test.R.raw.red_image,
            getInstrumentation().getContext(),
            UiTestUtils.FileTypes.IMAGE);
    File blackImageFile =
        UiTestUtils.saveFileToProject(
            project.getName(),
            blackImageName,
            org.catrobat.catroid.test.R.raw.black_image,
            getInstrumentation().getContext(),
            UiTestUtils.FileTypes.IMAGE);
    yellowLookData.setLookFilename(yellowImageFile.getName());
    greenLookData.setLookFilename(greenImageFile.getName());
    blueLookData.setLookFilename(blueImageFile.getName());
    redLookData.setLookFilename(redImageFile.getName());
    blackLookData.setLookFilename(blackImageFile.getName());

    StorageHandler.getInstance().saveProject(project);
    ProjectManager.getInstance().setProject(project);
  }