--[[

File:  ui_gps_trade.script
Copyright by Idler (and AMK TEAM 2007-2008 местами :)
rev: 15/08/08.01
]]

-- инициализация
class "gps_trade" (CUIScriptWnd)

function gps_trade:__init(owner, objid) super()
	self.boxId = objid
	self.owner = owner
	self:InitControls()
	self:InitCallBacks()
end

function gps_trade:__finalize() 
end

function gps_trade:InitControls()
	self:SetWndRect(Frect():set(0,0,1024,768))
	self:Enable(true)
	
	-- файл-описатель наших элементов
	local xml = CScriptXmlInit()
	xml:ParseFile("ui_gps_trade_wnd.xml")

	self.dialog					= xml:InitStatic("main_dialog:dialog", self)
	xml:InitStatic				("main_dialog:capt", self.dialog)
	xml:InitStatic				("main_dialog:msg", self.dialog)
	
	-- кнопки
	self:Register(xml:Init3tButton("main_dialog:btn_1", self.dialog),"btn_1")
	self:Register(xml:Init3tButton("main_dialog:btn_quit", self.dialog),"btn_quit")
end

function gps_trade:InitCallBacks()
	-- тут интерактивные элементы, при определенном действии выполняется заданная ф-ия
	self:AddCallback("btn_1", ui_events.BUTTON_CLICKED, self.btn_1, self)
	self:AddCallback("btn_quit", ui_events.BUTTON_CLICKED, self.on_quit, self)
end

function gps_trade: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_RETURN then
			self:btn_1()
		end
	end
	return true
end

function gps_trade:btn_1()
	gps_habar.update_gps( nil, nil, self.boxId, true)
	self:on_quit()
end

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

