added dialogues from external file
This commit is contained in:
parent
8641d78c7e
commit
8f1a12e6e3
@ -26,8 +26,13 @@ public class Dialog {
|
||||
charNumber = 0;
|
||||
}
|
||||
|
||||
Dialog(DialogBar dialogBar) {
|
||||
this.dialogBar = dialogBar;
|
||||
charNumber = 0;
|
||||
}
|
||||
|
||||
private JLabel prepareDialogBar(String string) {
|
||||
|
||||
public JLabel prepareDialogBar(String string) {
|
||||
Font f1 = new Font("Times New Roman", Font.PLAIN, 20);
|
||||
|
||||
JLabel text = new JLabel();
|
||||
@ -79,5 +84,13 @@ public class Dialog {
|
||||
dialogBar.repaint();
|
||||
}
|
||||
|
||||
public void setText(String text) {
|
||||
this.text = text;
|
||||
this.textLength = text.length() + 1;
|
||||
}
|
||||
|
||||
public void setImageDialog(ImageDialog imageDialog) {
|
||||
this.imageDialog = imageDialog;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,16 +1,21 @@
|
||||
import java.awt.*;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class InteractionCell extends Cell {
|
||||
private String message;
|
||||
private Dialog dialog;
|
||||
private Scanner scanner;
|
||||
|
||||
InteractionCell(){
|
||||
super(-1,-1, WindowOfFreeMove.CELL_SIZE, Color.ORANGE);
|
||||
}
|
||||
|
||||
InteractionCell(int x, int y, String message) {
|
||||
InteractionCell(int x, int y, String message, Dialog dialog) {
|
||||
super(x, y, WindowOfFreeMove.CELL_SIZE, Color.ORANGE);
|
||||
this.message = message;
|
||||
this.dialog = dialog;
|
||||
}
|
||||
|
||||
InteractionCell(int x, int y, Dialog dialog) {
|
||||
@ -21,9 +26,36 @@ public class InteractionCell extends Cell {
|
||||
public void startEvent() {
|
||||
WindowOfFreeMove.setCanPersonMove(false);
|
||||
if (message != null)
|
||||
System.out.println(message);
|
||||
if (dialog != null) {
|
||||
readDialogFile(message);
|
||||
}
|
||||
|
||||
public void readDialogFile(String name) {
|
||||
try {
|
||||
File dialogFile = new File("src/main/resources/" + name + ".txt");
|
||||
scanner = new Scanner(dialogFile);
|
||||
readNextLine();
|
||||
} catch (FileNotFoundException e) {
|
||||
System.out.println("An error occurred.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void readNextLine() {
|
||||
if (scanner.hasNextLine()) {
|
||||
String data = scanner.nextLine();
|
||||
if (data.equals("<end>"))
|
||||
endEvent();
|
||||
else if (data.contains("<image>")) {
|
||||
String[] imageName = data.split(" ");
|
||||
dialog.setImageDialog(new ImageDialog(imageName[1]));
|
||||
readNextLine();
|
||||
}
|
||||
else {
|
||||
dialog.hideText();
|
||||
dialog.setText(data);
|
||||
dialog.showText();
|
||||
dialog.prepareDialogBar(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -31,6 +63,7 @@ public class InteractionCell extends Cell {
|
||||
if (dialog != null)
|
||||
dialog.hideText();
|
||||
WindowOfFreeMove.setCanPersonMove(true);
|
||||
Person.setInEvent(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -8,7 +8,7 @@ public class Person extends Cell {
|
||||
private int directionSight;
|
||||
private int directionMoveLast;
|
||||
private boolean isMoving;
|
||||
private boolean isInEvent;
|
||||
private static boolean isInEvent;
|
||||
private int size;
|
||||
|
||||
public void setDirectionMoveLast(int directionMoveLast) {
|
||||
@ -25,7 +25,6 @@ public class Person extends Cell {
|
||||
this.map = map;
|
||||
this.directionSight = 3;
|
||||
this.isMoving = false;
|
||||
this.isInEvent = false;
|
||||
this.size = WindowOfFreeMove.CELL_SIZE;
|
||||
}
|
||||
|
||||
@ -82,8 +81,7 @@ public class Person extends Cell {
|
||||
map.findInteractionByXY(x, y, directionSight).startEvent();
|
||||
}
|
||||
else if (isEventInFront(x,y,directionSight) && isInEvent) {
|
||||
map.findInteractionByXY(x, y, directionSight).endEvent();
|
||||
isInEvent = false;
|
||||
map.findInteractionByXY(x, y, directionSight).readNextLine();
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -219,4 +217,8 @@ public class Person extends Cell {
|
||||
public void setSize(int size) {
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
public static void setInEvent(boolean isInEvent) {
|
||||
Person.isInEvent = isInEvent;
|
||||
}
|
||||
}
|
||||
|
||||
@ -143,8 +143,8 @@ public class WindowOfFreeMove extends JFrame {
|
||||
|
||||
m1.addMoveToEvent(new EventMoveToCell(1, 1, 8, 8, m2, this));
|
||||
m1.addMoveToEvent(new EventMoveToCell(4, 3, 8, 1, m4, this));
|
||||
m1.addInteractionEvent(new InteractionCell(3, 5, new Dialog("First line", dialogBar)));
|
||||
m1.addInteractionEvent(new InteractionCell(5, 5, new Dialog("Second line", dialogBar, new ImageDialog("BaetoriceFace.png"))));
|
||||
m1.addInteractionEvent(new InteractionCell(3,5,"first-dialog", new Dialog(dialogBar)));
|
||||
m1.addInteractionEvent(new InteractionCell(5,5,"dialog-test", new Dialog(dialogBar)));
|
||||
|
||||
m2.addMoveToEvent(new EventMoveToCell(2, 1, 8, 8, m3, this));
|
||||
m2.addMoveToEvent(new EventMoveToCell(1, 3, 8, 1, m1, this));
|
||||
|
||||
4
src/main/resources/dialog-test.txt
Normal file
4
src/main/resources/dialog-test.txt
Normal file
@ -0,0 +1,4 @@
|
||||
<image> BaetoriceFace.png
|
||||
Wow
|
||||
to je úžasné
|
||||
<end>
|
||||
7
src/main/resources/first-dialog.txt
Normal file
7
src/main/resources/first-dialog.txt
Normal file
@ -0,0 +1,7 @@
|
||||
Tento
|
||||
dialog
|
||||
je
|
||||
na
|
||||
několik
|
||||
řádků
|
||||
<end>
|
||||
Loading…
x
Reference in New Issue
Block a user