117 lines
2.8 KiB
Go
117 lines
2.8 KiB
Go
package screens
|
|
|
|
import (
|
|
"lab.zaar.be/thefish/alchemyst-go/engine/types"
|
|
"lab.zaar.be/thefish/alchemyst-go/ui/mainwindow"
|
|
blt "lab.zaar.be/thefish/bearlibterminal"
|
|
"strings"
|
|
)
|
|
|
|
const runeIndex = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
|
|
type MenuScreen struct {
|
|
*types.Rect
|
|
|
|
mw *mainwindow.MainWindow
|
|
scm *types.ScreenManager
|
|
renderParent bool
|
|
|
|
items []interface{}
|
|
title string
|
|
header string
|
|
footer string
|
|
redraw bool
|
|
bgColor string
|
|
fgColor string
|
|
}
|
|
|
|
func NewMenuScreen(mw *mainwindow.MainWindow, scm *types.ScreenManager, title, header, footer string, rect *types.Rect, renderParent bool) *MenuScreen {
|
|
return &MenuScreen{
|
|
title: title,
|
|
header: header,
|
|
footer: footer,
|
|
Rect: rect,
|
|
mw: mw,
|
|
scm: scm,
|
|
renderParent: renderParent,
|
|
}
|
|
}
|
|
|
|
func (ms *MenuScreen) SetBgColor(color string) *MenuScreen {
|
|
ms.bgColor = color
|
|
return ms
|
|
}
|
|
|
|
func (ms *MenuScreen) SetFgColor(color string) *MenuScreen {
|
|
ms.fgColor = color
|
|
return ms
|
|
}
|
|
|
|
//fixme!!
|
|
|
|
func (ms *MenuScreen) SetItems(items []interface{}) *MenuScreen {
|
|
ms.items = items
|
|
return ms
|
|
}
|
|
|
|
func (ms *MenuScreen) UseEcs() bool { return false }
|
|
|
|
func (ms *MenuScreen) Enter() {
|
|
ms.redraw = true
|
|
}
|
|
|
|
func (ms *MenuScreen) HandleInput(input string) {
|
|
//
|
|
//if input != "" {
|
|
// ms.redraw = true
|
|
//}
|
|
|
|
switch input {
|
|
case "Space":
|
|
ms.scm.SetScreen(ms.scm.PreviousScreen)
|
|
break
|
|
}
|
|
}
|
|
|
|
func (ms *MenuScreen) Exit() {
|
|
menuLayer := ms.mw.GetLayer("menu")
|
|
menuLayer.ClearRect(ms.Rect)
|
|
bgLayer := ms.mw.GetLayer("menubg")
|
|
bgLayer.ClearRect(ms.Rect)
|
|
}
|
|
|
|
func (ms *MenuScreen) Render() {
|
|
if ms.renderParent {
|
|
ms.scm.PreviousScreen.Render()
|
|
}
|
|
if (ms.redraw || ms.renderParent) {
|
|
ms.redraw = false
|
|
menuLayer := ms.mw.GetLayer("menu")
|
|
menuLayer.ClearRect(ms.Rect)
|
|
bgLayer := ms.mw.GetLayer("menubg")
|
|
bgLayer.ClearRect(ms.Rect)
|
|
bgLayer.WithColor(ms.bgColor).NewWindow(ms.Rect).Splash()
|
|
menuLayer.WithColor(ms.fgColor).NewWindow(ms.Rect).DoubleBordered(ms.title)
|
|
menuLayer.Print(ms.X+(ms.W/2)-7, ms.Y+ms.H-1, "╡"+"[color=green]Space[/color] to close"+"╞")
|
|
footerHeight := 0
|
|
if ms.footer != "" {
|
|
_, footerHeight = menuLayer.PrintInside(ms.Rect, ms.footer, 9)
|
|
footerHeight = footerHeight + 2
|
|
}
|
|
_, headerHeight := menuLayer.PrintInside(ms.Rect, ms.header, blt.TK_ALIGN_LEFT)
|
|
itemField := types.Rect{ms.X, ms.Y + headerHeight + 1, ms.W, ms.H - headerHeight - footerHeight}
|
|
_ = itemField
|
|
if (len(ms.items) > 0) {
|
|
//fixme itemfield object, scroller, inputhandler, current selected item
|
|
menuItems := make([]string, 0)
|
|
for i, _ := range ms.items {
|
|
if string(ms.items[i].(string)) != "" {
|
|
menuItems = append(menuItems, ms.items[i].(string))
|
|
}
|
|
}
|
|
menuLayer.PrintInside(&itemField, strings.Join(menuItems, "\n"), blt.TK_ALIGN_LEFT)
|
|
|
|
}
|
|
}
|
|
}
|