Пример #1
0
  private void addScriptToProject(int position, ScriptBrick scriptBrick) {
    Sprite currentSprite = ProjectManager.getInstance().getCurrentSprite();

    int[] temp = getScriptAndBrickIndexFromProject(position);

    int scriptPosition = temp[0];
    int brickPosition = temp[1];

    Script newScript = scriptBrick.getScriptSafe();
    if (currentSprite.getNumberOfBricks() > 0) {
      int addScriptTo = position == 0 ? 0 : scriptPosition + 1;
      currentSprite.addScript(addScriptTo, newScript);
    } else {
      currentSprite.addScript(newScript);
    }

    Script previousScript = currentSprite.getScript(scriptPosition);
    if (previousScript != null) {
      Brick brick;
      int size = previousScript.getBrickList().size();
      for (int i = brickPosition; i < size; i++) {
        brick = previousScript.getBrick(brickPosition);
        previousScript.removeBrick(brick);
        newScript.addBrick(brick);
      }
    }
    ProjectManager.getInstance().setCurrentScript(newScript);
  }
Пример #2
0
  public void removeFromBrickListAndProject(int index, boolean removeScript) {
    if (addingNewBrick) {
      brickList.remove(draggedBrick);
    } else if (script == null) {
      int[] temp = getScriptAndBrickIndexFromProject(index);
      Script script = ProjectManager.getInstance().getCurrentSprite().getScript(temp[0]);
      if (script != null) {

        Brick brick = script.getBrick(temp[1]);
        if (brick instanceof NestingBrick) {
          for (NestingBrick tempBrick : ((NestingBrick) brick).getAllNestingBrickParts(true)) {
            script.removeBrick((Brick) tempBrick);
          }
        } else {
          script.removeBrick(brick);
        }
        if (removeScript) {
          brickList.remove(script);
        }
      }
    } else {

      Brick brick = script.getBrick(getPositionInUserScript(index));
      if (brick instanceof NestingBrick) {
        for (NestingBrick tempBrick : ((NestingBrick) brick).getAllNestingBrickParts(true)) {
          script.removeBrick((Brick) tempBrick);
        }
      } else {
        script.removeBrick(brick);
      }
    }

    firstDrag = true;
    draggedBrick = null;
    addingNewBrick = false;

    initBrickList();
    notifyDataSetChanged();
  }
Пример #3
0
  public void launchAddBrickAndSelectBrickAt(Context context, int index) {
    int[] temp = getScriptAndBrickIndexFromProject(index);
    Script script = ProjectManager.getInstance().getCurrentSprite().getScript(temp[0]);
    if (script != null) {
      Brick brick = script.getBrick(temp[1]);

      if (!viewSwitchLock.tryLock()) {
        return;
      }

      if (brick instanceof UserBrick) {
        AddBrickFragment.setBrickFocus(((UserBrick) brick));
      }

      ScriptFragment theScriptFragment = ((ScriptFragment) scriptFragment);
      theScriptFragment.onCategorySelected(context.getString(R.string.category_user_bricks));
    }
  }
Пример #4
0
  private void moveExistingProjectBrick(int from, int to) {
    Sprite currentSprite = ProjectManager.getInstance().getCurrentSprite();

    int[] tempFrom = getScriptAndBrickIndexFromProject(from);
    int scriptPositionFrom = tempFrom[0];
    int brickPositionFrom = tempFrom[1];

    Script fromScript = currentSprite.getScript(scriptPositionFrom);

    Brick brick = fromScript.getBrick(brickPositionFrom);
    if (draggedBrick != brick) {
      Log.e(TAG, "Want to save wrong brick");
      return;
    }
    fromScript.removeBrick(brick);

    int[] tempTo = getScriptAndBrickIndexFromProject(to);
    int scriptPositionTo = tempTo[0];
    int brickPositionTo = tempTo[1];

    Script toScript = currentSprite.getScript(scriptPositionTo);

    toScript.addBrick(brickPositionTo, brick);
  }
Пример #5
0
 private void moveUserBrick(int from, int to) {
   Brick brick = script.getBrick(getPositionInUserScript(from));
   script.removeBrick(brick);
   script.addBrick(getPositionInUserScript(to), brick);
 }