-
Notifications
You must be signed in to change notification settings - Fork 399
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
Add damage and icon for bombing target selection #2339
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
import java.awt.BorderLayout; | ||
import java.awt.Color; | ||
import java.awt.Component; | ||
import java.awt.Dimension; | ||
import java.awt.FlowLayout; | ||
import java.awt.Font; | ||
|
@@ -60,12 +61,14 @@ | |
import javax.swing.JTextArea; | ||
import javax.swing.JToggleButton; | ||
import javax.swing.JToolTip; | ||
import javax.swing.ListCellRenderer; | ||
import javax.swing.ListSelectionModel; | ||
import javax.swing.Popup; | ||
import javax.swing.PopupFactory; | ||
import javax.swing.SwingConstants; | ||
import javax.swing.SwingUtilities; | ||
import javax.swing.WindowConstants; | ||
import javax.swing.border.EmptyBorder; | ||
import javax.swing.border.EtchedBorder; | ||
import javax.swing.tree.DefaultMutableTreeNode; | ||
import javax.swing.tree.TreeNode; | ||
|
@@ -112,6 +115,7 @@ | |
import games.strategy.thread.ThreadPool; | ||
import games.strategy.triplea.Properties; | ||
import games.strategy.triplea.TripleAPlayer; | ||
import games.strategy.triplea.TripleAUnit; | ||
import games.strategy.triplea.ai.proAI.ProAI; | ||
import games.strategy.triplea.attachments.AbstractConditionsAttachment; | ||
import games.strategy.triplea.attachments.AbstractTriggerAttachment; | ||
|
@@ -904,6 +908,7 @@ public Unit getStrategicBombingRaidTarget(final Territory territory, final Colle | |
final JList<Unit> list = new JList<>(new Vector<>(potentialTargets)); | ||
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); | ||
list.setSelectedIndex(0); | ||
list.setCellRenderer(new UnitRenderer()); | ||
final JPanel panel = new JPanel(); | ||
panel.setLayout(new BorderLayout()); | ||
if (bombers != null) { | ||
|
@@ -924,6 +929,37 @@ public Unit getStrategicBombingRaidTarget(final Territory territory, final Colle | |
return selected.get(); | ||
} | ||
|
||
@SuppressWarnings("serial") | ||
class UnitRenderer extends JLabel implements ListCellRenderer<Unit> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This class is only used within There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed to private |
||
|
||
public UnitRenderer() { | ||
setOpaque(true); | ||
} | ||
|
||
@Override | ||
public Component getListCellRendererComponent(final JList<? extends Unit> list, final Unit unit, final int index, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A quick comment here might be good, summarize that we are building a dialog with the unit image next to name. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added comment to class |
||
final boolean isSelected, final boolean cellHasFocus) { | ||
|
||
setText(unit.toString() + ", damage=" + TripleAUnit.get(unit).getUnitDamage()); | ||
final Optional<ImageIcon> icon = uiContext.getUnitImageFactory().getIcon(unit.getType(), unit.getOwner(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. very minor, you can write the optional + if statement in one statement:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Gonna leave it on separate lines as I think its a little easier to read |
||
Matches.unitHasTakenSomeBombingUnitDamage().match(unit), Matches.unitIsDisabled().match(unit)); | ||
if (icon.isPresent()) { | ||
setIcon(icon.get()); | ||
} | ||
setBorder(new EmptyBorder(0, 0, 0, 10)); | ||
|
||
if (isSelected) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't fully understand why we are setting foreground/background colors. Likely not terribly important, though a comment here may help to capture that context. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added comment |
||
setBackground(list.getSelectionBackground()); | ||
setForeground(list.getSelectionForeground()); | ||
} else { | ||
setBackground(list.getBackground()); | ||
setForeground(list.getForeground()); | ||
} | ||
|
||
return this; | ||
} | ||
} | ||
|
||
public int[] selectFixedDice(final int numDice, final int hitAt, final boolean hitOnlyIfEquals, final String title, | ||
final int diceSides) { | ||
if (messageAndDialogThreadPool == null) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should have eclipse generate a serialVersionUID for you instead of supressing this warning
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done