Floating chat messages and remote server
This commit is contained in:
20
game/chat.go
20
game/chat.go
@ -23,6 +23,7 @@ type Chat struct {
|
||||
isTyping bool
|
||||
cursorPos int
|
||||
scrollOffset int
|
||||
userData interface{}
|
||||
}
|
||||
|
||||
func NewChat() *Chat {
|
||||
@ -61,6 +62,25 @@ func (c *Chat) HandleServerMessages(messages []*pb.ChatMessage) {
|
||||
c.messages = c.messages[1:]
|
||||
}
|
||||
c.messages = append(c.messages, localMsg)
|
||||
|
||||
// Add floating message to the player
|
||||
if game, ok := c.userData.(*Game); ok {
|
||||
if msg.PlayerId == game.Player.ID {
|
||||
game.Player.Lock()
|
||||
game.Player.FloatingMessage = &types.FloatingMessage{
|
||||
Content: msg.Content,
|
||||
ExpireTime: time.Now().Add(6 * time.Second),
|
||||
}
|
||||
game.Player.Unlock()
|
||||
} else if otherPlayer, exists := game.OtherPlayers[msg.PlayerId]; exists {
|
||||
otherPlayer.Lock()
|
||||
otherPlayer.FloatingMessage = &types.FloatingMessage{
|
||||
Content: msg.Content,
|
||||
ExpireTime: time.Now().Add(6 * time.Second),
|
||||
}
|
||||
otherPlayer.Unlock()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user