[Mobile] Deck View on Player Tab

- Deck Viewer is available on Player Tab -> Avatar Image click/tap
This commit is contained in:
Anthony Calosa
2022-01-23 15:48:39 +08:00
parent d5d70b51a7
commit bea0a53cbf
5 changed files with 144 additions and 107 deletions

View File

@@ -7,6 +7,8 @@ import java.util.List;
import java.util.Map;
import forge.ai.GameState;
import forge.deck.Deck;
import forge.game.player.Player;
import forge.item.IPaperCard;
import org.apache.commons.lang3.StringUtils;
@@ -94,14 +96,26 @@ public class MatchController extends AbstractGuiGame {
}
}
public static Deck getPlayerDeck(final PlayerView playerView) {
try {
for (Player p : instance.getGameView().getGame().getPlayers()) {
if (p.getView() == playerView) {
return p.getRegisteredPlayer().getDeck();
}
}
} catch (Exception e) {
return null;
}
return null;
}
public static FImage getPlayerAvatar(final PlayerView p) {
final String lp = p.getLobbyPlayerName();
FImage avatar = avatarImages.get(lp);
if (avatar == null) {
if (StringUtils.isEmpty(p.getAvatarCardImageKey())) {
avatar = new FTextureRegionImage(FSkin.getAvatars().get(p.getAvatarIndex()));
}
else { //handle lobby players with art from cards
} else { //handle lobby players with art from cards
avatar = new CardAvatarImage(p.getAvatarCardImageKey());
}
}

View File

@@ -354,26 +354,24 @@ public class MatchScreen extends FScreen {
final GameView game = MatchController.instance.getGameView();
if (game == null) { return; }
if(gameMenu!=null) {
if(gameMenu.getChildCount()>3){
if(viewWinLose == null) {
if (gameMenu!=null) {
if (gameMenu.getChildCount()>2){
if (viewWinLose == null) {
gameMenu.getChildAt(0).setEnabled(!game.isMulligan());
gameMenu.getChildAt(1).setEnabled(!game.isMulligan());
gameMenu.getChildAt(2).setEnabled(!game.isMulligan());
gameMenu.getChildAt(3).setEnabled(!game.isMulligan());
gameMenu.getChildAt(4).setEnabled(false);
gameMenu.getChildAt(3).setEnabled(false);
} else {
gameMenu.getChildAt(0).setEnabled(false);
gameMenu.getChildAt(1).setEnabled(false);
gameMenu.getChildAt(2).setEnabled(false);
gameMenu.getChildAt(3).setEnabled(false);
gameMenu.getChildAt(4).setEnabled(true);
gameMenu.getChildAt(3).setEnabled(true);
}
}
}
if(devMenu!=null) {
if(devMenu.isVisible()){
if(viewWinLose == null)
if (devMenu!=null) {
if (devMenu.isVisible()){
if (viewWinLose == null)
devMenu.setEnabled(true);
else
devMenu.setEnabled(false);

View File

@@ -47,26 +47,6 @@ public class VGameMenu extends FDropDownMenu {
GameStateDeserializer.loadGameState(MatchUtil.getGame(), ForgeConstants.USER_GAMES_DIR + "GameSave.txt");
}
}));*/
addItem(new FMenuItem(localizer.getMessage("lblDeckList"), FSkinImage.DECKLIST, new FEventHandler() {
@Override
public void handleEvent(FEvent e) {
//pause game when spectating AI Match
if (!MatchController.instance.hasLocalPlayers()) {
if(!MatchController.instance.isGamePaused())
MatchController.instance.pauseMatch();
}
final Player player = MatchController.getHostedMatch().getGame().getPhaseHandler().getPlayerTurn();
if (player != null) {
final Deck deck = player.getRegisteredPlayer().getDeck();
if (deck != null) {
FDeckViewer.show(deck);
return;
}
}
FOptionPane.showMessageDialog(localizer.getMessage("lblNoPlayerPriorityNoDeckListViewed"));
}
}));
addItem(new FMenuItem(localizer.getMessage("lblAutoYields"), Forge.hdbuttons ? FSkinImage.HDYIELD : FSkinImage.WARNING, new FEventHandler() {
@Override
public void handleEvent(FEvent e) {

View File

@@ -2,14 +2,19 @@ package forge.screens.match.views;
import com.badlogic.gdx.utils.Align;
import forge.Forge;
import forge.Graphics;
import forge.assets.FImage;
import forge.assets.FSkinFont;
import forge.assets.FSkinImage;
import forge.deck.Deck;
import forge.deck.FDeckViewer;
import forge.game.player.PlayerView;
import forge.menu.FDropDown;
import forge.screens.match.MatchController;
import forge.toolbox.FContainer;
import forge.toolbox.FDisplayObject;
import forge.toolbox.FEvent;
import forge.toolbox.FLabel;
import forge.toolbox.FList;
import forge.util.Utils;
@@ -42,14 +47,38 @@ public class VPlayers extends FDropDown {
private static final float PADDING = Utils.scale(5);
private static final float HEIGHT = Utils.AVG_FINGER_HEIGHT * 1.8f;
private final PlayerView player;
private final Deck playerDeck;
private final FLabel btnDeck;
private boolean btnAdded = false;
private PlayerInfoPanel(PlayerView player0) {
player = player0;
playerDeck = MatchController.getPlayerDeck(player0);
btnDeck = new FLabel.ButtonBuilder().opaque(true).iconScaleFactor(0.99f).selectable().alphaComposite(1).iconInBackground(true).build();
btnDeck.setCommand(new FEvent.FEventHandler() {
@Override
public void handleEvent(FEvent e) {
if (playerDeck != null) {
//pause game when spectating AI Match
if (!MatchController.instance.hasLocalPlayers()) {
if(!MatchController.instance.isGamePaused())
MatchController.instance.pauseMatch();
}
FDeckViewer.show(playerDeck);
}
}
});
}
@Override
protected void doLayout(float width, float height) {
//TODO: Add FLabels to click to select player in top or bottom panel of Match screen
if (!btnAdded) {
btnDeck.setBounds(PADDING, PADDING, getHeight() - 2 * PADDING, getHeight() - 2 * PADDING);
btnDeck.setIcon(MatchController.getPlayerAvatar(player));
btnDeck.setOverlayIcon(Forge.hdbuttons ? FSkinImage.HDSEARCH : FSkinImage.SEARCH);
add(btnDeck);
btnAdded = true;
}
}
@Override
@@ -57,12 +86,9 @@ public class VPlayers extends FDropDown {
float x = PADDING;
float y = PADDING;
float h = getHeight() - 2 * y;
FImage avatarImage = MatchController.getPlayerAvatar(player);
g.drawImage(avatarImage, x, y, h, h);
x += h + PADDING;
g.drawText(player.getDetails(), FONT, FList.FORE_COLOR, x, y, getWidth() - PADDING - x, h, true, Align.left, true);
//Draw Player Details
g.drawText(player.getDetails() + playerDeck.getName(), FONT, FList.FORE_COLOR, x, y, getWidth() - PADDING - x, h, true, Align.left, true);
}
@Override

View File

@@ -9,6 +9,7 @@ import forge.assets.FImage;
import forge.assets.FSkinColor;
import forge.assets.FSkinColor.Colors;
import forge.assets.FSkinFont;
import forge.assets.FSkinImage;
import forge.assets.TextRenderer;
import forge.gui.UiCommand;
import forge.gui.interfaces.IButton;
@@ -110,6 +111,7 @@ public class FLabel extends FDisplayObject implements IButton {
private String text;
private FImage icon;
private FSkinImage overlayIcon;
private FSkinColor textColor, pressedColor;
private FEventHandler command;
private TextRenderer textRenderer;
@@ -172,6 +174,9 @@ public class FLabel extends FDisplayObject implements IButton {
public void setIcon(final FImage icon0) {
icon = icon0;
}
public void setOverlayIcon(final FSkinImage overlayIcon0) {
overlayIcon = overlayIcon0;
}
public boolean getIconScaleAuto() {
return iconScaleAuto;
@@ -321,81 +326,95 @@ public class FLabel extends FDisplayObject implements IButton {
}
protected void drawContent(Graphics g, float x, float y, float w, float h) {
if (icon != null) {
float textY = y;
float iconWidth = icon.getWidth();
float iconHeight = icon.getHeight();
float aspectRatio = iconWidth / iconHeight;
try {
if (icon != null) {
float textY = y;
float iconWidth = icon.getWidth();
float iconHeight = icon.getHeight();
float aspectRatio = iconWidth / iconHeight;
if (iconScaleWithFont) {
iconHeight = font.getLineHeight() * iconScaleFactor;
iconWidth = iconHeight * aspectRatio;
}
else if (iconInBackground || iconScaleAuto) {
iconHeight = h * iconScaleFactor;
iconWidth = iconHeight * aspectRatio;
if (iconWidth > w && iconInBackground) { //ensure background icon stays with label bounds
iconWidth = w;
iconHeight = iconWidth / aspectRatio;
if (iconScaleWithFont) {
iconHeight = font.getLineHeight() * iconScaleFactor;
iconWidth = iconHeight * aspectRatio;
}
}
float iconOffset = iconWidth + insets.x + getExtraGapBetweenIconAndText();
if (iconInBackground || text.isEmpty()) {
if (alignment == Align.center) {
x += (w - iconWidth) / 2;
}
y += (h - iconHeight) / 2;
}
else {
if (alignment == Align.center) {
float dx;
while (true) {
dx = (w - iconOffset - getTextWidth()) / 2;
if (dx > 0) {
x += dx;
break;
}
if (!font.canShrink()) {
break;
}
font = font.shrink();
else if (iconInBackground || iconScaleAuto) {
iconHeight = h * iconScaleFactor;
iconWidth = iconHeight * aspectRatio;
if (iconWidth > w && iconInBackground) { //ensure background icon stays with label bounds
iconWidth = w;
iconHeight = iconWidth / aspectRatio;
}
}
else if (alignment == Align.right) {
float dx;
while (true) {
dx = (w - iconWidth - getTextWidth() - insets.x);
if (dx > 0) {
x += dx;
break;
}
if (!font.canShrink()) {
break;
}
font = font.shrink();
}
}
y += (h - iconHeight) / 2;
}
float mod = isHovered() && selectable ? iconWidth < iconHeight ? iconWidth/8f : iconHeight/8f : 0;
g.drawImage(icon, x-mod/2, y-mod/2, iconWidth+mod, iconHeight+mod);
if (!text.isEmpty()) {
x += iconOffset;
w -= iconOffset;
drawText(g, x, textY, w, h, Align.left);
float iconOffset = iconWidth + insets.x + getExtraGapBetweenIconAndText();
if (iconInBackground || text.isEmpty()) {
if (alignment == Align.center) {
x += (w - iconWidth) / 2;
}
y += (h - iconHeight) / 2;
}
else {
if (alignment == Align.center) {
float dx;
while (true) {
dx = (w - iconOffset - getTextWidth()) / 2;
if (dx > 0) {
x += dx;
break;
}
if (!font.canShrink()) {
break;
}
font = font.shrink();
}
}
else if (alignment == Align.right) {
float dx;
while (true) {
dx = (w - iconWidth - getTextWidth() - insets.x);
if (dx > 0) {
x += dx;
break;
}
if (!font.canShrink()) {
break;
}
font = font.shrink();
}
}
y += (h - iconHeight) / 2;
}
float mod = isHovered() && selectable ? iconWidth < iconHeight ? iconWidth/8f : iconHeight/8f : 0;
//draw icon
g.drawImage(icon, x-mod/2, y-mod/2, iconWidth+mod, iconHeight+mod);
//draw overlay
if (overlayIcon != null) {
float oldAlpha = g.getfloatAlphaComposite();
float overlayWidth = isHovered() ? iconWidth/2.5f : iconWidth/3.5f;
float overlayHeight = isHovered() ? iconHeight/2.5f : iconHeight/3.5f;
if (!isHovered())
g.setAlphaComposite(0.4f);
g.drawImage(overlayIcon, iconWidth-overlayWidth+mod, iconHeight-overlayHeight+mod, overlayWidth, overlayHeight);
g.setAlphaComposite(oldAlpha);
}
if (!text.isEmpty()) {
x += iconOffset;
w -= iconOffset;
drawText(g, x, textY, w, h, Align.left);
}
}
}
else if (!text.isEmpty()) {
float oldAlpha = g.getfloatAlphaComposite();
if (isHovered() && selectable) {
g.setAlphaComposite(0.4f);
g.fillRect(Color.GRAY, x, y, w, h);
g.setAlphaComposite(oldAlpha);
else if (!text.isEmpty()) {
float oldAlpha = g.getfloatAlphaComposite();
if (isHovered() && selectable) {
g.setAlphaComposite(0.4f);
g.fillRect(Color.GRAY, x, y, w, h);
g.setAlphaComposite(oldAlpha);
}
drawText(g, x, y, w, h, alignment);
}
drawText(g, x, y, w, h, alignment);
} catch (Exception e) {
e.printStackTrace();
}
}