Commit 86d51d5b authored by ceddral's avatar ceddral
Browse files

gamelobby: split into views

playerlist, extensionlist and statusbar to show keymappings
parent 03dcc67c
......@@ -3,12 +3,19 @@ package main
import (
tg "fahrradwurstmond2.0/telnet_gui"
"sync"
"fmt"
)
const (
glPlayerListStatusColumnWidth = 8
)
type GameLobbyPlayer struct {
name string
scr *tg.Screen
lobbyv *tg.View
playerListv *tg.View
extensionListv *tg.View
statusBarv *tg.View
lobbyKill chan struct{}
lobbyEvent chan struct{}
inputEvent chan []byte
......@@ -44,7 +51,9 @@ func (gl *GameLobby) Register(glp *Player) {
p := &GameLobbyPlayer{
name: glp.name,
scr: glp.scr,
lobbyv: tg.NewView(glp.scr, 0, 0, glp.scr.W, glp.scr.H),
playerListv: tg.NewViewEmpty(glp.scr),
extensionListv: tg.NewViewEmpty(glp.scr),
statusBarv: tg.NewViewEmpty(glp.scr),
lobbyKill: make(chan struct{}, 1),
lobbyEvent: make(chan struct{}, 50),
inputEvent: glp.inputEvent,
......@@ -52,6 +61,7 @@ func (gl *GameLobby) Register(glp *Player) {
gl.players[glp.name] = p
gl.playerOrder = append(gl.playerOrder, p.name)
gl.agent = gl.players[gl.playerOrder[0]]
gl.Resize(glp.scr.W, glp.scr.H, glp)
go gl.Loop(p)
gl.Update()
gl.Unlock()
......@@ -94,7 +104,9 @@ func (gl *GameLobby) unregisterUnlocked(name string) {
func (gl *GameLobby) Resize(w, h int, glp *Player) {
p := gl.players[glp.name]
p.lobbyv.Resize(w, h)
p.playerListv.Reshape(0, 0, glPlayerListStatusColumnWidth + 1 + nameMaxLen, h - 2)
p.extensionListv.Reshape(p.playerListv.W + 2, 0, w, h - 2)
p.statusBarv.Reshape(0, h - 1, w, 1)
}
func (gl *GameLobby) Redraw(glp *Player) {
......@@ -159,15 +171,18 @@ func (gl *GameLobby) Loop(p *GameLobbyPlayer) {
}
func (p *GameLobbyPlayer) Redraw(gl *GameLobby) {
gl.Lock()
defer gl.Unlock()
v := p.lobbyv
v.Clear()
line := 0
fg := tg.ColorDefault
bg := tg.ColorDefault
gl.Lock()
defer gl.Unlock()
v := p.playerListv
v.Clear()
v.DrawTextClearLine(fg, bg, []byte(fmt.Sprintf("%*s %s", glPlayerListStatusColumnWidth, "", "Seats:")), 0, line)
line++
for _, name := range gl.playerOrder {
v.DrawTextClearLine(fg, bg, []byte(name), 0, line)
status := "assigned"
v.DrawTextClearLine(fg, bg, []byte(fmt.Sprintf("%*s %s", glPlayerListStatusColumnWidth, status, name)), 0, line)
line++
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment