Esempio n. 1
0
  private void initMilitaryTopPane() {
    Table contentTable = new Table();

    int itemPerRow =
        (int) (militaryTablePos.width / (militaryTablePortraitSize.x + militaryTableCaptionSize.x));
    int index = 0;
    for (Military m : parent.getCurrentArchitecture().getMilitariesWithLeader()) {
      Table item = new Table();

      Person leader = m.getLeader();
      ImageWidget<Military> portrait;
      if (leader != null) {
        portrait =
            new ImageWidget<>(
                parent.getScreen().getSmallPortrait(leader.getPortraitId()),
                militaryTablePortraitColor);
      } else {
        portrait = new ImageWidget<>(null, militaryTablePortraitColor);
      }
      portrait.setExtra(m);
      item.add(portrait).width(militaryTablePortraitSize.x).height(militaryTablePortraitSize.y);

      Table detail = new Table();

      TextWidget<Military> caption = new TextWidget<>(militaryTableCaptionTemplate);
      caption.setExtra(m);
      caption.setText(m.getName());
      detail
          .add(caption)
          .width(militaryTableCaptionSize.x)
          .height(militaryTableCaptionSize.y)
          .row();

      TextWidget<Military> quantity = new TextWidget<>(militaryTableDetailTemplate);
      quantity.setExtra(m);
      quantity.setText(
          GlobalStrings.getString(GlobalStrings.Keys.MILITARY_QUANTITY_SHORT) + m.getQuantity());
      detail.add(quantity).width(militaryTableDetailSize.x).height(militaryTableDetailSize.y).row();

      TextWidget<Military> morale = new TextWidget<>(militaryTableDetailTemplate);
      morale.setExtra(m);
      morale.setText(
          GlobalStrings.getString(GlobalStrings.Keys.MILITARY_MORALE_SHORT) + m.getMorale());
      detail.add(morale).width(militaryTableDetailSize.x).height(militaryTableDetailSize.y).row();

      TextWidget<Military> combativity = new TextWidget<>(militaryTableDetailTemplate);
      combativity.setExtra(m);
      combativity.setText(
          GlobalStrings.getString(GlobalStrings.Keys.MILITARY_COMBATIVITY_SHORT)
              + m.getCombativity());
      detail
          .add(combativity)
          .width(militaryTableDetailSize.x)
          .height(militaryTableDetailSize.y)
          .row();

      detail.top();
      item.add(detail);

      item.addListener(
          new InputListener() {
            @Override
            public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
              currentMilitary = m;
              currentMilitaryPos =
                  new Rectangle(
                      item.getX() + militaryTablePos.getX(),
                      item.getY() + militaryTablePos.getY(),
                      item.getWidth(),
                      item.getHeight());
              if (m.isCampaignable()) {
                parent
                    .getScreen()
                    .getMapLayer()
                    .startSelectingLocation(
                        parent.getCurrentArchitecture().getCampaignablePositions(),
                        p -> {
                          m.startCampaign(p);
                          invalidateListPanes();
                        });
              }
              return true;
            }
          });

      contentTable.add(item);

      index++;
      if (index % itemPerRow == 0) {
        contentTable.row();
      }
    }

    contentTable.top().left();

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

    parent.addActor(militaryTopPane);
  }
Esempio n. 2
0
 @Override
 public void onClick(float x, float y) {
   if (newMilitaryPos.contains(x, y)) {
     parent
         .getScreen()
         .showTabList(
             GlobalStrings.getString(GlobalStrings.Keys.NEW_MILITARY),
             TabListGameFrame.ListKindType.MILITARY_KIND,
             parent.getCurrentArchitecture(),
             parent.getCurrentArchitecture().getActualCreatableMilitaryKinds(),
             TabListGameFrame.Selection.SINGLE,
             selectedItems -> {
               MilitaryKind kind = (MilitaryKind) selectedItems.get(0);
               parent.getCurrentArchitecture().createMilitary(kind);
               invalidateListPanes();
             });
   } else if (recruitPos.contains(x, y)
       && parent.getCurrentArchitecture().getRecruitableMilitaries().size() > 0) {
     parent
         .getScreen()
         .showTabList(
             GlobalStrings.getString(GlobalStrings.Keys.RECRUIT_MILITARY),
             TabListGameFrame.ListKindType.PERSON,
             parent.getCurrentArchitecture(),
             parent.getCurrentArchitecture().getPersonsExcludingMayor(),
             TabListGameFrame.Selection.MULTIPLE,
             selectedItems -> {
               for (GameObject i : selectedItems) {
                 Person p = (Person) i;
                 p.setDoingWork(Person.DoingWork.RECRUIT);
               }
               invalidateListPanes();
             });
   } else if (trainingPos.contains(x, y)
       && parent.getCurrentArchitecture().getSelectTrainableMilitaries().size() > 0) {
     parent
         .getScreen()
         .showTabList(
             GlobalStrings.getString(GlobalStrings.Keys.TRAIN_MILITARY),
             TabListGameFrame.ListKindType.PERSON,
             parent.getCurrentArchitecture().getPersonsExcludingMayor(),
             TabListGameFrame.Selection.MULTIPLE,
             selectedItems -> {
               for (GameObject i : selectedItems) {
                 Person p = (Person) i;
                 p.setDoingWork(Person.DoingWork.TRAINING);
               }
               invalidateListPanes();
             });
   } else if (reorganizePos.contains(x, y) && currentMilitary != null) {
     GameObjectList<Person> leaderCandidates =
         new GameObjectList<>(parent.getCurrentArchitecture().getPersonsNotInMilitary());
     leaderCandidates.add(currentMilitary.getLeader());
     parent
         .getScreen()
         .showTabList(
             GlobalStrings.getString(GlobalStrings.Keys.ASSIGN_LEADER),
             TabListGameFrame.ListKindType.PERSON,
             leaderCandidates,
             TabListGameFrame.Selection.SINGLE,
             selectedItems -> {
               currentMilitary.setLeader((Person) selectedItems.get(0));
               parent
                   .getScreen()
                   .showTabList(
                       GlobalStrings.getString(GlobalStrings.Keys.ASSIGN_MILITARY_PERSON),
                       TabListGameFrame.ListKindType.PERSON,
                       parent.getCurrentArchitecture().getPersonsNotInMilitary(),
                       TabListGameFrame.Selection.MULTIPLE,
                       selectedItems1 -> {
                         currentMilitary.setPersons(
                             selectedItems1
                                 .stream()
                                 .map(o -> (Person) o)
                                 .collect(Collectors.toCollection(GameObjectList<Person>::new)));
                         invalidateListPanes();
                       });
             });
   }
 }
Esempio n. 3
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);
  }