class 'l_ProfilesScreen' (BaseScreen)

ProfilesScreen = nil;
local listbox = nil;
------------------------------------------------------------------------------
function l_ProfilesScreen:__init(name, screen)
	BaseScreen.__init(self, name, screen)

    -- create buttons
    self:CreateButtonByName('New',    KEY_INSERT)
    self:CreateButtonByName('Ok',     KEY_ENTER)
    self:CreateButtonByName('Delete', KEY_DELETE)
	
	-- create listbox
	do
	    listbox = self:CreateListBox('LP')
	    listbox:SetSelectSprite( self:GetObject('select'):GetAnimation() )
	    listbox:SetFont(PLAYER_LIST_FONT)
	    listbox:SetTextOffsetY(-6)
	    listbox:SetXY(512, 350)
	    listbox:SetDisplaySelectionUnderText(true)
	    self:UpdatePlayers()
	end
	
	ProfilesScreen = screen
end

function l_ProfilesScreen:OnUpdate(dt)
end

function l_ProfilesScreen:OnAllItemsFound()
end

function l_ProfilesScreen:OnObjectMouseEnter(object)
end

function l_ProfilesScreen:OnObjectMouseLeave(object)
end

function l_ProfilesScreen:OnScreenObjectMouseDown(object)
end

function l_ProfilesScreen:OnObjectMouseDownProcessed(is_wrong_click)
end

function l_ProfilesScreen:OnObjectMouseUp(object)
end

function l_ProfilesScreen:OnObjectFound(object)
end

function l_ProfilesScreen:OnToolFound(tool)
end

function l_ProfilesScreen:OnToolApply(tool, object)
end

function l_ProfilesScreen:OnObjectReachPanel(object)
end

function l_ProfilesScreen:OnButtonPress(title)
end

function l_ProfilesScreen:OnMouseMove(previous_pos, current_pos)
end

function l_ProfilesScreen:OnSetTool(tool)
end

function l_ProfilesScreen:OnLoaded()
end

function l_ProfilesScreen:OnDestroy()
end

function l_ProfilesScreen:UpdatePlayers()
    if listbox then
        listbox:RemoveAllItems()
        
        local vecUsers   = GM:GetPlayers()
        local iSizeUser  = vecUsers:size()
        local currPlayer = GM:GetCurrPlayer()
        
        for i = 0, iSizeUser - 1 do
            local player = vecUsers:get(i)
            listbox:AddItem(player.name, i)
            
            if currPlayer then
                if currPlayer.name == player.name then
                    listbox:SetSelectedPos(i)
                end
            elseif i == 0 then
                listbox:SetSelectedPos(i)
                GM:SetCurrPlayer(player.name)
            end
        end
    end
end

function l_ProfilesScreen:OnListboxClicked(name, text)
    local selectedName = listbox:GetSelectedName()
    GM:SetCurrPlayer(selectedName)
end
--------------------------------------------------------------------------------

function CreateProfilesScreen()
    local screen = CreateScriptedScreen('data/Scripts/screens/ProfilesScreen.lua', 'l_ProfilesScreen');
    PopUpScreensMgr:Push(screen, false, nil);
end
--------------------------------------------------------------------------------

function l_ProfilesScreen:OnNewButtonClick()
    if GM:GetProfilesCount() >= MAX_PROFILES then
        CreateOKScreen(GetString('MAX_PROFILES'), nil, true)
        return
    end
    CreateInputNameScreen(true)
end
--------------------------------------------------------------------------------

function l_ProfilesScreen:OnOkButtonClick()
    PopUpScreensMgr:Pop()
    ProfilesScreen = nil
end
--------------------------------------------------------------------------------

function l_ProfilesScreen:OnDeleteButtonClick()
    playerDeleteScreen = CreateYesNoScreen("QUESTION_DELETE_PROFILE",
                                           "PlayerDeleteConfirm",
                                           "PlayerDeleteDiscard", true)
end
--------------------------------------------------------------------------------

function PlayerDeleteConfirm()
    local selectedName = listbox:GetSelectedName()
    
    if selectedName ~= '' then
        GM:DeletePlayer(selectedName)
        ProfilesScreen:GetAssociatedLuaObject():UpdatePlayers()

        if GM:GetProfilesCount() == 0 then
            CreateInputNameScreen(true)
        end
    end
end
--------------------------------------------------------------------------------

function PlayerDeleteDiscard()
end
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
-- CLEAR_ON_SAVE_BEGIN
-- Do not edit code listed below (generated by the editor on each save)
function l_ProfilesScreen:LoadData(screen)
	local anim
	anim = CreateAnimation('data/Texture/GUI/Profiles/ProfilesBackground.png',0,0,498,482,1,0)
	anim:SetHotSpot(249,241)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('ProfilesBackground',anim,512,384,100,0,1,1)
	
	anim = CreateAnimation('data/Texture/GUI/Profiles/select.png',0,0,430,35,1,0)
	anim:SetHotSpot(215,17)
	anim:SetBlendMode(2)
	anim:SetColor('0x00FFFFFF')
	screen:CreateObject('select',anim,423,74,120,0,1,1)
	
	anim = CreateAnimation('data/Texture/GUI/Buttons/bttn_new.png',0,0,162,104,3,0)
	anim:SetHotSpot(81,52)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('bttn_new',anim,362,600,120,0,1,1)
	
	anim = CreateAnimation('data/Texture/GUI/Buttons/bttn_delete.png',0,0,162,104,3,0)
	anim:SetHotSpot(81,52)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('bttn_delete',anim,662,600,120,0,1,1)
	
	anim = CreateAnimation('data/Texture/GUI/Buttons/bttn_ok.png',0,0,162,104,3,0)
	anim:SetHotSpot(81,52)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('bttn_ok',anim,512,600,120,0,1,1)
	
end
-- CLEAR_ON_SAVE_END
