Add support for displaying achievement earned dialog nicer

This commit is contained in:
drdev
2014-09-18 18:25:59 +00:00
parent 0d006b6ab6
commit b6222582fa
8 changed files with 111 additions and 21 deletions

View File

@@ -71,6 +71,7 @@ import forge.sound.IAudioMusic;
import forge.toolbox.FButton;
import forge.toolbox.FOptionPane;
import forge.toolbox.FSkin;
import forge.toolbox.FSkin.SkinImage;
import forge.toolbox.MouseTriggerEvent;
import forge.toolbox.special.PhaseLabel;
import forge.util.BuildInfo;
@@ -146,6 +147,11 @@ public class GuiDesktop implements IGuiBase {
return new FSkin.UnskinnedIcon(image, opacity);
}
@Override
public void showImageDialog(ISkinImage image, String message, String title) {
FOptionPane.showMessageDialog(message, title, (SkinImage)image);
}
@Override
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);

View File

@@ -5,6 +5,7 @@ import forge.toolbox.FSkin.SkinImage;
import forge.view.FDialog;
import javax.swing.*;
import javax.swing.text.StyleConstants;
import java.awt.*;
import java.awt.event.ActionEvent;
@@ -137,21 +138,41 @@ public class FOptionPane extends FDialog {
int padding = 10;
int x = padding;
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) {
FLabel lblIcon = new FLabel.Builder().icon(icon).build();
int labelWidth = icon.getWidth();
this.add(lblIcon, "x " + (x - 3) + ", ay top, w " + labelWidth + ", h " + icon.getHeight() + ", gapbottom " + gapBottom);
x += labelWidth;
if (icon.getWidth() < 100) {
FLabel lblIcon = new FLabel.Builder().icon(icon).build();
this.add(lblIcon, "x " + (x - 3) + ", ay top, w " + icon.getWidth() + ", h " + icon.getHeight() + ", gapbottom " + gapBottom);
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) {
FTextArea prompt = new FTextArea(message);
prompt.setFont(FSkin.getFont(14));
prompt.setAutoSize(true);
Dimension parentSize = JOptionPane.getRootFrame().getSize();
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);
if (centeredLabel == null) {
FTextArea prompt = new FTextArea(message);
prompt.setFont(FSkin.getFont(14));
prompt.setAutoSize(true);
Dimension parentSize = JOptionPane.getRootFrame().getSize();
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;
}
if (comp != null) {
@@ -233,6 +254,11 @@ public class FOptionPane extends FDialog {
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
}

View 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);
}
}