GUI, game: added card popup support in choose target amount dialogs (example: damage distribution, related to #9827)

This commit is contained in:
Oleg Agafonov 2024-10-24 16:15:03 +04:00
parent 0fbd9bb60f
commit 1ec277631f
6 changed files with 43 additions and 24 deletions

View file

@ -41,7 +41,7 @@ public class MageTextArea extends MageEditorPane {
// prepare text format as header and details texts // prepare text format as header and details texts
final StringBuilder buffer = new StringBuilder(512); final StringBuilder buffer = new StringBuilder();
// Dialog is a java logical font family, so it should work on all systems // Dialog is a java logical font family, so it should work on all systems
buffer.append("<body style='font-family:Dialog;font-size:"); buffer.append("<body style='font-family:Dialog;font-size:");
buffer.append(GUISizeHelper.gameFeedbackPanelMainMessageFontSize); buffer.append(GUISizeHelper.gameFeedbackPanelMainMessageFontSize);

View file

@ -1,5 +1,7 @@
package mage.client.dialog; package mage.client.dialog;
import mage.client.cards.BigCard;
import mage.client.components.MageTextArea;
import mage.constants.ColoredManaSymbol; import mage.constants.ColoredManaSymbol;
import mage.util.MultiAmountMessage; import mage.util.MultiAmountMessage;
@ -11,20 +13,24 @@ import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
* Game GUI: dialog to distribute values between multiple items * Game GUI: dialog to distribute values between multiple items
* (used for some cards and add lands in cheat menu, search by MultiAmountMessage) * (used for some cards and add lands in cheat menu, search by MultiAmountMessage)
* *
* @author weirddan455 * @author weirddan455, JayDi85
*/ */
public class PickMultiNumberDialog extends MageDialog { public class PickMultiNumberDialog extends MageDialog {
private boolean cancel; private boolean cancel;
private PickMultiNumberCallback callback = null; private PickMultiNumberCallback callback = null;
private UUID gameId = null;
private BigCard bigCard = null;
private List<JLabel> labelList = null; private List<MageTextArea> infoList = null;
private List<JSpinner> spinnerList = null; private List<JSpinner> spinnerList = null;
public PickMultiNumberDialog() { public PickMultiNumberDialog() {
@ -36,6 +42,11 @@ public class PickMultiNumberDialog extends MageDialog {
void onChoiceDone(); void onChoiceDone();
} }
public void init(UUID gameId, BigCard bigCard) {
this.gameId = gameId;
this.bigCard = bigCard;
}
public void showDialog(List<MultiAmountMessage> messages, int min, int max, Map<String, Serializable> options, PickMultiNumberCallback callback) { public void showDialog(List<MultiAmountMessage> messages, int min, int max, Map<String, Serializable> options, PickMultiNumberCallback callback) {
this.cancel = false; this.cancel = false;
this.callback = callback; this.callback = callback;
@ -46,9 +57,10 @@ public class PickMultiNumberDialog extends MageDialog {
boolean canCancel = options.get("canCancel") != null && (boolean) options.get("canCancel"); boolean canCancel = options.get("canCancel") != null && (boolean) options.get("canCancel");
btnCancel.setVisible(canCancel); btnCancel.setVisible(canCancel);
if (labelList != null) { // clean
for (JLabel label : labelList) { if (infoList != null) {
jPanel1.remove(label); for (MageTextArea info : infoList) {
jPanel1.remove(info);
} }
} }
if (spinnerList != null) { if (spinnerList != null) {
@ -56,14 +68,15 @@ public class PickMultiNumberDialog extends MageDialog {
jPanel1.remove(spinner); jPanel1.remove(spinner);
} }
} }
int size = messages.size(); int size = messages.size();
labelList = new ArrayList<>(size); infoList = new ArrayList<>(size);
spinnerList = new ArrayList<>(size); spinnerList = new ArrayList<>(size);
jPanel1.setLayout(new GridBagLayout()); jPanel1.setLayout(new GridBagLayout());
GridBagConstraints labelC = new GridBagConstraints();
GridBagConstraints spinnerC = new GridBagConstraints();
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
JLabel label = new JLabel(); MageTextArea info = new MageTextArea();
info.enableTextLabelMode();
info.setGameData(this.gameId, this.bigCard);
// mana mode // mana mode
String manaText = null; String manaText = null;
@ -86,24 +99,23 @@ public class PickMultiNumberDialog extends MageDialog {
break; break;
} }
if (manaText != null) { if (manaText != null) {
label.setText("<html>" + manaText); // mana mode
Image image = ManaSymbols.getSizedManaSymbol(input); info.setText("{" + input + "}" + "&nbsp;" + manaText);
if (image != null) {
label.setIcon(new ImageIcon(image));
}
} else { } else {
// text mode // text mode
label.setText("<html>" + ManaSymbols.replaceSymbolsWithHTML(input, ManaSymbols.Type.DIALOG)); info.setText(input);
} }
labelC.weightx = 0.5; GridBagConstraints infoC = new GridBagConstraints();
labelC.gridx = 0; infoC.weightx = 0.5;
labelC.gridy = i; infoC.gridx = 0;
jPanel1.add(label, labelC); infoC.gridy = i;
labelList.add(label); jPanel1.add(info, infoC);
infoList.add(info);
JSpinner spinner = new JSpinner(); JSpinner spinner = new JSpinner();
spinner.setModel(new SpinnerNumberModel(messages.get(i).defaultValue, messages.get(i).min, messages.get(i).max, 1)); spinner.setModel(new SpinnerNumberModel(messages.get(i).defaultValue, messages.get(i).min, messages.get(i).max, 1));
GridBagConstraints spinnerC = new GridBagConstraints();
spinnerC.weightx = 0.5; spinnerC.weightx = 0.5;
spinnerC.gridx = 1; spinnerC.gridx = 1;
spinnerC.gridy = i; spinnerC.gridy = i;

View file

@ -650,6 +650,11 @@ public final class GamePanel extends javax.swing.JPanel {
this.abilityPicker.fullRefresh(GUISizeHelper.dialogGuiScale); this.abilityPicker.fullRefresh(GUISizeHelper.dialogGuiScale);
this.abilityPicker.init(gameId, bigCard); this.abilityPicker.init(gameId, bigCard);
} }
if (this.pickMultiNumber != null && !this.pickMultiNumber.isVisible()) {
// TODO: add pick number dialogs support here
//this.pickMultiNumber.fullRefresh(GUISizeHelper.dialogGuiScale);
this.pickMultiNumber.init(gameId, bigCard);
}
} }
private void setSkipButtonImage(JButton button, Image image) { private void setSkipButtonImage(JButton button, Image image) {
@ -819,6 +824,7 @@ public final class GamePanel extends javax.swing.JPanel {
MageFrame.addGame(gameId, this); MageFrame.addGame(gameId, this);
this.feedbackPanel.init(gameId, bigCard); this.feedbackPanel.init(gameId, bigCard);
this.feedbackPanel.clear(); this.feedbackPanel.clear();
this.pickMultiNumber.init(gameId, bigCard);
this.abilityPicker.init(gameId, bigCard); this.abilityPicker.init(gameId, bigCard);
this.btnConcede.setVisible(true); this.btnConcede.setVisible(true);
this.btnStopWatching.setVisible(false); this.btnStopWatching.setVisible(false);
@ -2177,6 +2183,7 @@ public final class GamePanel extends javax.swing.JPanel {
hideAll(); hideAll();
DialogManager.getManager(gameId).fadeOut(); DialogManager.getManager(gameId).fadeOut();
pickMultiNumber.init(gameId, bigCard);
pickMultiNumber.showDialog(messages, min, max, lastGameData.options, () -> { pickMultiNumber.showDialog(messages, min, max, lastGameData.options, () -> {
if (pickMultiNumber.isCancel()) { if (pickMultiNumber.isCancel()) {
SessionHandler.sendPlayerBoolean(gameId, false); SessionHandler.sendPlayerBoolean(gameId, false);

View file

@ -1124,7 +1124,7 @@ public class HumanPlayer extends PlayerImpl {
MageObject targetObject = game.getObject(targetId); MageObject targetObject = game.getObject(targetId);
if (targetObject != null) { if (targetObject != null) {
targetNames.add(String.format("%s, P/T: %d/%d", targetNames.add(String.format("%s, P/T: %d/%d",
targetObject.getIdName(), targetObject.getLogName(),
targetObject.getPower().getValue(), targetObject.getPower().getValue(),
targetObject.getToughness().getValue() targetObject.getToughness().getValue()
)); ));

View file

@ -112,7 +112,7 @@ class MasterOfTheWildHuntEffect extends OneShotEffect {
int totalDamage = target.getPower().getValue(); int totalDamage = target.getPower().getValue();
List<String> messages = new ArrayList<>(); List<String> messages = new ArrayList<>();
wolves.forEach(permanent -> { wolves.forEach(permanent -> {
String info = String.format("%s (%s/%s)", String info = String.format("%s, P/T: %d/%d",
permanent.getLogName(), permanent.getLogName(),
permanent.getPower().getValue(), permanent.getPower().getValue(),
permanent.getToughness().getValue() permanent.getToughness().getValue()

View file

@ -75,7 +75,7 @@ public class GameState implements Serializable, Copyable<GameState> {
private Watchers watchers; private Watchers watchers;
private Turn turn; private Turn turn;
private TurnMods turnMods; // one time turn modifications (turn, phase or step) private TurnMods turnMods; // one time turn modifications (turn, phase or step)
private UUID activePlayerId; // playerId which turn it is private UUID activePlayerId; // player which turn it is
private UUID priorityPlayerId; // player that has currently priority (setup before any choose) private UUID priorityPlayerId; // player that has currently priority (setup before any choose)
private UUID playerByOrderId; // player that has currently priority private UUID playerByOrderId; // player that has currently priority
private UUID monarchId; // player that is the monarch private UUID monarchId; // player that is the monarch