Search in sources :

Example 11 with Button

use of com.ldtteam.blockout.controls.Button in project minecolonies by ldtteam.

the class WindowPermissionsPage method togglePermMode.

/**
 * Switch the view on the rank view (between permissions and settings)
 *
 * @param button the button clicked
 */
private void togglePermMode(Button button) {
    SwitchView permSwitch = findPaneOfTypeByID(TOWNHALL_PERM_MANAGEMENT, SwitchView.class);
    permSwitch.setView(permSwitch.getCurrentView() != null && permSwitch.getCurrentView().getID().equals(TOWNHALL_PERM_LIST) ? TOWNHALL_PERM_SETTINGS : TOWNHALL_PERM_LIST);
    if (permSwitch.getCurrentView().getID().equals(TOWNHALL_PERM_SETTINGS)) {
        DropDownList dropdown = findPaneOfTypeByID(TOWNHALL_RANK_TYPE_PICKER, DropDownList.class);
        dropdown.setDataProvider(new DropDownList.DataProvider() {

            @Override
            public int getElementCount() {
                return rankTypes.size();
            }

            @Override
            public String getLabel(final int i) {
                return LanguageHandler.format(rankTypes.get(i));
            }
        });
        dropdown.setHandler(this::changeRankMode);
        dropdown.setSelectedIndex(actionsRank.isColonyManager() ? 0 : (actionsRank.isHostile() ? 1 : 2));
        findPaneOfTypeByID(TOWNHALL_BUTTON_SUBSCRIBER, Button.class).setText(new TranslationTextComponent(actionsRank.isSubscriber() ? COM_MINECOLONIES_COREMOD_GUI_WORKERHUTS_RETRIEVE_ON : COM_MINECOLONIES_COREMOD_GUI_WORKERHUTS_RETRIEVE_OFF));
    }
}
Also used : Button(com.ldtteam.blockout.controls.Button) SwitchView(com.ldtteam.blockout.views.SwitchView) DropDownList(com.ldtteam.blockout.views.DropDownList) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent)

Example 12 with Button

use of com.ldtteam.blockout.controls.Button in project minecolonies by ldtteam.

the class WindowMineGuardModule method onOpened.

@Override
public void onOpened() {
    super.onOpened();
    guardsList = findPaneOfTypeByID(LIST_GUARDS, ScrollingList.class);
    guardsList.setDataProvider(new ScrollingList.DataProvider() {

        @Override
        public int getElementCount() {
            return guardsInfo.size();
        }

        @Override
        public void updateElement(final int i, final Pane pane) {
            final ICitizenDataView citizen = guardsInfo.get(i);
            if (citizen != null) {
                final IBuildingView building = buildingView.getColony().getBuilding(citizen.getWorkBuilding());
                if (building instanceof AbstractBuildingGuards.View) {
                    pane.findPaneOfTypeByID("guardName", Text.class).setText(citizen.getName());
                    final AbstractBuildingGuards.View guardbuilding = (AbstractBuildingGuards.View) building;
                    final Button button = pane.findPaneOfTypeByID("assignGuard", Button.class);
                    if (guardbuilding.getMinePos() == null) {
                        button.setText(new TranslationTextComponent("com.minecolonies.coremod.gui.hiring.buttonassign"));
                        if (assignedGuards >= getMaxGuards()) {
                            button.setEnabled(false);
                        } else {
                            button.setEnabled(true);
                        }
                    } else if (guardbuilding.getMinePos().equals(buildingView.getPosition())) {
                        button.setText(new TranslationTextComponent("com.minecolonies.coremod.gui.hiring.buttonunassign"));
                    } else {
                        button.setText(new TranslationTextComponent("com.minecolonies.coremod.gui.hiring.buttonassign"));
                        button.setEnabled(false);
                    }
                }
            } else {
                final Button button = pane.findPaneOfTypeByID("assignGuard", Button.class);
                button.setEnabled(false);
            }
        }
    });
}
Also used : AbstractBuildingGuards(com.minecolonies.coremod.colony.buildings.AbstractBuildingGuards) Button(com.ldtteam.blockout.controls.Button) IBuildingView(com.minecolonies.api.colony.buildings.views.IBuildingView) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) ICitizenDataView(com.minecolonies.api.colony.ICitizenDataView) ScrollingList(com.ldtteam.blockout.views.ScrollingList) Pane(com.ldtteam.blockout.Pane) IBuildingView(com.minecolonies.api.colony.buildings.views.IBuildingView) ICitizenDataView(com.minecolonies.api.colony.ICitizenDataView) SettingsModuleView(com.minecolonies.coremod.colony.buildings.moduleviews.SettingsModuleView)

Example 13 with Button

use of com.ldtteam.blockout.controls.Button in project minecolonies by Minecolonies.

the class WindowPermissionsPage method onOpened.

/**
 * Executed when <code>WindowTownHall</code> is opened. Does tasks like setting buttons.
 */
@Override
public void onOpened() {
    super.onOpened();
    fillUserList();
    fillFreeBlockList();
    fillRanks();
    fillPermissionList();
    PlayerEntity player = Minecraft.getInstance().player;
    Text label = findPaneOfTypeByID(TOWNHALL_PERMISSION_ERROR, Text.class);
    Button button = findPaneOfTypeByID(BUTTON_ADD_PLAYER, Button.class);
    if (building.getColony().getPermissions().hasPermission(player, Action.EDIT_PERMISSIONS)) {
        label.hide();
        button.setEnabled(true);
    } else {
        label.show();
        button.setEnabled(false);
    }
}
Also used : Button(com.ldtteam.blockout.controls.Button) Text(com.ldtteam.blockout.controls.Text) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Example 14 with Button

use of com.ldtteam.blockout.controls.Button in project minecolonies by Minecolonies.

the class WindowPermissionsPage method togglePermMode.

/**
 * Switch the view on the rank view (between permissions and settings)
 *
 * @param button the button clicked
 */
private void togglePermMode(Button button) {
    SwitchView permSwitch = findPaneOfTypeByID(TOWNHALL_PERM_MANAGEMENT, SwitchView.class);
    permSwitch.setView(permSwitch.getCurrentView() != null && permSwitch.getCurrentView().getID().equals(TOWNHALL_PERM_LIST) ? TOWNHALL_PERM_SETTINGS : TOWNHALL_PERM_LIST);
    if (permSwitch.getCurrentView().getID().equals(TOWNHALL_PERM_SETTINGS)) {
        DropDownList dropdown = findPaneOfTypeByID(TOWNHALL_RANK_TYPE_PICKER, DropDownList.class);
        dropdown.setDataProvider(new DropDownList.DataProvider() {

            @Override
            public int getElementCount() {
                return rankTypes.size();
            }

            @Override
            public String getLabel(final int i) {
                return LanguageHandler.format(rankTypes.get(i));
            }
        });
        dropdown.setHandler(this::changeRankMode);
        dropdown.setSelectedIndex(actionsRank.isColonyManager() ? 0 : (actionsRank.isHostile() ? 1 : 2));
        findPaneOfTypeByID(TOWNHALL_BUTTON_SUBSCRIBER, Button.class).setText(new TranslationTextComponent(actionsRank.isSubscriber() ? COM_MINECOLONIES_COREMOD_GUI_WORKERHUTS_RETRIEVE_ON : COM_MINECOLONIES_COREMOD_GUI_WORKERHUTS_RETRIEVE_OFF));
    }
}
Also used : Button(com.ldtteam.blockout.controls.Button) SwitchView(com.ldtteam.blockout.views.SwitchView) DropDownList(com.ldtteam.blockout.views.DropDownList) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent)

Example 15 with Button

use of com.ldtteam.blockout.controls.Button 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();
            }
        }
    });
}
Also used : Text(com.ldtteam.blockout.controls.Text) WorkerBuildingModuleView(com.minecolonies.coremod.colony.buildings.moduleviews.WorkerBuildingModuleView) Pane(com.ldtteam.blockout.Pane) JobEntry(com.minecolonies.api.colony.jobs.registry.JobEntry) Skill(com.minecolonies.api.entity.citizen.Skill) JobEntry(com.minecolonies.api.colony.jobs.registry.JobEntry) TextBuilder(com.ldtteam.blockout.controls.AbstractTextBuilder.TextBuilder) Button(com.ldtteam.blockout.controls.Button) Style(net.minecraft.util.text.Style) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) StringTextComponent(net.minecraft.util.text.StringTextComponent) ICitizenDataView(com.minecolonies.api.colony.ICitizenDataView) ScrollingList(com.ldtteam.blockout.views.ScrollingList)

Aggregations

Button (com.ldtteam.blockout.controls.Button)19 Text (com.ldtteam.blockout.controls.Text)9 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)9 Pane (com.ldtteam.blockout.Pane)6 ScrollingList (com.ldtteam.blockout.views.ScrollingList)5 ICitizenDataView (com.minecolonies.api.colony.ICitizenDataView)5 ItemIcon (com.ldtteam.blockout.controls.ItemIcon)4 SwitchView (com.ldtteam.blockout.views.SwitchView)4 BuildingBuilderResource (com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource)4 ItemStack (net.minecraft.item.ItemStack)4 StringTextComponent (net.minecraft.util.text.StringTextComponent)4 TextBuilder (com.ldtteam.blockout.controls.AbstractTextBuilder.TextBuilder)2 DropDownList (com.ldtteam.blockout.views.DropDownList)2 IBuildingView (com.minecolonies.api.colony.buildings.views.IBuildingView)2 JobEntry (com.minecolonies.api.colony.jobs.registry.JobEntry)2 Rank (com.minecolonies.api.colony.permissions.Rank)2 Skill (com.minecolonies.api.entity.citizen.Skill)2 AbstractBuildingGuards (com.minecolonies.coremod.colony.buildings.AbstractBuildingGuards)2 SettingsModuleView (com.minecolonies.coremod.colony.buildings.moduleviews.SettingsModuleView)2 WorkerBuildingModuleView (com.minecolonies.coremod.colony.buildings.moduleviews.WorkerBuildingModuleView)2