Dialogues working

master
GammelJAN 5 years ago
parent 2071e3e69b
commit 758a4cf55c

@ -1,11 +1,21 @@
Ultra geile ultra Frage
Antwort 2#5
Antwort 7#9
Wie gehts
gut#5
schlecht#9
Frage von Antwort 2
Nice#-1
Nice2#-1
Das freut mich
wie gehts dir#20
tschüss#-1
Frage von Antwort 7
lolol#-1
lolol#-1
Das tut mir leid. Wieso denn?
Spaß mir gehts gut#5
tschüss#-1
Halts Maul#14
Ey es gibt gleich Stress hier
cool, bin ich dabei#17
KAMPF
LOS#-1
Ich will Krieg
KRIEG!#17

@ -34,7 +34,8 @@ public class DialogueParser {
break;
}
else {
ans.add(tempAns);
String[] split = tempAns.split("#");
ans.add(split[0]);
}
}
String[] answers = new String[ans.size()];
@ -52,7 +53,7 @@ public class DialogueParser {
String[] newLine = s.split("#");
line = Integer.parseInt(newLine[1]) - 1;
if(line == -1) {
if(line < 0) {
return null;
}
@ -64,11 +65,17 @@ public class DialogueParser {
break;
}
else {
ans.add(tempAns);
String[] split = tempAns.split("#");
ans.add(split[0]);
}
}
result.ans = (String[]) ans.toArray();
String[] answer = new String[ans.size()];
for(int i = 0; i < ans.size(); i++){
answer[i] = ans.get(i);
}
result.ans = answer;
return result;
}
}

@ -122,22 +122,20 @@ public class MapContainer {
if(Main.gamestate == 1) {
Textbox t = null;
for(Actor a : stage.getActors()){
if(a.getName().equals("textbox")){
if(a instanceof Textbox){
t = (Textbox)a;
if(t.getState() == 2){
if(t.getState() == 3){
a.remove();
System.out.println("aösdkjf");
Main.gamestate = 0;
t.getSelectedAsw(); // DO STUFF NICENICE
}
}
}
System.out.println();
}
// center camera
for(Actor a : stage.getActors()){
if(a.getName().equals("player")){
if(a instanceof Player){
stage.getCamera().position.set((a.getX()+a.getWidth()/2), (a.getY()+a.getHeight()/2), 0);
stage.getCamera().update();
break;

@ -138,25 +138,28 @@ public class MovingNpc extends Actor{
movementY = 0;
}
else if(Main.gamestate == 1) {
animatedSprite.setRow(facing);
if(currentlyTalking) {
for(Actor a : getStage().getActors()) {
if(a instanceof Textbox) {
if(((Textbox) a).state == 2) {
int answer = ((Textbox) a).getSelectedAsw();
Dialogue newDialogue = parser.nextDialogue(answer + 1);
if(newDialogue == null) {
currentlyTalking = false;
}
else {
t.update(newDialogue);
}
}
}
}
}
animatedSprite.setRow(facing);
if(currentlyTalking) {
for(Actor a : getStage().getActors().toArray(Actor.class)) {
if(a instanceof Textbox) {
if(((Textbox) a).getState() == 2) {
int answer = ((Textbox) a).getSelectedAsw();
Dialogue newDialogue = parser.nextDialogue(answer + 1);
if(newDialogue == null) {
currentlyTalking = false;
parser = new DialogueParser("dialogues/test.txt");
System.out.println("asdfasdf");
}
else {
((Textbox)a).update(newDialogue);
System.out.println("update nicencie");
}
}
}
}
}
}
animatedSprite.updateAnimation(delta);

@ -84,8 +84,7 @@ public class Player extends Actor{
Actor a = collidingActor();
if(a != null && a instanceof MovingNpc){
Main.gamestate = 1;
Textbox t = ((MovingNpc)a).getTextbox();
getStage().addActor(new Textbox(t, getX()+32, getY()+32));
((MovingNpc)a).startDialogue(getX()+32, getY()+32);
movementX = 0;
movementY = 0;
}

@ -79,8 +79,8 @@ public class Textbox extends Actor{
textHeight = getTextHeight("A");
this.splitted = t.splitted;
this.ans = t.ans;
System.out.println(splitted.size());
float height = this.splitted.size() * 1.2f * textHeight + (this.ans.length+2) * 1.2f * textHeight;
//System.out.println(splitted.size());
float height = this.splitted.size() * 1.2f * textHeight + (this.ans.length+1) * 1.2f * textHeight;
r = new Rectangle(xPos - Main.CAMERA_WIDTH/2 + 20, yPos - Main.CAMERA_HEIGHT/2 + 20, Main.CAMERA_WIDTH - 40, height);
setBounds(r.getX(), r.getY(), r.getWidth(), r.getHeight());
@ -95,13 +95,13 @@ public class Textbox extends Actor{
this.splitted = getSplitted(d.question, (int) Main.CAMERA_WIDTH / 2);
this.ans = d.ans;
float height = this.splitted.size() * 1.2f * textHeight + (this.ans.length+2) * 1.2f * textHeight;
r = new Rectangle(getX(), getY(), Main.CAMERA_WIDTH - 40, height);
setBounds(r.getX(), r.getY(), r.getWidth(), r.getHeight());
this.state = 0;
printLine = 0;
printChar = 0;
float height = this.splitted.size() * 1.2f * textHeight + (this.ans.length+1) * 1.2f * textHeight;
r = new Rectangle(getX(), getY(), getWidth(), height);
setBounds(r.getX(), r.getY(), r.getWidth(), r.getHeight());
this.state = 0;
printLine = 0;
printChar = 0;
selectedAsw = 0;
}
@Override
@ -127,6 +127,9 @@ public class Textbox extends Actor{
System.out.println(ans[selectedAsw]);
}
}
else if(state == 2){
state = 3;
}
else{
if(printChar >= splitted.get(printLine).length()){
if(splitted.size()-1 <= printLine){
@ -195,7 +198,7 @@ public class Textbox extends Actor{
font.setColor(Color.BLACK);
}
font.draw(batch, ans[i], getX()+5, getY() + getHeight() - ((splitted.size() + i + 1) * 1.2f * textHeight - 5));
font.draw(batch, ans[i], getX()+20, getY() + getHeight() - ((splitted.size() + i + 1) * 1.2f * textHeight - 5));
}
}
super.draw(batch, parentAlpha);

@ -6,12 +6,7 @@
package com.trs.main.view.screens;
import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.utils.viewport.FitViewport;
import com.trs.main.Textbox;
/**
*

@ -6,27 +6,9 @@
package com.trs.main.view.screens;
import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.maps.MapObject;
import com.badlogic.gdx.maps.objects.RectangleMapObject;
import com.badlogic.gdx.maps.tiled.TiledMap;
import com.badlogic.gdx.maps.tiled.TmxMapLoader;
import com.badlogic.gdx.maps.tiled.objects.TiledMapTileMapObject;
import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.physics.box2d.BodyDef;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Group;
import com.trs.main.Main;
import com.trs.main.MapCollisionObject;
import com.trs.main.MapContainer;
import com.trs.main.MovingNpc;
import com.trs.main.Player;
import com.trs.main.Textbox;
import java.util.ArrayList;
/**
*

Loading…
Cancel
Save