mirror of
https://github.com/correl/mage.git
synced 2024-12-25 03:00:15 +00:00
Mana Circles for deck analysis
This commit is contained in:
parent
d0d7f7720a
commit
b6a7998eab
2 changed files with 110 additions and 29 deletions
|
@ -7,7 +7,6 @@ import mage.cards.decks.DeckCardLayout;
|
|||
import mage.cards.repository.CardCriteria;
|
||||
import mage.cards.repository.CardInfo;
|
||||
import mage.cards.repository.CardRepository;
|
||||
import mage.client.MageFrame;
|
||||
import mage.client.constants.Constants;
|
||||
import mage.client.dialog.PreferencesDialog;
|
||||
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>";
|
||||
for (String qty : qtys.keySet()) {
|
||||
int value = qtys.get(qty);
|
||||
if (value > 0) {
|
||||
finalInfo += "<li>" + qty + " = " + value;
|
||||
}
|
||||
}
|
||||
JPanel panel = new JPanel();
|
||||
panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
|
||||
|
||||
for (String source : sourcePips.keySet()) {
|
||||
int value = sourcePips.get(source);
|
||||
if (value > 0) {
|
||||
finalInfo += "<li>" + "Mana source " + source + " = " + value;
|
||||
}
|
||||
}
|
||||
JPanel panel2 = new JPanel();
|
||||
panel2.setLayout(new BoxLayout(panel2, BoxLayout.Y_AXIS));
|
||||
ManaPieChart chart = new ManaPieChart(pips.get("#w}"), pips.get("#u}"), pips.get("#b}"), pips.get("#r}"), pips.get("#g}"), pips.get("#c}"));
|
||||
chart.setMinimumSize(new Dimension(200, 200));
|
||||
panel2.add(new JLabel("Casting Costs found:"));
|
||||
panel2.add(chart);
|
||||
|
||||
for (String pip : pips.keySet()) {
|
||||
int value = pips.get(pip);
|
||||
if (value > 0) {
|
||||
finalInfo += "<li>" + pip.toUpperCase() + " mana pip/s = " + value;
|
||||
}
|
||||
}
|
||||
JPanel panel3 = new JPanel();
|
||||
panel3.setLayout(new BoxLayout(panel3, BoxLayout.Y_AXIS));
|
||||
ManaPieChart chart2 = new ManaPieChart(qtys.get("plains"), qtys.get("island"), qtys.get("swamp"), qtys.get("mountain"), qtys.get("forest"), qtys.get("wastes"));
|
||||
chart2.setMinimumSize(new Dimension(200, 200));
|
||||
panel3.add(new JLabel("Basic Land types found:"));
|
||||
panel3.add(chart2);
|
||||
|
||||
for (String mana : manaCounts.keySet()) {
|
||||
int value = manaCounts.get(mana);
|
||||
if (value > 0) {
|
||||
finalInfo += "<li>" + mana.toUpperCase() + " mana sources = " + value;
|
||||
}
|
||||
}
|
||||
finalInfo = finalInfo.replaceAll("#", "\\{");
|
||||
finalInfo += "</ul>";
|
||||
JPanel panel4 = new JPanel();
|
||||
panel4.setLayout(new BoxLayout(panel4, BoxLayout.Y_AXIS));
|
||||
ManaPieChart chart3 = new ManaPieChart(manaCounts.get("{W}"), manaCounts.get("{U}"), manaCounts.get("{B}"), manaCounts.get("{R}"), manaCounts.get("{G}"), manaCounts.get("{C}"));
|
||||
chart3.setMinimumSize(new Dimension(200, 200));
|
||||
panel4.add(new JLabel("Mana sources found:"));
|
||||
panel4.add(chart3);
|
||||
|
||||
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() {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue