mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 04:38:00 +00:00
Add support for displaying achievement earned dialog nicer
This commit is contained in:
1
.gitattributes
vendored
1
.gitattributes
vendored
@@ -1011,6 +1011,7 @@ forge-gui-desktop/src/main/java/forge/toolbox/FTabbedPane.java -text
|
|||||||
forge-gui-desktop/src/main/java/forge/toolbox/FTextArea.java -text
|
forge-gui-desktop/src/main/java/forge/toolbox/FTextArea.java -text
|
||||||
forge-gui-desktop/src/main/java/forge/toolbox/FTextEditor.java -text
|
forge-gui-desktop/src/main/java/forge/toolbox/FTextEditor.java -text
|
||||||
forge-gui-desktop/src/main/java/forge/toolbox/FTextField.java -text
|
forge-gui-desktop/src/main/java/forge/toolbox/FTextField.java -text
|
||||||
|
forge-gui-desktop/src/main/java/forge/toolbox/FTextPane.java -text
|
||||||
forge-gui-desktop/src/main/java/forge/toolbox/FUndoManager.java -text
|
forge-gui-desktop/src/main/java/forge/toolbox/FUndoManager.java -text
|
||||||
forge-gui-desktop/src/main/java/forge/toolbox/IDisposable.java -text
|
forge-gui-desktop/src/main/java/forge/toolbox/IDisposable.java -text
|
||||||
forge-gui-desktop/src/main/java/forge/toolbox/JXButtonPanel.java -text
|
forge-gui-desktop/src/main/java/forge/toolbox/JXButtonPanel.java -text
|
||||||
|
|||||||
@@ -71,6 +71,7 @@ import forge.sound.IAudioMusic;
|
|||||||
import forge.toolbox.FButton;
|
import forge.toolbox.FButton;
|
||||||
import forge.toolbox.FOptionPane;
|
import forge.toolbox.FOptionPane;
|
||||||
import forge.toolbox.FSkin;
|
import forge.toolbox.FSkin;
|
||||||
|
import forge.toolbox.FSkin.SkinImage;
|
||||||
import forge.toolbox.MouseTriggerEvent;
|
import forge.toolbox.MouseTriggerEvent;
|
||||||
import forge.toolbox.special.PhaseLabel;
|
import forge.toolbox.special.PhaseLabel;
|
||||||
import forge.util.BuildInfo;
|
import forge.util.BuildInfo;
|
||||||
@@ -146,6 +147,11 @@ public class GuiDesktop implements IGuiBase {
|
|||||||
return new FSkin.UnskinnedIcon(image, opacity);
|
return new FSkin.UnskinnedIcon(image, opacity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void showImageDialog(ISkinImage image, String message, String title) {
|
||||||
|
FOptionPane.showMessageDialog(message, title, (SkinImage)image);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int showOptionDialog(String message, String title, FSkinProp icon, String[] options, int defaultOption) {
|
public int showOptionDialog(String message, String title, FSkinProp icon, String[] options, int defaultOption) {
|
||||||
return FOptionPane.showOptionDialog(message, title, icon == null ? null : FSkin.getImage(icon), options, defaultOption);
|
return FOptionPane.showOptionDialog(message, title, icon == null ? null : FSkin.getImage(icon), options, defaultOption);
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import forge.toolbox.FSkin.SkinImage;
|
|||||||
import forge.view.FDialog;
|
import forge.view.FDialog;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
import javax.swing.text.StyleConstants;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
@@ -137,21 +138,41 @@ public class FOptionPane extends FDialog {
|
|||||||
int padding = 10;
|
int padding = 10;
|
||||||
int x = padding;
|
int x = padding;
|
||||||
int gapAboveButtons = padding * 3 / 2;
|
int gapAboveButtons = padding * 3 / 2;
|
||||||
int gapBottom = comp == null ? gapAboveButtons: padding;
|
int gapBottom = comp == null ? gapAboveButtons : padding;
|
||||||
|
FLabel centeredLabel = null;
|
||||||
|
FTextPane centeredPrompt = null;
|
||||||
|
|
||||||
if (icon != null) {
|
if (icon != null) {
|
||||||
FLabel lblIcon = new FLabel.Builder().icon(icon).build();
|
if (icon.getWidth() < 100) {
|
||||||
int labelWidth = icon.getWidth();
|
FLabel lblIcon = new FLabel.Builder().icon(icon).build();
|
||||||
this.add(lblIcon, "x " + (x - 3) + ", ay top, w " + labelWidth + ", h " + icon.getHeight() + ", gapbottom " + gapBottom);
|
this.add(lblIcon, "x " + (x - 3) + ", ay top, w " + icon.getWidth() + ", h " + icon.getHeight() + ", gapbottom " + gapBottom);
|
||||||
x += labelWidth;
|
x += icon.getWidth();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
FLabel lblIcon = new FLabel.Builder().icon(icon).iconInBackground(true).iconScaleFactor(1).iconAlignX(SwingConstants.CENTER).build();
|
||||||
|
lblIcon.setMinimumSize(new Dimension(icon.getWidth() * 2, icon.getHeight()));
|
||||||
|
this.add(lblIcon, "x " + x + ", ay top, wrap, gapbottom " + gapBottom);
|
||||||
|
centeredLabel = lblIcon;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (message != null) {
|
if (message != null) {
|
||||||
FTextArea prompt = new FTextArea(message);
|
if (centeredLabel == null) {
|
||||||
prompt.setFont(FSkin.getFont(14));
|
FTextArea prompt = new FTextArea(message);
|
||||||
prompt.setAutoSize(true);
|
prompt.setFont(FSkin.getFont(14));
|
||||||
Dimension parentSize = JOptionPane.getRootFrame().getSize();
|
prompt.setAutoSize(true);
|
||||||
prompt.setMaximumSize(new Dimension(parentSize.width / 2, parentSize.height - 100));
|
Dimension parentSize = JOptionPane.getRootFrame().getSize();
|
||||||
this.add(prompt, "x " + x + ", ay top, wrap, gaptop " + (icon == null ? 0 : 7) + ", gapbottom " + gapBottom);
|
prompt.setMaximumSize(new Dimension(parentSize.width / 2, parentSize.height - 100));
|
||||||
|
this.add(prompt, "x " + x + ", ay top, wrap, gaptop " + (icon == null ? 0 : 7) + ", gapbottom " + gapBottom);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
FTextPane prompt = new FTextPane(message);
|
||||||
|
prompt.setFont(FSkin.getFont(14));
|
||||||
|
prompt.setTextAlignment(StyleConstants.ALIGN_CENTER);
|
||||||
|
Dimension parentSize = JOptionPane.getRootFrame().getSize();
|
||||||
|
prompt.setMaximumSize(new Dimension(parentSize.width / 2, parentSize.height - 100));
|
||||||
|
this.add(prompt, "x " + x + ", ay top, wrap, gapbottom " + gapBottom);
|
||||||
|
centeredPrompt = prompt;
|
||||||
|
}
|
||||||
x = padding;
|
x = padding;
|
||||||
}
|
}
|
||||||
if (comp != null) {
|
if (comp != null) {
|
||||||
@@ -233,6 +254,11 @@ public class FOptionPane extends FDialog {
|
|||||||
x += dx;
|
x += dx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (centeredLabel != null) {
|
||||||
|
centeredLabel.setPreferredSize(new Dimension(width - 2 * padding, centeredLabel.getMinimumSize().height));
|
||||||
|
centeredPrompt.setPreferredSize(new Dimension(width - 2 * padding, centeredPrompt.getPreferredSize().height));
|
||||||
|
}
|
||||||
|
|
||||||
this.setSize(width, this.getHeight() + buttonHeight); //resize dialog again to account for buttons
|
this.setSize(width, this.getHeight() + buttonHeight); //resize dialog again to account for buttons
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
37
forge-gui-desktop/src/main/java/forge/toolbox/FTextPane.java
Normal file
37
forge-gui-desktop/src/main/java/forge/toolbox/FTextPane.java
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
package forge.toolbox;
|
||||||
|
|
||||||
|
import forge.toolbox.FSkin.SkinnedTextPane;
|
||||||
|
|
||||||
|
import javax.swing.text.SimpleAttributeSet;
|
||||||
|
import javax.swing.text.StyleConstants;
|
||||||
|
import javax.swing.text.StyledDocument;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A custom instance of JTextArea using Forge skin properties.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("serial")
|
||||||
|
public class FTextPane extends SkinnedTextPane {
|
||||||
|
/** */
|
||||||
|
public FTextPane() {
|
||||||
|
super();
|
||||||
|
this.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT));
|
||||||
|
this.setCaretColor(FSkin.getColor(FSkin.Colors.CLR_TEXT));
|
||||||
|
this.setOpaque(false);
|
||||||
|
this.setFocusable(false);
|
||||||
|
this.setEditable(false);
|
||||||
|
}
|
||||||
|
/** @param str {@java.lang.String} */
|
||||||
|
public FTextPane(final String str) {
|
||||||
|
this();
|
||||||
|
this.setText(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Use constant in StyleConstants
|
||||||
|
public void setTextAlignment(int alignment) {
|
||||||
|
StyledDocument doc = getStyledDocument();
|
||||||
|
SimpleAttributeSet attrSet = new SimpleAttributeSet();
|
||||||
|
StyleConstants.setAlignment(attrSet, alignment);
|
||||||
|
doc.setParagraphAttributes(0, doc.getLength(), attrSet, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,6 +15,7 @@ import com.google.common.base.Function;
|
|||||||
|
|
||||||
import forge.assets.FBufferedImage;
|
import forge.assets.FBufferedImage;
|
||||||
import forge.assets.FDelayLoadImage;
|
import forge.assets.FDelayLoadImage;
|
||||||
|
import forge.assets.FImage;
|
||||||
import forge.assets.FSkin;
|
import forge.assets.FSkin;
|
||||||
import forge.assets.FSkinProp;
|
import forge.assets.FSkinProp;
|
||||||
import forge.assets.FTextureImage;
|
import forge.assets.FTextureImage;
|
||||||
@@ -127,6 +128,16 @@ public class GuiMobile implements IGuiBase {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void showImageDialog(final ISkinImage image, final String message, final String title) {
|
||||||
|
new WaitCallback<Void>() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
FOptionPane.showMessageDialog(message, title, (FImage)image);
|
||||||
|
}
|
||||||
|
}.invokeAndWait();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int showOptionDialog(final String message, final String title, final FSkinProp icon, final String[] options, final int defaultOption) {
|
public int showOptionDialog(final String message, final String title, final FSkinProp icon, final String[] options, final int defaultOption) {
|
||||||
return new WaitCallback<Integer>() {
|
return new WaitCallback<Integer>() {
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import forge.assets.ISkinImage;
|
|||||||
import forge.game.Game;
|
import forge.game.Game;
|
||||||
import forge.game.player.Player;
|
import forge.game.player.Player;
|
||||||
import forge.interfaces.IGuiBase;
|
import forge.interfaces.IGuiBase;
|
||||||
import forge.util.gui.SOptionPane;
|
|
||||||
|
|
||||||
public abstract class Achievement {
|
public abstract class Achievement {
|
||||||
private final String displayName, sharedDesc, commonDesc, uncommonDesc, rareDesc, mythicDesc;
|
private final String displayName, sharedDesc, commonDesc, uncommonDesc, rareDesc, mythicDesc;
|
||||||
@@ -147,6 +146,7 @@ public abstract class Achievement {
|
|||||||
}
|
}
|
||||||
else if (current >= best) { return; }
|
else if (current >= best) { return; }
|
||||||
|
|
||||||
|
boolean hadEarnedSpecial = earnedSpecial();
|
||||||
boolean hadEarnedMythic = earnedMythic();
|
boolean hadEarnedMythic = earnedMythic();
|
||||||
boolean hadEarnedRare = earnedRare();
|
boolean hadEarnedRare = earnedRare();
|
||||||
boolean hadEarnedUncommon = earnedUncommon();
|
boolean hadEarnedUncommon = earnedUncommon();
|
||||||
@@ -154,6 +154,16 @@ public abstract class Achievement {
|
|||||||
|
|
||||||
best = current;
|
best = current;
|
||||||
|
|
||||||
|
if (earnedSpecial()) {
|
||||||
|
if (!hadEarnedSpecial) {
|
||||||
|
if (image != null) { //only update image if it has already been initialized
|
||||||
|
updateTrophyImage();
|
||||||
|
}
|
||||||
|
gui.showImageDialog(image, displayName + "\n" + sharedDesc + ".", "Achievement Earned");
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
String type = null;
|
String type = null;
|
||||||
String desc = null;
|
String desc = null;
|
||||||
if (earnedMythic()) {
|
if (earnedMythic()) {
|
||||||
@@ -181,14 +191,11 @@ public abstract class Achievement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (type != null) {
|
if (type != null) {
|
||||||
if (image != null) { //only update image if it has already been initialized
|
updateTrophyImage();
|
||||||
updateTrophyImage();
|
|
||||||
}
|
|
||||||
if (sharedDesc != null) {
|
if (sharedDesc != null) {
|
||||||
desc = sharedDesc + " " + desc;
|
desc = sharedDesc + " " + desc;
|
||||||
}
|
}
|
||||||
SOptionPane.showMessageDialog(gui, "You've earned a " + type + " trophy!\n\n" +
|
gui.showImageDialog(image, displayName + " (" + type + ")\n" + desc + ".", "Achievement Earned");
|
||||||
displayName + "\n" + desc + ".", "Achievement Earned", overlayImage);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,16 +4,17 @@ import forge.assets.FSkinProp;
|
|||||||
import forge.game.Game;
|
import forge.game.Game;
|
||||||
import forge.game.GameType;
|
import forge.game.GameType;
|
||||||
import forge.game.player.Player;
|
import forge.game.player.Player;
|
||||||
|
import forge.util.Lang;
|
||||||
|
|
||||||
public class VariantWins extends Achievement {
|
public class VariantWins extends Achievement {
|
||||||
private GameType variant;
|
private GameType variant;
|
||||||
|
|
||||||
public VariantWins(GameType variant0, int silver0, int gold0, int mythic0, FSkinProp image0) {
|
public VariantWins(GameType variant0, int silver0, int gold0, int mythic0, FSkinProp image0) {
|
||||||
super(variant0.toString(), null,
|
super(variant0.toString(), null,
|
||||||
String.format("Win a %s game", variant0.toString()), 1,
|
"Win " + Lang.nounWithAmount(1, variant0.toString() + " game"), 1,
|
||||||
String.format("Win %d %s games", silver0, variant0.toString()), silver0,
|
"Win " + Lang.nounWithAmount(silver0, variant0.toString() + " game"), silver0,
|
||||||
String.format("Win %d %s games", gold0, variant0.toString()), gold0,
|
"Win " + Lang.nounWithAmount(gold0, variant0.toString() + " game"), gold0,
|
||||||
String.format("Win %d %s games", mythic0, variant0.toString()), mythic0,
|
"Win " + Lang.nounWithAmount(mythic0, variant0.toString() + " game"), mythic0,
|
||||||
image0);
|
image0);
|
||||||
variant = variant0;
|
variant = variant0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ public interface IGuiBase {
|
|||||||
ISkinImage getUnskinnedIcon(String path);
|
ISkinImage getUnskinnedIcon(String path);
|
||||||
ISkinImage createLayeredImage(FSkinProp background, FSkinProp overlay, float opacity);
|
ISkinImage createLayeredImage(FSkinProp background, FSkinProp overlay, float opacity);
|
||||||
void showBugReportDialog(String title, String text, boolean showExitAppBtn);
|
void showBugReportDialog(String title, String text, boolean showExitAppBtn);
|
||||||
|
void showImageDialog(ISkinImage image, String message, String title);
|
||||||
int showOptionDialog(String message, String title, FSkinProp icon, String[] options, int defaultOption);
|
int showOptionDialog(String message, String title, FSkinProp icon, String[] options, int defaultOption);
|
||||||
int showCardOptionDialog(CardView card, String message, String title, FSkinProp icon, String[] options, int defaultOption);
|
int showCardOptionDialog(CardView card, String message, String title, FSkinProp icon, String[] options, int defaultOption);
|
||||||
<T> T showInputDialog(String message, String title, FSkinProp icon, T initialInput, T[] inputOptions);
|
<T> T showInputDialog(String message, String title, FSkinProp icon, T initialInput, T[] inputOptions);
|
||||||
|
|||||||
Reference in New Issue
Block a user