Esempio n. 1
0
  private void createPlanetGui(final Planet planet) {
    WorldAlignementContainer cont =
        new WorldAlignementContainer(gui, renderer.getCamera(), planet.getPosition());
    cont.setBackgroundColor(new Color(0, 0, 0, 0.5f));
    Label label_strength = new Label(gui, "Strength");
    Slider slider_strength = new Slider(gui, 0.1f, 1, 0.5f);
    Label label_health = new Label(gui, "Health");
    Slider slider_health = new Slider(gui, 0.1f, 1, 0.5f);
    Label label_speed = new Label(gui, "Speed");
    Slider slider_speed = new Slider(gui, Constants.BOID_MIN_SPEED, 1, 0.5f);
    Label label_resources = new Label(gui, "Resources");
    Slider slider_resources = new Slider(gui, 10, Constants.PLANET_MAX_CREATURES, 20);
    CheckBox start_planet = new CheckBox(gui, "Start Planet");

    slider_strength.setSize(100, 8);
    slider_health.setSize(100, 8);
    slider_speed.setSize(100, 8);
    slider_resources.setSize(100, 8);

    Color bg = new Color(0.3f, 0.3f, 0.3f, 1);
    slider_strength.setBackgroundColor(bg);
    slider_health.setBackgroundColor(bg);
    slider_speed.setBackgroundColor(bg);
    slider_resources.setBackgroundColor(bg);

    slider_strength.setValue(planet.getStrength());
    slider_health.setValue(planet.getHealth());
    slider_speed.setValue(planet.getSpeed());
    slider_resources.setValue(planet.getMaxResources());

    start_planet.setChecked(planet.isStartPlanet());
    start_planet.setSize(150, 24);

    cont.addWidget(label_strength);
    cont.addWidget(new Spacer(gui, 0, 3));
    cont.addWidget(slider_strength);
    cont.addWidget(new Spacer(gui, 0, 3));
    cont.addWidget(label_health);
    cont.addWidget(new Spacer(gui, 0, 3));
    cont.addWidget(slider_health);
    cont.addWidget(new Spacer(gui, 0, 3));
    cont.addWidget(label_speed);
    cont.addWidget(new Spacer(gui, 0, 3));
    cont.addWidget(slider_speed);
    cont.addWidget(new Spacer(gui, 0, 3));
    cont.addWidget(label_resources);
    cont.addWidget(new Spacer(gui, 0, 3));
    cont.addWidget(slider_resources);
    cont.addWidget(new Spacer(gui, 0, 3));
    cont.addWidget(start_planet);
    cont.addWidget(new Spacer(gui, slider_resources.getWidth() + 20, 10));
    gui.add(cont);
    conts.add(cont);

    slider_strength.setValueChangedListener(
        new ValueChangedListener() {

          public void valueChanged(Widget widget) {
            for (Planet planet : selected_planets) planet.setStrength(((Slider) widget).getValue());

            for (WorldAlignementContainer cont : conts) {
              VerticalBoxContainer v_box = (VerticalBoxContainer) cont.getWidgets().get(0);
              ((Slider) v_box.getWidgets().get(2)).setValue(((Slider) widget).getValue());
            }
          }
        });

    slider_health.setValueChangedListener(
        new ValueChangedListener() {

          public void valueChanged(Widget widget) {
            for (Planet planet : selected_planets) planet.setHealth(((Slider) widget).getValue());

            for (WorldAlignementContainer cont : conts) {
              VerticalBoxContainer v_box = (VerticalBoxContainer) cont.getWidgets().get(0);
              ((Slider) v_box.getWidgets().get(6)).setValue(((Slider) widget).getValue());
            }
          }
        });

    slider_speed.setValueChangedListener(
        new ValueChangedListener() {

          public void valueChanged(Widget widget) {
            for (Planet planet : selected_planets) planet.setSpeed(((Slider) widget).getValue());

            for (WorldAlignementContainer cont : conts) {
              VerticalBoxContainer v_box = (VerticalBoxContainer) cont.getWidgets().get(0);
              ((Slider) v_box.getWidgets().get(10)).setValue(((Slider) widget).getValue());
            }
          }
        });

    slider_resources.setValueChangedListener(
        new ValueChangedListener() {

          public void valueChanged(Widget widget) {
            for (Planet planet : selected_planets)
              planet.setResources((int) ((Slider) widget).getValue());

            for (WorldAlignementContainer cont : conts) {
              VerticalBoxContainer v_box = (VerticalBoxContainer) cont.getWidgets().get(0);
              ((Slider) v_box.getWidgets().get(14)).setValue(((Slider) widget).getValue());
            }
          }
        });

    start_planet.setClickedListener(
        new ClickedListener() {

          public void clicked(Widget widget) {
            for (Planet planet : selected_planets)
              planet.setStartPlanet(((CheckBox) widget).isChecked());

            for (WorldAlignementContainer cont : conts) {
              VerticalBoxContainer v_box = (VerticalBoxContainer) cont.getWidgets().get(0);
              ((CheckBox) v_box.getWidgets().get(16)).setChecked(((CheckBox) widget).isChecked());
            }
          }
        });
  }
Esempio n. 2
0
  public void display(GLCanvas canvas) {
    GL gl = canvas.getGL();

    //
    // render the simulation
    //
    try {
      sim.update();
    } catch (Exception e) {
      Log.println("[Editor] exception in simulation update/calculate paths: " + e.getMessage());
      e.printStackTrace();
    }
    renderer.render(sim, canvas);

    //
    // render the grid
    //
    gl.glColor4f(0.4f, 0.4f, 0.4f, 0.4f);
    gl.glEnable(GL.GL_BLEND);
    gl.glBegin(GL.GL_LINES);
    for (int x = 0; x < 100; x++) {
      gl.glVertex2f(
          -50 * Constants.PLANET_MAX_SIZE * 4 + x * Constants.PLANET_MAX_SIZE * 4,
          -50 * Constants.PLANET_MAX_SIZE * 4);
      gl.glVertex2f(
          -50 * Constants.PLANET_MAX_SIZE * 4 + x * Constants.PLANET_MAX_SIZE * 4,
          50 * Constants.PLANET_MAX_SIZE * 4);
    }

    for (int x = 0; x < 100; x++) {
      gl.glVertex2f(
          -50 * Constants.PLANET_MAX_SIZE * 4,
          -50 * Constants.PLANET_MAX_SIZE * 4 + x * Constants.PLANET_MAX_SIZE * 4);
      gl.glVertex2f(
          +50 * Constants.PLANET_MAX_SIZE * 4,
          -50 * Constants.PLANET_MAX_SIZE * 4 + x * Constants.PLANET_MAX_SIZE * 4);
    }
    gl.glDisable(GL.GL_BLEND);
    gl.glEnd();

    //
    // render rectangle selection
    //
    if (drag_start != null && drag_end != null && selected_planets.size() == 0) {
      gl.glLineWidth(2);
      gl.glColor4f(1, 1, 1, 1);
      Widget.renderOutlinedQuad(
          drag_start.x, drag_start.y, drag_end.x - drag_start.x, -(drag_end.y - drag_start.y));
      gl.glLineWidth(1);
    }

    //
    // render reference system
    //
    gl.glColor3f(1, 1, 1);
    gl.glBegin(GL.GL_LINES);
    gl.glColor3f(1, 0, 0);
    gl.glVertex2f(Constants.PLANET_MAX_SIZE * 50, 0);
    gl.glVertex2f(-Constants.PLANET_MAX_SIZE * 50, 0);
    gl.glColor3f(0, 1, 0);
    gl.glVertex2f(0, Constants.PLANET_MAX_SIZE * 50);
    gl.glVertex2f(0, -Constants.PLANET_MAX_SIZE * 50);
    gl.glEnd();

    try {
      Thread.sleep(5);
    } catch (InterruptedException e) {
    }

    //
    // check mouse over planet
    //
    if (sim.getPlanet(
                renderer.getCamera().getScreenToWorldX(mouse_pos.x),
                renderer.getCamera().getScreenToWorldY(mouse_pos.y))
            != null
        && !this.wasGuiIntersected(mouse_pos.x, mouse_pos.y)
        && drag_start != null) for (WorldAlignementContainer cont : conts) cont.setVisible(false);
    else for (WorldAlignementContainer cont : conts) cont.setVisible(true);
  }