-------------------------------------------------------------------------------
class 'EntityInfoScreen' (Node)
-------------------------------------------------------------------------------

-------------------------------------------------------------------------------
local SHOW_OPACITY = 1
local HIDE_OPACITY = 0.2
-------------------------------------------------------------------------------

-------------------------------------------------------------------------------
function EntityInfoScreen:__init(editScreen)   
    Node.__init(self, editScreen:getMainEntity(), 'EntityInfoScreen', 2000)  
    self.editScreen = editScreen

    self:loadData(self) 
    self:initScreen()  
    self:setEventHandlers()
end
-------------------------------------------------------------------------------

-------------------------------------------------------------------------------
function EntityInfoScreen:loadData()
    if self.CreateLoaderTable then
        local table_resource = self:CreateLoaderTable()
        LoadScene(self.main_entity, table_resource)
    end 
end
-------------------------------------------------------------------------------

-------------------------------------------------------------------------------
function EntityInfoScreen:initScreen()
    self.prevMousePos = {}

    self:getEntityNamed('window_border'):setOpacity(HIDE_OPACITY)
    self:getEntityNamed('window_border'):setX(960)
end  
-------------------------------------------------------------------------------

-------------------------------------------------------------------------------
function EntityInfoScreen:setEventHandlers()
    self.main_entity.onUpdate:add( bind(self.updateScreen, self) )

    self:getEntityNamed('window_border').onFocusIn:add( bind(self.setBorderOpacity, self, SHOW_OPACITY) )
    self:getEntityNamed('window_border').onFocusOut:add( bind(self.setBorderOpacity, self, HIDE_OPACITY) )

    self:getEntityNamed('window_border').onClickBegin:add( bind(self.setMoveScreen, self, true) )
    self:getEntityNamed('window_border').onClickEnd:add( bind(self.setMoveScreen, self, false) )
end  
-------------------------------------------------------------------------------

-------------------------------------------------------------------------------
function EntityInfoScreen:updateScreen()
    if self.isScreenMoved then
        local obj = self:getEntityNamed('window_border')
        local mousePos = getHandledCursor():getPosition()

        local x, y = obj:getX(), obj:getY()
        local dx, dy = 0, 0

        if self.prevMousePos.x then
            dx, dy = mousePos.x - self.prevMousePos.x, mousePos.y - self.prevMousePos.y
        end

        self:getEntityNamed('window_border'):setXY(x + dx, y + dy)

        self.prevMousePos = mousePos
    else
        self.prevMousePos = {}
    end
end
-------------------------------------------------------------------------------

-------------------------------------------------------------------------------
function EntityInfoScreen:setMoveScreen(move)
    self.isScreenMoved = move
end
-------------------------------------------------------------------------------

-------------------------------------------------------------------------------
function EntityInfoScreen:setBorderOpacity(opacity)
    local current_opacity  = self:getEntityNamed('window_border'):getOpacity()

    if self.changeOpacity then
        self.changeOpacity:destroy() 
        self.changeOpacity = nil
    end

    self.changeOpacity = self:getEntityNamed('window_border'):ChangeOpacity(current_opacity, opacity, 0.5)
    self.changeOpacity:setDestroysOnEnd(false)
end
-------------------------------------------------------------------------------

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

function EntityInfoScreen:CreateLoaderTable()
	local objects =
	{
		{ name = 'window_border',  entityType = 'SpriteEntity',  x = 512,  y = 384,  order = 0,  editingLocked = false,  treeItemIsExpanded = true,  texturePath = 'Data/Textures/InGameEditor/GUI/Layers/window_border.png',  width = 463,  height = 568,  },
		{ name = 'anchor_name',  entityType = 'SpriteEntity',  parentName = 'window_border',  x = -180,  y = -220,  order = 0,  color = {r = 1, g = 1, b = 1, a = 0},  editingLocked = false,  treeItemIsExpanded = true,  width = 2,  height = 2,  },
		{ name = 'entity_name',  entityType = 'TextEntity',  parentName = 'anchor_name',  x = 110,  y = 0,  order = 0,  editingLocked = false,  treeItemIsExpanded = false,  text = '',  font = 'Data/Fonts/Options.fnt',  height = 25,  hotSpotType = TextEntity.ETextHotSpotTypeLeft,  },
		{ name = 'name_field',  entityType = 'TextEntity',  parentName = 'anchor_name',  x = 39,  y = 0,  order = 0,  editingLocked = false,  treeItemIsExpanded = true,  localizationKey = 'ENTITY_NAME',  font = 'Data/Fonts/Options.fnt',  height = 24,  },
		{ name = 'anchor_pos',  entityType = 'SpriteEntity',  parentName = 'window_border',  x = -180,  y = -200,  order = 0,  color = {r = 1, g = 1, b = 1, a = 0},  editingLocked = false,  treeItemIsExpanded = true,  width = 2,  height = 2,  },
		{ name = 'entity_pos',  entityType = 'TextEntity',  parentName = 'anchor_pos',  x = 110,  y = 0,  order = 0,  editingLocked = false,  treeItemIsExpanded = false,  text = '',  font = 'Data/Fonts/Options.fnt',  height = 25,  hotSpotType = TextEntity.ETextHotSpotTypeLeft,  },
		{ name = 'pos_field',  entityType = 'TextEntity',  parentName = 'anchor_pos',  x = 50,  y = 0,  order = 0,  editingLocked = false,  treeItemIsExpanded = true,  localizationKey = 'ENTITY_POS',  font = 'Data/Fonts/Options.fnt',  height = 24,  },
	}
	return objects
end
