local item_table = {
	"wpn_addon_scope", "wpn_addon_scope_4x", "wpn_addon_scope_susat", "wpn_addon_silencer",
	"wpn_addon_grenade_launcher", "wpn_addon_grenade_launcher_m203",
	"bread", "kolbasa", "conserva", "vodka", "antirad", "medkit", "medkit_army", "medkit_scientic",
	"energy_drink", "bandage",
	"device_pda", "device_torch", "detector_simple", "detector_advanced", "detector_elite",
	"device_pda_fang", "esc_trader_habar", "device_pda_military", "device_pda_old",
	"device_pda_garbage_traitor", "device_pda_comendant", "device_pda_freedom",
	"device_pda_bloodsucker", "device_pda_digger", "mar_quest_wpn_pm_1",
	"mar_quest_wpn_ak74u_1", "mar_quest_af_cristall_flower_1", "mar_quest_scout_pda",
	"mar_quest_novice_outfit_1", "mil_quest_af_fuzz_kolobok", "mil_device_pda_lost_squard",
	"esc_device_pda_driver", "agr_pda_for_secret_trader", "agr_map_animals",
	"red_forest_pda_map", "red_forest_pda_map_2"
}
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_7h14",
	"ammo_223_fmj",			"ammo_gauss",			"ammo_9x39_pab9",		"ammo_9x39_ap",
	"ammo_12x70_buck",		"ammo_12x76_dart",		"ammo_12x76_zhekan",	"ammo_og-7b",
	"ammo_vog-25p",			"ammo_vog-25",			"ammo_m209",			"ammo_minigame",
	"grenade_f1",			"grenade_rgd5",			"grenade_gd-05"
}
local wpn_table = {
	"wpn_pm",	"wpn_pm_up",	"wpn_pm_minigame",	"wpn_pm_9x19",
	"wpn_pb",	"wpn_fort",		"wpn_hpsa",
	"wpn_beretta",	"wpn_beretta_minigame",	"wpn_walther",	"wpn_sig220",
	"wpn_sig550_minigame",	"wpn_colt1911",	"wpn_usp",
	"wpn_desert_eagle",	"wpn_desert_eagle_up",
	"wpn_bm16",	"wpn_toz34",
	"wpn_wincheaster1300",	"wpn_spas12",
	"wpn_mp5",		"wpn_mp5_minigame",
	"wpn_ak74u",	"wpn_ak74",	"wpn_ak74_up",
	"wpn_ak74_up2",	"wpn_ak74_minigame",	"wpn_ak74u_minigame",
	"wpn_abakan",	"wpn_l85",	"wpn_sig550",
	"wpn_groza",	"wpn_val",	"wpn_val_minigame",
	"wpn_vintorez",	"wpn_vintorez_up",	"wpn_svu",	"wpn_svd",
	"wpn_rg-6",		"wpn_rpg7",	"wpn_g36",	"wpn_fn2000",	"wpn_pkm",
	"wpn_gauss",	"wpn_gauss_aes",
	"wpn_lr300",	"wpn_lr300_minigame",	"wpn_lr300_up2"
}
local art_table = {
	"af_medusa",		"af_cristall_flower",	"af_night_star",
	"af_vyvert",		"af_gravi",				"af_gold_fish",
	"af_cristall",		"af_fireball",			"af_dummy_glassbeads",
	"af_eye",			"af_fire",				"af_blood",
	"af_mincer_meat",	"af_soul",				"af_fuzz_kolobok",
	"af_baloon",		"af_glass",				"af_electra_sparkler",
	"af_electra_flash",	"af_electra_moonlight",	"af_dummy_battery",
	"af_dummy_dummy",	"af_ice",				"af_compass"
}
local outf_table = {
	"novice_outfit", "bandit_outfit", "stalker_outfit",
	"cs_light_outfit", "cs_heavy_outfit",
	"svoboda_light_outfit", "svoboda_heavy_outfit", "svoboda_exo_outfit",
	"dolg_outfit", "dolg_heavy_outfit",
	"scientific_outfit", "specops_outfit", "exo_outfit", "military_outfit"
}

class "spawn_item" (CUIListItemEx)

function spawn_item:__init() super()
	self.text					= CUIStatic()
	self:AttachChild			(self.text)
	self.text:SetFont			(GetFontLetterica18Russian())
	self.text:SetTextColor		(255,216,186,140)
end

class "spawn_item_dialog" (CUIScriptWnd)

function spawn_item_dialog:__init() super()
   self:InitControls()
   self:InitCallBacks()
end

function spawn_item_dialog:__finalize()
end

function spawn_item_dialog:InitControls()
	self:SetWndRect(Frect():set(0,0,1024,768))
	local xml = CScriptXmlInit()
	xml:ParseFile	("ui_si_dlg.xml")
	xml:InitStatic	("background", self)	-- рамка
	self.list = xml:InitList("list",self)	-- список
	self.list:ShowSelectedItem(true)
	self:Register(self.list, "list_window")
	self:Register(xml:Init3tButton("btn_ammo", self),"btn_ammo")	-- верхние кнопки
	self:Register(xml:Init3tButton("btn_wpn", self),"btn_wpn")
	self:Register(xml:Init3tButton("btn_art", self),"btn_art")
	self:Register(xml:Init3tButton("btn_item", self),"btn_item")
	self:Register(xml:Init3tButton("btn_outf", self),"btn_outf")
	self:Register(xml:Init3tButton("btn_create", self),"btn_create")	-- нижние кнопки
	self:Register(xml:Init3tButton("btn_close", self),"btn_close")
end

function spawn_item_dialog:InitCallBacks()
	self:AddCallback("btn_ammo",	ui_events.BUTTON_CLICKED,	self.FillList_ammo, self)
	self:AddCallback("btn_wpn",		ui_events.BUTTON_CLICKED,	self.FillList_wpn, self)
	self:AddCallback("btn_art",		ui_events.BUTTON_CLICKED,	self.FillList_art, self)
	self:AddCallback("btn_item",	ui_events.BUTTON_CLICKED,	self.FillList_item, self)
	self:AddCallback("btn_outf",	ui_events.BUTTON_CLICKED,	self.FillList_outf, self)
	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)
end

function spawn_item_dialog:FillList_ammo()
	self.list:RemoveAll()
	for i = 1, #ammo_table do
		self:AddItemToList(ammo_table[i])
	end
end
function spawn_item_dialog:FillList_wpn()
	self.list:RemoveAll()
	for i = 1, #wpn_table do
		self:AddItemToList(wpn_table[i])
	end
end
function spawn_item_dialog:FillList_art()
	self.list:RemoveAll()
	for i = 1, #art_table do
		self:AddItemToList(art_table[i])
	end
end
function spawn_item_dialog:FillList_item()
	self.list:RemoveAll()
	for i = 1, #item_table do
		self:AddItemToList(item_table[i])
	end
end
function spawn_item_dialog:FillList_outf()
	self.list:RemoveAll()
	for i = 1, #outf_table do
		self:AddItemToList(outf_table[i])
	end
end
function spawn_item_dialog:AddItemToList(item_name)
	local _itm				= spawn_item()
	_itm.text:SetText		(item_name)
	self.list:AddItem		(_itm)
end

function spawn_item_dialog:OnButton_create_clicked()	
	if self.list:GetSize()==0 then 
		return 
	end
	local index = self.list:GetSelectedItem()
	if index == -1 then 
		return 
	end
	local item = self.list:GetItem(index).text:GetText()
	if alife() and db.actor:alive() then
		alife():create(item, db.actor:position(), 0, 0, db.actor:id())
	end
end

function spawn_item_dialog:OnButton_close_clicked()
	self:GetHolder():start_stop_menu	(self,true)
	self.owner:Show						(true)
	if level.present() and db.actor and db.actor:alive() then
		get_console():execute("main_menu off")
	end
end

function spawn_item_dialog:OnKeyboard(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 main()
end
