Improve appearance of multiple items on stack

This commit is contained in:
drdev
2014-03-24 02:39:33 +00:00
parent b6f245071f
commit 13259c9896
2 changed files with 52 additions and 18 deletions

View File

@@ -1,5 +1,8 @@
package forge.screens.match.views;
import java.util.ArrayList;
import java.util.List;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.BitmapFont.HAlignment;
@@ -66,13 +69,25 @@ public class VStack extends FDropDown {
float y = 0;
float width = maxWidth / 2;
StackInstanceDisplay display;
float height;
float height = 0;
float scale = 1; //scale size down as you go from top to bottom
List<StackInstanceDisplay> displays = new ArrayList<StackInstanceDisplay>();
for (final SpellAbilityStackInstance stackInstance : stack) {
display = add(new StackInstanceDisplay(stackInstance));
if (y > 0) {
y -= CARD_HEIGHT * scale / 4; //allow partial overlap between layers of stack
}
display = new StackInstanceDisplay(stackInstance);
display.scale = scale;
height = display.getMinHeight(width);
display.setBounds(0, y, width, height);
display.setBounds(width - width * scale, y, width * scale, height);
y += height;
scale *= 0.85f;
displays.add(display);
}
//add in reverse order so top of stack appears on top
for (int i = displays.size() - 1; i >= 0; i--) {
add(displays.get(i));
}
return new ScrollBounds(width, y);
}
@@ -80,6 +95,7 @@ public class VStack extends FDropDown {
private class StackInstanceDisplay extends FDisplayObject {
private final SpellAbilityStackInstance stackInstance;
private FSkinColor foreColor, backColor;
private float scale;
private String text;
private StackInstanceDisplay(SpellAbilityStackInstance stackInstance0) {
@@ -130,13 +146,15 @@ public class VStack extends FDropDown {
}
foreColor = foreColor.alphaColor(0.9f);
backColor = backColor.alphaColor(0.8f);
backColor = backColor.alphaColor(0.9f);
}
private float getMinHeight(float width) {
width -= CARD_WIDTH; //account for card picture
width -= 3 * PADDING; //account for left and right insets and gap between picture and text
return Math.max(CARD_HEIGHT, FONT.getFont().getWrappedBounds(text, width).height) + 2 * PADDING;
float height = Math.max(CARD_HEIGHT, FONT.getFont().getWrappedBounds(text, width).height);
height += 2 * PADDING;
return height * scale;
}
@Override
@@ -148,13 +166,17 @@ public class VStack extends FDropDown {
g.fillRect(backColor, 0, 0, w, h);
g.drawRect(2, foreColor, 0, 0, w, h);
float x = PADDING;
float y = PADDING;
g.drawImage(ImageCache.getImage(stackInstance.getSourceCard()), x, y, CARD_WIDTH, CARD_HEIGHT);
float padding = PADDING * scale;
float cardWidth = CARD_WIDTH * scale;
float cardHeight = CARD_HEIGHT * scale;
float x = padding;
float y = padding;
g.drawImage(ImageCache.getImage(stackInstance.getSourceCard()), x, y, cardWidth, cardHeight);
x += CARD_WIDTH + PADDING;
w -= x + PADDING;
h -= y + PADDING;
x += cardWidth + padding;
w -= x + padding;
h -= y + padding;
g.drawText(text, FONT, foreColor, x, y, w, h, true, HAlignment.LEFT, true);

View File

@@ -4,6 +4,7 @@ import com.google.common.base.Function;
import com.google.common.collect.Iterables;
import forge.game.card.Card;
import org.apache.commons.lang3.StringUtils;
import java.util.*;
@@ -173,14 +174,28 @@ public class GuiChoose {
}
public static <T> List<T> getChoices(final String message, final int min, final int max, final Collection<T> choices, final T selected, final Function<T, String> display) {
/*if (choices == null || choices.isEmpty()) {
if (choices == null || choices.isEmpty()) {
if (min == 0) {
return new ArrayList<T>();
}
throw new RuntimeException("choice required from empty list");
}
Callable<List<T>> showChoice = new Callable<List<T>>() {
//TODO: Remove this temporary code and uncomment below
int resultCount = min;
if (resultCount == 0 && max > 0) {
resultCount = 1;
}
List<T> result = new ArrayList<T>();
for (T choice : choices) {
result.add(choice);
if (result.size() == resultCount) {
break;
}
}
return result;
/*Callable<List<T>> showChoice = new Callable<List<T>>() {
@Override
public List<T> call() {
ListChooser<T> c = new ListChooser<T>(message, min, max, choices, display);
@@ -225,7 +240,6 @@ public class GuiChoose {
} catch (Exception e) { // should be no exception here
e.printStackTrace();
}*/
return null;
}
public static <T> List<T> many(final String title, final String topCaption, int cnt, final List<T> sourceChoices, Card referenceCard) {
@@ -303,15 +317,14 @@ public class GuiChoose {
}
final List<T> choice = GuiChoose.sortedGetChoices(message, 0, 1, choices, comparer);
return choice.isEmpty() ? null : choice.get(0);
} // getChoiceOptional(String,T...)
}
// If comparer is NULL, T has to be comparable. Otherwise you'll get an exception from inside the Arrays.sort() routine
public static <T> T sortedOne(final String message, final T[] choices, Comparator<T> comparer) {
final List<T> choice = GuiChoose.sortedGetChoices(message, 1, 1, choices, comparer);
assert choice.size() == 1;
return choice.get(0);
} // getChoice()
}
// If comparer is NULL, T has to be comparable. Otherwise you'll get an exception from inside the Arrays.sort() routine
public static <T> T sortedOne(final String message, final List<T> choices, Comparator<T> comparer) {
@@ -341,6 +354,5 @@ public class GuiChoose {
Collections.sort(choices, comparer);
return getChoices(message, min, max, choices);
}
}