fix: Windows support

eww...
This commit is contained in:
Martin Prokoph
2025-09-08 18:27:22 +02:00
parent 223c3356b9
commit 7cbe2466d8
9 changed files with 30 additions and 15 deletions

View File

@@ -9,6 +9,10 @@ Können Sie meinen Highscore schlagen?
![Screenshot des Tetris-Spiels](assets/ingame.png)
## Im Falle einer IllegalArgumentException
Eclipse ist unfähig Java-Konventionen zu befolgen und fügt den resources-Ordner nicht automatisch zum classpath hinzu.
Um das zu beheben, gehen Sie in die Projekteinstellungen -> Java Build Path -> Source und fügen Sie den resources-Ordner manuell hinzu.
## Rechtliche Hinweise
»Tetris« ist eine eingetragene Marke von The Tetris Company, Inc.
Die Verwendung des Namens »Tetris« und des Spielkonzepts erfolgen lediglich zu Bildungszwecken.

View File

@@ -1,16 +1,22 @@
package eu.midnightdust.yaytris.ui;
import eu.midnightdust.yaytris.util.CatppuccinColor;
import javax.swing.*;
import java.awt.*;
import static eu.midnightdust.yaytris.ui.TetrisUI.scale;
import static eu.midnightdust.yaytris.ui.TetrisUI.setFontScale;
public class AbstractMenu extends JPanel {
@Override
public Component add(Component comp) {
comp.setBounds(scale(60), scale(20+getSpacing()*this.getComponentCount()), scale(100), scale(20));
if (comp instanceof JComponent) setFontScale((JComponent) comp);
if (comp instanceof JLabel) {
comp.setForeground(CatppuccinColor.TEXT.getColor());
}
if (comp instanceof JComponent) {
((JComponent) comp).setOpaque(false);
}
return super.add(comp);
}

View File

@@ -29,11 +29,13 @@ public class HighScoreMenu extends JPanel {
highscores.sort((s1, s2) -> Integer.compare(Integer.parseInt(s2.split("")[0].replace(" ", "")), Integer.parseInt(s1.split("")[0].replace(" ", ""))));
JList<String> highscoreList = new JList<>(highscores.toArray(String[]::new));
highscoreList.setBackground(CatppuccinColor.BASE.getColor());
highscoreList.setForeground(CatppuccinColor.TEXT.getColor());
highscoreList.setSelectionForeground(CatppuccinColor.CRUST.getColor());
JScrollPane highscoreScrollPane = new JScrollPane(highscoreList);
highscoreScrollPane.setBorder(new LineBorder(CatppuccinColor.SURFACE0.getColor(), 3, true));
this.add(highscoreScrollPane);
highscoreScrollPane.setBounds(scale(60), scale(43), scale(100), scale(80));
highscoreList.setBounds(scale(60), scale(43), scale(100), scale(80));
JButton backButton = new JButton(t("ui.back"));
backButton.addActionListener(ui::openMainMenu);
@@ -45,6 +47,10 @@ public class HighScoreMenu extends JPanel {
public Component add(Component comp) {
if (comp instanceof JLabel) {
comp.setBounds(scale(60), scale(30), scale(100), scale(7));
comp.setForeground(CatppuccinColor.TEXT.getColor());
}
if (comp instanceof JComponent) {
((JComponent) comp).setOpaque(false);
}
return super.add(comp);
}

View File

@@ -2,6 +2,7 @@ package eu.midnightdust.yaytris.ui;
import eu.midnightdust.yaytris.Settings;
import eu.midnightdust.yaytris.Translation;
import eu.midnightdust.yaytris.util.CatppuccinColor;
import eu.midnightdust.yaytris.util.Difficulty;
import eu.midnightdust.yaytris.util.Language;
@@ -10,7 +11,6 @@ import java.awt.*;
import static eu.midnightdust.yaytris.Translation.t;
import static eu.midnightdust.yaytris.ui.TetrisUI.scale;
import static eu.midnightdust.yaytris.ui.TetrisUI.setFontScale;
public class SettingsMenu extends JPanel {
final TetrisUI ui;
@@ -87,9 +87,10 @@ public class SettingsMenu extends JPanel {
comp.setBounds(scale(60), scale(20+17*this.getComponentCount()-labelAmount*10), scale(100), scale(20));
if (comp instanceof JLabel) {
comp.setBounds(scale(60), scale(20+17*(this.getComponentCount())-labelAmount*10), scale(100), scale(7));
comp.setForeground(CatppuccinColor.TEXT.getColor());
labelAmount++;
}
if (comp instanceof JComponent) setFontScale((JComponent) comp);
if (comp instanceof JComponent) ((JComponent) comp).setOpaque(false);
return super.add(comp);
}
}

View File

@@ -29,7 +29,7 @@ public class TetrisUI extends JFrame implements KeyListener {
public TetrisUI() {
this.setLayout(null);
this.setTitle("Tetris");
this.setSize((int) (400 * guiScale), (int) (300 * guiScale));
this.setSize((int) (400 * guiScale), (int) (320 * guiScale));
this.setResizable(false);
this.getContentPane().setBackground(CatppuccinColor.MANTLE.getColor());
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
@@ -62,13 +62,10 @@ public class TetrisUI extends JFrame implements KeyListener {
* Resize all elements to match the current GUI scale.
*/
private void rescale() {
this.setSize((int) (400 * guiScale), (int) (300 * guiScale));
this.setSize((int) (400 * guiScale), (int) (320 * guiScale));
titleLabel.setBounds(scale(225), scale(7), scale(110), scale(30));
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);
}
}
/**
@@ -79,9 +76,6 @@ public class TetrisUI extends JFrame implements KeyListener {
public static int scale(int bound) {
return (int) (bound * guiScale);
}
public static void setFontScale(JComponent label) {
//if (label.getFont() != null) label.setFont(label.getFont().deriveFont((float) label.getFont().getSize() * guiScale));
}
public GameCanvas getGamePanel() {
return gamePanel;

View File

@@ -6,7 +6,7 @@ import java.awt.*;
* Color scheme based on the <a href="https://github.com/catppuccin/catppuccin">Catppuccin Mocha</a> color palette
*/
public enum CatppuccinColor {
CRUST(0x11111b), MANTLE(0x181825), BASE(0x1e1e2e), SURFACE0(0x313244);
TEXT(0xcdd6f4), CRUST(0x11111b), MANTLE(0x181825), BASE(0x1e1e2e), SURFACE0(0x313244);
final Color color;
CatppuccinColor(int rgb) {

View File

@@ -65,6 +65,8 @@ public class MusicThread extends Thread {
sourceDataLine.close();
} catch (LineUnavailableException | IOException | UnsupportedAudioFileException e) {
throw new RuntimeException(e);
} catch (IllegalArgumentException ignored) {
// Happens when no audio device is connected
}
}
}

View File

@@ -52,6 +52,8 @@ public class SoundUtil {
setVolume(audioClip, Settings.soundVolume);
} catch (LineUnavailableException | IOException | UnsupportedAudioFileException e) {
throw new RuntimeException(e);
} catch (IllegalArgumentException ignored) {
// Happens when no audio device is connected
}
}

View File

@@ -1,10 +1,10 @@
{
// Volume of theme music (0-100)
"musicVolume": 30,
"musicVolume": 100,
// Volume of sound effects (0-100)
"soundVolume": 100,
// Amount the user interface should be scaled
"guiScale": 5.7,
"guiScale": 2.00,
// Whether speed should scale with level (true/false)
"shouldScaleSpeed": true,
// One of [Noob, Easy, Normal, Hard, Extreme, WTF]