Skip to content

Commit

Permalink
ho-dev#2229 ReInit player overview table
Browse files Browse the repository at this point in the history
  • Loading branch information
wsbrenk committed Jan 17, 2025
1 parent 3d76ebd commit d942474
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions src/main/java/module/training/ui/PlayerDetailPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import core.constants.player.PlayerAbility;
import core.constants.player.PlayerSkill;
import core.gui.RefreshManager;
import core.gui.comp.entry.ColorLabelEntry;
import core.gui.comp.panel.ImagePanel;
import core.gui.comp.panel.LazyImagePanel;
Expand Down Expand Up @@ -66,8 +67,7 @@ protected void initialize() {
@Override
protected void update() {
if ( m_jtaNotes.isFocusOwner() ){
// Notes could be changed
saveNotes(m_jtaNotes.getText());
stopEdit();
}
loadFromModel();
}
Expand Down Expand Up @@ -274,12 +274,12 @@ else if ( i == 0){
m_jtaNotes.addFocusListener(new FocusListener() {
@Override
public void focusGained(FocusEvent e) {
editingPlayer = model.getActivePlayer();
startEdit(model.getActivePlayer());
}

@Override
public void focusLost(FocusEvent e) {
editingPlayer = null;
stopEdit();
}
});

Expand All @@ -301,6 +301,20 @@ public void focusLost(FocusEvent e) {
add(dummyPanelToConsumeAllExtraSpace, maingbc);
}

private void startEdit(Player activePlayer) {
if (this.editingPlayer!=null) {
stopEdit();
}
this.editingPlayer = activePlayer;
}

private void stopEdit() {
if (this.editingPlayer != null){
saveNotes(m_jtaNotes.getText());
this.editingPlayer = null;
}
}

private void selectTraining(ActionEvent e, PlayerSkill skillIndex) {
var player = this.model.getActivePlayer();
if (player != null) {
Expand All @@ -324,8 +338,9 @@ private void selectTraining(ActionEvent e, PlayerSkill skillIndex) {
}

private void saveNotes(String notes) {
if( editingPlayer!= null && !notes.equals(editingPlayer.getNote())){
editingPlayer.setNote(m_jtaNotes.getText());
if(editingPlayer!= null && !notes.equals(editingPlayer.getNote())){
editingPlayer.setNote(notes);
RefreshManager.instance().doReInit();
}
}
}
}

0 comments on commit d942474

Please sign in to comment.