コード例 #1
0
  private void initMilitaryBottomPane() {
    Table contentTable = new Table();

    for (Military m : parent.getCurrentArchitecture().getMilitariesWithoutLeader()) {
      List<TextWidget<Military>> rowWidgets = new ArrayList<>();

      TextWidget<Military> name = new TextWidget<>(militaryListTextTemplate);
      name.setExtra(m);
      name.setText(m.getName());
      contentTable.add(name).width(listNameWidth).height(listRowHeight);
      rowWidgets.add(name);

      TextWidget<Military> quantity = new TextWidget<>(militaryListTextTemplate);
      quantity.setExtra(m);
      quantity.setText(String.valueOf(m.getQuantity()));
      contentTable.add(quantity).width(listQuantityWidth).height(listRowHeight);
      rowWidgets.add(quantity);

      TextWidget<Military> recruit = new TextWidget<>(militaryListTextTemplate);
      recruit.setExtra(m);
      if (m.isFullyRecruited()) {
        recruit.setText(GlobalStrings.getString(GlobalStrings.Keys.TICK));
      } else if (m.isBeingRecruited()) {
        recruit.setText(GlobalStrings.getString(GlobalStrings.Keys.UP_ARROW));
      } else {
        recruit.setText("");
      }
      contentTable.add(recruit).width(listRecruitWidth).height(listRowHeight).center();
      rowWidgets.add(recruit);

      TextWidget<Military> train = new TextWidget<>(militaryListTextTemplate);
      train.setExtra(m);
      if (m.isFullyTrained()) {
        train.setText(GlobalStrings.getString(GlobalStrings.Keys.TICK));
      } else if (m.isBeingTrained()) {
        train.setText(GlobalStrings.getString(GlobalStrings.Keys.UP_ARROW));
      } else {
        train.setText("");
      }
      contentTable.add(train).width(listTrainWidth).height(listRowHeight).center();
      rowWidgets.add(train);

      rowWidgets.forEach(
          x ->
              x.addListener(
                  new InputListener() {
                    @Override
                    public boolean touchDown(
                        InputEvent event, float x, float y, int pointer, int button) {
                      currentMilitary = m;
                      currentMilitaryPos =
                          new Rectangle(
                              name.getX() + militaryListPos.getX(),
                              name.getY() + militaryListPos.getY(),
                              militaryListPos.getWidth(),
                              name.getHeight());
                      return true;
                    }
                  }));

      showingTextWidgets.addAll(rowWidgets);

      contentTable.row().height(listRowHeight);
    }

    contentTable.top().left();

    ScrollPane data = new ScrollPane(contentTable);
    militaryBottomPane =
        WidgetUtility.setupScrollpane(
            militaryListPos.getX(),
            militaryListPos.getY(),
            militaryListPos.getWidth(),
            militaryListPos.getHeight(),
            data,
            parent.getScrollbar());

    parent.addActor(militaryBottomPane);
  }