/MWClient/src/main/java/mw/client/managers/DialogManager.java
Java | 605 lines | 418 code | 162 blank | 25 comment | 45 complexity | 8fbefeabe96e0ece9234f1083c3fa543 MD5 | raw file
- package mw.client.managers;
-
- import java.awt.Component;
- import java.awt.Rectangle;
- import java.awt.event.MouseEvent;
- import java.awt.event.MouseListener;
- import java.awt.event.MouseMotionListener;
- import java.awt.event.MouseWheelEvent;
- import java.util.ArrayList;
- import java.util.HashSet;
-
- import javax.swing.JComponent;
- import javax.swing.JOptionPane;
-
- import mw.client.dialogs.MessageDlg;
- import mw.client.utils.dialogs.DialogContainer;
- import mw.client.utils.dialogs.DlgParams;
- import mw.server.list.CardBeanList;
- import mw.server.model.DeckInfo;
- import mw.server.model.bean.CardBean;
- import mw.server.model.bean.SpellBean;
-
- public class DialogManager extends JComponent implements MouseListener,
- MouseMotionListener {
-
- private static DialogManager dialogManager = null;
- //private static final Logger log = Logger.getLogger(DialogManager.class);
-
- public static DialogManager getManager() {
- if (dialogManager == null) {
- dialogManager = new DialogManager();
- dialogManager.setVisible(true);
- }
- return dialogManager;
- }
-
- public enum MTGDialogs {
- none, AboutDialog, MessageDialog, StackDialog, AssignDamageDialog, ManaChoiceDialog, ChoiceDialog, GraveDialog, DialogContainer, CombatDialog,
- ChooseDeckDialog, ChooseCommonDialog, RevealDialog
- }
-
- private MTGDialogs currentDialog = MTGDialogs.none;
-
- private DialogContainer dialogContainer = null;
-
- private int screen_width = 0;
- private int screen_height = 0;
-
- // /////////////////////////////// *** for drag and drop ***
- // /////////////////////////////////
- private boolean bDragged = false;
- private int dx, dy;
- private int mx, my;
- private Rectangle rec, oldRec;
- private JComponent j;
-
- public DialogManager() {
- addMouseListener(this);
- addMouseMotionListener(this);
- //addMouseWheelListener(this);
- }
-
- public void setScreenWidth(int screen_width) {
- this.screen_width = screen_width;
- }
-
- public void setScreenHeight(int screen_height) {
- this.screen_height = screen_height;
- }
-
- public void showStackDialog() {
-
- int w = (int) (screen_width * 0.7);
- int h = (int) (screen_height * 0.5);
-
- if (h < 500) {
- h = 500;
- }
-
- if (w > 1024) {
- w = 1024;
- }
-
- int height = getHeight();
- int width = getWidth();
-
- int x = ((width - w) / 2);
- int y = ((height - h) / 2);
-
- DlgParams params = new DlgParams();
- params.rect = new Rectangle(x, y, w, h);
- dialogContainer = new DialogContainer(MTGDialogs.StackDialog, params);
- dialogContainer.setVisible(true);
- add(dialogContainer);
-
- this.currentDialog = MTGDialogs.DialogContainer;
-
- setDlgBounds(new Rectangle(x, y, w, h));
-
- dialogContainer.showDialog(true);
-
- setVisible(true);
- }
-
- public void showAboutDialog() {
-
- int w = (int) (screen_width * 0.7);
- int h = (int) (screen_height * 0.5);
-
- if (h < 500) {
- h = 500;
- }
-
- if (w > 1024) {
- w = 1024;
- }
-
- int height = getHeight();
- int width = getWidth();
-
- int x = ((width - w) / 2);
- int y = ((height - h) / 2);
-
- DlgParams params = new DlgParams();
- params.rect = new Rectangle(x, y, w, h);
- dialogContainer = new DialogContainer(MTGDialogs.AboutDialog, params);
- dialogContainer.setVisible(true);
- add(dialogContainer);
-
- this.currentDialog = MTGDialogs.DialogContainer;
-
- setDlgBounds(new Rectangle(x, y, w, h));
-
- dialogContainer.showDialog(true);
-
- setVisible(true);
- }
-
- public void showChoiceDialog(CardBeanList cardList, boolean targetOptional, boolean cancelStopsPlaying) {
-
- int w = (int) (790);
- int h = (int) (600);
-
- int height = getHeight();
- int width = getWidth();
-
- int x = ((width - w) / 2);
- int y = ((height - h) / 2);
-
- DlgParams params = new DlgParams();
- params.rect = new Rectangle(x, y, w, h);
- params.setCardList(cardList);
- params.setOptional(targetOptional);
- params.setCancelStopsPlaying(cancelStopsPlaying);
-
- dialogContainer = new DialogContainer(MTGDialogs.ChoiceDialog, params);
- dialogContainer.setVisible(true);
- add(dialogContainer);
-
- this.currentDialog = MTGDialogs.DialogContainer;
-
- setDlgBounds(new Rectangle(x, y, w, h));
-
- dialogContainer.showDialog(true);
-
- setVisible(true);
- }
-
- public void showAbilityChoiceDialog(ArrayList<SpellBean> spellBeanList, boolean targetOptional) {
-
- int w = (int) (790);
- int h = (int) (600);
-
- int height = getHeight();
- int width = getWidth();
-
- int x = ((width - w) / 2);
- int y = ((height - h) / 2);
-
- DlgParams params = new DlgParams();
- params.rect = new Rectangle(x, y, w, h);
-
- /**
- * Form card bean list from spell bean list
- */
- CardBeanList cardList = new CardBeanList();
- for (SpellBean spellBean : spellBeanList) {
- CardBean cardBean = spellBean.getSourceCardBean();
- cardBean.setAttachedSpellBean(spellBean);
- cardList.add(cardBean);
- }
- params.setCardList(cardList);
-
- params.setOptional(targetOptional);
- params.setChooseAbility(true);
- dialogContainer = new DialogContainer(MTGDialogs.ChoiceDialog, params);
- dialogContainer.setVisible(true);
- add(dialogContainer);
-
- this.currentDialog = MTGDialogs.DialogContainer;
-
- setDlgBounds(new Rectangle(x, y, w, h));
-
- dialogContainer.showDialog(true);
-
- setVisible(true);
- }
-
- public void showGraveDialog(int playerID, CardBeanList cardList) {
- int w = (int) (790);
- int h = (int) (600);
-
- int height = getHeight();
- int width = getWidth();
-
- int x = ((width - w) / 2);
- int y = ((height - h) / 2);
-
- DlgParams params = new DlgParams();
- params.rect = new Rectangle(x, y, w, h);
- params.setCardList(cardList);
- params.setPlayerID(playerID);
- dialogContainer = new DialogContainer(MTGDialogs.GraveDialog, params);
- dialogContainer.setVisible(true);
- add(dialogContainer);
-
- this.currentDialog = MTGDialogs.DialogContainer;
-
- setDlgBounds(new Rectangle(x, y, w, h));
-
- dialogContainer.showDialog(true);
-
- setVisible(true);
- }
-
- public void showRevealDialog(int playerID, CardBeanList cardList) {
- int w = (int) (790);
- int h = (int) (600);
-
- int height = getHeight();
- int width = getWidth();
-
- int x = ((width - w) / 2);
- int y = ((height - h) / 2);
-
- DlgParams params = new DlgParams();
- params.rect = new Rectangle(x, y, w, h);
- params.setCardList(cardList);
- params.setPlayerID(playerID);
- dialogContainer = new DialogContainer(MTGDialogs.RevealDialog, params);
- dialogContainer.setVisible(true);
- add(dialogContainer);
-
- this.currentDialog = MTGDialogs.DialogContainer;
-
- setDlgBounds(new Rectangle(x, y, w, h));
-
- dialogContainer.showDialog(true);
-
- setVisible(true);
- }
-
- public void showManaChoiceDialog(HashSet<String> manaSet) {
- removeAll();
-
- int w = (int) (350);
- int h = (int) (330);
-
- int height = getHeight();
- int width = getWidth();
-
- int x = ((width - w) / 2);
- int y = ((height - h) / 2);
-
- DlgParams params = new DlgParams();
- params.rect = new Rectangle(x, y, w, h);
- params.setManaChoices(manaSet);
- dialogContainer = new DialogContainer(MTGDialogs.ManaChoiceDialog, params);
- dialogContainer.setVisible(true);
- add(dialogContainer);
-
- this.currentDialog = MTGDialogs.DialogContainer;
-
- setDlgBounds(new Rectangle(x, y, w, h));
-
- dialogContainer.showDialog(true);
-
- setVisible(true);
- }
-
- public void showCombatDialog() {
- removeAll();
-
- int w = (int) (screen_width * 0.7);
- int h = (int) (screen_height * 0.5);
-
- if (h < 500) {
- h = 500;
- }
-
- int height = getHeight();
- int width = getWidth();
-
- int x = ((width - w) / 2);
- int y = ((height - h) / 2);
-
- DlgParams params = new DlgParams();
- params.rect = new Rectangle(x, y, w, h);
- dialogContainer = new DialogContainer(MTGDialogs.CombatDialog, params);
- dialogContainer.setVisible(true);
- add(dialogContainer);
-
- this.currentDialog = MTGDialogs.DialogContainer;
-
- setDlgBounds(new Rectangle(x, y, w, h));
-
- dialogContainer.showDialog(true);
-
- setVisible(true);
- }
-
- public void showAssignDamageDialog() {
- removeAll();
-
- int w = 600;
- int h = SettingsManager.getManager().getCardSize().height + 200;
-
- int height = getHeight();
- int width = getWidth();
-
- int x = ((width - w) / 2);
- int y = ((height - h) / 2);
-
- DlgParams params = new DlgParams();
- params.rect = new Rectangle(x, y, w, h);
- dialogContainer = new DialogContainer(MTGDialogs.AssignDamageDialog, params);
- dialogContainer.setVisible(true);
- add(dialogContainer);
-
- this.currentDialog = MTGDialogs.DialogContainer;
-
- setDlgBounds(new Rectangle(x, y, w, h));
-
- dialogContainer.showDialog(true);
-
- setVisible(true);
- }
-
- public void showMessageDlgWarning(String title, String message) {
- //showMessageDlg(title, message, 350, 88, MessageDlg.Types.Warning);
- JOptionPane.showMessageDialog(null, message, title, JOptionPane.WARNING_MESSAGE);
- }
-
- public DialogContainer showMessageDlg(String title, String message, int w, int h, MessageDlg.Types type) {
-
- DlgParams params = new DlgParams();
- params.setTitle(title);
- params.setMessage(message);
- params.type = type;
-
- int height = getHeight();
- int width = getWidth();
-
- int x = ((width - w) / 2);
- int y = ((height - h) / 2);
-
- params.rect = new Rectangle(x, y, w, h);
-
- dialogContainer = new DialogContainer(MTGDialogs.MessageDialog, params);
- dialogContainer.setVisible(true);
- add(dialogContainer);
-
- this.currentDialog = MTGDialogs.DialogContainer;
-
- setDlgBounds(new Rectangle(x, y, w, h));
-
- dialogContainer.showDialog(true);
-
- setVisible(true);
-
- //log.debug("show dialog: showMessageDlg");
-
- return dialogContainer;
- }
-
- public void showChooseDeckDialog(ArrayList<DeckInfo> deckList) {
- showChooseDeckDialog(deckList, false);
- }
-
- public void showChooseDeckDialog(ArrayList<DeckInfo> deckList, boolean isAI) {
-
- /*int w = (int) (screen_width * 0.7);
- int h = (int) (screen_height * 0.5);
-
- if (h < 500) {
- h = 500;
- }
-
- if (w > 1024) {
- w = 1024;
- }*/
-
- int w = 480;
- int h = 320;
-
- int height = getHeight();
- int width = getWidth();
-
- int x = ((width - w) / 2) + 100;
- int y = ((height - h) / 2) + 100;
- if (isAI) {
- x -= 150;
- y -= 150;
- }
-
-
-
- DlgParams params = new DlgParams();
- params.rect = new Rectangle(x, y, w, h);
- params.setDeckList(deckList);
- params.setAI(isAI);
- dialogContainer = new DialogContainer(MTGDialogs.ChooseDeckDialog, params);
- dialogContainer.setVisible(true);
- add(dialogContainer);
-
- this.currentDialog = MTGDialogs.DialogContainer;
-
- setDlgBounds(new Rectangle(x, y, w, h));
-
- dialogContainer.showDialog(true);
-
- setVisible(true);
- }
-
- public void showChooseDialog(ArrayList<Object> objectList) {
- showChooseDialog(objectList, null);
- }
-
- public void showChooseDialog(ArrayList<Object> objectList, String title) {
-
- int w = 440;
- int h = 240;
-
- int height = getHeight();
- int width = getWidth();
-
- int x = ((width - w) / 2);
- //int y = (2*(height - h) / 3);
- int y = ((height - h) / 2);
-
- DlgParams params = new DlgParams();
- params.rect = new Rectangle(x, y, w, h);
- params.setObjectList(objectList);
- params.setTitle(title);
- dialogContainer = new DialogContainer(MTGDialogs.ChooseCommonDialog, params);
- dialogContainer.setVisible(true);
- add(dialogContainer);
-
- this.currentDialog = MTGDialogs.DialogContainer;
-
- setDlgBounds(new Rectangle(x, y, w, h));
-
- dialogContainer.showDialog(true);
-
- setVisible(true);
- }
-
- public DialogContainer showMessageDlg(String title, String message, MessageDlg.Types type) {
- Rectangle r = new Rectangle();
- if (type.equals(MessageDlg.Types.Warning)) {
- r.width = 350;
- r.height = 88;
- } else if (type.equals(MessageDlg.Types.FlashInfo)) {
- r.width = 350;
- r.height = 90;
- }
- return showMessageDlg(title, message, r.width, r.height, type);
- }
-
- public void setDlgBounds(Rectangle r) {
- if (currentDialog == MTGDialogs.DialogContainer) {
- dialogContainer.setBounds(r.x, r.y, r.width, r.height);
- }
- }
-
- public void fadeOut() {
-
- if (dialogContainer != null) {
- dialogContainer.showDialog(false);
- removeAll();
- }
-
- this.currentDialog = MTGDialogs.none;
-
- setVisible(false);
-
- repaint();
- }
-
- public void fadeOut(DialogContainer dc) {
- //log.debug("start:fadeOut:"+dc.toString());
-
- dc.showDialog(false);
- remove(dc);
-
- Component[] components = getComponents();
- boolean bFound = false;
- for (int i = 0; i < components.length; i++) {
- if (components[i] instanceof DialogContainer) {
- bFound = true;
- }
- }
-
- if (!bFound) {
- setVisible(false);
- }
-
- //revalidate();
- validate();
- }
-
- public void mouseDragged(MouseEvent e) {
- if (bDragged == true) {
- dx = e.getX() - mx;
- dy = e.getY() - my;
-
- rec.x += dx;
- rec.y += dy;
- mx = e.getX();
- my = e.getY();
- if (oldRec == null) {
- oldRec = new Rectangle(rec);
- }
- int i = Math.abs(oldRec.x - rec.x) + Math.abs(oldRec.y - rec.y);
- if (i > 3) {
- oldRec = new Rectangle(rec);
- j.setBounds(oldRec);
- }
- }
- }
-
- public void mouseMoved(MouseEvent e) {
- }
-
- public void mouseClicked(MouseEvent e) {
- }
-
- public void mouseEntered(MouseEvent e) {
- }
-
- public void mouseExited(MouseEvent e) {
- }
-
- public void mousePressed(MouseEvent e) {
- if (e.getButton() == MouseEvent.BUTTON1) {
- j = (JComponent) getComponentAt(e.getX(), e.getY());
-
- if (j != null && j instanceof DialogContainer) {
- rec = j.getBounds();
- bDragged = true;
- mx = e.getX();
- my = e.getY();
- }
- }
- }
-
- public void mouseReleased(MouseEvent e) {
- bDragged = false;
- if (j instanceof DialogManager) {
- return;
- }
-
- if (j != null && rec != null) {
- j.setBounds(rec);
- }
- oldRec = null;
- if (rec == null)
- return;
- if (rec.x < 0) {
- rec.x = 0;
- if (j != null)
- j.setBounds(rec);
- }
- if (rec.y < 0) {
- rec.y = 0;
- if (j != null)
- j.setBounds(rec);
- }
- j = null;
- }
-
- public void mouseWheelMoved(MouseWheelEvent e) {
- int notches = e.getWheelRotation();
- System.out.println("outx:"+notches);
- if (currentDialog != null && currentDialog.equals(MTGDialogs.ChooseCommonDialog)) {
- System.out.println("out:"+1);
- }
- }
-
- /**
- * Default UID.
- */
- private static final long serialVersionUID = 1L;
-
- }