Add StartButton

This commit is contained in:
drdev
2014-02-23 07:27:46 +00:00
parent a3a7ecaf6f
commit fc2fe0b3dc
11 changed files with 75 additions and 14 deletions

1
.gitattributes vendored
View File

@@ -16002,6 +16002,7 @@ forge-m-base/src/forge/toolbox/FButton.java -text
forge-m-base/src/forge/toolbox/FContainer.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/FDisplayObject.java -text
forge-m-base/src/forge/toolbox/FLabel.java -text forge-m-base/src/forge/toolbox/FLabel.java -text
forge-m-base/src/forge/toolbox/StartButton.java -text
forge-m-base/src/forge/utils/Utils.java -text forge-m-base/src/forge/utils/Utils.java -text
forge-m-desktop/.classpath -text forge-m-desktop/.classpath -text
forge-m-desktop/.project -text forge-m-desktop/.project -text

View File

@@ -85,14 +85,14 @@ public abstract class FScreen extends FContainer {
if (lblHeader != null) { if (lblHeader != null) {
lblHeader.setBounds(headerX, 0, headerWidth, headerHeight); lblHeader.setBounds(headerX, 0, headerWidth, headerHeight);
doLayout(0, headerHeight, width, height - headerHeight); doLayout(headerHeight, width, height);
} }
else { else {
doLayout(0, 0, width, height); doLayout(0, width, height);
} }
} }
protected abstract void doLayout(float x, float y, float width, float height); protected abstract void doLayout(float startY, float width, float height);
@Override @Override
protected void drawBackground(Graphics g) { protected void drawBackground(Graphics g) {

View File

@@ -1,14 +1,23 @@
package forge.screens.constructed; package forge.screens.constructed;
import forge.FScreen; import forge.FScreen;
import forge.toolbox.StartButton;
public class ConstructedScreen extends FScreen { public class ConstructedScreen extends FScreen {
private final StartButton btnStart;
public ConstructedScreen() { public ConstructedScreen() {
super(true, "Constructed", true); super(true, "Constructed", true);
btnStart = add(new StartButton() {
@Override
public void start() {
//TODO: Start match
}
});
} }
@Override @Override
protected void doLayout(float x, float y, float width, float height) { protected void doLayout(float startY, float width, float height) {
height = btnStart.updateLayout(width, height); //update height to exclude area taken up by StartButton
} }
} }

View File

@@ -9,6 +9,6 @@ public class DraftScreen extends FScreen {
} }
@Override @Override
protected void doLayout(float x, float y, float width, float height) { protected void doLayout(float startY, float width, float height) {
} }
} }

View File

@@ -9,6 +9,6 @@ public class GuantletScreen extends FScreen {
} }
@Override @Override
protected void doLayout(float x, float y, float width, float height) { protected void doLayout(float startY, float width, float height) {
} }
} }

View File

@@ -72,9 +72,9 @@ public class HomeScreen extends FScreen {
} }
@Override @Override
protected void doLayout(float x, float y, float width, float height) { protected void doLayout(float startY, float width, float height) {
x = width * INSETS_FACTOR; float x = width * INSETS_FACTOR;
y = width * LOGO_SIZE_FACTOR + 2 * x; //start below background logo float y = width * LOGO_SIZE_FACTOR + 2 * x; //start below background logo
float dy = height * GAP_Y_FACTOR; float dy = height * GAP_Y_FACTOR;
float buttonWidth = width - 2 * x; float buttonWidth = width - 2 * x;
float buttonHeight = (height - y - x) / buttons.size() - dy; float buttonHeight = (height - y - x) / buttons.size() - dy;

View File

@@ -9,6 +9,6 @@ public class QuestScreen extends FScreen {
} }
@Override @Override
protected void doLayout(float x, float y, float width, float height) { protected void doLayout(float startY, float width, float height) {
} }
} }

View File

@@ -9,6 +9,6 @@ public class SealedScreen extends FScreen {
} }
@Override @Override
protected void doLayout(float x, float y, float width, float height) { protected void doLayout(float startY, float width, float height) {
} }
} }

View File

@@ -9,6 +9,6 @@ public class SettingsScreen extends FScreen {
} }
@Override @Override
protected void doLayout(float x, float y, float width, float height) { protected void doLayout(float startY, float width, float height) {
} }
} }

View File

@@ -90,7 +90,7 @@ public class FButton extends FDisplayObject {
@Override @Override
public final boolean touchDown(float x, float y) { public final boolean touchDown(float x, float y) {
if (isToggled() || !isEnabled()) { return true; } if (isToggled()) { return true; }
imgL = FSkinImage.BTN_DOWN_LEFT; imgL = FSkinImage.BTN_DOWN_LEFT;
imgM = FSkinImage.BTN_DOWN_CENTER; imgM = FSkinImage.BTN_DOWN_CENTER;
imgR = FSkinImage.BTN_DOWN_RIGHT; imgR = FSkinImage.BTN_DOWN_RIGHT;
@@ -99,7 +99,7 @@ public class FButton extends FDisplayObject {
@Override @Override
public final boolean touchUp(float x, float y) { public final boolean touchUp(float x, float y) {
if (isToggled() || !isEnabled()) { return true; } if (isToggled()) { return true; }
resetImg(); resetImg();
return true; return true;
} }

View File

@@ -0,0 +1,51 @@
package forge.toolbox;
import com.badlogic.gdx.math.Vector2;
import forge.Forge.Graphics;
import forge.assets.FSkinImage;
public abstract class StartButton extends FDisplayObject {
private boolean pressed;
/**
* Instantiates a new FButton.
*/
public StartButton() {
}
public abstract void start();
@Override
public final boolean touchDown(float x, float y) {
pressed = true;
return true;
}
@Override
public final boolean touchUp(float x, float y) {
pressed = false;
return true;
}
@Override
public final boolean tap(float x, float y, int count) {
if (count == 1) {
start();
}
return true;
}
public float updateLayout(float parentWidth, float parentHeight) {
Vector2 size = FSkinImage.BTN_START_UP.getSize();
float padding = size.y * 0.1f;
setBounds((parentWidth - size.x) / 2, parentHeight - size.y - padding, size.x, size.y);
return parentHeight - size.y - 2 * padding; //indicate to caller how much space is taken up by StartButton
}
@Override
public void draw(Graphics g) {
g.drawImage(pressed ? FSkinImage.BTN_START_DOWN : FSkinImage.BTN_START_UP,
0, 0, getWidth(), getHeight());
}
}