fixed some stuff, added tileset overview

This commit is contained in:
musilto9 2020-04-25 01:12:40 +02:00
parent 52efb4032a
commit 1e1aa8b20a
24 changed files with 193 additions and 9 deletions

View File

@ -33,9 +33,16 @@ public class EventMoveToCell extends Cell {
window.getMapManager().getActualMap().setIdExit(id); window.getMapManager().getActualMap().setIdExit(id);
window.paintMapOnWindow(); window.paintMapOnWindow();
window.repaintCanvas(); window.repaintCanvas();
if (!isActiveTriggerBehindMoveTo())
window.setCanPersonMove(true); window.setCanPersonMove(true);
} }
private boolean isActiveTriggerBehindMoveTo() {
int x = window.getMapManager().getActualMap().getPerson().getX();
int y = window.getMapManager().getActualMap().getPerson().getY();
return map.isActiveTriggerCell(x, y);
}
@Override @Override
public void paint(Graphics2D g) { public void paint(Graphics2D g) {
super.paint(g); super.paint(g);

View File

@ -187,6 +187,12 @@ public class InteractionCell extends Cell {
} }
readNextLine(); readNextLine();
} }
else if (data.contains("<activate>")) {
String[] eventInfo = data.split(" ");
Map map = Map.findMapByName(eventInfo[1], window);
map.findTriggerByXY(Integer.parseInt(eventInfo[2]), Integer.parseInt(eventInfo[3])).setActive(Boolean.parseBoolean(eventInfo[4]));
readNextLine();
}
else { else {
if (data.contains("<br/>")) if (data.contains("<br/>"))
data = "<html>" + data + "</html>"; data = "<html>" + data + "</html>";
@ -242,8 +248,8 @@ public class InteractionCell extends Cell {
else if (data[1].contains("<moveto>")) { else if (data[1].contains("<moveto>")) {
Map map = Map.findMapByName(data[2], window); Map map = Map.findMapByName(data[2], window);
window.getMapManager().setMap(map); window.getMapManager().setMap(map);
map.getPerson().set(map.getSpawnPoint()[0], map.getSpawnPoint()[1]); map.getPerson().set(Integer.parseInt(data[3]), Integer.parseInt(data[4]));
map.getPerson().setDirectionSight(Integer.parseInt(data[3])); map.getPerson().setDirectionSight(Integer.parseInt(data[5]));
map.setIdExit(0); map.setIdExit(0);
} }
else if (data[1].equals("<music>")) { else if (data[1].equals("<music>")) {

View File

@ -14,6 +14,11 @@ public class TriggerCell extends InteractionCell {
this.isActive = true; this.isActive = true;
} }
public TriggerCell(int x, int y, String message, Dialog dialog, Map map, WindowOfFreeMove window, boolean active) {
super(x, y, message, dialog, map, window, false);
this.isActive = active;
}
@Override @Override
public void endEvent() { public void endEvent() {
super.endEvent(); super.endEvent();

View File

@ -1,5 +1,6 @@
package ruscz.game.gameOfProd; package ruscz.game.gameOfProd;
import ruscz.game.gameOfProd.LevelEditor.TilesetOverview;
import ruscz.game.gameOfProd.Windows.WindowOfBattle; import ruscz.game.gameOfProd.Windows.WindowOfBattle;
import ruscz.game.gameOfProd.Windows.WindowOfFreeMove; import ruscz.game.gameOfProd.Windows.WindowOfFreeMove;
import ruscz.game.gameOfProd.Windows.WindowOfMenu; import ruscz.game.gameOfProd.Windows.WindowOfMenu;
@ -15,6 +16,7 @@ public class Game extends JFrame {
private WindowOfMenu menu; private WindowOfMenu menu;
private WindowOfFreeMove freeMove; private WindowOfFreeMove freeMove;
private WindowOfBattle battle; private WindowOfBattle battle;
private TilesetOverview tilesetOverview;
public WindowOfMenu getMenu() { public WindowOfMenu getMenu() {
return menu; return menu;
@ -48,6 +50,9 @@ public class Game extends JFrame {
// add(battle); // add(battle);
// battle.startBattle(); // battle.startBattle();
//Tohle spustí na začátku tileset overview
// tilesetOverview = new TilesetOverview();
setDefaultCloseOperation(EXIT_ON_CLOSE); setDefaultCloseOperation(EXIT_ON_CLOSE);
setUndecorated(true); setUndecorated(true);
setBounds(0, 0, CELL_SIZE * WINDOW_WIDTH, CELL_SIZE * WINDOW_HEIGHT); setBounds(0, 0, CELL_SIZE * WINDOW_WIDTH, CELL_SIZE * WINDOW_HEIGHT);

View File

@ -59,7 +59,7 @@ public class ImageCell {
private void imageTileset(String[] mapInfo) { private void imageTileset(String[] mapInfo) {
try { try {
image = ImageIO.read(new File("src/main/resources/" + mapInfo[1])); image = ImageIO.read(new File("src/main/resources/tilesets/" + mapInfo[1]));
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -26,7 +26,7 @@ public class ImageDoor {
public ImageDoor(String door, Rectangle[] rectangles) { public ImageDoor(String door, Rectangle[] rectangles) {
try { try {
String[] doorInfo = door.split(","); String[] doorInfo = door.split(",");
image = ImageIO.read(new File("src/main/resources/" + doorInfo[0])); image = ImageIO.read(new File("src/main/resources/tilesets/" + doorInfo[0]));
size = Integer.parseInt(doorInfo[1]); size = Integer.parseInt(doorInfo[1]);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();

View File

@ -0,0 +1,149 @@
package ruscz.game.gameOfProd.LevelEditor;
import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.LinkedList;
public class TilesetOverview extends JFrame {
private JLayeredPane view;
private JLayeredPane tilesetPanel;
private JScrollPane scrollPane;
private JLabel info;
private int offset = 0;
private int tilesetOffset = 0;
private LinkedList<String> activeTilesets;
private LinkedList<BufferedImage> imagesOfTiles;
public TilesetOverview() {
final File folder = new File("src/main/resources/tilesets/");
view = new JLayeredPane();
tilesetPanel = new JLayeredPane();
scrollPane = new JScrollPane(tilesetPanel);
listFilesForFolder(folder);
}
public void listFilesForFolder(File folder) {
activeTilesets = new LinkedList<>();
for (final File fileEntry : folder.listFiles()) {
loadTileset(fileEntry.getName());
}
JButton generate = new JButton("Generate Tileset Overview");
generate.setBounds(50, offset, 200, 50);
generate.addActionListener(actionEvent -> {
generateOverview();
});
add(generate);
info = new JLabel();
info.setBounds(300, 830, 200, 50);
add(info);
tilesetPanel.setPreferredSize(new Dimension(630, 800));
scrollPane.setLocation(300, 0);
scrollPane.setBounds(300, 0, 650, 800);
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
scrollPane.setWheelScrollingEnabled(true);
scrollPane.getVerticalScrollBar().setUnitIncrement(10);
view.add(scrollPane);
add(view);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setBounds(0, 0, 1000, 1000);
setLocationRelativeTo(null);
setVisible(true);
setResizable(false);
}
private void loadTileset(String name) {
JLabel text = new JLabel(name);
text.setBounds(50 , offset, 200, 50);
JCheckBox checkBox = new JCheckBox();
checkBox.setBounds(220, offset, 30, 50);
checkBox.addActionListener(actionEvent -> {
if (activeTilesets.contains(name)) activeTilesets.remove(name);
else activeTilesets.add(name);
});
checkBox.setName(name);
add(text);
add(checkBox);
offset += 70;
}
private void generateOverview() {
tilesetOffset = 0;
imagesOfTiles = new LinkedList<>();
tilesetPanel.removeAll();
for (String name : activeTilesets) {
JPanel tileset = new JPanel();
LinkedList<JLabel> tileList = new LinkedList<>();
BufferedImage image = null;
try {
image = ImageIO.read(new File("src/main/resources/tilesets/" + name));
} catch (IOException e) {
e.printStackTrace();
}
int width = image.getWidth();
int height = image.getHeight();
int tileSize = 32;
int Xtiles = width / tileSize;
int Ytiles = height / tileSize;
int tiles = Xtiles * Ytiles;
Rectangle[] rectangles = new Rectangle[tiles];
int count = 0;
for (int i = 0; i < rectangles.length / Ytiles; i++) {
for (int j = 0; j < rectangles.length / Xtiles; j++) {
rectangles[count] = new Rectangle(tileSize * i, tileSize * j, tileSize, tileSize);
count++;
}
}
for (int i = 0; i < tiles; i++) {
BufferedImage tileImage = image.getSubimage(rectangles[i].x, rectangles[i].y, rectangles[i].height, rectangles[i].width);
imagesOfTiles.add(tileImage);
ImageIcon imageIcon = new ImageIcon(tileImage);
JLabel tile = new JLabel("<html><span color='black'>" + (imagesOfTiles.size() - 1) + "</span></html>", imageIcon, JLabel.CENTER);
tile.setHorizontalTextPosition(JLabel.CENTER);
tile.setPreferredSize(new Dimension(tileSize, tileSize));
tile.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
info.setIcon(new ImageIcon(tileImage.getScaledInstance(50, 50, Image.SCALE_DEFAULT)));
info.setText(tile.getText());
}
});
tileList.add(tile);
}
//
for (int i = 0; i < Ytiles; i++) {
for (int j = 0; j < Xtiles; j++) {
tileset.add(tileList.get(i + (j*Ytiles)));
}
}
// for (int i = 0; i < 16; i++) {
// tileset.add(tileList.get(i));
// }
tileset.setBounds(0, tilesetOffset, width + (Xtiles * 6), height + (Ytiles * 6));
tilesetOffset += height + + (Ytiles * 6);
tilesetPanel.add(tileset);
int panelWidth = tilesetPanel.getWidth();
if (panelWidth < width + (Xtiles * 6)) panelWidth = width + (Xtiles * 6);
tilesetPanel.setPreferredSize(new Dimension(panelWidth, tilesetOffset));
}
view.repaint();
}
}

View File

@ -110,7 +110,10 @@ public class Map {
map.addInteractionEvent(new InteractionCell(x, y, event[1], new Dialog(window.getDialogBar()), map, window, false)); map.addInteractionEvent(new InteractionCell(x, y, event[1], new Dialog(window.getDialogBar()), map, window, false));
} else if (line[x].contains("TRIGGER")) { } else if (line[x].contains("TRIGGER")) {
String[] trigger = line[x].split(","); String[] trigger = line[x].split(",");
if (trigger.length == 2)
map.addInteractionEvent(new TriggerCell(x, y, trigger[1], new Dialog(window.getDialogBar()), map, window)); map.addInteractionEvent(new TriggerCell(x, y, trigger[1], new Dialog(window.getDialogBar()), map, window));
else
map.addInteractionEvent(new TriggerCell(x, y, trigger[1], new Dialog(window.getDialogBar()), map, window, Boolean.parseBoolean(trigger[2])));
} else if (line[x].equals("SPAWN")) { } else if (line[x].equals("SPAWN")) {
map.setIdExit(0); map.setIdExit(0);
map.setSpawnPoint(x, y); map.setSpawnPoint(x, y);

Binary file not shown.

Before

Width:  |  Height:  |  Size: 62 KiB

View File

@ -1,6 +1,6 @@
<1> <personmove> false <1> <personmove> false
<1> <foreground> error <1> <foreground> error
<3> <moveto> openspace 4 <3> <moveto> openspace 14 16 4
<3> <text> Shit.. <3> <text> Shit..
<5> <foreground> null <5> <foreground> null
<5> <text> null <5> <text> null

View File

@ -0,0 +1,3 @@
<1> <text> test
<3> <text> null
<3> <end>

View File

@ -0,0 +1,4 @@
Ok, I should probably go back to my desk and check<br/>out the Game-of-Prod's code to familiarize myself<br/>with it.
I have a feeling this is going to be a long day.<br/>But hey, new project is always exciting.
<activate> openspace 14 16 true
<end>

View File

@ -7,4 +7,6 @@ I know, this is on very short notice<br/>but as you've probably heard,<br/>we ki
And that someone is gonna be,<br/>you guessed it, you. You start by tomorrow. And that someone is gonna be,<br/>you guessed it, you. You start by tomorrow.
You can go now. You can go now.
Bye. Bye.
<activate> office 4 2 true
<activate> openspace 6 4 false
<end> <end>

View File

@ -1,7 +1,7 @@
20 13 20 13
BLOCK,d BLOCK,d BLOCK,d BLOCK,d EMPTY BLOCK,d BLOCK,d BLOCK,d BLOCK,d BLOCK,d BLOCK,d BLOCK,d BLOCK,d BLOCK,d BLOCK,d BLOCK,d BLOCK,d BLOCK,d BLOCK,d BLOCK,d BLOCK,d BLOCK,d BLOCK,d BLOCK,d EMPTY BLOCK,d BLOCK,d BLOCK,d BLOCK,d BLOCK,d BLOCK,d BLOCK,d BLOCK,d BLOCK,d BLOCK,d BLOCK,d BLOCK,d BLOCK,d BLOCK,d BLOCK,d
BLOCK BLOCK BLOCK BLOCK DOORTO,true,0,3,boss BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK DOOR,true,locked BLOCK BLOCK BLOCK BLOCK DOOR,true,locked BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK DOORTO,true,0,3,boss BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK DOOR,true,locked BLOCK BLOCK BLOCK BLOCK DOOR,true,locked BLOCK BLOCK
BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK BLOCK EMPTY EMPTY EMPTY TRIGGER,nextstep,false EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK
BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY block BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY block
BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY block BLOCK BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY block BLOCK
BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK EMPTY EMPTY EMPTY BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK EMPTY EMPTY EMPTY BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK

View File

@ -15,7 +15,7 @@ BLOCK EMPTY block block inter,minecraft block block EMPTY BLOCK,u EMPTY EMPTY EM
BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY DOOR,false EMPTY EMPTY EMPTY EMPTY EMPTY block block EMPTY block block block BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY DOOR,false EMPTY EMPTY EMPTY EMPTY EMPTY block block EMPTY block block block
BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY block BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY block
BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK EMPTY moveto,1,2,office EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK EMPTY moveto,1,2,office EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK
BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK EMPTY moveto,2,2,office EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY SPAWN block EMPTY block EMPTY BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK EMPTY moveto,2,2,office EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY TRIGGER,cutscene-work,false block EMPTY block EMPTY BLOCK
BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY block block EMPTY block block block BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY block block EMPTY block block block
BLOCK block EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY block BLOCK block EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY block
BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY block BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY block

View File

Before

Width:  |  Height:  |  Size: 35 KiB

After

Width:  |  Height:  |  Size: 35 KiB

View File

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 21 KiB

View File

Before

Width:  |  Height:  |  Size: 85 KiB

After

Width:  |  Height:  |  Size: 85 KiB

View File

Before

Width:  |  Height:  |  Size: 39 KiB

After

Width:  |  Height:  |  Size: 39 KiB

View File

Before

Width:  |  Height:  |  Size: 36 KiB

After

Width:  |  Height:  |  Size: 36 KiB

View File

Before

Width:  |  Height:  |  Size: 51 KiB

After

Width:  |  Height:  |  Size: 51 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

View File

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 12 KiB