local artefacts_table = {
	"af_medusa",
	"af_medusa_ars_1",
	"af_medusa_ars_2",
	"af_medusa_ars_3",
	"af_medusa_ars_4",
	"af_medusa_ars_5",
	"af_cristall_flower",
	"af_cristall_flower_ars_1",
	"af_cristall_flower_ars_2",
	"af_cristall_flower_ars_3",
	"af_cristall_flower_ars_4",
	"af_cristall_flower_ars_5",
	"af_night_star",
	"af_night_star_ars_1",
	"af_night_star_ars_2",
	"af_night_star_ars_3",
	"af_night_star_ars_4",
	"af_night_star_ars_5",
	"af_vyvert",
	"af_vyvert_ars_1",
	"af_vyvert_ars_2",
	"af_vyvert_ars_3",
	"af_vyvert_ars_4",
	"af_vyvert_ars_5",
	"af_gravi",
	"af_gravi_ars_1",
	"af_gravi_ars_2",
	"af_gravi_ars_3",
	"af_gravi_ars_4",
	"af_gravi_ars_5",
	"af_gold_fish",
	"af_gold_fish_ars_1",
	"af_gold_fish_ars_2",
	"af_gold_fish_ars_3",
	"af_gold_fish_ars_4",
	"af_gold_fish_ars_5",
	"af_cristall",
	"af_cristall_ars_1",
	"af_cristall_ars_2",
	"af_cristall_ars_3",
	"af_cristall_ars_4",
	"af_cristall_ars_5",
	"af_fireball",
	"af_fireball_ars_1",
	"af_fireball_ars_2",
	"af_fireball_ars_3",
	"af_fireball_ars_4",
	"af_fireball_ars_5",
	"af_dummy_glassbeads",
	"af_dummy_glassbeads_ars_1",
	"af_dummy_glassbeads_ars_2",
	"af_dummy_glassbeads_ars_3",
	"af_dummy_glassbeads_ars_4",
	"af_dummy_glassbeads_ars_5",
	"af_eye",
	"af_eye_ars_1",
	"af_eye_ars_2",
	"af_eye_ars_3",
	"af_eye_ars_4",
	"af_eye_ars_5",
	"af_fire",
	"af_fire_ars_1",
	"af_fire_ars_2",
	"af_fire_ars_3",
	"af_fire_ars_4",
	"af_fire_ars_5",
	"af_blood",
	"af_blood_ars_1",
	"af_blood_ars_2",
	"af_blood_ars_3",
	"af_blood_ars_4",
	"af_blood_ars_5",
	"af_mincer_meat",
	"af_mincer_meat_ars_1",
	"af_mincer_meat_ars_2",
	"af_mincer_meat_ars_3",
	"af_mincer_meat_ars_4",
	"af_mincer_meat_ars_5",
	"af_soul",
	"af_soul_ars_1",
	"af_soul_ars_2",
	"af_soul_ars_3",
	"af_soul_ars_4",
	"af_soul_ars_5",
	"af_fuzz_kolobok",
	"af_fuzz_kolobok_ars_1",
	"af_fuzz_kolobok_ars_2",
	"af_fuzz_kolobok_ars_3",
	"af_fuzz_kolobok_ars_4",
	"af_fuzz_kolobok_ars_5",
	"af_baloon",
	"af_baloon_ars_1",
	"af_baloon_ars_2",
	"af_baloon_ars_3",
	"af_baloon_ars_4",
	"af_baloon_ars_5",
	"af_glass",
	"af_glass_ars_1",
	"af_glass_ars_2",
	"af_glass_ars_3",
	"af_glass_ars_4",
	"af_glass_ars_5",
	"af_electra_sparkler",
	"af_electra_sparkler_ars_1",
	"af_electra_sparkler_ars_2",
	"af_electra_sparkler_ars_3",
	"af_electra_sparkler_ars_4",
	"af_electra_sparkler_ars_5",
	"af_electra_flash",
	"af_electra_flash_1",
	"af_electra_flash_2",
	"af_electra_flash_3",
	"af_electra_flash_4",
	"af_electra_flash_5",
	"af_electra_moonlight",
	"af_electra_moonlight_ars_1",
	"af_electra_moonlight_ars_2",
	"af_electra_moonlight_ars_3",
	"af_electra_moonlight_ars_4",
	"af_electra_moonlight_ars_5",
	"af_dummy_battery",
	"af_dummy_battery_ars_1",
	"af_dummy_battery_ars_2",
	"af_dummy_battery_ars_3",
	"af_dummy_battery_ars_4",
	"af_dummy_battery_ars_5",
	"af_dummy_dummy",
	"af_dummy_dummy_ars_1",
	"af_dummy_dummy_ars_2",
	"af_dummy_dummy_ars_3",
	"af_dummy_dummy_ars_4",
	"af_dummy_dummy_ars_5",
	"af_ice",
	"af_ice_ars_1",
	"af_ice_ars_2",
	"af_ice_ars_3",
	"af_ice_ars_4",
	"af_ice_ars_5",
	"af_compass",
	"af_oasis_heart",
	"jup_b1_half_artifact",
	"af_quest_b14_twisted",
}
local outfits_table = {
	"helm_respirator",
	"helm_respirator_gp7",
	"helm_hardhat",
	"helm_protective",
	"helm_tactic",
	"helm_battle",
	"helm_battle_dolg",
	"helm_respirator_joker",
	"helm_hardhat_snag",
	"novice_outfit",
	"stalker_outfit",
	"svoboda_light_outfit",
	"dolg_outfit",
	"scientific_outfit",
	"cs_heavy_outfit",
	"svoboda_heavy_outfit",
	"specops_outfit",
	"specops_outfit_2",
	"military_outfit",
	"dolg_heavy_outfit",
	"exo_outfit",
	"stalker_outfit_barge",
	"neutral_assault_outfit",
	"bandit_outfit",
	"bandit_brownrain_outfit",
	"bandit_blackrain_outfit",
	"bandit_light_outfit",
	"soldier_outfit",
	"svoboda_outfit",
	"svoboda_exo_outfit",
	"dolg_scientific_outfit",
	"dolg_exo_outfit",
	"merc_outfit",
	"merc_exo_outfit",
	"monolith_outfit",
	"monolith_scientific_outfit",
	"monolith_assault_outfit",
	"monolith_exo_outfit",
	"ecolog_outfit",
	"svoboda_scientific_outfit",
	"stalker_medic_outfit"
}
local devices_table = {
	"device_torch",
	"detector_simple",
	"detector_advanced",
	"detector_elite",
	"detector_scientific",
	"guitar_a",
	"harmonica_a",
	"hand_radio",
	"anomaly_scaner",
	"sleeping_bag",
	"inventory_ruck",
	"notepad",
	"ars_mutanter_knife_lite",
	"ars_mutanter_knife_ext",
	"ars_mutanter_knife_pro",
	"ars_mutanter_knife_uniq",
	"termos_small_full_cofee",
	"termos_small_full_tea",
	"termos_small_full_voda",
	"termos_full_cofee",
	"termos_full_tea",
	"termos_full_voda",
	"mutant_dog_tail",
	"mutant_boar_leg",
	"mutant_krovosos_jaw",
	"mutant_flesh_eye",
	"mutant_psevdodog_tail",
	"mutant_snork_leg",
	"mutant_face_tushkano",
	"mutant_psevdogigant_hand",
	"mutant_hand_kontroler",
	"mutant_burer_hand",
	"mutant_chimera_kogot",
}
local food_and_drugs_table = {
	"bandage",
	"antirad",
	"medkit",
	"medkit_army",
	"medkit_scientic",
	"drug_booster",
	"drug_coagulant",
	"drug_psy_blockade",
	"drug_antidot",
	"drug_radioprotector",
	"drug_anabiotic",
--	"drug_antipohmel",
--	"drug_cardiosimulator",
	"bread",
	"kolbasa",
	"conserva",
	"vodka",
	"energy_drink",
	"sardina",
	"pivo",
	"food_gde-3",
	"food_cpp5",
}
local wpn_addons_table = {
	"wpn_addon_scope",
	"wpn_addon_scope_x2.7",
	"wpn_addon_scope_detector",
	"wpn_addon_scope_night",
	"wpn_addon_scope_susat",
	"wpn_addon_scope_susat_x1.6",
	"wpn_addon_scope_susat_custom",
	"wpn_addon_scope_susat_dusk",
	"wpn_addon_scope_susat_night",
	"wpn_addon_silencer",
	"wpn_addon_grenade_launcher",
	"wpn_addon_grenade_launcher_m203",
}
local weapons_table = {
	"wpn_pm",
	"wpn_pb",
	"wpn_fort",
	"wpn_hpsa",
	"wpn_beretta",
	"wpn_walther",
	"wpn_sig220",
	"wpn_colt1911",
	"wpn_usp",
	"wpn_desert_eagle",
	"wpn_bm16",
	"wpn_toz34",
	"wpn_wincheaster1300",
	"wpn_spas12",
	"wpn_protecta",
	"wpn_ak74u",
	"wpn_mp5",
	"wpn_ak74",
	"wpn_abakan",
	"wpn_l85",
	"wpn_lr300",
	"wpn_sig550",
	"wpn_groza",
	"wpn_val",
	"wpn_vintorez",
	"wpn_svu",
	"wpn_svd",
	"wpn_rg-6",
	"wpn_rpg7",
	"wpn_g36",
	"wpn_fn2000",
	"wpn_pkm",
	"wpn_gauss",
	"wpn_pm_actor",
	"wpn_fort_snag",
	"wpn_sig220_nimble",
	"wpn_usp_nimble",
	"wpn_desert_eagle_nimble",
	"wpn_wincheaster1300_trapper",
	"wpn_spas12_nimble",
	"wpn_protecta_nimble",
	"wpn_ak74u_snag",
	"wpn_mp5_nimble",
	"wpn_sig550_luckygun",
	"wpn_groza_nimble",
	"wpn_vintorez_nimble",
	"wpn_svu_nimble",
	"wpn_svd_nimble",
	"wpn_g36_nimble",
	"wpn_fn2000_nimble",
	"wpn_pkm_zulus",
	"pri_a17_gauss_rifle",
	"grenade_f1",
	"grenade_rgd5",
	"grenade_gd-05",
	"grenade_light",
}
local info_table ={
 	"jup_a9_conservation_info",
	"jup_a9_power_info",
	"jup_a9_way_info",
	"jup_a9_evacuation_info",
	"jup_a9_meeting_info",
	"jup_a9_losses_info",
	"jup_a9_delivery_info",
	"jup_b10_ufo_memory",
	"jup_b10_ufo_memory_2",
	"jup_b10_notes_01",
	"jup_b10_notes_02",
	"jup_b10_notes_03",
	"jup_b205_sokolov_note",
	"jup_b206_plant",
	"jup_b209_monster_scanner",
	"jup_b200_tech_materials_wire",
	"jup_b200_tech_materials_acetone",
	"jup_b200_tech_materials_textolite",
	"jup_b200_tech_materials_transistor",
	"jup_b200_tech_materials_capacitor",
	"jup_b202_bandit_pda",
	"device_flash_snag",
	"jup_b9_blackbox",
 	"jup_b32_scanner_device",
	"jup_b46_duty_founder_pda",
	"jup_b207_merc_pda_with_contract",
	"jup_b47_jupiter_products_info",
	"jup_b47_merc_pda",
	"toolkit_1",
	"toolkit_2",
	"toolkit_3",
	"zat_b33_safe_container",
	"zat_b57_gas",
	"zat_b12_key_1",
	"zat_b12_key_2",
	"zat_b12_documents_1",
	"zat_b12_documents_2",
 	"device_pda_port_bandit_leader",
	"zat_b40_notebook",
	"zat_b40_pda_1",
	"zat_b40_pda_2",
	"device_pda_zat_b5_dealer",
	"zat_b20_noah_pda",
	"zat_a23_access_card",
	"zat_a23_gauss_rifle_docs",
	"zat_b44_barge_pda",
	"zat_b39_joker_pda",
	"zat_b22_medic_pda",
	"pri_b35_lab_x8_key",
	"pri_b306_envoy_pda",
	"pri_b36_monolith_hiding_place_pda",
	"pri_a25_explosive_charge_item",
	"pri_a19_american_experiment_info",
	"pri_a19_lab_x16_info",
	"pri_a19_lab_x10_info",
	"pri_a19_lab_x7_info",
	"pri_a19_lab_x18_info",
	"zat_a23_labx8_key",
	"lx8_service_instruction",
	"zaton_visited",
	"jupiter_visited",
	"underpass_visited",
	"pripyat_visited",
	"labx8_visited",
	"detective_reward_p",
	"ars_headshoter_reward_p",
	"ars_medic_reward_p",
	"ars_medic_reward",
	"ars_potroshitel_reward",
	"ars_headshoter_precond",
	"ars_medic_precond",
	"ars_potroshitel_precond",
	"ars_scout_precond",
	"ars_crower_precond",
}
local ammo_table = {
	"ammo_9x18_fmj",
	"ammo_9x18_pmm",
	"ammo_9x19_fmj",
	"ammo_9x19_pbp",
	"ammo_11.43x23_fmj",
	"ammo_11.43x23_hydro",
	"ammo_5.45x39_fmj",
	"ammo_5.45x39_ap",
	"ammo_5.56x45_ss190",
	"ammo_5.56x45_ap",
	"ammo_pkm_100",
	"ammo_7.62x54_7h1",
	"ammo_gauss",
	"ammo_gauss_cardan",
	"ammo_9x39_pab9",
	"ammo_9x39_ap",
	"ammo_9x39_sp5",
	"ammo_12x70_buck",
	"ammo_12x76_zhekan",
	"ammo_og-7b",
	"ammo_vog-25",
	"ammo_m209"
}
local monster_table = {
	"bloodsucker_normal",
	"bloodsucker_strong",
	"boar_normal",
	"boar_strong",
	"burer_normal",
	"chimera_normal",
	"m_controller_normal",
	"controller_tubeman",
	"dog_weak",
	"dog_strong",
	"dog_cute",
	"flesh_normal",
	"flesh_strong",
	"flesh_group",
	"gigant_normal",
	"pseudodog_normal",
	"psy_dog",
	"psy_dog_phantom",
	"psy_dog_normal",
	"snork_weak",
	"snork_normal",
	"snork_strong",
	"snork_indoor",
	"snork_outdoor",
	"snork_jumper",
	"tushkano_normal"
}
local npc_table = {
	"sim_default_zombied_1",
	"sim_default_zombied_2",
	"sim_default_zombied_3",
	"sim_default_zombied_4",
	"sim_default_bandit_0",
	"sim_default_bandit_1",
	"sim_default_bandit_2",
	"sim_default_bandit_3",
	"sim_default_bandit_4",
	"sim_default_monolith_0",
	"sim_default_monolith_1",
	"sim_default_monolith_2",
	"sim_default_monolith_3",
	"sim_default_monolith_4"
}


class "spawn_item" (CUIListBoxItem)
function spawn_item:__init(height) super(height)
	self.text = self:GetTextItem()
	self:SetTextColor(GetARGB(255, 210, 210, 210))
	self.text:SetFont(GetFontLetterica18Russian())
	self.text:SetWndSize(vector2():set(400,height))
	self.text:SetEllipsis(true)
end

class "spawn_item_dialog" (CUIScriptWnd)
function spawn_item_dialog:__init() super()
	local xml = CScriptXmlInit()
	local ctrl
	xml:ParseFile("ui_spawn_dlg.xml")
	ctrl = xml:InitFrame("background",self)
	self:SetWndPos(vector2():set(100,100))
	self:SetWndSize(vector2():set(ctrl:GetWidth(), ctrl:GetHeight()))
	self:Register(xml:Init3tButton("btn_weapons",self), "btn_weapons")
	self:Register(xml:Init3tButton("btn_addons",self), "btn_addons")
	self:Register(xml:Init3tButton("btn_outfits",self), "btn_outfits")
	self:Register(xml:Init3tButton("btn_devices",self), "btn_devices")
	self:Register(xml:Init3tButton("btn_ammo",self), "btn_ammo")
	self:Register(xml:Init3tButton("btn_artefacts",self), "btn_artefacts")
	self:Register(xml:Init3tButton("btn_food",self), "btn_food")
	self:Register(xml:Init3tButton("btn_info",self), "btn_info")
	self:Register(xml:Init3tButton("btn_monsters",self), "btn_monsters")
	self:Register(xml:Init3tButton("btn_npc",self), "btn_npc")
	self.list = xml:InitListBox("list",self)
	self.list:ShowSelectedItem(true)
	self:Register(self.list, "list_window")
	self.check = xml:InitCheck("check_own_to_actor",self)
	self.check:SetCheck(true)
	self:Register(xml:Init3tButton("btn_create",self), "btn_create")
	self:Register(xml:Init3tButton("btn_close",self), "btn_close")
	self:AddCallback("btn_create",ui_events.BUTTON_CLICKED,self.OnButton_create_clicked,self)
	self:AddCallback("btn_close",ui_events.BUTTON_CLICKED,self.OnButton_close_clicked,self)
	self:AddCallback("list_window",ui_events.WINDOW_LBUTTON_DB_CLICK,self.OnButton_create_clicked,self)
	self:AddCallback("btn_artefacts",ui_events.BUTTON_CLICKED,self.OnButton_artefacts_clicked,self)
	self:AddCallback("btn_outfits",ui_events.BUTTON_CLICKED,self.OnButton_outfits_clicked,self)
	self:AddCallback("btn_devices",ui_events.BUTTON_CLICKED,self.OnButton_devices_clicked,self)
	self:AddCallback("btn_food",ui_events.BUTTON_CLICKED,self.OnButton_food_clicked,self)
	self:AddCallback("btn_weapons",ui_events.BUTTON_CLICKED,self.OnButton_weapons_clicked,self)
	self:AddCallback("btn_addons",ui_events.BUTTON_CLICKED,self.OnButton_addons_clicked,self)
	self:AddCallback("btn_info",ui_events.BUTTON_CLICKED,self.OnButton_info_clicked,self)
	self:AddCallback("btn_ammo",ui_events.BUTTON_CLICKED,self.OnButton_ammo_clicked,self)
	self:AddCallback("btn_monsters",ui_events.BUTTON_CLICKED,self.OnButton_monsters_clicked,self)
	self:AddCallback("btn_npc",ui_events.BUTTON_CLICKED,self.OnButton_npc_clicked,self)
	self:FillList(weapons_table)
end
function spawn_item_dialog:__finalize()
end

function spawn_item_dialog:FillList(tbl)
	self.list:Clear()
	for i = 1, #tbl do
		self:AddItemToList(tbl[i])
	end
end

function spawn_item_dialog:OnButton_artefacts_clicked()
	self.check:SetCheck(true)
	self:FillList(artefacts_table)
end
function spawn_item_dialog:OnButton_outfits_clicked()
	self.check:SetCheck(true)
	self:FillList(outfits_table)
end
function spawn_item_dialog:OnButton_devices_clicked()
	self.check:SetCheck(true)
	self:FillList(devices_table)
end
function spawn_item_dialog:OnButton_food_clicked()
	self.check:SetCheck(true)
	self:FillList(food_and_drugs_table)
end
function spawn_item_dialog:OnButton_weapons_clicked()
	self.check:SetCheck(true)
	self:FillList(weapons_table)
end
function spawn_item_dialog:OnButton_addons_clicked()
	self.check:SetCheck(true)
	self:FillList(wpn_addons_table)
end
function spawn_item_dialog:OnButton_info_clicked()
	self.check:SetCheck(true)
	self:FillList(info_table)
end
function spawn_item_dialog:OnButton_ammo_clicked()
	self.check:SetCheck(true)
	self:FillList(ammo_table)
end
function spawn_item_dialog:OnButton_monsters_clicked()
	self.check:SetCheck(false)
	self:FillList(monster_table)
end
function spawn_item_dialog:OnButton_npc_clicked()
	self.check:SetCheck(false)
	self:FillList(npc_table)
end

function spawn_item_dialog:OnButton_create_clicked()
	if self.list:GetSize()==0 then
		return
	end
	local item = self.list:GetSelectedItem()
	if not(item) then
		return
	end
	local item_text = item.text:GetText()
	local id = -1
	local actor = db.actor
	local pos = actor:position()
	if self.check:GetCheck() then
		id = actor:id()
	else
		local dir = actor:direction()
		pos = pos:add(dir:mul(5))
	end
	if system_ini():section_exist(item_text) and system_ini():line_exist(item_text, "class") then
		alife():create(item_text, pos, actor:level_vertex_id(), actor:game_vertex_id(), id)
	else
		if not actor:has_info(item_text) then
			actor:give_info_portion(item_text)
		end
	end
end

function spawn_item_dialog:OnButton_close_clicked()
	local console = get_console()
	console:execute("main_menu off")
	xr_s.on_main_menu_off()
	_G.si_dlg = nil
end

function spawn_item_dialog:OnKeyboard(dik, keyboard_action)
	CUIScriptWnd.OnKeyboard(self,dik,keyboard_action)
	local bind = dik_to_bind(dik)
	if bind == key_bindings.kQUIT then
		self:OnButton_close_clicked()
	else
		if dik==28 then
			self:OnButton_create_clicked()
		end
	end
	return true
end

function spawn_item_dialog:AddItemToList(item_name)
	local _itm = spawn_item(22)
	_itm.text:SetText(item_name)
	self.list:AddExistingItem(_itm)
end

function main()
	if _G.si_dlg==nil then
		_G.si_dlg = spawn_item_dialog()
	end
	_G.si_dlg:ShowDialog(true)
end