
class 'BaseScreen'

function BaseScreen:__init(name, screen)
    self.name    = name
    self.screen  = screen
    self.timer   = Timer()
    self.buttons = {}
    self.listbox = nil

    assert(self.screen)
    self:LoadDefaultData(self.screen)
end
-------------------------------------------------------------------------------

function BaseScreen:OnDefaultBeforeDestroy()
    if self.OnBeforeDestroy then
        self:OnBeforeDestroy()
    end

    self.screen = nil
end
-------------------------------------------------------------------------------

function BaseScreen:GetName()
    assert(self.name)
    return self.name
end
-------------------------------------------------------------------------------

function BaseScreen:GetTopLevelScreen()
    assert(self.screen)
    return self.screen
end
-------------------------------------------------------------------------------

function BaseScreen:GetButton(buttonName)
    assert(self.buttons[buttonName])
    return self.buttons[buttonName]
end
-------------------------------------------------------------------------------

function BaseScreen:OnDefaultUpdate(dt)
    self.timer:Update(dt)
    
    if self.OnUpdate then
	    self:OnUpdate(dt)
	end
end
-------------------------------------------------------------------------------

function BaseScreen:OnDefaultLostFocus()
    if self.OnLostFocus then
	    self:OnLostFocus()
	end
end
-------------------------------------------------------------------------------

function BaseScreen:OnDefaultGainFocus()
    if self.OnGainFocus then
	    self:OnGainFocus()
	end
end
-------------------------------------------------------------------------------

function BaseScreen:GetObject(objectName)
    assert(objectName and self.screen)
    return self.screen:GetObject(objectName)
end
-------------------------------------------------------------------------------

function BaseScreen:HasObject(objectName)
    assert(objectName and self.screen)
    return self.screen:HasObject(objectName)
end
-------------------------------------------------------------------------------

function BaseScreen:OnDefaultObjectMouseEnter(object)
    if self.OnObjectMouseEnter then
        self:OnObjectMouseEnter(object)
    end
end
-------------------------------------------------------------------------------

function BaseScreen:OnDefaultObjectMouseLeave(object)
    if self.OnObjectMouseLeave then
        self:OnObjectMouseLeave(object)
    end
end
-------------------------------------------------------------------------------

function BaseScreen:OnObjectMouseDown(object)
    if self.OnScreenObjectMouseDown then
        self:OnScreenObjectMouseDown(object)
    end
    
    self:OnDefaultObjectMouseDownProcessed(false)
end

-------------------------------------------------------------------------------
function BaseScreen:OnDefaultObjectMouseDownProcessed(is_wrong_click)
    if self.OnObjectMouseDownProcessed then
        self:OnObjectMouseDownProcessed(is_wrong_click)
    end
end
-------------------------------------------------------------------------------

function BaseScreen:OnDefaultObjectMouseUp(object)
    if self.OnObjectMouseUp then
        self:OnObjectMouseUp(object)
    end
end
-------------------------------------------------------------------------------

function BaseScreen:OnDefaultButtonMouseEnter(buttonName)
    if self.OnButtonMouseEnter then
        self:OnButtonMouseEnter(buttonName)
    end
end
-------------------------------------------------------------------------------

function BaseScreen:OnDefaultButtonMouseLeave(buttonName)
    if self.OnButtonMouseLeave then
        self:OnButtonMouseLeave(buttonName)
    end
end
-------------------------------------------------------------------------------

function BaseScreen:OnDefaultButtonPress(buttonName)
    if self.OnButtonPress then
        self:OnButtonPress(buttonName)
    end
end
-------------------------------------------------------------------------------

function BaseScreen:OnDefaultButtonDepress(buttonName)
    if self.OnButtonDepress then
        self:OnButtonDepress(buttonName)
    end
end
-------------------------------------------------------------------------------

function BaseScreen:GetObjectUnderMouse()
    assert(self.screen)
    return self.screen:GetObjectUnderMouse()
end
-------------------------------------------------------------------------------

function BaseScreen:IgnoreOnTestPoint(objectName)
    assert(self.screen)
    self.screen:IgnoreOnTestPoint(objectName)
end
-------------------------------------------------------------------------------

function BaseScreen:CreateButton(objectName, message, hotKey)
    assert(self:HasObject(objectName))
    message = message or objectName

    local object = self:GetObject(objectName)
    local anim   = object:GetAnimation()
    assert(anim:GetFrames() == 3 and 'Animation which is used to create button should contents three frame (normal, over and clicked states)')

    object:SetVisible(false)
    self:IgnoreOnTestPoint(objectName)

    local button = CreateButton("", "", "", message, self.screen)
    button:AttachTo(object)
    button:SetVisible(true)
    
    anim:SetFrame(0)
    button:SetSpriteUp(anim)
    anim:SetFrame(1)
    button:SetSpriteOver(anim)
    anim:SetFrame(2)
    button:SetSpriteDown(anim)
    
    assert(not self.buttons[message])
    self.buttons[message] = button
    
    if hotKey ~= nil then
        button:SetKeyEquivalent(hotKey)
    end
    
    return button
end
-------------------------------------------------------------------------------

function BaseScreen:CreateButtonByName(name, hotKey)
    local bttn = self:CreateButton('bttn_'..string.lower(name), 'On'..name..'ButtonClick', hotKey)
    bttn:SetAction('On'..name..'ButtonClick', self)
    bttn:SetActionSound('Menu_button_click')
    
    return bttn
end
--------------------------------------------------------------------------------

function BaseScreen:MakeButton(centerX, centerY, width, height)
    local result = CreateButton("", "", "", "", nil);

    result:SetXY(centerX, centerY);
	result:SetRect(centerX - width / 2,
                   centerY - height / 2,
                   width,
                   height);
    return result;
end
-------------------------------------------------------------------------------

function BaseScreen:CreateListBox(name)
    local listbox = CreateListBoxEntityEx(name, self.screen)
    listbox:SetXY(512, 440)
    listbox:AttachTo(self.screen)
    listbox:SetZ(150)
    listbox:SetRectSize(400,250)
    listbox:SetFont("Main")
    self.listbox = listbox

    return listbox
end
-------------------------------------------------------------------------------

--------------------------------------------------------------------------------
-- CLEAR_ON_SAVE_BEGIN
-- Do not edit code listed below (generated by the editor on each save)
function BaseScreen:LoadDefaultData(screen)
    local anim = CreateAnimation('data/Texture/Common/fade.png',0,0,512,384,1,0)
    anim:SetHotSpot(256,192)
    anim:SetBlendMode(2)
    anim:SetColor('0x80FFFFFF')
    screen:CreateObject('fade',anim,512,385,0,0,3,3)
    
    if self.LoadData then
	    self:LoadData(screen)
	end
end
-- CLEAR_ON_SAVE_END
