diff --git a/.gitattributes b/.gitattributes index a6203cda068..0e0878f52a8 100644 --- a/.gitattributes +++ b/.gitattributes @@ -16005,6 +16005,7 @@ forge-m-base/src/forge/assets/FSkin.java -text forge-m-base/src/forge/assets/FSkinColor.java -text forge-m-base/src/forge/assets/FSkinFont.java -text forge-m-base/src/forge/assets/FSkinImage.java -text +forge-m-base/src/forge/assets/FSkinTexture.java -text forge-m-base/src/forge/player/LobbyPlayerHuman.java -text forge-m-base/src/forge/player/PlayerControllerHuman.java -text forge-m-base/src/forge/screens/FScreen.java -text diff --git a/forge-m-base/src/forge/Forge.java b/forge-m-base/src/forge/Forge.java index d27439e2677..1e202113705 100644 --- a/forge-m-base/src/forge/Forge.java +++ b/forge-m-base/src/forge/Forge.java @@ -8,6 +8,7 @@ import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.GL10; import com.badlogic.gdx.graphics.GL20; +import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.TextureRegion; @@ -413,6 +414,9 @@ public class Forge implements ApplicationListener { public void drawImage(FImage image, float x, float y, float w, float h) { image.draw(this, x, y, w, h); } + public void drawImage(Texture image, float x, float y, float w, float h) { + batch.draw(image, adjustX(x), adjustY(y, h), w, h); + } public void drawImage(TextureRegion image, float x, float y, float w, float h) { batch.draw(image, adjustX(x), adjustY(y, h), w, h); } diff --git a/forge-m-base/src/forge/assets/FImage.java b/forge-m-base/src/forge/assets/FImage.java index 3343f89c3a1..d8fead1e944 100644 --- a/forge-m-base/src/forge/assets/FImage.java +++ b/forge-m-base/src/forge/assets/FImage.java @@ -3,7 +3,7 @@ package forge.assets; import forge.Forge.Graphics; public interface FImage { - float getSourceWidth(); - float getSourceHeight(); + float getWidth(); + float getHeight(); void draw(Graphics g, float x, float y, float w, float h); } diff --git a/forge-m-base/src/forge/assets/FSkin.java b/forge-m-base/src/forge/assets/FSkin.java index a307ef4d089..03d40e3dee1 100644 --- a/forge-m-base/src/forge/assets/FSkin.java +++ b/forge-m-base/src/forge/assets/FSkin.java @@ -23,7 +23,6 @@ public class FSkin { FILE_AVATAR_SPRITE = "sprite_avatars.png", DEFAULT_DIR = FILE_SKINS_DIR + "default/"; - private static final Map images = new HashMap(); private static final Map avatars = new HashMap(); private static ArrayList allSkins; @@ -65,14 +64,12 @@ public class FSkin { } } - images.clear(); - // Non-default (preferred) skin name and dir. preferredName = skinName.toLowerCase().replace(' ', '_'); preferredDir = FILE_SKINS_DIR + preferredName + "/"; if (splashScreen != null) { - final FileHandle f = Gdx.files.internal(preferredDir + SourceFile.SPLASH.getFilename()); + final FileHandle f = Gdx.files.internal(preferredDir + "bg_splash.png"); if (!f.exists()) { if (!skinName.equals("default")) { FSkin.loadLight("default", splashScreen); @@ -161,12 +158,12 @@ public class FSkin { c.setColor(new Color(preferredIcons.getPixel(c.getX(), c.getY()))); } - //add images + //load images for (FSkinImage image : FSkinImage.values()) { - TextureRegion textureRegion = loadTextureRegion(image, textures, preferredIcons); - if (textureRegion != null) { - images.put(image, textureRegion); - } + image.load(preferredDir, DEFAULT_DIR, textures, preferredIcons); + } + for (FSkinTexture image : FSkinTexture.values()) { + image.load(preferredDir, DEFAULT_DIR); } //assemble avatar textures @@ -269,91 +266,6 @@ public class FSkin { addEncodingSymbol("T", GameplayImages.IMG_TAP);*/ } - private static TextureRegion loadTextureRegion(FSkinImage image, Map textures, Pixmap preferredIcons) { - SourceFile sourceFile = image.getSourceFile(); - String filename = sourceFile.getFilename(); - String preferredFile = preferredDir + filename; - Texture texture = textures.get(preferredFile); - if (texture == null) { - FileHandle file = Gdx.files.internal(preferredFile); - if (file.exists()) { - try { - texture = new Texture(file); - } - catch (final Exception e) { - System.err.println("Failed to load skin file: " + preferredFile); - e.printStackTrace(); - } - } - } - if (texture != null) { - int fullWidth = texture.getWidth(); - int fullHeight = texture.getHeight(); - int x0 = image.getX(); - int y0 = image.getY(); - int w0 = image.getWidth(fullWidth); - int h0 = image.getHeight(fullHeight); - - if (sourceFile != SourceFile.ICONS) { //just return region for preferred file if not icons file - return new TextureRegion(texture, x0, y0, w0, h0); - } - else { - // Test if requested sub-image in inside bounds of preferred sprite. - // (Height and width of preferred sprite were set in loadFontAndImages.) - if (x0 + w0 <= fullWidth && y0 + h0 <= fullHeight) { - // Test if various points of requested sub-image are transparent. - // If any return true, image exists. - int x = 0, y = 0; - Color c; - - // Center - x = (x0 + w0 / 2); - y = (y0 + h0 / 2); - c = new Color(preferredIcons.getPixel(x, y)); - if (c.a != 0) { return new TextureRegion(texture, x0, y0, w0, h0); } - - x += 2; - y += 2; - c = new Color(preferredIcons.getPixel(x, y)); - if (c.a != 0) { return new TextureRegion(texture, x0, y0, w0, h0); } - - x -= 4; - c = new Color(preferredIcons.getPixel(x, y)); - if (c.a != 0) { return new TextureRegion(texture, x0, y0, w0, h0); } - - y -= 4; - c = new Color(preferredIcons.getPixel(x, y)); - if (c.a != 0) { return new TextureRegion(texture, x0, y0, w0, h0); } - - x += 4; - c = new Color(preferredIcons.getPixel(x, y)); - if (c.a != 0) { return new TextureRegion(texture, x0, y0, w0, h0); } - } - } - } - - //use default file if can't use preferred file - String defaultFile = DEFAULT_DIR + filename; - texture = textures.get(defaultFile); - if (texture == null) { - FileHandle file = Gdx.files.internal(defaultFile); - if (file.exists()) { - try { - texture = new Texture(file); - } - catch (final Exception e) { - System.err.println("Failed to load skin file: " + defaultFile); - e.printStackTrace(); - } - } - } - if (texture != null) { - return new TextureRegion(texture, image.getX(), image.getY(), - image.getWidth(texture.getWidth()), image.getHeight(texture.getHeight())); - } - return null; - } - /** * Gets the name. * @@ -406,10 +318,6 @@ public class FSkin { return allSkins; } - public static Map getImages() { - return images; - } - public static Map getAvatars() { return avatars; } diff --git a/forge-m-base/src/forge/assets/FSkinImage.java b/forge-m-base/src/forge/assets/FSkinImage.java index b484516db4c..06c2f627b89 100644 --- a/forge-m-base/src/forge/assets/FSkinImage.java +++ b/forge-m-base/src/forge/assets/FSkinImage.java @@ -1,15 +1,20 @@ package forge.assets; +import java.util.Map; + +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.files.FileHandle; +import com.badlogic.gdx.graphics.Color; +import com.badlogic.gdx.graphics.Pixmap; +import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.graphics.g2d.TextureRegion; + import forge.Forge.Graphics; /** Properties of various components that make up the skin. * This interface allows all enums to be under the same roof. * It also enforces a getter for coordinate locations in sprites. */ public enum FSkinImage implements FImage { - //Backgrounds - BG_TEXTURE (0, 0, 0, 0, SourceFile.TEXTURE), - BG_MATCH (0, 0, 0, 0, SourceFile.MATCH), - //Zones HAND (280, 40, 40, 40, SourceFile.ICONS), LIBRARY (280, 0, 40, 40, SourceFile.ICONS), @@ -227,10 +232,7 @@ public enum FSkinImage implements FImage { public enum SourceFile { ICONS("sprite_icons.png"), FOILS("sprite_foils.png"), - OLD_FOILS("sprite_old_foils.png"), - SPLASH("bg_splash.png"), - MATCH("bg_match.jpg"), - TEXTURE("bg_texture.jpg"); + OLD_FOILS("sprite_old_foils.png"); private final String filename; @@ -245,6 +247,7 @@ public enum FSkinImage implements FImage { private final int x, y, w, h; private final SourceFile sourceFile; + private TextureRegion textureRegion; FSkinImage(int x0, int y0, int w0, int h0, SourceFile sourceFile0) { x = x0; @@ -254,44 +257,111 @@ public enum FSkinImage implements FImage { sourceFile = sourceFile0; } - public int getX() { - return x; - } - - public int getY() { - return y; - } - - public int getWidth(int fullWidth) { - if (w > 0) { - return w; + public void load(String preferredDir, String defaultDir, Map textures, Pixmap preferredIcons) { + String filename = sourceFile.getFilename(); + String preferredFile = preferredDir + filename; + Texture texture = textures.get(preferredFile); + if (texture == null) { + FileHandle file = Gdx.files.internal(preferredFile); + if (file.exists()) { + try { + texture = new Texture(file); + } + catch (final Exception e) { + System.err.println("Failed to load skin file: " + preferredFile); + e.printStackTrace(); + } + } } - return fullWidth + w; - } + if (texture != null) { + if (sourceFile != SourceFile.ICONS) { //just return region for preferred file if not icons file + textureRegion = new TextureRegion(texture, x, y, w, h); + return; + } - public int getHeight(int fullHeight) { - if (h > 0) { - return h; + int fullWidth = texture.getWidth(); + int fullHeight = texture.getHeight(); + + // Test if requested sub-image in inside bounds of preferred sprite. + // (Height and width of preferred sprite were set in loadFontAndImages.) + if (x + w <= fullWidth && y + h <= fullHeight) { + // Test if various points of requested sub-image are transparent. + // If any return true, image exists. + int x0 = 0, y0 = 0; + Color c; + + // Center + x0 = (x + w / 2); + y0 = (y + h / 2); + c = new Color(preferredIcons.getPixel(x0, y0)); + if (c.a != 0) { + textureRegion = new TextureRegion(texture, x, y, w, h); + return; + } + + x0 += 2; + y0 += 2; + c = new Color(preferredIcons.getPixel(x0, y0)); + if (c.a != 0) { + textureRegion = new TextureRegion(texture, x, y, w, h); + return; + } + + x0 -= 4; + c = new Color(preferredIcons.getPixel(x0, y0)); + if (c.a != 0) { + textureRegion = new TextureRegion(texture, x, y, w, h); + return; + } + + y0 -= 4; + c = new Color(preferredIcons.getPixel(x0, y0)); + if (c.a != 0) { + textureRegion = new TextureRegion(texture, x, y, w, h); + return; + } + + x0 += 4; + c = new Color(preferredIcons.getPixel(x0, y0)); + if (c.a != 0) { + textureRegion = new TextureRegion(texture, x, y, w, h); + return; + } + } } - return fullHeight + h; - } - public SourceFile getSourceFile() { - return sourceFile; + //use default file if can't use preferred file + String defaultFile = defaultDir + filename; + texture = textures.get(defaultFile); + if (texture == null) { + FileHandle file = Gdx.files.internal(defaultFile); + if (file.exists()) { + try { + texture = new Texture(file); + } + catch (final Exception e) { + System.err.println("Failed to load skin file: " + defaultFile); + e.printStackTrace(); + } + } + } + if (texture != null) { + textureRegion = new TextureRegion(texture, x, y, w, h); + } } @Override - public float getSourceWidth() { + public float getWidth() { return w; } @Override - public float getSourceHeight() { + public float getHeight() { return h; } @Override public void draw(Graphics g, float x, float y, float w, float h) { - g.drawImage(FSkin.getImages().get(this), x, y, w, h); + g.drawImage(this.textureRegion, x, y, w, h); } } \ No newline at end of file diff --git a/forge-m-base/src/forge/assets/FSkinTexture.java b/forge-m-base/src/forge/assets/FSkinTexture.java new file mode 100644 index 00000000000..c791f851fb8 --- /dev/null +++ b/forge-m-base/src/forge/assets/FSkinTexture.java @@ -0,0 +1,61 @@ +package forge.assets; + +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.files.FileHandle; +import com.badlogic.gdx.graphics.Texture; +import forge.Forge.Graphics; + +public enum FSkinTexture implements FImage { + BG_TEXTURE("bg_texture.jpg"), + BG_MATCH("bg_match.jpg"); + + private final String filename; + private Texture texture; + + FSkinTexture(String filename0) { + filename = filename0; + } + + public void load(String preferredDir, String defaultDir) { + String preferredFile = preferredDir + filename; + FileHandle file = Gdx.files.internal(preferredFile); + if (file.exists()) { + try { + texture = new Texture(file); + } + catch (final Exception e) { + System.err.println("Failed to load skin file: " + preferredFile); + e.printStackTrace(); + } + } + if (texture == null) { + //use default file if can't use preferred file + String defaultFile = defaultDir + filename; + file = Gdx.files.internal(defaultFile); + if (file.exists()) { + try { + texture = new Texture(file); + } + catch (final Exception e) { + System.err.println("Failed to load skin file: " + defaultFile); + e.printStackTrace(); + } + } + } + } + + @Override + public float getWidth() { + return texture.getWidth(); + } + + @Override + public float getHeight() { + return texture.getHeight(); + } + + @Override + public void draw(Graphics g, float x, float y, float w, float h) { + g.drawImage(texture, x, y, w, h); + } +} \ No newline at end of file diff --git a/forge-m-base/src/forge/screens/FScreen.java b/forge-m-base/src/forge/screens/FScreen.java index 55947004101..6a99dba3c6d 100644 --- a/forge-m-base/src/forge/screens/FScreen.java +++ b/forge-m-base/src/forge/screens/FScreen.java @@ -7,18 +7,22 @@ import forge.Forge.Graphics; import forge.assets.FSkinColor; import forge.assets.FSkinImage; import forge.assets.FSkinColor.Colors; +import forge.assets.FSkinTexture; import forge.toolbox.FContainer; import forge.toolbox.FLabel; import forge.utils.Utils; public abstract class FScreen extends FContainer { + public static final float BTN_WIDTH = Utils.AVG_FINGER_WIDTH; + public static final float BTN_HEIGHT = Utils.AVG_FINGER_HEIGHT; + private static final FSkinColor clrTheme = FSkinColor.get(Colors.CLR_THEME); private static final FSkinColor clr = clrTheme.stepColor(0); private static final FSkinColor a100 = clr.alphaColor(100f / 255f); private static final FSkinColor d40 = clr.stepColor(-40); private static final FSkinColor d80 = clr.stepColor(-80); - protected final FLabel btnBack, lblHeader, btnMenu; + private final FLabel btnBack, lblHeader, btnMenu; protected FScreen(boolean showBackButton, String headerCaption, boolean showMenuButton) { if (showBackButton) { @@ -75,16 +79,15 @@ public abstract class FScreen extends FContainer { float headerX = 0; float insets = 0; float headerWidth = width; - float buttonWidth = Utils.AVG_FINGER_WIDTH; - float headerHeight = Utils.AVG_FINGER_HEIGHT; + float headerHeight = BTN_HEIGHT; if (btnBack != null) { - btnBack.setBounds(insets, insets, buttonWidth, headerHeight); + btnBack.setBounds(insets, insets, BTN_WIDTH, BTN_HEIGHT); headerX = btnBack.getWidth(); headerWidth -= headerX; } if (btnMenu != null) { - btnMenu.setBounds(width - buttonWidth - insets, insets, buttonWidth, headerHeight); + btnMenu.setBounds(width - BTN_WIDTH - insets, insets, BTN_WIDTH, BTN_HEIGHT); headerWidth -= btnMenu.getWidth(); } if (lblHeader != null) { @@ -103,7 +106,7 @@ public abstract class FScreen extends FContainer { protected void drawBackground(Graphics g) { float w = getWidth(); float h = getHeight(); - g.drawImage(FSkinImage.BG_TEXTURE, 0, 0, w, h); + g.drawImage(FSkinTexture.BG_TEXTURE, 0, 0, w, h); g.fillRect(clrTheme, 0, 0, w, h); if (lblHeader != null) { //draw custom background behind header label diff --git a/forge-m-base/src/forge/screens/LaunchScreen.java b/forge-m-base/src/forge/screens/LaunchScreen.java index 3caa37e8fe6..3d59defe8df 100644 --- a/forge-m-base/src/forge/screens/LaunchScreen.java +++ b/forge-m-base/src/forge/screens/LaunchScreen.java @@ -24,8 +24,8 @@ public abstract class LaunchScreen extends FScreen { @Override protected final void doLayout(float startY, float width, float height) { - float imageWidth = FSkinImage.BTN_START_UP.getSourceWidth(); - float imageHeight = FSkinImage.BTN_START_UP.getSourceHeight(); + float imageWidth = FSkinImage.BTN_START_UP.getWidth(); + float imageHeight = FSkinImage.BTN_START_UP.getHeight(); float padding = imageHeight * 0.1f; btnStart.setBounds((width - imageWidth) / 2, height - imageHeight - padding, imageWidth, imageHeight); diff --git a/forge-m-base/src/forge/screens/constructed/ConstructedScreen.java b/forge-m-base/src/forge/screens/constructed/ConstructedScreen.java index 5f71a82af8a..1c06868fcb5 100644 --- a/forge-m-base/src/forge/screens/constructed/ConstructedScreen.java +++ b/forge-m-base/src/forge/screens/constructed/ConstructedScreen.java @@ -26,12 +26,14 @@ public class ConstructedScreen extends LaunchScreen { //TODO: Allow picking decks Deck humanDeck = Utils.generateRandomDeck(2); LobbyPlayerHuman humanLobbyPlayer = new LobbyPlayerHuman("Human"); + humanLobbyPlayer.setAvatarIndex(0); RegisteredPlayer humanRegisteredPlayer = new RegisteredPlayer(humanDeck); humanRegisteredPlayer.setPlayer(humanLobbyPlayer); launchParams.players.add(humanRegisteredPlayer); Deck aiDeck = Utils.generateRandomDeck(2); LobbyPlayerAi aiLobbyPlayer = new LobbyPlayerAi("AI Player"); + aiLobbyPlayer.setAvatarIndex(1); RegisteredPlayer aiRegisteredPlayer = new RegisteredPlayer(aiDeck); aiRegisteredPlayer.setPlayer(aiLobbyPlayer); launchParams.players.add(aiRegisteredPlayer); diff --git a/forge-m-base/src/forge/screens/match/MatchScreen.java b/forge-m-base/src/forge/screens/match/MatchScreen.java index b3a539b82fb..b9366a93d15 100644 --- a/forge-m-base/src/forge/screens/match/MatchScreen.java +++ b/forge-m-base/src/forge/screens/match/MatchScreen.java @@ -1,7 +1,6 @@ package forge.screens.match; import java.util.HashMap; -import java.util.List; import java.util.Map; import forge.screens.FScreen; @@ -9,9 +8,7 @@ import forge.screens.match.views.VLog; import forge.screens.match.views.VPlayerPanel; import forge.screens.match.views.VPrompt; import forge.screens.match.views.VStack; -import forge.utils.Utils; import forge.game.Match; -import forge.game.player.Player; import forge.game.player.RegisteredPlayer; public class MatchScreen extends FScreen { @@ -46,16 +43,12 @@ public class MatchScreen extends FScreen { @Override protected void doLayout(float startY, float width, float height) { - float logHeight = btnMenu.getHeight(); - float stackWidth = Utils.AVG_FINGER_WIDTH; - float stackHeight = stackWidth * Utils.CARD_ASPECT_RATIO; - float promptHeight = Utils.AVG_FINGER_HEIGHT; - float playerPanelHeight = (height - startY - promptHeight - logHeight) / 2f; + float playerPanelHeight = (height - startY - VPrompt.HEIGHT - VLog.HEIGHT) / 2f; - log.setBounds(0, startY, width - btnMenu.getWidth(), logHeight); - topPlayerPanel.setBounds(0, startY + logHeight, width, playerPanelHeight); - stack.setBounds(0, startY + logHeight + playerPanelHeight - stackHeight / 2, stackWidth, stackHeight); - bottomPlayerPanel.setBounds(0, height - promptHeight - playerPanelHeight, width, playerPanelHeight); - prompt.setBounds(0, height - promptHeight, width, promptHeight); + log.setBounds(0, startY, width - FScreen.BTN_WIDTH, VLog.HEIGHT); + topPlayerPanel.setBounds(0, startY + VLog.HEIGHT, width, playerPanelHeight); + stack.setBounds(0, startY + VLog.HEIGHT + playerPanelHeight - VStack.HEIGHT / 2, VStack.WIDTH, VStack.HEIGHT); + bottomPlayerPanel.setBounds(0, height - VPrompt.HEIGHT - playerPanelHeight, width, playerPanelHeight); + prompt.setBounds(0, height - VPrompt.HEIGHT, width, VPrompt.HEIGHT); } } diff --git a/forge-m-base/src/forge/screens/match/views/VAvatar.java b/forge-m-base/src/forge/screens/match/views/VAvatar.java index f9b5ae96ca4..89536b89635 100644 --- a/forge-m-base/src/forge/screens/match/views/VAvatar.java +++ b/forge-m-base/src/forge/screens/match/views/VAvatar.java @@ -1,5 +1,27 @@ package forge.screens.match.views; -public class VAvatar { +import com.badlogic.gdx.graphics.g2d.TextureRegion; +import forge.Forge.Graphics; +import forge.assets.FSkin; +import forge.toolbox.FDisplayObject; +import forge.utils.Utils; + +public class VAvatar extends FDisplayObject { + public static final float WIDTH = Utils.AVG_FINGER_WIDTH; + public static final float HEIGHT = Utils.AVG_FINGER_HEIGHT; + + private final TextureRegion image; + + public VAvatar(int avatarIndex) { + image = FSkin.getAvatars().get(avatarIndex); + setSize(WIDTH, HEIGHT); + } + + @Override + public void draw(Graphics g) { + float w = getWidth(); + float h = getHeight(); + g.drawImage(image, 0, 0, w, h); + } } diff --git a/forge-m-base/src/forge/screens/match/views/VField.java b/forge-m-base/src/forge/screens/match/views/VField.java index f8aa3ed51f1..1485cf5a757 100644 --- a/forge-m-base/src/forge/screens/match/views/VField.java +++ b/forge-m-base/src/forge/screens/match/views/VField.java @@ -1,13 +1,33 @@ package forge.screens.match.views; +import forge.Forge.Graphics; +import forge.assets.FSkinTexture; import forge.toolbox.FContainer; public class VField extends FContainer { + private boolean flipped; + + public VField() { + } + + public boolean isFlipped() { + return flipped; + } + public void setFlipped(boolean flipped0) { + flipped = flipped0; + } + @Override protected void doLayout(float width, float height) { // TODO Auto-generated method stub } + @Override + protected void drawBackground(Graphics g) { + float w = getWidth(); + float h = getHeight(); + g.drawImage(FSkinTexture.BG_MATCH, 0, 0, w, h); + } } diff --git a/forge-m-base/src/forge/screens/match/views/VLog.java b/forge-m-base/src/forge/screens/match/views/VLog.java index ac4aa7771f5..38da006c939 100644 --- a/forge-m-base/src/forge/screens/match/views/VLog.java +++ b/forge-m-base/src/forge/screens/match/views/VLog.java @@ -3,9 +3,11 @@ package forge.screens.match.views; import com.badlogic.gdx.graphics.Color; import forge.Forge.Graphics; +import forge.screens.FScreen; import forge.toolbox.FContainer; public class VLog extends FContainer { + public static final float HEIGHT = FScreen.BTN_HEIGHT; //TODO: Consider changing this @Override protected void doLayout(float width, float height) { diff --git a/forge-m-base/src/forge/screens/match/views/VPhases.java b/forge-m-base/src/forge/screens/match/views/VPhases.java index 3900cf7648a..066bc9d682b 100644 --- a/forge-m-base/src/forge/screens/match/views/VPhases.java +++ b/forge-m-base/src/forge/screens/match/views/VPhases.java @@ -1,5 +1,8 @@ package forge.screens.match.views; +import com.badlogic.gdx.graphics.Color; + +import forge.Forge.Graphics; import forge.toolbox.FContainer; public class VPhases extends FContainer { @@ -10,4 +13,10 @@ public class VPhases extends FContainer { } + @Override + protected void drawBackground(Graphics g) { + float w = getWidth(); + float h = getHeight(); + g.fillRect(Color.CYAN, 0, 0, w, h); + } } diff --git a/forge-m-base/src/forge/screens/match/views/VPlayerPanel.java b/forge-m-base/src/forge/screens/match/views/VPlayerPanel.java index e7cb53e20c2..52d8b724701 100644 --- a/forge-m-base/src/forge/screens/match/views/VPlayerPanel.java +++ b/forge-m-base/src/forge/screens/match/views/VPlayerPanel.java @@ -1,10 +1,8 @@ package forge.screens.match.views; -import com.badlogic.gdx.graphics.Color; - -import forge.Forge.Graphics; import forge.game.player.RegisteredPlayer; import forge.toolbox.FContainer; +import forge.toolbox.FDisplayObject; public class VPlayerPanel extends FContainer { private final RegisteredPlayer player; @@ -12,32 +10,33 @@ public class VPlayerPanel extends FContainer { private final VField field; private final VAvatar avatar; - private boolean flipped; - public VPlayerPanel(RegisteredPlayer player0) { player = player0; - phases = new VPhases(); - field = new VField(); - avatar = new VAvatar(); + phases = add(new VPhases()); + field = add(new VField()); + avatar = add(new VAvatar(player.getPlayer().getAvatarIndex())); } public boolean isFlipped() { - return flipped; + return field.isFlipped(); } public void setFlipped(boolean flipped0) { - flipped = flipped0; + field.setFlipped(flipped0); } @Override protected void doLayout(float width, float height) { - // TODO Auto-generated method stub - - } + //layout for bottom panel by default + float phasesTop = VStack.HEIGHT / 2; + float phasesWidth = VStack.WIDTH; + phases.setBounds(0, phasesTop, phasesWidth, height - VAvatar.HEIGHT - phasesTop); + field.setBounds(phasesWidth, 0, width - phasesWidth, height - VAvatar.HEIGHT); + avatar.setPosition(0, height - VAvatar.HEIGHT); - @Override - protected void drawBackground(Graphics g) { - float w = getWidth(); - float h = getHeight(); - g.fillRect(flipped ? Color.LIGHT_GRAY : Color.GRAY, 0, 0, w, h); + if (isFlipped()) { //flip all positions across x-axis if needed + for (FDisplayObject child : getChildren()) { + child.setTop(height - child.getBottom()); + } + } } } diff --git a/forge-m-base/src/forge/screens/match/views/VPrompt.java b/forge-m-base/src/forge/screens/match/views/VPrompt.java index 1eaf8c158ae..21ae8c5a6b2 100644 --- a/forge-m-base/src/forge/screens/match/views/VPrompt.java +++ b/forge-m-base/src/forge/screens/match/views/VPrompt.java @@ -4,8 +4,10 @@ import com.badlogic.gdx.graphics.Color; import forge.Forge.Graphics; import forge.toolbox.FContainer; +import forge.utils.Utils; public class VPrompt extends FContainer { + public static final float HEIGHT = Utils.AVG_FINGER_HEIGHT; @Override protected void doLayout(float width, float height) { diff --git a/forge-m-base/src/forge/screens/match/views/VStack.java b/forge-m-base/src/forge/screens/match/views/VStack.java index 393226a7954..b03b25c710d 100644 --- a/forge-m-base/src/forge/screens/match/views/VStack.java +++ b/forge-m-base/src/forge/screens/match/views/VStack.java @@ -4,8 +4,15 @@ import com.badlogic.gdx.graphics.Color; import forge.Forge.Graphics; import forge.toolbox.FContainer; +import forge.utils.Utils; public class VStack extends FContainer { + public static final float WIDTH = Utils.AVG_FINGER_WIDTH; + public static final float HEIGHT = WIDTH * Utils.CARD_ASPECT_RATIO; + + public VStack() { + setSize(WIDTH, HEIGHT); + } @Override protected void doLayout(float width, float height) { diff --git a/forge-m-base/src/forge/toolbox/FContainer.java b/forge-m-base/src/forge/toolbox/FContainer.java index 32461f89fa5..958b6c58e59 100644 --- a/forge-m-base/src/forge/toolbox/FContainer.java +++ b/forge-m-base/src/forge/toolbox/FContainer.java @@ -12,6 +12,10 @@ public abstract class FContainer extends FDisplayObject { return child; } + public Iterable getChildren() { + return children; + } + protected void drawBackground(Graphics g) { } diff --git a/forge-m-base/src/forge/toolbox/FDisplayObject.java b/forge-m-base/src/forge/toolbox/FDisplayObject.java index b9c66cc758e..edbac63050d 100644 --- a/forge-m-base/src/forge/toolbox/FDisplayObject.java +++ b/forge-m-base/src/forge/toolbox/FDisplayObject.java @@ -24,21 +24,33 @@ public abstract class FDisplayObject { public float getLeft() { return bounds.x; } + public void setLeft(float x) { + bounds.x = x; + } public float getRight() { return bounds.x + bounds.width; } public float getTop() { return bounds.y; } + public void setTop(float y) { + bounds.y = y; + } public float getBottom() { return bounds.y + bounds.height; } public float getWidth() { return bounds.width; } + public void setWidth(float width) { + bounds.width = width; + } public float getHeight() { return bounds.height; } + public void setHeight(float height) { + bounds.height = height; + } public boolean contains(float x, float y) { return visible && bounds.contains(x, y); } diff --git a/forge-m-base/src/forge/toolbox/FLabel.java b/forge-m-base/src/forge/toolbox/FLabel.java index 616097fda89..543c76a5235 100644 --- a/forge-m-base/src/forge/toolbox/FLabel.java +++ b/forge-m-base/src/forge/toolbox/FLabel.java @@ -186,8 +186,8 @@ public class FLabel extends FDisplayObject { } if (icon != null) { - float iconWidth = icon.getSourceWidth(); - float iconHeight = icon.getSourceHeight(); + float iconWidth = icon.getWidth(); + float iconHeight = icon.getHeight(); float aspectRatio = iconWidth / iconHeight; if (iconInBackground || iconScaleAuto) {