
current_comics = nil

clComicsScreen = {}
-------------------------------------------------------------------------------
setmetatable(clComicsScreen, {__index = clWindow})
-------------------------------------------------------------------------------
function clComicsScreen:init_dlg(_back_bar, _phrases)
    self.phrases = _phrases;
    self.back_bar = _back_bar;
    self.active = false
    DelayedExec(0.5, function()
        self.active = true;
    end)
    
    for key, value in pairs(self.phrases) do
        ItemSetOpacity(value, 0.0)
    end
    
    self.current_phrase = 1;
    self:show_next_phrase();  
    ItemSetDepth("menu_button_screen", LAYERS.FRONT_MOST)
    ItemSetDepth("hud", LAYERS.FRONT_MOST)
    self.old_game_mode = HUDScreen:GetHUDMode();
    HUDScreen:SetComicsMode()
    
    current_comics = self;
end
------------------------------------------------------
function clComicsScreen:show_next_phrase()
    if(self.phrases[self.current_phrase] == nil) then
        self.active = false
        HUDScreen:SetHUDMode(self.old_game_mode);
        if(self.on_finish) then
            self:on_finish();
        end
        self:FadeIn();
        DelayedExec(0.5, function() 
            current_comics = nil
            clScreenManager:remove_screen(self); 
        end)
        return;
     end
    
    for key, value in pairs(self.phrases) do
        ItemSetOpacity(value, 0.0)
    end
    if(self.cue) then
        ItemSetOpacity(self.cue, 0.0)
    end
    self.cue = self.back_bar[self.current_phrase]
    ItemSetOpacity(self.cue, 1.0)
    
    ItemSetOpacity(self.phrases[self.current_phrase], 1.0)
    self.current_phrase = self.current_phrase + 1
end
------------------------------------------------------
function clComicsScreen:OnClick(item_name)
    if(clApplication.game_pause) then return end
    if(not self.active) then return end
    
    if(item_name == "comics_skip") then
        SoundPlay("sound/interface/button.ogg")
        
        self.active = false
        HUDScreen:SetHUDMode(self.old_game_mode);
        if(self.on_finish) then
            self:on_finish();
        end
        self:FadeIn();
        DelayedExec(0.5, function() 
            current_comics = nil
            clScreenManager:remove_screen(self); 
        end)
    else
        self:show_next_phrase(); 
    end
end
-------------------------------------------------------------------------------
function NewComics(objects_list, win_name, _script_name)
	objects_list[win_name] = {}
	setmetatable(objects_list[win_name], {__index =  clComicsScreen})
	objects_list[win_name].name = win_name;
	objects_list[win_name].script_name = _script_name;
	objects_list[win_name].win = false;
	GameScreen = objects_list[win_name];
	require(_script_name);
end
