adding a status bar, to be removed hopefullyyyyy

master
Jordan Orelli 4 years ago
parent ca5ccbf7c9
commit 3f6f825c4c

@ -55,3 +55,11 @@ func (b *buffer) blit(s tcell.Screen, offset math.Vec) {
} }
} }
} }
func (b *buffer) fill(style tcell.Style) {
for x := 0; x < b.width; x++ {
for y := 0; y < b.height; y++ {
b.set(x, y, tile{r: ' ', style: style})
}
}
}

@ -0,0 +1,25 @@
package app
import (
"fmt"
"github.com/gdamore/tcell/v2"
"github.com/jordanorelli/astro-domu/internal/math"
)
type statusBar struct {
inFocus bool
ui *UI
}
func (s *statusBar) handleEvent(ui *UI, e tcell.Event) bool { return false }
func (s *statusBar) draw(b *buffer) {
if s.ui == nil {
return
}
line := fmt.Sprintf("shown: %08d cleared: %08d", s.ui.showCount, s.ui.clearCount)
b.writeString(line, math.Vec{0, 0}, tcell.StyleDefault)
}
func (s *statusBar) setFocus(enabled bool) { s.inFocus = enabled }

@ -17,10 +17,13 @@ type UI struct {
screen tcell.Screen screen tcell.Screen
room *wire.Room room *wire.Room
client *wire.Client client *wire.Client
showCount int
clearCount int
gameView *gameView statusBar *statusBar
chatView *chatView gameView *gameView
focussed view chatView *chatView
focussed view
} }
func (ui *UI) Run() { func (ui *UI) Run() {
@ -61,6 +64,9 @@ func (ui *UI) Run() {
Log: ui.Child("chat-view"), Log: ui.Child("chat-view"),
history: make([]sim.ChatMessage, 0, 32), history: make([]sim.ChatMessage, 0, 32),
} }
ui.statusBar = &statusBar{
ui: ui,
}
ui.focussed = ui.gameView ui.focussed = ui.gameView
ui.Info("running ui") ui.Info("running ui")
@ -109,6 +115,7 @@ func (ui *UI) setupTerminal() {
} }
func (ui *UI) clearTerminal() { func (ui *UI) clearTerminal() {
ui.clearCount++
ui.screen.Clear() ui.screen.Clear()
ui.screen.Fini() ui.screen.Fini()
} }
@ -123,6 +130,7 @@ func (ui *UI) handleNotifications(c <-chan wire.Response) {
} }
ui.Info("notifications channel is closed so we must be done") ui.Info("notifications channel is closed so we must be done")
ui.Info("clearing and finalizing screen from notifications goroutine") ui.Info("clearing and finalizing screen from notifications goroutine")
ui.clearCount++
ui.screen.Clear() ui.screen.Clear()
ui.screen.Fini() ui.screen.Fini()
ui.Info("screen finalized") ui.Info("screen finalized")
@ -173,6 +181,7 @@ func (ui *UI) writeString(x, y int, s string, style tcell.Style) {
} }
func (ui *UI) handleUserInput() bool { func (ui *UI) handleUserInput() bool {
ui.clearCount++
ui.screen.Clear() ui.screen.Clear()
ui.render() ui.render()
@ -206,8 +215,10 @@ func (ui *UI) handleUserInput() bool {
} }
ui.focussed.handleEvent(ui, e) ui.focussed.handleEvent(ui, e)
ui.clearCount++
ui.screen.Clear() ui.screen.Clear()
ui.render() ui.render()
ui.showCount++
ui.screen.Show() ui.screen.Show()
HANDLED: HANDLED:
} }
@ -217,16 +228,24 @@ func (ui *UI) render() {
width, height := ui.screen.Size() width, height := ui.screen.Size()
{ {
b := newBuffer(width/2, height/2) b := newBuffer(width, 1)
ui.gameView.draw(b) ui.statusBar.draw(b)
b.blit(ui.screen, math.Vec{0, 0}) b.blit(ui.screen, math.Vec{0, 0})
} }
gameViewHeight := math.Max((height-1)/2, 8)
{
b := newBuffer(width/2, gameViewHeight)
ui.gameView.draw(b)
b.blit(ui.screen, math.Vec{0, 1})
}
{ {
b := newBuffer(width, height/2) b := newBuffer(width, height-gameViewHeight-1)
ui.chatView.draw(b) ui.chatView.draw(b)
b.blit(ui.screen, math.Vec{0, height / 2}) b.blit(ui.screen, math.Vec{0, gameViewHeight + 1})
} }
ui.showCount++
ui.screen.Show() ui.screen.Show()
} }

Loading…
Cancel
Save