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); }
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); }