Пример #1
0
  @Override
  public void render() {
    Gdx.gl.glClearColor(
        background.rgb.getRed() / 255f,
        background.rgb.getGreen() / 255f,
        background.rgb.getBlue() / 255f,
        background.rgb.getAlpha() / 255f);

    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

    boolean hasUserInput = false;
    if (input.getText() != null && input.getText().length() != 0) hasUserInput = true;
    final String text =
        hasUserInput ? input.getText() : "The quick brown fox jumps over the lazy dog";

    float scale = scaleSlider.getValue();

    cam.setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    batch.setProjectionMatrix(cam.combined);

    batch.getProjectionMatrix().scale(scale, scale, 0.0f);

    //		batch.getTransformMatrix().scale(scale, scale, 0.0f);

    if (fonts != null) {
      batch.begin();

      int x = 5;
      int y = 0;

      for (FontElement e : fonts) {
        y += e.font.getLineHeight() + 5;
        String str = hasUserInput ? text : e.name + " " + e.size + ": " + text;
        e.font.draw(batch, str, x, y);
      }

      batch.end();
    }

    input.setY(Gdx.graphics.getHeight() - input.getHeight() - 5);
    labelInput.setY(Gdx.graphics.getHeight() - input.getHeight() - 5);

    labelScale.setY(labelInput.getY() - labelInput.getHeight() - 5);
    scaleSlider.setY(input.getY() - input.getHeight() - 5);
    scaleAmt.setY(scaleSlider.getY());

    linearFiltering.setY(scaleSlider.getY() - scaleSlider.getHeight() - 10);

    stage.act();
    stage.draw();
  }
 void savePrefs() {
   if (!prefsLoaded) return;
   prefs.putBoolean("debugBones", debugBonesCheckbox.isChecked());
   prefs.putBoolean("debugRegions", debugRegionsCheckbox.isChecked());
   prefs.putBoolean("debugMeshHull", debugMeshHullCheckbox.isChecked());
   prefs.putBoolean("debugMeshTriangles", debugMeshTrianglesCheckbox.isChecked());
   prefs.putBoolean("debugPaths", debugPathsCheckbox.isChecked());
   prefs.putBoolean("premultiplied", premultipliedCheckbox.isChecked());
   prefs.putBoolean("loop", loopCheckbox.isChecked());
   prefs.putFloat("speed", speedSlider.getValue());
   prefs.putFloat("mix", mixSlider.getValue());
   prefs.putFloat("scale", scaleSlider.getValue());
   prefs.putInteger("x", skeletonX);
   prefs.putInteger("y", skeletonY);
   TrackEntry current = state.getCurrent(0);
   if (current != null) {
     String name = current.animation.name;
     if (name.equals("<empty>")) name = current.next == null ? "" : current.next.animation.name;
     prefs.putString("animationName", name);
   }
   if (skinList.getSelected() != null) prefs.putString("skinName", skinList.getSelected());
   prefs.flush();
 }
Пример #3
0
  @Override
  public void create() {

    //		Gdx.gl.glClearColor(
    //			background.rgb.getRed() / 255f,
    //			background.rgb.getGreen() / 255f,
    //			background.rgb.getBlue() / 255f,
    //			background.rgb.getAlpha() / 255f);
    //		Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

    //		Gdx.graphics.setContinuousRendering(false);
    //		Gdx.graphics.requestRendering();

    cam = new OrthographicCamera();
    batch = new SpriteBatch();

    stage = new Stage();
    skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    input = new TextField("", skin);

    // can't use Table here since it will conflict with the Swing Table toolkit
    // this is why static is shit -.-
    labelInput = new Label("Sample Text:", skin);
    labelScale = new Label("Scale:", skin);
    scaleAmt = new Label("1.0", skin);

    labelInput.setHeight(input.getHeight());
    labelInput.setPosition(10, Gdx.graphics.getHeight() - labelInput.getHeight() - 5);
    input.setPosition(
        labelInput.getX() + labelInput.getWidth() + 10,
        Gdx.graphics.getHeight() - input.getHeight() - 5);

    scaleSlider = new Slider(0, 3, 0.05f, false, skin);
    scaleSlider.setSnapToValues(new float[] {0.0f, 0.5f, 1.0f}, 0.05f);

    scaleSlider.addListener(
        new ChangeListener() {
          @Override
          public void changed(ChangeEvent arg0, Actor arg1) {
            scaleAmt.setText(String.format("%.2f", scaleSlider.getValue()));
          }
        });
    scaleSlider.setValue(1.0f);
    scaleAmt.setText(String.format("%.2f", scaleSlider.getValue()));

    linearFiltering = new ToggleBox("Linear Filtering", skin);
    linearFiltering.addListener(
        new ClickListener() {
          public void clicked(InputEvent ev, float x, float y) {
            updateFiltering();
          }
        });

    scaleAmt.setHeight(scaleSlider.getHeight());
    labelScale.setHeight(scaleSlider.getHeight());

    labelScale.setPosition(
        input.getX() - 10 - labelScale.getWidth(), labelInput.getY() - labelInput.getHeight() - 5);
    scaleSlider.setPosition(input.getX(), input.getY() - input.getHeight() - 5);
    scaleAmt.setPosition(scaleSlider.getX() + scaleSlider.getWidth() + 5, scaleSlider.getY());

    linearFiltering.setPosition(input.getX(), scaleSlider.getY() - scaleSlider.getHeight() - 10);

    Gdx.input.setInputProcessor(stage);
    stage.addActor(labelInput);
    stage.addActor(input);
    stage.addActor(labelScale);
    stage.addActor(scaleSlider);
    stage.addActor(scaleAmt);
    stage.addActor(linearFiltering);

    myButton = new TextButton("Blah", skin);
  }
  @Override
  public void render() {
    long timeToRun = (long) (sliderMillisAvailablePerFrame.getValue() * 1000000f);
    scheduler.run(timeToRun);

    renderer.begin(ShapeType.Filled);
    int level = 0;
    worldMap.setLevel(level);
    int xMax = HierarchicalTiledGraph.sizeX[level];
    int yMax = HierarchicalTiledGraph.sizeY[level];
    for (int x = 0; x < xMax; x++) {
      for (int y = 0; y < yMax; y++) {
        switch (worldMap.getNode(x, y).type) {
          case TiledNode.TILE_FLOOR:
            renderer.setColor(Color.WHITE);
            break;
          case TiledNode.TILE_WALL:
            renderer.setColor(Color.GRAY);
            break;
          default:
            renderer.setColor(Color.BLACK);
            break;
        }
        renderer.rect(x * width, y * width, width, width);
      }
    }

    // Draw path nodes
    for (int p = 0; p < numPaths; p++) {
      TiledSmoothableGraphPath<HierarchicalTiledNode> path = paths[p];
      int nodeCount = path.getCount();
      if (nodeCount == 0) break;
      renderer.setColor(p % 2 == 0 ? Color.RED : Color.ORANGE);
      for (int i = 0; i < nodeCount; i++) {
        HierarchicalTiledNode node = path.nodes.get(i);
        renderer.rect(node.x * width, node.y * width, width, width);
      }
    }

    if (smooth) {
      renderer.end();
      renderer.begin(ShapeType.Line);
      // Draw lines between path nodes
      for (int p = 0; p < numPaths; p++) {
        TiledSmoothableGraphPath<HierarchicalTiledNode> path = paths[p];
        int nodeCount = path.getCount();
        if (nodeCount > 0) {
          float hw = width / 2f;
          HierarchicalTiledNode prevNode = path.nodes.get(0);
          renderer.setColor(p % 2 == 0 ? Color.RED : Color.ORANGE);
          for (int i = 1; i < nodeCount; i++) {
            HierarchicalTiledNode node = path.nodes.get(i);
            renderer.line(
                node.x * width + hw,
                node.y * width + hw,
                prevNode.x * width + hw,
                prevNode.y * width + hw);
            prevNode = node;
          }
        }
      }
    }

    // Draw the lower level node of the buildings (usually a tile close to the center of mass)
    level = 1;
    worldMap.setLevel(level);
    xMax = HierarchicalTiledGraph.sizeX[level];
    yMax = HierarchicalTiledGraph.sizeY[level];
    renderer.end();
    renderer.begin(ShapeType.Line);
    renderer.setColor(Color.MAROON);
    float hw = width * .5f;
    for (int x = 0; x < xMax; x++) {
      for (int y = 0; y < yMax; y++) {
        HierarchicalTiledNode lln = worldMap.getNode(x, y).getLowerLevelNode();
        renderer.circle(lln.x * width + hw, lln.y * width + hw, hw);
      }
    }

    renderer.end();
  }
  @SuppressWarnings("unchecked")
  @Override
  public void create(Table table) {
    lastEndTileX = -1;
    lastEndTileY = -1;
    startTileX = 1;
    startTileY = 1;

    // Create the map
    worldMap = new HierarchicalTiledGraph();
    int roomCount = 100;
    int roomMinSize = 2;
    int roomMaxSize = 8;
    int squashIterations = 100;
    worldMap.init(roomCount, roomMinSize, roomMaxSize, squashIterations);

    paths =
        (TiledSmoothableGraphPath<HierarchicalTiledNode>[]) new TiledSmoothableGraphPath[NUM_PATHS];
    for (int i = 0; i < NUM_PATHS; i++) {
      paths[i] = new TiledSmoothableGraphPath<HierarchicalTiledNode>();
    }
    numPaths = 0;
    heuristic = new TiledManhattanDistance<HierarchicalTiledNode>();
    IndexedAStarPathFinder<HierarchicalTiledNode> levelPathFinder =
        new IndexedAStarPathFinder<HierarchicalTiledNode>(worldMap, true);
    pathFinder = new HierarchicalPathFinder<HierarchicalTiledNode>(worldMap, levelPathFinder);
    pathSmoother =
        new PathSmoother<HierarchicalTiledNode, Vector2>(
            new TiledRaycastCollisionDetector<HierarchicalTiledNode>(worldMap));
    pathSmootherRequest = new PathSmootherRequest<HierarchicalTiledNode, Vector2>();

    requestPool =
        new Pool<MyPathFinderRequest>() {
          @Override
          protected MyPathFinderRequest newObject() {
            return new MyPathFinderRequest();
          }
        };
    PathFinderQueue<HierarchicalTiledNode> pathFinderQueue =
        new PathFinderQueue<HierarchicalTiledNode>(pathFinder);
    MessageManager.getInstance().addListener(pathFinderQueue, PF_REQUEST);

    scheduler = new LoadBalancingScheduler(100);
    scheduler.add(pathFinderQueue, 1, 0);

    renderer = new ShapeRenderer();
    inputProcessor = new TiledHierarchicalAStarInputProcessor(this);

    Table detailTable = new Table(container.skin);

    detailTable.row();
    checkSmooth = new CheckBox("[RED]S[]mooth Path", container.skin);
    checkSmooth.setChecked(smooth);
    checkSmooth.addListener(
        new ChangeListener() {
          @Override
          public void changed(ChangeEvent event, Actor actor) {
            CheckBox checkBox = (CheckBox) event.getListenerActor();
            smooth = checkBox.isChecked();
            updatePath(true);
          }
        });
    detailTable.add(checkSmooth);

    detailTable.row();
    checkDiagonal = new CheckBox("Prefer [RED]D[]iagonal", container.skin);
    checkDiagonal.setChecked(worldMap.diagonal);
    checkDiagonal.addListener(
        new ChangeListener() {
          @Override
          public void changed(ChangeEvent event, Actor actor) {
            CheckBox checkBox = (CheckBox) event.getListenerActor();
            worldMap.diagonal = checkBox.isChecked();
            updatePath(true);
          }
        });
    detailTable.add(checkDiagonal);

    detailTable.row();
    addSeparator(detailTable);

    detailTable.row();
    checkMetrics = new CheckBox("Calculate [RED]M[]etrics", container.skin);
    checkMetrics.setChecked(metrics);
    checkMetrics.addListener(
        new ChangeListener() {
          @Override
          public void changed(ChangeEvent event, Actor actor) {
            CheckBox checkBox = (CheckBox) event.getListenerActor();
            metrics = checkBox.isChecked();
            updatePath(true);
          }
        });
    detailTable.add(checkMetrics);
    detailTable.row();
    addSeparator(detailTable);

    detailTable.row();
    sliderMillisAvailablePerFrame = new Slider(0.1f, 40f, 0.1f, false, container.skin);
    sliderMillisAvailablePerFrame.setValue(16);
    final Label labelMillisAvailablePerFrame =
        new Label(
            "Millis Available per Frame [[" + sliderMillisAvailablePerFrame.getValue() + "]",
            container.skin);
    detailTable.add(labelMillisAvailablePerFrame);
    detailTable.row();
    sliderMillisAvailablePerFrame.addListener(
        new ChangeListener() {
          @Override
          public void changed(ChangeEvent event, Actor actor) {
            labelMillisAvailablePerFrame.setText(
                "Millis Available per Frame [[" + sliderMillisAvailablePerFrame.getValue() + "]");
          }
        });
    Table sliderMapfTable = new Table();
    sliderMapfTable.add(new Label("[RED]-[]  ", container.skin));
    sliderMapfTable.add(sliderMillisAvailablePerFrame);
    sliderMapfTable.add(new Label("  [RED]+[]", container.skin));
    detailTable.add(sliderMapfTable);

    detailWindow = createDetailWindow(detailTable);
  }