Skip to content

Commit 07c5f05

Browse files
author
Adam Arold
committed
Add help and examine dialogs
1 parent 8ad9f45 commit 07c5f05

6 files changed

Lines changed: 105 additions & 2 deletions

File tree

src/main/kotlin/org/hexworks/cavesofzircon/systems/InputReceiver.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ import org.hexworks.cavesofzircon.commands.MoveUp
1010
import org.hexworks.cavesofzircon.commands.PickItemUp
1111
import org.hexworks.cavesofzircon.extensions.GameEntity
1212
import org.hexworks.cavesofzircon.extensions.position
13+
import org.hexworks.cavesofzircon.view.dialog.HelpDialog
1314
import org.hexworks.cavesofzircon.world.GameContext
1415
import org.hexworks.cobalt.logging.api.LoggerFactory
1516
import org.hexworks.zircon.api.data.impl.Position3D
17+
import org.hexworks.zircon.api.screen.Screen
1618
import org.hexworks.zircon.api.uievent.KeyCode
1719
import org.hexworks.zircon.api.uievent.KeyboardEvent
1820

@@ -33,6 +35,7 @@ object InputReceiver : BaseBehavior<GameContext>() {
3335
KeyCode.KEY_F -> player.moveDown(context)
3436
KeyCode.KEY_P -> player.pickItemUp(currentPos, context)
3537
KeyCode.KEY_I -> player.inspectInventory(currentPos, context)
38+
KeyCode.KEY_H -> showHelp(context.screen)
3639
else -> {
3740
logger.debug("UI Event ($uiEvent) does not have a corresponding command, it is ignored.")
3841
}
@@ -45,6 +48,10 @@ object InputReceiver : BaseBehavior<GameContext>() {
4548
executeCommand(InspectInventory(context, this, position))
4649
}
4750

51+
private fun showHelp(screen: Screen) {
52+
screen.openModal(HelpDialog(screen))
53+
}
54+
4855
private fun GameEntity<Player>.pickItemUp(position: Position3D, context: GameContext) {
4956
executeCommand(PickItemUp(context, this, position))
5057
}

src/main/kotlin/org/hexworks/cavesofzircon/systems/InventoryInspector.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import org.hexworks.cavesofzircon.commands.InspectInventory
1616
import org.hexworks.cavesofzircon.extensions.GameCommand
1717
import org.hexworks.cavesofzircon.extensions.GameItem
1818
import org.hexworks.cavesofzircon.extensions.whenTypeIs
19+
import org.hexworks.cavesofzircon.view.dialog.ExamineDialog
1920
import org.hexworks.cavesofzircon.view.fragment.InventoryFragment
2021
import org.hexworks.cavesofzircon.world.GameContext
2122
import org.hexworks.cobalt.datatypes.Maybe
@@ -30,7 +31,7 @@ import org.hexworks.zircon.internal.component.modal.EmptyModalResult
3031

3132
object InventoryInspector : BaseFacet<GameContext>() {
3233

33-
val DIALOG_SIZE = Sizes.create(33, 14)
34+
val DIALOG_SIZE = Sizes.create(40, 14)
3435

3536
override fun executeCommand(command: GameCommand<out EntityType>) = command
3637
.responseWhenCommandIs(InspectInventory::class) { (context, itemHolder, position) ->
@@ -43,6 +44,9 @@ object InventoryInspector : BaseFacet<GameContext>() {
4344
onDrop = { item ->
4445
itemHolder.executeCommand(DropItem(context, itemHolder, item, position))
4546
},
47+
onExamine = { item ->
48+
screen.openModal(ExamineDialog(screen, item))
49+
},
4650
onEat = { item ->
4751
itemHolder.whenTypeIs<EnergyUser> { eater ->
4852
item.whenTypeIs<Food> { food ->
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package org.hexworks.cavesofzircon.view.dialog
2+
3+
import org.hexworks.cavesofzircon.attributes.types.iconTile
4+
import org.hexworks.cavesofzircon.extensions.GameItem
5+
import org.hexworks.zircon.api.Components
6+
import org.hexworks.zircon.api.GraphicalTilesetResources
7+
import org.hexworks.zircon.api.graphics.BoxType
8+
import org.hexworks.zircon.api.screen.Screen
9+
10+
class ExamineDialog(screen: Screen, item: GameItem) : Dialog(screen) {
11+
12+
override val container = Components.panel()
13+
.withTitle("Examining ${item.name}")
14+
.withSize(25, 15)
15+
.withBoxType(BoxType.TOP_BOTTOM_DOUBLE)
16+
.wrapWithBox()
17+
.build().apply {
18+
addComponent(Components.textBox()
19+
.withContentWidth(23)
20+
.addHeader("Name", withNewLine = false)
21+
.addInlineComponent(Components.icon()
22+
.withIcon(item.iconTile)
23+
.withTileset(GraphicalTilesetResources.nethack16x16())
24+
.build())
25+
.addInlineComponent(Components.label()
26+
.withText(" ${item.name}")
27+
.build())
28+
.commitInlineElements()
29+
.addNewLine()
30+
.addHeader("Description", withNewLine = false)
31+
.addParagraph(item.description, withNewLine = false))
32+
}
33+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package org.hexworks.cavesofzircon.view.dialog
2+
3+
import org.hexworks.zircon.api.Components
4+
import org.hexworks.zircon.api.graphics.BoxType
5+
import org.hexworks.zircon.api.screen.Screen
6+
7+
class HelpDialog(screen: Screen) : Dialog(screen) {
8+
9+
override val container = Components.panel()
10+
.withTitle("Help")
11+
.withSize(44, 27)
12+
.withBoxType(BoxType.TOP_BOTTOM_DOUBLE)
13+
.wrapWithBox()
14+
.build().apply {
15+
addComponent(Components.textBox()
16+
.withContentWidth(42)
17+
.addNewLine()
18+
.addHeader("Caves of Zircon")
19+
.addParagraph("""
20+
Descend to the Caves Of Zircon and collect as many Zircons as you can.
21+
Find the exit (+) to win the game. Use what you find to avoid dying.""".trimIndent())
22+
.addNewLine())
23+
24+
addComponent(Components.textBox()
25+
.withContentWidth(27)
26+
.withPosition(0, 8)
27+
.addHeader("Movement:")
28+
.addListItem("wasd: Movement")
29+
.addListItem("r: Move up")
30+
.addListItem("f: Move down"))
31+
32+
addComponent(Components.textBox()
33+
.withContentWidth(40)
34+
.withPosition(0, 16)
35+
.addHeader("Navigation:")
36+
.addListItem("[Tab]: Focus next")
37+
.addListItem("[Shift] + [Tab]: Focus previous")
38+
.addListItem("[Space]: Activate focused item"))
39+
40+
addComponent(Components.textBox()
41+
.withContentWidth(21)
42+
.withPosition(28, 8)
43+
.addHeader("Actions:")
44+
.addListItem("(i)nventory")
45+
.addListItem("(p)ick up")
46+
.addListItem("(h)elp"))
47+
}
48+
}

src/main/kotlin/org/hexworks/cavesofzircon/view/fragment/InventoryFragment.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ class InventoryFragment(inventory: Inventory,
1616
width: Int,
1717
private val onDrop: (GameItem) -> Unit,
1818
private val onEat: (GameItem) -> Unit,
19-
private val onEquip: (GameItem) -> Maybe<GameItem>) : Fragment {
19+
private val onEquip: (GameItem) -> Maybe<GameItem>,
20+
private val onExamine: (GameItem) -> Unit) : Fragment {
2021

2122
override val root = Components.vbox()
2223
.withSize(width, inventory.size + 1)
@@ -42,6 +43,10 @@ class InventoryFragment(inventory: Inventory,
4243
onDrop(item)
4344
Processed
4445
}
46+
examineButton.onComponentEvent(ACTIVATED) {
47+
onExamine(item)
48+
Processed
49+
}
4550
eatButton.onComponentEvent(ACTIVATED) {
4651
list.removeComponent(this.root)
4752
onEat(item)

src/main/kotlin/org/hexworks/cavesofzircon/view/fragment/InventoryRowFragment.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ class InventoryRowFragment(width: Int, item: GameItem) : Fragment {
2525
.withText("Equip")
2626
.build()
2727

28+
val examineButton = Components.button()
29+
.wrapSides(false)
30+
.withText("Examine")
31+
.build()
32+
2833
override val root = Components.hbox()
2934
.withSpacing(1)
3035
.withSize(width, 1)
@@ -35,6 +40,7 @@ class InventoryRowFragment(width: Int, item: GameItem) : Fragment {
3540
.withSize(InventoryFragment.NAME_COLUMN_WIDTH, 1)
3641
.withText(item.name))
3742
addComponent(dropButton)
43+
addComponent(examineButton)
3844
item.whenTypeIs<Food> {
3945
addComponent(eatButton)
4046
}

0 commit comments

Comments
 (0)