Merge origin/master

This commit is contained in:
LevelX2 2018-02-04 17:21:16 +01:00
commit b9ec919f06
3 changed files with 59 additions and 20 deletions

View file

@ -52,6 +52,7 @@ import static mage.constants.Constants.Option.ORIGINAL_ID;
import static mage.constants.Constants.Option.SECOND_MESSAGE;
import static mage.constants.Constants.Option.SPECIAL_BUTTON;
import mage.constants.PlayerAction;
import mage.constants.TurnPhase;
import org.apache.log4j.Logger;
/**
@ -97,7 +98,8 @@ public class FeedbackPanel extends javax.swing.JPanel {
private void setGUISize() {
}
public void getFeedback(FeedbackMode mode, String message, boolean special, Map<String, Serializable> options, int messageId) {
public void getFeedback(FeedbackMode mode, String message, boolean special, Map<String, Serializable> options,
int messageId, boolean gameNeedUserFeedback, TurnPhase gameTurnPhase) {
synchronized (this) {
if (messageId < this.lastMessageId) {
LOGGER.warn("ignoring message from later source: " + messageId + ", text=" + message);
@ -151,7 +153,8 @@ public class FeedbackPanel extends javax.swing.JPanel {
this.helper.setLinks(btnLeft, btnRight, btnSpecial, btnUndo);
this.helper.setVisible(true);
this.helper.autoSizeButtons();
this.helper.setGameNeedFeedback(gameNeedUserFeedback, gameTurnPhase);
this.helper.autoSizeButtonsAndFeedbackState();
}
private void setButtonState(String leftText, String rightText, FeedbackMode mode) {
@ -213,7 +216,7 @@ public class FeedbackPanel extends javax.swing.JPanel {
connectedDialog = (MageDialog) options.get("dialog");
}
this.helper.autoSizeButtons();
this.helper.autoSizeButtonsAndFeedbackState();
}
}

View file

@ -52,6 +52,7 @@ import mage.client.util.gui.ArrowBuilder;
import mage.client.util.gui.MageDialogState;
import mage.constants.*;
import mage.game.events.PlayerQueryEvent;
import mage.game.turn.Phase;
import mage.view.*;
import org.apache.log4j.Logger;
import org.mage.card.arcane.CardPanel;
@ -1064,7 +1065,7 @@ public final class GamePanel extends javax.swing.JPanel {
public void ask(String question, GameView gameView, int messageId, Map<String, Serializable> options) {
updateGame(gameView);
this.feedbackPanel.getFeedback(FeedbackMode.QUESTION, question, false, options, messageId);
this.feedbackPanel.getFeedback(FeedbackMode.QUESTION, question, false, options, messageId, true, gameView.getPhase());
}
/**
@ -1113,7 +1114,7 @@ public final class GamePanel extends javax.swing.JPanel {
dialog = showCards(message, cardView, required, options0, popupMenuType);
options0.put("dialog", dialog);
}
this.feedbackPanel.getFeedback(required ? FeedbackMode.INFORM : FeedbackMode.CANCEL, message, gameView.getSpecial(), options0, messageId);
this.feedbackPanel.getFeedback(required ? FeedbackMode.INFORM : FeedbackMode.CANCEL, message, gameView.getSpecial(), options0, messageId, true, gameView.getPhase());
if (dialog != null) {
this.pickTarget.add(dialog); // TODO: 01.01.2018, JayDi85: why feedbackPanel saved to pickTarget list? Need to research
}
@ -1121,11 +1122,11 @@ public final class GamePanel extends javax.swing.JPanel {
public void inform(String information, GameView gameView, int messageId) {
updateGame(gameView);
this.feedbackPanel.getFeedback(FeedbackMode.INFORM, information, gameView.getSpecial(), null, messageId);
this.feedbackPanel.getFeedback(FeedbackMode.INFORM, information, gameView.getSpecial(), null, messageId, false, gameView.getPhase());
}
public void endMessage(String message, int messageId) {
this.feedbackPanel.getFeedback(FeedbackMode.END, message, false, null, messageId);
this.feedbackPanel.getFeedback(FeedbackMode.END, message, false, null, messageId, true, null);
ArrowBuilder.getBuilder().removeAllArrows(gameId);
}
@ -1168,19 +1169,19 @@ public final class GamePanel extends javax.swing.JPanel {
priorityPlayerText = " / priority " + gameView.getPriorityPlayerName();
}
String messageToDisplay = message + FeedbackPanel.getSmallText(activePlayerText + " / " + gameView.getStep().toString() + priorityPlayerText);
this.feedbackPanel.getFeedback(FeedbackMode.SELECT, messageToDisplay, gameView.getSpecial(), panelOptions, messageId);
this.feedbackPanel.getFeedback(FeedbackMode.SELECT, messageToDisplay, gameView.getSpecial(), panelOptions, messageId, true, gameView.getPhase());
}
public void playMana(String message, GameView gameView, Map<String, Serializable> options, int messageId) {
updateGame(gameView);
DialogManager.getManager(gameId).fadeOut();
this.feedbackPanel.getFeedback(FeedbackMode.CANCEL, message, gameView.getSpecial(), options, messageId);
this.feedbackPanel.getFeedback(FeedbackMode.CANCEL, message, gameView.getSpecial(), options, messageId, true, gameView.getPhase());
}
public void playXMana(String message, GameView gameView, int messageId) {
updateGame(gameView);
DialogManager.getManager(gameId).fadeOut();
this.feedbackPanel.getFeedback(FeedbackMode.CONFIRM, message, gameView.getSpecial(), null, messageId);
this.feedbackPanel.getFeedback(FeedbackMode.CONFIRM, message, gameView.getSpecial(), null, messageId, true, gameView.getPhase());
}
public void replayMessage(String message) {

View file

@ -39,7 +39,6 @@ import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.Random;
import java.util.UUID;
import javax.swing.JButton;
import javax.swing.JMenuItem;
@ -59,7 +58,7 @@ import mage.client.game.FeedbackPanel.FeedbackMode;
import static mage.client.game.FeedbackPanel.FeedbackMode.QUESTION;
import mage.client.util.GUISizeHelper;
import mage.util.RandomUtil;
import mage.constants.TurnPhase;
import static mage.constants.PlayerAction.REQUEST_AUTO_ANSWER_ID_NO;
import static mage.constants.PlayerAction.REQUEST_AUTO_ANSWER_ID_YES;
@ -70,7 +69,7 @@ import static mage.constants.PlayerAction.REQUEST_AUTO_ANSWER_TEXT_YES;
/**
* Panel with buttons that copy the state of feedback panel.
*
* @author ayrat
* @author ayrat, JayDi85
*/
public class HelperPanel extends JPanel {
@ -107,6 +106,8 @@ public class HelperPanel extends JPanel {
private String message;
private UUID gameId;
private boolean gameNeedFeedback = false;
private TurnPhase gameTurnPhase = null;
public HelperPanel() {
initComponents();
@ -147,7 +148,7 @@ public class HelperPanel extends JPanel {
}
}
autoSizeButtons();
autoSizeButtonsAndFeedbackState();
GUISizeHelper.changePopupMenuFont(popupMenuAskNo);
GUISizeHelper.changePopupMenuFont(popupMenuAskYes);
@ -178,7 +179,7 @@ public class HelperPanel extends JPanel {
buttonContainer.setOpaque(false);
add(buttonContainer);
buttonGrid = new JPanel(); // buttons layout auto changes by autoSizeButtons
buttonGrid = new JPanel(); // buttons layout auto changes by autoSizeButtonsAndFeedbackState
buttonGrid.setOpaque(false);
buttonContainer.add(buttonGrid);
@ -292,7 +293,7 @@ public class HelperPanel extends JPanel {
this.btnRight.setActionCommand(mode.toString() + txtRight);
}
}
autoSizeButtons();
autoSizeButtonsAndFeedbackState();
}
public void setSpecial(String txtSpecial, boolean specialVisible) {
@ -302,7 +303,7 @@ public class HelperPanel extends JPanel {
public void setUndoEnabled(boolean enabled) {
this.btnUndo.setVisible(enabled);
autoSizeButtons();
autoSizeButtonsAndFeedbackState();
}
public void setLeft(String text, boolean visible) {
@ -310,7 +311,7 @@ public class HelperPanel extends JPanel {
if (!text.isEmpty()) {
this.btnLeft.setText(text);
}
autoSizeButtons();
autoSizeButtonsAndFeedbackState();
}
public void setRight(String txtRight, boolean rightVisible) {
@ -318,13 +319,22 @@ public class HelperPanel extends JPanel {
if (!txtRight.isEmpty()) {
this.btnRight.setText(txtRight);
}
autoSizeButtons();
autoSizeButtonsAndFeedbackState();
}
public void autoSizeButtons() {
public void setGameNeedFeedback(boolean need, TurnPhase gameTurnPhase) {
this.gameNeedFeedback = need;
this.gameTurnPhase = gameTurnPhase;
}
public void autoSizeButtonsAndFeedbackState() {
// two mode: same size for small texts (flow), different size for long texts (grid)
// plus colorize feedback panel on player's priority
int BUTTONS_H_GAP = 15;
Color ACTIVE_FEEDBACK_BACKGROUND_COLOR_MAIN = new Color(0, 0, 255, 50);
Color ACTIVE_FEEDBACK_BACKGROUND_COLOR_BATTLE = new Color(255, 0, 0, 50);
Color ACTIVE_FEEDBACK_BACKGROUND_COLOR_OTHER = new Color(0, 255, 0, 50);
// cleanup current settings to default (flow layout - different sizes)
this.buttonGrid.setLayout(new FlowLayout(FlowLayout.CENTER, BUTTONS_H_GAP, 0));
@ -336,6 +346,31 @@ public class HelperPanel extends JPanel {
if (this.btnSpecial.isVisible()) { buttons.add(this.btnSpecial); }
if (this.btnUndo.isVisible()) { buttons.add(this.btnUndo); }
// color panel on player's feedback waiting
if (this.gameNeedFeedback) {
// wait player's action
this.setOpaque(true);
// different colors for different game phases
Color backColor = ACTIVE_FEEDBACK_BACKGROUND_COLOR_OTHER;
if (this.gameTurnPhase != null) {
switch (this.gameTurnPhase) {
case PRECOMBAT_MAIN:
case POSTCOMBAT_MAIN:
backColor = ACTIVE_FEEDBACK_BACKGROUND_COLOR_MAIN;
break;
case COMBAT:
backColor = ACTIVE_FEEDBACK_BACKGROUND_COLOR_BATTLE;
break;
}
}
this.setBackground(backColor);
} else {
// inform about other players
this.setOpaque(false);
}
if (buttons.size() == 0) {
return;
}