improved dialog

This commit is contained in:
musilto9 2020-04-24 15:21:52 +02:00
parent 3f39e8b183
commit 52efb4032a
10 changed files with 82 additions and 77 deletions

View File

@ -178,6 +178,15 @@ public class InteractionCell extends Cell {
}
readNextLine();
}
else if (data.contains("<sight>")) {
String[] directionSight = data.split(" ");
if (directionSight[1].equals("main"))
window.getMapManager().getActualMap().getPerson().setDirectionSight(Integer.parseInt(directionSight[2]));
else {
window.getMapManager().getActualMap().findNpcByName(directionSight[1]).setDirection(Integer.parseInt(directionSight[2]));
}
readNextLine();
}
else {
if (data.contains("<br/>"))
data = "<html>" + data + "</html>";

View File

@ -10,17 +10,27 @@ import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Scanner;
public class Npc extends Person {
private MapManager mapManager;
private String name;
private int direction;
private int width;
private int height;
private int offsetX;
private int offsetY;
private int widthCoef;
private int heightCoef;
private String imageNpc;
public Npc(int x, int y, String name, Map map, MapManager mapManager) {
super(x, y, map);
this.name = name;
this.mapManager = mapManager;
loadNpc();
}
public void move(int endX, int endY) {
@ -65,26 +75,41 @@ public class Npc extends Person {
set(x, getY());
}
private void loadNpc() {
File dialogFile = new File("src/main/resources/characters/" + name + ".txt");
Scanner scanner = null;
try {
scanner = new Scanner(dialogFile);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
scanner.nextLine();
String[] imageInfo = scanner.nextLine().split(" ");
width = Integer.parseInt(imageInfo[0]);
height = Integer.parseInt(imageInfo[1]);
direction = Integer.parseInt(imageInfo[2]);
offsetX = Integer.parseInt(imageInfo[3]);
offsetY = Integer.parseInt(imageInfo[4]);
widthCoef = Integer.parseInt(imageInfo[5]);
heightCoef = Integer.parseInt(imageInfo[6]);
imageNpc = scanner.nextLine();
}
@Override
public void paint(Graphics2D g) {
BufferedImage image = null;
try {
File dialogFile = new File("src/main/resources/characters/" + name + ".txt");
Scanner scanner = new Scanner(dialogFile);
scanner.nextLine();
String[] imageInfo = scanner.nextLine().split(" ");
int width = Integer.parseInt(imageInfo[0]);
int height = Integer.parseInt(imageInfo[1]);
int direction = Integer.parseInt(imageInfo[2]);
int offsetX = Integer.parseInt(imageInfo[3]);
int offsetY = Integer.parseInt(imageInfo[4]);
int widthCoef = Integer.parseInt(imageInfo[5]);
int heightCoef = Integer.parseInt(imageInfo[6]);
image = ImageIO.read(new File("src/main/resources/characters/" + scanner.nextLine())).getSubimage(width * direction, 0, width, height);
image = ImageIO.read(new File("src/main/resources/characters/" + imageNpc)).getSubimage(width * direction, 0, width, height);
g.drawImage(image, getX() * getSize() + (getSize() / 5) + offsetX,
getY() * getSize() - (getSize() * 3/5) + offsetY, getSize() * widthCoef/5, getSize() * heightCoef/2, null);
} catch (IOException e) {
e.printStackTrace();
}
}
public void setDirection(int direction) {
this.direction = direction;
}
public String getName() { return name; }
}

View File

@ -25,9 +25,9 @@ public class DialogBar extends JPanel {
WindowOfFreeMove.CELL_SIZE * WindowOfFreeMove.WINDOW_HEIGHT / 4, this);
if (imageDialog != null){
g.drawImage(imageDialog.getImage(), WindowOfFreeMove.CELL_SIZE / 4, WindowOfFreeMove.CELL_SIZE / 4,
WindowOfFreeMove.CELL_SIZE * WindowOfFreeMove.WINDOW_HEIGHT / 4 - WindowOfFreeMove.CELL_SIZE / 2,
g.drawImage(imageDialog.getImage(), WindowOfFreeMove.CELL_SIZE / 4, WindowOfFreeMove.CELL_SIZE / 4 + 3,
WindowOfFreeMove.CELL_SIZE * WindowOfFreeMove.WINDOW_HEIGHT / 4 - WindowOfFreeMove.CELL_SIZE / 2,
WindowOfFreeMove.CELL_SIZE * WindowOfFreeMove.WINDOW_HEIGHT / 4 - WindowOfFreeMove.CELL_SIZE / 2 - 3,
this);
}
this.paintChildren(g);

View File

@ -400,6 +400,13 @@ public class Map {
return null;
}
public Npc findNpcByName(String name) {
for (Npc npc : npcs) {
if (npc.getName().equals(name)) return npc;
}
return null;
}
public int[] directionSightSwitch(int x, int y, int directionSight) {
switch (directionSight) {
case 1:

View File

Before

Width:  |  Height:  |  Size: 4.1 KiB

After

Width:  |  Height:  |  Size: 4.1 KiB

View File

@ -7,4 +7,30 @@ I mean he wouldn't just vanish, right?
<image> boy2-face.png
<voice> voice5
Beats me.
<sight> main 2
<image> main-face.png
<voice> voice1
Hi, guys.
<sight> girl1 1
<image> girl1-face.png
<voice> voice2
Hi.
<sight> boy2 1
<image> boy2-face.png
<voice> voice5
Hi, Mark.
<image> girl1-face.png
<voice> voice2
Mark, Hugo says you should go see him.<br/>Sounds important.
<image> main-face.png
<voice> voice1
Is he in the meeting room?
<image> girl1-face.png
<voice> voice2
No, he's in his office upstairs.
<image> main-face.png
<voice> voice1
Thanks.
<sight> girl1 2
<sight> boy2 0
<end>

View File

@ -3,7 +3,7 @@ BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BL
BLOCK block block block EMPTY block block block BLOCK EMPTY EMPTY EMPTY BLOCK EMPTY EMPTY inter,laugh inter,laugh EMPTY EMPTY BLOCK
BLOCK block EMPTY EMPTY EMPTY EMPTY EMPTY block BLOCK EMPTY EMPTY EMPTY BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK
BLOCK block EMPTY EMPTY EMPTY EMPTY EMPTY block BLOCK,u EMPTY EMPTY EMPTY BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY block
BLOCK block EMPTY EMPTY EMPTY EMPTY EMPTY TRIGGER,dialog DOOR,false EMPTY EMPTY EMPTY BLOCK EMPTY block block block block EMPTY block
BLOCK block EMPTY EMPTY EMPTY EMPTY TRIGGER,dialog EMPTY DOOR,false EMPTY EMPTY EMPTY BLOCK EMPTY block block block block EMPTY block
BLOCK BLOCK,d EMPTY BLOCK,d BLOCK,d BLOCK,d EMPTY BLOCK,d BLOCK EMPTY EMPTY EMPTY BLOCK EMPTY block block block block EMPTY block
BLOCK BLOCK DOOR,true,locked,false BLOCK BLOCK BLOCK DOOR,true BLOCK BLOCK EMPTY EMPTY EMPTY BLOCK EMPTY block block block block EMPTY block
BLOCK block EMPTY block BLOCK block EMPTY block BLOCK EMPTY EMPTY EMPTY BLOCK EMPTY block CHEST,confroom block block EMPTY block

View File

@ -1,55 +0,0 @@
<map>
<mapName>tutorial</mapName>
<events>
<trigger>
<x>11</x>
<y>6</y>
<active>false</active>
</trigger>
</events>
</map>
<map>
<mapName>openspace</mapName>
<events>
<trigger>
<x>7</x>
<y>4</y>
<active>true</active>
</trigger>
<chest>
<x>15</x>
<y>7</y>
<active>false</active>
</chest>
</events>
</map>
<map>
<mapName>office</mapName>
<events>
<chest>
<x>1</x>
<y>9</y>
<active>false</active>
</chest>
</events>
</map>
<map>
<mapName>boss</mapName>
<events>
<trigger>
<x>4</x>
<y>18</y>
<active>true</active>
</trigger>
</events>
</map>
<map>
<mapName>treasure</mapName>
<events>
<trigger>
<x>6</x>
<y>1</y>
<active>false</active>
</trigger>
</events>
</map>

View File

@ -1,6 +0,0 @@
<location>
<map>office</map>
<x>17</x>
<y>11</y>
<direction>2</direction>
</location>

View File

@ -1 +0,0 @@
TODO: Village