
class PlayerEntry < IGSEntry

  @@head_align= 'w'

  attr_reader   :userinfo

  def initialize(canvas,x1,y1, userinfo, sizes, titles= nil, &cb)

    @userinfo= userinfo
    @sizes = sizes
    @callback= cb

    @name= userinfo.nil? ? nil : userinfo.name 

    super(canvas,x1,y1, @name, sizes, titles)

    if @rect
      $tk_cb['pe'+@rect.to_s]= cb
      $ip._eval("#{@canvas.path} bind #@rect <Button-3> {ruby {tk_callback( '#{'pe'+@rect}', %X, %Y)}}")
    end 
  end

  def entry_callback(x,y)
    @callback.call(x,y,@userinfo)
  end

  def init

    return unless  @userinfo

    notes= Defaults::NOTES[@userinfo.name]
    if notes and notes['image']
      head= Defaults::HEADS[notes['image']]

    end

    case  @userinfo.game
    when '!'
      add_bitmap Defaults::ICONS['looking'],  @sizes[0]
    when 'X'
      add_bitmap Defaults::ICONS['no_match'], @sizes[0]
    when '?'
      add_bitmap Defaults::ICONS['unknown'], @sizes[0]
    else
      add_blank  @sizes[0]
    end

    add_text  @userinfo.rank,  @sizes[1]
    add_text  @userinfo.name,  @sizes[2]


    if  head
      add_bitmap head, @sizes[3], @@head_align
      @@head_align= (@@head_align == 'w' ? 'e' : 'w')
    else
      add_blank @sizes[3]
      @@head_align = 'w'
    end
    if  @userinfo.info.include?(?{)
      add_blank @sizes[4]
    else
      add_text  @userinfo.info,  @sizes[4] 
    end

    add_text  @userinfo.idle,  @sizes[5]
    add_text  @userinfo.country,  @sizes[6]
    add_text  @userinfo.won,  @sizes[7]
    add_text  @userinfo.lost,  @sizes[8]
    add_text  @userinfo.observing,  @sizes[9]
    @game_nb= add_text  @userinfo.playing,  @sizes[10], '-fill blue'


  end

  def set_game(nb)

    if nb
      set_text(@game_nb, nb.to_s)
    else
      set_text(@game_nb,'')
    end
    @userinfo.playing= nb
  end


end
