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