cursor update

This commit is contained in:
thefish 2019-11-19 22:15:02 +03:00
parent d167e5eae4
commit bf13c9c7a2

View File

@ -31,11 +31,12 @@ type displayItem struct {
type preparedList []displayItem type preparedList []displayItem
func (p *preparedList) Prepare(is *InventoryScreen) { func (p *preparedList) Prepare(is *InventoryScreen) {
//fixme add item class sorting //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) bp := items.Controller.GetComponent(is.who, ecs.BackpackComponent).(items.Backpack)
is.prepared = make([]displayItem, len(bp.GetItems())) is.prepared = make([]displayItem, len(bp.GetItems()))
//todo prepare item list //prepare item list
for i, ent := range bp.GetItems() { for i, ent := range bp.GetItems() {
namec := items.Controller.GetComponent(ent, ecs.Named{}.Type()).(ecs.Named) namec := items.Controller.GetComponent(ent, ecs.Named{}.Type()).(ecs.Named)
is.prepared[i] = displayItem{ is.prepared[i] = displayItem{
@ -75,6 +76,36 @@ func (is *InventoryScreen) HandleInput(input string) {
return return
} }
switch input { 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": case "PageUp":
is.offset = is.offset - 1 is.offset = is.offset - 1
if is.offset < 0 { if is.offset < 0 {
@ -114,12 +145,13 @@ func (is *InventoryScreen) InventoryRender() {
_, headerHeight := menuLayer.PrintInside(is.Rect, is.header, blt.TK_ALIGN_LEFT) _, 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 := types.Rect{is.X, is.Y + headerHeight + 1, is.W, is.H - headerHeight - footerHeight}
_ = itemField _ = itemField
is.pageSize = itemField.H - 2
if (len(is.prepared) > 0) { if (len(is.prepared) > 0) {
for i := is.offset; i < itemField.H; i++ { for i := is.offset; i < itemField.H; i++ {
if i < len(is.prepared) { if i < len(is.prepared) {
selectedColor := "blue" selectedColor := "white"
selectedDash := "-" selectedDash := "-"
if is.prepared[i].Selected { if is.prepared[i].Selected {
selectedColor = "green" selectedColor = "green"