improved door & doorto handling

This commit is contained in:
musilto9 2020-05-23 22:20:14 +02:00
parent 39306b66f9
commit 7fb1ea5d34
4 changed files with 84 additions and 8 deletions

View File

@ -205,10 +205,12 @@ public class DetailedCellInfo extends JPanel {
info += getFieldInfo("map name", true);
}
else if (type.equals("DOOR")) {
info = getDoorInfo(type);
info += getTrueFalseInfo("vertical", "horizontal");
info += getFieldInfo("dialog", false);
}
else if (type.equals("DOORTO")) {
info = getDoorInfo(type);
info += getLockedInfo();
info += getTrueFalseInfo("vertical", "horizontal");
info += getFieldInfo("dialog", false);
@ -224,7 +226,6 @@ public class DetailedCellInfo extends JPanel {
info += getTrueFalseInfo("chest", "item");
}
editor.hideError();
System.out.println(info);
return info;
}
@ -328,6 +329,17 @@ public class DetailedCellInfo extends JPanel {
return info;
}
private String getDoorInfo(String type) {
String info = "";
if (j == 0 || editor.getCellArray()[i][j+1].split(",")[0].equals(type)) {
info = type.toLowerCase();
}
else {
info = type;
}
return info;
}
private String getLockedInfo() {
String info = "";
for (JTextField field : textFields) {
@ -340,6 +352,7 @@ public class DetailedCellInfo extends JPanel {
private void setInfo() {
String[] info = editor.getCellArray()[i][j].split(",");
System.out.println(editor.getCellArray()[i][j]);
String type = info[0];
if (type.equals("BLOCK") || type.equals("block")) {
setTrueFalseInfo(type);
@ -359,11 +372,11 @@ public class DetailedCellInfo extends JPanel {
setDirectionInfo(info[2]);
setFieldInfo("map name", info[3]);
}
else if (type.equals("DOOR")) {
else if (type.equals("DOOR") || type.equals("door")) {
setTrueFalseInfo(info[1]);
if (info.length > 2) setFieldInfo("dialog", info[2]);
}
else if (type.equals("DOORTO")) {
else if (type.equals("DOORTO") || type.equals("doorto")) {
if (info[1].equals("locked")) {
setTrueFalseInfo(info[2]);
setFieldInfo("dialog", info[3]);

View File

@ -60,7 +60,8 @@ public class EditorSaveManager {
for (int i = 0; i < editor.getMapWidth(); i++) {
for (int j = 0; j < editor.getMapHeight(); j++) {
if (j != 0) info += " ";
info += set[i][j];
if (set[j][i].split(",")[0].contains("door")) info += "EMPTY";
else info += set[j][i];
}
if (i != editor.getMapWidth() -1) info += System.lineSeparator();
}

View File

@ -222,7 +222,8 @@ public class InfoManager {
saveInfo.addActionListener(e -> {
String value = detailedCellInfo.getCellInfo(String.valueOf(cellType.getSelectedItem()));
if (value == null) return;
editor.getCellArray()[x][y] = value;
if (value.contains("DOOR") || value.contains("door")) saveDoor(value, x, y);
else editor.getCellArray()[x][y] = value;
editor.getMapLayers().repaintCellSet();
info.removeAll();
info.revalidate();
@ -242,4 +243,21 @@ public class InfoManager {
info.add(openCellMap);
info.add(saveInfo);
}
private void saveDoor(String value, int x, int y) {
System.out.println(value + y);
if (value.split(",")[0].contains("DOOR") && y == 0) {
value = value.substring(0, value.indexOf(",")).toLowerCase() + value.substring(value.indexOf(","));
}
if (value.split(",")[0].contains("DOOR")) {
editor.getCellArray()[x][y] = value;
value = value.substring(0, value.indexOf(",")).toLowerCase() + value.substring(value.indexOf(","));
editor.getCellArray()[x][y-1] = value;
}
else if (value.split(",")[0].contains("door")) {
editor.getCellArray()[x][y] = value;
value = value.substring(0, value.indexOf(",")).toUpperCase() + value.substring(value.indexOf(","));
editor.getCellArray()[x][y+1] = value;
}
}
}

View File

@ -169,11 +169,12 @@ public class MapLayersManager {
private void setCellIcon(JLabel cell, int i, int j) {
String value;
String[] info = editor.getCellArray()[i][j].split(",");
if (info[0].equals(info[0].toLowerCase())) {
if (info[0].toUpperCase().equals("DOOR") || info[0].toUpperCase().equals("DOORTO")) {
setDoorImage(cell, info);
return;
}
if (info[0].toUpperCase().equals("DOOR") || info[0].toUpperCase().equals("DOORTO")) {
value = "DOOR/DOORTO";
if (info[0].equals(info[0].toLowerCase())) {
return;
}
else {
value = info[0].toUpperCase();
@ -212,6 +213,49 @@ public class MapLayersManager {
return image;
}
private void setDoorImage(JLabel cell, String[] info) {
if (editor.getCellMap().get("DOOR/DOORTO") == 0) {
cell.setIcon(new ImageIcon(imagesOfTiles.get(editor.getCellMap().get("DOOR/DOORTO")).getScaledInstance(50, 50, Image.SCALE_DEFAULT)));
return;
}
if (info[0].equals("DOOR") || info[0].equals("door")) {
if (info[1].equals("true")) {
if (info[0].equals("door")) {
cell.setIcon(new ImageIcon(imagesOfTiles.get(editor.getCellMap().get("DOOR/DOORTO") - 1).getScaledInstance(50, 50, Image.SCALE_DEFAULT)));
}
else {
cell.setIcon(new ImageIcon(imagesOfTiles.get(editor.getCellMap().get("DOOR/DOORTO")).getScaledInstance(50, 50, Image.SCALE_DEFAULT)));
}
}
else if (info[1].equals("false")) {
if (info[0].equals("door")) {
cell.setIcon(new ImageIcon(imagesOfTiles.get(editor.getCellMap().get("DOOR/DOORTO") + 3).getScaledInstance(50, 50, Image.SCALE_DEFAULT)));
}
else {
cell.setIcon(new ImageIcon(imagesOfTiles.get(editor.getCellMap().get("DOOR/DOORTO") + 4).getScaledInstance(50, 50, Image.SCALE_DEFAULT)));
}
}
}
if (info[0].equals("DOORTO") || info[0].equals("doorto")) {
if (info[1].equals("true") || info[2].equals("true")) {
if (info[0].equals("doorto")) {
cell.setIcon(new ImageIcon(imagesOfTiles.get(editor.getCellMap().get("DOOR/DOORTO") - 1).getScaledInstance(50, 50, Image.SCALE_DEFAULT)));
}
else {
cell.setIcon(new ImageIcon(imagesOfTiles.get(editor.getCellMap().get("DOOR/DOORTO")).getScaledInstance(50, 50, Image.SCALE_DEFAULT)));
}
}
else if (info[1].equals("false") || info[2].equals("false")) {
if (info[0].equals("doorto")) {
cell.setIcon(new ImageIcon(imagesOfTiles.get(editor.getCellMap().get("DOOR/DOORTO") + 3).getScaledInstance(50, 50, Image.SCALE_DEFAULT)));
}
else {
cell.setIcon(new ImageIcon(imagesOfTiles.get(editor.getCellMap().get("DOOR/DOORTO") + 4).getScaledInstance(50, 50, Image.SCALE_DEFAULT)));
}
}
}
}
public JLayeredPane getMapLayers() {
return mapLayers;
}