Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First pass at adding TAG-phase Torso Twist #5040

Merged
merged 6 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions megamek/i18n/megamek/client/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3500,6 +3500,7 @@ TargetingPhaseDisplay.fireFire=Fire
TargetingPhaseDisplay.fireFlipArms=Flip Arms
TargetingPhaseDisplay.its_others_turn=It''s {0}''s turn to declare indirect attacks.
TargetingPhaseDisplay.its_your_turn=It's your turn to declare indirect attacks.
TargetingPhaseDisplay.its_your_tag_turn=It's your turn to declare offboard / TAG attacks.
TargetingPhaseDisplay.fireCancel=Cancel
TargetingPhaseDisplay.fireMode=Mode
TargetingPhaseDisplay.fireNextTarg=Next Target
Expand Down
12 changes: 7 additions & 5 deletions megamek/src/megamek/client/commands/FireCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,14 @@ private void torsoTwist(int target) {
getClient().getGame().removeActionsFor(cen);

// restore any other movement to default
ce().setSecondaryFacing(ce().getFacing());
ce().setArmsFlipped(false);
if (!ce().getAlreadyTwisted()) {
ce().setSecondaryFacing(ce().getFacing());
ce().setArmsFlipped(false);

int direction = ce().clipSecondaryFacing(target);
attacks.addElement(new TorsoTwistAction(cen, direction));
ce().setSecondaryFacing(direction);
int direction = ce().clipSecondaryFacing(target);
attacks.addElement(new TorsoTwistAction(cen, direction));
ce().setSecondaryFacing(direction);
}
}

private void fire(int weaponNum, Targetable target) {
Expand Down
16 changes: 13 additions & 3 deletions megamek/src/megamek/client/ui/swing/FiringDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ public void performAction() {
@Override
public boolean shouldPerformAction() {
if (!clientgui.getClient().isMyTurn()
|| ce().getAlreadyTwisted()
|| clientgui.getBoardView().getChatterBoxActive()
|| !display.isVisible()
|| display.isIgnoringEvents()) {
Expand All @@ -310,6 +311,7 @@ public void performAction() {
@Override
public boolean shouldPerformAction() {
if (!clientgui.getClient().isMyTurn()
|| ce().getAlreadyTwisted()
|| clientgui.getBoardView().getChatterBoxActive()
|| !display.isVisible()
|| display.isIgnoringEvents()) {
Expand Down Expand Up @@ -825,10 +827,10 @@ public void selectEntity(int en) {
}

// only twist if crew conscious
setTwistEnabled(ce().canChangeSecondaryFacing() && ce().getCrew().isActive());
setTwistEnabled(!ce().getAlreadyTwisted() && ce().canChangeSecondaryFacing() && ce().getCrew().isActive());

setFindClubEnabled(FindClubAction.canMechFindClub(clientgui.getClient().getGame(), en));
setFlipArmsEnabled(ce().canFlipArms());
setFlipArmsEnabled(!ce().getAlreadyTwisted() && ce().canFlipArms());
updateSearchlight();
updateClearTurret();
updateClearWeaponJam();
Expand Down Expand Up @@ -2076,6 +2078,9 @@ void updateVTOLGroundTarget() {
* Torso twist in the proper direction.
*/
void torsoTwist(Coords twistTarget) {
if (ce().getAlreadyTwisted()) {
return;
}
int direction = ce().getFacing();

if (twistTarget != null) {
Expand All @@ -2098,6 +2103,9 @@ void torsoTwist(Coords twistTarget) {
*/

void torsoTwist(int twistDir) {
if (ce().getAlreadyTwisted()) {
return;
}
int direction = ce().getSecondaryFacing();
if (twistDir == 0) {
clearAttacks();
Expand Down Expand Up @@ -2149,7 +2157,7 @@ public void hexMoused(BoardViewEvent b) {
}

if (b.getType() == BoardViewEvent.BOARD_HEX_DRAGGED) {
if (shiftheld || twisting) {
if (!ce().getAlreadyTwisted() && (shiftheld || twisting)) {
updateFlipArms(false);
torsoTwist(b.getCoords());
}
Expand Down Expand Up @@ -2343,6 +2351,8 @@ void updateFlipArms(boolean armsFlipped) {
return;
} else if (armsFlipped == ce().getArmsFlipped()) {
return;
} else if (ce().getAlreadyTwisted()) {
return;
}

twisting = false;
Expand Down
128 changes: 123 additions & 5 deletions megamek/src/megamek/client/ui/swing/TargetingPhaseDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public class TargetingPhaseDisplay extends AttackPhaseDisplay implements
*/
public enum TargetingCommand implements PhaseCommand {
FIRE_NEXT("fireNext"),
FIRE_TWIST("fireTwist"),
FIRE_FIRE("fireFire"),
FIRE_SKIP("fireSkip"),
FIRE_NEXT_TARG("fireNextTarg"),
Expand Down Expand Up @@ -105,6 +106,8 @@ public String toString() {
public String getHotKeyDesc() {
String result = "";

String msg_left = Messages.getString("Left");
String msg_right = Messages.getString("Right");
String msg_next= Messages.getString("Next");
String msg_previous = Messages.getString("Previous");
String msg_valid = Messages.getString("TargetingPhaseDisplay.FireNextTarget.tooltip.Valid");
Expand All @@ -116,6 +119,11 @@ public String getHotKeyDesc() {
result += "  " + msg_next + ": " + KeyCommandBind.getDesc(KeyCommandBind.NEXT_UNIT);
result += "  " + msg_previous + ": " + KeyCommandBind.getDesc(KeyCommandBind.PREV_UNIT);
break;
case FIRE_TWIST:
result = "<BR>";
result += "&nbsp;&nbsp;" + msg_left + ": " + KeyCommandBind.getDesc(KeyCommandBind.TWIST_LEFT);
result += "&nbsp;&nbsp;" + msg_right + ": " + KeyCommandBind.getDesc(KeyCommandBind.TWIST_RIGHT);
break;
case FIRE_FIRE:
result = "<BR>";
result += "&nbsp;&nbsp;" + KeyCommandBind.getDesc(KeyCommandBind.FIRE);
Expand Down Expand Up @@ -166,6 +174,7 @@ public String getHotKeyDesc() {

// is the shift key held?
private boolean shiftheld;
protected boolean twisting;

private final GamePhase phase;

Expand Down Expand Up @@ -248,6 +257,54 @@ public void performAction() {
}
});

// Register the action for TWIST_LEFT
controller.registerCommandAction(KeyCommandBind.TWIST_LEFT.cmd,
new CommandAction() {

@Override
public boolean shouldPerformAction() {
if (!clientgui.getClient().isMyTurn()
|| !phase.isOffboard()
|| clientgui.getBoardView().getChatterBoxActive()
|| !display.isVisible()
|| display.isIgnoringEvents()) {
return false;
} else {
return true;
}
}

@Override
public void performAction() {
updateFlipArms(false);
torsoTwist(0);
}
});

// Register the action for TWIST_RIGHT
controller.registerCommandAction(KeyCommandBind.TWIST_RIGHT.cmd,
new CommandAction() {

@Override
public boolean shouldPerformAction() {
if (!clientgui.getClient().isMyTurn()
|| !phase.isOffboard()
|| clientgui.getBoardView().getChatterBoxActive()
|| !display.isVisible()
|| display.isIgnoringEvents()) {
return false;
} else {
return true;
}
}

@Override
public void performAction() {
updateFlipArms(false);
torsoTwist(1);
}
});

// Register the action for FIRE
controller.registerCommandAction(KeyCommandBind.FIRE.cmd,
new CommandAction() {
Expand Down Expand Up @@ -563,6 +620,7 @@ private void selectEntity(int en) {
clientgui.getBoardView().centerOnHex(ce().getPosition());
}

setTwistEnabled(phase.isOffboard() && ce().canChangeSecondaryFacing() && ce().getCrew().isActive());
setFlipArmsEnabled(ce().canFlipArms() && ce().getCrew().isActive());
updateSearchlight();

Expand Down Expand Up @@ -694,6 +752,7 @@ private void endMyTurn() {
*/
private void disableButtons() {
setFireEnabled(false);
setTwistEnabled(false);
setSkipEnabled(false);
setNextEnabled(false);
butDone.setEnabled(false);
Expand Down Expand Up @@ -1182,6 +1241,48 @@ private void jumpToPrevTarget() {
target(targ);
}

/**
* Torso twist in the proper direction.
*/
void torsoTwist(Coords twistTarget) {
int direction = ce().getFacing();

if (twistTarget != null) {
direction = ce().clipSecondaryFacing(ce().getPosition().direction(twistTarget));
}

if (direction != ce().getSecondaryFacing()) {
clearAttacks();
addAttack(new TorsoTwistAction(cen, direction));
ce().setSecondaryFacing(direction);
refreshAll();
}
}

/**
* Torso twist to the left or right
*
* @param twistDir An <code>int</code> specifying whether we're twisting left or
* right, 0 if we're twisting to the left, 1 if to the right.
*/

void torsoTwist(int twistDir) {
int direction = ce().getSecondaryFacing();
if (twistDir == 0) {
clearAttacks();
direction = ce().clipSecondaryFacing((direction + 5) % 6);
addAttack(new TorsoTwistAction(cen, direction));
ce().setSecondaryFacing(direction);
refreshAll();
} else if (twistDir == 1) {
clearAttacks();
direction = ce().clipSecondaryFacing((direction + 7) % 6);
addAttack(new TorsoTwistAction(cen, direction));
ce().setSecondaryFacing(direction);
refreshAll();
}
}

/**
* Returns the current entity.
*/
Expand Down Expand Up @@ -1216,12 +1317,16 @@ public void hexMoused(BoardViewEvent b) {
}

if (b.getType() == BoardViewEvent.BOARD_HEX_DRAGGED) {
if (shiftheld) {
if (phase.isOffboard() && (shiftheld || twisting)) {
updateFlipArms(false);
torsoTwist(b.getCoords());
}
clientgui.getBoardView().cursor(b.getCoords());
} else if (b.getType() == BoardViewEvent.BOARD_HEX_CLICKED) {
clientgui.getBoardView().select(b.getCoords());
twisting = false;
if (!shiftheld) {
clientgui.getBoardView().select(b.getCoords());
}
}
}

Expand All @@ -1236,8 +1341,9 @@ public void hexSelected(BoardViewEvent b) {

if (client.isMyTurn() && (b.getCoords() != null)
&& (ce() != null) && !b.getCoords().equals(ce().getPosition())) {
if (shiftheld) {
if (shiftheld && phase.isOffboard()) {
updateFlipArms(false);
torsoTwist(b.getCoords());
} else if (phase.isTargeting()) {
target(new HexTarget(b.getCoords(), Targetable.TYPE_HEX_ARTILLERY));
} else {
Expand Down Expand Up @@ -1339,8 +1445,9 @@ public void gameTurnChange(GameTurnChangeEvent e) {
if (cen == Entity.NONE) {
beginMyTurn();
}

setStatusBarText(Messages.getString("TargetingPhaseDisplay.its_your_turn") + s);
String t = (phase.isTargeting()) ? Messages.getString("TargetingPhaseDisplay.its_your_turn") :
Messages.getString("TargetingPhaseDisplay.its_your_tag_turn");
setStatusBarText(t + s);
clientgui.bingOthersTurn();
} else {
endMyTurn();
Expand Down Expand Up @@ -1386,6 +1493,8 @@ public void actionPerformed(ActionEvent ev) {

if (ev.getActionCommand().equals(TargetingCommand.FIRE_FIRE.getCmd())) {
fire();
} else if (ev.getActionCommand().equals(FiringCommand.FIRE_TWIST.getCmd())) {
twisting = true;
} else if (ev.getActionCommand().equals(TargetingCommand.FIRE_SKIP.getCmd())) {
nextWeapon();
} else if (ev.getActionCommand().equals(TargetingCommand.FIRE_NEXT.getCmd())) {
Expand Down Expand Up @@ -1414,6 +1523,10 @@ private void updateFlipArms(boolean armsFlipped) {
return;
}

twisting = false;

torsoTwist(null);

clearAttacks();
ce().setArmsFlipped(armsFlipped);
addAttack(new FlipArmsAction(cen, armsFlipped));
Expand All @@ -1434,6 +1547,11 @@ private void setFireEnabled(boolean enabled) {
clientgui.getMenuBar().setEnabled(FiringCommand.FIRE_FIRE.getCmd(), enabled);
}

protected void setTwistEnabled(boolean enabled) {
buttons.get(TargetingCommand.FIRE_TWIST).setEnabled(enabled);
clientgui.getMenuBar().setEnabled(FiringCommand.FIRE_TWIST.getCmd(), enabled);
}

private void setSkipEnabled(boolean enabled) {
buttons.get(TargetingCommand.FIRE_SKIP).setEnabled(enabled);
clientgui.getMenuBar().setEnabled(FiringCommand.FIRE_SKIP.getCmd(), enabled);
Expand Down
Loading