
class Chat
  def initialize (player,title=nil)
    @player=player
    if @player.to_i != 0
      $igsClient.send("yell \\#@player")
      title = "Chat in channel #@player"
    elsif title.nil?
      title = "Chat with #@player"
    end

    @top= GoWindow.new(self)
    @top.title(title)
    @top.protocol('WM_DELETE_WINDOW', proc{ quit })


        #@top.help_menu.add('command','label'=>'The chat window','command'=>proc { TkHtml.new("file://#{$current_path}/../help/manual.html#chat") })

    if notes= Defaults::NOTES[player] and notes['image']
      TkLabel.new(@top, 'image'=>Defaults::HEADS[notes['image']]).pack('side'=>'left','expand'=>'no')
    end
    @talk = Dialog.new(@top,'Chat' ).pack('fill' =>'both','expand'=>'yes')
    cmd=CmdLine.new(@top, proc { |msg| send_message(msg)})
    cmd.pack('fill' =>'x','expand'=>'no')
    cmd.focus
  end

  def quit
    close
    if @player.to_i != 0
      $igsClient.send('yell \-1')
    end
    $chatobserver.delete( @player)
  end

  def close
        # TkDefaults.save_top_options(self,@top)
    @top.destroy
  end
  def raise
    @top.raise
  end

  def send_message(msg)
    @talk.putline(msg + "\n", 'user_cmd')
    if @player.to_i != 0
      $igsClient.send( "yell \\#@player  #{msg}")
    else
      $igsClient.send( "tell #@player #{msg}")
    end
  end

  def rec_message(line,tag=nil)
    @talk.putline(line + "\n",tag)
    Tk.update
    playsound('ding.wav')
  end

end




