Tip = {}

function Tip:Show(resouce, pos_x, pos_y, end_fun, loop)
    if(self.resouce == resouce and self.tip_text_active) then
        ItemSetDepth("tip", LAYERS.FRONT_MOST)
        return;
    else
        Tip:Remove()
    end
    
    self.data = {resouce, pos_x, pos_y, end_fun, loop}
    
    HintTest:Remove()
    
    self.resouce = resouce;
    
    cpp_application_add_window("tip");
    self.end_fun = end_fun;
   
    cpp_create_sprite("tip", OBJ_TYPE.NO_ACTIVE, "tip_panel", "graphics/interface/hud/text_bar", 296, 1096);
    cpp_create_sprite("tip", OBJ_TYPE.NO_ACTIVE, "tip_text", resouce, pos_x, pos_y)
    
    self.tip_text_active = true;
    self.tip_text_active2 = true;
    ItemSetOpacity("tip", 0.0)
    ItemChangeOpacity("tip", 1.0, 0.5)
end

function Tip:Hide()
    if(self.tip_text_active2) then
        StopRequests(106)
        self.tip_text_active2 = false
        
        if(self.end_fun) then self:end_fun() end
        self.end_fun = nil;
        
        DelayedExec(5.0, function()
            ItemChangeOpacity("tip", 0.0, 0.5)
            DelayedExec(0.5, function()
                cpp_application_remove_window("tip");
                if(self.data and self.data[5]) then
                    local _data = self.data;
                    DelayedExec(15.0, function()
                         Tip:Show(_data[1], _data[2], _data[3], nil, _data[5])    
                    end, 115)
                    self.data = nil;
                end
            end, 105)
            DelayedExec(1.5, function()
                self.tip_text_active = false;
            end, 105)
        end, 106)
    end
end

function Tip:Remove()
    cpp_application_remove_window("tip");
    StopRequests(105)
    StopRequests(106)
    self.hint_text_active = false
    
    if(self.data and self.data[5]) then
        local _data = self.data;
        DelayedExec(15.0, function()
             Tip:Show(_data[1], _data[2], _data[3], nil, _data[5])    
        end, 115)
        self.data = nil;
    end
end

function Tip:RemoveLoop()
    self.data = nil;
    StopRequests(115)
end