foul-magics/Mage.Client/src/main/java/mage/client/MagePane.java
draxdyn a7409f3d08 Hold priority on Ctrl+click
In most cases, it is not useful to hold priority after doing something,
since the spell or ability added to the stack can just be performed
beforehand.

Hence, automatically passing priority is the only comfortable setting.

However, in some cases it is useful (chiefly for Infernal Tutor +
Lion's Eye Diamond and similar interaction), and currently players
have to open Preferences, change the option and then change it back
whenever they need to hold priority, which is very annoying.

This change allows to temporarily hold priority by simply holding
Control while performing an action, which solves the issue in a
manner similar to other clients.

A "Hold" indicator next to the spells cast indicator is displayed so
that the user knows his Control key holding was registered.

The code works by adding a new HOLD_PRIORITY player action that causes
the automatic priority pass options to be ignored until the player is
given priority again.

The client sends the message whenever it's not already holding priority
and Ctrl+click/space/enter happens anywhere.

This is somewhat "loose" as it means that Ctrl+click on the background
also holds priority, but this might actually be desirable and it greatly
simplifies the code, since only a global AWT event listener is required,
and there is no need to change every place in the code that could add
something to the stack.

It is also possible to hold priority and stop holding priority using
the context menu.
2016-06-29 19:57:45 +02:00

125 lines
3.9 KiB
Java

/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
/*
* MagePane.java
*
* Created on 15-Dec-2009, 9:34:25 PM
*/
package mage.client;
import java.awt.AWTEvent;
import java.awt.KeyboardFocusManager;
import java.beans.PropertyVetoException;
import javax.swing.plaf.basic.BasicInternalFrameUI;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public abstract class MagePane extends javax.swing.JInternalFrame {
/**
* Creates new form MagePane
*/
public MagePane() {
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
initComponents();
hideTitle();
}
private void hideTitle() {
if (ui instanceof BasicInternalFrameUI) {
((BasicInternalFrameUI) ui).setNorthPane(null);
}
}
public void changeGUISize() {
}
@Override
public void updateUI() {
super.updateUI();
hideTitle();
}
public void hideFrame() {
MageFrame.deactivate(this);
}
public void removeFrame() {
KeyboardFocusManager.getCurrentKeyboardFocusManager().clearGlobalFocusOwner();
try {
this.setClosed(true);
} catch (PropertyVetoException ex) {
}
MageFrame.deactivate(this);
MageFrame.getDesktop().remove(this);
}
public void activated() {
}
public void deactivated() {
}
public void handleEvent(AWTEvent event) {
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
setBorder(null);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 765, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 476, Short.MAX_VALUE)
);
pack();
}// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
// End of variables declaration//GEN-END:variables
}