mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 02:38:02 +00:00
Refactor how skin images are loaded
Further enhance match layout
This commit is contained in:
1
.gitattributes
vendored
1
.gitattributes
vendored
@@ -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/FSkinColor.java -text
|
||||||
forge-m-base/src/forge/assets/FSkinFont.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/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/LobbyPlayerHuman.java -text
|
||||||
forge-m-base/src/forge/player/PlayerControllerHuman.java -text
|
forge-m-base/src/forge/player/PlayerControllerHuman.java -text
|
||||||
forge-m-base/src/forge/screens/FScreen.java -text
|
forge-m-base/src/forge/screens/FScreen.java -text
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import com.badlogic.gdx.Gdx;
|
|||||||
import com.badlogic.gdx.graphics.Color;
|
import com.badlogic.gdx.graphics.Color;
|
||||||
import com.badlogic.gdx.graphics.GL10;
|
import com.badlogic.gdx.graphics.GL10;
|
||||||
import com.badlogic.gdx.graphics.GL20;
|
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.BitmapFont;
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
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) {
|
public void drawImage(FImage image, float x, float y, float w, float h) {
|
||||||
image.draw(this, x, y, w, 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) {
|
public void drawImage(TextureRegion image, float x, float y, float w, float h) {
|
||||||
batch.draw(image, adjustX(x), adjustY(y, h), w, h);
|
batch.draw(image, adjustX(x), adjustY(y, h), w, h);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package forge.assets;
|
|||||||
import forge.Forge.Graphics;
|
import forge.Forge.Graphics;
|
||||||
|
|
||||||
public interface FImage {
|
public interface FImage {
|
||||||
float getSourceWidth();
|
float getWidth();
|
||||||
float getSourceHeight();
|
float getHeight();
|
||||||
void draw(Graphics g, float x, float y, float w, float h);
|
void draw(Graphics g, float x, float y, float w, float h);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ public class FSkin {
|
|||||||
FILE_AVATAR_SPRITE = "sprite_avatars.png",
|
FILE_AVATAR_SPRITE = "sprite_avatars.png",
|
||||||
DEFAULT_DIR = FILE_SKINS_DIR + "default/";
|
DEFAULT_DIR = FILE_SKINS_DIR + "default/";
|
||||||
|
|
||||||
private static final Map<FSkinImage, TextureRegion> images = new HashMap<FSkinImage, TextureRegion>();
|
|
||||||
private static final Map<Integer, TextureRegion> avatars = new HashMap<Integer, TextureRegion>();
|
private static final Map<Integer, TextureRegion> avatars = new HashMap<Integer, TextureRegion>();
|
||||||
|
|
||||||
private static ArrayList<String> allSkins;
|
private static ArrayList<String> allSkins;
|
||||||
@@ -65,14 +64,12 @@ public class FSkin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
images.clear();
|
|
||||||
|
|
||||||
// Non-default (preferred) skin name and dir.
|
// Non-default (preferred) skin name and dir.
|
||||||
preferredName = skinName.toLowerCase().replace(' ', '_');
|
preferredName = skinName.toLowerCase().replace(' ', '_');
|
||||||
preferredDir = FILE_SKINS_DIR + preferredName + "/";
|
preferredDir = FILE_SKINS_DIR + preferredName + "/";
|
||||||
|
|
||||||
if (splashScreen != null) {
|
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 (!f.exists()) {
|
||||||
if (!skinName.equals("default")) {
|
if (!skinName.equals("default")) {
|
||||||
FSkin.loadLight("default", splashScreen);
|
FSkin.loadLight("default", splashScreen);
|
||||||
@@ -161,12 +158,12 @@ public class FSkin {
|
|||||||
c.setColor(new Color(preferredIcons.getPixel(c.getX(), c.getY())));
|
c.setColor(new Color(preferredIcons.getPixel(c.getX(), c.getY())));
|
||||||
}
|
}
|
||||||
|
|
||||||
//add images
|
//load images
|
||||||
for (FSkinImage image : FSkinImage.values()) {
|
for (FSkinImage image : FSkinImage.values()) {
|
||||||
TextureRegion textureRegion = loadTextureRegion(image, textures, preferredIcons);
|
image.load(preferredDir, DEFAULT_DIR, textures, preferredIcons);
|
||||||
if (textureRegion != null) {
|
|
||||||
images.put(image, textureRegion);
|
|
||||||
}
|
}
|
||||||
|
for (FSkinTexture image : FSkinTexture.values()) {
|
||||||
|
image.load(preferredDir, DEFAULT_DIR);
|
||||||
}
|
}
|
||||||
|
|
||||||
//assemble avatar textures
|
//assemble avatar textures
|
||||||
@@ -269,91 +266,6 @@ public class FSkin {
|
|||||||
addEncodingSymbol("T", GameplayImages.IMG_TAP);*/
|
addEncodingSymbol("T", GameplayImages.IMG_TAP);*/
|
||||||
}
|
}
|
||||||
|
|
||||||
private static TextureRegion loadTextureRegion(FSkinImage image, Map<String, Texture> 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.
|
* Gets the name.
|
||||||
*
|
*
|
||||||
@@ -406,10 +318,6 @@ public class FSkin {
|
|||||||
return allSkins;
|
return allSkins;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Map<FSkinImage, TextureRegion> getImages() {
|
|
||||||
return images;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Map<Integer, TextureRegion> getAvatars() {
|
public static Map<Integer, TextureRegion> getAvatars() {
|
||||||
return avatars;
|
return avatars;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,20 @@
|
|||||||
package forge.assets;
|
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;
|
import forge.Forge.Graphics;
|
||||||
|
|
||||||
/** Properties of various components that make up the skin.
|
/** Properties of various components that make up the skin.
|
||||||
* This interface allows all enums to be under the same roof.
|
* This interface allows all enums to be under the same roof.
|
||||||
* It also enforces a getter for coordinate locations in sprites. */
|
* It also enforces a getter for coordinate locations in sprites. */
|
||||||
public enum FSkinImage implements FImage {
|
public enum FSkinImage implements FImage {
|
||||||
//Backgrounds
|
|
||||||
BG_TEXTURE (0, 0, 0, 0, SourceFile.TEXTURE),
|
|
||||||
BG_MATCH (0, 0, 0, 0, SourceFile.MATCH),
|
|
||||||
|
|
||||||
//Zones
|
//Zones
|
||||||
HAND (280, 40, 40, 40, SourceFile.ICONS),
|
HAND (280, 40, 40, 40, SourceFile.ICONS),
|
||||||
LIBRARY (280, 0, 40, 40, SourceFile.ICONS),
|
LIBRARY (280, 0, 40, 40, SourceFile.ICONS),
|
||||||
@@ -227,10 +232,7 @@ public enum FSkinImage implements FImage {
|
|||||||
public enum SourceFile {
|
public enum SourceFile {
|
||||||
ICONS("sprite_icons.png"),
|
ICONS("sprite_icons.png"),
|
||||||
FOILS("sprite_foils.png"),
|
FOILS("sprite_foils.png"),
|
||||||
OLD_FOILS("sprite_old_foils.png"),
|
OLD_FOILS("sprite_old_foils.png");
|
||||||
SPLASH("bg_splash.png"),
|
|
||||||
MATCH("bg_match.jpg"),
|
|
||||||
TEXTURE("bg_texture.jpg");
|
|
||||||
|
|
||||||
private final String filename;
|
private final String filename;
|
||||||
|
|
||||||
@@ -245,6 +247,7 @@ public enum FSkinImage implements FImage {
|
|||||||
|
|
||||||
private final int x, y, w, h;
|
private final int x, y, w, h;
|
||||||
private final SourceFile sourceFile;
|
private final SourceFile sourceFile;
|
||||||
|
private TextureRegion textureRegion;
|
||||||
|
|
||||||
FSkinImage(int x0, int y0, int w0, int h0, SourceFile sourceFile0) {
|
FSkinImage(int x0, int y0, int w0, int h0, SourceFile sourceFile0) {
|
||||||
x = x0;
|
x = x0;
|
||||||
@@ -254,44 +257,111 @@ public enum FSkinImage implements FImage {
|
|||||||
sourceFile = sourceFile0;
|
sourceFile = sourceFile0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getX() {
|
public void load(String preferredDir, String defaultDir, Map<String, Texture> textures, Pixmap preferredIcons) {
|
||||||
return x;
|
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) {
|
||||||
|
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 getY() {
|
int fullWidth = texture.getWidth();
|
||||||
return y;
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getWidth(int fullWidth) {
|
x0 += 2;
|
||||||
if (w > 0) {
|
y0 += 2;
|
||||||
return w;
|
c = new Color(preferredIcons.getPixel(x0, y0));
|
||||||
}
|
if (c.a != 0) {
|
||||||
return fullWidth + w;
|
textureRegion = new TextureRegion(texture, x, y, w, h);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getHeight(int fullHeight) {
|
x0 -= 4;
|
||||||
if (h > 0) {
|
c = new Color(preferredIcons.getPixel(x0, y0));
|
||||||
return h;
|
if (c.a != 0) {
|
||||||
}
|
textureRegion = new TextureRegion(texture, x, y, w, h);
|
||||||
return fullHeight + h;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SourceFile getSourceFile() {
|
y0 -= 4;
|
||||||
return sourceFile;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//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
|
@Override
|
||||||
public float getSourceWidth() {
|
public float getWidth() {
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float getSourceHeight() {
|
public float getHeight() {
|
||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(Graphics g, float x, float y, float w, float h) {
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
61
forge-m-base/src/forge/assets/FSkinTexture.java
Normal file
61
forge-m-base/src/forge/assets/FSkinTexture.java
Normal file
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,18 +7,22 @@ import forge.Forge.Graphics;
|
|||||||
import forge.assets.FSkinColor;
|
import forge.assets.FSkinColor;
|
||||||
import forge.assets.FSkinImage;
|
import forge.assets.FSkinImage;
|
||||||
import forge.assets.FSkinColor.Colors;
|
import forge.assets.FSkinColor.Colors;
|
||||||
|
import forge.assets.FSkinTexture;
|
||||||
import forge.toolbox.FContainer;
|
import forge.toolbox.FContainer;
|
||||||
import forge.toolbox.FLabel;
|
import forge.toolbox.FLabel;
|
||||||
import forge.utils.Utils;
|
import forge.utils.Utils;
|
||||||
|
|
||||||
public abstract class FScreen extends FContainer {
|
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 clrTheme = FSkinColor.get(Colors.CLR_THEME);
|
||||||
private static final FSkinColor clr = clrTheme.stepColor(0);
|
private static final FSkinColor clr = clrTheme.stepColor(0);
|
||||||
private static final FSkinColor a100 = clr.alphaColor(100f / 255f);
|
private static final FSkinColor a100 = clr.alphaColor(100f / 255f);
|
||||||
private static final FSkinColor d40 = clr.stepColor(-40);
|
private static final FSkinColor d40 = clr.stepColor(-40);
|
||||||
private static final FSkinColor d80 = clr.stepColor(-80);
|
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) {
|
protected FScreen(boolean showBackButton, String headerCaption, boolean showMenuButton) {
|
||||||
if (showBackButton) {
|
if (showBackButton) {
|
||||||
@@ -75,16 +79,15 @@ public abstract class FScreen extends FContainer {
|
|||||||
float headerX = 0;
|
float headerX = 0;
|
||||||
float insets = 0;
|
float insets = 0;
|
||||||
float headerWidth = width;
|
float headerWidth = width;
|
||||||
float buttonWidth = Utils.AVG_FINGER_WIDTH;
|
float headerHeight = BTN_HEIGHT;
|
||||||
float headerHeight = Utils.AVG_FINGER_HEIGHT;
|
|
||||||
|
|
||||||
if (btnBack != null) {
|
if (btnBack != null) {
|
||||||
btnBack.setBounds(insets, insets, buttonWidth, headerHeight);
|
btnBack.setBounds(insets, insets, BTN_WIDTH, BTN_HEIGHT);
|
||||||
headerX = btnBack.getWidth();
|
headerX = btnBack.getWidth();
|
||||||
headerWidth -= headerX;
|
headerWidth -= headerX;
|
||||||
}
|
}
|
||||||
if (btnMenu != null) {
|
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();
|
headerWidth -= btnMenu.getWidth();
|
||||||
}
|
}
|
||||||
if (lblHeader != null) {
|
if (lblHeader != null) {
|
||||||
@@ -103,7 +106,7 @@ public abstract class FScreen extends FContainer {
|
|||||||
protected void drawBackground(Graphics g) {
|
protected void drawBackground(Graphics g) {
|
||||||
float w = getWidth();
|
float w = getWidth();
|
||||||
float h = getHeight();
|
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);
|
g.fillRect(clrTheme, 0, 0, w, h);
|
||||||
|
|
||||||
if (lblHeader != null) { //draw custom background behind header label
|
if (lblHeader != null) { //draw custom background behind header label
|
||||||
|
|||||||
@@ -24,8 +24,8 @@ public abstract class LaunchScreen extends FScreen {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected final void doLayout(float startY, float width, float height) {
|
protected final void doLayout(float startY, float width, float height) {
|
||||||
float imageWidth = FSkinImage.BTN_START_UP.getSourceWidth();
|
float imageWidth = FSkinImage.BTN_START_UP.getWidth();
|
||||||
float imageHeight = FSkinImage.BTN_START_UP.getSourceHeight();
|
float imageHeight = FSkinImage.BTN_START_UP.getHeight();
|
||||||
float padding = imageHeight * 0.1f;
|
float padding = imageHeight * 0.1f;
|
||||||
|
|
||||||
btnStart.setBounds((width - imageWidth) / 2, height - imageHeight - padding, imageWidth, imageHeight);
|
btnStart.setBounds((width - imageWidth) / 2, height - imageHeight - padding, imageWidth, imageHeight);
|
||||||
|
|||||||
@@ -26,12 +26,14 @@ public class ConstructedScreen extends LaunchScreen {
|
|||||||
//TODO: Allow picking decks
|
//TODO: Allow picking decks
|
||||||
Deck humanDeck = Utils.generateRandomDeck(2);
|
Deck humanDeck = Utils.generateRandomDeck(2);
|
||||||
LobbyPlayerHuman humanLobbyPlayer = new LobbyPlayerHuman("Human");
|
LobbyPlayerHuman humanLobbyPlayer = new LobbyPlayerHuman("Human");
|
||||||
|
humanLobbyPlayer.setAvatarIndex(0);
|
||||||
RegisteredPlayer humanRegisteredPlayer = new RegisteredPlayer(humanDeck);
|
RegisteredPlayer humanRegisteredPlayer = new RegisteredPlayer(humanDeck);
|
||||||
humanRegisteredPlayer.setPlayer(humanLobbyPlayer);
|
humanRegisteredPlayer.setPlayer(humanLobbyPlayer);
|
||||||
launchParams.players.add(humanRegisteredPlayer);
|
launchParams.players.add(humanRegisteredPlayer);
|
||||||
|
|
||||||
Deck aiDeck = Utils.generateRandomDeck(2);
|
Deck aiDeck = Utils.generateRandomDeck(2);
|
||||||
LobbyPlayerAi aiLobbyPlayer = new LobbyPlayerAi("AI Player");
|
LobbyPlayerAi aiLobbyPlayer = new LobbyPlayerAi("AI Player");
|
||||||
|
aiLobbyPlayer.setAvatarIndex(1);
|
||||||
RegisteredPlayer aiRegisteredPlayer = new RegisteredPlayer(aiDeck);
|
RegisteredPlayer aiRegisteredPlayer = new RegisteredPlayer(aiDeck);
|
||||||
aiRegisteredPlayer.setPlayer(aiLobbyPlayer);
|
aiRegisteredPlayer.setPlayer(aiLobbyPlayer);
|
||||||
launchParams.players.add(aiRegisteredPlayer);
|
launchParams.players.add(aiRegisteredPlayer);
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package forge.screens.match;
|
package forge.screens.match;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import forge.screens.FScreen;
|
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.VPlayerPanel;
|
||||||
import forge.screens.match.views.VPrompt;
|
import forge.screens.match.views.VPrompt;
|
||||||
import forge.screens.match.views.VStack;
|
import forge.screens.match.views.VStack;
|
||||||
import forge.utils.Utils;
|
|
||||||
import forge.game.Match;
|
import forge.game.Match;
|
||||||
import forge.game.player.Player;
|
|
||||||
import forge.game.player.RegisteredPlayer;
|
import forge.game.player.RegisteredPlayer;
|
||||||
|
|
||||||
public class MatchScreen extends FScreen {
|
public class MatchScreen extends FScreen {
|
||||||
@@ -46,16 +43,12 @@ public class MatchScreen extends FScreen {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doLayout(float startY, float width, float height) {
|
protected void doLayout(float startY, float width, float height) {
|
||||||
float logHeight = btnMenu.getHeight();
|
float playerPanelHeight = (height - startY - VPrompt.HEIGHT - VLog.HEIGHT) / 2f;
|
||||||
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;
|
|
||||||
|
|
||||||
log.setBounds(0, startY, width - btnMenu.getWidth(), logHeight);
|
log.setBounds(0, startY, width - FScreen.BTN_WIDTH, VLog.HEIGHT);
|
||||||
topPlayerPanel.setBounds(0, startY + logHeight, width, playerPanelHeight);
|
topPlayerPanel.setBounds(0, startY + VLog.HEIGHT, width, playerPanelHeight);
|
||||||
stack.setBounds(0, startY + logHeight + playerPanelHeight - stackHeight / 2, stackWidth, stackHeight);
|
stack.setBounds(0, startY + VLog.HEIGHT + playerPanelHeight - VStack.HEIGHT / 2, VStack.WIDTH, VStack.HEIGHT);
|
||||||
bottomPlayerPanel.setBounds(0, height - promptHeight - playerPanelHeight, width, playerPanelHeight);
|
bottomPlayerPanel.setBounds(0, height - VPrompt.HEIGHT - playerPanelHeight, width, playerPanelHeight);
|
||||||
prompt.setBounds(0, height - promptHeight, width, promptHeight);
|
prompt.setBounds(0, height - VPrompt.HEIGHT, width, VPrompt.HEIGHT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,27 @@
|
|||||||
package forge.screens.match.views;
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,33 @@
|
|||||||
package forge.screens.match.views;
|
package forge.screens.match.views;
|
||||||
|
|
||||||
|
import forge.Forge.Graphics;
|
||||||
|
import forge.assets.FSkinTexture;
|
||||||
import forge.toolbox.FContainer;
|
import forge.toolbox.FContainer;
|
||||||
|
|
||||||
public class VField extends FContainer {
|
public class VField extends FContainer {
|
||||||
|
|
||||||
|
private boolean flipped;
|
||||||
|
|
||||||
|
public VField() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isFlipped() {
|
||||||
|
return flipped;
|
||||||
|
}
|
||||||
|
public void setFlipped(boolean flipped0) {
|
||||||
|
flipped = flipped0;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doLayout(float width, float height) {
|
protected void doLayout(float width, float height) {
|
||||||
// TODO Auto-generated method stub
|
// 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,9 +3,11 @@ package forge.screens.match.views;
|
|||||||
import com.badlogic.gdx.graphics.Color;
|
import com.badlogic.gdx.graphics.Color;
|
||||||
|
|
||||||
import forge.Forge.Graphics;
|
import forge.Forge.Graphics;
|
||||||
|
import forge.screens.FScreen;
|
||||||
import forge.toolbox.FContainer;
|
import forge.toolbox.FContainer;
|
||||||
|
|
||||||
public class VLog extends FContainer {
|
public class VLog extends FContainer {
|
||||||
|
public static final float HEIGHT = FScreen.BTN_HEIGHT; //TODO: Consider changing this
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doLayout(float width, float height) {
|
protected void doLayout(float width, float height) {
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
package forge.screens.match.views;
|
package forge.screens.match.views;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.graphics.Color;
|
||||||
|
|
||||||
|
import forge.Forge.Graphics;
|
||||||
import forge.toolbox.FContainer;
|
import forge.toolbox.FContainer;
|
||||||
|
|
||||||
public class VPhases extends 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
package forge.screens.match.views;
|
package forge.screens.match.views;
|
||||||
|
|
||||||
import com.badlogic.gdx.graphics.Color;
|
|
||||||
|
|
||||||
import forge.Forge.Graphics;
|
|
||||||
import forge.game.player.RegisteredPlayer;
|
import forge.game.player.RegisteredPlayer;
|
||||||
import forge.toolbox.FContainer;
|
import forge.toolbox.FContainer;
|
||||||
|
import forge.toolbox.FDisplayObject;
|
||||||
|
|
||||||
public class VPlayerPanel extends FContainer {
|
public class VPlayerPanel extends FContainer {
|
||||||
private final RegisteredPlayer player;
|
private final RegisteredPlayer player;
|
||||||
@@ -12,32 +10,33 @@ public class VPlayerPanel extends FContainer {
|
|||||||
private final VField field;
|
private final VField field;
|
||||||
private final VAvatar avatar;
|
private final VAvatar avatar;
|
||||||
|
|
||||||
private boolean flipped;
|
|
||||||
|
|
||||||
public VPlayerPanel(RegisteredPlayer player0) {
|
public VPlayerPanel(RegisteredPlayer player0) {
|
||||||
player = player0;
|
player = player0;
|
||||||
phases = new VPhases();
|
phases = add(new VPhases());
|
||||||
field = new VField();
|
field = add(new VField());
|
||||||
avatar = new VAvatar();
|
avatar = add(new VAvatar(player.getPlayer().getAvatarIndex()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isFlipped() {
|
public boolean isFlipped() {
|
||||||
return flipped;
|
return field.isFlipped();
|
||||||
}
|
}
|
||||||
public void setFlipped(boolean flipped0) {
|
public void setFlipped(boolean flipped0) {
|
||||||
flipped = flipped0;
|
field.setFlipped(flipped0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doLayout(float width, float height) {
|
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);
|
||||||
|
|
||||||
}
|
if (isFlipped()) { //flip all positions across x-axis if needed
|
||||||
|
for (FDisplayObject child : getChildren()) {
|
||||||
@Override
|
child.setTop(height - child.getBottom());
|
||||||
protected void drawBackground(Graphics g) {
|
}
|
||||||
float w = getWidth();
|
}
|
||||||
float h = getHeight();
|
|
||||||
g.fillRect(flipped ? Color.LIGHT_GRAY : Color.GRAY, 0, 0, w, h);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,8 +4,10 @@ import com.badlogic.gdx.graphics.Color;
|
|||||||
|
|
||||||
import forge.Forge.Graphics;
|
import forge.Forge.Graphics;
|
||||||
import forge.toolbox.FContainer;
|
import forge.toolbox.FContainer;
|
||||||
|
import forge.utils.Utils;
|
||||||
|
|
||||||
public class VPrompt extends FContainer {
|
public class VPrompt extends FContainer {
|
||||||
|
public static final float HEIGHT = Utils.AVG_FINGER_HEIGHT;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doLayout(float width, float height) {
|
protected void doLayout(float width, float height) {
|
||||||
|
|||||||
@@ -4,8 +4,15 @@ import com.badlogic.gdx.graphics.Color;
|
|||||||
|
|
||||||
import forge.Forge.Graphics;
|
import forge.Forge.Graphics;
|
||||||
import forge.toolbox.FContainer;
|
import forge.toolbox.FContainer;
|
||||||
|
import forge.utils.Utils;
|
||||||
|
|
||||||
public class VStack extends FContainer {
|
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
|
@Override
|
||||||
protected void doLayout(float width, float height) {
|
protected void doLayout(float width, float height) {
|
||||||
|
|||||||
@@ -12,6 +12,10 @@ public abstract class FContainer extends FDisplayObject {
|
|||||||
return child;
|
return child;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Iterable<FDisplayObject> getChildren() {
|
||||||
|
return children;
|
||||||
|
}
|
||||||
|
|
||||||
protected void drawBackground(Graphics g) {
|
protected void drawBackground(Graphics g) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,21 +24,33 @@ public abstract class FDisplayObject {
|
|||||||
public float getLeft() {
|
public float getLeft() {
|
||||||
return bounds.x;
|
return bounds.x;
|
||||||
}
|
}
|
||||||
|
public void setLeft(float x) {
|
||||||
|
bounds.x = x;
|
||||||
|
}
|
||||||
public float getRight() {
|
public float getRight() {
|
||||||
return bounds.x + bounds.width;
|
return bounds.x + bounds.width;
|
||||||
}
|
}
|
||||||
public float getTop() {
|
public float getTop() {
|
||||||
return bounds.y;
|
return bounds.y;
|
||||||
}
|
}
|
||||||
|
public void setTop(float y) {
|
||||||
|
bounds.y = y;
|
||||||
|
}
|
||||||
public float getBottom() {
|
public float getBottom() {
|
||||||
return bounds.y + bounds.height;
|
return bounds.y + bounds.height;
|
||||||
}
|
}
|
||||||
public float getWidth() {
|
public float getWidth() {
|
||||||
return bounds.width;
|
return bounds.width;
|
||||||
}
|
}
|
||||||
|
public void setWidth(float width) {
|
||||||
|
bounds.width = width;
|
||||||
|
}
|
||||||
public float getHeight() {
|
public float getHeight() {
|
||||||
return bounds.height;
|
return bounds.height;
|
||||||
}
|
}
|
||||||
|
public void setHeight(float height) {
|
||||||
|
bounds.height = height;
|
||||||
|
}
|
||||||
public boolean contains(float x, float y) {
|
public boolean contains(float x, float y) {
|
||||||
return visible && bounds.contains(x, y);
|
return visible && bounds.contains(x, y);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -186,8 +186,8 @@ public class FLabel extends FDisplayObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (icon != null) {
|
if (icon != null) {
|
||||||
float iconWidth = icon.getSourceWidth();
|
float iconWidth = icon.getWidth();
|
||||||
float iconHeight = icon.getSourceHeight();
|
float iconHeight = icon.getHeight();
|
||||||
float aspectRatio = iconWidth / iconHeight;
|
float aspectRatio = iconWidth / iconHeight;
|
||||||
|
|
||||||
if (iconInBackground || iconScaleAuto) {
|
if (iconInBackground || iconScaleAuto) {
|
||||||
|
|||||||
Reference in New Issue
Block a user