Skip to content

Commit

Permalink
#2119 Fix reinit of player overview table
Browse files Browse the repository at this point in the history
  • Loading branch information
wsbrenk committed Nov 3, 2024
1 parent f579c45 commit f2771fb
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/main/java/core/gui/model/UserColumnFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -581,14 +581,14 @@ public IHOTableEntry getTableEntry(Player player, Player playerCompare) {
byte idealPosition = player.getIdealPosition();
String posValue = String.format("%s (%.2f)",
MatchRoleID.getNameForPosition(idealPosition),
player.getIdealPositionRating());
player.getPositionRating(idealPosition));
if ( player.isAnAlternativeBestPosition(idealPosition) ) {
posValue += " *";
}

ColorLabelEntry tmp = new ColorLabelEntry(
-MatchRoleID.getSortId(idealPosition, false)
+ (player.getIdealPositionRating() / 100.0f),
+ (player.getPositionRating(idealPosition) / 100.0f),
posValue,
ColorLabelEntry.FG_STANDARD,
ColorLabelEntry.BG_STANDARD, SwingConstants.LEFT);
Expand Down
26 changes: 16 additions & 10 deletions src/main/java/core/model/player/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.*;

import static core.constants.player.PlayerSkill.*;
import static core.model.player.IMatchRoleID.aPositionBehaviours;
import static core.model.player.MatchRoleID.getPosition;
import static core.model.player.MatchRoleID.isFieldMatchRoleId;
import static java.lang.Integer.MAX_VALUE;
Expand All @@ -33,7 +34,7 @@

public class Player extends AbstractTable.Storable {

private byte idealPos = IMatchRoleID.UNKNOWN;
private byte calculatedBestPosition = IMatchRoleID.UNKNOWN;

private static final PlayerSkill[] trainingSkills = {STAMINA, KEEPER, SETPIECES, DEFENDING, SCORING, WINGER, PASSING, PLAYMAKING};
private static final String BREAK = "[br]";
Expand Down Expand Up @@ -845,21 +846,26 @@ public MatchLineupPosition getIdealMatchLineupPosition() {
public byte getIdealPosition() {
//in case player best position is forced by user
final int flag = getUserPosFlag();

if (flag == IMatchRoleID.UNKNOWN) {
if (idealPos == IMatchRoleID.UNKNOWN) {
var matchLineupPosition = getIdealMatchLineupPosition();
idealPos = getPosition(matchLineupPosition.getRoleId(), matchLineupPosition.getBehaviour());
}
return idealPos;
return getCalculatedBestPosition();
}

return (byte) flag;
}

public byte getCalculatedBestPosition() {
if (calculatedBestPosition == IMatchRoleID.UNKNOWN) {
var matchLineupPosition = getIdealMatchLineupPosition();
calculatedBestPosition = getPosition(matchLineupPosition.getRoleId(), matchLineupPosition.getBehaviour());
}
return calculatedBestPosition;
}

public double getPositionRating(byte position) {
var ratingPredictionModel = HOVerwaltung.instance().getModel().getRatingPredictionModel();
return ratingPredictionModel.getPlayerMatchAverageRating(this, position);
if ( aPositionBehaviours.contains((int)position)) {
var ratingPredictionModel = HOVerwaltung.instance().getModel().getRatingPredictionModel();
return ratingPredictionModel.getPlayerMatchAverageRating(this, position);
}
return 0;
}

private Map<Integer, Integer> wagesHistory = null; // age->wage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ private void setLabels() {
m_jlSeasonSeriesGoals.setText(String.valueOf(m_clPlayer.getLeagueGoals()));
m_jlSeasonCupGoals.setText(String.valueOf(m_clPlayer.getCupGameGoals()));

var bestPosition = m_clPlayer.getIdealPosition();
var bestPosition = m_clPlayer.getCalculatedBestPosition();
m_jlBestPosition.setText(MatchRoleID.getNameForPosition(bestPosition)
+ " ("
+ Helper.getNumberFormat(false, core.model.UserParameter.instance().nbDecimals).format(
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
### Squad

* Calculation of the tsi sub by approximating the tsi formula (#235)
* Fix display of best position rating (#2166)

### Team Analyzer
* Fix illegal argument exception in team rating panel (#2155)
Expand Down

0 comments on commit f2771fb

Please sign in to comment.