fixed and improved cell info menu
This commit is contained in:
parent
cbb077e429
commit
481ebf5e5b
@ -41,7 +41,7 @@ public class Game extends JFrame {
|
||||
battle = new WindowOfBattle(this);
|
||||
|
||||
//tohle spustí na začátku menu
|
||||
add(menu);
|
||||
// add(menu);
|
||||
|
||||
//tohle spustí na začátku hru
|
||||
// add(freeMove);
|
||||
@ -52,7 +52,7 @@ public class Game extends JFrame {
|
||||
// battle.startBattle();
|
||||
|
||||
//Tohle spustí na začátku tileset overview
|
||||
// new LevelEditor();
|
||||
new LevelEditor();
|
||||
|
||||
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||
setUndecorated(true);
|
||||
|
||||
@ -0,0 +1,153 @@
|
||||
package ruscz.game.gameOfProd.LevelEditor;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.LinkedList;
|
||||
|
||||
public class CellSetConfig {
|
||||
|
||||
private LevelEditor editor;
|
||||
private JLayeredPane view;
|
||||
private JScrollPane scrollInfo;
|
||||
|
||||
public CellSetConfig(LevelEditor editor, JScrollPane scrollInfo) {
|
||||
this.editor = editor;
|
||||
this.view = editor.getView();
|
||||
this.scrollInfo = scrollInfo;
|
||||
}
|
||||
|
||||
public void displayCellSetConfig() {
|
||||
int offset = 0;
|
||||
String[] array = {"BLOCK", "INTER", "TRIGGER", "MOVETO", "DOOR/DOORTO", "CHEST"}; //EMPTY is missing on purpose, DOOR & DOORTO are combined on purpose
|
||||
LinkedList<JTextField> numFields = new LinkedList<>();
|
||||
|
||||
JPanel infoPanel = new JPanel();
|
||||
infoPanel.setPreferredSize(new Dimension(250, array.length * 160 + 50));
|
||||
infoPanel.setLayout(null);
|
||||
|
||||
if (scrollInfo != null) {
|
||||
scrollInfo.removeAll();
|
||||
view.remove(scrollInfo);
|
||||
scrollInfo = null;
|
||||
}
|
||||
scrollInfo = new JScrollPane(infoPanel);
|
||||
scrollInfo.setBounds(20, 200, 270, 730);
|
||||
scrollInfo.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
|
||||
scrollInfo.setWheelScrollingEnabled(true);
|
||||
scrollInfo.getVerticalScrollBar().setUnitIncrement(10);
|
||||
|
||||
for (String name : array) {
|
||||
JLabel nameLabel = nameLabel(name, offset);
|
||||
JLabel iconLabel = iconLabel(name, offset);
|
||||
JLabel valueLabel = valueLabel(offset);
|
||||
JTextField numField = numField(name, offset);
|
||||
numFields.add(numField);
|
||||
JButton importButton = importButton(iconLabel, numField, offset);
|
||||
JButton selectButton = selectButton(importButton, offset);
|
||||
JLabel dividerLabel = dividerLabel(offset);
|
||||
|
||||
infoPanel.add(nameLabel);
|
||||
infoPanel.add(iconLabel);
|
||||
infoPanel.add(valueLabel);
|
||||
infoPanel.add(numField);
|
||||
infoPanel.add(importButton);
|
||||
infoPanel.add(selectButton);
|
||||
infoPanel.add(dividerLabel);
|
||||
|
||||
offset += 160;
|
||||
}
|
||||
|
||||
JButton saveInfo = new JButton("Save CellMap info");
|
||||
saveInfo.setBounds(50, offset, 150, 30);
|
||||
saveInfo.addActionListener(e -> {
|
||||
for (JTextField field : numFields) {
|
||||
try {
|
||||
editor.getCellMap().replace(field.getName(), Integer.parseInt(field.getText()));
|
||||
}
|
||||
catch (NumberFormatException ex) {
|
||||
editor.displayError("Inner Value for " + field.getName() + " is not an Integer.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
editor.hideError();
|
||||
editor.getMapLayers().repaintCellSet();
|
||||
scrollInfo.removeAll();
|
||||
scrollInfo.revalidate();
|
||||
view.remove(scrollInfo);
|
||||
view.revalidate();
|
||||
view.repaint();
|
||||
});
|
||||
|
||||
infoPanel.add(saveInfo);
|
||||
|
||||
scrollInfo.revalidate();
|
||||
scrollInfo.requestFocus();
|
||||
view.add(scrollInfo);
|
||||
}
|
||||
|
||||
private JLabel nameLabel(String name, int offset) {
|
||||
JLabel label = new JLabel("<html><div style='width: 250; text-align:center; font-size: 16'>" + name + "</div></html>");
|
||||
label.setBounds(0, offset, 250, 20);
|
||||
return label;
|
||||
}
|
||||
|
||||
private JLabel iconLabel(String name, int offset) {
|
||||
JLabel label = new JLabel();
|
||||
label.setBounds(0, offset + 40, 50, 50);
|
||||
if (editor.getImagesOfTiles() != null && editor.getImagesOfTiles().size() > 0)
|
||||
label.setIcon(new ImageIcon(editor.getImagesOfTiles().get(editor.getCellMap().get(name)).getScaledInstance(50, 50, Image.SCALE_DEFAULT)));
|
||||
label.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
|
||||
return label;
|
||||
}
|
||||
|
||||
private JLabel valueLabel(int offset) {
|
||||
JLabel label = new JLabel("Inner Value:");
|
||||
label.setBounds(80, offset + 40, 100, 30);
|
||||
return label;
|
||||
}
|
||||
|
||||
private JTextField numField(String name, int offset) {
|
||||
JTextField field = new JTextField(String.valueOf(editor.getCellMap().get(name)));
|
||||
field.setName(name);
|
||||
field.setBounds(160, offset + 40, 50, 30);
|
||||
return field;
|
||||
}
|
||||
|
||||
private JButton importButton(JLabel iconLabel, JTextField tileNum, int offset) {
|
||||
JButton button = new JButton("Import selected tile");
|
||||
button.setVisible(false);
|
||||
button.setBounds(100, offset + 100, 150, 30);
|
||||
button.addActionListener(e -> {
|
||||
if (!editor.getOverview().getInfo().getText().equals("")) {
|
||||
iconLabel.setIcon(editor.getOverview().getInfo().getIcon());
|
||||
tileNum.setText(editor.getOverview().getInfo().getText().replace("<html><span color='black'>", "").replace("</span></html>", ""));
|
||||
}
|
||||
else {
|
||||
editor.getOverview().setState(Frame.NORMAL);
|
||||
editor.getOverview().toFront();
|
||||
}
|
||||
});
|
||||
return button;
|
||||
}
|
||||
|
||||
private JButton selectButton(JButton importButton, int offset) {
|
||||
JButton button = new JButton("Select tile");
|
||||
button.setBounds(0, offset + 100, 90, 30);
|
||||
button.addActionListener(e -> {
|
||||
if (editor.getOverview() == null) editor.setOverview(new TilesetOverview());
|
||||
else {
|
||||
editor.getOverview().setState(Frame.NORMAL);
|
||||
editor.getOverview().toFront();
|
||||
}
|
||||
importButton.setVisible(true);
|
||||
});
|
||||
return button;
|
||||
}
|
||||
|
||||
private JLabel dividerLabel(int offset) {
|
||||
JLabel label = new JLabel();
|
||||
label.setBounds(0, offset + 140, 255, 1);
|
||||
label.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
|
||||
return label;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,133 @@
|
||||
package ruscz.game.gameOfProd.LevelEditor;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.LinkedList;
|
||||
|
||||
public class DetailedCellInfo extends JPanel {
|
||||
|
||||
private LinkedList<JRadioButton> radioButtons;
|
||||
private LevelEditor editor;
|
||||
private int i;
|
||||
private int j;
|
||||
|
||||
public DetailedCellInfo(LevelEditor editor, int i, int j) {
|
||||
this.radioButtons = new LinkedList<>();
|
||||
this.editor = editor;
|
||||
this.i = i;
|
||||
this.j = j;
|
||||
}
|
||||
|
||||
public void displayDetailedCellInfo(String type) {
|
||||
removeAll();
|
||||
setVisible(false);
|
||||
if (type.equals("BLOCK")) {
|
||||
visibleInfo();
|
||||
upperLowerInfo();
|
||||
}
|
||||
setRadioButtons();
|
||||
}
|
||||
|
||||
private void visibleInfo() {
|
||||
JLabel label = new JLabel("<html><div style='text-align: center; width: 260'>Is Visible</div></html>");
|
||||
label.setBounds(0, 0, 260, 20);
|
||||
|
||||
JRadioButton yes = new JRadioButton("Yes");
|
||||
yes.setBounds(75, 30, 70, 20);
|
||||
yes.setSelected(true);
|
||||
yes.setName("visible");
|
||||
radioButtons.add(yes);
|
||||
|
||||
JRadioButton no = new JRadioButton("No");
|
||||
no.setBounds(150, 30, 70, 20);
|
||||
no.setName("hidden");
|
||||
radioButtons.add(no);
|
||||
|
||||
ButtonGroup group = new ButtonGroup();
|
||||
group.add(yes);
|
||||
group.add(no);
|
||||
|
||||
add(label);
|
||||
add(yes);
|
||||
add(no);
|
||||
|
||||
repaint();
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
private void upperLowerInfo() {
|
||||
JLabel label = new JLabel("<html><div style='text-align: center; width: 260'>Half Block</div></html>");
|
||||
label.setBounds(0, 100, 260, 20);
|
||||
|
||||
JRadioButton up = new JRadioButton("Upper");
|
||||
up.setBounds(0, 130, 70, 20);
|
||||
up.setName("up");
|
||||
add(up);
|
||||
|
||||
JRadioButton low = new JRadioButton("Lower");
|
||||
low.setBounds(100, 130, 70, 20);
|
||||
low.setName("low");
|
||||
add(low);
|
||||
|
||||
JRadioButton none = new JRadioButton("None");
|
||||
none.setBounds(200, 130, 70, 20);
|
||||
none.setSelected(true);
|
||||
none.setName("full");
|
||||
add(none);
|
||||
|
||||
ButtonGroup group = new ButtonGroup();
|
||||
group.add(up);
|
||||
group.add(low);
|
||||
group.add(none);
|
||||
|
||||
radioButtons.add(up);
|
||||
radioButtons.add(low);
|
||||
|
||||
add(label);
|
||||
add(up);
|
||||
add(low);
|
||||
add(none);
|
||||
|
||||
repaint();
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
public String getCellInfo(String type) {
|
||||
String info = "";
|
||||
for (JRadioButton button : radioButtons) {
|
||||
if (button.getName().equals("visible") && button.isSelected()) {
|
||||
info = type.toUpperCase();
|
||||
}
|
||||
else if (button.getName().equals("hidden") && button.isSelected()) {
|
||||
info = type.toLowerCase();
|
||||
break;
|
||||
}
|
||||
else if (button.getName().equals("up") && button.isSelected()) {
|
||||
info += ",u";
|
||||
}
|
||||
else if (button.getName().equals("low") && button.isSelected()) {
|
||||
info += ",d";
|
||||
}
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
private void setRadioButtons() {
|
||||
String[] info = editor.getCellArray()[i][j].split(",");
|
||||
if (info[0].equals(info[0].toLowerCase())) {
|
||||
for (JRadioButton btn : radioButtons) {
|
||||
if (btn.getName().equals("hidden")) btn.setSelected(true);
|
||||
}
|
||||
}
|
||||
if (info.length > 1) {
|
||||
if (info[1].equals("u")) {
|
||||
for (JRadioButton btn : radioButtons) {
|
||||
if (btn.getName().equals("up")) btn.setSelected(true);
|
||||
}
|
||||
} else if (info[1].equals("d")) {
|
||||
for (JRadioButton btn : radioButtons) {
|
||||
if (btn.getName().equals("low")) btn.setSelected(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -5,7 +5,6 @@ import java.awt.*;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
|
||||
public class InfoManager {
|
||||
|
||||
@ -13,8 +12,7 @@ public class InfoManager {
|
||||
private JPanel info;
|
||||
private JScrollPane scrollInfo;
|
||||
private JLayeredPane view;
|
||||
|
||||
private LinkedList<JRadioButton> radioButtons;
|
||||
private DetailedCellInfo detailedCellInfo;
|
||||
|
||||
public InfoManager(LevelEditor editor) {
|
||||
this.editor = editor;
|
||||
@ -37,6 +35,11 @@ public class InfoManager {
|
||||
info.setBounds(20, 200, 260, 730);
|
||||
info.setLayout(null);
|
||||
|
||||
detailedCellInfo = new DetailedCellInfo(editor, x, y);
|
||||
detailedCellInfo.setBounds(20, 270, 260, 280);
|
||||
detailedCellInfo.setLayout(null);
|
||||
detailedCellInfo.setVisible(false);
|
||||
|
||||
switch (layer) {
|
||||
case "object":
|
||||
displayObjectAndTileInfo(label, x, y, true);
|
||||
@ -49,7 +52,8 @@ public class InfoManager {
|
||||
break;
|
||||
}
|
||||
|
||||
view.add(info);
|
||||
view.add(detailedCellInfo, JLayeredPane.POPUP_LAYER);
|
||||
view.add(info, JLayeredPane.MODAL_LAYER);
|
||||
view.revalidate();
|
||||
}
|
||||
|
||||
@ -161,7 +165,6 @@ public class InfoManager {
|
||||
|
||||
private void displayCellInfo(JLabel label, int x, int y) {
|
||||
String[] array = {"EMPTY", "BLOCK", "INTER", "TRIGGER", "MOVETO", "DOOR", "DOORTO", "CHEST"};
|
||||
radioButtons = new LinkedList<>();
|
||||
|
||||
JLabel infoLabel = new JLabel();
|
||||
infoLabel.setBounds(0, 0, 50, 50);
|
||||
@ -177,16 +180,15 @@ public class InfoManager {
|
||||
|
||||
JComboBox cellType = new JComboBox(array);
|
||||
cellType.setBounds(170, 10, 90, 30);
|
||||
String[] cellname = label.getName().split(",");
|
||||
cellType.setSelectedItem(cellname[0]);
|
||||
cellType.setSelectedItem(editor.getCellArray()[x][y].split(",")[0].toUpperCase());
|
||||
cellType.addActionListener(e -> {
|
||||
if (editor.getImagesOfTiles() != null && editor.getImagesOfTiles().size() > 0) {
|
||||
if (editor.getImagesOfTiles() != null && editor.getImagesOfTiles().size() > 0 && !cellType.getSelectedItem().equals("EMPTY")) {
|
||||
String value;
|
||||
if (cellType.getSelectedItem().equals("DOOR") || cellType.getSelectedItem().equals("DOORTO")) value = "DOOR/DOORTO";
|
||||
else value = String.valueOf(cellType.getSelectedItem());
|
||||
infoLabel.setIcon(new ImageIcon(editor.getImagesOfTiles().get(editor.getCellMap().get(value)).getScaledInstance(50, 50, Image.SCALE_DEFAULT)));
|
||||
}
|
||||
displayDetailedCellInfo(String.valueOf(cellType.getSelectedItem()), openCellMap, saveInfo);
|
||||
detailedCellInfo.displayDetailedCellInfo(String.valueOf(cellType.getSelectedItem()));
|
||||
for (Component component : info.getComponents()) {
|
||||
component.requestFocus();
|
||||
}
|
||||
@ -204,204 +206,38 @@ public class InfoManager {
|
||||
@Override public void mouseExited(MouseEvent e) {}
|
||||
});
|
||||
|
||||
openCellMap.setBounds(30, 70, 200, 30);
|
||||
openCellMap.setBounds(30, 580, 200, 30);
|
||||
openCellMap.addActionListener(e -> {
|
||||
info.removeAll();
|
||||
info.revalidate();
|
||||
detailedCellInfo.removeAll();
|
||||
detailedCellInfo.revalidate();
|
||||
view.remove(info);
|
||||
view.remove(detailedCellInfo);
|
||||
view.revalidate();
|
||||
displayCellSetConfig();
|
||||
new CellSetConfig(editor, scrollInfo).displayCellSetConfig();
|
||||
});
|
||||
|
||||
saveInfo.setBounds(50, 120, 150, 30);
|
||||
saveInfo.setBounds(50, 630, 150, 30);
|
||||
saveInfo.addActionListener(e -> {
|
||||
editor.getCellArray()[x][y] = String.valueOf(cellType.getSelectedItem());
|
||||
editor.getCellArray()[x][y] = detailedCellInfo.getCellInfo(String.valueOf(cellType.getSelectedItem()));
|
||||
editor.getMapLayers().repaintCellSet();
|
||||
info.removeAll();
|
||||
info.revalidate();
|
||||
detailedCellInfo.removeAll();
|
||||
detailedCellInfo.revalidate();
|
||||
view.remove(info);
|
||||
view.remove(detailedCellInfo);
|
||||
view.revalidate();
|
||||
view.repaint();
|
||||
});
|
||||
|
||||
detailedCellInfo.displayDetailedCellInfo(String.valueOf(cellType.getSelectedItem()));
|
||||
|
||||
info.add(infoLabel);
|
||||
info.add(valueLabel);
|
||||
info.add(cellType);
|
||||
info.add(openCellMap);
|
||||
info.add(saveInfo);
|
||||
}
|
||||
|
||||
private void displayDetailedCellInfo(String type, JButton open, JButton save) {
|
||||
if (type.equals("BLOCK")) upperLowerInfo(open, save);
|
||||
}
|
||||
|
||||
private void upperLowerInfo(JButton open, JButton save) {
|
||||
JLabel label = new JLabel("<html><div style='text-align: center; width: 260'>Half Block</div></html>");
|
||||
label.setBounds(0, 120, 260, 20);
|
||||
|
||||
JRadioButton up = new JRadioButton("Upper");
|
||||
up.setBounds(0, 150, 70, 20);
|
||||
up.setName("up");
|
||||
radioButtons.add(up);
|
||||
|
||||
JRadioButton low = new JRadioButton("Lower");
|
||||
low.setBounds(100, 150, 70, 20);
|
||||
low.setName("low");
|
||||
radioButtons.add(low);
|
||||
|
||||
JRadioButton none = new JRadioButton("None");
|
||||
none.setBounds(200, 150, 70, 20);
|
||||
none.setSelected(true);
|
||||
none.setName("none");
|
||||
radioButtons.add(none);
|
||||
|
||||
ButtonGroup group = new ButtonGroup();
|
||||
group.add(up);
|
||||
group.add(low);
|
||||
group.add(none);
|
||||
|
||||
open.setLocation(open.getX(), open.getY() + 110);
|
||||
|
||||
save.setLocation(save.getX(), save.getY() + 110);
|
||||
|
||||
info.add(label);
|
||||
info.add(up);
|
||||
info.add(low);
|
||||
info.add(none);
|
||||
}
|
||||
|
||||
private void displayCellSetConfig() {
|
||||
int offset = 0;
|
||||
String[] array = {"BLOCK", "INTER", "TRIGGER", "MOVETO", "DOOR/DOORTO", "CHEST"}; //EMPTY is missing on purpose, DOOR & DOORTO are combined on purpose
|
||||
LinkedList<JTextField> numFields = new LinkedList<>();
|
||||
|
||||
JPanel infoPanel = new JPanel();
|
||||
infoPanel.setPreferredSize(new Dimension(250, array.length * 160 + 50));
|
||||
infoPanel.setLayout(null);
|
||||
|
||||
if (scrollInfo != null) {
|
||||
scrollInfo.removeAll();
|
||||
view.remove(scrollInfo);
|
||||
scrollInfo = null;
|
||||
}
|
||||
scrollInfo = new JScrollPane(infoPanel);
|
||||
scrollInfo.setBounds(20, 200, 270, 730);
|
||||
scrollInfo.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
|
||||
scrollInfo.setWheelScrollingEnabled(true);
|
||||
scrollInfo.getVerticalScrollBar().setUnitIncrement(10);
|
||||
|
||||
for (String name : array) {
|
||||
JLabel nameLabel = nameLabel(name, offset);
|
||||
JLabel iconLabel = iconLabel(name, offset);
|
||||
JLabel valueLabel = valueLabel(offset);
|
||||
JTextField numField = numField(name, offset);
|
||||
numFields.add(numField);
|
||||
JButton importButton = importButton(iconLabel, numField, offset);
|
||||
JButton selectButton = selectButton(importButton, offset);
|
||||
JLabel dividerLabel = dividerLabel(offset);
|
||||
|
||||
infoPanel.add(nameLabel);
|
||||
infoPanel.add(iconLabel);
|
||||
infoPanel.add(valueLabel);
|
||||
infoPanel.add(numField);
|
||||
infoPanel.add(importButton);
|
||||
infoPanel.add(selectButton);
|
||||
infoPanel.add(dividerLabel);
|
||||
|
||||
offset += 160;
|
||||
}
|
||||
|
||||
JButton saveInfo = new JButton("Save CellMap info");
|
||||
saveInfo.setBounds(50, offset, 150, 30);
|
||||
saveInfo.addActionListener(e -> {
|
||||
for (JTextField field : numFields) {
|
||||
try {
|
||||
editor.getCellMap().replace(field.getName(), Integer.parseInt(field.getText()));
|
||||
}
|
||||
catch (NumberFormatException ex) {
|
||||
editor.displayError("Inner Value for " + field.getName() + " is not an Integer.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
editor.hideError();
|
||||
editor.getMapLayers().repaintCellSet();
|
||||
scrollInfo.removeAll();
|
||||
scrollInfo.revalidate();
|
||||
view.remove(scrollInfo);
|
||||
view.revalidate();
|
||||
view.repaint();
|
||||
});
|
||||
|
||||
infoPanel.add(saveInfo);
|
||||
|
||||
scrollInfo.revalidate();
|
||||
scrollInfo.requestFocus();
|
||||
view.add(scrollInfo);
|
||||
}
|
||||
|
||||
private JLabel nameLabel(String name, int offset) {
|
||||
JLabel label = new JLabel("<html><div style='width: 250; text-align:center; font-size: 16'>" + name + "</div></html>");
|
||||
label.setBounds(0, offset, 250, 20);
|
||||
return label;
|
||||
}
|
||||
|
||||
private JLabel iconLabel(String name, int offset) {
|
||||
JLabel label = new JLabel();
|
||||
label.setBounds(0, offset + 40, 50, 50);
|
||||
if (editor.getImagesOfTiles() != null && editor.getImagesOfTiles().size() > 0)
|
||||
label.setIcon(new ImageIcon(editor.getImagesOfTiles().get(editor.getCellMap().get(name)).getScaledInstance(50, 50, Image.SCALE_DEFAULT)));
|
||||
label.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
|
||||
return label;
|
||||
}
|
||||
|
||||
private JLabel valueLabel(int offset) {
|
||||
JLabel label = new JLabel("Inner Value:");
|
||||
label.setBounds(80, offset + 40, 100, 30);
|
||||
return label;
|
||||
}
|
||||
|
||||
private JTextField numField(String name, int offset) {
|
||||
JTextField field = new JTextField(String.valueOf(editor.getCellMap().get(name)));
|
||||
field.setName(name);
|
||||
field.setBounds(160, offset + 40, 50, 30);
|
||||
return field;
|
||||
}
|
||||
|
||||
private JButton importButton(JLabel iconLabel, JTextField tileNum, int offset) {
|
||||
JButton button = new JButton("Import selected tile");
|
||||
button.setVisible(false);
|
||||
button.setBounds(100, offset + 100, 150, 30);
|
||||
button.addActionListener(e -> {
|
||||
if (!editor.getOverview().getInfo().getText().equals("")) {
|
||||
iconLabel.setIcon(editor.getOverview().getInfo().getIcon());
|
||||
tileNum.setText(editor.getOverview().getInfo().getText().replace("<html><span color='black'>", "").replace("</span></html>", ""));
|
||||
}
|
||||
else {
|
||||
editor.getOverview().setState(Frame.NORMAL);
|
||||
editor.getOverview().toFront();
|
||||
}
|
||||
});
|
||||
return button;
|
||||
}
|
||||
|
||||
private JButton selectButton(JButton importButton, int offset) {
|
||||
JButton button = new JButton("Select tile");
|
||||
button.setBounds(0, offset + 100, 90, 30);
|
||||
button.addActionListener(e -> {
|
||||
if (editor.getOverview() == null) editor.setOverview(new TilesetOverview());
|
||||
else {
|
||||
editor.getOverview().setState(Frame.NORMAL);
|
||||
editor.getOverview().toFront();
|
||||
}
|
||||
importButton.setVisible(true);
|
||||
});
|
||||
return button;
|
||||
}
|
||||
|
||||
private JLabel dividerLabel(int offset) {
|
||||
JLabel label = new JLabel();
|
||||
label.setBounds(0, offset + 140, 255, 1);
|
||||
label.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
|
||||
return label;
|
||||
}
|
||||
}
|
||||
|
||||
@ -106,16 +106,13 @@ public class MapLayersManager {
|
||||
for (int j = 0; j < height; j++) {
|
||||
JLabel cell = new JLabel();
|
||||
if (imagesOfTiles == null || imagesOfTiles.size() == 0) {
|
||||
cell.setText("<html><div style='text-align: center; width: 50'>" + editor.getCellArray()[i][j] + "</div></html>");
|
||||
cell.setText("<html><div style='text-align: center; width: 50'>" + editor.getCellArray()[i][j].split(",")[0].toUpperCase() + "</div></html>");
|
||||
cell.setHorizontalTextPosition(JLabel.CENTER);
|
||||
cellSet.setOpaque(true);
|
||||
cellSet.setBackground(Color.GREEN);
|
||||
}
|
||||
else if (!editor.getCellArray()[i][j].equals("EMPTY")) {
|
||||
String value;
|
||||
if (editor.getCellArray()[i][j].equals("DOOR") || editor.getCellArray()[i][j].equals("DOORTO")) value = "DOOR/DOORTO";
|
||||
else value = editor.getCellArray()[i][j];
|
||||
cell.setIcon(new ImageIcon(imagesOfTiles.get(editor.getCellMap().get(value)).getScaledInstance(50, 50, Image.SCALE_DEFAULT)));
|
||||
else if (!editor.getCellArray()[i][j].split(",")[0].toUpperCase().equals("EMPTY")) {
|
||||
setCellIcon(cell, i, j);
|
||||
}
|
||||
else cellSet.setOpaque(false);
|
||||
cell.setName(String.valueOf(editor.getCellArray()[i][j]));
|
||||
@ -169,6 +166,52 @@ public class MapLayersManager {
|
||||
view.repaint();
|
||||
}
|
||||
|
||||
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())) {
|
||||
return;
|
||||
}
|
||||
if (info[0].toUpperCase().equals("DOOR") || info[0].toUpperCase().equals("DOORTO")) {
|
||||
value = "DOOR/DOORTO";
|
||||
}
|
||||
else {
|
||||
value = info[0].toUpperCase();
|
||||
}
|
||||
if(info.length > 1) {
|
||||
if (info[1].equals("u")) {
|
||||
BufferedImage img = toBufferedImage(imagesOfTiles.get(editor.getCellMap().get(value)).getScaledInstance(50, 50, Image.SCALE_DEFAULT));
|
||||
img = img.getSubimage(0, 0, 50, 25);
|
||||
cell.setIcon(new ImageIcon(tilify(img, true)));
|
||||
}
|
||||
else if (info[1].equals("d")) {
|
||||
BufferedImage img = toBufferedImage(imagesOfTiles.get(editor.getCellMap().get(value)).getScaledInstance(50, 50, Image.SCALE_DEFAULT));
|
||||
img = img.getSubimage(0, 25, 50, 25);
|
||||
cell.setIcon(new ImageIcon(tilify(img, false)));
|
||||
}
|
||||
}
|
||||
else {
|
||||
cell.setIcon(new ImageIcon(imagesOfTiles.get(editor.getCellMap().get(value)).getScaledInstance(50, 50, Image.SCALE_DEFAULT)));
|
||||
}
|
||||
}
|
||||
|
||||
private BufferedImage toBufferedImage(Image img) {
|
||||
BufferedImage bimage = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics2D bGr = bimage.createGraphics();
|
||||
bGr.drawImage(img, 0, 0, null);
|
||||
bGr.dispose();
|
||||
return bimage;
|
||||
}
|
||||
|
||||
private BufferedImage tilify(BufferedImage img, boolean isUp) {
|
||||
BufferedImage image = new BufferedImage(50, 50, BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics2D bGr = image.createGraphics();
|
||||
if (isUp) bGr.drawImage(img, 0, 0, null);
|
||||
else bGr.drawImage(img, 0, 25, null);
|
||||
bGr.dispose();
|
||||
return image;
|
||||
}
|
||||
|
||||
public JLayeredPane getMapLayers() {
|
||||
return mapLayers;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user