Search in sources :

Example 6 with StructureName

use of com.minecolonies.coremod.colony.StructureName in project minecolonies by Minecolonies.

the class WindowBuildTool method changeSchematic.

/*
     * ---------------- Miscellaneous ----------------
     */
/**
 * Changes the current structure.
 * Set to button position at that time
 */
private void changeSchematic() {
    final String sname;
    if (Settings.instance.isStaticSchematicMode()) {
        sname = Settings.instance.getStaticSchematicName();
    } else {
        sname = schematics.get(schematicsDropDownList.getSelectedIndex());
    }
    final StructureName structureName = new StructureName(sname);
    final Structure structure = new Structure(null, structureName.toString(), new PlacementSettings().setRotation(BlockUtils.getRotation(Settings.instance.getRotation())).setMirror(Settings.instance.getMirror()));
    final String md5 = Structures.getMD5(structureName.toString());
    if (structure.isTemplateMissing() || !structure.isCorrectMD5(md5)) {
        if (structure.isTemplateMissing()) {
            Log.getLogger().info("Template structure " + structureName + " missing");
        } else {
            Log.getLogger().info("structure " + structureName + " md5 error");
        }
        Log.getLogger().info("Request To Server for structure " + structureName);
        if (FMLCommonHandler.instance().getMinecraftServerInstance() == null) {
            MineColonies.getNetwork().sendToServer(new SchematicRequestMessage(structureName.toString()));
            return;
        } else {
            Log.getLogger().error("WindowBuildTool: Need to download schematic on a standalone client/server. This should never happen");
        }
    }
    Settings.instance.setStructureName(structureName.toString());
    Settings.instance.setActiveSchematic(structure);
    if (Settings.instance.getPosition() == null) {
        Settings.instance.setPosition(this.pos);
    }
}
Also used : SchematicRequestMessage(com.minecolonies.coremod.network.messages.SchematicRequestMessage) StructureName(com.minecolonies.coremod.colony.StructureName) Structure(com.minecolonies.structures.helpers.Structure) PlacementSettings(net.minecraft.world.gen.structure.template.PlacementSettings)

Example 7 with StructureName

use of com.minecolonies.coremod.colony.StructureName in project minecolonies by Minecolonies.

the class WindowBuildTool method setStructureName.

/**
 * Set the structure name.
 *
 * @param structureName name of the structure name
 *               Ex: schematics/wooden/Builder2
 */
private void setStructureName(final String structureName) {
    if (structureName != null) {
        final StructureName sn = new StructureName(structureName);
        final int sectionIndex = sections.indexOf(sn.getSection());
        if (sectionIndex != -1) {
            sectionsDropDownList.setSelectedIndex(sectionIndex);
            final int styleIndex = styles.indexOf(sn.getStyle());
            if (styleIndex != -1) {
                stylesDropDownList.setSelectedIndex(styleIndex);
                final int schematicIndex = schematics.indexOf(sn.toString());
                if (schematicIndex != -1) {
                    schematicsDropDownList.setSelectedIndex(schematicIndex);
                    return;
                }
            }
        }
    }
    // We did not find the structure, select the first of each
    sectionsDropDownList.setSelectedIndex(0);
    stylesDropDownList.setSelectedIndex(0);
    schematicsDropDownList.setSelectedIndex(0);
}
Also used : StructureName(com.minecolonies.coremod.colony.StructureName)

Example 8 with StructureName

use of com.minecolonies.coremod.colony.StructureName in project minecolonies by Minecolonies.

the class WindowBuildTool method updateSchematics.

/**
 * Update the list a available schematics.
 */
private void updateSchematics() {
    String schematic = "";
    if (schematicsDropDownList.getSelectedIndex() > -1 && schematicsDropDownList.getSelectedIndex() < schematics.size()) {
        schematic = schematics.get(schematicsDropDownList.getSelectedIndex());
    }
    final String currentSchematic = schematic.isEmpty() ? "" : (new StructureName(schematic)).getSchematic();
    final String section = sections.get(sectionsDropDownList.getSelectedIndex());
    final String style = styles.get(stylesDropDownList.getSelectedIndex());
    if (Settings.instance.isStaticSchematicMode()) {
        schematics = new ArrayList<>();
        schematics.add(staticSchematicName);
    } else {
        schematics = Structures.getSchematicsFor(section, style);
    }
    int newIndex = -1;
    for (int i = 0; i < schematics.size(); i++) {
        final StructureName sn = new StructureName(schematics.get(i));
        if (sn.getSchematic().equals(currentSchematic)) {
            newIndex = i;
            break;
        }
    }
    if (newIndex == -1) {
        newIndex = 0;
    }
    final boolean enabled;
    if (Settings.instance.isStaticSchematicMode()) {
        enabled = false;
    } else {
        enabled = schematics.size() > 1;
    }
    findPaneOfTypeByID(BUTTON_PREVIOUS_SCHEMATIC_ID, Button.class).setEnabled(enabled);
    findPaneOfTypeByID(DROPDOWN_SCHEMATIC_ID, DropDownList.class).setEnabled(enabled);
    findPaneOfTypeByID(BUTTON_NEXT_SCHEMATIC_ID, Button.class).setEnabled(enabled);
    schematicsDropDownList.setSelectedIndex(newIndex);
}
Also used : Button(com.minecolonies.blockout.controls.Button) StructureName(com.minecolonies.coremod.colony.StructureName) DropDownList(com.minecolonies.blockout.views.DropDownList)

Example 9 with StructureName

use of com.minecolonies.coremod.colony.StructureName in project minecolonies by Minecolonies.

the class WindowBuildTool method onDialogClosed.

/**
 * handle when a dialog is closed.
 *
 * @param dialog which is being closed.
 * @param buttonId is the id of the button used to close the dialog.
 */
public void onDialogClosed(final DialogDoneCancel dialog, final int buttonId) {
    if (dialog == confirmDeleteDialog && buttonId == DialogDoneCancel.DONE) {
        final StructureName structureName = new StructureName(schematics.get(schematicsDropDownList.getSelectedIndex()));
        if (Structures.SCHEMATICS_SCAN.equals(structureName.getPrefix()) && Structures.deleteScannedStructure(structureName)) {
            Structures.loadScannedStyleMaps();
            if (schematics.size() > 1) {
                schematicsDropDownList.selectNext();
                stylesDropDownList.setSelectedIndex(stylesDropDownList.getSelectedIndex());
            } else if (styles.size() > 1) {
                stylesDropDownList.selectNext();
            } else {
                sectionsDropDownList.selectNext();
            }
        }
    }
}
Also used : StructureName(com.minecolonies.coremod.colony.StructureName)

Example 10 with StructureName

use of com.minecolonies.coremod.colony.StructureName in project minecolonies by Minecolonies.

the class WindowBuildTool method initSchematicNavigation.

/**
 * Initialise the previous/next and drop down list for schematic.
 */
private void initSchematicNavigation() {
    registerButton(BUTTON_PREVIOUS_SCHEMATIC_ID, this::previousSchematic);
    registerButton(BUTTON_NEXT_SCHEMATIC_ID, this::nextSchematic);
    schematicsDropDownList = findPaneOfTypeByID(DROPDOWN_SCHEMATIC_ID, DropDownList.class);
    schematicsDropDownList.setHandler(this::onDropDownListChanged);
    schematicsDropDownList.setDataProvider(new DropDownList.DataProvider() {

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

        @Override
        public String getLabel(final int index) {
            final StructureName sn = new StructureName(schematics.get(index));
            return sn.getLocalizedName();
        }
    });
}
Also used : DropDownList(com.minecolonies.blockout.views.DropDownList) StructureName(com.minecolonies.coremod.colony.StructureName)

Aggregations

StructureName (com.minecolonies.coremod.colony.StructureName)16 DropDownList (com.minecolonies.blockout.views.DropDownList)2 BuildToolPasteMessage (com.minecolonies.coremod.network.messages.BuildToolPasteMessage)2 ArrayList (java.util.ArrayList)2 ItemStack (net.minecraft.item.ItemStack)2 Nullable (org.jetbrains.annotations.Nullable)2 Button (com.minecolonies.blockout.controls.Button)1 ScrollingList (com.minecolonies.blockout.views.ScrollingList)1 AbstractBuilding (com.minecolonies.coremod.colony.buildings.AbstractBuilding)1 WorkOrderBuild (com.minecolonies.coremod.colony.workorders.WorkOrderBuild)1 BuildToolPlaceMessage (com.minecolonies.coremod.network.messages.BuildToolPlaceMessage)1 SchematicRequestMessage (com.minecolonies.coremod.network.messages.SchematicRequestMessage)1 SchematicSaveMessage (com.minecolonies.coremod.network.messages.SchematicSaveMessage)1 StructureWrapper (com.minecolonies.coremod.util.StructureWrapper)1 Structure (com.minecolonies.structures.helpers.Structure)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1