@Override public void dispose() { textWidgets.forEach(TextWidget::dispose); background.dispose(); reorganize.dispose(); newMilitary.dispose(); recruit.dispose(); training.dispose(); merge.dispose(); disband.dispose(); upgrade.dispose(); militaryListTextTemplate.dispose(); invalidateListPanes(); }
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); }
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); }
@Override public void draw(Batch batch, float parentAlpha) { batch.draw( reorganize.get(), parent.getX() + reorganizePos.x, parent.getY() + reorganizePos.y, reorganizePos.width, reorganizePos.height); batch.draw( newMilitary.get(), parent.getX() + newMilitaryPos.x, parent.getY() + newMilitaryPos.y, newMilitaryPos.width, newMilitaryPos.height); batch.draw( recruit.get(), parent.getX() + recruitPos.x, parent.getY() + recruitPos.y, recruitPos.width, recruitPos.height); batch.draw( training.get(), parent.getX() + trainingPos.x, parent.getY() + trainingPos.y, trainingPos.width, trainingPos.height); batch.draw( merge.get(), parent.getX() + mergePos.x, parent.getY() + mergePos.y, mergePos.width, mergePos.height); batch.draw( disband.get(), parent.getX() + disbandPos.x, parent.getY() + disbandPos.y, disbandPos.width, disbandPos.height); batch.draw( upgrade.get(), parent.getX() + upgradePos.x, parent.getY() + upgradePos.y, upgradePos.width, upgradePos.height); for (TextWidget<ArchitectureCommandFrame.TextType> textWidget : textWidgets) { textWidget.setPosition( textWidget.getExtra().position.x + parent.getX(), textWidget.getExtra().position.y + parent.getY()); if (textWidget.getExtra().staticText) { textWidget.setText(textWidget.getExtra().name); } else { textWidget.setText( parent.getCurrentArchitecture().getFieldString(textWidget.getExtra().name)); } textWidget.draw(batch, parentAlpha); } if (militaryBottomPane == null) { initMilitaryBottomPane(); } if (militaryTopPane == null) { initMilitaryTopPane(); } if (currentMilitary != null) { batch.end(); shapeRenderer.begin(ShapeRenderer.ShapeType.Line); shapeRenderer.setProjectionMatrix(batch.getProjectionMatrix()); shapeRenderer.setTransformMatrix(batch.getTransformMatrix()); shapeRenderer.setColor(selectedBorderColor); shapeRenderer.rect( parent.getX() + currentMilitaryPos.getX(), parent.getY() + currentMilitaryPos.getY(), currentMilitaryPos.getWidth(), currentMilitaryPos.getHeight()); shapeRenderer.end(); batch.begin(); } }