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