Dialogues working

master
GammelJAN 5 years ago
parent 2071e3e69b
commit 758a4cf55c

@ -1,11 +1,21 @@
Ultra geile ultra Frage Wie gehts
Antwort 2#5 gut#5
Antwort 7#9 schlecht#9
Frage von Antwort 2 Das freut mich
Nice#-1 wie gehts dir#20
Nice2#-1 tschüss#-1
Frage von Antwort 7 Das tut mir leid. Wieso denn?
lolol#-1 Spaß mir gehts gut#5
lolol#-1 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; break;
} }
else { else {
ans.add(tempAns); String[] split = tempAns.split("#");
ans.add(split[0]);
} }
} }
String[] answers = new String[ans.size()]; String[] answers = new String[ans.size()];
@ -52,7 +53,7 @@ public class DialogueParser {
String[] newLine = s.split("#"); String[] newLine = s.split("#");
line = Integer.parseInt(newLine[1]) - 1; line = Integer.parseInt(newLine[1]) - 1;
if(line == -1) { if(line < 0) {
return null; return null;
} }
@ -64,11 +65,17 @@ public class DialogueParser {
break; break;
} }
else { 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; return result;
} }
} }

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

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

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

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

@ -6,12 +6,7 @@
package com.trs.main.view.screens; package com.trs.main.view.screens;
import com.badlogic.gdx.Game; import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen; 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; package com.trs.main.view.screens;
import com.badlogic.gdx.Game; 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.Main;
import com.trs.main.MapCollisionObject;
import com.trs.main.MapContainer; import com.trs.main.MapContainer;
import com.trs.main.MovingNpc;
import com.trs.main.Player; import com.trs.main.Player;
import com.trs.main.Textbox;
import java.util.ArrayList;
/** /**
* *

Loading…
Cancel
Save