mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 03:08:02 +00:00
Add more screens
Add FLabel Support FButton command on tap Support visible/enabled at FDisplayObject level
This commit is contained in:
8
.gitattributes
vendored
8
.gitattributes
vendored
@@ -15986,14 +15986,22 @@ forge-m-base/libs/gdx-sources.jar -text
|
||||
forge-m-base/libs/gdx.jar -text
|
||||
forge-m-base/src/forge/FScreen.java -text
|
||||
forge-m-base/src/forge/Forge.java -text
|
||||
forge-m-base/src/forge/assets/FImage.java -text
|
||||
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/screens/constructed/ConstructedScreen.java -text
|
||||
forge-m-base/src/forge/screens/draft/DraftScreen.java -text
|
||||
forge-m-base/src/forge/screens/guantlet/GuantletScreen.java -text
|
||||
forge-m-base/src/forge/screens/home/HomeScreen.java -text
|
||||
forge-m-base/src/forge/screens/quest/QuestScreen.java -text
|
||||
forge-m-base/src/forge/screens/sealed/SealedScreen.java -text
|
||||
forge-m-base/src/forge/screens/settings/SettingsScreen.java -text
|
||||
forge-m-base/src/forge/toolbox/FButton.java -text
|
||||
forge-m-base/src/forge/toolbox/FContainer.java -text
|
||||
forge-m-base/src/forge/toolbox/FDisplayObject.java -text
|
||||
forge-m-base/src/forge/toolbox/FLabel.java -text
|
||||
forge-m-desktop/.classpath -text
|
||||
forge-m-desktop/.project -text
|
||||
forge-m-desktop/.settings/org.eclipse.jdt.core.prefs -text
|
||||
|
||||
@@ -22,7 +22,7 @@ import com.badlogic.gdx.scenes.scene2d.utils.ScissorStack;
|
||||
import forge.assets.FSkin;
|
||||
import forge.assets.FSkinColor;
|
||||
import forge.assets.FSkinFont;
|
||||
import forge.assets.FSkinImage;
|
||||
import forge.assets.FImage;
|
||||
import forge.screens.home.HomeScreen;
|
||||
import forge.toolbox.FDisplayObject;
|
||||
|
||||
@@ -127,7 +127,7 @@ public class Forge implements ApplicationListener {
|
||||
public boolean touchDown(float x, float y, int pointer, int button) {
|
||||
potentialListeners.clear();
|
||||
if (currentScreen != null) { //base potential listeners on object containing touch down point
|
||||
currentScreen.buildObjectsContainingPoint(x, y, potentialListeners);
|
||||
currentScreen.buildTouchListeners(x, y, potentialListeners);
|
||||
}
|
||||
for (FDisplayObject listener : potentialListeners) {
|
||||
if (listener.touchDown(x, y)) {
|
||||
@@ -264,14 +264,14 @@ public class Forge implements ApplicationListener {
|
||||
batch.begin();
|
||||
}
|
||||
|
||||
public void drawImage(FSkinImage image, float x, float y) {
|
||||
drawImage(FSkin.getImages().get(image), x, y);
|
||||
public void drawImage(FImage image, float x, float y) {
|
||||
image.draw(this, x, y);
|
||||
}
|
||||
public void drawImage(TextureRegion image, float x, float y) {
|
||||
batch.draw(image, adjustX(x), adjustY(y, image.getRegionHeight()));
|
||||
}
|
||||
public void drawImage(FSkinImage image, float x, float y, float w, float h) {
|
||||
drawImage(FSkin.getImages().get(image), x, y, w, h);
|
||||
public void drawImage(FImage image, float x, float y, float w, float h) {
|
||||
image.draw(this, x, y, 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);
|
||||
|
||||
8
forge-m-base/src/forge/assets/FImage.java
Normal file
8
forge-m-base/src/forge/assets/FImage.java
Normal file
@@ -0,0 +1,8 @@
|
||||
package forge.assets;
|
||||
|
||||
import forge.Forge.Graphics;
|
||||
|
||||
public interface FImage {
|
||||
void draw(Graphics g, float x, float y);
|
||||
void draw(Graphics g, float x, float y, float w, float h);
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
package forge.assets;
|
||||
|
||||
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 {
|
||||
public enum FSkinImage implements FImage {
|
||||
//Backgrounds
|
||||
BG_SPLASH (0, 0, 0, -100, SourceFile.SPLASH), //treat 0 and negative as offset from full width/height
|
||||
BG_TEXTURE (0, 0, 0, 0, SourceFile.TEXTURE),
|
||||
@@ -277,4 +279,13 @@ public enum FSkinImage {
|
||||
public SourceFile getSourceFile() {
|
||||
return sourceFile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Graphics g, float x, float y) {
|
||||
g.drawImage(FSkin.getImages().get(this), x, y);
|
||||
}
|
||||
@Override
|
||||
public void draw(Graphics g, float x, float y, float w, float h) {
|
||||
g.drawImage(FSkin.getImages().get(this), x, y, w, h);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package forge.screens.constructed;
|
||||
|
||||
import forge.FScreen;
|
||||
|
||||
public class ConstructedScreen extends FScreen {
|
||||
|
||||
public ConstructedScreen() {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doLayout(float width, float height) {
|
||||
}
|
||||
}
|
||||
13
forge-m-base/src/forge/screens/draft/DraftScreen.java
Normal file
13
forge-m-base/src/forge/screens/draft/DraftScreen.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package forge.screens.draft;
|
||||
|
||||
import forge.FScreen;
|
||||
|
||||
public class DraftScreen extends FScreen {
|
||||
|
||||
public DraftScreen() {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doLayout(float width, float height) {
|
||||
}
|
||||
}
|
||||
13
forge-m-base/src/forge/screens/guantlet/GuantletScreen.java
Normal file
13
forge-m-base/src/forge/screens/guantlet/GuantletScreen.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package forge.screens.guantlet;
|
||||
|
||||
import forge.FScreen;
|
||||
|
||||
public class GuantletScreen extends FScreen {
|
||||
|
||||
public GuantletScreen() {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doLayout(float width, float height) {
|
||||
}
|
||||
}
|
||||
@@ -3,8 +3,15 @@ package forge.screens.home;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import forge.FScreen;
|
||||
import forge.Forge;
|
||||
import forge.Forge.Graphics;
|
||||
import forge.assets.FSkinImage;
|
||||
import forge.screens.constructed.ConstructedScreen;
|
||||
import forge.screens.draft.DraftScreen;
|
||||
import forge.screens.guantlet.GuantletScreen;
|
||||
import forge.screens.quest.QuestScreen;
|
||||
import forge.screens.sealed.SealedScreen;
|
||||
import forge.screens.settings.SettingsScreen;
|
||||
import forge.toolbox.FButton;
|
||||
|
||||
public class HomeScreen extends FScreen {
|
||||
@@ -14,12 +21,42 @@ public class HomeScreen extends FScreen {
|
||||
private final ArrayList<FButton> buttons = new ArrayList<FButton>();
|
||||
|
||||
public HomeScreen() {
|
||||
addButton("Constructed");
|
||||
addButton("Draft");
|
||||
addButton("Sealed");
|
||||
addButton("Quest");
|
||||
addButton("Guantlet");
|
||||
addButton("Settings");
|
||||
addButton("Constructed", new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Forge.openScreen(new ConstructedScreen());
|
||||
}
|
||||
});
|
||||
addButton("Draft", new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Forge.openScreen(new DraftScreen());
|
||||
}
|
||||
});
|
||||
addButton("Sealed", new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Forge.openScreen(new SealedScreen());
|
||||
}
|
||||
});
|
||||
addButton("Quest", new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Forge.openScreen(new QuestScreen());
|
||||
}
|
||||
});
|
||||
addButton("Guantlet", new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Forge.openScreen(new GuantletScreen());
|
||||
}
|
||||
});
|
||||
addButton("Settings", new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Forge.openScreen(new SettingsScreen());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -47,7 +84,7 @@ public class HomeScreen extends FScreen {
|
||||
}
|
||||
}
|
||||
|
||||
private void addButton(String caption) {
|
||||
buttons.add(this.add(new FButton(caption)));
|
||||
private void addButton(String caption, Runnable command) {
|
||||
buttons.add(this.add(new FButton(caption, command)));
|
||||
}
|
||||
}
|
||||
|
||||
13
forge-m-base/src/forge/screens/quest/QuestScreen.java
Normal file
13
forge-m-base/src/forge/screens/quest/QuestScreen.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package forge.screens.quest;
|
||||
|
||||
import forge.FScreen;
|
||||
|
||||
public class QuestScreen extends FScreen {
|
||||
|
||||
public QuestScreen() {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doLayout(float width, float height) {
|
||||
}
|
||||
}
|
||||
13
forge-m-base/src/forge/screens/sealed/SealedScreen.java
Normal file
13
forge-m-base/src/forge/screens/sealed/SealedScreen.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package forge.screens.sealed;
|
||||
|
||||
import forge.FScreen;
|
||||
|
||||
public class SealedScreen extends FScreen {
|
||||
|
||||
public SealedScreen() {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doLayout(float width, float height) {
|
||||
}
|
||||
}
|
||||
13
forge-m-base/src/forge/screens/settings/SettingsScreen.java
Normal file
13
forge-m-base/src/forge/screens/settings/SettingsScreen.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package forge.screens.settings;
|
||||
|
||||
import forge.FScreen;
|
||||
|
||||
public class SettingsScreen extends FScreen {
|
||||
|
||||
public SettingsScreen() {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doLayout(float width, float height) {
|
||||
}
|
||||
}
|
||||
@@ -13,18 +13,23 @@ public class FButton extends FDisplayObject {
|
||||
private FSkinImage imgL, imgM, imgR;
|
||||
private String caption;
|
||||
private FSkinFont font;
|
||||
private boolean enabled = true;
|
||||
private boolean toggled = false;
|
||||
private Runnable command;
|
||||
|
||||
/**
|
||||
* Instantiates a new FButton.
|
||||
*/
|
||||
public FButton() {
|
||||
this("");
|
||||
this("", null);
|
||||
}
|
||||
|
||||
public FButton(final String caption0) {
|
||||
this(caption0, null);
|
||||
}
|
||||
|
||||
public FButton(final String caption0, Runnable command0) {
|
||||
caption = caption0;
|
||||
command = command0;
|
||||
font = FSkinFont.get(14);
|
||||
resetImg();
|
||||
}
|
||||
@@ -35,15 +40,12 @@ public class FButton extends FDisplayObject {
|
||||
imgR = FSkinImage.BTN_UP_RIGHT;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEnabled(boolean b0) {
|
||||
if (enabled == b0) { return; }
|
||||
enabled = b0;
|
||||
if (isEnabled() == b0) { return; }
|
||||
super.setEnabled(b0);
|
||||
|
||||
if (enabled) {
|
||||
if (b0) {
|
||||
resetImg();
|
||||
}
|
||||
else {
|
||||
@@ -80,6 +82,10 @@ public class FButton extends FDisplayObject {
|
||||
}
|
||||
}
|
||||
|
||||
public void setCommand(Runnable command0) {
|
||||
command = command0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean touchDown(float x, float y) {
|
||||
if (isToggled() || !isEnabled()) { return true; }
|
||||
@@ -98,8 +104,8 @@ public class FButton extends FDisplayObject {
|
||||
|
||||
@Override
|
||||
public boolean tap(float x, float y, int count) {
|
||||
if (count == 1) {
|
||||
//TODO: Run command
|
||||
if (count == 1 && command != null) {
|
||||
command.run();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,9 @@ public abstract class FContainer extends FDisplayObject {
|
||||
public final void draw(Graphics g) {
|
||||
drawBackground(g);
|
||||
for (FDisplayObject child : children) {
|
||||
g.draw(child);
|
||||
if (child.isVisible()) {
|
||||
g.draw(child);
|
||||
}
|
||||
}
|
||||
drawOverlay(g);
|
||||
}
|
||||
@@ -46,12 +48,13 @@ public abstract class FContainer extends FDisplayObject {
|
||||
|
||||
protected abstract void doLayout(float width, float height);
|
||||
|
||||
public final void buildObjectsContainingPoint(float x, float y, ArrayList<FDisplayObject> objs) {
|
||||
if (contains(x, y)) {
|
||||
@Override
|
||||
public final void buildTouchListeners(float x, float y, ArrayList<FDisplayObject> listeners) {
|
||||
if (isEnabled() && contains(x, y)) {
|
||||
for (FDisplayObject child : children) {
|
||||
child.buildObjectsContainingPoint(x, y, objs);
|
||||
child.buildTouchListeners(x, y, listeners);
|
||||
}
|
||||
objs.add(this);
|
||||
listeners.add(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@ import com.badlogic.gdx.math.Vector2;
|
||||
import forge.Forge.Graphics;
|
||||
|
||||
public abstract class FDisplayObject {
|
||||
private boolean visible = true;
|
||||
private boolean enabled = true;
|
||||
private final Rectangle bounds = new Rectangle();
|
||||
|
||||
public void setPosition(float x, float y) {
|
||||
@@ -38,14 +40,28 @@ public abstract class FDisplayObject {
|
||||
return bounds.height;
|
||||
}
|
||||
public boolean contains(float x, float y) {
|
||||
return bounds.contains(x, y);
|
||||
return visible && bounds.contains(x, y);
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
public void setEnabled(boolean b0) {
|
||||
enabled = b0;
|
||||
}
|
||||
|
||||
public boolean isVisible() {
|
||||
return visible;
|
||||
}
|
||||
public void setVisible(boolean b0) {
|
||||
visible = b0;
|
||||
}
|
||||
|
||||
public abstract void draw(Graphics g);
|
||||
|
||||
public void buildObjectsContainingPoint(float x, float y, ArrayList<FDisplayObject> objs) {
|
||||
if (contains(x, y)) {
|
||||
objs.add(this);
|
||||
public void buildTouchListeners(float x, float y, ArrayList<FDisplayObject> listeners) {
|
||||
if (enabled && contains(x, y)) {
|
||||
listeners.add(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
121
forge-m-base/src/forge/toolbox/FLabel.java
Normal file
121
forge-m-base/src/forge/toolbox/FLabel.java
Normal file
@@ -0,0 +1,121 @@
|
||||
package forge.toolbox;
|
||||
|
||||
import com.badlogic.gdx.graphics.g2d.BitmapFont.HAlignment;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
|
||||
import forge.Forge.Graphics;
|
||||
import forge.assets.FSkinColor;
|
||||
import forge.assets.FSkinColor.Colors;
|
||||
import forge.assets.FSkinFont;
|
||||
import forge.assets.FSkinImage;
|
||||
|
||||
public class FLabel extends FDisplayObject {
|
||||
public static class Builder {
|
||||
//========== Default values for FLabel are set here.
|
||||
private double bldIconScaleFactor = 0.8;
|
||||
private int bldFontSize = 14;
|
||||
private HAlignment bldFontAlign = HAlignment.LEFT;
|
||||
private HAlignment bldIconAlignX = HAlignment.LEFT;
|
||||
private Vector2 bldIconInsets = new Vector2(0, 0);
|
||||
|
||||
private boolean bldSelectable = false;
|
||||
private boolean bldSelected = false;
|
||||
private boolean bldOpaque = false;
|
||||
private boolean bldIconInBackground = false;
|
||||
private boolean bldIconScaleAuto = true;
|
||||
private boolean bldEnabled = true;
|
||||
|
||||
private String bldText;
|
||||
private FSkinImage bldIcon;
|
||||
private Runnable bldCommand;
|
||||
|
||||
public FLabel build() { return new FLabel(this); }
|
||||
|
||||
// Begin builder methods.
|
||||
public Builder text(final String s0) { this.bldText = s0; return this; }
|
||||
public Builder icon(final FSkinImage i0) { this.bldIcon = i0; return this; }
|
||||
public Builder fontAlign(final HAlignment a0) { this.bldFontAlign = a0; return this; }
|
||||
public Builder opaque(final boolean b0) { this.bldOpaque = b0; return this; }
|
||||
public Builder opaque() { opaque(true); return this; }
|
||||
public Builder selectable(final boolean b0) { this.bldSelectable = b0; return this; }
|
||||
public Builder selectable() { selectable(true); return this; }
|
||||
public Builder selected(final boolean b0) { this.bldSelected = b0; return this; }
|
||||
public Builder selected() { selected(true); return this; }
|
||||
public Builder command(final Runnable c0) { this.bldCommand = c0; return this; }
|
||||
public Builder fontSize(final int i0) { this.bldFontSize = i0; return this; }
|
||||
public Builder enabled(final boolean b0) { this.bldEnabled = b0; return this; }
|
||||
public Builder iconScaleAuto(final boolean b0) { this.bldIconScaleAuto = b0; return this; }
|
||||
public Builder iconScaleFactor(final double d0) { this.bldIconScaleFactor = d0; return this; }
|
||||
public Builder iconInBackground(final boolean b0) { this.bldIconInBackground = b0; return this; }
|
||||
public Builder iconInBackground() { iconInBackground(true); return this; }
|
||||
public Builder iconAlignX(final HAlignment a0) { this.bldIconAlignX = a0; return this; }
|
||||
public Builder iconInsets(final Vector2 v0) { this.bldIconInsets = v0; return this; }
|
||||
}
|
||||
|
||||
// sets better defaults for button labels
|
||||
public static class ButtonBuilder extends Builder {
|
||||
public ButtonBuilder() {
|
||||
opaque();
|
||||
}
|
||||
}
|
||||
|
||||
private static final FSkinColor clrText = FSkinColor.get(Colors.CLR_TEXT);
|
||||
private static final FSkinColor clrMain = FSkinColor.get(Colors.CLR_INACTIVE);
|
||||
private static final FSkinColor d50 = clrMain.stepColor(-50);
|
||||
private static final FSkinColor d30 = clrMain.stepColor(-30);
|
||||
private static final FSkinColor d10 = clrMain.stepColor(-10);
|
||||
private static final FSkinColor l10 = clrMain.stepColor(10);
|
||||
private static final FSkinColor l20 = clrMain.stepColor(20);
|
||||
private static final FSkinColor l30 = clrMain.stepColor(30);
|
||||
|
||||
private double iconScaleFactor;
|
||||
private FSkinFont font;
|
||||
private HAlignment fontAlign, iconAlignX;
|
||||
private Vector2 iconInsets;
|
||||
private boolean selectable, selected, opaque, iconInBackground, iconScaleAuto, enabled;
|
||||
|
||||
private String text;
|
||||
private FSkinImage icon;
|
||||
private Runnable command;
|
||||
|
||||
// Call this using FLabel.Builder()...
|
||||
protected FLabel(final Builder b0) {
|
||||
iconScaleFactor = b0.bldIconScaleFactor;
|
||||
font = FSkinFont.get(b0.bldFontSize);
|
||||
fontAlign = b0.bldFontAlign;
|
||||
iconAlignX = b0.bldIconAlignX;
|
||||
iconInsets = b0.bldIconInsets;
|
||||
selectable = b0.bldSelectable;
|
||||
selected = b0.bldSelected;
|
||||
opaque = b0.bldOpaque;
|
||||
iconInBackground = b0.bldIconInBackground;
|
||||
iconScaleAuto = b0.bldIconScaleAuto;
|
||||
setEnabled(b0.bldEnabled);
|
||||
}
|
||||
|
||||
public boolean getSelected() {
|
||||
return this.selected;
|
||||
}
|
||||
public void setSelected(final boolean b0) {
|
||||
this.selected = b0;
|
||||
}
|
||||
|
||||
public boolean tap(float x, float y, int count) {
|
||||
boolean handled = false;
|
||||
if (selectable) {
|
||||
setSelected(!selected);
|
||||
handled = true;
|
||||
}
|
||||
if (command != null) {
|
||||
command.run();
|
||||
handled = true;
|
||||
}
|
||||
return handled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Graphics g) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user