feat: final game space sizing
Also fixes logo after changing ui scale
This commit is contained in:
@@ -19,7 +19,7 @@ public class Space {
|
||||
* Space saves the current state of the game map
|
||||
*/
|
||||
public Space() {
|
||||
gameMap = new Color[20][12];
|
||||
gameMap = new Color[19][10];
|
||||
nextShape = generateNextShape();
|
||||
score = 0;
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import java.awt.event.ActionEvent;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.KeyListener;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import static eu.midnightdust.yaytris.Settings.guiScale;
|
||||
import static eu.midnightdust.yaytris.Translation.t;
|
||||
@@ -20,6 +21,7 @@ public class TetrisUI extends JFrame implements KeyListener {
|
||||
JLabel titleLabel;
|
||||
GameCanvas gamePanel;
|
||||
JPanel menuPanel;
|
||||
Image titleImage;
|
||||
|
||||
/**
|
||||
* Initialize the main Tetris GUI based on Swing
|
||||
@@ -35,14 +37,13 @@ public class TetrisUI extends JFrame implements KeyListener {
|
||||
|
||||
titleLabel = new JLabel("Tetris");
|
||||
titleLabel.setForeground(Color.WHITE);
|
||||
Image titleImage;
|
||||
try {
|
||||
titleImage = ImageIO.read(this.getClass().getResourceAsStream("/textures/logo.png"));
|
||||
try (InputStream stream = this.getClass().getResourceAsStream("/textures/logo.png")) {
|
||||
assert stream != null;
|
||||
titleImage = ImageIO.read(stream);
|
||||
} catch (IOException | NullPointerException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
titleLabel = new JLabel();
|
||||
titleLabel.setIcon(new ImageIcon(new ImageIcon(titleImage).getImage().getScaledInstance(scale(110), scale(30), Image.SCALE_DEFAULT)));
|
||||
this.add(titleLabel);
|
||||
|
||||
gamePanel = new GameCanvas(this);
|
||||
@@ -63,7 +64,8 @@ public class TetrisUI extends JFrame implements KeyListener {
|
||||
private void rescale() {
|
||||
this.setSize((int) (400 * guiScale), (int) (300 * guiScale));
|
||||
titleLabel.setBounds(scale(225), scale(7), scale(110), scale(30));
|
||||
gamePanel.setBounds(scale(10), scale(10), scale(150), scale(256));
|
||||
titleLabel.setIcon(new ImageIcon(new ImageIcon(titleImage).getImage().getScaledInstance(scale(110), scale(30), Image.SCALE_DEFAULT)));
|
||||
gamePanel.setBounds(scale(10), scale(10), scale(150), scale(282));
|
||||
for (Component comp : this.getComponents()){
|
||||
if (comp instanceof JComponent) setFontScale((JComponent) comp);
|
||||
}
|
||||
@@ -110,7 +112,7 @@ public class TetrisUI extends JFrame implements KeyListener {
|
||||
if (this.menuPanel != null) this.remove(menuPanel);
|
||||
Tetris.resetSpace();
|
||||
rescale();
|
||||
menuPanel = new MainMenu(scale(170), scale(40), scale(220), scale(226), this);
|
||||
menuPanel = new MainMenu(scale(170), scale(40), scale(220), scale(252), this);
|
||||
menuPanel.setBackground(CatppuccinColor.BASE.getColor());
|
||||
menuPanel.setBorder(new LineBorder(CatppuccinColor.SURFACE0.getColor(), scale(2)));
|
||||
this.add(menuPanel);
|
||||
@@ -126,7 +128,7 @@ public class TetrisUI extends JFrame implements KeyListener {
|
||||
*/
|
||||
public void openSettings(ActionEvent actionEvent) {
|
||||
if (this.menuPanel != null) this.remove(menuPanel);
|
||||
menuPanel = new SettingsMenu(scale(170), scale(40), scale(220), scale(226), this);
|
||||
menuPanel = new SettingsMenu(scale(170), scale(40), scale(220), scale(252), this);
|
||||
menuPanel.setBackground(CatppuccinColor.BASE.getColor());
|
||||
menuPanel.setBorder(new LineBorder(CatppuccinColor.SURFACE0.getColor(), scale(2)));
|
||||
this.add(menuPanel);
|
||||
@@ -140,7 +142,7 @@ public class TetrisUI extends JFrame implements KeyListener {
|
||||
*/
|
||||
public void openScoreMenu(ActionEvent actionEvent) {
|
||||
if (this.menuPanel != null) this.remove(menuPanel);
|
||||
menuPanel = new ScoreMenu(scale(170), scale(40), scale(220), scale(226), this);
|
||||
menuPanel = new ScoreMenu(scale(170), scale(40), scale(220), scale(252), this);
|
||||
menuPanel.setBackground(CatppuccinColor.BASE.getColor());
|
||||
menuPanel.setBorder(new LineBorder(CatppuccinColor.SURFACE0.getColor(), scale(2)));
|
||||
this.add(menuPanel);
|
||||
@@ -154,7 +156,7 @@ public class TetrisUI extends JFrame implements KeyListener {
|
||||
*/
|
||||
public void openHighscores(ActionEvent actionEvent) {
|
||||
if (this.menuPanel != null) this.remove(menuPanel);
|
||||
menuPanel = new HighScoreMenu(scale(170), scale(40), scale(220), scale(226), this);
|
||||
menuPanel = new HighScoreMenu(scale(170), scale(40), scale(220), scale(252), this);
|
||||
menuPanel.setBackground(CatppuccinColor.BASE.getColor());
|
||||
menuPanel.setBorder(new LineBorder(CatppuccinColor.SURFACE0.getColor(), scale(2)));
|
||||
this.add(menuPanel);
|
||||
|
||||
Reference in New Issue
Block a user