HintTest = {}

function HintTest:Show(resouce, pos_x, pos_y, end_fun, bar_pos, loop)
    if(self.resouce == resouce and self.hint_text_active) then
        ItemSetDepth("hint_text_win", LAYERS.FRONT_MOST)
        return;
    else
        HintTest:Remove()
    end
    
    self.data = {resouce, pos_x, pos_y, end_fun, bar_pos, loop}
    
    Tip:Remove()
    
    cpp_application_add_window("hint_text_win");
    self.end_fun = end_fun;
    
    self.resouce = resouce;
    
    local __bar_pos = {296, 1096}
    if(bar_pos) then __bar_pos = bar_pos; end
    
    cpp_create_sprite("hint_text_win", OBJ_TYPE.NO_ACTIVE, "hint_panel", "graphics/interface/hud/hint_bar", __bar_pos[1], __bar_pos[2]);
    cpp_create_sprite("hint_text_win", OBJ_TYPE.NO_ACTIVE, "hint_text", resouce, pos_x, pos_y)
    
    self.hint_text_active = true;
    self.hint_text_active2 = true;
    ItemSetOpacity("hint_text_win", 0.0)
    ItemChangeOpacity("hint_text_win", 1.0, 0.5)
end
------------------------------------------
--self.hint_text_active2 из за этого флага скорее всегои бажит
function HintTest:Hide()
    if(self.hint_text_active2) then
        StopRequests(104)
        self.hint_text_active2 = false;
        
        if(self.end_fun) then self:end_fun() end
        self.end_fun = nil;
        
        DelayedExec(5.0, function()
            ItemChangeOpacity("hint_text_win", 0.0, 0.5)
            DelayedExec(0.5, function()
                cpp_application_remove_window("hint_text_win");
                if(self.data and self.data[6]) then
                    local _data = self.data;
                    DelayedExec(20.0, function()
                         HintTest:Show(_data[1], _data[2], _data[3], nil, _data[5], _data[6])    
                    end, 114)   
                    self.data = nil;
                end
            end, 103)
            DelayedExec(0.5, function()
                self.hint_text_active = false;
            end, 103)
        end, 104)
    end
end

function HintTest:Remove()
    cpp_application_remove_window("hint_text_win");
    StopRequests(103)
    StopRequests(104)
    self.hint_text_active = false
    
    if(self.data and self.data[6]) then
        local _data = self.data;
        DelayedExec(20.0, function()
             HintTest:Show(_data[1], _data[2], _data[3], nil, _data[5], _data[6])    
        end, 114)
        self.data = nil;
    end
end

function HintTest:RemoveLoop()
    self.data = nil;
    StopRequests(114)
end