--------------------------------------------------------------------------------
-- redesign

PopUpScreenManagerClass = CreateInheritedClass(LuaStack);

--------------------------------------------------------------------------------
function PopUpScreenManagerClass:Push(screen, hideActiveScreen)
	hideActiveScreen = (hideActiveScreen == nil and true or hideActiveScreen);
    
    local curScr = self:GetTop();
    if (curScr)
    then
        if hideActiveScreen then
            curScr:ScreenHide();
        else
            curScr:StopChilds();
            curScr:Stop();
        end
    end
    LuaStack.Push(self, screen);
    
    screen:SetOpacity(0);
    screen:ScreenShow();
    
    GM:SetCurrentScreen(screen);
    
    SetCursor('CursorDefault');
end

--------------------------------------------------------------------------------
function PopUpScreenManagerClass:Pop()
    --
    local curScr = self:GetTop();
    assert(curScr ~= nil);
    
    LuaStack.Pop(self);
    curScr:ScreenDestroy();
    
    curScr = self:GetTop();
    --if (curScr and curScr:GetOpacity() == 0)
    if (curScr)
    then
        curScr:ScreenShow();
    end
end

--------------------------------------------------------------------------------
function PopUpScreenManagerClass:DestroyAll()
    local screen = PopUpScreensMgr:GetTop();
    while (screen)
    do
        screen:Destroy();
        LuaStack.Pop(self);
        screen = PopUpScreensMgr:GetTop();
    end
end

--------------------------------------------------------------------------------
-- convenient to be passed as a callback
function PopCurrentPopUpScreen()
    
    PopUpScreensMgr:Pop();

end

--------------------------------------------------------------------------------
PopUpScreensMgr = PopUpScreenManagerClass:New();
