Esempio n. 1
0
  public TutorialForm(NetworkSelector network, GUIRoot gui_root) {
    this.gui_root = gui_root;
    this.network = network;
    Label headline =
        new Label(
            Utils.getBundleString(bundle, "tutorial_caption"), Skin.getSkin().getHeadlineFont());
    addChild(headline);

    HorizButton button_tutorial1 = new HorizButton(formatTutorial(TUTORIAL_CAMERA), 120);
    button_tutorial1.addMouseClickListener(new TutorialListener(TUTORIAL_CAMERA));
    addChild(button_tutorial1);
    Label label_tutorial1 =
        new Label(Utils.getBundleString(bundle, "tutorial1_tip"), Skin.getSkin().getEditFont());
    addChild(label_tutorial1);

    HorizButton button_tutorial2 = new HorizButton(formatTutorial(TUTORIAL_QUARTERS), 120);
    button_tutorial2.addMouseClickListener(new TutorialListener(TUTORIAL_QUARTERS));
    addChild(button_tutorial2);
    Label label_tutorial2 =
        new Label(Utils.getBundleString(bundle, "tutorial2_tip"), Skin.getSkin().getEditFont());
    addChild(label_tutorial2);

    HorizButton button_tutorial3 = new HorizButton(formatTutorial(TUTORIAL_ARMORY), 120);
    button_tutorial3.addMouseClickListener(new TutorialListener(TUTORIAL_ARMORY));
    addChild(button_tutorial3);
    Label label_tutorial3 =
        new Label(Utils.getBundleString(bundle, "tutorial3_tip"), Skin.getSkin().getEditFont());
    addChild(label_tutorial3);

    HorizButton button_tutorial4 = new HorizButton(formatTutorial(TUTORIAL_TOWER), 120);
    button_tutorial4.addMouseClickListener(new TutorialListener(TUTORIAL_TOWER));
    addChild(button_tutorial4);
    Label label_tutorial4 =
        new Label(Utils.getBundleString(bundle, "tutorial4_tip"), Skin.getSkin().getEditFont());
    addChild(label_tutorial4);

    HorizButton button_tutorial5 = new HorizButton(formatTutorial(TUTORIAL_CHIEFTAIN), 120);
    button_tutorial5.addMouseClickListener(new TutorialListener(TUTORIAL_CHIEFTAIN));
    addChild(button_tutorial5);
    Label label_tutorial5 =
        new Label(Utils.getBundleString(bundle, "tutorial5_tip"), Skin.getSkin().getEditFont());
    addChild(label_tutorial5);

    HorizButton button_tutorial6 = new HorizButton(formatTutorial(TUTORIAL_BATTLE), 120);
    button_tutorial6.addMouseClickListener(new TutorialListener(TUTORIAL_BATTLE));
    addChild(button_tutorial6);
    Label label_tutorial6 =
        new Label(Utils.getBundleString(bundle, "tutorial6_tip"), Skin.getSkin().getEditFont());
    addChild(label_tutorial6);

    HorizButton cancel_button = new CancelButton(120);
    addChild(cancel_button);
    cancel_button.addMouseClickListener(new CancelListener(this));

    // Place objects
    headline.place();
    button_tutorial1.place(headline, BOTTOM_LEFT);
    label_tutorial1.place(button_tutorial1, RIGHT_MID);
    button_tutorial2.place(button_tutorial1, BOTTOM_LEFT);
    label_tutorial2.place(button_tutorial2, RIGHT_MID);
    button_tutorial3.place(button_tutorial2, BOTTOM_LEFT);
    label_tutorial3.place(button_tutorial3, RIGHT_MID);
    button_tutorial4.place(button_tutorial3, BOTTOM_LEFT);
    label_tutorial4.place(button_tutorial4, RIGHT_MID);
    button_tutorial5.place(button_tutorial4, BOTTOM_LEFT);
    label_tutorial5.place(button_tutorial5, RIGHT_MID);
    button_tutorial6.place(button_tutorial5, BOTTOM_LEFT);
    label_tutorial6.place(button_tutorial6, RIGHT_MID);
    cancel_button.place(ORIGIN_BOTTOM_RIGHT);

    // headline
    compileCanvas();
    centerPos();
  }
Esempio n. 2
0
  private final GUIObject createPlayerPulldown(
      GUIRoot gui_root,
      Group group,
      GUIObject previous,
      PulldownButton[] slot_buttons,
      PulldownButton[] race_buttons,
      PulldownButton[] team_buttons,
      Diode[] ready_marks,
      Label[] ratings,
      int index,
      int num_players) {
    PulldownMenu pulldown_menu = new PulldownMenu();
    PulldownItem open_item = new PulldownItem(Utils.getBundleString(bundle, "open"));
    PulldownItem closed_item = new PulldownItem(Utils.getBundleString(bundle, "closed"));
    PulldownItem computer_easy_item = new PulldownItem(Utils.getBundleString(bundle, "easy_ai"));
    PulldownItem computer_normal_item =
        new PulldownItem(Utils.getBundleString(bundle, "normal_ai"));
    PulldownItem computer_hard_item = new PulldownItem(Utils.getBundleString(bundle, "hard_ai"));
    pulldown_menu.addItem(open_item);
    pulldown_menu.addItem(closed_item);
    if (!rated) {
      pulldown_menu.addItem(computer_easy_item);
      pulldown_menu.addItem(computer_normal_item);
      pulldown_menu.addItem(computer_hard_item);
    }
    PulldownButton pulldown_button = new PulldownButton(gui_root, pulldown_menu, CLOSED_INDEX, 150);
    slot_buttons[index] = pulldown_button;
    group.addChild(pulldown_button);
    if (previous != null) pulldown_button.place(previous, BOTTOM_MID);
    else pulldown_button.place();
    pulldown_menu.addItemChosenListener(new PlayerSlotListener(index));
    pulldown_button.setDisabled(local_player_slot != 0 || index == local_player_slot);

    PulldownMenu race_pulldown_menu = new PulldownMenu();
    for (int i = 0; i < RacesResources.getNumRaces(); i++) {
      PulldownItem race_item = new PulldownItem(RacesResources.getRaceName(i));
      race_pulldown_menu.addItem(race_item);
    }
    PulldownMenu team_pulldown_menu = new PulldownMenu();
    int num_teams = num_players;
    if (rated) num_teams = 2;
    for (int i = 0; i < num_teams; i++) {
      String team_str =
          Utils.getBundleString(bundle, "team", new Object[] {Integer.toString(i + 1)});
      PulldownItem race_item = new PulldownItem(team_str);
      team_pulldown_menu.addItem(race_item);
    }
    PulldownButton race_pulldown_button = new PulldownButton(gui_root, race_pulldown_menu, 0, 115);
    PulldownButton team_pulldown_button =
        new PulldownButton(gui_root, team_pulldown_menu, index % num_teams, 115);
    race_buttons[index] = race_pulldown_button;
    team_buttons[index] = team_pulldown_button;
    group.addChild(race_pulldown_button);
    group.addChild(team_pulldown_button);
    race_pulldown_button.place(pulldown_button, RIGHT_MID);
    team_pulldown_button.place(race_pulldown_button, RIGHT_MID);
    race_pulldown_menu.addItemChosenListener(new PlayerSlotListener(index));
    team_pulldown_menu.addItemChosenListener(new PlayerSlotListener(index));
    race_pulldown_button.setDisabled(!canControlSlot(index));
    team_pulldown_button.setDisabled(!canControlSlot(index));

    Diode ready_mark = new Diode();
    ready_marks[index] = ready_mark;
    group.addChild(ready_mark);
    ready_mark.place(team_pulldown_button, RIGHT_MID);
    Font font = Skin.getSkin().getEditFont();
    ratings[index] = new Label("", font, RATING_WIDTH, Label.ALIGN_RIGHT);
    if (rated) {
      group.addChild(ratings[index]);
      ratings[index].place(ready_mark, RIGHT_MID);
    }
    String player_str =
        Utils.getBundleString(bundle, "player", new Object[] {Integer.toString(index + 1)});
    Label label = new Label(player_str, Skin.getSkin().getEditFont());
    label.setColor(Player.COLORS[index]);
    group.addChild(label);
    label.place(pulldown_button, LEFT_MID);

    return pulldown_button;
  }
Esempio n. 3
0
  public GameMenu(
      GameNetwork game_network,
      GUIRoot gui_root,
      SelectGameMenu owner,
      Game game,
      WorldGenerator generator,
      int player_slot,
      int compare_width,
      int compare_height,
      int button_width) {
    super(Utils.getBundleString(getBundle(), "game_caption"));
    this.game_network = game_network;
    this.owner = owner;
    this.gui_root = gui_root;
    this.local_player_slot = player_slot;
    this.rated = game.isRated();
    this.game = game;

    String tag = "";
    if (rated) tag = Utils.getBundleString(bundle, "rated") + " ";
    Label game_name_label =
        new Label(
            Utils.getBundleString(bundle, "game") + " " + tag + game.getName(),
            Skin.getSkin().getHeadlineFont());
    slot_buttons = new PulldownButton[MatchmakingServerInterface.MAX_PLAYERS];
    race_buttons = new PulldownButton[MatchmakingServerInterface.MAX_PLAYERS];
    team_buttons = new PulldownButton[MatchmakingServerInterface.MAX_PLAYERS];
    ready_marks = new Diode[MatchmakingServerInterface.MAX_PLAYERS];
    ratings = new Label[MatchmakingServerInterface.MAX_PLAYERS];
    Group player_group = new Group();
    GUIObject previous = null;
    for (int i = 0; i < MatchmakingServerInterface.MAX_PLAYERS; i++)
      previous =
          createPlayerPulldown(
              gui_root,
              player_group,
              previous,
              slot_buttons,
              race_buttons,
              team_buttons,
              ready_marks,
              ratings,
              i,
              MatchmakingServerInterface.MAX_PLAYERS);
    player_group.compileCanvas();
    addChild(player_group);

    Box pdata = Skin.getSkin().getPanelData().getBox();
    FormData fdata = Skin.getSkin().getFormData();

    int width = compare_width - pdata.getLeftOffset() - pdata.getRightOffset();
    chat_info =
        new Label(Utils.getBundleString(bundle, "chat"), Skin.getSkin().getEditFont(), width);
    Group chat_line_group = new Group();
    chat_line = new EditLine(width - SEND_BUTTON_WIDTH - fdata.getObjectSpacing(), 100);
    send_button = new HorizButton(Utils.getBundleString(bundle, "send"), SEND_BUTTON_WIDTH);
    send_button.addMouseClickListener(new SendListener());
    chat_line_group.addChild(chat_line);
    chat_line.place();
    chat_line_group.addChild(send_button);
    send_button.place(chat_line, RIGHT_MID);
    chat_line_group.compileCanvas();
    addChild(chat_line_group);

    chat_line.addEnterListener(new ChatListener());
    addChild(game_name_label);
    addChild(chat_info);

    start_button = new HorizButton(Utils.getBundleString(bundle, "start"), button_width);
    if (local_player_slot == 0) {
      addChild(start_button);
      start_button.addMouseClickListener(new StartListener());
    }
    int height =
        compare_height
            - pdata.getTopOffset()
            - pdata.getBottomOffset()
            - chat_info.getHeight()
            - chat_line.getHeight()
            - game_name_label.getHeight()
            - player_group.getHeight()
            - start_button.getHeight()
            - 5 * fdata.getObjectSpacing();
    chat_box = new TextBox(width, height, Skin.getSkin().getEditFont(), -1);
    addChild(chat_box);
    ready_button = new HorizButton(Utils.getBundleString(bundle, "ready"), button_width);
    addChild(ready_button);
    ready_button.addMouseClickListener(new ReadyListener());
    HorizButton cancel_button =
        new HorizButton(Utils.getBundleString(bundle, "cancel"), button_width);
    addChild(cancel_button);
    cancel_button.addMouseClickListener(new CancelButtonListener());
    HorizButton info_button = new HorizButton(Utils.getBundleString(bundle, "info"), button_width);
    addChild(info_button);
    info_button.addMouseClickListener(new InfoButtonListener());

    game_name_label.place();
    player_group.place(game_name_label, BOTTOM_LEFT);
    chat_info.place(player_group, BOTTOM_LEFT);
    chat_box.place(chat_info, BOTTOM_LEFT);
    chat_line_group.place(chat_box, BOTTOM_LEFT);
    cancel_button.place(chat_line_group, BOTTOM_RIGHT);
    info_button.place(chat_line_group, BOTTOM_LEFT);
    ready_button.place(cancel_button, LEFT_MID);
    if (local_player_slot == 0) start_button.place(ready_button, LEFT_MID);
    Font font = Skin.getSkin().getEditFont();
    if (rated) {
      Label rating =
          new Label(Utils.getBundleString(bundle, "rating"), font, RATING_WIDTH, Label.ALIGN_RIGHT);
      addChild(rating);
      rating.place(player_group, TOP_RIGHT);
    }
    compileCanvas();
  }
Esempio n. 4
0
  public final void debugRender(float landscape_x, float landscape_y) {
    GL11.glDisable(GL11.GL_TEXTURE_2D);
    GL11.glBegin(GL11.GL_LINES);
    GL11.glColor3f(1f, 1f, 0f);
    int RADIUS = 30;
    int center_x = toGridCoordinate(landscape_x);
    int center_y = toGridCoordinate(landscape_y);
    int start_x = StrictMath.max(0, center_x - RADIUS);
    int end_x = StrictMath.min(occupants.length - 0, center_x + RADIUS);
    int start_y = StrictMath.max(0, center_y - RADIUS);
    int end_y = StrictMath.min(occupants.length - 0, center_y + RADIUS);
    for (int y = start_y; y < end_y; y++)
      for (int x = start_x; x < end_x; x++)
        if (isGridOccupied(x, y)) {
          debugRenderQuad(x, y);
        }
    GL11.glEnd();
    GL11.glEnable(GL11.GL_TEXTURE_2D);
    Font font = Skin.getSkin().getEditFont();
    final float OFFSET = 2f;
    int s = HeightMap.METERS_PER_UNIT_GRID;
    TextLineRenderer renderer = new TextLineRenderer(font);
    if (Globals.draw_axes) {
      GL11.glColor3f(1f, 1f, 1f);
      GL11.glEnable(GL11.GL_BLEND);
      for (int y = start_y; y < end_y; y++)
        for (int x = start_x; x < end_x; x++)
          if (!isGridOccupied(x, y)) {
            float xf = (x + .5f) * s;
            float yf = (y + .5f) * s;
            float z = heightmap.getNearestHeight(xf, yf) + OFFSET;
            GL11.glPushMatrix();
            GL11.glTranslatef(xf, yf, z);
            GL11.glScalef(.08f, .08f, .08f);
            font.setupQuads();
            renderer.render(
                4,
                4,
                Float.NEGATIVE_INFINITY,
                Float.POSITIVE_INFINITY,
                Float.NEGATIVE_INFINITY,
                Float.POSITIVE_INFINITY,
                "" + heightmap.getBuildValue(x, y));
            font.resetQuads();
            GL11.glPopMatrix();
          }
      GL11.glDisable(GL11.GL_BLEND);
    }
    GL11.glColor3f(1f, 0f, 0f);
    List last_path_search = PathFinder.visited_list;
    if (last_path_search != null) {
      for (int i = 0; i < last_path_search.size(); i++) {
        //				int[] coords = (int[])last_path_search.get(i);
        Node node = (Node) last_path_search.get(i);
        GL11.glPushMatrix();
        GL11.glDisable(GL11.GL_TEXTURE_2D);
        GL11.glBegin(GL11.GL_LINES);
        debugRender(node.getGridX(), node.getGridY());
        GL11.glEnd();

        GL11.glEnable(GL11.GL_TEXTURE_2D);
        float xf = node.getGridX() * s;
        float yf = node.getGridY() * s;
        float z = heightmap.getNearestHeight(xf, yf) + OFFSET;
        GL11.glTranslatef(xf, yf, z);
        GL11.glScalef(.08f, .08f, .08f);
        GL11.glEnable(GL11.GL_BLEND);
        font.setupQuads();
        renderer.render(
            4,
            4,
            Float.NEGATIVE_INFINITY,
            Float.POSITIVE_INFINITY,
            Float.NEGATIVE_INFINITY,
            Float.POSITIVE_INFINITY,
            "" + node.getTotalCost());
        font.resetQuads();
        GL11.glDisable(GL11.GL_BLEND);
        GL11.glPopMatrix();
      }
    }
  }