mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 03:08:02 +00:00
Overlay utils moved from GuiUtils to OverlayUtils.
This commit is contained in:
1
.gitattributes
vendored
1
.gitattributes
vendored
@@ -11425,6 +11425,7 @@ src/main/java/forge/gui/ListChooser.java svneol=native#text/plain
|
||||
src/main/java/forge/gui/MultiLineLabel.java svneol=native#text/plain
|
||||
src/main/java/forge/gui/MultiLineLabelUI.java svneol=native#text/plain
|
||||
src/main/java/forge/gui/MultiPhaseProgressMonitorWithETA.java svneol=native#text/plain
|
||||
src/main/java/forge/gui/OverlayUtils.java -text
|
||||
src/main/java/forge/gui/deckeditor/DeckController.java -text
|
||||
src/main/java/forge/gui/deckeditor/DeckEditorBase.java -text
|
||||
src/main/java/forge/gui/deckeditor/DeckEditorConstructed.java svneol=native#text/plain
|
||||
|
||||
@@ -15,6 +15,7 @@ import forge.deck.Deck;
|
||||
import forge.game.GameNew;
|
||||
import forge.game.GameType;
|
||||
import forge.gui.GuiUtils;
|
||||
import forge.gui.OverlayUtils;
|
||||
import forge.item.CardDb;
|
||||
import forge.item.CardPrinted;
|
||||
import forge.properties.ForgePreferences.FPref;
|
||||
@@ -61,14 +62,14 @@ public class ControlWinLose {
|
||||
|
||||
/** Action performed when "continue" button is pressed in default win/lose UI. */
|
||||
public void actionOnContinue() {
|
||||
GuiUtils.closeOverlay();
|
||||
OverlayUtils.closeOverlay();
|
||||
startNextRound();
|
||||
}
|
||||
|
||||
/** Action performed when "restart" button is pressed in default win/lose UI. */
|
||||
public void actionOnRestart() {
|
||||
Singletons.getModel().getMatchState().reset();
|
||||
GuiUtils.closeOverlay();
|
||||
OverlayUtils.closeOverlay();
|
||||
startNextRound();
|
||||
}
|
||||
|
||||
@@ -77,7 +78,7 @@ public class ControlWinLose {
|
||||
Singletons.getModel().getMatchState().reset();
|
||||
Singletons.getModel().savePrefs();
|
||||
Singletons.getControl().changeState(FControl.HOME_SCREEN);
|
||||
GuiUtils.closeOverlay();
|
||||
OverlayUtils.closeOverlay();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
*/
|
||||
package forge.gui;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Font;
|
||||
@@ -25,8 +24,6 @@ import java.awt.FontFormatException;
|
||||
import java.awt.Image;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Window;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -35,23 +32,14 @@ import java.util.List;
|
||||
|
||||
import javax.swing.Box;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JList;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.Timer;
|
||||
import javax.swing.border.LineBorder;
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
import javax.swing.event.ListSelectionListener;
|
||||
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
import forge.Card;
|
||||
import forge.Singletons;
|
||||
import forge.gui.toolbox.FLabel;
|
||||
import forge.gui.toolbox.FOverlay;
|
||||
import forge.gui.toolbox.FPanel;
|
||||
import forge.gui.toolbox.FSkin;
|
||||
import forge.properties.ForgeProps;
|
||||
import forge.properties.NewConstants;
|
||||
|
||||
@@ -64,8 +52,6 @@ import forge.properties.NewConstants;
|
||||
* @version $Id$
|
||||
*/
|
||||
public final class GuiUtils {
|
||||
private static int counter = 0;
|
||||
|
||||
private GuiUtils() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
@@ -403,98 +389,6 @@ public final class GuiUtils {
|
||||
return ttf;
|
||||
}
|
||||
|
||||
/** @return {@forge.gui.toolbox.FOverlay} */
|
||||
public static FOverlay startGameOverlay() {
|
||||
final FOverlay overlay = GuiUtils.genericOverlay();
|
||||
final int w = overlay.getWidth();
|
||||
final int h = overlay.getHeight();
|
||||
final int pnlW = 400;
|
||||
final int pnlH = 300;
|
||||
|
||||
// Adds the "loading" panel to generic overlay container
|
||||
// (which is preset with null layout and close button)
|
||||
final FPanel pnl = new FPanel();
|
||||
pnl.setCornerDiameter(0);
|
||||
pnl.setBackgroundTexture(FSkin.getIcon(FSkin.Backgrounds.BG_TEXTURE));
|
||||
pnl.setLayout(new MigLayout("insets 0, gap 0, ax center, wrap"));
|
||||
pnl.setBackground(FSkin.getColor(FSkin.Colors.CLR_ACTIVE));
|
||||
pnl.setBounds(new Rectangle(((w - pnlW) / 2), ((h - pnlH) / 2), pnlW, pnlH));
|
||||
|
||||
pnl.add(new FLabel.Builder().icon(FSkin.getIcon(FSkin.ForgeIcons.ICO_LOGO)).build(),
|
||||
"h 200px!, align center");
|
||||
pnl.add(new FLabel.Builder().text("Loading new game...")
|
||||
.fontScaleAuto(false).fontSize(22).build(), "h 40px!, align center");
|
||||
|
||||
overlay.add(pnl);
|
||||
|
||||
return overlay;
|
||||
}
|
||||
|
||||
/** @param msg0   {@link java.lang.String}
|
||||
@return {@forge.gui.toolbox.FOverlay} */
|
||||
// NOTE: This animation happens on the EDT; if the EDT is tied up doing something
|
||||
// else, the animation is effectively frozen. So, this needs some work.
|
||||
public static FOverlay loadingOverlay(final String msg0) {
|
||||
final FOverlay overlay = GuiUtils.genericOverlay();
|
||||
final FPanel pnlLoading = new FPanel();
|
||||
final int w = overlay.getWidth();
|
||||
final int h = overlay.getHeight();
|
||||
|
||||
final JLabel lblLoading = new JLabel("");
|
||||
lblLoading.setOpaque(true);
|
||||
lblLoading.setBackground(FSkin.getColor(FSkin.Colors.CLR_TEXT));
|
||||
lblLoading.setMinimumSize(new Dimension(0, 20));
|
||||
|
||||
pnlLoading.setBounds((int) ((w - 170) / 2), (int) ((h - 80) / 2), 170, 80);
|
||||
pnlLoading.setLayout(new MigLayout("wrap, align center"));
|
||||
pnlLoading.add(new FLabel.Builder().fontSize(18)
|
||||
.fontScaleAuto(false).text(msg0).build(), "h 20px!, w 140px!, gap 0 0 5px 0");
|
||||
pnlLoading.add(lblLoading, "gap 0 0 0 10px");
|
||||
|
||||
overlay.add(pnlLoading);
|
||||
|
||||
GuiUtils.counter = 0;
|
||||
final Timer timer = new Timer(300, new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
lblLoading.setMinimumSize(new Dimension(10 * (GuiUtils.counter++), 20));
|
||||
lblLoading.revalidate();
|
||||
if (GuiUtils.counter > 13) { GuiUtils.counter = 0; }
|
||||
}
|
||||
});
|
||||
timer.start();
|
||||
|
||||
return overlay;
|
||||
}
|
||||
|
||||
/** @return {@forge.gui.toolbox.FOverlay} */
|
||||
public static FOverlay genericOverlay() {
|
||||
final FOverlay overlay = Singletons.getView().getOverlay();
|
||||
final int w = overlay.getWidth();
|
||||
|
||||
final JButton btnCloseTopRight = new JButton("X");
|
||||
btnCloseTopRight.setBounds(w - 25, 10, 15, 15);
|
||||
btnCloseTopRight.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT));
|
||||
btnCloseTopRight.setBorder(new LineBorder(FSkin.getColor(FSkin.Colors.CLR_TEXT), 1));
|
||||
btnCloseTopRight.setOpaque(false);
|
||||
btnCloseTopRight.setBackground(new Color(0, 0, 0));
|
||||
btnCloseTopRight.setFocusPainted(false);
|
||||
btnCloseTopRight.addActionListener(new ActionListener() { @Override
|
||||
public void actionPerformed(ActionEvent arg0) { overlay.hideOverlay(); } });
|
||||
|
||||
overlay.removeAll();
|
||||
overlay.setLayout(null);
|
||||
overlay.add(btnCloseTopRight);
|
||||
|
||||
return overlay;
|
||||
}
|
||||
|
||||
/** Removes child components and closes overlay. */
|
||||
public static void closeOverlay() {
|
||||
Singletons.getView().getOverlay().removeAll();
|
||||
Singletons.getView().getOverlay().hideOverlay();
|
||||
}
|
||||
|
||||
/** Duplicate in DeckEditorQuestMenu and
|
||||
* probably elsewhere...can streamline at some point
|
||||
* (probably shouldn't be here).
|
||||
|
||||
119
src/main/java/forge/gui/OverlayUtils.java
Normal file
119
src/main/java/forge/gui/OverlayUtils.java
Normal file
@@ -0,0 +1,119 @@
|
||||
package forge.gui;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.Timer;
|
||||
import javax.swing.border.LineBorder;
|
||||
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
import forge.Singletons;
|
||||
import forge.gui.toolbox.FLabel;
|
||||
import forge.gui.toolbox.FOverlay;
|
||||
import forge.gui.toolbox.FPanel;
|
||||
import forge.gui.toolbox.FSkin;
|
||||
|
||||
/**
|
||||
* All overlay interaction is handled here.
|
||||
*
|
||||
*/
|
||||
public final class OverlayUtils {
|
||||
private static int counter = 0;
|
||||
|
||||
/** @return {@forge.gui.toolbox.FOverlay} */
|
||||
public static FOverlay startGameOverlay() {
|
||||
final FOverlay overlay = OverlayUtils.genericOverlay();
|
||||
final int w = overlay.getWidth();
|
||||
final int h = overlay.getHeight();
|
||||
final int pnlW = 400;
|
||||
final int pnlH = 300;
|
||||
|
||||
// Adds the "loading" panel to generic overlay container
|
||||
// (which is preset with null layout and close button)
|
||||
final FPanel pnl = new FPanel();
|
||||
pnl.setCornerDiameter(0);
|
||||
pnl.setBackgroundTexture(FSkin.getIcon(FSkin.Backgrounds.BG_TEXTURE));
|
||||
pnl.setLayout(new MigLayout("insets 0, gap 0, ax center, wrap"));
|
||||
pnl.setBackground(FSkin.getColor(FSkin.Colors.CLR_ACTIVE));
|
||||
pnl.setBounds(new Rectangle(((w - pnlW) / 2), ((h - pnlH) / 2), pnlW, pnlH));
|
||||
|
||||
pnl.add(new FLabel.Builder().icon(FSkin.getIcon(FSkin.ForgeIcons.ICO_LOGO)).build(),
|
||||
"h 200px!, align center");
|
||||
pnl.add(new FLabel.Builder().text("Loading new game...")
|
||||
.fontScaleAuto(false).fontSize(22).build(), "h 40px!, align center");
|
||||
|
||||
overlay.add(pnl);
|
||||
|
||||
return overlay;
|
||||
}
|
||||
|
||||
/** @param msg0   {@link java.lang.String}
|
||||
@return {@forge.gui.toolbox.FOverlay} */
|
||||
// NOTE: This animation happens on the EDT; if the EDT is tied up doing something
|
||||
// else, the animation is effectively frozen. So, this needs some work.
|
||||
public static FOverlay loadingOverlay(final String msg0) {
|
||||
final FOverlay overlay = OverlayUtils.genericOverlay();
|
||||
final FPanel pnlLoading = new FPanel();
|
||||
final int w = overlay.getWidth();
|
||||
final int h = overlay.getHeight();
|
||||
|
||||
final JLabel lblLoading = new JLabel("");
|
||||
lblLoading.setOpaque(true);
|
||||
lblLoading.setBackground(FSkin.getColor(FSkin.Colors.CLR_TEXT));
|
||||
lblLoading.setMinimumSize(new Dimension(0, 20));
|
||||
|
||||
pnlLoading.setBounds(((w - 170) / 2), ((h - 80) / 2), 170, 80);
|
||||
pnlLoading.setLayout(new MigLayout("wrap, align center"));
|
||||
pnlLoading.add(new FLabel.Builder().fontSize(18)
|
||||
.fontScaleAuto(false).text(msg0).build(), "h 20px!, w 140px!, gap 0 0 5px 0");
|
||||
pnlLoading.add(lblLoading, "gap 0 0 0 10px");
|
||||
|
||||
overlay.add(pnlLoading);
|
||||
|
||||
OverlayUtils.counter = 0;
|
||||
final Timer timer = new Timer(300, new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
lblLoading.setMinimumSize(new Dimension(10 * (OverlayUtils.counter++), 20));
|
||||
lblLoading.revalidate();
|
||||
if (OverlayUtils.counter > 13) { OverlayUtils.counter = 0; }
|
||||
}
|
||||
});
|
||||
timer.start();
|
||||
|
||||
return overlay;
|
||||
}
|
||||
|
||||
/** @return {@forge.gui.toolbox.FOverlay} */
|
||||
public static FOverlay genericOverlay() {
|
||||
final FOverlay overlay = Singletons.getView().getOverlay();
|
||||
final int w = overlay.getWidth();
|
||||
|
||||
final JButton btnCloseTopRight = new JButton("X");
|
||||
btnCloseTopRight.setBounds(w - 25, 10, 15, 15);
|
||||
btnCloseTopRight.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT));
|
||||
btnCloseTopRight.setBorder(new LineBorder(FSkin.getColor(FSkin.Colors.CLR_TEXT), 1));
|
||||
btnCloseTopRight.setOpaque(false);
|
||||
btnCloseTopRight.setBackground(new Color(0, 0, 0));
|
||||
btnCloseTopRight.setFocusPainted(false);
|
||||
btnCloseTopRight.addActionListener(new ActionListener() { @Override
|
||||
public void actionPerformed(ActionEvent arg0) { overlay.hideOverlay(); } });
|
||||
|
||||
overlay.removeAll();
|
||||
overlay.setLayout(null);
|
||||
overlay.add(btnCloseTopRight);
|
||||
|
||||
return overlay;
|
||||
}
|
||||
|
||||
/** Removes child components and closes overlay. */
|
||||
public static void closeOverlay() {
|
||||
Singletons.getView().getOverlay().removeAll();
|
||||
Singletons.getView().getOverlay().hideOverlay();
|
||||
}
|
||||
}
|
||||
@@ -44,6 +44,7 @@ import forge.deck.DeckGroup;
|
||||
import forge.error.ErrorViewer;
|
||||
import forge.game.limited.IBoosterDraft;
|
||||
import forge.gui.GuiUtils;
|
||||
import forge.gui.OverlayUtils;
|
||||
import forge.gui.deckeditor.elements.CardPanelLite;
|
||||
import forge.gui.deckeditor.elements.ManaCostRenderer;
|
||||
import forge.gui.deckeditor.elements.TableColumnInfo;
|
||||
@@ -128,7 +129,7 @@ public class DraftingProcess extends DeckEditorBase<CardPrinted, DeckGroup> {
|
||||
if (n == JOptionPane.YES_OPTION) {
|
||||
DraftingProcess.this.dispose();
|
||||
CSubmenuDraft.SINGLETON_INSTANCE.update();
|
||||
GuiUtils.closeOverlay();
|
||||
OverlayUtils.closeOverlay();
|
||||
}
|
||||
} // windowClosing()
|
||||
});
|
||||
@@ -340,7 +341,7 @@ public class DraftingProcess extends DeckEditorBase<CardPrinted, DeckGroup> {
|
||||
|
||||
// This should be handled in the exit command of the editor, not here.
|
||||
CSubmenuDraft.SINGLETON_INSTANCE.update();
|
||||
GuiUtils.closeOverlay();
|
||||
OverlayUtils.closeOverlay();
|
||||
} /* saveDraft() */
|
||||
|
||||
/*
|
||||
|
||||
@@ -34,7 +34,7 @@ import forge.deck.generate.Generate3ColorDeck;
|
||||
import forge.deck.generate.Generate5ColorDeck;
|
||||
import forge.deck.generate.GenerateThemeDeck;
|
||||
import forge.game.GameNew;
|
||||
import forge.gui.GuiUtils;
|
||||
import forge.gui.OverlayUtils;
|
||||
import forge.gui.home.ICSubmenu;
|
||||
import forge.gui.toolbox.FLabel;
|
||||
import forge.gui.toolbox.FOverlay;
|
||||
@@ -365,7 +365,7 @@ public enum CSubmenuConstructed implements ICSubmenu {
|
||||
GameNew.newGame(Constant.Runtime.HUMAN_DECK[0], Constant.Runtime.COMPUTER_DECK[0]);
|
||||
}
|
||||
|
||||
GuiUtils.closeOverlay();
|
||||
OverlayUtils.closeOverlay();
|
||||
}
|
||||
|
||||
/** Generates deck from current list selection(s). */
|
||||
|
||||
@@ -19,6 +19,7 @@ import forge.game.GameType;
|
||||
import forge.game.limited.BoosterDraft;
|
||||
import forge.game.limited.CardPoolLimitation;
|
||||
import forge.gui.GuiUtils;
|
||||
import forge.gui.OverlayUtils;
|
||||
import forge.gui.deckeditor.DraftingProcess;
|
||||
import forge.gui.home.ICSubmenu;
|
||||
import forge.gui.toolbox.FOverlay;
|
||||
@@ -78,7 +79,7 @@ public enum CSubmenuDraft implements ICSubmenu {
|
||||
@Override
|
||||
public void execute() {
|
||||
update();
|
||||
GuiUtils.closeOverlay();
|
||||
OverlayUtils.closeOverlay();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -182,7 +183,7 @@ public enum CSubmenuDraft implements ICSubmenu {
|
||||
return;
|
||||
}
|
||||
|
||||
GuiUtils.startGameOverlay().showOverlay();
|
||||
OverlayUtils.startGameOverlay().showOverlay();
|
||||
|
||||
DeckGroup opponentDecks = Singletons.getModel().getDecks().getDraft().get(human.getName());
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ import forge.deck.DeckGroup;
|
||||
import forge.game.GameNew;
|
||||
import forge.game.limited.SealedDeck;
|
||||
import forge.gui.GuiUtils;
|
||||
import forge.gui.OverlayUtils;
|
||||
import forge.gui.deckeditor.DeckEditorBase;
|
||||
import forge.gui.deckeditor.DeckEditorLimited;
|
||||
import forge.gui.home.ICSubmenu;
|
||||
@@ -47,7 +48,7 @@ public enum CSubmenuSealed implements ICSubmenu {
|
||||
@Override
|
||||
public void execute() {
|
||||
update();
|
||||
GuiUtils.closeOverlay();
|
||||
OverlayUtils.closeOverlay();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -140,7 +141,7 @@ public enum CSubmenuSealed implements ICSubmenu {
|
||||
return;
|
||||
}
|
||||
|
||||
GuiUtils.startGameOverlay().showOverlay();
|
||||
OverlayUtils.startGameOverlay().showOverlay();
|
||||
|
||||
Constant.Runtime.HUMAN_DECK[0] = human;
|
||||
Constant.Runtime.COMPUTER_DECK[0] = Singletons.getModel().getDecks().getSealed().get(human.getName()).getAiDecks().get(0);
|
||||
|
||||
@@ -17,7 +17,7 @@ import javax.swing.text.StyledDocument;
|
||||
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
import forge.game.GameType;
|
||||
import forge.gui.GuiUtils;
|
||||
import forge.gui.OverlayUtils;
|
||||
import forge.gui.home.EMenuGroup;
|
||||
import forge.gui.home.EMenuItem;
|
||||
import forge.gui.home.ICSubmenu;
|
||||
@@ -154,7 +154,7 @@ public enum VSubmenuDraft implements IVSubmenu {
|
||||
|
||||
/** */
|
||||
public void showDirections() {
|
||||
final FOverlay overlay = GuiUtils.genericOverlay();
|
||||
final FOverlay overlay = OverlayUtils.genericOverlay();
|
||||
final int w = overlay.getWidth();
|
||||
|
||||
final String instructions = "BOOSTER DRAFT MODE INSTRUCTIONS"
|
||||
|
||||
@@ -15,7 +15,7 @@ import javax.swing.text.StyledDocument;
|
||||
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
import forge.game.GameType;
|
||||
import forge.gui.GuiUtils;
|
||||
import forge.gui.OverlayUtils;
|
||||
import forge.gui.home.EMenuGroup;
|
||||
import forge.gui.home.EMenuItem;
|
||||
import forge.gui.home.ICSubmenu;
|
||||
@@ -133,7 +133,7 @@ public enum VSubmenuSealed implements IVSubmenu {
|
||||
|
||||
/** */
|
||||
public void showDirections() {
|
||||
final FOverlay overlay = GuiUtils.genericOverlay();
|
||||
final FOverlay overlay = OverlayUtils.genericOverlay();
|
||||
final int w = overlay.getWidth();
|
||||
|
||||
final String instructions = "SEALED DECK MODE INSTRUCTIONS"
|
||||
|
||||
@@ -44,6 +44,7 @@ import forge.game.GamePlayerRating;
|
||||
import forge.game.GameSummary;
|
||||
import forge.gui.GuiUtils;
|
||||
import forge.gui.ListChooser;
|
||||
import forge.gui.OverlayUtils;
|
||||
import forge.gui.home.quest.CSubmenuChallenges;
|
||||
import forge.gui.home.quest.CSubmenuDuels;
|
||||
import forge.gui.toolbox.FSkin;
|
||||
@@ -108,7 +109,7 @@ public class QuestWinLoseHandler extends ControlWinLose {
|
||||
@Override
|
||||
public final void startNextRound() {
|
||||
Singletons.getModel().savePrefs();
|
||||
GuiUtils.closeOverlay();
|
||||
OverlayUtils.closeOverlay();
|
||||
Singletons.getModel().getQuestPreferences().save();
|
||||
|
||||
if (Constant.Quest.FANTASY_QUEST[0]) {
|
||||
@@ -298,7 +299,7 @@ public class QuestWinLoseHandler extends ControlWinLose {
|
||||
|
||||
Singletons.getControl().changeState(FControl.HOME_SCREEN);
|
||||
|
||||
GuiUtils.closeOverlay();
|
||||
OverlayUtils.closeOverlay();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user