diff --git a/.gitattributes b/.gitattributes index f3fd4fc0669..3cb281b68d0 100644 --- a/.gitattributes +++ b/.gitattributes @@ -15981,7 +15981,11 @@ forge-m-base/.settings/org.eclipse.jdt.core.prefs -text forge-m-base/libs/gdx-sources.jar -text forge-m-base/libs/gdx.jar -text forge-m-base/src/forge/ForgeGame.java -text +forge-m-base/src/forge/ForgeScreen.java -text +forge-m-base/src/forge/gui/home/HomeScreen.java -text +forge-m-base/src/forge/gui/toolbox/FButton.java -text forge-m-base/src/forge/gui/toolbox/FSkin.java -text +forge-m-base/src/forge/gui/toolbox/LayoutHelper.java -text forge-m-desktop/.classpath -text forge-m-desktop/.project -text forge-m-desktop/.settings/org.eclipse.jdt.core.prefs -text diff --git a/forge-m-base/src/forge/ForgeGame.java b/forge-m-base/src/forge/ForgeGame.java index 8669cc96280..a12ebec2096 100644 --- a/forge-m-base/src/forge/ForgeGame.java +++ b/forge-m-base/src/forge/ForgeGame.java @@ -1,22 +1,55 @@ package forge; -import com.badlogic.gdx.ApplicationListener; +import java.util.Stack; +import com.badlogic.gdx.ApplicationListener; +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.graphics.GL10; + +import forge.gui.home.HomeScreen; import forge.gui.toolbox.FSkin; public class ForgeGame implements ApplicationListener { + private static final Stack screens = new Stack(); + private static ForgeScreen currentScreen; + @Override public void create () { - FSkin.loadLight("default", true); + Gdx.graphics.setContinuousRendering(false); //save power consumption by disabling continuous rendering + + FSkin.loadLight("journeyman", true); FSkin.loadFull(true); + pushScreen(new HomeScreen()); + } + + public static void popScreen() { + if (screens.size() < 2) { return; } //don't allow popping final screen + screens.pop().dispose(); + setCurrentScreen(screens.lastElement()); + } + + public static void pushScreen(ForgeScreen screen0) { + if (currentScreen == screen0) { return; } + screens.push(screen0); + setCurrentScreen(screen0); + } + + private static void setCurrentScreen(ForgeScreen screen0) { + currentScreen = screen0; + Gdx.input.setInputProcessor(currentScreen); + Gdx.graphics.requestRendering(); } @Override public void render () { + Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); + currentScreen.act(Gdx.graphics.getDeltaTime()); + currentScreen.draw(); } @Override - public void resize (int width, int height) { + public void resize(int width, int height) { + currentScreen.setViewport(width, height); } @Override @@ -29,5 +62,6 @@ public class ForgeGame implements ApplicationListener { @Override public void dispose () { + currentScreen.dispose(); } } diff --git a/forge-m-base/src/forge/ForgeScreen.java b/forge-m-base/src/forge/ForgeScreen.java new file mode 100644 index 00000000000..d0f57c9cdac --- /dev/null +++ b/forge-m-base/src/forge/ForgeScreen.java @@ -0,0 +1,31 @@ +package forge; + +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.graphics.GL10; +import com.badlogic.gdx.scenes.scene2d.Stage; + +import forge.gui.toolbox.FSkin; +import forge.gui.toolbox.FSkin.SkinImage; + +public abstract class ForgeScreen extends Stage { + private static SkinImage background = FSkin.getImage(FSkin.Backgrounds.BG_TEXTURE); + + @Override + public void setViewport(float width, float height) { + super.setViewport(width, height); + doLayout(width, height); + } + + protected abstract void doLayout(float width, float height); + + @Override + public void draw() { + //draw background image + Gdx.gl.glClearColor(0, 1, 0, 0.5f); + Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); + getSpriteBatch().begin(); + FSkin.drawImage(getSpriteBatch(), background, 0, 0, this.getWidth(), this.getHeight()); + getSpriteBatch().end(); + super.draw(); + } +} diff --git a/forge-m-base/src/forge/gui/home/HomeScreen.java b/forge-m-base/src/forge/gui/home/HomeScreen.java new file mode 100644 index 00000000000..961dea758c8 --- /dev/null +++ b/forge-m-base/src/forge/gui/home/HomeScreen.java @@ -0,0 +1,47 @@ +package forge.gui.home; + +import com.badlogic.gdx.scenes.scene2d.Actor; +import com.badlogic.gdx.scenes.scene2d.ui.Table; + +import forge.ForgeScreen; +import forge.gui.toolbox.FButton; +import forge.gui.toolbox.LayoutHelper; + +public class HomeScreen extends ForgeScreen { + private final FButton btnConstructed = new FButton("Constructed"); + private final FButton btnDraft = new FButton("Draft"); + private final FButton btnSealed = new FButton("Sealed"); + private final FButton btnQuest = new FButton("Quest"); + private final FButton btnGuantlet = new FButton("Guantlet"); + private final FButton btnSettings = new FButton("Settings"); + + public HomeScreen() { + final Table table = new Table(); + table.setFillParent(true); + + addButton(table, btnConstructed); + addButton(table, btnDraft); + addButton(table, btnSealed); + addButton(table, btnQuest); + addButton(table, btnGuantlet); + addButton(table, btnSettings); + + this.addActor(table); + } + + private void addButton(Table table, final FButton button) { + button.setWidth(60); + button.setHeight(60); + table.add(button).expandX().center(); + table.row(); + } + + @Override + protected void doLayout(float width, float height) { + /*LayoutHelper helper = new LayoutHelper(width, height); + float buttonHeight = height / this.getActors().size - helper.getGapY(); + for (Actor actor : this.getActors()) { + helper.fillLine(actor, buttonHeight); + }*/ + } +} diff --git a/forge-m-base/src/forge/gui/toolbox/FButton.java b/forge-m-base/src/forge/gui/toolbox/FButton.java new file mode 100644 index 00000000000..669e7c9efe3 --- /dev/null +++ b/forge-m-base/src/forge/gui/toolbox/FButton.java @@ -0,0 +1,111 @@ +package forge.gui.toolbox; + +import java.awt.AlphaComposite; + +import com.badlogic.gdx.graphics.Color; +import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import com.badlogic.gdx.scenes.scene2d.ui.Widget; + +import forge.gui.toolbox.FSkin.SkinImage; + +public class FButton extends Widget { + private SkinImage imgL, imgM, imgR; + private boolean allImagesPresent = false; + private String caption; + private boolean enabled = true; + private boolean toggled = false; + private final AlphaComposite disabledComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.25f); + + /** + * Instantiates a new FButton. + */ + public FButton() { + this(""); + } + + public FButton(final String caption0) { + caption = caption0; + /*setOpaque(false); + setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); + setBackground(Color.red); + setFocusPainted(false); + setBorder(BorderFactory.createEmptyBorder()); + setContentAreaFilled(false); + setMargin(new Insets(0, 25, 0, 25)); + setFont(FSkin.getBoldFont(14));*/ + resetImg(); + if ((imgL != null) && (imgM != null) && (imgR != null)) { + allImagesPresent = true; + } + } + + private void resetImg() { + imgL = FSkin.getImage(FSkin.ButtonImages.IMG_BTN_UP_LEFT); + imgM = FSkin.getImage(FSkin.ButtonImages.IMG_BTN_UP_CENTER); + imgR = FSkin.getImage(FSkin.ButtonImages.IMG_BTN_UP_RIGHT); + } + + public boolean isEnabled() { + return enabled; + } + + public void setEnabled(boolean b0) { + if (enabled == b0) { return; } + enabled = b0; + + if (enabled) { + resetImg(); + } + else { + imgL = FSkin.getImage(FSkin.ButtonImages.IMG_BTN_DISABLED_LEFT); + imgM = FSkin.getImage(FSkin.ButtonImages.IMG_BTN_DISABLED_CENTER); + imgR = FSkin.getImage(FSkin.ButtonImages.IMG_BTN_DISABLED_RIGHT); + } + } + + /** + * Button toggle state, for a "permanently pressed" functionality, e.g. as a tab. + * + * @return boolean + */ + public boolean isToggled() { + return toggled; + } + + /** @param b0   boolean. */ + public void setToggled(boolean b0) { + if (toggled == b0) { return; } + toggled = b0; + + if (toggled) { + imgL = FSkin.getImage(FSkin.ButtonImages.IMG_BTN_TOGGLE_LEFT); + imgM = FSkin.getImage(FSkin.ButtonImages.IMG_BTN_TOGGLE_CENTER); + imgR = FSkin.getImage(FSkin.ButtonImages.IMG_BTN_TOGGLE_RIGHT); + } + else if (isEnabled()) { + resetImg(); + } + else { + imgL = FSkin.getImage(FSkin.ButtonImages.IMG_BTN_DISABLED_LEFT); + imgM = FSkin.getImage(FSkin.ButtonImages.IMG_BTN_DISABLED_CENTER); + imgR = FSkin.getImage(FSkin.ButtonImages.IMG_BTN_DISABLED_RIGHT); + } + } + + @Override + public void draw(SpriteBatch batch, float parentAlpha) { + if (!allImagesPresent) { + return; + } + + float w = getWidth(); + float h = getHeight(); + + Color color = getColor(); + batch.setColor(color.r, color.g, color.b, color.a * parentAlpha); + + FSkin.drawImage(batch, imgL, 0, 0, h, h); + FSkin.drawImage(batch, imgM, h, 0, w - (2 * h), h); + FSkin.drawImage(batch, imgR, w - h, 0, h, h); + } +} diff --git a/forge-m-base/src/forge/gui/toolbox/FSkin.java b/forge-m-base/src/forge/gui/toolbox/FSkin.java index 09be6eb813a..4f1c0a6ec98 100644 --- a/forge-m-base/src/forge/gui/toolbox/FSkin.java +++ b/forge-m-base/src/forge/gui/toolbox/FSkin.java @@ -238,10 +238,10 @@ public class FSkin { } } - public static void drawImage(SpriteBatch batch, SkinImage skinImage, int x, int y) { + public static void drawImage(SpriteBatch batch, SkinImage skinImage, float x, float y) { batch.draw(skinImage.image, x, y); } - public static void drawImage(SpriteBatch batch, SkinImage skinImage, int x, int y, int w, int h) { + public static void drawImage(SpriteBatch batch, SkinImage skinImage, float x, float y, float w, float h) { batch.draw(skinImage.image, x, y, w, h); } diff --git a/forge-m-base/src/forge/gui/toolbox/LayoutHelper.java b/forge-m-base/src/forge/gui/toolbox/LayoutHelper.java new file mode 100644 index 00000000000..7bfd707eaca --- /dev/null +++ b/forge-m-base/src/forge/gui/toolbox/LayoutHelper.java @@ -0,0 +1,180 @@ +package forge.gui.toolbox; + +import com.badlogic.gdx.scenes.scene2d.Actor; + +/** + * Helper class for doing custom layout + * + */ +public final class LayoutHelper { + private final float parentWidth, parentHeight; + private float x, y, lineBottom, gapX, gapY; + + public LayoutHelper(float parentWidth0, float parentHeight0) { + this(parentWidth0, parentHeight0, 3, 3); + } + public LayoutHelper(float parentWidth0, float parentHeight0, float gapX0, float gapY0) { + parentWidth = parentWidth0; + parentHeight = parentHeight0; + gapX = gapX0; + gapY = gapY0; + } + + /** + * Layout actoronent to fill remaining vertical space of parent + * @param actor + */ + public void fill(final Actor actor) { + newLine(); //start new line if needed + include(actor, parentWidth, parentHeight - y); + } + + /** + * Layout actoronent to fill remaining horizontal space of current line + * @param actor + * @param height + */ + public void fillLine(final Actor actor, float height) { + fillLine(actor, height, 0); + } + + /** + * Layout actoronent to fill remaining horizontal space of current line + * @param actor + * @param height + * @param rightPadding + */ + public void fillLine(final Actor actor, float height, float rightPadding) { + if (x >= parentWidth) { + newLine(); + } + include(actor, parentWidth - x - rightPadding, height); + } + + /** + * Include actoronent in layout with a percentage width and fixed height + * @param actor + * @param widthPercent + * @param height + */ + public void include(final Actor actor, double widthPercent, float height) { + include(actor, parentWidth * widthPercent, height); + } + + /** + * Include actoronent in layout with a fixed width and percentage height + * @param actor + * @param width + * @param heightPercent + */ + public void include(final Actor actor, float width, double heightPercent) { + include(actor, width, parentHeight * heightPercent); + } + + /** + * Include actoronent in layout with a percentage width and height + * @param actor + * @param widthPercent + * @param heightPercent + */ + public void include(final Actor actor, double widthPercent, double heightPercent) { + include(actor, parentWidth * widthPercent, parentHeight * heightPercent); + } + + /** + * Include actoronent in layout with a fixed width and height + * @param actor + * @param width + * @param height + */ + public void include(final Actor actor, float width, float height) { + if (width <= 0 || height <= 0) { return; } + + if (x + width > parentWidth) { + newLine(); + if (width > parentWidth) { + width = parentWidth; + } + } + if (y + height > parentHeight) { + y = parentHeight - height; + if (y >= parentHeight) { return; } + } + actor.setBounds(x, y, width, height); + x += width + gapX; + if (y + height > lineBottom) { + lineBottom = y + height; + } + } + + /** + * Offset current layout helper position + * @param dx + * @param dy + */ + public void offset(float dx, float dy) { + x += dx; + y += dy; + } + + /** + * Start new line of layout + */ + public void newLine() { + if (lineBottom == y) { return; } + x = 0; + y = lineBottom + gapY; + lineBottom = y; + } + + /** + * Start new line of layout + */ + public void newLine(float dy) { + x = 0; + y = lineBottom + gapY + dy; + lineBottom = y; + } + + /** + * @return width of parent + */ + public float getParentWidth() { + return parentWidth; + } + + /** + * @return width of parent + */ + public float getParentHeight() { + return parentHeight; + } + + /** + * @return current X + */ + public float getX() { + return x; + } + + /** + * @return current Y + */ + public float getY() { + return y; + } + + /** + * @return gap X + */ + public float getGapX() { + return gapX; + } + + /** + * @return gap Y + */ + public float getGapY() { + return gapY; + } +}