Skip to content

Commit

Permalink
Macro system based on recording clicks rather than typing (#4006)
Browse files Browse the repository at this point in the history
* Add a new macro system that tracks clicks

* Old macro system is still around, but currently inaccessible. Maybe give an option if people rebel against that.
  • Loading branch information
tehdiplomat authored Dec 7, 2023
1 parent 6399288 commit 03725d2
Show file tree
Hide file tree
Showing 19 changed files with 563 additions and 163 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package forge.game.player.actions;

import forge.game.GameEntityView;

public class ActivateAbilityAction extends PlayerAction{
public ActivateAbilityAction(GameEntityView cardView) {
super(cardView);
name = "Activate ability";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package forge.game.player.actions;

import forge.game.GameEntityView;

public class CastSpellAction extends PlayerAction {
public CastSpellAction(GameEntityView cardView) {
super(cardView);
name = "Cast spell";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package forge.game.player.actions;

public class FinishTargetingAction extends PlayerAction{
public FinishTargetingAction() {
super(null);

name = "Finish game entity";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package forge.game.player.actions;

public class PassPriorityAction extends PlayerAction {
public PassPriorityAction() {
super(null);
name = "Pass Priority";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package forge.game.player.actions;

import forge.game.GameEntityView;

public class PayCostAction extends PlayerAction {
public PayCostAction(GameEntityView cardView) {
super(cardView);
name = "Pay cost";
gameEntityView = cardView;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package forge.game.player.actions;


public class PayManaFromPoolAction extends PlayerAction{
private byte colorSelected;
public PayManaFromPoolAction(byte colorCode) {
super(null);

name = "Pay mana";
colorSelected = colorCode;
}

public byte getSelectedColor() {
return colorSelected;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package forge.game.player.actions;

import forge.game.GameEntityView;
import forge.game.player.PlayerController;

public abstract class PlayerAction {
protected String name;
protected GameEntityView gameEntityView = null;

public PlayerAction(GameEntityView cardView) {
gameEntityView = cardView;
}

public void run(PlayerController controller) {
// Turn this abstract soon
// This should try to replicate the recorded macro action
}

public GameEntityView getGameEntityView() {
return gameEntityView;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package forge.game.player.actions;

import forge.game.GameEntityView;

public class SelectCardAction extends PlayerAction{
public SelectCardAction(GameEntityView cardView) {
super(cardView);
name = "Select card";
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package forge.game.player.actions;

import forge.game.GameEntityView;

public class SelectPlayerAction extends PlayerAction {
public SelectPlayerAction(GameEntityView playerView) {
super(playerView);
name = "Select player";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package forge.game.player.actions;

import forge.game.GameEntityView;

public class TargetEntityAction extends PlayerAction {
// TODO Add distribution damage/counters
public TargetEntityAction(GameEntityView cardView) {
super(cardView);
name = "Target game entity";
}
}
18 changes: 18 additions & 0 deletions forge-gui/src/main/java/forge/gamemodes/match/input/InputBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,24 @@ protected String getTurnPhasePriorityMessage(final Game game) {
sb.append("\n").append(localizer.getMessage("lblStormCount")).append(": ").append(stormCount);
}
}

if (controller.macros() != null) {
boolean isRecording = controller.macros().isRecording();
String pbText = controller.macros().playbackText();
if (pbText != null) {
sb.append("\n");
if (isRecording) {
sb.append("Macro Recording -- ");
} else {
sb.append("Macro Playback -- ");
}

sb.append(pbText);
} else if (isRecording) {
sb.append("\n").append("Macro Recording -- ");
}
}

return sb.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import forge.game.card.Card;
import forge.game.player.Player;
import forge.game.player.PlayerController;
import forge.game.player.actions.PassPriorityAction;
import forge.game.spellability.LandAbility;
import forge.game.spellability.SpellAbility;
import forge.localinstance.properties.ForgePreferences.FPref;
Expand Down Expand Up @@ -74,6 +75,7 @@ protected final void onOk() {
passPriority(new Runnable() {
@Override
public void run() {
getController().macros().addRememberedAction(new PassPriorityAction());
stop();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import forge.game.mana.ManaCostBeingPaid;
import forge.game.player.Player;
import forge.game.player.PlayerView;
import forge.game.player.actions.PayManaFromPoolAction;
import forge.game.spellability.AbilityManaPart;
import forge.game.spellability.SpellAbility;
import forge.game.spellability.SpellAbilityView;
Expand Down Expand Up @@ -200,6 +201,8 @@ public List<SpellAbility> getUsefulManaAbilities(Card card) {
public void useManaFromPool(byte colorCode) {
// find the matching mana in pool.
if (player.getManaPool().tryPayCostWithColor(colorCode, saPaidFor, manaCost, saPaidFor.getPayingMana())) {
// Record paying mana from pool here
getController().macros().addRememberedAction(new PayManaFromPoolAction(colorCode));
onManaAbilityPaid();
showMessage();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ else if (ge instanceof Player) {

private void done() {
for (final GameEntity c : targets) {
//getController().macros().addRememberedAction(new TargetEntityAction(c.getView()));
if (c instanceof Card) {
getController().getGui().setUsedToPay(CardView.get((Card) c), false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import forge.game.card.CardView;
import forge.game.player.PlayerView;
import forge.game.player.actions.PlayerAction;
import forge.game.spellability.SpellAbilityView;
import forge.gamemodes.match.NextGameDecision;
import forge.gamemodes.net.GameProtocolSender;
Expand Down Expand Up @@ -124,11 +125,16 @@ public void reorderHand(final CardView card, final int index) {
@Override
public IMacroSystem macros() {
if (macros == null) {
macros = new MacroSystem();
macros = new NetMacroSystem();
}
return macros;
}
public class MacroSystem implements IMacroSystem {
public class NetMacroSystem implements IMacroSystem {
@Override
public void addRememberedAction(PlayerAction action) {
// DO i need to send this?
}

@Override
public void setRememberedActions() {
send(ProtocolMethod.setRememberedActions);
Expand All @@ -138,5 +144,15 @@ public void setRememberedActions() {
public void nextRememberedAction() {
send(ProtocolMethod.nextRememberedAction);
}

@Override
public boolean isRecording() {
return false;
}

@Override
public String playbackText() {
return null;
}
}
}
5 changes: 5 additions & 0 deletions forge-gui/src/main/java/forge/interfaces/IMacroSystem.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package forge.interfaces;

import forge.game.player.actions.PlayerAction;

public interface IMacroSystem {
void addRememberedAction(PlayerAction action);
void setRememberedActions();
void nextRememberedAction();
boolean isRecording();
String playbackText();
}
Loading

0 comments on commit 03725d2

Please sign in to comment.