--/ ui_remkit_select.script /--
--/ Repair kit module /--
--/ OGS Evolution Team 2009 /--
--/ version 0.9 /--

--/ Модуль походного ремонтного комплекта, скрипт всплывающего меню /--



local repaired_item = 0
local item_table
local item_table_index = 0


class "select_repair_items" (CUIListItemEx)


function select_repair_items:__init() super()
-- -- amk.logf("Начинаем инициализацию поля списка предметов")
	self.item_name		= "itemname"
	self:SetWndRect		(0,0,320,22)
	
	local ca = 255
	local cr = 216
	local cg = 186
	local cb = 140
	
	self.itmnum				= CUIStatic	()
	self.itmnum:SetAutoDelete	(true)
	self:AttachChild		(self.itmnum)
	self.itmnum:SetWndRect	(0,0,20,22)
	self.itmnum:SetText		("itemnum")
	self.itmnum:SetFont		(GetFontLetterica16Russian())
	self.itmnum:SetTextColor	(ca,cr,cg,cb)

	self.itmn					= CUIStatic	()
	self.itmn:SetAutoDelete	(true)
	self:AttachChild		(self.itmn)
	self.itmn:SetWndRect		(25,0,205,22)
	self.itmn:SetText			("itemname")
	self.itmn:SetFont			(GetFontLetterica18Russian())
	self.itmn:SetTextColor	(ca,cr,cg,cb)

	self.itmage				= CUIStatic	()
	self.itmage:SetAutoDelete	(true)
	self:AttachChild		(self.itmage)
	self.itmage:SetWndRect	(250,0,40,22)
	self.itmage:SetText		("itemage")
	self.itmage:SetFont		(GetFontLetterica16Russian())
	self.itmage:SetTextColor	(ca,cr,cg,cb)
-- -- amk.logf("Поле списка предметов инициализировано")
end


class "repair_dialog" (CUIScriptWnd)


function repair_dialog:__init() super()
	self:InitControls()
	self:InitCallBacks()
	self:FillList()
	local repaired_item_name = game.translate_string(get_inv_name_short(repaired_item:section()))
	self:DrawConditionBar(repaired_item, 100, 130)
	self:DrawCurItemName(repaired_item_name, 100, 45)
	self:DrawCurItem(repaired_item, 100, 90)
	self:DrawShansBar(repaired_item, 200, 100)
end

function repair_dialog:__finalize() end


function repair_dialog:InitControls()
-- -- amk.logf("Инициализируем управление формой")
	-- здесь определяем координаты левого верхнего угла и ширину-высоту
	self:Init(50,50,550,450)

	-- файл-описатель наших элементов
	local xml = CScriptXmlInit()
	local ctrl
	xml:ParseFile("ui_remkit_sel.xml")
	-- видео на заднем плане
	xml:InitStatic("back_video", self)
	-- рамка
	xml:InitStatic("background", self)
	-- рамка предмета 1
	xml:InitStatic("item_frame1", self)
	-- колба предмета 1
	xml:InitStatic("bar_frame1", self)
	-- рамка предмета 2
	xml:InitStatic("item_frame2", self)
	-- колба предмета 2
	xml:InitStatic("bar_frame2", self)
	-- колба шансов на успех
	xml:InitStatic("shans_bar_frame", self)
	-- список предметов
	xml:InitFrame("list_frame", self)

	ctrl = xml:InitList("list", self)
	ctrl:ShowSelectedItem(true)
	self:Register(ctrl, "list_window")

	-- кнопки
	self:Register(xml:Init3tButton("window_name", self),"window_name")
	self:Register(xml:Init3tButton("caption1", self),"caption1")
	self:Register(xml:Init3tButton("caption2", self),"caption2")
	self:Register(xml:Init3tButton("caption3", self),"caption3")
	self:Register(xml:Init3tButton("caption4", self),"caption4")
	self.btn_4 = xml:Init3tButton("btn_4", self)
	self:Register(self.btn_4, "btn_4")
	self.btn_4:Enable(false)	
	-- кнопка выхода
	self:Register(xml:Init3tButton("btn_quit", self),"btn_quit")

	self.message_box = CUIMessageBoxEx()
	self:Register(self.message_box,"message_box")
-- -- amk.logf("Управление формой инициализировано")
end


function repair_dialog:InitCallBacks()
-- -- amk.logf("Инициализируем коллбэки")
	-- тут интерактивные элементы, при определенном действии выполняется заданная ф-ия
	self:AddCallback("btn_4", ui_events.BUTTON_CLICKED, self.rep_btn, self)
	
	self:AddCallback("btn_quit", ui_events.BUTTON_CLICKED, self.on_quit, self)
	
	self:AddCallback("list_window", ui_events.LIST_ITEM_CLICKED, 			  self.OnListItemClicked,		self)
	self:AddCallback("list_window", ui_events.WINDOW_LBUTTON_DB_CLICK,		  self.OnListItemDbClicked,		self)

	self:AddCallback("message_box",		ui_events.MESSAGE_BOX_OK_CLICKED,	  self.OnMsgYes,				self)
-- -- amk.logf("Коллбэки инициализированы")
end


function repair_dialog:FillList()
-- -- amk.logf("Наполняем список предметами:")
	local rep_slot = db.repaired_slot
	if db.actor:item_in_slot(rep_slot) ~= nil then
		repaired_item = db.actor:item_in_slot(rep_slot)
	end

-- -- amk.logf("Начинаем перебирать инвентарь")
	item_table = 0
	item_table = {}
	item_table_index = 0
	db.actor:iterate_inventory(item_for_repair, db.actor)
-- -- amk.logf("Закончили перебирать инвентарь")
	
	local i = 1
	while (item_table[i]) do
-- -- amk.logf("Извлекаем предмет из таблицы")
		local s_item = item_table[i]
		local s_item_section = s_item:section()
		local _item_num = "" .. i .. ""
		local _item_name = game.translate_string(get_inv_name_short(s_item_section))
		local _item_cond = s_item:condition()*100
		if _item_cond ~= 100 then _item_cond = string.format("%.1f", _item_cond) end
		_item_cond = "[" .. _item_cond .. "%]"
-- -- amk.logf("Передаём строку с предметом в список")
		self:AddItemToList(_item_num, _item_name, _item_cond)
		i = i+1
	end

-- -- amk.logf("Закончили наполнять список")
end


function item_for_repair(npc, item)
-- -- amk.logf("Сравниваем предмет с ремонтируемым")
if  item:id() ~= repaired_item:id() then
	if item:section() == repaired_item:section() then
-- -- amk.logf("Предмет нам подходит, запоминаем его в таблице")
		item_table_index = item_table_index + 1
		item_table[item_table_index] = item
	else
-- -- amk.logf("Нет полного совпадения, исследуем подробнее")
		if remkit_main.compatibility_item(item, repaired_item) == true then
-- -- amk.logf("Предмет нам подходит, запоминаем его в таблице")
			item_table_index = item_table_index + 1
			item_table[item_table_index] = item
		end
	end
end
end


function repair_dialog:OnListItemClicked()
	local list_box = self:GetListWnd("list_window")
	
	if list_box:GetSize() == 0 then return end
	
	local itm_index = list_box:GetSelectedItem()
	
	local item = list_box:GetItem(itm_index)

	if item == nil then return end
	
	self.btn_4:Enable(true)

	local destr_item_name = item.itmn:GetText()
	local destr_item_index = tonumber(item.itmnum:GetText())
	local destr_item_st = item_table[destr_item_index]
	self:DrawConditionRemBar(destr_item_st, 300, 130)
	self:DrawCurRemItemName(destr_item_name, 300, 45)
	self:DrawCurRemItem(destr_item_st, 300, 90)
	self:DrawShansBar(repaired_item, 200, 100, destr_item_st)
end


function repair_dialog:OnListItemDbClicked()
	self:rep_btn()
end


function repair_dialog:rep_btn()

-- -- amk.logf("Будем ремонтировать")
	local console = get_console()
	local list = self:GetListWnd("list_window")	
	if list:GetSize()==0 then
--		amk.send_tip("Нет предметов для разбора на запчасти.")
		self.msgbox_id = 1
		self.message_box:Init("message_box_out_of_item")
		self:GetHolder():start_stop_menu(self.message_box, true)
		return
	end
-- -- amk.logf("И есть, чем")
	local index = list:GetSelectedItem()
	if index == -1 then
--		amk.send_tip("Выберите предмет для разбора на запчасти.")
		self.msgbox_id = 1
		self.message_box:Init("message_box_select_item")
		self:GetHolder():start_stop_menu(self.message_box, true)
		return
	end

-- -- amk.logf("Выбрали разбираемый предмет")
	local item = list:GetItem(index)
-- -- amk.logf("Вытаскиваем его из таблицы")
	local destr_item_index = tonumber(item.itmnum:GetText())
	local destr_item = item_table[destr_item_index]
-- -- amk.logf("У него номер " .. destr_item_index .. " и ID = " ..destr_item:id())
	if destr_item:condition() <= 0.15 then
--		amk.send_tip("Ничего не выйдет - вещь разбита в хлам.")
		self.msgbox_id = 1
		self.message_box:Init("message_box_invalid_item")
		self:GetHolder():start_stop_menu(self.message_box, true)
		return
	else
		local result_of_use = remkit_main.use_repair_kit(db.repaired_slot,destr_item)
		if result_of_use ~= nil then
			if result_of_use == "success" then
				self.msgbox_id = 1
				self.message_box:Init("message_box_repair_success")
				self:GetHolder():start_stop_menu(self.message_box, true)
			elseif result_of_use == "without_changes" then
				self.msgbox_id = 1
				self.message_box:Init("message_box_repair_without_changes")
				self:GetHolder():start_stop_menu(self.message_box, true)
			elseif result_of_use == "failure" then
				self.msgbox_id = 1
				self.message_box:Init("message_box_repair_failure")
				self:GetHolder():start_stop_menu(self.message_box, true)
			end
		end
		self:on_quit()
	end
end


-- сразу созадим ф-ию для выхода
function repair_dialog:on_quit()
	local console = get_console()
	self:GetHolder():start_stop_menu (self.owner, true)
	self:GetHolder():start_stop_menu (self,true)
	self.owner:Show	(true)
-- если мы вызывались из игры, то убираем главное меню
	if level.present() and (db.actor ~= nil) and db.actor:alive() then
		console:execute("main_menu off")
	end
end
	

function repair_dialog:OnKeyboard(dik, keyboard_action)
	CUIScriptWnd.OnKeyboard(self,dik,keyboard_action)
	if keyboard_action == ui_events.WINDOW_KEY_PRESSED then
-- на выход повесим Esc
		if dik == DIK_keys.DIK_ESCAPE then
			self:on_quit()
		end
		if dik == DIK_keys.DIK_NUMPAD4 then
			self:rep_btn()
		end
		
	end
	return true
end


function repair_dialog:on_quit()
	self:GetHolder():start_stop_menu (self,true)
	remkit_main.create_repair_kit() 
end


function repair_dialog:AddItemToList(item_num, item_name, item_cond)
-- -- amk.logf("Пытаемся добавить строку списка:")
	local _itm = select_repair_items()
	
-- -- amk.logf("Передача индекса..." .. item_num)
	_itm.itmnum:SetText (item_num)
-- -- amk.logf("Передача имени..." .. item_name)
	_itm.itmn:SetText (item_name)
-- -- amk.logf("Передача кондиции..." .. item_cond)
	_itm.itmage:SetText (item_cond)
	
-- -- amk.logf("Получаем доступ к полю списка...")
	local list_box = self:GetListWnd("list_window")
-- -- amk.logf("Добавление строки...")
	list_box:AddItem (_itm)
-- -- amk.logf("Строка списка добавлена")
end


function get_inv_name_short(section)
	return system_ini():r_string(section,"inv_name_short")
end


--Рисуем ремонтируемый предмет
function repair_dialog:DrawCurItem(item, x, y)

if x == nil then x = 0 end
if y == nil then y = 0 end

	local item_section = item:section()

	local scope = 0
	local launcher = 0
	local silence = 0

	local cur_state, sect_addon
	local tx,ty,tw,th
	local x_g,y_g,x_sco,y_sco,x_sil,y_sil
	local xa,ya,wa,ha
	local isGrenade=false
	local isScope=false
	local isSilencer=false
	
  
  local a = self.cur_textur
  local sys = system_ini()
  if not a then
	self.cur_textur = CUIStatic()
    a = self.cur_textur
    a:SetWindowName("cur_textur")
    a:SetAutoDelete(true)  
	a:InitTexture("ui\\ui_icon_equipment")   
    a:SetStretchTexture(true)
    self:AttachChild(a)
  end
	if item then
	tx = remkit_main.get_x(item)
    ty = remkit_main.get_y(item)
	tw = remkit_main.get_w(item)
    th = remkit_main.get_h(item)
	tx=tx*50
	ty=ty*50
	tw=tw*50
	th=th*50

	x = x-(tw/4)
	y = y-(th/4)

    a:SetOriginalRect(tx,ty,tw,th)
	a:Init(x,y,tw/2,th/2)

		if system_ini():line_exist(item_section, "scope_status") then
			scope = system_ini():r_u32(item_section, "scope_status")
		end
		if system_ini():line_exist(item_section, "grenade_launcher_status") then
			launcher = system_ini():r_u32(item_section, "grenade_launcher_status")
		end
		if system_ini():line_exist(item_section, "silencer_status") then
			silence = system_ini():r_u32(item_section, "silencer_status")
		end
	cur_state = remkit_main.get_weapon_data(alife():object(item:id()))

	if cur_state == nil then return end

--Рисуем подствольник
if launcher == 2 and bit_and(cur_state.addon_flags, 2) == 2 then
	isGrenade=true
	sect_addon=sys:r_string(item_section,"grenade_launcher_name")
	x_g=x+(sys:r_u32(item_section, "grenade_launcher_x")/2)
	y_g=y+(sys:r_u32(item_section, "grenade_launcher_y")/2)
	xa=sys:r_u32(sect_addon, "inv_grid_x")*50
	ya=sys:r_u32(sect_addon, "inv_grid_y")*50
	wa=sys:r_u32(sect_addon, "inv_grid_width")*50
	ha=sys:r_u32(sect_addon, "inv_grid_height")*50
  
  local b = self.grenade_textur   
  
 if not b then
	self.grenade_textur=CUIStatic()
	b = self.grenade_textur
	b:SetWindowName("grenade_textur")
	b:SetAutoDelete(true)  
	b:InitTexture("ui\\ui_icon_equipment")   
	b:SetStretchTexture(true)
	self:AttachChild(b)
 end
	b:SetOriginalRect(xa,ya,wa,ha)
	b:Init(x_g,y_g,wa/2,ha/2)
 end

 --Рисуем оптический прицел
if scope == 2 and bit_and(cur_state.addon_flags, 1) == 1 then
	isScope=true
	sect_addon=sys:r_string(item_section,"scope_name")
	x_sco=x+(sys:r_u32(item_section, "scope_x")/2)
	y_sco=y+(sys:r_u32(item_section, "scope_y")/2)
	xa=sys:r_u32(sect_addon, "inv_grid_x")*50
	ya=sys:r_u32(sect_addon, "inv_grid_y")*50
	wa=sys:r_u32(sect_addon, "inv_grid_width")*50
	ha=sys:r_u32(sect_addon, "inv_grid_height")*50
  
  local b = self.scope_textur   
  
 if not b then
	self.scope_textur=CUIStatic()
	b = self.scope_textur
	b:SetWindowName("scope_textur")
	b:SetAutoDelete(true)  
	b:InitTexture("ui\\ui_icon_equipment")   
	b:SetStretchTexture(true)
	self:AttachChild(b)
 end
	b:SetOriginalRect(xa,ya,wa,ha)
	b:Init(x_sco,y_sco,wa/2,ha/2)
	
end

--Рисуем глушитель
if silence == 2 and bit_and(cur_state.addon_flags, 4) == 4 then 	
	isSilencer=true
	sect_addon=sys:r_string(item_section,"silencer_name")
	x_sil=x+(sys:r_u32(item_section, "silencer_x")/2)
	y_sil=y+(sys:r_u32(item_section, "silencer_y")/2)
	xa=sys:r_u32(sect_addon, "inv_grid_x")*50
	ya=sys:r_u32(sect_addon, "inv_grid_y")*50
	wa=sys:r_u32(sect_addon, "inv_grid_width")*50
	ha=sys:r_u32(sect_addon, "inv_grid_height")*50
  
 local b = self.silencer_textur   
  
 if not b then
	self.silencer_textur=CUIStatic()
	b = self.silencer_textur
	b:SetWindowName("silencer_textur")
	b:SetAutoDelete(true)  
	b:InitTexture("ui\\ui_icon_equipment")   
	b:SetStretchTexture(true)
	self:AttachChild(b)
 end
	b:SetOriginalRect(xa,ya,wa,ha)
	b:Init(x_sil,y_sil,wa/2,ha/2)
end

end
	local d1 = self.grenade_textur
	local d2 = self.scope_textur
	local d3 = self.silencer_textur
	
	if d1 and not isGrenade  then
	d1:Init(0,0,0,0)
	end

	if d2 and not isScope  then
	d2:Init(0,0,0,0)
	end
	
	if d3 and not isSilencer  then
	d3:Init(0,0,0,0)
	end

end


--Рисуем разбираемый предмет
function repair_dialog:DrawCurRemItem(de_item, x, y)

if x == nil then x = 0 end
if y == nil then y = 0 end

	local di_section = de_item:section()

  local scope = 0
  local launcher = 0
  local silence = 0

  local cur_destr_state, sect_addon
  local xa,ya,wa,ha
  local x_g,y_g,x_sco,y_sco,x_sil,y_sil
  local isGrenade=false
  local isScope=false
  local isSilencer=false
  
  local a = self.cur_rem_textur
  local sys = system_ini()
  if not a then
	self.cur_rem_textur = CUIStatic()
    a = self.cur_rem_textur
    a:SetWindowName("cur_rem_textur")
    a:SetAutoDelete(true)  
	a:InitTexture("ui\\ui_icon_equipment")   
    a:SetStretchTexture(true)
    self:AttachChild(a)
  end
	
	if de_item then
	tx = remkit_main.get_x(de_item)
    ty = remkit_main.get_y(de_item)
	tw = remkit_main.get_w(de_item)
    th = remkit_main.get_h(de_item)
	tx=tx*50
	ty=ty*50
	tw=tw*50
	th=th*50

	x = x-(tw/4)
	y = y-(th/4)

    a:SetOriginalRect(tx,ty,tw,th)
	a:Init(x,y,tw/2,th/2)
	
		if system_ini():line_exist(di_section, "scope_status") then
			scope = system_ini():r_u32(di_section, "scope_status")
		end
		if system_ini():line_exist(di_section, "grenade_launcher_status") then
			launcher = system_ini():r_u32(di_section, "grenade_launcher_status")
		end
		if system_ini():line_exist(di_section, "silencer_status") then
			silence = system_ini():r_u32(di_section, "silencer_status")
		end
	cur_destr_state = remkit_main.get_weapon_data(alife():object(de_item:id()))

	if cur_destr_state == nil then return end

--Рисуем подствольник
if launcher == 2 and bit_and(cur_destr_state.addon_flags, 2) == 2 then
	isGrenade=true
	sect_addon=sys:r_string(di_section,"grenade_launcher_name")
	x_g=x+(sys:r_u32(di_section, "grenade_launcher_x")/2)
	y_g=y+(sys:r_u32(di_section, "grenade_launcher_y")/2)
	xa=sys:r_u32(sect_addon, "inv_grid_x")*50
	ya=sys:r_u32(sect_addon, "inv_grid_y")*50
	wa=sys:r_u32(sect_addon, "inv_grid_width")*50
	ha=sys:r_u32(sect_addon, "inv_grid_height")*50
  
  local b = self.grenade_rem_textur   
  
 if not b then
	self.grenade_rem_textur=CUIStatic()
	b = self.grenade_rem_textur
	b:SetWindowName("grenade_rem_textur")
	b:SetAutoDelete(true)  
	b:InitTexture("ui\\ui_icon_equipment")   
	b:SetStretchTexture(true)
	self:AttachChild(b)
 end
	b:SetOriginalRect(xa,ya,wa,ha)
	b:Init(x_g,y_g,wa/2,ha/2)
 end

 --Рисуем оптический прицел
if scope == 2 and bit_and(cur_destr_state.addon_flags, 1) == 1 then
	isScope=true
	sect_addon=sys:r_string(di_section,"scope_name")
	x_sco=x+(sys:r_u32(di_section, "scope_x")/2)
	y_sco=y+(sys:r_u32(di_section, "scope_y")/2)
	xa=sys:r_u32(sect_addon, "inv_grid_x")*50
	ya=sys:r_u32(sect_addon, "inv_grid_y")*50
	wa=sys:r_u32(sect_addon, "inv_grid_width")*50
	ha=sys:r_u32(sect_addon, "inv_grid_height")*50
  
  local b = self.scope_rem_textur   
  
 if not b then
	self.scope_rem_textur =CUIStatic()
	b = self.scope_rem_textur 
	b:SetWindowName("scope_rem_textur ")
	b:SetAutoDelete(true)  
	b:InitTexture("ui\\ui_icon_equipment")   
	b:SetStretchTexture(true)
	self:AttachChild(b)
 end
	b:SetOriginalRect(xa,ya,wa,ha)
	b:Init(x_sco,y_sco,wa/2,ha/2)
	
end

--Рисуем глушитель
if silence == 2 and bit_and(cur_destr_state.addon_flags, 4) == 4 then 	
	isSilencer=true
	sect_addon=sys:r_string(di_section,"silencer_name")
	x_sil=x+(sys:r_u32(di_section, "silencer_x")/2)
	y_sil=y+(sys:r_u32(di_section, "silencer_y")/2)
	xa=sys:r_u32(sect_addon, "inv_grid_x")*50
	ya=sys:r_u32(sect_addon, "inv_grid_y")*50
	wa=sys:r_u32(sect_addon, "inv_grid_width")*50
	ha=sys:r_u32(sect_addon, "inv_grid_height")*50
  
 local b = self.silencer_rem_textur   
  
 if not b then
	self.silencer_rem_textur=CUIStatic()
	b = self.silencer_rem_textur
	b:SetWindowName("silencer_rem_textur")
	b:SetAutoDelete(true)  
	b:InitTexture("ui\\ui_icon_equipment")   
	b:SetStretchTexture(true)
	self:AttachChild(b)
 end
	b:SetOriginalRect(xa,ya,wa,ha)
	b:Init(x_sil,y_sil,wa/2,ha/2)
end

else
a:Init(0,0,0,0)
end	
	local d1 = self.grenade_rem_textur
	local d2 = self.scope_rem_textur
	local d3 = self.silencer_rem_textur
	
	if d1 and not isGrenade  then
	d1:Init(0,0,0,0)
	end

	if d2 and not isScope  then
	d2:Init(0,0,0,0)
	end
	
	if d3 and not isSilencer  then
	d3:Init(0,0,0,0)
	end

end


--Полоска состояния оружия, которое чиним
function repair_dialog:DrawConditionBar(item, x, y)

if x == nil then x = 0 end
if y == nil then y = 0 end
local cond_bar_width = 0
	if item then
	cond_bar_width = (math.floor(item:condition()*100)*1.1)
	x = x - 55--(cond_bar_width/2)
	local c=self.cond_bar
	if not c then
	self.cond_bar = CUIStatic()
    c = self.cond_bar
    c:SetWindowName("cond_bar")
    c:SetAutoDelete(true)
	c:InitTexture("ui\\ui_hud")
    c:SetOriginalRect(347,207,110,10)   
    c:SetStretchTexture(true)
    self:AttachChild(c) 
	end
	if cond_bar_width > 109 then cond_bar_width = 109
	elseif cond_bar_width <= 0 then cond_bar_width = 1 end
    c:SetOriginalRect(346+cond_bar_width,207,1,10)   
	c:Init(x,y,cond_bar_width,10)
	else
	c:Init(0,0,0,0)
	end
end


--Полоска состояния оружия, которое разбираем
function repair_dialog:DrawConditionRemBar(de_item, x, y)

if x == nil then x = 0 end
if y == nil then y = 0 end
local cond_rem_bar_width = 0
	if de_item then
	cond_rem_bar_width = (math.floor(de_item:condition()*100)*1.1)
	x = x - 55--(cond_rem_bar_width/2)
	local c=self.cond_rem_bar
	if not c then
	self.cond_rem_bar = CUIStatic()
    c = self.cond_rem_bar
    c:SetWindowName("cond_rem_bar")
    c:SetAutoDelete(true)
	c:InitTexture("ui\\ui_hud")
    c:SetOriginalRect(347,207,110,10)   
    c:SetStretchTexture(true)
    self:AttachChild(c) 
	end
	if cond_rem_bar_width > 109 then cond_rem_bar_width = 109
	elseif cond_rem_bar_width <= 0 then cond_rem_bar_width = 1 end
	c:SetOriginalRect(346+cond_rem_bar_width,207,1,10)   
	c:Init(x,y,cond_rem_bar_width,10)
	else
	c:Init(0,0,0,0)
	end
end


--Название предмета, который ремонтируем
function repair_dialog:DrawCurItemName(item, x, y)

if x == nil then x = 0 end
if y == nil then y = 0 end
	local w = self.item_name
	if not w then
	self.item_name = CUI3tButton()
    w = self.item_name
    w:SetWindowName("item_name")
    w:SetAutoDelete(true)
    self:AttachChild(w) 
	end
	if item then
	w:SetFont(GetFontLetterica16Russian())
	w:SetTextColor (95,255,255,255)
	w:SetText(item)
	w:Init(x-100,y,200,10)
	else
	w:SetText("")
	w:Init(0,0,0,0)
	end
end


--Название предмета, который разбираем
function repair_dialog:DrawCurRemItemName(de_item, x, y)

if x == nil then x = 0 end
if y == nil then y = 0 end
	local w = self.item_name_rem
	if not w then
	self.item_name_rem = CUI3tButton()
    w = self.item_name_rem
    w:SetWindowName("item_name_rem")
    w:SetAutoDelete(true)
    self:AttachChild(w) 
	end
	if de_item then
	w:SetFont(GetFontLetterica16Russian())
	w:SetTextColor (95,255,255,255)
	w:SetText(de_item)
	w:Init(x-100,y,200,10)
	else
	w:SetText("")
	w:Init(0,0,0,0)
	end
end


--Полоска шансов на успешный ремонт
function repair_dialog:DrawShansBar(item, x, y, destr_item)

if x == nil then x = 0 end
if y == nil then y = 0 end

	local s=self.shans_bar
	if not s then
	self.shans_bar = CUIStatic()
    s = self.shans_bar
    s:SetWindowName("shans_bar")
    s:SetAutoDelete(true)
	s:InitTexture("ui\\ui_hud")
    s:SetOriginalRect(565,110,10,100)   
    s:SetStretchTexture(true)
    self:AttachChild(s) 
	end
	if item then
	local actor_rank = db.actor:character_rank()
	if actor_rank > 1000 then actor_rank = 1000 end
	local coincidence = 0
	if destr_item then
		if item:section() == destr_item:section() then coincidence = 100 end
	end
	local shans_bar_height = (actor_rank - remkit_main.technical_complication(item) + 500 + coincidence)/10
	if shans_bar_height <= 0 then shans_bar_height = 1
	elseif shans_bar_height > 100 then shans_bar_height = 100 end
	s:SetOriginalRect(565,210-shans_bar_height,10,1)   
	x = x - 5
	y = y + (50 - shans_bar_height) --(shans_bar_height/2)
	s:Init(x,y,10,shans_bar_height)
	end
end


function repair_dialog:OnMsgYes()

	if self.msgbox_id == 1 then return
	end
	
	self.msgbox_id = 0
end
