Commit 058cde8c authored by ceddral's avatar ceddral
Browse files

make Resize/Redraw scope player specific

should've committed this when i still knew why i did it
parent b5ec153a
......@@ -41,11 +41,14 @@ var (
nameWhitelist = regexp.MustCompile("[^"+nameWhitelistChars+"]")
)
type ContextPlayer interface {
Resize(int, int)
Redraw()
}
type Context interface {
Register(*Player)
Unregister(string)
Resize(int, int, *Player)
Redraw(*Player)
Lock()
Unlock()
}
......@@ -59,6 +62,7 @@ type Player struct {
windowSizeLoopKill chan struct{}
Name string
Context Context
ContextPlayer ContextPlayer
Scr *tg.Screen
}
......@@ -240,8 +244,8 @@ func (p *Player) windowSizeLoop() {
State.Lock()
p.Context.Lock()
p.Scr.Resize(w, h)
p.Context.Resize(w, h, p)
p.Context.Redraw(p)
p.ContextPlayer.Resize(w, h)
p.ContextPlayer.Redraw()
p.Context.Unlock()
State.Unlock()
}
......
......@@ -395,6 +395,7 @@ func (g *Game) Register(glp *common.Player) {
glp.Scr.Clear()
g.Lock()
p := g.Players[glp.Name]
glp.ContextPlayer = p
p.lostConnection = false
err := glp.Scr.Redraw()
if err != nil {
......@@ -431,14 +432,12 @@ func (g *Game) Unregister(Name string) {
}
}
func (g *Game) Resize(w, h int, glp *common.Player) {
p := g.Players[glp.Name]
func (p *GamePlayer) Resize(w, h int) {
p.menuv.Resize(min(30, w), h)
p.boardv.Resize(max(0, w-30), h)
}
func (g *Game) Redraw(glp *common.Player) {
p := g.Players[glp.Name]
func (p *GamePlayer) Redraw() {
p.InputEvent<-[]byte{byte(common.KeyRedraw)}
}
......
......@@ -63,7 +63,8 @@ func (l *Lobby) Register(glp *common.Player) {
l.Players[glp.Name] = p
l.playerOrder = append(l.playerOrder, p.Name)
l.agent = l.Players[l.playerOrder[0]]
l.Resize(glp.Scr.W, glp.Scr.H, glp)
glp.ContextPlayer = p
p.Resize(glp.Scr.W, glp.Scr.H)
go l.Loop(p)
l.Update()
l.Unlock()
......@@ -104,15 +105,13 @@ func (l *Lobby) unregisterUnlocked(Name string) {
l.Update()
}
func (l *Lobby) Resize(w, h int, glp *common.Player) {
p := l.Players[glp.Name]
func (p *Player) Resize(w, h int) {
p.playerListv.Reshape(0, 0, glPlayerListStatusColumnWidth + 1 + common.NameMaxLen, h - 2)
p.extensionListv.Reshape(p.playerListv.W + 2, 0, w, h - 2)
p.statusBarv.Reshape(0, h - 1, w, 1)
}
func (l *Lobby) Redraw(glp *common.Player) {
p := l.Players[glp.Name]
func (p *Player) Redraw() {
p.Event<-struct{}{}
}
......@@ -167,12 +166,12 @@ func (l *Lobby) Loop(p *Player) {
return
default:
}
p.Redraw(l)
p.DrawLobby(l)
p.Scr.Update()
}
}
func (p *Player) Redraw(l *Lobby) {
func (p *Player) DrawLobby(l *Lobby) {
line := 0
fg := tg.ColorDefault
bg := tg.ColorDefault
......@@ -180,11 +179,11 @@ func (p *Player) Redraw(l *Lobby) {
defer l.Unlock()
v := p.playerListv
v.Clear()
v.DrawTextClearLine(fg, bg, []byte(fmt.Sprintf("%*s %s", glPlayerListStatusColumnWidth, "", "Seats:")), 0, line)
v.DrawTextClearLine(fg, bg, []byte(fmt.Sprintf(" Seats:")), 0, line)
line++
for _, Name := range l.playerOrder {
for i, Name := range l.playerOrder {
status := "assigned"
v.DrawTextClearLine(fg, bg, []byte(fmt.Sprintf("%*s %s", glPlayerListStatusColumnWidth, status, Name)), 0, line)
v.DrawTextClearLine(fg, bg, []byte(fmt.Sprintf("%d. %*s %s", i, common.NameMaxLen, Name, status)), 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