diff --git a/core/assets/textureData/UI/box.png b/core/assets/textureData/UI/box.png new file mode 100644 index 0000000..74aa27c Binary files /dev/null and b/core/assets/textureData/UI/box.png differ diff --git a/core/assets/textureData/UI/questbook.png b/core/assets/textureData/UI/questbook.png new file mode 100644 index 0000000..219e609 Binary files /dev/null and b/core/assets/textureData/UI/questbook.png differ diff --git a/core/assets/textureData/sprites/player.png b/core/assets/textureData/sprites/player.png index 98c4acc..2137080 100644 Binary files a/core/assets/textureData/sprites/player.png and b/core/assets/textureData/sprites/player.png differ diff --git a/core/src/com/trs/main/view/QuestWindow.java b/core/src/com/trs/main/view/QuestWindow.java deleted file mode 100644 index 62bc94e..0000000 --- a/core/src/com/trs/main/view/QuestWindow.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package com.trs.main.view; - -import com.badlogic.gdx.Gdx; -import com.badlogic.gdx.Input; -import com.badlogic.gdx.graphics.Color; -import com.badlogic.gdx.graphics.GL20; -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.freetype.FreeTypeFontGenerator; -import com.badlogic.gdx.graphics.glutils.ShapeRenderer; -import com.badlogic.gdx.math.Rectangle; -import com.trs.main.InformationQuest; -import com.trs.main.Main; -import com.trs.main.Quest; - -/** - * - * @author janeh - */ - -public class QuestWindow { - - BitmapFont font; - ShapeRenderer renderer; - boolean visible; - int selectedQuest; - - public QuestWindow(){ - renderer = new ShapeRenderer(); - visible = true; - selectedQuest = 0; - - 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.WHITE); - } - - public void draw(Quest[] quests, Batch batch, float playerX, float playerY){ - if(Main.gamestate == 2) visible = false; - else visible = true; - - if(Gdx.input.isKeyJustPressed(Input.Keys.RIGHT)){ - if(selectedQuest < quests.length-1){ - selectedQuest++; - } - } - if(Gdx.input.isKeyJustPressed(Input.Keys.LEFT)){ - if(selectedQuest > 0){ - selectedQuest--; - } - } - - if(visible){ - float boxX = playerX + Main.CAMERA_WIDTH/2 - 150; - float boxY = playerY + Main.CAMERA_HEIGHT/2 - 250; - float boxWidth = 140; - float boxHeight = 240; - - renderer.setProjectionMatrix(batch.getProjectionMatrix()); - Gdx.gl.glEnable(GL20.GL_BLEND); - Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); - renderer.begin(ShapeRenderer.ShapeType.Filled); - renderer.setColor(0.1f, 0.1f, 0.1f, 0.5f); - renderer.rect(boxX, boxY, boxWidth, boxHeight); - renderer.end(); - batch.begin(); - font.draw(batch, quests[selectedQuest].getQuestName(), boxX + 10, boxY + boxHeight - getTextHeight("A") - 10); - if(quests[selectedQuest] instanceof InformationQuest){ - InformationQuest quest = (InformationQuest)quests[selectedQuest]; - font.getData().setScale(0.8f); - for(int i = 0; i < quest.getInformationNpcId().length; i++){ - font.draw(batch, "MAP: " + quest.getInformationNpcMapId()[i] + " NPC: " - + quest.getInformationNpcId()[i], boxX + 10, boxY + boxHeight - getTextHeight("A") - 10 - ((i+1) * (getTextHeight("A") + 10))); - } - font.getData().setScale(1f); - } - batch.end(); - Gdx.gl.glDisable(GL20.GL_BLEND); - } - } - - public float getTextWidth(String text){ - GlyphLayout glyphLayout = new GlyphLayout(); - glyphLayout.setText(font,text); - return glyphLayout.width; - } - public float getTextHeight(String text){ - GlyphLayout glyphLayout = new GlyphLayout(); - glyphLayout.setText(font,text); - return glyphLayout.height; - } -} diff --git a/core/src/com/trs/main/view/UI/QuestWindow.java b/core/src/com/trs/main/view/UI/QuestWindow.java new file mode 100644 index 0000000..6126b35 --- /dev/null +++ b/core/src/com/trs/main/view/UI/QuestWindow.java @@ -0,0 +1,163 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +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.GL20; +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.Rectangle; +import com.trs.main.InformationQuest; +import com.trs.main.Main; +import com.trs.main.Quest; + +/** + * + * @author janeh + */ + +public class QuestWindow { + + BitmapFont font; + ShapeRenderer renderer; + boolean visible; + int selectedQuest; + + double visiblePerc; + + public QuestWindow(){ + renderer = new ShapeRenderer(); + visible = true; + selectedQuest = 0; + + 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.WHITE); + } + + public void draw(Quest[] quests, Batch batch, float playerX, float playerY){ + + if(Gdx.input.isKeyJustPressed(Input.Keys.RIGHT)){ + if(selectedQuest < quests.length-1){ + selectedQuest++; + } + } + if(Gdx.input.isKeyJustPressed(Input.Keys.LEFT)){ + if(selectedQuest > 0){ + selectedQuest--; + } + } + + + float boxX = playerX + Main.CAMERA_WIDTH/2 - 0.2f*Main.CAMERA_WIDTH - 30; + 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; + + renderer.setProjectionMatrix(batch.getProjectionMatrix()); + + if(visible && Main.gamestate != 2){ + if(visiblePerc < 1){ + visiblePerc += 0.2; + Gdx.gl.glEnable(GL20.GL_BLEND); + Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); + renderer.begin(ShapeRenderer.ShapeType.Filled); + renderer.setColor(0.1f, 0.1f, 0.1f, 0.5f); + renderer.rect((float)(boxX + boxWidth-(boxWidth * visiblePerc)), (float)(boxY + boxHeight-(boxHeight * visiblePerc)), (float)(boxWidth * visiblePerc), (float)(boxHeight * visiblePerc)); + renderer.end(); + Gdx.gl.glDisable(GL20.GL_BLEND); + UIDrawer.drawCharBox(batch, font, boxX + boxWidth - 16 , boxY + boxHeight - 16, 32, "^"); + } + else{ + Gdx.gl.glEnable(GL20.GL_BLEND); + Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); + renderer.begin(ShapeRenderer.ShapeType.Filled); + renderer.setColor(0.1f, 0.1f, 0.1f, 0.5f); + renderer.rect(boxX, boxY, boxWidth, boxHeight); + renderer.end(); + + + + batch.begin(); + font.draw(batch, quests[selectedQuest].getQuestName(), boxX + 10, boxY + boxHeight - getTextHeight("A") - 10); + if(quests[selectedQuest] instanceof InformationQuest){ + InformationQuest quest = (InformationQuest)quests[selectedQuest]; + font.getData().setScale(0.6f); + for(int i = 0; i < quest.getInformationNpcId().length; i++){ + if(quest.getTalked()[i]){ + font.draw(batch, "MAP: " + quest.getInformationNpcMapId()[i] + " NPC: " + + quest.getInformationNpcId()[i] +" true", boxX + 10, boxY + boxHeight - getTextHeight("A") - 15 - ((i+1) * (getTextHeight("A") + 15))); + } + else{ + font.draw(batch, "MAP: " + quest.getInformationNpcMapId()[i] + " NPC: " + + quest.getInformationNpcId()[i] +" false", boxX + 10, boxY + boxHeight - getTextHeight("A") - 15 - ((i+1) * (getTextHeight("A") + 15))); + } + } + font.getData().setScale(1f); + } + batch.end(); + + if(selectedQuest > 0){ + UIDrawer.drawCharBox(batch, font, boxX - 16 , boxY + boxHeight/2 - 16, 32, "<"); + } + if(selectedQuest < quests.length-1){ + UIDrawer.drawCharBox(batch, font, boxX + boxWidth - 16 , boxY + boxHeight/2 - 16, 32, ">"); + } + + UIDrawer.drawCharBox(batch, font, boxX + boxWidth - 16 , boxY + boxHeight - 16, 32, "^"); + + UIDrawer.drawIcon(batch, boxX + boxWidth/2, boxY + boxHeight, 0); + + Gdx.gl.glDisable(GL20.GL_BLEND); + } + + if(Gdx.input.isKeyJustPressed(Input.Keys.UP)){ + visible = false; + } + + } + else{ + if(visiblePerc > 0){ + visiblePerc -= 0.2; + Gdx.gl.glEnable(GL20.GL_BLEND); + Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); + renderer.begin(ShapeRenderer.ShapeType.Filled); + renderer.setColor(0.1f, 0.1f, 0.1f, 0.5f); + renderer.rect((float)(boxX + boxWidth-(boxWidth * visiblePerc)), (float)(boxY + boxHeight-(boxHeight * visiblePerc)),(float)(boxWidth * visiblePerc), (float)(boxHeight * visiblePerc)); + renderer.end(); + Gdx.gl.glDisable(GL20.GL_BLEND); + UIDrawer.drawCharBox(batch, font, boxX + boxWidth - 16 , boxY + boxHeight - 16, 32, "V"); + } + else{ + UIDrawer.drawCharBox(batch, font, boxX + boxWidth - 16 , boxY + boxHeight - 16, 32, "V"); + UIDrawer.drawIcon(batch, boxX + boxWidth - 16 , boxY + boxHeight - 16, 0); + } + if(Gdx.input.isKeyJustPressed(Input.Keys.DOWN)){ + visible = true; + } + } + } + + public float getTextWidth(String text){ + GlyphLayout glyphLayout = new GlyphLayout(); + glyphLayout.setText(font,text); + return glyphLayout.width; + } + public float getTextHeight(String text){ + GlyphLayout glyphLayout = new GlyphLayout(); + glyphLayout.setText(font,text); + return glyphLayout.height; + } +} diff --git a/core/src/com/trs/main/view/UI/UIDrawer.java b/core/src/com/trs/main/view/UI/UIDrawer.java new file mode 100644 index 0000000..8758f18 --- /dev/null +++ b/core/src/com/trs/main/view/UI/UIDrawer.java @@ -0,0 +1,66 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package com.trs.main.view.UI; + +import com.badlogic.gdx.Gdx; +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.Sprite; + +/** + * + * @author janeh + */ +public class UIDrawer { + + static Sprite box32 = new Sprite(new Texture(Gdx.files.internal("textureData/UI/box.png"))); + static Texture questbook = new Texture(Gdx.files.internal("textureData/UI/questbook.png")); + + static void drawCharBox(Batch batch, BitmapFont font, float x, float y, int size, String character){ + if(!batch.isDrawing()) batch.begin(); + font.setColor(Color.WHITE); + switch(size){ + case 16: + font.draw(batch, ""+character, x + 16 - getTextWidth(font, character)/2, y + 16 - getTextHeight(font, character)/2); + break; + case 32: + box32.setPosition(x, y); + box32.draw(batch); + font.getData().setScale(1.5f); + font.draw(batch, ""+character, x + 16 - getTextWidth(font, character)/2, y + 16 + (getTextHeight(font, character)/2) - 2); + font.getData().setScale(1); + break; + } + + batch.end(); + } + + static void drawIcon(Batch batch, float x, float y, int iconID){ + if(!batch.isDrawing()) batch.begin(); + switch(iconID){ + case 0: + batch.draw(questbook, x - questbook.getWidth()/2, y - questbook.getHeight()/2); + break; + } + + batch.end(); + } + + static float getTextWidth(BitmapFont font, String text){ + GlyphLayout glyphLayout = new GlyphLayout(); + glyphLayout.setText(font,text); + return glyphLayout.width; + } + static float getTextHeight(BitmapFont font, String text){ + GlyphLayout glyphLayout = new GlyphLayout(); + glyphLayout.setText(font,text); + return glyphLayout.height; + } + +} diff --git a/core/src/com/trs/main/view/screens/GameScreen.java b/core/src/com/trs/main/view/screens/GameScreen.java index 46ea7df..658446a 100644 --- a/core/src/com/trs/main/view/screens/GameScreen.java +++ b/core/src/com/trs/main/view/screens/GameScreen.java @@ -10,7 +10,7 @@ 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.view.QuestWindow; +import com.trs.main.view.UI.QuestWindow; import com.trs.main.worldobjects.Player; /**