Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[LTR] Add Goldberry, River-Daughter #10524

Merged
merged 14 commits into from
Jul 29, 2023
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package mage.client.dialog;

import mage.constants.ColoredManaSymbol;
import mage.util.MultiAmountMessage;

import org.mage.card.arcane.ManaSymbols;

import javax.swing.*;
Expand All @@ -25,7 +27,7 @@ public PickMultiNumberDialog() {
this.setModal(true);
}

public void showDialog(List<String> messages, int min, int max, Map<String, Serializable> options) {
public void showDialog(List<MultiAmountMessage> messages, int min, int max, Map<String, Serializable> options) {
this.header.setText((String) options.get("header"));
this.header.setHorizontalAlignment(SwingConstants.CENTER);
this.setTitle((String) options.get("title"));
Expand All @@ -51,7 +53,7 @@ public void showDialog(List<String> messages, int min, int max, Map<String, Seri

// mana mode
String manaText = null;
String input = messages.get(i);
String input = messages.get(i).message;
switch (input) {
case "W":
manaText = ColoredManaSymbol.W.getColorHtmlName();
Expand Down Expand Up @@ -87,34 +89,42 @@ public void showDialog(List<String> messages, int min, int max, Map<String, Seri
labelList.add(label);

JSpinner spinner = new JSpinner();
spinner.setModel(new SpinnerNumberModel(0, 0, max, 1));
spinner.setModel(new SpinnerNumberModel(0, messages.get(i).min, messages.get(i).max, 1));
spinnerC.weightx = 0.5;
spinnerC.gridx = 1;
spinnerC.gridy = i;
spinnerC.ipadx = 20;
spinner.addChangeListener(e -> {
updateControls(min, max);
updateControls(min, max, messages);
});
jPanel1.add(spinner, spinnerC);
spinnerList.add(spinner);
}
this.counterText.setText("0 out of 0");
this.counterText.setHorizontalAlignment(SwingConstants.CENTER);

updateControls(min, max);
updateControls(min, max, messages);

this.pack();
this.makeWindowCentered();
this.setVisible(true);
}

private void updateControls(int min, int max) {
private void updateControls(int min, int max, List<MultiAmountMessage> messages) {
int totalChosenAmount = 0;
for (JSpinner jSpinner : spinnerList) {
totalChosenAmount += ((Number) jSpinner.getValue()).intValue();
boolean chooseEnabled = true;

for (int i = 0; i < spinnerList.size(); i++) {
JSpinner jSpinner = spinnerList.get(i);
int value = ((Number) jSpinner.getValue()).intValue();
totalChosenAmount += value;

chooseEnabled &= value >= messages.get(i).min && value <= messages.get(i).max;
}
counterText.setText(totalChosenAmount + " out of " + max);
chooseButton.setEnabled(totalChosenAmount >= min && totalChosenAmount <= max);

chooseEnabled &= totalChosenAmount >= min && totalChosenAmount <= max;
chooseButton.setEnabled(chooseEnabled);
}

public String getMultiAmount() {
Expand Down
4 changes: 3 additions & 1 deletion Mage.Client/src/main/java/mage/client/game/GamePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import mage.game.events.PlayerQueryEvent;
import mage.players.PlayableObjectStats;
import mage.players.PlayableObjectsList;
import mage.util.MultiAmountMessage;
import mage.view.*;
import org.apache.log4j.Logger;
import org.mage.plugins.card.utils.impl.ImageManagerImpl;
Expand Down Expand Up @@ -1774,7 +1775,8 @@ public void getAmount(GameView gameView, Map<String, Serializable> options, int
}
}

public void getMultiAmount(List<String> messages, GameView gameView, Map<String, Serializable> options, int min, int max) {
public void getMultiAmount(List<MultiAmountMessage> messages, GameView gameView, Map<String, Serializable> options,
int min, int max) {
updateGame(gameView, false, options, null);
hideAll();
DialogManager.getManager(gameId).fadeOut();
Expand Down
8 changes: 5 additions & 3 deletions Mage.Common/src/main/java/mage/view/GameClientMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.google.gson.annotations.Expose;

import mage.choices.Choice;
import mage.util.MultiAmountMessage;

/**
*
Expand Down Expand Up @@ -42,7 +43,7 @@ public class GameClientMessage implements Serializable {
@Expose
private Choice choice;
@Expose
private List<String> messages;
private List<MultiAmountMessage> messages;

public GameClientMessage(GameView gameView, Map<String, Serializable> options) {
this.gameView = gameView;
Expand Down Expand Up @@ -80,7 +81,8 @@ public GameClientMessage(GameView gameView, Map<String, Serializable> options, S
this.cardsView2 = pile2;
}

public GameClientMessage(GameView gameView, Map<String, Serializable> options, List<String> messages, int min, int max) {
public GameClientMessage(GameView gameView, Map<String, Serializable> options, List<MultiAmountMessage> messages,
int min, int max) {
this.gameView = gameView;
this.options = options;
this.messages = messages;
Expand Down Expand Up @@ -134,7 +136,7 @@ public Choice getChoice() {
return choice;
}

public List<String> getMessages() {
public List<MultiAmountMessage> getMessages() {
return messages;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2169,11 +2169,12 @@ public int getAmount(int min, int max, String message, Game game) {
}

@Override
public List<Integer> getMultiAmount(Outcome outcome, List<String> messages, int min, int max, MultiAmountType type, Game game) {
public List<Integer> getMultiAmountWithIndividualConstraints(Outcome outcome, List<MultiAmountMessage> messages,
int min, int max, MultiAmountType type, Game game) {
log.debug("getMultiAmount");

int needCount = messages.size();
List<Integer> defaultList = MultiAmountType.prepareDefaltValues(needCount, min, max);
List<Integer> defaultList = MultiAmountType.prepareDefaltValues(messages, min, max);
if (needCount == 0) {
return defaultList;
}
Expand All @@ -2188,7 +2189,7 @@ public List<Integer> getMultiAmount(Outcome outcome, List<String> messages, int
// GOOD effect
// values must be stable, so AI must able to simulate it and choose correct actions
// fill max values as much as possible
return MultiAmountType.prepareMaxValues(needCount, min, max);
return MultiAmountType.prepareMaxValues(messages, min, max);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
import mage.util.GameLog;
import mage.util.ManaUtil;
import mage.util.MessageToClient;
import mage.util.MultiAmountMessage;

import org.apache.log4j.Logger;

import java.awt.*;
Expand Down Expand Up @@ -2045,10 +2047,12 @@ public int getAmount(int min, int max, String message, Game game) {
}

@Override
public List<Integer> getMultiAmount(Outcome outcome, List<String> messages, int min, int max, MultiAmountType type, Game game) {
public List<Integer> getMultiAmountWithIndividualConstraints(Outcome outcome, List<MultiAmountMessage> messages,
int min, int max, MultiAmountType type, Game game) {
int needCount = messages.size();
List<Integer> defaultList = MultiAmountType.prepareDefaltValues(needCount, min, max);
if (needCount == 0) {
List<Integer> defaultList = MultiAmountType.prepareDefaltValues(messages, min, max);
if (needCount == 0 || (needCount == 1 && min == max)
|| messages.stream().map(m -> m.min == m.max).reduce(true, Boolean::logicalAnd)) {
return defaultList;
}

Expand All @@ -2070,8 +2074,8 @@ public List<Integer> getMultiAmount(Outcome outcome, List<String> messages, int

// waiting correct values only
if (response.getString() != null) {
answer = MultiAmountType.parseAnswer(response.getString(), needCount, min, max, false);
if (MultiAmountType.isGoodValues(answer, needCount, min, max)) {
answer = MultiAmountType.parseAnswer(response.getString(), messages, min, max, false);
if (MultiAmountType.isGoodValues(answer, messages, min, max)) {
break;
} else {
// it's not normal: can be cheater or a wrong GUI checks
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import mage.server.managers.ManagerFactory;
import mage.server.util.Splitter;
import mage.server.util.SystemUtil;
import mage.util.MultiAmountMessage;
import mage.utils.StreamUtils;
import mage.utils.timer.PriorityTimer;
import mage.view.*;
Expand Down Expand Up @@ -870,7 +871,9 @@ private synchronized void amount(UUID playerId, final String message, final int
perform(playerId, playerId1 -> getGameSession(playerId1).getAmount(message, min, max));
}

private synchronized void multiAmount(UUID playerId, final List<String> messages, final int min, final int max, final Map<String, Serializable> options) throws MageException {
private synchronized void multiAmount(UUID playerId, final List<MultiAmountMessage> messages,
final int min, final int max, final Map<String, Serializable> options)
throws MageException {
perform(playerId, playerId1 -> getGameSession(playerId1).getMultiAmount(messages, min, max, options));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import mage.server.User;
import mage.server.managers.ManagerFactory;
import mage.server.managers.UserManager;
import mage.util.MultiAmountMessage;
import mage.view.*;
import org.apache.log4j.Logger;

Expand Down Expand Up @@ -114,7 +115,8 @@ public void getAmount(final String message, final int min, final int max) {
}
}

public void getMultiAmount(final List<String> messages, final int min, final int max, final Map<String, Serializable> options) {
public void getMultiAmount(final List<MultiAmountMessage> messages, final int min, final int max,
final Map<String, Serializable> options) {
if (!killed) {
userManager.getUser(userId).ifPresent(user
-> user.fireCallback(new ClientCallback(ClientCallbackMethod.GAME_GET_MULTI_AMOUNT, game.getId(), new GameClientMessage(getGameView(), options, messages, min, max))));
Expand Down
Loading