Skip to content

Commit 92715e7

Browse files
committed
Added new clock UI and logic for it.
1 parent 8bdef66 commit 92715e7

10 files changed

Lines changed: 116 additions & 35 deletions

File tree

β€Žsave.datβ€Ž

5.82 KB
Binary file not shown.

β€Žsrc/main/java/com/khomsi/game/entity/Entity.javaβ€Ž

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,14 @@
77
import com.khomsi.game.objects.gui.ManaObject;
88
import com.khomsi.game.objects.interact.CoinBObject;
99

10-
import javax.imageio.ImageIO;
1110
import java.awt.*;
1211
import java.awt.image.BufferedImage;
13-
import java.io.IOException;
1412
import java.util.ArrayList;
1513
import java.util.List;
16-
import java.util.Objects;
1714
import java.util.Random;
1815

1916
//parent class for player, monster etc
20-
public class Entity {
17+
public class Entity extends Tools{
2118
//IMAGES
2219
public BufferedImage image, image2, image3;
2320
//Store our walking images in this variables
@@ -130,7 +127,8 @@ public class Entity {
130127
public Rectangle attackArea = new Rectangle(0, 0, 0, 0);
131128
public int solidAreaDefaultX, solidAreaDefaultY;
132129
public GameManager gameManager;
133-
public Tools tools = new Tools();
130+
//FIXME
131+
// public Tools tools = new Tools();
134132
public ProjectTile projectTile;
135133
public Entity attacker;
136134
public String knockBackDirection;
@@ -450,23 +448,6 @@ private void dieAnimation(Graphics2D graphics2D) {
450448
}
451449
}
452450

453-
//Method with default values for images
454-
public BufferedImage setup(String imageName) {
455-
return setup(imageName, GameManager.TILE_SIZE, GameManager.TILE_SIZE);
456-
}
457-
458-
public BufferedImage setup(String imagePath, int width, int height) {
459-
BufferedImage image = null;
460-
try {
461-
image = ImageIO.read(Objects.requireNonNull(
462-
getClass().getResourceAsStream(imagePath + ".png")));
463-
image = tools.scaledImage(image, width, height);
464-
} catch (IOException e) {
465-
System.err.println("Error in setup in " + getClass().getSimpleName());
466-
e.printStackTrace();
467-
}
468-
return image;
469-
}
470451

471452
private void changeAlfa(Graphics2D graphics2D, float alfaValue) {
472453
graphics2D.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alfaValue));

β€Žsrc/main/java/com/khomsi/game/enviroment/Lightning.javaβ€Ž

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.khomsi.game.enviroment;
22

33
import com.khomsi.game.main.GameManager;
4+
import com.khomsi.game.main.tools.Tools;
45

56
import java.awt.*;
67
import java.awt.image.BufferedImage;
@@ -17,6 +18,7 @@ public class Lightning {
1718
public static final int NIGHT = 2;
1819
public static final int DAWN = 3;
1920
public int dayState = DAY;
21+
Tools tools = new Tools();
2022

2123
public Lightning(GameManager gameManager) {
2224
this.gameManager = gameManager;
@@ -86,7 +88,6 @@ public void update() {
8688
setLightSource();
8789
gameManager.player.lightUpdated = false;
8890
}
89-
//TODO adjust settings with day-night
9091
//Check the state of the day
9192
if (dayState == DAY) {
9293
dayCounter++;
@@ -127,16 +128,22 @@ public void draw(Graphics2D g2d) {
127128
g2d.drawImage(darknessFilter, 0, 0, null);
128129
}
129130
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1F));
130-
//Debug
131-
String situation = "";
132-
switch (dayState) {
133-
case DAY -> situation = "Day";
134-
case NIGHTFALL -> situation = "NightFall";
135-
case NIGHT -> situation = "Night";
136-
case DAWN -> situation = "Dawn";
131+
debugDayState(g2d);
132+
gameManager.ui.drawClock(g2d, dayState, filterAlfa);
133+
}
134+
135+
private void debugDayState(Graphics2D g2d) {
136+
if (gameManager.keyHandler.debugMode) {
137+
String situation = "";
138+
switch (dayState) {
139+
case DAY -> situation = "Day";
140+
case NIGHTFALL -> situation = "NightFall";
141+
case NIGHT -> situation = "Night";
142+
case DAWN -> situation = "Dawn";
143+
}
144+
g2d.setColor(Color.WHITE);
145+
g2d.setFont(g2d.getFont().deriveFont(45F));
146+
g2d.drawString(situation, 750, 500);
137147
}
138-
g2d.setColor(Color.WHITE);
139-
g2d.setFont(g2d.getFont().deriveFont(45F));
140-
g2d.drawString(situation, 750, 500);
141148
}
142149
}

β€Žsrc/main/java/com/khomsi/game/main/tools/Tools.javaβ€Ž

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33
import com.khomsi.game.main.GameManager;
44

5+
import javax.imageio.ImageIO;
56
import java.awt.*;
67
import java.awt.image.BufferedImage;
8+
import java.io.IOException;
9+
import java.util.Objects;
710

811
public class Tools {
912
public BufferedImage scaledImage(BufferedImage image, int width, int height) {
@@ -29,4 +32,22 @@ public void optimizeMapDraw(Graphics2D graphics2D, BufferedImage image, GameMana
2932
GameManager.TILE_SIZE, GameManager.TILE_SIZE, null);
3033
}
3134
}
35+
36+
//Method with default values for images
37+
public BufferedImage setup(String imageName) {
38+
return setup(imageName, GameManager.TILE_SIZE, GameManager.TILE_SIZE);
39+
}
40+
41+
public BufferedImage setup(String imagePath, int width, int height) {
42+
BufferedImage image = null;
43+
try {
44+
image = ImageIO.read(Objects.requireNonNull(
45+
getClass().getResourceAsStream(imagePath + ".png")));
46+
image = scaledImage(image, width, height);
47+
} catch (IOException e) {
48+
System.err.println("Error in setup in " + getClass().getSimpleName());
49+
e.printStackTrace();
50+
}
51+
return image;
52+
}
3253
}

β€Žsrc/main/java/com/khomsi/game/main/tools/UI.javaβ€Ž

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.khomsi.game.main.tools;
22

33
import com.khomsi.game.entity.Entity;
4-
import com.khomsi.game.enviroment.Lightning;
54
import com.khomsi.game.main.GameManager;
65
import com.khomsi.game.objects.gui.HeartObject;
76
import com.khomsi.game.objects.gui.ManaObject;
@@ -14,11 +13,15 @@
1413
import java.util.ArrayList;
1514
import java.util.List;
1615

16+
import static com.khomsi.game.enviroment.Lightning.*;
17+
1718
public class UI {
1819
GameManager gameManager;
1920
Graphics2D graphics2D;
21+
Tools tools = new Tools();
2022
public Font playMeGames;
2123
BufferedImage heartFull, heartHalf, heartEmpty, manaFull, manaEmpty, coin;
24+
private BufferedImage arrow, sun, moon, line, nightFall;
2225
List<String> message = new ArrayList<>();
2326
List<Integer> messageCounter = new ArrayList<>();
2427
public String currentDialog = "";
@@ -125,7 +128,7 @@ private void drawSleepScreen() {
125128
if (gameManager.enManagement.lightning.filterAlfa <= 0F) {
126129
gameManager.enManagement.lightning.filterAlfa = 0F;
127130
counter = 0;
128-
gameManager.enManagement.lightning.dayState = Lightning.DAY;
131+
gameManager.enManagement.lightning.dayState = DAY;
129132
gameManager.enManagement.lightning.dayCounter = 0;
130133
gameManager.gameState = GameManager.PLAY_STATE;
131134
gameManager.player.getImage();
@@ -903,6 +906,75 @@ private void fullScreenNotification(int frameX, int frameY) {
903906
}
904907
}
905908

909+
public void drawClock(Graphics2D g2d, int dayState, float filterAlfa) {
910+
int clockX = 730;
911+
int clockY = 50;
912+
int clockGap = 42;
913+
int clockWidth = GameManager.TILE_SIZE * 6;
914+
int clockHeight = (int) (GameManager.TILE_SIZE * 1.3);
915+
final int LINE_COUNT = 5;
916+
final int WINDOW_OFFSET_X = 20;
917+
final int WINDOW_OFFSET_Y = 4;
918+
int startX = clockX - WINDOW_OFFSET_X - 1;
919+
int endX = clockX + (clockGap * 4 + 1) + WINDOW_OFFSET_X;
920+
921+
moon = tools.setup("/clock/clock_moon");
922+
sun = tools.setup("/clock/clock_sun");
923+
arrow = tools.setup("/clock/clock_arrow");
924+
line = tools.setup("/clock/clock_line");
925+
//Add the NightFall day
926+
nightFall = tools.setup("/clock/clock_nightfall");
927+
928+
if (gameManager.gameState != GameManager.CHARACTER_STATE) {
929+
//Draw window for clocks
930+
drawRoundUiWindow(clockX - WINDOW_OFFSET_X, clockY - WINDOW_OFFSET_Y, clockWidth, clockHeight, g2d);
931+
// Draw lines
932+
for (int i = 0; i < LINE_COUNT; i++) {
933+
int xPos = clockX + (clockGap * i);
934+
g2d.drawImage(line, xPos, clockY + WINDOW_OFFSET_Y, null);
935+
}
936+
int xPos = clockX + (clockGap * 4 + 1);
937+
int yPos = (int) (clockY - WINDOW_OFFSET_Y * 3.2);
938+
g2d.drawImage(moon, xPos + WINDOW_OFFSET_X, yPos, null);
939+
940+
xPos = (xPos - clockGap * 2);
941+
yPos = yPos - WINDOW_OFFSET_Y;
942+
g2d.drawImage(nightFall, xPos, yPos, null);
943+
944+
xPos = startX + 1;
945+
g2d.drawImage(sun, xPos, yPos, null);
946+
947+
// Calculate arrow position based on dayState and filterAlfa
948+
int arrowX;
949+
int arrowY = clockY + WINDOW_OFFSET_Y * 6;
950+
951+
if (dayState == DAY) {
952+
arrowX = startX;
953+
} else if (dayState == NIGHTFALL || dayState == NIGHT) {
954+
arrowX = (int) (startX + (endX - startX) * filterAlfa);
955+
} else { // DAWN
956+
arrowX = endX - (int) ((endX - startX) * filterAlfa);
957+
958+
// Reverse the arrow movement during the dawn phase
959+
arrowX = endX - (arrowX - startX);
960+
961+
if (arrowX < startX) {
962+
arrowX = startX;
963+
}
964+
}
965+
g2d.drawImage(arrow, arrowX, arrowY, null);
966+
}
967+
}
968+
969+
//TODO Move setup to separate class and call here
970+
public void drawRoundUiWindow(int x, int y, int width, int height, Graphics2D g2d) {
971+
//Less %, more transparent
972+
int alpha = 120; // % transparent
973+
Color color = new Color(36, 36, 36, alpha);
974+
g2d.setColor(color);
975+
g2d.fillRoundRect(x, y, width, height, 8, 8);
976+
}
977+
906978
private void showControl(int frameX, int frameY) {
907979
int textX;
908980
int textY;
131 Bytes
Loading
165 Bytes
Loading
153 Bytes
Loading
141 Bytes
Loading
159 Bytes
Loading

0 commit comments

Comments
Β (0)