last_light/game/ui/ui_event_logger.go

63 lines
1.2 KiB
Go
Raw Normal View History

2024-05-30 23:39:54 +03:00
package ui
import (
"mvvasilev/last_light/engine"
2024-06-06 23:17:22 +03:00
"mvvasilev/last_light/game/systems"
2024-05-30 23:39:54 +03:00
"github.com/gdamore/tcell/v2"
"github.com/gdamore/tcell/v2/views"
"github.com/google/uuid"
)
type UIEventLog struct {
id uuid.UUID
eventLogger *engine.GameEventLog
window *UIWindow
style tcell.Style
}
func CreateUIEventLog(x, y, width, height int, eventLogger *engine.GameEventLog, style tcell.Style) *UIEventLog {
return &UIEventLog{
id: uuid.New(),
eventLogger: eventLogger,
window: CreateWindow(x, y, width, height, "", style),
style: style,
}
}
func (uie *UIEventLog) MoveTo(x int, y int) {
uie.window.MoveTo(x, y)
}
func (uie *UIEventLog) Position() engine.Position {
return uie.window.Position()
}
func (uie *UIEventLog) Size() engine.Size {
return uie.window.Size()
}
2024-06-06 23:17:22 +03:00
func (uie *UIEventLog) Input(inputAction systems.InputAction) {
2024-05-30 23:39:54 +03:00
}
func (uie *UIEventLog) UniqueId() uuid.UUID {
return uie.id
}
func (uie *UIEventLog) Draw(v views.View) {
uie.window.Draw(v)
x, y := uie.Position().XY()
height := uie.Size().Height()
textHeight := height - 2
for i, ge := range uie.eventLogger.Tail(textHeight) {
engine.DrawText(x+1, y+i+1, ge.Contents(), uie.style, v)
}
}