

function GameScreen:InitScreen()
    self:LoadScreen()
    
    --SetState("GLOBAL", "crystal", "15")
    
    self:FadeOut(0.5);
    
    for i = 1, 6 do
        ItemSetOpacity("story_0"..i, 0.0)
    end
    
    local num = tonumber(GetState("GLOBAL", "crystal"))
    self.story_amount = math.floor(num / 6);
    if(self.story_amount > 6) then
        self.story_amount = 6;
    end
    self.cur_story = 0; 
    self.state = "start"
    
     MusicPlay({"sound/music/final.ogg"}, 34) 
end
------------------------------------------------------------------------------------------------------
function GameScreen:__show_next_story()
    if(self.cur_story < self.story_amount + 1 and self.cur_story < 6) then
        self.cur_story = self.cur_story + 1
        ItemChangeOpacity("story_0"..(self.cur_story - 1), 0.0, 0.3)
        ItemChangeOpacity("story_0"..self.cur_story, 1.0, 0.3)
    else
        ItemSetOpacity("next", 0.0);
        ItemChangeOpacity("story_0"..self.cur_story, 0.0, 0.3)
        self.state = "finish"
        ItemChangeOpacity("finish_win", 1.0, 0.4)
        ItemChangeOpacity("continue", 1.0, 0.4)
        self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "finish_win", "graphics/interface/hud/the_end", 265, 454);
        self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "continue", "graphics/interface/menu/ok", 548, 714);
    end
end
------------------------------------------------------------------------------------------------------
function GameScreen:onObjectClick(item_name)   
    if(self.state == "start" and item_name == "ok") then
        ItemChangeOpacity("next", 1.0, 0.3);
        SoundPlay("sound/interface/button.ogg")
        self.state = "story"
        ItemRemove(self.name, "crystals_found", 0.2)
        ItemRemove(self.name, "ok", 0.2)
        ItemRemove(self.name, "finish_text1", 0.2)
        ItemRemove(self.name, "finish_text2", 0.2)
        ItemRemove(self.name, "finish_text3", 0.2)
        ItemRemove(self.name, "finish_text4", 0.2)
        self:__show_next_story();
    elseif(self.state == "story" and item_name == "next") then
        SoundPlay("sound/interface/button.ogg")
        self:__show_next_story();
    elseif(self.state == "finish" and item_name == "continue") then
        SoundPlay("sound/interface/button.ogg")
        SetState("GLOBAL", "finish", "true")
        ItemRemove(self.name, "finish_win", 0.2)
        ItemRemove(self.name, "continue", 0.2)
        clScreenManager:add_screen("MainMenuScreen") 
    end
end
------------------------------------------------------------------------------------------------------
function GameScreen:LoadScreen()
	--[[---Background---]]--
	self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "story_01", "graphics/screens/story_01/story_01", 0, 0);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "story_02", "graphics/screens/story_02/story_02", 0, 0);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "story_03", "graphics/screens/story_03/story_03", 0, 0);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "story_04", "graphics/screens/story_04/story_04", 0, 0);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "story_05", "graphics/screens/story_05/story_05", 0, 0);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "story_06", "graphics/screens/story_06/story_06", 0, 0);

    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "crystals_found", "graphics/interface/hud/crystals_found", 267, 385);
    ItemSetOpacity("crystals_found", 0.5)
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "ok", "graphics/interface/menu/ok", 545, 730);
    
    if(GetState("GLOBAL", "crystal") == "") then SetState("GLOBAL", "crystal", "0") end
    local num = tonumber(GetState("GLOBAL", "crystal"))
    
    self:CreateLabel("finish_text4", "", 0, 450, 55, FONT_QUICKSAND)
    ItemSetSize("finish_text4", 1030, 30)
    ItemSetColor("finish_text4", 1.0, 1.0, 1.0, 1.0)
    SetLabelText("finish_text4", "Game complete!")
    ItemSetPosition("finish_text4", WINDOW_WIDTH / 2 - ItemGetWidth("finish_text4") / 2, 410)

    self:CreateLabel("finish_text1", "", 0, 450, 55, FONT_QUICKSAND)
    ItemSetSize("finish_text1", 1030, 30)
    ItemSetColor("finish_text1", 1.0, 1.0, 1.0, 1.0)
    SetLabelText("finish_text1", "You've collected "..num.." crystals out of 36.")
    ItemSetPosition("finish_text1", WINDOW_WIDTH / 2 - ItemGetWidth("finish_text1") / 2, 480)
    
    self:CreateLabel("finish_text2", "", 0, 450, 55, FONT_QUICKSAND)
    ItemSetSize("finish_text2", 1030, 30)
    ItemSetColor("finish_text2", 1.0, 1.0, 1.0, 1.0)
    SetLabelText("finish_text2", "You will now see bonus episodes")
    ItemSetPosition("finish_text2", WINDOW_WIDTH / 2 - ItemGetWidth("finish_text2") / 2, 550)
    
    self:CreateLabel("finish_text3", "", 0, 450, 55, FONT_QUICKSAND)
    ItemSetSize("finish_text3", 1030, 30)
    ItemSetColor("finish_text3", 1.0, 1.0, 1.0, 1.0)
    local count = math.floor(num / 6) + 1;
    if(count > 6) then count = 6;end
    SetLabelText("finish_text3", "of the story ("..count.." out of 6).")
    ItemSetPosition("finish_text3", WINDOW_WIDTH / 2 - ItemGetWidth("finish_text3") / 2, 630)

    clScreenManager:add_screen("hud") 
    HUDScreen:SetInvntoryOnlyMode()
    
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "next", "graphics/interface/hud/next", 1392, 1104);
    ItemSetOpacity("next", 0.0)
end