From 305c9993253c252d89123a029f24ec2a2f7e706d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20=C3=81d=C3=A1m?= Date: Wed, 30 Nov 2022 11:10:17 +0200 Subject: [PATCH] refactor ButtonContainer --- .../java/com/vamk/tbg/ui/ButtonContainer.java | 23 ++++++------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/vamk/tbg/ui/ButtonContainer.java b/src/main/java/com/vamk/tbg/ui/ButtonContainer.java index 344d270..e8a3077 100644 --- a/src/main/java/com/vamk/tbg/ui/ButtonContainer.java +++ b/src/main/java/com/vamk/tbg/ui/ButtonContainer.java @@ -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()); @@ -93,7 +86,13 @@ 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); @@ -101,14 +100,6 @@ public void updateButtonsFor(Entity entity) { } } - 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;