From ad1518e6a9dd7d197b95d407072d9f4efe9f94df Mon Sep 17 00:00:00 2001 From: Julian Date: Sun, 29 Oct 2023 16:07:35 +0100 Subject: [PATCH] display hero cost --- src/main/scala/uicomponents.scala | 8 +++++--- src/main/scala/view.scala | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/scala/uicomponents.scala b/src/main/scala/uicomponents.scala index ebeedd4..cd75e81 100644 --- a/src/main/scala/uicomponents.scala +++ b/src/main/scala/uicomponents.scala @@ -4,6 +4,7 @@ import rescala.default._ import miniscribe.data.{Force, Warband} import scalatags.JsDom._ import scalatags.JsDom.all._ +import miniscribe.data.given trait UIComponent: def render: HtmlTag @@ -19,10 +20,11 @@ object UIComponent: // things that change the UI state val toggled: Signal[Map[ID, Boolean]] = Events.foldAll(Map.WithDefault(Map.empty[ID, Boolean], _ => false)) { acc => + // everything that can toggle a menu Seq( - // toggle button presses + // button presses toggleMenuEvt act2 (id => acc.updated(id, !acc(id))), - // force removals + // removal of a force collapses the associated menu armyEvents.deleteForce act2 (forceName => acc.updated(forceName, false)) ) } @@ -81,6 +83,6 @@ case class WarbandComponent( warband: Warband ) extends UIComponent: def render: HtmlTag = div( - h3(warband.hero.flatMap(_.model.map(_.name))), + h3(warband.hero.flatMap(h => h.model.map(m => s"${m.name} (${h.cost})"))), warband.troops.map(_.name) ) diff --git a/src/main/scala/view.scala b/src/main/scala/view.scala index f50f0e7..d2f0a6a 100644 --- a/src/main/scala/view.scala +++ b/src/main/scala/view.scala @@ -14,7 +14,7 @@ class toggleMenu(label: String, content: Signal[TypedTag[Element]]): val toggle: Evt[String] = Evt() println(s"menu $label created") private val visible: Signal[Boolean] = - this.toggle.fold(true)((vis, _) => !vis) + this.toggle.fold(false)((vis, _) => !vis) private val toggleButton = Events.fromCallback[UIEvent](cb => Signal.dynamic {