refactor: Don't use deprecated API

This commit is contained in:
2026-01-02 13:05:25 +01:00
parent 86f2159750
commit 17d162bd76
2 changed files with 12 additions and 4 deletions

View File

@@ -109,7 +109,7 @@ public class FullRoomDrawHandler extends AbstractEventHandler<FullRoomDraw> {
// Screen too small to fit the room // Screen too small to fit the room
eventManager.emitEvent(new TerminalTooSmallEvent()); eventManager.emitEvent(new TerminalTooSmallEvent());
renderState.setTerminalTooSmall(true); renderState.setTerminalTooSmall(true);
log.error("Terminal too small", e); //log.error("Terminal too small", e);
} }
} }

View File

@@ -14,6 +14,8 @@ import cz.jzitnik.utils.DependencyManager;
import cz.jzitnik.utils.events.AbstractEventHandler; import cz.jzitnik.utils.events.AbstractEventHandler;
import java.io.IOException; import java.io.IOException;
import java.util.EnumSet;
import java.util.HashSet;
@EventHandler(TerminalTooSmallEvent.class) @EventHandler(TerminalTooSmallEvent.class)
public class TerminalTooSmallEventHandler extends AbstractEventHandler<TerminalTooSmallEvent> { public class TerminalTooSmallEventHandler extends AbstractEventHandler<TerminalTooSmallEvent> {
@@ -26,9 +28,10 @@ public class TerminalTooSmallEventHandler extends AbstractEventHandler<TerminalT
@Override @Override
public void handle(TerminalTooSmallEvent event) { public void handle(TerminalTooSmallEvent event) {
// Directly render message for the user // Directly render the message for the user
TerminalScreen terminalScreen = terminalState.getTerminalScreen(); TerminalScreen terminalScreen = terminalState.getTerminalScreen();
terminalScreen.clear(); terminalScreen.clear();
var tg = terminalState.getTextGraphics();
TerminalSize terminalSize = terminalScreen.getTerminalSize(); TerminalSize terminalSize = terminalScreen.getTerminalSize();
String text = "Terminal too small!"; String text = "Terminal too small!";
@@ -38,11 +41,16 @@ public class TerminalTooSmallEventHandler extends AbstractEventHandler<TerminalT
int textStartX = (terminalSize.getColumns() / 2) - (text.length() / 2); int textStartX = (terminalSize.getColumns() / 2) - (text.length() / 2);
for (char character : text.toCharArray()) { for (char character : text.toCharArray()) {
terminalScreen.setCharacter(textStartX++, startY, new TextCharacter(character, TextColor.ANSI.RED, TextColor.ANSI.DEFAULT, SGR.BOLD)); tg.setForegroundColor(TextColor.ANSI.RED);
tg.setBackgroundColor(TextColor.ANSI.DEFAULT);
tg.setModifiers(EnumSet.of(SGR.BOLD));
tg.setCharacter(textStartX++, startY, character);
} }
int subTextStartX = (terminalSize.getColumns() / 2) - (subText.length() / 2); int subTextStartX = (terminalSize.getColumns() / 2) - (subText.length() / 2);
for (char character : subText.toCharArray()) { for (char character : subText.toCharArray()) {
terminalScreen.setCharacter(subTextStartX++, startY + 1, new TextCharacter(character, TextColor.ANSI.BLACK_BRIGHT, TextColor.ANSI.DEFAULT)); tg.setForegroundColor(TextColor.ANSI.BLACK_BRIGHT);
tg.setBackgroundColor(TextColor.ANSI.DEFAULT);
tg.setCharacter(subTextStartX++, startY + 1, character);
} }
try { try {