use of com.minecolonies.api.colony.ICitizenDataView in project minecolonies by Minecolonies.
the class WindowAssignCitizen method hireClicked.
/**
* When assignment was clicked.
* @param button the clicked button.
*/
private void hireClicked(@NotNull final Button button) {
final int row = citizenList.getListElementIndexByPane(button);
final ICitizenDataView data = citizens.get(row);
final boolean isAssign = button.getText().getString().equals(new TranslationTextComponent("com.minecolonies.coremod.gui.hiring.buttonassign").getString());
if (isAssign) {
if (building.getResidents().size() >= building.getMax()) {
return;
}
building.addResident(data.getId());
data.setHomeBuilding(building.getPosition());
} else {
building.removeResident(data.getId());
data.setHomeBuilding(null);
}
Network.getNetwork().sendToServer(new AssignUnassignMessage(this.building, isAssign, data.getId(), null));
updateCitizens();
citizenList.refreshElementPanes();
}
use of com.minecolonies.api.colony.ICitizenDataView in project minecolonies by Minecolonies.
the class CitizenWindowUtils method createSaturationBar.
/**
* Creates an health bar according to the citizen maxHealth and currentHealth.
*
* @param citizen the citizen.
* @param view the view to add these to.
*/
public static void createSaturationBar(final ICitizenDataView citizen, final View view) {
view.findPaneOfTypeByID(WINDOW_ID_SATURATION_BAR, View.class).setAlignment(Alignment.MIDDLE_RIGHT);
// Max saturation (Black food items).
for (int i = 0; i < ICitizenData.MAX_SATURATION; i++) {
@NotNull final Image saturation = new Image();
saturation.setImage(Screen.GUI_ICONS_LOCATION, EMPTY_SATURATION_ITEM_ROW_POS, SATURATION_ICON_COLUMN, SATURATION_ICON_HEIGHT_WIDTH, SATURATION_ICON_HEIGHT_WIDTH, false);
saturation.setPosition(getXOffsetModifier(i) * SATURATION_ICON_POS_X + SATURATION_ICON_OFFSET_X, SATURATION_ICON_POS_Y + getYOffset(i));
view.findPaneOfTypeByID(WINDOW_ID_SATURATION_BAR, View.class).addChild(saturation);
}
// Current saturation (Full food hearts).
int saturationPos;
for (saturationPos = 0; saturationPos < ((int) citizen.getSaturation()); saturationPos++) {
@NotNull final Image saturation = new Image();
saturation.setImage(Screen.GUI_ICONS_LOCATION, FULL_SATURATION_ITEM_ROW_POS, SATURATION_ICON_COLUMN, SATURATION_ICON_HEIGHT_WIDTH, SATURATION_ICON_HEIGHT_WIDTH, false);
saturation.setPosition(getXOffsetModifier(saturationPos) * SATURATION_ICON_POS_X + SATURATION_ICON_OFFSET_X, SATURATION_ICON_POS_Y + getYOffset(saturationPos));
view.findPaneOfTypeByID(WINDOW_ID_SATURATION_BAR, View.class).addChild(saturation);
}
// Half food items.
if (citizen.getSaturation() / 2 % 1 > 0) {
@NotNull final Image saturation = new Image();
saturation.setImage(Screen.GUI_ICONS_LOCATION, HALF_SATURATION_ITEM_ROW_POS, SATURATION_ICON_COLUMN, SATURATION_ICON_HEIGHT_WIDTH, SATURATION_ICON_HEIGHT_WIDTH, false);
saturation.setPosition(getXOffsetModifier(saturationPos) * SATURATION_ICON_POS_X + SATURATION_ICON_OFFSET_X, SATURATION_ICON_POS_Y + getYOffset(saturationPos));
view.findPaneOfTypeByID(WINDOW_ID_SATURATION_BAR, View.class).addChild(saturation);
}
}
use of com.minecolonies.api.colony.ICitizenDataView in project minecolonies by Minecolonies.
the class FamilyWindowCitizen method onOpened.
@Override
public void onOpened() {
super.onOpened();
final String firstParent = citizen.getParents().getA();
final String secondParent = citizen.getParents().getB();
findPaneOfTypeByID("parentA", Text.class).setText(firstParent.isEmpty() ? new TranslationTextComponent("com.minecolonies.coremod.gui.citizen.family.unknown") : new StringTextComponent(firstParent));
findPaneOfTypeByID("parentB", Text.class).setText(secondParent.isEmpty() ? new TranslationTextComponent("com.minecolonies.coremod.gui.citizen.family.unknown") : new StringTextComponent(secondParent));
final int partner = citizen.getPartner();
final ICitizenDataView partnerView = colony.getCitizen(partner);
final Text partnerText = findPaneOfTypeByID("partner", Text.class);
if (partnerView == null) {
partnerText.setText(new StringTextComponent("-"));
} else {
partnerText.setText(new StringTextComponent(partnerView.getName()));
}
childrenList.setDataProvider(new ScrollingList.DataProvider() {
/**
* The number of rows of the list.
* @return the number.
*/
@Override
public int getElementCount() {
return citizen.getChildren().size();
}
/**
* Inserts the elements into each row.
* @param index the index of the row/list element.
* @param rowPane the parent Pane for the row, containing the elements to update.
*/
@Override
public void updateElement(final int index, @NotNull final Pane rowPane) {
rowPane.findPaneOfTypeByID("name", Text.class).setText(new StringTextComponent(colony.getCitizen(citizen.getChildren().get(index)).getName()));
}
});
siblingList.setDataProvider(new ScrollingList.DataProvider() {
/**
* The number of rows of the list.
* @return the number.
*/
@Override
public int getElementCount() {
return citizen.getSiblings().size();
}
/**
* Inserts the elements into each row.
* @param index the index of the row/list element.
* @param rowPane the parent Pane for the row, containing the elements to update.
*/
@Override
public void updateElement(final int index, @NotNull final Pane rowPane) {
rowPane.findPaneOfTypeByID("name", Text.class).setText(new StringTextComponent(colony.getCitizen(citizen.getSiblings().get(index)).getName()));
}
});
}
use of com.minecolonies.api.colony.ICitizenDataView in project minecolonies by Minecolonies.
the class WindowHireWorker method onOpened.
/**
* Called when the GUI has been opened. Will fill the fields and lists.
*/
@Override
public void onOpened() {
updateCitizens();
findPaneOfTypeByID(AUTO_HIRE_WARN, Text.class).off();
citizenList.setDataProvider(new ScrollingList.DataProvider() {
@Override
public int getElementCount() {
return citizens.size();
}
@Override
public void updateElement(final int index, @NotNull final Pane rowPane) {
@NotNull final ICitizenDataView citizen = citizens.get(index);
final Button isPaused = rowPane.findPaneOfTypeByID(BUTTON_PAUSE, Button.class);
if (selectedModule.canAssign(citizen) && !selectedModule.isFull() && !selectedModule.getAssignedCitizens().contains(citizen.getId())) {
rowPane.findPaneOfTypeByID(BUTTON_FIRE, Button.class).off();
rowPane.findPaneOfTypeByID(BUTTON_DONE, Button.class).on();
isPaused.off();
rowPane.findPaneOfTypeByID(BUTTON_RESTART, Button.class).off();
} else if ((selectedModule.isFull()) && !selectedModule.getAssignedCitizens().contains(citizen.getId())) {
rowPane.findPaneOfTypeByID(BUTTON_FIRE, Button.class).off();
rowPane.findPaneOfTypeByID(BUTTON_DONE, Button.class).off();
isPaused.off();
rowPane.findPaneOfTypeByID(BUTTON_RESTART, Button.class).off();
} else {
rowPane.findPaneOfTypeByID(BUTTON_DONE, Button.class).off();
rowPane.findPaneOfTypeByID(BUTTON_FIRE, Button.class).on();
if ((!selectedModule.getColony().isManualHiring() && selectedModule.getHiringMode() == HiringMode.DEFAULT) || (selectedModule.getHiringMode() == HiringMode.AUTO)) {
rowPane.findPaneOfTypeByID(BUTTON_FIRE, Button.class).disable();
findPaneOfTypeByID(AUTO_HIRE_WARN, Text.class).on();
}
isPaused.on();
isPaused.setText(LanguageHandler.format(citizen.isPaused() ? COM_MINECOLONIES_COREMOD_GUI_HIRE_UNPAUSE : COM_MINECOLONIES_COREMOD_GUI_HIRE_PAUSE));
}
if (citizen.isPaused()) {
rowPane.findPaneOfTypeByID(BUTTON_RESTART, Button.class).on();
} else {
rowPane.findPaneOfTypeByID(BUTTON_RESTART, Button.class).off();
}
final StringTextComponent intermString = new StringTextComponent(" ");
final TextBuilder textBuilder = PaneBuilders.textBuilder();
textBuilder.append(new StringTextComponent(""));
int skillCount = citizen.getCitizenSkillHandler().getSkills().entrySet().size();
final Skill primary = selectedModule instanceof WorkerBuildingModuleView ? ((WorkerBuildingModuleView) selectedModule).getPrimarySkill() : null;
final Skill secondary = selectedModule instanceof WorkerBuildingModuleView ? ((WorkerBuildingModuleView) selectedModule).getSecondarySkill() : null;
for (final Map.Entry<Skill, Tuple<Integer, Double>> entry : citizen.getCitizenSkillHandler().getSkills().entrySet()) {
final String skillName = entry.getKey().name().toLowerCase(Locale.US);
final int skillLevel = entry.getValue().getA();
final Style skillStyle = createColor(primary, secondary, entry.getKey());
textBuilder.append(new TranslationTextComponent("com.minecolonies.coremod.gui.citizen.skills." + skillName).setStyle(skillStyle));
textBuilder.append(new StringTextComponent(": " + skillLevel).setStyle(skillStyle));
if (--skillCount > 0) {
textBuilder.append(intermString);
}
}
// finish the current line
textBuilder.newLine();
rowPane.findPaneOfTypeByID(CITIZEN_LABEL, Text.class).setText((citizen.getJob().isEmpty() ? "" : LanguageHandler.format(citizen.getJob()) + ": ") + citizen.getName());
rowPane.findPaneOfTypeByID(ATTRIBUTES_LABEL, Text.class).setText(textBuilder.getText());
}
});
jobList.setDataProvider(new ScrollingList.DataProvider() {
@Override
public int getElementCount() {
return moduleViews.size();
}
@Override
public void updateElement(final int index, @NotNull final Pane rowPane) {
final JobEntry entry = moduleViews.get(index).getJobEntry();
final Button button = rowPane.findPaneOfTypeByID(BUTTON_JOB, Button.class);
button.setText(new TranslationTextComponent(entry.getTranslationKey()));
if (entry.equals(selectedModule.getJobEntry())) {
button.disable();
} else {
button.enable();
}
}
});
}
use of com.minecolonies.api.colony.ICitizenDataView in project minecolonies by Minecolonies.
the class WindowAssignCitizen method onButtonClicked.
/**
* Called when any button has been clicked.
*
* @param button the clicked button.
*/
@Override
public void onButtonClicked(@NotNull final Button button) {
if (button.getID().equals(BUTTON_DONE)) {
final int row = citizenList.getListElementIndexByPane(button);
final ICitizenDataView data = citizens.get(row);
if (building instanceof LivingBuildingView) {
((LivingBuildingView) building).addResident(data.getId());
}
Network.getNetwork().sendToServer(new AssignUnassignMessage(this.building, true, data.getId(), null));
} else if (!button.getID().equals(BUTTON_CANCEL)) {
return;
}
if (colony.getTownHall() != null) {
building.openGui(false);
}
}
Aggregations