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

attack tool tip update #4097

Merged
merged 5 commits into from
Jan 21, 2023
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
45 changes: 37 additions & 8 deletions megamek/src/megamek/client/ui/swing/boardview/AttackSprite.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@
import java.awt.Rectangle;
import java.awt.image.ImageObserver;
import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;

import megamek.client.ui.Messages;
import megamek.client.ui.swing.util.StraightArrowPolygon;
import megamek.common.Compute;
import megamek.common.Coords;
import megamek.common.Entity;
import megamek.common.Targetable;
import megamek.common.WeaponType;
import megamek.common.*;
import megamek.common.actions.AttackAction;
import megamek.common.actions.ChargeAttackAction;
import megamek.common.actions.ClubAttackAction;
Expand Down Expand Up @@ -60,6 +58,12 @@ class AttackSprite extends Sprite {

private final Targetable target;

private Coords aCoord;
private Coords tCoord;
private IdealHex aHex;
private IdealHex tHex;


public AttackSprite(BoardView boardView1, final AttackAction attack) {
super(boardView1);
this.boardView1 = boardView1;
Expand All @@ -68,6 +72,10 @@ public AttackSprite(BoardView boardView1, final AttackAction attack) {
targetId = attack.getTargetId();
ae = this.boardView1.game.getEntity(attack.getEntityId());
target = this.boardView1.game.getTarget(targetType, targetId);
aCoord = ae.getPosition();
tCoord = target.getPosition();
aHex = new IdealHex(aCoord);
tHex = new IdealHex(tCoord);

// color?
attackColor = ae.getOwner().getColour().getColour();
Expand Down Expand Up @@ -239,6 +247,12 @@ public boolean isInside(Point point) {
return attackPoly.contains(point.x - bounds.x, point.y - bounds.y);
}

public boolean isInside(Coords mcoords) {
IdealHex mHex = new IdealHex(mcoords);

return ((mHex.isIntersectedBy(aHex.cx, aHex.cy, tHex.cx, tHex.cy)) && (mcoords.between(aCoord, tCoord)));
}

public int getEntityId() {
return entityId;
}
Expand All @@ -255,8 +269,23 @@ public void addWeapon(WeaponAttackAction attack) {
final WeaponType wtype = (WeaponType) entity.getEquipment(
attack.getWeaponId()).getType();
final String roll = attack.toHit(this.boardView1.game).getValueAsString();
final String table = attack.toHit(this.boardView1.game).getTableDesc();
weaponDescs.add(wtype.getName() + Messages.getString("BoardView1.needs") + roll + " " + table);
String table = attack.toHit(this.boardView1.game).getTableDesc();
if (!table.isEmpty()) {
table = " " + table;
}
boolean b = false;
ListIterator<String> i = weaponDescs.listIterator();
while (i.hasNext()) {
String s = i.next();
if (s.contains(wtype.getName())) {
i.set(s + ", " + roll + table);
b = true;
}
}

if (!b) {
weaponDescs.add(wtype.getName() + Messages.getString("BoardView1.needs") + roll + table);
}
}

public void addWeapon(KickAttackAction attack) {
Expand Down Expand Up @@ -378,7 +407,7 @@ public StringBuffer getTooltip() {
tipString.append(Integer.toHexString(attackColor.getRGB() & 0xFFFFFF));
tipString.append(">");
tipString.append(attackerDesc
+ "<BR>&nbsp;&nbsp;" + Messages.getString("BoardView1.on") + " " + targetDesc);
+ "<BR>&nbsp;&nbsp;" + Messages.getString("BoardView1.on") + "&nbsp;&nbsp;" + targetDesc);
tipString.append("</FONT>");
for (String wpD: weaponDescs) {
tipString.append("<BR>"+wpD);
Expand Down
22 changes: 12 additions & 10 deletions megamek/src/megamek/client/ui/swing/boardview/BoardView.java
Original file line number Diff line number Diff line change
Expand Up @@ -5450,6 +5450,7 @@ public String getHexTooltip(MouseEvent e) {
Hex mhex = game.getBoard().getHex(mcoords);

StringBuffer txt = new StringBuffer(HTML_BEGIN);
txt.append("<div WIDTH=500>");
// Hex Terrain
if (GUIPreferences.getInstance().getShowMapHexPopup() && (mhex != null)) {
appendTerrainTooltip(txt, mhex);
Expand Down Expand Up @@ -5555,15 +5556,6 @@ public String getHexTooltip(MouseEvent e) {
}
}

// check if it's on any attacks
for (AttackSprite aSprite : attackSprites) {
if (aSprite.isInside(point)) {
txt.append("<TABLE BORDER=0 BGCOLOR=" + ALT_BGCOLOR + " width=100%><TR><TD><FONT color=\"black\">");
txt.append(aSprite.getTooltip().toString());
txt.append("</FONT></TD></TR></TABLE>");
}
}

// Add wreck info
var wreckList = useIsometric() ? isometricWreckSprites : wreckSprites;
for (var wSprite : wreckList) {
Expand Down Expand Up @@ -5601,6 +5593,15 @@ public String getHexTooltip(MouseEvent e) {
txt.append("</TD></TR></TABLE>");
}

// check if it's on any attacks
for (AttackSprite aSprite : attackSprites) {
if (aSprite.isInside(mcoords)) {
txt.append("<TABLE BORDER=0 BGCOLOR=" + ALT_BGCOLOR + " width=100%><TR><TD><FONT color=\"black\">");
txt.append(aSprite.getTooltip().toString());
txt.append("</FONT></TD></TR></TABLE>");
}
}

// Artillery attacks
for (ArtilleryAttackAction aaa : getArtilleryAttacksAtLocation(mcoords)) {
// Default texts if no real names can be found
Expand Down Expand Up @@ -5677,6 +5678,7 @@ public String getHexTooltip(MouseEvent e) {
}
}

txt.append("</div>");
txt.append(HTML_END);

// Check to see if the tool tip is completely empty
Expand Down Expand Up @@ -5850,7 +5852,7 @@ public void appendEntityTooltip(StringBuffer txt, @Nullable Entity entity) {
txt.append(" width=6></TD><TD>");

// Entity tooltip
txt.append("<div WIDTH=500>" + UnitToolTip.getEntityTipGame(entity, getLocalPlayer()) + "</div");
txt.append(UnitToolTip.getEntityTipGame(entity, getLocalPlayer()));
txt.append("</TD></TR></TABLE>");
}

Expand Down
8 changes: 8 additions & 0 deletions megamek/src/megamek/common/Coords.java
Original file line number Diff line number Diff line change
Expand Up @@ -520,4 +520,12 @@ public int getX() {
public int getY() {
return y;
}

/**
* return true if this is between s and e
* based on distance
*/
public boolean between(Coords s, Coords e) {
return (s.distance(e) == s.distance(this) + this.distance(e));
}
}