Skip to content

Commit

Permalink
refactor ButtonContainer
Browse files Browse the repository at this point in the history
  • Loading branch information
adamtomi committed Nov 30, 2022
1 parent 0cadeee commit 305c999
Showing 1 changed file with 7 additions and 16 deletions.
23 changes: 7 additions & 16 deletions src/main/java/com/vamk/tbg/ui/ButtonContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,6 @@ private void onGameReady(GameReadySignal signal) {
add(movePanel);
}

private void onEntityPlays(EntityPlaysSignal signal) {
tick();
updateButtonsFor(signal.getEntity());
if (signal.isUserControlled()) enableMoveButtons();
else disableMoveButtons();
}

private void onEntityDeath(EntityDeathSignal signal) {
Entity entity = signal.getEntity();
JButton button = this.entityButtons.remove(entity.getId());
Expand All @@ -93,22 +86,20 @@ private void onEntityDeath(EntityDeathSignal signal) {
button.setEnabled(false);
}

public void updateButtonsFor(Entity entity) {
private void onEntityPlays(EntityPlaysSignal signal) {
tick();
this.moveButtons.forEach(x -> x.setEnabled(signal.isUserControlled()));
updateButtonsFor(signal.getEntity());
}

private void updateButtonsFor(Entity entity) {
for (int i = 0; i < this.moveButtons.size(); i++) {
JButton button = this.moveButtons.get(i);
Move move = entity.getMoves().get(i);
button.setText(move.getId());
}
}

public void enableMoveButtons() {
this.moveButtons.forEach(btn -> btn.setEnabled(true));
}

public void disableMoveButtons() {
this.moveButtons.forEach(btn -> btn.setEnabled(false));
}

@Override
public void tick() {
this.moveIdx = 3;
Expand Down

0 comments on commit 305c999

Please sign in to comment.