GUI: fixed that size settings changes do not work in-game sometimes (broken fonts in feedback panel);

This commit is contained in:
Oleg Agafonov 2024-05-07 15:16:54 +04:00
parent 907ac5c3e1
commit d3437c9b1e
3 changed files with 39 additions and 53 deletions

View file

@ -15,6 +15,7 @@ import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
@ -66,18 +67,27 @@ public class FeedbackPanel extends javax.swing.JPanel {
private void setGUISize() {
}
public void prepareFeedback(FeedbackMode mode, String message, boolean special, Map<String, Serializable> options,
public void prepareFeedback(FeedbackMode mode, String basicMessage, String additionalMessage, boolean special, Map<String, Serializable> options,
boolean gameNeedUserFeedback, TurnPhase gameTurnPhase) {
synchronized (this) {
this.lastOptions = options;
this.mode = mode;
}
this.helper.setBasicMessage(message);
this.helper.setOriginalId(null); // reference to the feedback causing ability
String lblText = addAdditionalText(message, options);
this.helper.setTextArea(lblText);
// build secondary message (will use smaller font)
java.util.ArrayList<String> secondaryMessages = new ArrayList<>();
if (additionalMessage != null && !additionalMessage.isEmpty()) {
// client side additional info like active priority/player
secondaryMessages.add(additionalMessage);
}
String serverSideAdditionalMessage = options != null && options.containsKey(SECOND_MESSAGE) ? (String) options.get(SECOND_MESSAGE) : null;
if (serverSideAdditionalMessage != null && !serverSideAdditionalMessage.isEmpty()) {
// server side additional info like card/source info
secondaryMessages.add(serverSideAdditionalMessage);
}
this.helper.setMessages(basicMessage, String.join("<br>", secondaryMessages));
this.helper.setOriginalId(null); // reference to the feedback causing ability
switch (this.mode) {
case INFORM:
@ -93,7 +103,7 @@ public class FeedbackPanel extends javax.swing.JPanel {
// Uses a filtered message for remembering choice if the original message contains a self-reference
this.helper.setAutoAnswerMessage((String) options.get(AUTO_ANSWER_MESSAGE));
} else {
this.helper.setAutoAnswerMessage(message);
this.helper.setAutoAnswerMessage(basicMessage);
}
break;
case CONFIRM:
@ -138,18 +148,6 @@ public class FeedbackPanel extends javax.swing.JPanel {
this.helper.setState(leftText, !leftText.isEmpty(), rightText, !rightText.isEmpty(), mode);
}
private String addAdditionalText(String message, Map<String, Serializable> options) {
if (options != null && options.containsKey(SECOND_MESSAGE)) {
return message + getSmallText((String) options.get(SECOND_MESSAGE));
} else {
return message;
}
}
protected static String getSmallText(String text) {
return "<div style='font-size:" + GUISizeHelper.gameDialogAreaFontSizeSmall + "pt'>" + text + "</div>";
}
private void setSpecial(String text, boolean visible) {
this.btnSpecial.setText(text);
this.btnSpecial.setVisible(visible);

View file

@ -1466,7 +1466,7 @@ public final class GamePanel extends javax.swing.JPanel {
public void ask(int messageId, GameView gameView, String question, Map<String, Serializable> options) {
updateGame(messageId, gameView, false, options, null);
this.feedbackPanel.prepareFeedback(FeedbackMode.QUESTION, question, false, options, true, gameView.getPhase());
this.feedbackPanel.prepareFeedback(FeedbackMode.QUESTION, question, "", false, options, true, gameView.getPhase());
}
public boolean isMissGameData() {
@ -1760,7 +1760,7 @@ public final class GamePanel extends javax.swing.JPanel {
dialog = prepareCardsDialog(message, cardsView, required, options0, popupMenuType);
options0.put("dialog", dialog);
}
this.feedbackPanel.prepareFeedback(required ? FeedbackMode.INFORM : FeedbackMode.CANCEL, message, gameView.getSpecial(), options0, true, gameView.getPhase());
this.feedbackPanel.prepareFeedback(required ? FeedbackMode.INFORM : FeedbackMode.CANCEL, message, "", gameView.getSpecial(), options0, true, gameView.getPhase());
if (dialog != null) {
this.pickTarget.add(dialog);
}
@ -1768,7 +1768,7 @@ public final class GamePanel extends javax.swing.JPanel {
public void inform(int messageId, GameView gameView, String information) {
updateGame(messageId, gameView);
this.feedbackPanel.prepareFeedback(FeedbackMode.INFORM, information, gameView.getSpecial(), null, false, gameView.getPhase());
this.feedbackPanel.prepareFeedback(FeedbackMode.INFORM, information, "", gameView.getSpecial(), null, false, gameView.getPhase());
}
public void endMessage(int messageId, GameView gameView, Map<String, Serializable> options, String message) {
@ -1776,7 +1776,7 @@ public final class GamePanel extends javax.swing.JPanel {
hideAll();
DialogManager.getManager(gameId).fadeOut();
this.feedbackPanel.prepareFeedback(FeedbackMode.END, message, false, null, true, null);
this.feedbackPanel.prepareFeedback(FeedbackMode.END, message, "", false, null, true, null);
ArrowBuilder.getBuilder().removeAllArrows(gameId);
}
@ -1823,8 +1823,8 @@ public final class GamePanel extends javax.swing.JPanel {
if (controllingPlayer) {
priorityPlayerText = " / priority " + gameView.getPriorityPlayerName();
}
String messageToDisplay = message + FeedbackPanel.getSmallText(activePlayerText + " / " + gameView.getStep().toString() + priorityPlayerText);
this.feedbackPanel.prepareFeedback(FeedbackMode.SELECT, messageToDisplay, gameView.getSpecial(), panelOptions, true, gameView.getPhase());
String additionalMessage = activePlayerText + " / " + gameView.getStep().toString() + priorityPlayerText;
this.feedbackPanel.prepareFeedback(FeedbackMode.SELECT, message, additionalMessage, gameView.getSpecial(), panelOptions, true, gameView.getPhase());
}
public void playMana(int messageId, GameView gameView, Map<String, Serializable> options, String message) {
@ -1832,7 +1832,7 @@ public final class GamePanel extends javax.swing.JPanel {
hideAll();
DialogManager.getManager(gameId).fadeOut();
this.feedbackPanel.prepareFeedback(FeedbackMode.CANCEL, message, gameView.getSpecial(), options, true, gameView.getPhase());
this.feedbackPanel.prepareFeedback(FeedbackMode.CANCEL, message, "", gameView.getSpecial(), options, true, gameView.getPhase());
}
public void playXMana(int messageId, GameView gameView, Map<String, Serializable> options, String message) {
@ -1840,7 +1840,7 @@ public final class GamePanel extends javax.swing.JPanel {
hideAll();
DialogManager.getManager(gameId).fadeOut();
this.feedbackPanel.prepareFeedback(FeedbackMode.CONFIRM, message, gameView.getSpecial(), null, true, gameView.getPhase());
this.feedbackPanel.prepareFeedback(FeedbackMode.CONFIRM, message, "", gameView.getSpecial(), null, true, gameView.getPhase());
}
public void replayMessage(String message) {

View file

@ -63,7 +63,8 @@ public class HelperPanel extends JPanel {
// originalId of feedback causing ability
private UUID originalId;
private String message;
private String basicMessage; // normal size
private String secondaryMessage; // smaller size
private String autoAnswerMessage; // Filtered version of message which is used for remembering answers to text
private UUID gameId;
@ -113,25 +114,7 @@ public class HelperPanel extends JPanel {
btnSpecial.setFont(GUISizeHelper.gameDialogAreaFont);
btnUndo.setFont(GUISizeHelper.gameDialogAreaFont);
// update text fonts
if (message != null) {
int pos1 = this.message.indexOf("font-size:");
if (pos1 > 0) {
int pos2 = this.message.indexOf("font-size:", pos1 + 10);
String newMessage;
if (pos2 > 0) {
// 2 sizes: big + small // TODO: 2 sizes for compatibility only? On 04.02.2018 can't find two size texts (JayDi85)
newMessage = this.message.substring(0, pos1 + 10) + GUISizeHelper.gameDialogAreaFontSizeBig + this.message.substring(pos1 + 12);
newMessage = newMessage.substring(0, pos1 + 10) + GUISizeHelper.gameDialogAreaFontSizeSmall + newMessage.substring(pos1 + 12);
} else {
// 1 size: small
newMessage = this.message.substring(0, pos1 + 10) + GUISizeHelper.gameDialogAreaFontSizeSmall + this.message.substring(pos1 + 12);
}
setBasicMessage(newMessage);
}
}
this.redrawMessages();
autoSizeButtonsAndFeedbackState();
@ -458,19 +441,24 @@ public class HelperPanel extends JPanel {
this.originalId = originalId;
}
public void setBasicMessage(String message) {
this.message = message;
this.dialogTextArea.setText(message, this.getWidth());
public void setMessages(String basicMessage, String secondaryMessage) {
this.basicMessage = basicMessage;
this.secondaryMessage = secondaryMessage;
redrawMessages();
}
private void redrawMessages() {
String panelText = this.basicMessage;
if (this.secondaryMessage != null) {
panelText += "<div style='font-size:" + GUISizeHelper.gameDialogAreaFontSizeSmall + "pt'>" + secondaryMessage + "</div>";
}
this.dialogTextArea.setText(panelText, this.getWidth());
}
public void setAutoAnswerMessage(String autoAnswerMessage) {
this.autoAnswerMessage = autoAnswerMessage;
}
public void setTextArea(String message) {
this.dialogTextArea.setText(message, this.getWidth());
}
@Override
public void requestFocus() {
this.btnRight.requestFocus();