From 0bd73baddaef10dda3520c54976a1e198530479e Mon Sep 17 00:00:00 2001 From: GammelJAN Date: Mon, 1 Feb 2021 19:03:23 +0100 Subject: [PATCH] textbox and questwindow now on its own matrix -> own layer on top of game world - font stopped working, not using .ttf file --- core/assets/txt.png | Bin 0 -> 691 bytes core/assets/txt_bot.png | Bin 0 -> 725 bytes core/assets/txt_top.png | Bin 0 -> 725 bytes core/src/com/trs/main/MapContainer.java | 1 + .../trs/main/fightscreen/FightDialogue.java | 15 +- .../com/trs/main/fightscreen/FightScreen.java | 22 +-- .../src/com/trs/main/view/UI/QuestWindow.java | 20 ++- .../com/trs/main/{ => view/UI}/Textbox.java | 134 ++++++------------ .../com/trs/main/view/screens/GameScreen.java | 11 +- .../main/worldobjects/InteractionObject.java | 8 +- .../com/trs/main/worldobjects/MovingNpc.java | 14 +- 11 files changed, 102 insertions(+), 123 deletions(-) create mode 100644 core/assets/txt.png create mode 100644 core/assets/txt_bot.png create mode 100644 core/assets/txt_top.png rename core/src/com/trs/main/{ => view/UI}/Textbox.java (58%) diff --git a/core/assets/txt.png b/core/assets/txt.png new file mode 100644 index 0000000000000000000000000000000000000000..08f98d59e2e40f7d6e101473996f0a33a54ada98 GIT binary patch literal 691 zcmeAS@N?(olHy`uVBq!ia0y~yVAcb&g*n)OWZC{mR|W>g)=X#T08eLUg@U5|w9K4T z1_q6ZwG(YU4hM*|`Ufu!(&8!;C_E7`SEr-vg<7aiQ|qO$jH?HqEUmw=MA5UbP$Y(% z@1IVXY|Na}(gIPIgYp9A=IXBEnjiNqxuA56yZ?LPJ=^y0@0eTMT34oBw^)!hZDQB) zBRP4YJbRoP`2TVwg(WSU=b@kWATs{@74K5%-PhGM9WH-1&S)Uc?dUBbR4S zJ6Ad1;*8fMry4(-vDfsZ!Z@C+|0yay{%)%yQEni)j-agp^XQ1h}z^E!vX3WQNDZ$}@-UpZu8o zWYWn{Hs#|?s{#})>ps~3u#MhqVEIt3HOb+7cW!+TLu2fM$n9_6C*RJS$M7%xfminL z)w~JMCV#1l?v`P!y?x+lY4qgp4X0%jK6p;&IXUsqmKG<*3j4+Rrx=;HI~1Iq8~s{l zIln_&+SVFo85yRY26GTBzTNp5 zD8gCb5n0T@pr;JNj1^1m%YcIHC7!;n>`$2(1r-&i8sEqR3Q3l@MwB?`=jNv7l`uFL zr6!i7rYMwWmSiZnd-?{1H}Z)C6?J*KIEGZ*dV75%qk{tj%R$u(+ml+d0-L-lCQ5On z9pcu%y;3UF+kO2-Nd|@k;_tq#TDPq{Dt$XpXT5q1kbKC*z@UJ_XyJy6pfDN=7#SEq jB4CC9Fx{ater#pGRm;AN>4H@w&{PIbS3j3^P6EX>4Tx04R}tkv&MmP!xqvQ>9WW3U&~2$WWauh>GYYRV;#q(pG5I!Q`cX(4-+r zad8w}3l9D)RvlcNb#-tR1i>E=H#a9m7b)?+q|hS93y=44-aUu+?gNBIg{fxOIG}2l zk&4H}Y;IKyyh4Bv{Rm=KVy2!*FJ|CbU-#5YbrouaY+z;1h}Gm~L3a8^qI_ zmd<&fILu0tLVQjPFL=9Bb# zTZl~*KK!#?ud;=UD z0;5IBUiWx+Pv_kJ?P<;L2V);{p_RUM)&Kwi24YJ`L;yDcHvl(t+lli4000SaNLh0L z04^f{04^f|c%?sf00007bV*G`2jv0*5g{bySuEiI000?uMObu0Z*6U5Zgc=ca%Ew3 zWn>_CX>@2HM@dakSAh-}00022Nkl6FdvK*`#z0RRB4 zqa{g}0PsiAvQ09SS)+&-0DzAkR={^Wi&v?Px|F5(3M0BEV7%v~MIn?s#@0{{RTn6=0SvjQw9Civ-900000NkvXX Hu0mjfDNiWz literal 0 HcmV?d00001 diff --git a/core/assets/txt_top.png b/core/assets/txt_top.png new file mode 100644 index 0000000000000000000000000000000000000000..1f2be34bcdfbe3877e9e64c40aa0ae88b0facf3a GIT binary patch literal 725 zcmV;`0xJE9P)EX>4Tx04R}tkv&MmP!xqvQ>9WW3U&~2$WWauh>GYYRV;#q(pG5I!Q`cX(4-+r zad8w}3l9D)RvlcNb#-tR1i>E=H#a9m7b)?+q|hS93y=44-aUu+?gNBIg{fxOIG}2l zk&4H}Y;IKyyh4Bv{Rm=KVy2!*FJ|CbU-#5YbrouaY+z;1h}Gm~L3a8^qI_ zmd<&fILu0tLVQjPFL=9Bb# zTZl~*KK!#?ud;=UD z0;5IBUiWx+Pv_kJ?P<;L2V);{p_RUM)&Kwi24YJ`L;yDcHvl(t+lli4000SaNLh0L z04^f{04^f|c%?sf00007bV*G`2jv0*5g{XcJ-I>v000?uMObu0Z*6U5Zgc=ca%Ew3 zWn>_CX>@2HM@dakSAh-}00022Nkl41mEnyf0Bd`RLSx~SFl35T4 zB$GfW@RZK*0I5b00000NkvXX Hu0mjf!kjNc literal 0 HcmV?d00001 diff --git a/core/src/com/trs/main/MapContainer.java b/core/src/com/trs/main/MapContainer.java index 6121595..164ebd7 100644 --- a/core/src/com/trs/main/MapContainer.java +++ b/core/src/com/trs/main/MapContainer.java @@ -25,6 +25,7 @@ import com.badlogic.gdx.math.Rectangle; import com.badlogic.gdx.scenes.scene2d.Actor; import com.badlogic.gdx.scenes.scene2d.Stage; import com.badlogic.gdx.utils.viewport.FitViewport; +import com.trs.main.view.UI.Textbox; /** * diff --git a/core/src/com/trs/main/fightscreen/FightDialogue.java b/core/src/com/trs/main/fightscreen/FightDialogue.java index edf23f3..081b0e7 100644 --- a/core/src/com/trs/main/fightscreen/FightDialogue.java +++ b/core/src/com/trs/main/fightscreen/FightDialogue.java @@ -11,8 +11,10 @@ import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.g2d.Batch; import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.GlyphLayout; +import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator; import com.badlogic.gdx.graphics.glutils.ShapeRenderer; +import com.badlogic.gdx.math.Matrix4; import com.badlogic.gdx.math.Rectangle; import com.trs.main.Main; @@ -28,21 +30,26 @@ public class FightDialogue { int selectedAsw = 0; String[] ans = {"Melee", "Range", "Skip"}; - public FightDialogue(float camX, float camY){ + public static Matrix4 m; + + Batch batch = new SpriteBatch(); + + public FightDialogue(){ FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("fontData/font.ttf")); FreeTypeFontGenerator.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter(); parameter.size = 21; font = generator.generateFont(parameter); generator.dispose(); font.setColor(Color.BLACK); - renderer = new ShapeRenderer(); - r = new Rectangle(camX-Main.CAMERA_WIDTH/2f + Main.CAMERA_WIDTH*0.8f, camY-Main.CAMERA_HEIGHT/2 + Main.CAMERA_HEIGHT*0.2f, Main.CAMERA_WIDTH*0.18f, Main.CAMERA_HEIGHT*0.6f); + r = new Rectangle(Main.CAMERA_WIDTH - 200, 20, 180, Main.CAMERA_HEIGHT-40); } - public void draw(Batch batch){ + public void draw(Batch camBatch){ + + batch.setProjectionMatrix(m); if(Gdx.input.isKeyJustPressed(Input.Keys.DOWN)){ if(selectedAsw < ans.length - 1) { diff --git a/core/src/com/trs/main/fightscreen/FightScreen.java b/core/src/com/trs/main/fightscreen/FightScreen.java index 4b7862d..eee300f 100644 --- a/core/src/com/trs/main/fightscreen/FightScreen.java +++ b/core/src/com/trs/main/fightscreen/FightScreen.java @@ -13,7 +13,7 @@ import com.trs.main.StaticMath; public class FightScreen { - final int gridWidth = 20; + final int gridWidth = 18; final int gridHeight = 12; Batch batch; @@ -29,16 +29,16 @@ public class FightScreen { int state = 0; public FightScreen(Batch batch, FightObject[] objects, Rectangle[] collisionRects, float camX, float camY) { - this.batch = batch; - this.objects = objects; - this.collisionRects = collisionRects; - this.renderer = new ShapeRenderer(); - this.fightDialogue = new FightDialogue(camX, camY); - - gridPos = new Vector2(); - - gridPos.x = (float)(Math.ceil((double)(camX-Main.CAMERA_WIDTH/2)/32.0) * 32.0) + 64; - gridPos.y = (float)(Math.ceil((double)(camY-Main.CAMERA_HEIGHT/2)/32.0) * 32.0) + 32; + this.batch = batch; + this.objects = objects; + this.collisionRects = collisionRects; + this.renderer = new ShapeRenderer(); + this.fightDialogue = new FightDialogue(); + + gridPos = new Vector2(); + + gridPos.x = (float)(Math.ceil((double)(camX-Main.CAMERA_WIDTH/2)/32.0) * 32.0) + 64; + gridPos.y = (float)(Math.ceil((double)(camY-Main.CAMERA_HEIGHT/2)/32.0) * 32.0) + 32; // SORTING OBJECTS BY INITIATIVE STAT diff --git a/core/src/com/trs/main/view/UI/QuestWindow.java b/core/src/com/trs/main/view/UI/QuestWindow.java index f227f45..a564863 100644 --- a/core/src/com/trs/main/view/UI/QuestWindow.java +++ b/core/src/com/trs/main/view/UI/QuestWindow.java @@ -15,7 +15,7 @@ import com.badlogic.gdx.graphics.g2d.GlyphLayout; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator; import com.badlogic.gdx.graphics.glutils.ShapeRenderer; -import com.badlogic.gdx.math.Rectangle; +import com.badlogic.gdx.math.Matrix4; import com.trs.main.InformationQuest; import com.trs.main.Main; import com.trs.main.Quest; @@ -36,11 +36,17 @@ public class QuestWindow { double visiblePerc; - public QuestWindow(){ + Batch batch = new SpriteBatch(); + + public QuestWindow(Matrix4 m){ renderer = new ShapeRenderer(); visible = true; selectedQuest = 0; + Matrix4 uiMatrix = m.cpy(); + uiMatrix.setToOrtho2D(0, 0, Main.CAMERA_WIDTH, Main.CAMERA_HEIGHT); + batch.setProjectionMatrix(uiMatrix); + FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("fontData/font.ttf")); FreeTypeFontGenerator.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter(); parameter.size = 21; @@ -49,7 +55,7 @@ public class QuestWindow { font.setColor(Color.WHITE); } - public void draw(Quest[] quests, Batch batch, float playerX, float playerY){ + public void draw(Quest[] quests){ if(Gdx.input.isKeyJustPressed(Input.Keys.RIGHT)){ if(selectedQuest < quests.length-1){ @@ -63,10 +69,10 @@ public class QuestWindow { } - float boxX = playerX + Main.CAMERA_WIDTH/2 - 200; - float boxY = playerY + Main.CAMERA_HEIGHT/2 - 0.4f*Main.CAMERA_HEIGHT - 30; - float boxWidth = 0.2f*Main.CAMERA_WIDTH; - float boxHeight = 0.4f*Main.CAMERA_HEIGHT; + float boxX = Main.CAMERA_WIDTH - 200; + float boxY = Main.CAMERA_HEIGHT - 250; + float boxWidth = 180; + float boxHeight = 230; renderer.setProjectionMatrix(batch.getProjectionMatrix()); diff --git a/core/src/com/trs/main/Textbox.java b/core/src/com/trs/main/view/UI/Textbox.java similarity index 58% rename from core/src/com/trs/main/Textbox.java rename to core/src/com/trs/main/view/UI/Textbox.java index 071aa06..b71183b 100644 --- a/core/src/com/trs/main/Textbox.java +++ b/core/src/com/trs/main/view/UI/Textbox.java @@ -3,18 +3,23 @@ * To change this template file, choose Tools | Templates * and open the template in the editor. */ -package com.trs.main; +package com.trs.main.view.UI; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Input; import com.badlogic.gdx.graphics.Color; +import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.Batch; import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.GlyphLayout; +import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator; import com.badlogic.gdx.graphics.glutils.ShapeRenderer; +import com.badlogic.gdx.math.Matrix4; import com.badlogic.gdx.math.Rectangle; import com.badlogic.gdx.scenes.scene2d.Actor; +import com.trs.main.Dialogue; +import com.trs.main.Main; import java.util.ArrayList; /** @@ -23,6 +28,9 @@ import java.util.ArrayList; */ public class Textbox extends Actor{ + final Color TextColor = Color.WHITE; + final Color SelectedColor = Color.FIREBRICK; + BitmapFont font; Rectangle r; float printChar; @@ -30,8 +38,6 @@ public class Textbox extends Actor{ float textSpeed = 0.8f; //ArrayList splitted; - ShapeRenderer renderer; - int state; // 0: drawing 1: waiting for input 2: finished int selectedAsw = 0; @@ -42,15 +48,22 @@ public class Textbox extends Actor{ String toPrint; - public Textbox(String toPrint, String[] ans, float xPos, float yPos) { + + Texture txt = new Texture("txt.png"); + Texture txtTop = new Texture("txt_top.png"); + Texture txtBot = new Texture("txt_bot.png"); + + public static Matrix4 m; + + Batch batch = new SpriteBatch(); + + public Textbox(String toPrint, String[] ans) { FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("fontData/font.ttf")); FreeTypeFontGenerator.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter(); parameter.size = 21; font = generator.generateFont(parameter); generator.dispose(); font.setColor(Color.BLACK); - - renderer = new ShapeRenderer(); textHeight = getTextHeight(font,"A"); printChar = 0; this.ans = ans; @@ -58,40 +71,13 @@ public class Textbox extends Actor{ font = new BitmapFont(); setWidth(Main.CAMERA_WIDTH - 40); - //splitted = getSplitted(toPrint, (int)(Main.CAMERA_WIDTH - 40)); - - // CALCULATE NEEDED HEIGHT - //float height = splitted.size() * 1.2f * textHeight + (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, 0); + r = new Rectangle(20, 20, 814, 0); setBounds(r.getX(), r.getY(), r.getWidth(), r.getHeight()); this.toPrint = toPrint; state = 0; } - public Textbox(Textbox t, float xPos, float yPos){ - font = new BitmapFont(); - FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("fontData/font.ttf")); - FreeTypeFontGenerator.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter(); - parameter.size = 21; - font = generator.generateFont(parameter); - generator.dispose(); - font.setColor(Color.BLACK); - - textHeight = getTextHeight(font,"A"); - this.ans = t.ans; - this.r = t.r; - this.r.setPosition(xPos - Main.CAMERA_WIDTH/2 + 20, yPos - Main.CAMERA_HEIGHT/2 + 20); - setBounds(r.getX(), r.getY(), r.getWidth(), r.getHeight()); - - renderer = new ShapeRenderer(); - printChar = 0; - setName("textbox"); - this.toPrint = t.toPrint; - - } - public void update(Dialogue d) { //this.splitted = getSplitted(d.question, (int) Main.CAMERA_WIDTH / 2); this.toPrint = d.question; @@ -155,82 +141,52 @@ public class Textbox extends Actor{ @Override - public void draw(Batch batch, float parentAlpha) { + public void draw(Batch camBatch, float parentAlpha) { + camBatch.end(); + + batch.setProjectionMatrix(m); + batch.begin(); int alignment = -1; font.setColor(Color.CLEAR); - float height = font.draw(batch, toPrint.substring(0, (int)printChar), getX()+2, getY(), getWidth(), alignment, true).height+5; - float textHeight = height; + float height = font.draw(batch, toPrint.substring(0, (int)printChar), getX()+2, getY(), getWidth(), alignment, true).height; + float textHeight = getTextHeight(font, "A"); + if(state == 1){ for(String s : ans){ - height += getTextHeight(font, "A") + 10; + height += textHeight + 5; } + } setHeight(height); font.setColor(Color.BLACK); - batch.end(); - renderer.setProjectionMatrix(batch.getProjectionMatrix()); - renderer.begin(ShapeRenderer.ShapeType.Filled); - renderer.setColor(Color.BLUE); - renderer.rect(getX(), getY(), getWidth(), getHeight()); - renderer.end(); - renderer.begin(ShapeRenderer.ShapeType.Line); - renderer.setColor(Color.RED); - renderer.rect(getX(), getY(), getWidth(), getHeight()); - renderer.end(); - batch.begin(); + int amount = 1+(int)(getHeight()/txt.getHeight()); + + batch.draw(txtTop, getX(), getY() + amount*txt.getHeight()); + for(int i = 0; i < amount; i++){ + batch.draw(txt, getX(), getY() + txt.getHeight()*i); + } + batch.draw(txtBot, getX(), getY() - txtBot.getHeight()); - font.draw(batch, toPrint.substring(0, (int)printChar), getX()+6, getY()+getHeight()-3, getWidth()-8, alignment, true); + font.setColor(TextColor); + font.draw(batch, toPrint.substring(0, (int)printChar), getX()+6, getY()+getHeight(), getWidth()-8, alignment, true); if(state == 1){ for(int i = 0; i < ans.length; i++){ if(selectedAsw == i){ - font.setColor(Color.RED); + font.setColor(SelectedColor); } - font.draw(batch, ans[i], getX()+20, (getY()+getHeight()-5) - (textHeight + i*(getTextHeight(font, "A")+5)) - 3, getWidth(), alignment, true); - font.setColor(Color.BLACK); + font.draw(batch, ans[i], getX()+20, (getY()+getHeight()-5) - (textHeight + i*(getTextHeight(font, "A")+5)), getWidth(), alignment, true); + + font.setColor(TextColor); } } + batch.end(); + camBatch.begin(); super.draw(batch, parentAlpha); } - /* - public ArrayList getSplitted(String toSplit, int maxLength){ - ArrayList words = new ArrayList<>(); - int tail = 0; - for(int head = 0; head < toSplit.length(); head++){ - if(toSplit.charAt(head) == ' '){ - words.add(toSplit.substring(tail, head+1)); - head++; - tail=head; - } - } - words.add(toSplit.substring(tail, toSplit.length())); - - ArrayList toReturn = new ArrayList<>(); - String string = new String(); - for(String s : words){ - if(getTextWidth(font,string)+getTextWidth(font,s) >= getWidth()){ - toReturn.add(string); - string = new String(); - string += s; - } - else if(getTextWidth(font,string)+getTextWidth(font,s) < getWidth()){ - string += s; - } - } - toReturn.add(string); - - System.out.println(getWidth()); - System.out.println(maxLength); - for(String s : toReturn){ - System.out.println("-"+s+"-"+getTextWidth(font,s)); - } - - return toReturn; - } -*/ public float getTextWidth(BitmapFont font, String text){ GlyphLayout glyphLayout = new GlyphLayout(); diff --git a/core/src/com/trs/main/view/screens/GameScreen.java b/core/src/com/trs/main/view/screens/GameScreen.java index 916538d..ac26e47 100644 --- a/core/src/com/trs/main/view/screens/GameScreen.java +++ b/core/src/com/trs/main/view/screens/GameScreen.java @@ -6,11 +6,14 @@ package com.trs.main.view.screens; import com.badlogic.gdx.Game; +import com.badlogic.gdx.math.Matrix4; import com.badlogic.gdx.math.Rectangle; import com.trs.main.Main; import com.trs.main.MapContainer; import com.trs.main.Quest; +import com.trs.main.fightscreen.FightDialogue; import com.trs.main.view.UI.QuestWindow; +import com.trs.main.view.UI.Textbox; import com.trs.main.worldobjects.Player; /** @@ -25,7 +28,11 @@ public class GameScreen extends AbstractScreen{ public GameScreen(Game game, float CAMERA_WIDTH, float CAMERA_HEIGHT) { super(game, CAMERA_WIDTH, CAMERA_HEIGHT); map = new MapContainer(CAMERA_WIDTH, CAMERA_HEIGHT, new Player(200, 200), "tiledmapData/maps/map1.tmx", 2, 1); - qw = new QuestWindow(); + qw = new QuestWindow(map.getCamera().combined); + Matrix4 uiMatrix = map.getCamera().combined.cpy(); + uiMatrix.setToOrtho2D(0, 0, Main.CAMERA_WIDTH, Main.CAMERA_HEIGHT); + Textbox.m = uiMatrix; + FightDialogue.m = uiMatrix; } public void loadNewMap(int map, int doorId){ @@ -48,7 +55,7 @@ public class GameScreen extends AbstractScreen{ } //qw.draw(rects, map.getStage().getBatch(), map.getPlayer().getX()+32, map.getPlayer().getY()+32); - qw.draw(rects, map.getStage().getBatch(), map.getStage().getCamera().position.x, map.getStage().getCamera().position.y ); + qw.draw(rects); if(map.getCollidingDoor() != null) { loadNewMap(map.getCollidingDoor().destinationMap, map.getCollidingDoor().destinationDoor); diff --git a/core/src/com/trs/main/worldobjects/InteractionObject.java b/core/src/com/trs/main/worldobjects/InteractionObject.java index 6ad685a..c06172b 100644 --- a/core/src/com/trs/main/worldobjects/InteractionObject.java +++ b/core/src/com/trs/main/worldobjects/InteractionObject.java @@ -9,7 +9,7 @@ import com.badlogic.gdx.scenes.scene2d.Actor; import com.trs.main.Dialogue; import com.trs.main.DialogueParser; import com.trs.main.Main; -import com.trs.main.Textbox; +import com.trs.main.view.UI.Textbox; public class InteractionObject extends Actor{ Textbox t; @@ -37,7 +37,7 @@ public class InteractionObject extends Actor{ dialoguePath = "mapData/map"+mapId+"/interactionObjects/"+id+"/dialogue.txt"; parser = new DialogueParser(dialoguePath); Dialogue nextDialogue = parser.firstDialogue(); - this.t = new Textbox(nextDialogue.question, nextDialogue.ans, getX()+getWidth()/2, getY()+getHeight()/2); + this.t = new Textbox(nextDialogue.question, nextDialogue.ans); setBounds(xPos, yPos, animatedSprite.getSprite().getWidth(), animatedSprite.getSprite().getHeight()); } @@ -53,14 +53,14 @@ public class InteractionObject extends Actor{ dialoguePath = "mapData/map"+mapId+"/interactionObjects/"+id+"/dialogue.txt"; parser = new DialogueParser(dialoguePath); Dialogue nextDialogue = parser.firstDialogue(); - this.t = new Textbox(nextDialogue.question, nextDialogue.ans, getX()+getWidth()/2, getY()+getHeight()/2); + this.t = new Textbox(nextDialogue.question, nextDialogue.ans); setBounds(xPos, yPos, collisionRect.getWidth(), collisionRect.getHeight()); } public void startDialogue(float xPos, float yPos) { currentlyTalking = true; - getStage().addActor(new Textbox(t, xPos, yPos)); + getStage().addActor(t); } @Override diff --git a/core/src/com/trs/main/worldobjects/MovingNpc.java b/core/src/com/trs/main/worldobjects/MovingNpc.java index 63e7a97..0a8b337 100644 --- a/core/src/com/trs/main/worldobjects/MovingNpc.java +++ b/core/src/com/trs/main/worldobjects/MovingNpc.java @@ -19,7 +19,7 @@ import com.trs.main.InformationQuest; import com.trs.main.Main; import com.trs.main.Quest; import com.trs.main.StaticMath; -import com.trs.main.Textbox; +import com.trs.main.view.UI.Textbox; /** * @@ -54,6 +54,7 @@ public class MovingNpc extends Actor{ private AnimatedSprite questBubble; public MovingNpc(Rectangle area, float xPos, float yPos, int id, int mapId, String texture){ + super(); setName("npc"); this.id = id; this.mapId = mapId; @@ -76,16 +77,17 @@ public class MovingNpc extends Actor{ dialoguePath = "mapData/map"+mapId+"/npcs/"+id+"/dialogue.txt"; parser = new DialogueParser(dialoguePath); Dialogue nextDialogue = parser.firstDialogue(); - this.t = new Textbox(nextDialogue.question, nextDialogue.ans, getX()+getWidth()/2, getY()+getHeight()/2); + this.t = new Textbox(nextDialogue.question, nextDialogue.ans); collisionRect = new Rectangle(xPos + 16, yPos, 32, 16); setBounds(xPos, yPos, animatedSprite.getSprite().getWidth(), animatedSprite.getSprite().getHeight()); + } public void startDialogue(float xPos, float yPos) { currentlyTalking = true; - getStage().addActor(new Textbox(t, xPos, yPos)); + getStage().addActor(t); } public void startSpecialDialogue(String path, float xPos, float yPos){ @@ -93,8 +95,8 @@ public class MovingNpc extends Actor{ currentlyTalking = true; specialDialogue = true; Dialogue nextDialogue = tempSpecialDialogueParser.firstDialogue(); - this.t = new Textbox(nextDialogue.question, nextDialogue.ans, getX()+getWidth()/2, getY()+getHeight()/2); - getStage().addActor(new Textbox(t, xPos, yPos)); + this.t = new Textbox(nextDialogue.question, nextDialogue.ans); + getStage().addActor(t); } @Override @@ -134,7 +136,7 @@ public class MovingNpc extends Actor{ specialDialogue = false; parser = new DialogueParser(dialoguePath); Dialogue nextDialogue = parser.firstDialogue(); - this.t = new Textbox(nextDialogue.question, nextDialogue.ans, getX()+getWidth()/2, getY()+getHeight()/2); + this.t = new Textbox(nextDialogue.question, nextDialogue.ans); tempSpecialDialogueParser = null; } else {