dofile('Data/Scripts/Common/Screens/ProfilesScreenBase.lua')

class 'ProfilesScreen' (ProfilesScreenBase)

function ProfilesScreen:__init(name)
	ProfilesScreenBase.__init(self, name)

	self.listbox_offset   = Vector2f(0, 40)
end
--------------------------------------------------------------------------------

function ProfilesScreen:createButtonName(name, position)
	local button = CreateButtonEntity('')
	button:attachTo( self:getMainEntity() )
	button:setName(name)
	button:setXY(position.x, position.y)
	button:setOrder(50)
	button:getOverlayTextEntity():setText(name)
	button:getOverlayTextEntity():setFont( 'Data/Fonts/tool_tip.fnt' ) 
	button:setActiveRectSize(350, 40)
	button.onPress:add(bind(self.onActiveButtonClick, self))
	
	return button
end
--------------------------------------------------------------------------------

function ProfilesScreen:createListBox()
	local vecProfiles = ProfilesManager:getProfiles()
	local position  = Vector2f(512, 314)
	local offset    = Vector2f(0, 32)
	
	-- Удаление всех игроков, если они были созданы до этого.
	if self.players then
		for _, bttn in pairs(self.players) do
			bttn:destroy()    
		end
	end
	self.players = {}

	for i = 0, vecProfiles:size() - 1 do
		local profile = vecProfiles:get(i)
		
		local bttn = self:createButtonName(profile.name, position)
		table.insert(self.players, bttn)
		position = position + offset
	end
	
	self:updateActivePlayers()
end

function ProfilesScreen:onDeleteButtonClick()
	self:onScreenDestroy()

	local screen = createYesNoScreen('QUESTION_DELETE_PROFILE', playerDeleteConfirm, playerDeleteDiscard, false, 0, YES_NO_SCREEN_DELETE_PLAYER_HEADER)
end

--------------------------------------------------------------------------------
--                      GENERATED CONTENT. DO NOT EDIT.                       --
--------------------------------------------------------------------------------

function ProfilesScreen:CreateLoaderTable()
	local objects =
	{
		{ name = 'Profiles',  entityType = 'SpriteEntity',  x = 512,  y = 384,  order = 10,  editingLocked = false,  treeItemIsExpanded = true,  hotSpot = {x = 268, y = 221},  texturePath = 'Data/Textures/Screens/Profiles/Profiles.png',  width = 530,  height = 450,  },
		{ name = 'bttn_ok',  entityType = 'ButtonEntity',  parentName = 'Profiles',  x = -128,  y = 170,  order = 2,  editingLocked = false,  treeItemIsExpanded = true,  texturePath = 'Data/Textures/GUI/Buttons/bttn_ok.png',  text = '',  },
		{ name = 'bttn_new',  entityType = 'ButtonEntity',  parentName = 'Profiles',  x = 0,  y = 170,  order = 2,  editingLocked = false,  treeItemIsExpanded = true,  texturePath = 'Data/Textures/GUI/Buttons/bttn_new.png',  text = '',  },
		{ name = 'bttn_delete',  entityType = 'ButtonEntity',  parentName = 'Profiles',  x = 128,  y = 170,  order = 2,  editingLocked = false,  treeItemIsExpanded = false,  texturePath = 'Data/Textures/GUI/Buttons/bttn_delete.png',  text = '',  },
		{ name = 'select',  entityType = 'SpriteEntity',  x = 181,  y = 39,  order = 18,  editingLocked = false,  treeItemIsExpanded = false,  texturePath = 'Data/Textures/Screens/Profiles/select.png',  width = 430,  height = 30,  },
	}
	return objects
end
