-
Notifications
You must be signed in to change notification settings - Fork 432
Fix13580 select in battle calculator #13587
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
base: main
Are you sure you want to change the base?
Fix13580 select in battle calculator #13587
Conversation
BattleCalculatorPanel.java - new member comboListenerEnabled - Constructor: Add ItemListener for comboBoxes; For swapSidesButton ensure new defender units are for defense
Mainly comments added BattleCalculatorPanel.java - new member comboListenerEnabled renamed to determineUnitsOnComboSelectionChange - methods setAttackerWithUnits/ setDefenderWithUnits: Limit determineUnitsOnComboSelectionChange to set-method for new GamePlayer
| @Nullable private final Territory battleSiteTerritory; | ||
| private final JList<String> territoryEffectsJList; | ||
| private final TuvCostsCalculator tuvCalculator = new TuvCostsCalculator(); | ||
| private boolean determineUnitsOnComboSelectionChange = true; |
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.
What's the rationale behind this variable and its purpose?
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.
It is to determine the units displayed when the combo selection changes, i.e., the user has change the attacking or defending player in one of the top combo field.
I thought I finally found a good name for it -.-
|
Did a git bisect to 2046ca7 to find when this problem started. Doing a selective revert of the offending code is this diff, it looks like this patch would solve the issue: I suggest we first do a surgical update to get us back to baseline functionality. Then, consider any future changes (which helps mitigate risk in case those updates have issues. It's a bad situation when fixes contain new problems) |
I recall that there was an issue with the switch concerning the unit types did not switch as well properly, leaving extra icons. When I see this old code you found, I think it is odd as the listener would be called every time (also during initial setup or other buttons that affect the combo button). That's why I introduced variable swapSidesButton.addActionListener(
e -> {
attackerOrderOfLosses = null;
defenderOrderOfLosses = null;
final GamePlayer newAttacker = getDefender();
final List<Unit> newAttackerUnits =
CollectionUtils.getMatches(
defendingUnitsPanel.getUnits(),
Matches.unitIsOwnedBy(getDefender())
.and(
Matches.unitCanBeInBattle(
true,
isLandBattle(),
1,
hasMaxRounds(isLandBattle(), data),
true,
List.of())));
final GamePlayer newDefender = getAttacker();
final List<Unit> newDefenderUnits =
CollectionUtils.getMatches(
attackingUnitsPanel.getUnits(),
Matches.unitCanBeInBattle(false, isLandBattle(), 1, true));
setAttackerWithUnits(newAttacker, newAttackerUnits);
setDefenderWithUnits(newDefender, newDefenderUnits);
setWidgetActivation();
});All in all, I still thing the PR makes sense the way it is. |
DanVanAtta
left a comment
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.
The determineUnitsOnComboSelectionChange gives me a lot of pause. I'd like to do that in a cleaner way (or at least with some polish if we really can't clean it up).
First though, what concrete fixes are achieving? I think we should step back and look at the high level objective, there might be an easier approach.
Should fix issue 13580 (Can´t select opponent in battle calculator)
Notes to Reviewer
BattleCalculatorPanel.java
Rest: Comments added