From 38dbb7fa92e2d31eca5abccbd79049c16a7435c6 Mon Sep 17 00:00:00 2001 From: James Daly Date: Fri, 14 Jun 2019 22:15:58 -0400 Subject: [PATCH] finished incorporating messaging into the UI window and added another custom control to make updating the UI easier --- FakeMon/src/fmon/Game.scala | 1 - FakeMon/src/fmon/battle/BattleEngine.scala | 2 +- FakeMon/src/fmon/battle/BattleUI.scala | 24 ++---- FakeMon/src/fmon/battle/InfoWidget.fxml | 38 +++++++++ FakeMon/src/fmon/battle/InfoWidget.scala | 30 +++++++ FakeMon/src/fmon/battle/battle.fxml | 66 +-------------- FakeMon/src/fmon/stat/Ability.scala | 5 +- FakeMon/src/fmon/stat/Monster.scala | 12 +-- FakeMon/src/fmon/stat/Move.scala | 2 +- FakeMon/src/fmon/stat/Status.scala | 30 +++---- FakeMon/src/fmon/stat/data/abilities.yaml | 15 ++-- FakeMon/src/fmon/stat/data/statuses.yaml | 97 ++++------------------ FakeMon/src/fmon/util/Fraction.scala | 2 + 13 files changed, 131 insertions(+), 193 deletions(-) create mode 100644 FakeMon/src/fmon/battle/InfoWidget.fxml create mode 100644 FakeMon/src/fmon/battle/InfoWidget.scala diff --git a/FakeMon/src/fmon/Game.scala b/FakeMon/src/fmon/Game.scala index d913120..e940abc 100644 --- a/FakeMon/src/fmon/Game.scala +++ b/FakeMon/src/fmon/Game.scala @@ -54,7 +54,6 @@ class Game extends Application { val party2 = new Party(p2, new MonsterPtr(Monster.generate("Wild Mon", p2, 500, form2, movepool2)), IndexedSeq( Monster.generate("Sideboard Mon", p2, 500, form2, movepool2) )) - println(form1.xpCurve) val engine = new BattleEngine(party1, party2) controller.setEngine(engine) diff --git a/FakeMon/src/fmon/battle/BattleEngine.scala b/FakeMon/src/fmon/battle/BattleEngine.scala index dddd789..454249b 100644 --- a/FakeMon/src/fmon/battle/BattleEngine.scala +++ b/FakeMon/src/fmon/battle/BattleEngine.scala @@ -43,7 +43,7 @@ class BattleEngine(val player: Party, val enemy: Party)(implicit val reader: Sig val replace = enemy.pollReplacement(player) enemy.switchIn(replace) } else { - println(s"${enemy.trainer} has lost!") + this ! Message(s"${enemy.trainer} has lost!") } } } diff --git a/FakeMon/src/fmon/battle/BattleUI.scala b/FakeMon/src/fmon/battle/BattleUI.scala index 67ac895..6aff388 100644 --- a/FakeMon/src/fmon/battle/BattleUI.scala +++ b/FakeMon/src/fmon/battle/BattleUI.scala @@ -15,17 +15,12 @@ import fmon.stat._ import fmon.stat.Statistic._ class BattleUI extends SignalConsumer { - @FXML var usName: jfxsc.Label = _ - @FXML var usLv: jfxsc.Label = _ - @FXML var usHealth: jfxsc.Label = _ - @FXML var usHealthBar: jfxsc.ProgressBar = _ - @FXML var themName: jfxsc.Label = _ - @FXML var themLv: jfxsc.Label = _ - @FXML var themHealth: jfxsc.Label = _ - @FXML var themHealthBar: jfxsc.ProgressBar = _ @FXML var buttonPane: javafx.scene.layout.VBox = _ @FXML var messages: jfxsc.TextArea = _ + @FXML var playerMonController: InfoWidget = _ + @FXML var enemyMonController: InfoWidget = _ + private var engine: BattleEngine = _ def setEngine(engine: BattleEngine): Unit = { @@ -35,19 +30,12 @@ class BattleUI extends SignalConsumer { def updateUI(): Unit = { val player = engine.player.lead - usName.text = player.name - usLv.text = s"Lv. ${player.level}" - usHealth.text = s"${player.hp}/${player.maxhp}" - usHealthBar.progress = player.hp.toDouble / player.maxhp - val enemy = engine.enemy.lead - themName.text = enemy.name - themLv.text = s"Lv. ${enemy.level}" - themHealth.text = s"${enemy.hp}/${enemy.maxhp}" - themHealthBar.progress = enemy.hp.toDouble / enemy.maxhp - val buttons = player.base.moves.map(move => loadMoveButton(move)) buttonPane.children = buttons + + playerMonController.update(player) + enemyMonController.update(enemy) } def onMove(move: Move): Unit = { diff --git a/FakeMon/src/fmon/battle/InfoWidget.fxml b/FakeMon/src/fmon/battle/InfoWidget.fxml new file mode 100644 index 0000000..06ddec5 --- /dev/null +++ b/FakeMon/src/fmon/battle/InfoWidget.fxml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/FakeMon/src/fmon/battle/InfoWidget.scala b/FakeMon/src/fmon/battle/InfoWidget.scala new file mode 100644 index 0000000..1e46c9b --- /dev/null +++ b/FakeMon/src/fmon/battle/InfoWidget.scala @@ -0,0 +1,30 @@ +package fmon.battle + +import javafx.fxml.FXML +import javafx.scene.{control => jfxsc} + +import scalafx.Includes._ +import scalafx.scene.control._ + +import fmon.stat.Monster +import fmon.stat._ + +class InfoWidget extends javafx.scene.layout.GridPane { + @FXML var name: jfxsc.Label = _ + @FXML var status: jfxsc.Label = _ + @FXML var health: jfxsc.Label = _ + @FXML var healthBar: jfxsc.ProgressBar = _ + + def update(mon: Monster): Unit = { + name.text = mon.name + mon.status match { + case Some(s) => status.text = s.name + case None => status.text = s"Lv. ${mon.level}" + } + + health.text = s"${mon.hp}/${mon.maxhp}" + val percent = mon.hp \\ mon.maxhp + healthBar.progress = percent.toDouble + // TODO : Change bar color + } +} \ No newline at end of file diff --git a/FakeMon/src/fmon/battle/battle.fxml b/FakeMon/src/fmon/battle/battle.fxml index e37421d..9bf7d70 100644 --- a/FakeMon/src/fmon/battle/battle.fxml +++ b/FakeMon/src/fmon/battle/battle.fxml @@ -1,21 +1,15 @@ - - - - - - @@ -75,70 +69,14 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -