mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 19:58:00 +00:00
Improve appearance of multiple items on stack
This commit is contained in:
@@ -1,5 +1,8 @@
|
|||||||
package forge.screens.match.views;
|
package forge.screens.match.views;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import com.badlogic.gdx.graphics.Color;
|
import com.badlogic.gdx.graphics.Color;
|
||||||
import com.badlogic.gdx.graphics.g2d.BitmapFont.HAlignment;
|
import com.badlogic.gdx.graphics.g2d.BitmapFont.HAlignment;
|
||||||
|
|
||||||
@@ -66,13 +69,25 @@ public class VStack extends FDropDown {
|
|||||||
float y = 0;
|
float y = 0;
|
||||||
float width = maxWidth / 2;
|
float width = maxWidth / 2;
|
||||||
StackInstanceDisplay display;
|
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) {
|
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);
|
height = display.getMinHeight(width);
|
||||||
display.setBounds(0, y, width, height);
|
display.setBounds(width - width * scale, y, width * scale, height);
|
||||||
y += 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);
|
return new ScrollBounds(width, y);
|
||||||
}
|
}
|
||||||
@@ -80,6 +95,7 @@ public class VStack extends FDropDown {
|
|||||||
private class StackInstanceDisplay extends FDisplayObject {
|
private class StackInstanceDisplay extends FDisplayObject {
|
||||||
private final SpellAbilityStackInstance stackInstance;
|
private final SpellAbilityStackInstance stackInstance;
|
||||||
private FSkinColor foreColor, backColor;
|
private FSkinColor foreColor, backColor;
|
||||||
|
private float scale;
|
||||||
private String text;
|
private String text;
|
||||||
|
|
||||||
private StackInstanceDisplay(SpellAbilityStackInstance stackInstance0) {
|
private StackInstanceDisplay(SpellAbilityStackInstance stackInstance0) {
|
||||||
@@ -130,13 +146,15 @@ public class VStack extends FDropDown {
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreColor = foreColor.alphaColor(0.9f);
|
foreColor = foreColor.alphaColor(0.9f);
|
||||||
backColor = backColor.alphaColor(0.8f);
|
backColor = backColor.alphaColor(0.9f);
|
||||||
}
|
}
|
||||||
|
|
||||||
private float getMinHeight(float width) {
|
private float getMinHeight(float width) {
|
||||||
width -= CARD_WIDTH; //account for card picture
|
width -= CARD_WIDTH; //account for card picture
|
||||||
width -= 3 * PADDING; //account for left and right insets and gap between picture and text
|
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
|
@Override
|
||||||
@@ -148,13 +166,17 @@ public class VStack extends FDropDown {
|
|||||||
g.fillRect(backColor, 0, 0, w, h);
|
g.fillRect(backColor, 0, 0, w, h);
|
||||||
g.drawRect(2, foreColor, 0, 0, w, h);
|
g.drawRect(2, foreColor, 0, 0, w, h);
|
||||||
|
|
||||||
float x = PADDING;
|
float padding = PADDING * scale;
|
||||||
float y = PADDING;
|
float cardWidth = CARD_WIDTH * scale;
|
||||||
g.drawImage(ImageCache.getImage(stackInstance.getSourceCard()), x, y, CARD_WIDTH, CARD_HEIGHT);
|
float cardHeight = CARD_HEIGHT * scale;
|
||||||
|
|
||||||
x += CARD_WIDTH + PADDING;
|
float x = padding;
|
||||||
w -= x + PADDING;
|
float y = padding;
|
||||||
h -= y + PADDING;
|
g.drawImage(ImageCache.getImage(stackInstance.getSourceCard()), x, y, cardWidth, cardHeight);
|
||||||
|
|
||||||
|
x += cardWidth + padding;
|
||||||
|
w -= x + padding;
|
||||||
|
h -= y + padding;
|
||||||
|
|
||||||
g.drawText(text, FONT, foreColor, x, y, w, h, true, HAlignment.LEFT, true);
|
g.drawText(text, FONT, foreColor, x, y, w, h, true, HAlignment.LEFT, true);
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import com.google.common.base.Function;
|
|||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
|
|
||||||
import forge.game.card.Card;
|
import forge.game.card.Card;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import java.util.*;
|
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) {
|
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) {
|
if (min == 0) {
|
||||||
return new ArrayList<T>();
|
return new ArrayList<T>();
|
||||||
}
|
}
|
||||||
throw new RuntimeException("choice required from empty list");
|
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
|
@Override
|
||||||
public List<T> call() {
|
public List<T> call() {
|
||||||
ListChooser<T> c = new ListChooser<T>(message, min, max, choices, display);
|
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
|
} catch (Exception e) { // should be no exception here
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}*/
|
}*/
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> List<T> many(final String title, final String topCaption, int cnt, final List<T> sourceChoices, Card referenceCard) {
|
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);
|
final List<T> choice = GuiChoose.sortedGetChoices(message, 0, 1, choices, comparer);
|
||||||
return choice.isEmpty() ? null : choice.get(0);
|
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
|
// 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) {
|
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);
|
final List<T> choice = GuiChoose.sortedGetChoices(message, 1, 1, choices, comparer);
|
||||||
assert choice.size() == 1;
|
assert choice.size() == 1;
|
||||||
return choice.get(0);
|
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
|
// 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) {
|
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);
|
Collections.sort(choices, comparer);
|
||||||
return getChoices(message, min, max, choices);
|
return getChoices(message, min, max, choices);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user