diff --git a/internal/app/container_view.go b/internal/app/container_view.go index 8d69ca9..ade17e5 100644 --- a/internal/app/container_view.go +++ b/internal/app/container_view.go @@ -50,6 +50,23 @@ func (c *containerView) nextFocus() { } } +func (c *containerView) focus(n int) { + if c.focussed == n { + return + } + + cur := c.children[c.focussed] + if v, ok := cur.view.(focusable); ok { + v.setFocus(false) + } + + c.focussed = n + cur = c.children[c.focussed] + if v, ok := cur.view.(focusable); ok { + v.setFocus(true) + } +} + func (c *containerView) draw(img canvas, st *state) { bounds := img.bounds() diff --git a/internal/app/game_view.go b/internal/app/game_view.go index 8023a06..d78ddbd 100644 --- a/internal/app/game_view.go +++ b/internal/app/game_view.go @@ -40,6 +40,8 @@ func (v *gameView) walkHandler(e *tcell.EventKey) change { return move{0, 1} case 'd': return move{1, 0} + case 'i': + return openInventory{} case 'l': v.keyHandler = v.lookHandler v.statusLine = "(look)" diff --git a/internal/app/inventory.go b/internal/app/inventory.go new file mode 100644 index 0000000..87f07f5 --- /dev/null +++ b/internal/app/inventory.go @@ -0,0 +1,34 @@ +package app + +import ( + "github.com/gdamore/tcell/v2" + "github.com/jordanorelli/astro-domu/internal/math" +) + +type inventory struct { + items []item +} + +type item struct { + name string +} + +type inventoryView struct { +} + +func (v *inventoryView) handleEvent(e tcell.Event) change { + return nil +} + +func (v *inventoryView) draw(img canvas, st *state) { + writeString(img, "Inventory", math.Vec{0, 0}, tcell.StyleDefault) +} + +type openInventory struct{} + +func (openInventory) exec(ui *UI) { + if ui.root == inGameView { + ui.state.detail = &inventoryView{} + inGameView.focus(1) + } +} diff --git a/internal/app/state.go b/internal/app/state.go index 9025a53..9eb32ad 100644 --- a/internal/app/state.go +++ b/internal/app/state.go @@ -10,6 +10,7 @@ type state struct { playerName string room *wire.Room history []sim.ChatMessage + inventory inventory detail view }