closes #699 : Option to speed up progression through the stack.
parent
8df2fc49bb
commit
e70a94be7f
Binary file not shown.
After Width: | Height: | Size: 367 B |
|
@ -24,6 +24,7 @@ public enum MagicIcon {
|
|||
DECK("ui/w_deck.png"),
|
||||
EDIT("ui/w_edit.png"),
|
||||
ENCHANTMENTS("ui/w_enchantments.png"),
|
||||
FAST_FORWARD("ui/fast-forward-16.png"),
|
||||
FIREMIND("ui/w_firemind.png"),
|
||||
GO_BACK("ui/w_back.png"),
|
||||
GO_NEXT("ui/w_next.png"),
|
||||
|
|
|
@ -22,6 +22,9 @@ public interface IUIGameController extends IGameController {
|
|||
void updateGameView();
|
||||
void waitForInput() throws UndoClickedException;
|
||||
void refreshSidebarLayout();
|
||||
void setStackFastForward(boolean b);
|
||||
boolean isStackFastForward();
|
||||
void doStackItemPause();
|
||||
|
||||
// Choices
|
||||
MagicSubType getLandSubTypeChoice(final MagicSource source) throws UndoClickedException;
|
||||
|
@ -34,5 +37,4 @@ public interface IUIGameController extends IGameController {
|
|||
int getModeChoice(final MagicSource source, final List<Integer> availableModes) throws UndoClickedException;
|
||||
int getPayManaCostXChoice(final MagicSource source, final int maximumX) throws UndoClickedException;
|
||||
MagicPlayChoiceResult getPlayChoice(final MagicSource source, final List<MagicPlayChoiceResult> results) throws UndoClickedException;
|
||||
|
||||
}
|
||||
|
|
|
@ -1,24 +1,23 @@
|
|||
package magic.model.choice;
|
||||
|
||||
import magic.data.GeneralConfig;
|
||||
import magic.model.MagicGame;
|
||||
import magic.model.MagicPlayer;
|
||||
import magic.model.MagicSource;
|
||||
import magic.model.MagicPermanentState;
|
||||
import magic.model.event.MagicActivation;
|
||||
import magic.model.event.MagicEvent;
|
||||
import magic.model.event.MagicSourceActivation;
|
||||
import magic.model.phase.MagicPhaseType;
|
||||
import magic.exception.UndoClickedException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import magic.exception.UndoClickedException;
|
||||
import magic.model.IUIGameController;
|
||||
import magic.translate.StringContext;
|
||||
import magic.model.MagicGame;
|
||||
import magic.model.MagicPermanentState;
|
||||
import magic.model.MagicPlayer;
|
||||
import magic.model.MagicSource;
|
||||
import magic.model.event.MagicActivation;
|
||||
import magic.model.event.MagicEvent;
|
||||
import magic.model.event.MagicSourceActivation;
|
||||
import magic.model.phase.MagicPhaseType;
|
||||
import magic.translate.MText;
|
||||
import magic.translate.StringContext;
|
||||
|
||||
public class MagicPlayChoice extends MagicChoice {
|
||||
|
||||
|
@ -116,9 +115,7 @@ public class MagicPlayChoice extends MagicChoice {
|
|||
//skip if phase is combat damage, not supposed to be able to do
|
||||
//anything but resolve triggers
|
||||
if (game.isPhase(MagicPhaseType.CombatDamage)) {
|
||||
if (game.getStack().hasItem()) {
|
||||
controller.pause(GeneralConfig.getInstance().getMessageDelay());
|
||||
}
|
||||
controller.doStackItemPause();
|
||||
return PASS_CHOICE_RESULTS;
|
||||
}
|
||||
|
||||
|
@ -136,10 +133,7 @@ public class MagicPlayChoice extends MagicChoice {
|
|||
}
|
||||
|
||||
if (skip) {
|
||||
//pause if there is an item on the stack
|
||||
if (game.getStack().hasItem()) {
|
||||
controller.pause(GeneralConfig.getInstance().getMessageDelay());
|
||||
}
|
||||
controller.doStackItemPause();
|
||||
return PASS_CHOICE_RESULTS;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -103,6 +103,8 @@ public class SwingGameController implements IUIGameController {
|
|||
private final AtomicBoolean running = new AtomicBoolean(false);
|
||||
private final AtomicBoolean isPaused = new AtomicBoolean(false);
|
||||
private final AtomicBoolean gameConceded = new AtomicBoolean(false);
|
||||
private final AtomicBoolean isStackFastForward = new AtomicBoolean(false);
|
||||
private final AtomicBoolean isPauseCancelled = new AtomicBoolean(false);
|
||||
private final Collection<IChoiceViewer> choiceViewers = new ArrayList<>();
|
||||
private Set<?> validChoices = Collections.emptySet();
|
||||
private AnnotatedCardPanel cardPopup;
|
||||
|
@ -208,12 +210,18 @@ public class SwingGameController implements IUIGameController {
|
|||
|
||||
@Override
|
||||
public void pause(final int t) {
|
||||
assert !SwingUtilities.isEventDispatchThread();
|
||||
disableActionUndoButtons();
|
||||
try { //sleep
|
||||
Thread.sleep(t);
|
||||
} catch (final InterruptedException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
int tick = 0;
|
||||
while (tick < t && isPauseCancelled.get() == false) {
|
||||
try {
|
||||
Thread.sleep(10);
|
||||
} catch (final InterruptedException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
tick += 10;
|
||||
}
|
||||
isPauseCancelled.set(false);
|
||||
}
|
||||
|
||||
private static void invokeAndWait(final Runnable task) {
|
||||
|
@ -1141,4 +1149,27 @@ public class SwingGameController implements IUIGameController {
|
|||
logStackViewer.setStackCount(count);
|
||||
}
|
||||
|
||||
private int getStackItemPause() {
|
||||
return isStackFastForward.get() == true ? 0 : CONFIG.getMessageDelay();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStackFastForward(boolean b) {
|
||||
isPauseCancelled.set(b);
|
||||
isStackFastForward.set(b);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStackFastForward() {
|
||||
return isStackFastForward.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doStackItemPause() {
|
||||
if (game.getStack().hasItem()) {
|
||||
if (getStackItemPause() > 0) {
|
||||
pause(getStackItemPause());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ public class ActionButtonTitleBar extends TitleBar {
|
|||
actionsPanel.add(btn, "w 16!, h 16!");
|
||||
}
|
||||
|
||||
add(actionsPanel, "alignx right");
|
||||
add(actionsPanel, "alignx right, hidemode 3");
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -15,15 +15,15 @@ public class TitleBar extends JPanel {
|
|||
|
||||
public TitleBar(final String text) {
|
||||
|
||||
label = new JLabel(text); //, MagicImages.getSmallManaIcon(MagicIcon.SAVE), SwingConstants.LEFT);
|
||||
label = new JLabel(text);
|
||||
label.setForeground(MagicStyle.getTheme().getColor(Theme.COLOR_TITLE_FOREGROUND));
|
||||
|
||||
setPreferredSize(new Dimension(getPreferredSize().width, 22));
|
||||
setMinimumSize(getPreferredSize());
|
||||
setMaximumSize(new Dimension(ScreenController.getFrame().getSize().width, 22));
|
||||
|
||||
setLayout(new MigLayout("insets 0 4 0 4", "", "grow, fill"));
|
||||
add(label, "pushx");
|
||||
setLayout(new MigLayout("insets 0 4 0 4", "[grow, fill][]", "[grow, fill]"));
|
||||
add(label);
|
||||
|
||||
setBackground(MagicStyle.getTheme().getColor(Theme.COLOR_TITLE_BACKGROUND));
|
||||
|
||||
|
@ -33,4 +33,7 @@ public class TitleBar extends JPanel {
|
|||
label.setText(text);
|
||||
}
|
||||
|
||||
public JLabel getLabel() {
|
||||
return label;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ public class DuelSideBarPanel extends JPanel implements IPlayerZoneListener {
|
|||
this.controller = controller;
|
||||
|
||||
logBookViewer = new LogViewer(controller);
|
||||
logStackViewer = new LogStackViewer(logBookViewer, imageStackViewer);
|
||||
logStackViewer = new LogStackViewer(logBookViewer, imageStackViewer, controller);
|
||||
controller.setLogStackViewer(logStackViewer);
|
||||
|
||||
gameStatusPanel= new GameStatusPanel(controller);
|
||||
|
|
|
@ -6,19 +6,27 @@ import java.awt.Font;
|
|||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.swing.AbstractAction;
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.SwingConstants;
|
||||
import javax.swing.SwingUtilities;
|
||||
import magic.data.GeneralConfig;
|
||||
import magic.data.MagicIcon;
|
||||
import magic.model.IUIGameController;
|
||||
import magic.translate.MText;
|
||||
import magic.ui.FontsAndBorders;
|
||||
import magic.ui.MagicImages;
|
||||
import magic.ui.ScreenController;
|
||||
import magic.ui.helpers.ImageHelper;
|
||||
import magic.ui.helpers.MouseHelper;
|
||||
import magic.ui.screen.widget.ActionBarButton;
|
||||
import magic.ui.screen.widget.DialButton;
|
||||
import magic.ui.widget.ActionButtonTitleBar;
|
||||
|
@ -28,6 +36,10 @@ import net.miginfocom.swing.MigLayout;
|
|||
@SuppressWarnings("serial")
|
||||
public class LogStackViewer extends JPanel {
|
||||
|
||||
private static final Icon FFORWARD_ICON = ImageHelper.getRecoloredIcon(
|
||||
MagicIcon.FAST_FORWARD, Color.black, Color.white
|
||||
);
|
||||
|
||||
public static final Font MESSAGE_FONT = FontsAndBorders.FONT1.deriveFont(Font.PLAIN);
|
||||
public static final Color CHOICE_COLOR = Color.RED.darker();
|
||||
|
||||
|
@ -41,20 +53,45 @@ public class LogStackViewer extends JPanel {
|
|||
private static final String _S8 = "Keywords glossary [K]";
|
||||
private static final String _S9 = "Quick reference...";
|
||||
private static final String _S10 = "Hide/show log [M]";
|
||||
private static final String _S11 = "Click to fast-forward stack.";
|
||||
|
||||
private final LogViewer logViewer;
|
||||
private final StackViewer stackViewer;
|
||||
private final ActionButtonTitleBar logTitleBar;
|
||||
private final ActionButtonTitleBar stackTitleBar;
|
||||
private MessageStyle messageStyle = GeneralConfig.getInstance().getLogMessageStyle();
|
||||
private int stackCount = 0;
|
||||
private final IUIGameController controller;
|
||||
|
||||
LogStackViewer(LogViewer aLogBookViewer, StackViewer aStackViewer) {
|
||||
LogStackViewer(LogViewer aLogBookViewer, StackViewer aStackViewer, IUIGameController controller) {
|
||||
|
||||
this.logViewer = aLogBookViewer;
|
||||
this.stackViewer = aStackViewer;
|
||||
this.controller = controller;
|
||||
|
||||
logTitleBar = new ActionButtonTitleBar(MText.get(_S4), getLogActionButtons());
|
||||
stackTitleBar = new ActionButtonTitleBar(MText.get(_S5), getStackActionButtons());
|
||||
stackTitleBar.getLabel().addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
if (stackCount > 0) {
|
||||
controller.setStackFastForward(true);
|
||||
MouseHelper.showDefaultCursor(stackTitleBar);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent e) {
|
||||
if (stackCount > 0 && !controller.isStackFastForward()) {
|
||||
MouseHelper.showHandCursor(stackTitleBar);
|
||||
} else {
|
||||
MouseHelper.showDefaultCursor(stackTitleBar);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void mouseExited(MouseEvent e) {
|
||||
MouseHelper.showDefaultCursor(stackTitleBar);
|
||||
}
|
||||
});
|
||||
|
||||
setOpaque(false);
|
||||
setBorders();
|
||||
|
@ -187,7 +224,22 @@ public class LogStackViewer extends JPanel {
|
|||
GeneralConfig.getInstance().save();
|
||||
}
|
||||
|
||||
public void setStackCount(int count) {
|
||||
stackTitleBar.setText(MText.get(_S5) + " : " + count);
|
||||
public void setStackCount(int newCount) {
|
||||
if (newCount == 0 || controller.isStackFastForward()) {
|
||||
final JLabel lbl = stackTitleBar.getLabel();
|
||||
lbl.setText(MText.get(_S5) + " : " + newCount);
|
||||
lbl.setIcon(null);
|
||||
lbl.setToolTipText(null);
|
||||
} else {
|
||||
final JLabel lbl = stackTitleBar.getLabel();
|
||||
lbl.setText(MText.get(_S5) + " : " + newCount + " ");
|
||||
lbl.setIcon(FFORWARD_ICON);
|
||||
lbl.setToolTipText(MText.get(_S11));
|
||||
lbl.setHorizontalTextPosition(SwingConstants.LEADING);
|
||||
}
|
||||
if (stackCount > 0 && newCount == 0) {
|
||||
controller.setStackFastForward(false);
|
||||
}
|
||||
stackCount = newCount;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue