can open an inventory view

master
Jordan Orelli 4 years ago
parent 49659ce876
commit 0346e619e4

@ -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) { func (c *containerView) draw(img canvas, st *state) {
bounds := img.bounds() bounds := img.bounds()

@ -40,6 +40,8 @@ func (v *gameView) walkHandler(e *tcell.EventKey) change {
return move{0, 1} return move{0, 1}
case 'd': case 'd':
return move{1, 0} return move{1, 0}
case 'i':
return openInventory{}
case 'l': case 'l':
v.keyHandler = v.lookHandler v.keyHandler = v.lookHandler
v.statusLine = "(look)" v.statusLine = "(look)"

@ -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)
}
}

@ -10,6 +10,7 @@ type state struct {
playerName string playerName string
room *wire.Room room *wire.Room
history []sim.ChatMessage history []sim.ChatMessage
inventory inventory
detail view detail view
} }

Loading…
Cancel
Save