
class PlayersList  < IGSList

  include PlayersMenu

  Sizes = [30,35,80,32,120,35,55,45,45,30,30]
#  Titles= ['','Rank','Name','','Info','Idle','Country','Won','Lost','Obs','Play']

  attr_reader :names

  def initialize(parent)

    super(parent,5,5)

    set_title PlayerEntry.new(@titlebar,0,0,nil,Sizes,TkDefaults::Titlebar['Players'])

    @userinfos = []
    @names = {}
    menu_init
  end

  def newgame(name,nb)

    return if @updating
    if @names.has_key?(name)
      @names[name].set_game(nb)
    end
  end

  def endgame(name,nb)

    return if @updating
    if @names.has_key?(name)
      @names[name].set_game(nil)
    end
  end

  def del_user(name)
    return if @updating
    if @names.has_key?(name)
      @names[name].set_disabled
    end
  end


  def add ( userinf)
    @userinfos.push(userinf)
  end

  def  push (userinf)
    user = PlayerEntry.new(@canvas,0,@posy,userinf,Sizes){ |x,y| popup(x,y,userinf) }
    @names[userinf.name]= user
    add_entry(user)

  end

  def insert (userinf)
    return if @updating
    @userinfos.push userinf
    push userinf
  end

  def begin_update
    clear
    @userinfos = []
    @names = {}
  end

  def end_update
    @updating=true
    @userinfos.sort.each {|ui | push ui}
    refresh
    @updating=false
  end

end


