class "ui_ms_weather" (CUIScriptWnd)

function ui_ms_weather:__init(owner) super()
	self.owner = owner
	self:InitControls()
	self:InitCallBacks()
end

function ui_ms_weather:__finalize() 

end

function ui_ms_weather:InitControls()
self:Init(50,50,550,450)
local xml = CScriptXmlInit()
xml:ParseFile("ui_ms.xml")
xml:InitStatic("back_video", self)
xml:InitStatic("background", self)
self:Register(xml:Init3tButton("caption", self),"caption")
self:Register(xml:Init3tButton("btn_1", self),"btn_1")
self:Register(xml:Init3tButton("btn_quit", self),"btn_quit")
self:Register(xml:InitEditBox("edit_box", self), "edit_box")
local caption = self:GetButton("caption")
local btn_1 = self:GetButton("btn_1")
caption:SetText("Пропишите секцию погоды")
btn_1:SetText("Change")
end

function ui_ms_weather:InitCallBacks()
self:AddCallback("btn_1", ui_events.BUTTON_CLICKED, self.set, self)
self:AddCallback("btn_quit", ui_events.BUTTON_CLICKED, self.on_close, self)
end

function ui_ms_weather: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_close()
		end		
	end
	return true
end

function ui_ms_weather:set()
local text = self:GetEditBox("edit_box"):GetText()
if text~="" then
self:set_weather(text)
end
end

function ui_ms_weather:set_weather(str)
	if system_ini():line_exist("weathers",str) then	
		level.set_weather(str,true)
		news_manager.send_tip(db.actor,"Установлена погода:"..str,nil,nil,1000)
	else
		news_manager.send_tip(db.actor,"Нет такой секции:"..str,nil,nil,1000)
	end
		self:on_close()	
end

function ui_ms_weather:on_close()
	self:GetHolder():start_stop_menu (self,true)
end