100 lines
		
	
	
		
			2.5 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			100 lines
		
	
	
		
			2.5 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package screens
 | |
| 
 | |
| import (
 | |
| 	"lab.zaar.be/thefish/alchemyst-go/engine/ecs"
 | |
| 	"lab.zaar.be/thefish/alchemyst-go/engine/types"
 | |
| 	"strings"
 | |
| )
 | |
| 
 | |
| type InventoryScreen struct {
 | |
| 	*MenuScreen
 | |
| 	items []ecs.Entity
 | |
| 	
 | |
| 	cursor int
 | |
| 	offset int
 | |
| 	pageSize int
 | |
| }
 | |
| 
 | |
| func (is *InventoryScreen) MakeInverntory() *InventoryScreen {
 | |
| 	is.drawFunc = is.InventoryRender
 | |
| 	is.inputFunc = is.HandleInput
 | |
| 	return is
 | |
| }
 | |
| 
 | |
| func (is *InventoryScreen) SetItems(items []ecs.Entity) *InventoryScreen {
 | |
| 	is.items = items
 | |
| 	return is
 | |
| }
 | |
| 
 | |
| func (is *InventoryScreen) HandleInput(input string) {
 | |
| 	switch input {
 | |
| 	case "PageUp":
 | |
| 		is.offset = is.offset - 1
 | |
| 		if is.offset < 0 {
 | |
| 			is.offset = 0
 | |
| 		}
 | |
| 		break
 | |
| 	case "PageDown":
 | |
| 		is.offset = is.offset + 1
 | |
| 		if is.offset > len(is.items)-1 {
 | |
| 			is.offset = len(is.items) - 1
 | |
| 		}
 | |
| 		break
 | |
| 	case "enter":
 | |
| 		//select current under cursor
 | |
| 		break;
 | |
| 	case "a","b","c","d","e","f","g","h","i","j","k","l":
 | |
| 		//selct by letter
 | |
| 		break;
 | |
| 	case "Escape":
 | |
| 		fallthrough
 | |
| 	case "Space":
 | |
| 		is.scm.SetScreen(is.scm.PreviousScreen)
 | |
| 		break
 | |
| 	}
 | |
| }
 | |
| 
 | |
| 
 | |
| 
 | |
| func (is *InventoryScreen) InventoryRender() {
 | |
| 	menuLayer := is.mw.GetLayer("menu")
 | |
| 	menuLayer.ClearRect(is.Rect)
 | |
| 	bgLayer := is.mw.GetLayer("menubg")
 | |
| 	bgLayer.ClearRect(is.Rect)
 | |
| 	bgLayer.WithColor(is.bgColor).NewWindow(is.Rect).Splash()
 | |
| 	menuLayer.WithColor(is.fgColor).NewWindow(is.Rect).DoubleBordered(is.title)
 | |
| 	menuLayer.Print(is.X+(is.W/2)-7, is.Y+is.H-1, "╡"+"[color=green]Space[/color] to close"+"╞")
 | |
| 	footerHeight := 0
 | |
| 	if is.footer != "" {
 | |
| 		_, footerHeight = menuLayer.PrintInside(is.Rect, is.footer, 9)
 | |
| 		footerHeight = footerHeight + 2
 | |
| 	}
 | |
| 	_, 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
 | |
| 	var ilw, ilh int
 | |
| 	if (len(is.items) > 0) {
 | |
| 		//fixme itemfield object, scroller, inputhandler, current selected item
 | |
| 		menuItems := make([]string, 0)
 | |
| 		for i := is.offset; i < len(is.items); i++ {
 | |
| 			if string(is.items[i].(string)) != "" {
 | |
| 				menuItems = append(menuItems, is.items[i].(string))
 | |
| 			}
 | |
| 		}
 | |
| 		ilw, ilh = menuLayer.PrintInside(itemField, strings.Join(menuItems, "\n"), blt.TK_ALIGN_LEFT)
 | |
| 	}
 | |
| 	if ilh < len(is.items) {
 | |
| 		is.drawScrollBar(menuLayer, itemField)
 | |
| 	}
 | |
| 	if ilw > itemField.W-4 {
 | |
| 		fmt.Printf("Excess width of item names found! Need h-scroll of certain names")
 | |
| 	}
 | |
| }
 | |
| 
 | |
| 
 | |
| //func (ms *InventoryScreen) UseEcs() bool {return true}
 | |
| //func (ms *InventoryScreen) Enter()       {}
 | |
| 
 | |
| //func (ms *InventoryScreen) Exit()   {}
 | |
| //func (ms *InventoryScreen) Render() {}
 |