Esempio n. 1
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. 2
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);
  }