-- Atlas (Spawn Menu) Mod 1.1
-- By: Helios (helios-50@hotmail.com)

class "atlas" (CUIScriptWnd)

function atlas:__init(owner,action) super()

	self.action = action
	self.owner = owner
	self:InitControls()
	self:InitCallBacks()
	end

function atlas:__finalize() end

function atlas:InitControls()

	self:SetWndRect		 (Frect():set(0,0,1000,1000))

	local xml = CScriptXmlInit()
	xml:ParseFile("ui_atlas3.xml")
	xml:InitStatic("background", self)

	self:Register(xml:Init3tButton("title", self),"title")
	self:Register(xml:Init3tButton("caption", self),"caption")
	self:Register(xml:Init3tButton("caption2", self),"caption2")
	self:Register(xml:InitEditBox("edit_box", self), "edit_box")
	self:Register(xml:Init3tButton("btn_0", self),"btn_0")
	self:Register(xml:Init3tButton("btn_1", self),"btn_1")
	self:Register(xml:Init3tButton("btn_2", self),"btn_2")
	self:Register(xml:Init3tButton("btn_3", self),"btn_3")
	self:Register(xml:Init3tButton("btn_4", self),"btn_4")
	self:Register(xml:Init3tButton("btn_5", self),"btn_5")
	self:Register(xml:Init3tButton("btn_6", self),"btn_6")
	self:Register(xml:Init3tButton("btn_7", self),"btn_7")
	self:Register(xml:Init3tButton("btn_8", self),"btn_8")
	self:Register(xml:Init3tButton("btn_9", self),"btn_9")
	self:Register(xml:Init3tButton("btn_10", self),"btn_10")
	self:Register(xml:Init3tButton("btn_11", self),"btn_11")
	self:Register(xml:Init3tButton("btn_12", self),"btn_12")
	self:Register(xml:Init3tButton("btn_13", self),"btn_13")
	self:Register(xml:Init3tButton("btn_14", self),"btn_14")
	self:Register(xml:Init3tButton("btn_15", self),"btn_15")
	self:Register(xml:Init3tButton("btn_16", self),"btn_16")
	self:Register(xml:Init3tButton("btn_17", self),"btn_17")
	self:Register(xml:Init3tButton("btn_18", self),"btn_18")
	self:Register(xml:Init3tButton("btn_19", self),"btn_19")
	self:Register(xml:Init3tButton("btn_20", self),"btn_20")
	self:Register(xml:Init3tButton("btn_21", self),"btn_21")
	self:Register(xml:Init3tButton("btn_22", self),"btn_22")
	self:Register(xml:Init3tButton("btn_23", self),"btn_23")
	self:Register(xml:Init3tButton("btn_24", self),"btn_24")
	self:Register(xml:Init3tButton("btn_25", self),"btn_25")
	self:Register(xml:Init3tButton("btn_26", self),"btn_26")
	self:Register(xml:Init3tButton("btn_27", self),"btn_27")

local caption = self:GetButton("caption")
local caption2 = self:GetButton("caption2")
local title = self:GetButton("title")
local btn_0 = self:GetButton("btn_0")
local btn_1 = self:GetButton("btn_1")
local btn_2 = self:GetButton("btn_2")
local btn_3 = self:GetButton("btn_3")
local btn_4 = self:GetButton("btn_4")
local btn_5 = self:GetButton("btn_5")
local btn_6 = self:GetButton("btn_6")
local btn_7 = self:GetButton("btn_7")
local btn_8 = self:GetButton("btn_8")
local btn_9 = self:GetButton("btn_9")
local btn_10 = self:GetButton("btn_10")
local btn_11 = self:GetButton("btn_11")
local btn_12 = self:GetButton("btn_12")
local btn_13 = self:GetButton("btn_13")
local btn_14 = self:GetButton("btn_14")
local btn_15 = self:GetButton("btn_15")
local btn_16 = self:GetButton("btn_16")
local btn_17 = self:GetButton("btn_17")
local btn_18 = self:GetButton("btn_18")
local btn_19 = self:GetButton("btn_19")
local btn_20 = self:GetButton("btn_20")
local btn_21 = self:GetButton("btn_21")
local btn_22 = self:GetButton("btn_22")
local btn_23 = self:GetButton("btn_23")
local btn_24 = self:GetButton("btn_24")
local btn_25 = self:GetButton("btn_25")
local btn_26 = self:GetButton("btn_26")
local btn_27 = self:GetButton("btn_27")
 
if self.action == "spawn" then

    	caption:SetText("Quantity Console:")
    	caption2:SetText("Enter the quantity of ammo you want to spawn, or click a button.")
    	title:SetText("Atlas (Spawn Menu) Mod 1.1 - Ammo Spawner")
    	btn_0:SetText("Quit")
    	btn_1:SetText("9x18 mm")
    	btn_2:SetText("9x19mm FMJ")
    	btn_3:SetText("5.45x39 mm")
    	btn_4:SetText("5.56x45 mm SS109")
    	btn_5:SetText("VOG-25")
    	btn_6:SetText("RGD-5")
    	btn_7:SetText("9x18 mm +P+")
    	btn_8:SetText("9x19mm PB1s")
    	btn_9:SetText("5.45x39 mm BP")
    	btn_10:SetText("5.56x45 mm AP")
    	btn_11:SetText("VOG-25R")
    	btn_12:SetText("F1")
    	btn_13:SetText("12x76 slug")
    	btn_14:SetText("9x39 mm PAB-9")
    	btn_15:SetText("7.62x54 mm 7N1")
    	btn_16:SetText(".45ACP")
    	btn_17:SetText("OG-7V")
    	btn_18:SetText("GD-05")
    	btn_19:SetText("12x76 dart")
    	btn_20:SetText("9x39 mm SP-5")
    	btn_21:SetText("7.62x54 mm BP")
    	btn_22:SetText(".45ACP Hydro-Shock")
    	btn_23:SetText("M209")
    	btn_24:SetText("12x70 shot")
    	btn_25:SetText("9x39 mm SP-6")
    	btn_26:SetText("7.62x54R mm 7N14")
    	btn_27:SetText("Gauss")

end

end

function atlas:InitCallBacks()

	self:AddCallback("btn_0", ui_events.BUTTON_CLICKED, self.on_quit, self)
	self:AddCallback("btn_1", ui_events.BUTTON_CLICKED, self.spawn_ammo_9x18_fmj, self)
	self:AddCallback("btn_2", ui_events.BUTTON_CLICKED, self.spawn_ammo_9x19_fmj, self)
	self:AddCallback("btn_3", ui_events.BUTTON_CLICKED, self.spawn_ammo_545x39_fmj, self)
	self:AddCallback("btn_4", ui_events.BUTTON_CLICKED, self.spawn_ammo_556x45_ss190, self)
	self:AddCallback("btn_5", ui_events.BUTTON_CLICKED, self.spawn_ammo_vog25, self)
	self:AddCallback("btn_6", ui_events.BUTTON_CLICKED, self.spawn_grenade_rgd5, self)
	self:AddCallback("btn_7", ui_events.BUTTON_CLICKED, self.spawn_ammo_9x18_pmm, self)
	self:AddCallback("btn_8", ui_events.BUTTON_CLICKED, self.spawn_ammo_9x19_pbp, self)
	self:AddCallback("btn_9", ui_events.BUTTON_CLICKED, self.spawn_ammo_545x39_ap, self)
	self:AddCallback("btn_10", ui_events.BUTTON_CLICKED, self.spawn_ammo_556x45_ap, self)
	self:AddCallback("btn_11", ui_events.BUTTON_CLICKED, self.spawn_ammo_vog25p, self)
	self:AddCallback("btn_12", ui_events.BUTTON_CLICKED, self.spawn_grenade_f1, self)
	self:AddCallback("btn_13", ui_events.BUTTON_CLICKED, self.spawn_ammo_12x76_zhekan, self)
	self:AddCallback("btn_14", ui_events.BUTTON_CLICKED, self.spawn_ammo_9x39_pab9, self)
	self:AddCallback("btn_15", ui_events.BUTTON_CLICKED, self.spawn_ammo_762x54_7h1, self)
	self:AddCallback("btn_16", ui_events.BUTTON_CLICKED, self.spawn_ammo_1143x23_fmj, self)
	self:AddCallback("btn_17", ui_events.BUTTON_CLICKED, self.spawn_ammo_og7b, self)
	self:AddCallback("btn_18", ui_events.BUTTON_CLICKED, self.spawn_grenade_gd05, self)
	self:AddCallback("btn_19", ui_events.BUTTON_CLICKED, self.spawn_ammo_12x76_dart, self)
	self:AddCallback("btn_20", ui_events.BUTTON_CLICKED, self.spawn_ammo_9x39_sp5, self)
	self:AddCallback("btn_21", ui_events.BUTTON_CLICKED, self.spawn_ammo_762x54_ap, self)
	self:AddCallback("btn_22", ui_events.BUTTON_CLICKED, self.spawn_ammo_1143x23_hydro, self)
	self:AddCallback("btn_23", ui_events.BUTTON_CLICKED, self.spawn_ammo_m209, self)
	self:AddCallback("btn_24", ui_events.BUTTON_CLICKED, self.spawn_ammo_12x70_buck, self)
	self:AddCallback("btn_25", ui_events.BUTTON_CLICKED, self.spawn_ammo_9x39_ap, self)
	self:AddCallback("btn_26", ui_events.BUTTON_CLICKED, self.spawn_ammo_762x54_7h14, self)
	self:AddCallback("btn_27", ui_events.BUTTON_CLICKED, self.spawn_ammo_gauss, self)

end

function atlas:OnKeyboard(dik, keyboard_action)

	CUIScriptWnd.OnKeyboard(self,dik,keyboard_action)

	if keyboard_action == ui_events.WINDOW_KEY_PRESSED then
		
	if dik == DIK_keys.DIK_ESCAPE then
	self:on_quit()
	end	

	end

	return true
end

function atlas:on_quit()
	self:GetHolder():start_stop_menu (self,true)
end

function atlas:spawn_ammo(spawn_item,npc)

	local number = self:GetEditBox("edit_box"):GetText()

  	if npc==nil then 
  	npc=db.actor 
	end

	if number ~= "" then
	local number2 = number + 0
  	se_respawn.create_ammo(spawn_item, npc:position(), npc:level_vertex_id(), npc:game_vertex_id(), npc:id(), number2)
	end

	if number == "" then
  	se_respawn.create_ammo(spawn_item, npc:position(), npc:level_vertex_id(), npc:game_vertex_id(), npc:id(), 1)
	end

end

function atlas:spawn_inventory(spawn_item,npc)

	local number = self:GetEditBox("edit_box"):GetText()

  	if npc==nil then 
  	npc=db.actor 
	end

	if number ~= "" then
	for i=1, number do
  	alife():create(spawn_item, npc:position(), npc:level_vertex_id(), npc:game_vertex_id(), npc:id())
      	end
	end

	if number == "" then
  	alife():create(spawn_item, npc:position(), npc:level_vertex_id(), npc:game_vertex_id(), npc:id())
	end

end

function atlas:spawn_ammo_9x18_pmm()
        self:spawn_ammo("ammo_9x18_pmm")
	end

function atlas:spawn_ammo_9x18_fmj()
        self:spawn_ammo("ammo_9x18_fmj")
	end

function atlas:spawn_ammo_12x76_dart()
        self:spawn_ammo("ammo_12x76_dart")
	end

function atlas:spawn_ammo_12x76_zhekan()
        self:spawn_ammo("ammo_12x76_zhekan")
	end

function atlas:spawn_ammo_12x70_buck()
        self:spawn_ammo("ammo_12x70_buck")
	end

function atlas:spawn_ammo_9x19_fmj()
        self:spawn_ammo("ammo_9x19_fmj")
	end

function atlas:spawn_ammo_9x19_pbp()
        self:spawn_ammo("ammo_9x19_pbp")
	end

function atlas:spawn_ammo_9x39_ap()
        self:spawn_ammo("ammo_9x39_ap")
	end

function atlas:spawn_ammo_9x39_pab9()
        self:spawn_ammo("ammo_9x39_pab9")
	end

function atlas:spawn_ammo_9x39_sp5()
        self:spawn_ammo("ammo_9x39_sp5")
	end

function atlas:spawn_ammo_545x39_ap()
        self:spawn_ammo("ammo_5.45x39_ap")
	end

function atlas:spawn_ammo_545x39_fmj()
        self:spawn_ammo("ammo_5.45x39_fmj")
	end

function atlas:spawn_ammo_762x54_7h14()
        self:spawn_ammo("ammo_7.62x54_7h14")
	end

function atlas:spawn_ammo_762x54_7h1()
        self:spawn_ammo("ammo_7.62x54_7h1")
	end

function atlas:spawn_ammo_762x54_ap()
        self:spawn_ammo("ammo_7.62x54_ap")
	end

function atlas:spawn_ammo_556x45_ss190()
        self:spawn_ammo("ammo_5.56x45_ss190")
	end

function atlas:spawn_ammo_556x45_ap()
        self:spawn_ammo("ammo_5.56x45_ap")
	end

function atlas:spawn_ammo_1143x23_hydro()
        self:spawn_ammo("ammo_11.43x23_hydro")
	end

function atlas:spawn_ammo_1143x23_fmj()
        self:spawn_ammo("ammo_11.43x23_fmj")
	end

function atlas:spawn_ammo_gauss()
        self:spawn_ammo("ammo_gauss")
	end

function atlas:spawn_ammo_og7b()
        self:spawn_ammo("ammo_og-7b")
	end

function atlas:spawn_ammo_vog25p()
        self:spawn_ammo("ammo_vog-25p")
	end

function atlas:spawn_ammo_vog25()
        self:spawn_ammo("ammo_vog-25")
	end

function atlas:spawn_ammo_m209()
        self:spawn_ammo("ammo_m209")
	end

function atlas:spawn_grenade_rgd5()
        self:spawn_inventory("grenade_rgd5")
	end

function atlas:spawn_grenade_f1()
        self:spawn_inventory("grenade_f1")
	end

function atlas:spawn_grenade_gd05()
        self:spawn_inventory("grenade_gd-05")
	end

