Search in sources :

Example 1 with MixedMaterialTableModel

use of org.pepsoft.worldpainter.MixedMaterialTableModel in project WorldPainter by Captain-Chaos.

the class CustomMaterialDialog method getNewMaterial.

private MixedMaterial getNewMaterial() {
    switch(jTabbedPane1.getSelectedIndex()) {
        case 0:
            // Simple
            return new MixedMaterial(fieldName.getText(), new Row(Material.get(comboBoxSimpleBlockID.getSelectedIndex(), (Integer) spinnerSimpleDataValue.getValue()), 1000, 1.0f), biome, checkBoxColour.isSelected() ? selectedColour : null);
        case 1:
            // Complex
            MixedMaterialTableModel tableModelClone = tableModel.clone();
            tableModelClone.normalise();
            Row[] rows = tableModelClone.getRows();
            if (rows.length == 1) {
                return new MixedMaterial(fieldName.getText(), rows[0], biome, checkBoxColour.isSelected() ? selectedColour : null);
            } else if (radioButtonNoise.isSelected()) {
                return new MixedMaterial(fieldName.getText(), rows, biome, checkBoxColour.isSelected() ? selectedColour : null);
            } else if (radioButtonBlobs.isSelected()) {
                return new MixedMaterial(fieldName.getText(), rows, biome, checkBoxColour.isSelected() ? selectedColour : null, ((Integer) spinnerScale.getValue()) / 100.0f);
            } else {
                NoiseSettings variation = noiseSettingsEditorLayeredVariation.getNoiseSettings().clone();
                boolean repeat = checkBoxLayeredRepeat.isSelected();
                return new MixedMaterial(fieldName.getText(), rows, biome, checkBoxColour.isSelected() ? selectedColour : null, (variation.getRange() != 0) ? variation : null, repeat ? Math.tan((-(Integer) spinnerLayeredXAngle.getValue()) / DEGREES_TO_RADIANS) : 0.0, repeat ? Math.tan((-(Integer) spinnerLayeredYAngle.getValue()) / DEGREES_TO_RADIANS) : 0.0, repeat);
            }
        default:
            throw new InternalError();
    }
}
Also used : MixedMaterialTableModel(org.pepsoft.worldpainter.MixedMaterialTableModel) Row(org.pepsoft.worldpainter.MixedMaterial.Row)

Example 2 with MixedMaterialTableModel

use of org.pepsoft.worldpainter.MixedMaterialTableModel in project WorldPainter by Captain-Chaos.

the class CustomMaterialDialog method init.

private void init(MixedMaterial mixedMaterial) {
    programmaticChange = true;
    try {
        biome = mixedMaterial.getBiome();
        fieldName.setText(mixedMaterial.getName());
        tableModel = new MixedMaterialTableModel(mixedMaterial);
        tableModel.addTableModelListener(e -> {
            if ((!checkBoxColour.isSelected()) && isExtendedBlockIds()) {
                checkBoxColour.setSelected(true);
            }
            setControlStates();
            updateName();
            schedulePreviewUpdate();
        });
        switch(mixedMaterial.getMode()) {
            case SIMPLE:
                jTabbedPane1.setSelectedIndex(0);
                Material simpleMaterial = mixedMaterial.getRows()[0].material;
                comboBoxSimpleBlockID.setSelectedIndex(simpleMaterial.blockType);
                spinnerSimpleDataValue.setValue(simpleMaterial.data);
                break;
            case NOISE:
                jTabbedPane1.setSelectedIndex(1);
                radioButtonNoise.setSelected(true);
                break;
            case BLOBS:
                jTabbedPane1.setSelectedIndex(1);
                radioButtonBlobs.setSelected(true);
                spinnerScale.setValue((int) (mixedMaterial.getScale() * 100 + 0.5f));
                break;
            case LAYERED:
                jTabbedPane1.setSelectedIndex(1);
                radioButtonLayered.setSelected(true);
                checkBoxLayeredRepeat.setSelected(mixedMaterial.isRepeat());
                if (mixedMaterial.getVariation() != null) {
                    noiseSettingsEditorLayeredVariation.setNoiseSettings(mixedMaterial.getVariation());
                }
                spinnerLayeredXAngle.setValue(-(int) Math.round(Math.atan(mixedMaterial.getLayerXSlope()) * DEGREES_TO_RADIANS));
                spinnerLayeredYAngle.setValue(-(int) Math.round(Math.atan(mixedMaterial.getLayerYSlope()) * DEGREES_TO_RADIANS));
                break;
        }
        tableMaterialRows.setModel(tableModel);
        previousCalculatedName = createName();
        selectedColour = (mixedMaterial.getColour() != null) ? mixedMaterial.getColour() : Color.ORANGE.getRGB();
        checkBoxColour.setSelected(mixedMaterial.getColour() != null);
        setControlStates();
        updatePreview();
        configureTable();
    } finally {
        programmaticChange = false;
    }
}
Also used : MixedMaterialTableModel(org.pepsoft.worldpainter.MixedMaterialTableModel) Material(org.pepsoft.minecraft.Material)

Aggregations

MixedMaterialTableModel (org.pepsoft.worldpainter.MixedMaterialTableModel)2 Material (org.pepsoft.minecraft.Material)1 Row (org.pepsoft.worldpainter.MixedMaterial.Row)1