Merge origin/master

This commit is contained in:
LevelX2 2017-07-29 17:39:36 +02:00
commit 052fbb3ab6
2 changed files with 110 additions and 29 deletions

View file

@ -7,7 +7,6 @@ import mage.cards.decks.DeckCardLayout;
import mage.cards.repository.CardCriteria; import mage.cards.repository.CardCriteria;
import mage.cards.repository.CardInfo; import mage.cards.repository.CardInfo;
import mage.cards.repository.CardRepository; import mage.cards.repository.CardRepository;
import mage.client.MageFrame;
import mage.client.constants.Constants; import mage.client.constants.Constants;
import mage.client.dialog.PreferencesDialog; import mage.client.dialog.PreferencesDialog;
import mage.client.plugins.impl.Plugins; import mage.client.plugins.impl.Plugins;
@ -1410,38 +1409,36 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
} }
} }
String finalInfo = "Found the following quantity of mana costs, mana sources and land types:<br><font size=-1><ul>"; JPanel panel = new JPanel();
for (String qty : qtys.keySet()) { panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
int value = qtys.get(qty);
if (value > 0) {
finalInfo += "<li>" + qty + " = " + value;
}
}
for (String source : sourcePips.keySet()) { JPanel panel2 = new JPanel();
int value = sourcePips.get(source); panel2.setLayout(new BoxLayout(panel2, BoxLayout.Y_AXIS));
if (value > 0) { ManaPieChart chart = new ManaPieChart(pips.get("#w}"), pips.get("#u}"), pips.get("#b}"), pips.get("#r}"), pips.get("#g}"), pips.get("#c}"));
finalInfo += "<li>" + "Mana source " + source + " = " + value; chart.setMinimumSize(new Dimension(200, 200));
} panel2.add(new JLabel("Casting Costs found:"));
} panel2.add(chart);
for (String pip : pips.keySet()) { JPanel panel3 = new JPanel();
int value = pips.get(pip); panel3.setLayout(new BoxLayout(panel3, BoxLayout.Y_AXIS));
if (value > 0) { ManaPieChart chart2 = new ManaPieChart(qtys.get("plains"), qtys.get("island"), qtys.get("swamp"), qtys.get("mountain"), qtys.get("forest"), qtys.get("wastes"));
finalInfo += "<li>" + pip.toUpperCase() + " mana pip/s = " + value; chart2.setMinimumSize(new Dimension(200, 200));
} panel3.add(new JLabel("Basic Land types found:"));
} panel3.add(chart2);
for (String mana : manaCounts.keySet()) { JPanel panel4 = new JPanel();
int value = manaCounts.get(mana); panel4.setLayout(new BoxLayout(panel4, BoxLayout.Y_AXIS));
if (value > 0) { ManaPieChart chart3 = new ManaPieChart(manaCounts.get("{W}"), manaCounts.get("{U}"), manaCounts.get("{B}"), manaCounts.get("{R}"), manaCounts.get("{G}"), manaCounts.get("{C}"));
finalInfo += "<li>" + mana.toUpperCase() + " mana sources = " + value; chart3.setMinimumSize(new Dimension(200, 200));
} panel4.add(new JLabel("Mana sources found:"));
} panel4.add(chart3);
finalInfo = finalInfo.replaceAll("#", "\\{");
finalInfo += "</ul>";
MageFrame.getInstance().showMessage(finalInfo); panel.add(panel2);
panel.add(panel3);
panel.add(panel4);
JFrame frame = new JFrame("JOptionPane showMessageDialog component example");
JOptionPane.showMessageDialog(frame, panel, "This is the distribution of colors found", JOptionPane.INFORMATION_MESSAGE);
} }
public void blingDeck() { public void blingDeck() {

View file

@ -0,0 +1,84 @@
package mage.client.cards;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.util.ArrayList;
import javax.swing.JComponent;
class Slice {
double value;
Color color;
public Slice(double value, Color color) {
this.value = value;
this.color = color;
}
}
public class ManaPieChart extends JComponent {
ArrayList<Slice> slices = new ArrayList<Slice>();
ManaPieChart() {
}
ManaPieChart(Integer w, Integer u, Integer b, Integer r, Integer g, Integer c) {
if (w != null && w > 0) {
slices.add(new Slice(w, Color.WHITE));
}
if (u != null && u > 0) {
slices.add(new Slice(u, Color.BLUE));
}
if (b != null && b > 0) {
slices.add(new Slice(b, Color.BLACK));
}
if (r != null && r > 0) {
slices.add(new Slice(r, Color.RED));
}
if (g != null && g > 0) {
slices.add(new Slice(g, Color.GREEN));
}
if (c != null && c > 0) {
slices.add(new Slice(c, Color.LIGHT_GRAY));
}
}
@Override
public Dimension getPreferredSize() {
Dimension preferred = super.getPreferredSize();
Dimension minimum = getMinimumSize();
Dimension maximum = getMaximumSize();
preferred.width = Math.min(Math.max(preferred.width, minimum.width), maximum.width);
preferred.height = Math.min(Math.max(preferred.height, minimum.height), maximum.height);
return preferred;
}
public void paint(Graphics g) {
drawPie((Graphics2D) g, getBounds(), slices.toArray(new Slice[slices.size()]));
}
void drawPie(Graphics2D g, Rectangle area, Slice[] slices) {
double total = 0.0D;
for (int i = 0; i < slices.length; i++) {
total += slices[i].value;
}
double curValue = 0.0D;
int startAngle = 0;
int lastAngle = 0;
for (int i = 0; i < slices.length; i++) {
startAngle = lastAngle;
int arcAngle = (int) (slices[i].value * 360 / total);
g.setColor(slices[i].color);
g.fillArc(area.x, area.y, area.width - 20, area.height - 20, startAngle, arcAngle);
curValue += slices[i].value;
lastAngle += arcAngle;
}
}
}