mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-15 10:18:01 +00:00
Support border behind card panels
This commit is contained in:
29
forge-gui-mobile/src/forge/assets/FSkinBorder.java
Normal file
29
forge-gui-mobile/src/forge/assets/FSkinBorder.java
Normal file
@@ -0,0 +1,29 @@
|
||||
package forge.assets;
|
||||
|
||||
import forge.Forge.Graphics;
|
||||
|
||||
public class FSkinBorder {
|
||||
private final FSkinColor color;
|
||||
private final float thickness;
|
||||
|
||||
public FSkinBorder(FSkinColor color0, float thickness0) {
|
||||
color = color0;
|
||||
thickness = thickness0;
|
||||
}
|
||||
|
||||
public FSkinColor getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
public float getThickness() {
|
||||
return thickness;
|
||||
}
|
||||
|
||||
public void draw(Graphics g, float x, float y, float w, float h) {
|
||||
x -= thickness;
|
||||
y -= thickness;
|
||||
w += 2 * thickness;
|
||||
h += 2 * thickness;
|
||||
g.fillRect(color, x, y, w, h); //draw filled rectangle behind object
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,10 @@
|
||||
*/
|
||||
package forge.screens.match.views;
|
||||
|
||||
import forge.Forge.KeyInputAdapter;
|
||||
import forge.assets.FSkinBorder;
|
||||
import forge.assets.FSkinColor;
|
||||
import forge.assets.FSkinColor.Colors;
|
||||
import forge.game.GameEntity;
|
||||
import forge.game.card.Card;
|
||||
import forge.game.card.CounterType;
|
||||
@@ -85,35 +89,6 @@ public class VAssignDamage extends FDialog {
|
||||
throw new RuntimeException("Asking to assign damage to object which is not present in defenders list");
|
||||
}
|
||||
|
||||
// Mouse actions
|
||||
/*private final MouseAdapter mad = new MouseAdapter() {
|
||||
@Override
|
||||
public void pressed(float x, float y) {
|
||||
Card source = ((FCardPanel) evt.getSource()).getCard();
|
||||
if (!damage.containsKey(source)) source = null; // to get player instead of fake card
|
||||
|
||||
FSkin.Colors brdrColor = VAssignDamage.canAssignTo(source) ? FSkin.Colors.CLR_ACTIVE : FSkin.Colors.CLR_INACTIVE;
|
||||
((FCardPanel) evt.getSource()).setBorder(new FSkin.LineSkinBorder(FSkin.getColor(brdrColor), 2));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void released(float x, float y) {
|
||||
//((FCardPanel) evt.getSource()).setBorder((Border)null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tap(float x, float y, int count) {
|
||||
Card source = ((FCardPanel) evt.getSource()).getCard(); // will be NULL for player
|
||||
|
||||
boolean meta = evt.isControlDown();
|
||||
boolean isLMB = SwingUtilities.isLeftMouseButton(evt);
|
||||
boolean isRMB = SwingUtilities.isRightMouseButton(evt);
|
||||
|
||||
if (isLMB || isRMB)
|
||||
assignDamageTo(source, meta, isLMB);
|
||||
}
|
||||
};*/
|
||||
|
||||
/** Constructor.
|
||||
*
|
||||
* @param attacker0 {@link forge.game.card.Card}
|
||||
@@ -203,7 +178,7 @@ public class VAssignDamage extends FDialog {
|
||||
DamageTarget dt = new DamageTarget(c, new FLabel.Builder().text("0").fontSize(18).align(HAlignment.CENTER).build());
|
||||
damage.put(c, dt);
|
||||
defenders.add(dt);
|
||||
add(new FCardPanel(c));
|
||||
add(new AssignDamageCardPanel(c));
|
||||
}
|
||||
|
||||
if (attackerHasTrample) {
|
||||
@@ -225,7 +200,7 @@ public class VAssignDamage extends FDialog {
|
||||
fakeCard = new Card(-2);
|
||||
fakeCard.setName(defender.getName());
|
||||
}
|
||||
add(new FCardPanel(fakeCard));
|
||||
add(new AssignDamageCardPanel(fakeCard));
|
||||
}
|
||||
|
||||
// Add "opponent placeholder" card if trample allowed
|
||||
@@ -253,6 +228,45 @@ public class VAssignDamage extends FDialog {
|
||||
}
|
||||
}
|
||||
|
||||
private class AssignDamageCardPanel extends FCardPanel {
|
||||
private FSkinColor borderColor;
|
||||
|
||||
private AssignDamageCardPanel(Card card0) {
|
||||
super(card0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean press(float x, float y) {
|
||||
Card source = getCard();
|
||||
if (!damage.containsKey(source)) {
|
||||
source = null; // to get player instead of fake card
|
||||
}
|
||||
|
||||
borderColor = canAssignTo(source) ? FSkinColor.get(Colors.CLR_ACTIVE) : FSkinColor.get(Colors.CLR_INACTIVE);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean release(float x, float y) {
|
||||
borderColor = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean tap(float x, float y, int count) {
|
||||
assignDamageTo(getCard(), KeyInputAdapter.isCtrlKeyDown(), true);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FSkinBorder getBorder() {
|
||||
if (borderColor == null) {
|
||||
return null;
|
||||
}
|
||||
return new FSkinBorder(borderColor, Utils.scaleMin(2));
|
||||
}
|
||||
}
|
||||
|
||||
private void assignDamageTo(Card source, boolean meta, boolean isAdding) {
|
||||
if (!damage.containsKey(source)) {
|
||||
source = null;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package forge.toolbox;
|
||||
|
||||
import forge.Forge.Graphics;
|
||||
import forge.assets.FSkinBorder;
|
||||
import forge.card.CardRenderer;
|
||||
import forge.game.card.Card;
|
||||
import forge.util.Utils;
|
||||
@@ -69,6 +70,10 @@ public class FCardPanel extends FDisplayObject {
|
||||
return x >= left && x <= left + w && y >= top && y <= top + h;
|
||||
}
|
||||
|
||||
protected FSkinBorder getBorder() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Graphics g) {
|
||||
if (card == null) { return; }
|
||||
@@ -86,6 +91,11 @@ public class FCardPanel extends FDisplayObject {
|
||||
g.setRotateTransform(x + edgeOffset, y + h - edgeOffset, tappedAngle);
|
||||
}
|
||||
|
||||
FSkinBorder border = getBorder();
|
||||
if (border != null) {
|
||||
border.draw(g, x, y, w, h);
|
||||
}
|
||||
|
||||
CardRenderer.drawCardWithOverlays(g, card, x, y, w, h);
|
||||
|
||||
if (tapped) {
|
||||
|
||||
Reference in New Issue
Block a user