diff --git a/engine/screens/inventory.go b/engine/screens/inventory.go index b586c2c..b5e4685 100644 --- a/engine/screens/inventory.go +++ b/engine/screens/inventory.go @@ -31,11 +31,12 @@ type displayItem struct { type preparedList []displayItem func (p *preparedList) Prepare(is *InventoryScreen) { + //fixme add item class sorting - //fixme text instead of list to rpint and use printinside() + bp := items.Controller.GetComponent(is.who, ecs.BackpackComponent).(items.Backpack) is.prepared = make([]displayItem, len(bp.GetItems())) - //todo prepare item list + //prepare item list for i, ent := range bp.GetItems() { namec := items.Controller.GetComponent(ent, ecs.Named{}.Type()).(ecs.Named) is.prepared[i] = displayItem{ @@ -75,6 +76,36 @@ func (is *InventoryScreen) HandleInput(input string) { return } switch input { + case "Up": + is.cursor = is.cursor - 1 + if is.cursor < 0 { + is.cursor = 0 + } + if is.cursor < is.offset { + is.offset = is.offset - 1 + if is.offset < 0 { + is.offset = 0 + } + } + break + case "Down": + is.cursor = is.cursor + 1 + if is.cursor >= len(is.prepared) { + is.cursor = len(is.prepared) - 1 + } + if is.cursor > is.offset { + is.offset = is.offset + 1 + if is.offset*is.pageSize > len(is.prepared) { + is.offset = len(is.prepared) / is.pageSize + } + } + break + case "Left": + is.prepared[is.cursor].Selected = false + break + case "Right": + is.prepared[is.cursor].Selected = true + break case "PageUp": is.offset = is.offset - 1 if is.offset < 0 { @@ -114,12 +145,13 @@ func (is *InventoryScreen) InventoryRender() { _, headerHeight := menuLayer.PrintInside(is.Rect, is.header, blt.TK_ALIGN_LEFT) itemField := types.Rect{is.X, is.Y + headerHeight + 1, is.W, is.H - headerHeight - footerHeight} _ = itemField + is.pageSize = itemField.H - 2 if (len(is.prepared) > 0) { for i := is.offset; i < itemField.H; i++ { if i < len(is.prepared) { - selectedColor := "blue" + selectedColor := "white" selectedDash := "-" if is.prepared[i].Selected { selectedColor = "green"