added dialog-hide in event

This commit is contained in:
musilto9 2020-03-24 18:31:49 +01:00
parent e49432cbed
commit b261be38e0
4 changed files with 49 additions and 10 deletions

View File

@ -12,6 +12,8 @@ import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
import static ruscz.game.gameOfProd.Windows.WindowOfFreeMove.*;
public class InteractionCell extends Cell {
private String message;
private ruscz.game.gameOfProd.Dialog.Dialog dialog;
@ -28,8 +30,10 @@ public class InteractionCell extends Cell {
}
public void startEvent() {
if (message != null)
if (message != null) {
window.setCanPersonMove(false);
readDialogFile(message);
}
}
public void readDialogFile(String name) {
@ -47,7 +51,6 @@ public class InteractionCell extends Cell {
if (scanner.hasNextLine() && !dialog.getTimerIsRunning()) {
String data = scanner.nextLine();
if (data.equals("<end>")) {
window.getMapPainter().setCameraBound(true);
endEvent();
}
else if (data.contains("<image>")) {
@ -61,6 +64,19 @@ public class InteractionCell extends Cell {
window.getMapPainter().setCameraBound(false);
window.getMapPainter().setCameraEnd(Integer.parseInt(cameraInfo[1]), Integer.parseInt(cameraInfo[2]));
window.getMapPainter().setCameraSpeed(Integer.parseInt(cameraInfo[3]));
readNextLine();
}
else if (data.contains("<dialog>")) {
String[] dialogInfo = data.split(" ");
switch (dialogInfo[1]) {
case "show":
readNextLine();
dialog.showText();
break;
case "hide":
dialog.hideText();
break;
}
}
else {
if (data.contains("<br/>"))
@ -80,6 +96,9 @@ public class InteractionCell extends Cell {
dialog.hideText();
dialog.setImageDialog(null);
}
if (!window.getMapPainter().getCameraBound()) {
window.getMapPainter().returnFreeCamera();
}
WindowOfFreeMove.setCanPersonMove(true);
Person.setInEvent(false);
}

View File

@ -30,8 +30,4 @@ public class TriggerCell extends InteractionCell {
public boolean getActive() {
return isActive;
}
public void setActive(boolean isActive) {
this.isActive = isActive;
}
}

View File

@ -20,6 +20,7 @@ public class MapPainter {
private int cameraSpeed;
private int cameraStartX;
private int cameraStartY;
private boolean isCameraReturning;
public MapPainter(LinkedList<Map> maps, WindowOfFreeMove.Canvas canvas) {
this.canvas = canvas;
@ -158,11 +159,30 @@ public class MapPainter {
int stepX = distanceX * cameraSpeed / CELL_SIZE;
int stepY = distanceY * cameraSpeed / CELL_SIZE;
canvas.setLocation(coordX + stepX, coordY + stepY);
// System.out.println("start: " + cameraStartX + " " + cameraStartY + ", end: " + cameraEndX + " " + cameraEndY);
System.out.println("distanceX: " + distanceX + ", distanceY: " + distanceY);
System.out.println("speed: " + cameraSpeed);
System.out.println("stepX: " + stepX + ", stepY: " + stepY);
}
if (coordX == cameraEndX && coordY == cameraEndY && isCameraReturning) {
isCameraBound = true;
}
}
public void returnFreeCamera() {
setCameraStart();
cameraEndX = (-1) * CELL_SIZE * (getActualMap().getPerson().getX() - WINDOW_WIDTH / 2);
cameraEndY = (-1) * CELL_SIZE * (getActualMap().getPerson().getY() - WINDOW_HEIGHT / 2);
if (cameraEndX > 0) {
cameraEndX = 0;
}
else if (CELL_SIZE * WINDOW_WIDTH - cameraEndX > CELL_SIZE * CANVAS_WIDTH) {
cameraEndX = (-1) * (CELL_SIZE * CANVAS_WIDTH - CELL_SIZE * WINDOW_WIDTH);
}
if (cameraEndY > 0) {
cameraEndY = 0;
}
else if (CELL_SIZE * WINDOW_WIDTH - cameraEndY > CELL_SIZE * CANVAS_WIDTH) {
cameraEndY = (-1) * (CELL_SIZE * CANVAS_HEIGHT - CELL_SIZE * WINDOW_HEIGHT);
}
cameraSpeed = 1;
isCameraReturning = true;
}
public void repaintCanvas() {
@ -184,4 +204,6 @@ public class MapPainter {
}
public void setCameraBound(boolean bound) { this.isCameraBound = bound; }
public boolean getCameraBound() {return isCameraBound; }
}

View File

@ -1,4 +1,6 @@
Keep out
...
<dialog> hide
<dialog> show
or enter<br/>I'm a sign not a cop
<end>