--[[
****************************************************
****************************************************
	  ABC - Interative Wish Granter
****************************************************
****************************************************
--]]

class "wisher_ui" (CUIScriptWnd)
function wisher_ui:__init(owner) super()
	self.owner = owner
	self:InitControls()
	self:InitCallBacks()
end

function wisher_ui:__finalize() end

function wisher_ui:InitControls()
	self:Init(0,0,1024,768)
	local xml = CScriptXmlInit()
	xml:ParseFile("ui_abc_repair.xml")
	local checkwish, showdesire, disable
	showdesire = "no"

	self.wishgranter = xml:InitStatic("wishgranter", self)
	xml:InitStatic("wishgranter:wish_picture", self.wishgranter)

	-- xml:InitStatic("wishgranter:wish_text", self.wishgranter)

  	disable = db.storage[db.actor:id()].pstor["abc_wishgranter_disable"]

   if disable ~= "yes" then

	checkwish = db.storage[db.actor:id()].pstor["abc_wishgranter_desire1"]
	if checkwish ~= "yes" then
		ctrl = xml:Init3tButton("wishgranter:wish_desire_1", self.wishgranter)
		self:Register(ctrl, "desire_1")
		showdesire = "yes"
	end

	checkwish = db.storage[db.actor:id()].pstor["abc_wishgranter_desire2"]
	if checkwish ~= "yes" then
		ctrl = xml:Init3tButton("wishgranter:wish_desire_2", self.wishgranter)
		self:Register(ctrl, "desire_2")
		showdesire = "yes"
	end

	checkwish = db.storage[db.actor:id()].pstor["abc_wishgranter_desire3"]
	if checkwish ~= "yes" then
		ctrl = xml:Init3tButton("wishgranter:wish_desire_3", self.wishgranter)
		self:Register(ctrl, "desire_3")
		showdesire = "yes"
	end

	checkwish = db.storage[db.actor:id()].pstor["abc_wishgranter_desire4"]
	if checkwish ~= "yes" then
		ctrl = xml:Init3tButton("wishgranter:wish_desire_4", self.wishgranter)
		self:Register(ctrl, "desire_4")
		showdesire = "yes"
	end

	checkwish = db.storage[db.actor:id()].pstor["abc_wishgranter_desire5"]
	if checkwish ~= "yes" then
		ctrl = xml:Init3tButton("wishgranter:wish_desire_5", self.wishgranter)
		self:Register(ctrl, "desire_5")
		showdesire = "yes"
	end

	checkwish = db.storage[db.actor:id()].pstor["abc_wishgranter_desire6"]
	if checkwish ~= "yes" then
		ctrl = xml:Init3tButton("wishgranter:wish_desire_6", self.wishgranter)
		self:Register(ctrl, "desire_6")
		showdesire = "yes"
	end
	checkwish = db.storage[db.actor:id()].pstor["abc_wishgranter_desire7"]
	if checkwish ~= "yes" then
		ctrl = xml:Init3tButton("wishgranter:wish_desire_7", self.wishgranter)
		self:Register(ctrl, "desire_7")
		showdesire = "yes"
	end
  end
	-- testing abaixo, para ver wish speak - preciso remover showdesire
	-- showdesire = "no"
	-- fim tet
	if showdesire == "no" or disable == "yes" then
		self.wish_speak = xml:InitStatic("wishgranter:wish_speak",	self.wishgranter)
		ctrl = xml:Init3tButton("wishgranter:no_desire", self.wishgranter)
		self:Register(ctrl, "no_desire")
	end

end

function wisher_ui:InitCallBacks()

	self:AddCallback("desire_1",		ui_events.BUTTON_CLICKED,             self.desire_1,	self)
	self:AddCallback("desire_2",		ui_events.BUTTON_CLICKED,             self.desire_2,	self)
	self:AddCallback("desire_3",		ui_events.BUTTON_CLICKED,             self.desire_3,	self)
	self:AddCallback("desire_4",		ui_events.BUTTON_CLICKED,             self.desire_4,	self)
	self:AddCallback("desire_5",		ui_events.BUTTON_CLICKED,             self.desire_5,	self)
	self:AddCallback("desire_6",		ui_events.BUTTON_CLICKED,             self.desire_6,	self)
	self:AddCallback("desire_7",		ui_events.BUTTON_CLICKED,             self.desire_7,	self)
	self:AddCallback("no_desire",		ui_events.BUTTON_CLICKED,             self.no_desire,	self)
	-- self:Onload()
end

function wisher_ui:on_quit(what)
 self:GetHolder():start_stop_menu (self,true)
 db.storage[db.actor:id()].pstor["wishgranter"] = "yes"
  local turnwgoff = "no"
 if what == "desire_1" then
	-- logf("mov_desire_1")
	game.start_tutorial("mov_desire_1")	
	db.storage[db.actor:id()].pstor["abc_wishgranter_desire1"] = "yes"
	db.storage[db.actor:id()].pstor["abc_wishgranter_des1_count"] = 0
    turnwgoff = "yes"
	-- preciso remover abaixo
	-- abc.wishnews("abc_wish_vendetta_1")
 end
 if what == "desire_2" then
	-- logf("mov_desire_2")
	game.start_tutorial("mov_desire_2")	
	db.storage[db.actor:id()].pstor["abc_wishgranter_desire2"] = "yes"
	db.storage[db.actor:id()].pstor["abc_wishgranter_des2_count"] = 0
    turnwgoff = "yes"
	-- preciso remover abaixo
	-- abc.wishnews("abc_wish_granted")
 end
 if what == "desire_3" then
	-- logf("mov_desire_3")
	game.start_tutorial("mov_desire_3")	
	db.storage[db.actor:id()].pstor["abc_wishgranter_desire3"] = "yes"
	db.storage[db.actor:id()].pstor["abc_wishgranter_des3_count"] = 0
    turnwgoff = "yes"
	-- preciso remover abaixo
	-- abc.wishnews("abc_wish_vendetta_3")
 end
 if what == "desire_4" then
	-- logf("mov_desire_4")
	game.start_tutorial("mov_desire_4")	
	db.storage[db.actor:id()].pstor["abc_wishgranter_desire4"] = "yes"
	db.storage[db.actor:id()].pstor["abc_wishgranter_des4_count"] = 0
    turnwgoff = "yes"
	-- preciso remover abaixo
	-- abc.wishnews("abc_wish_vendetta_4")
 end
 if what == "desire_5" then
	--- logf("mov_desire_5")
	game.start_tutorial("mov_desire_5")	
	db.storage[db.actor:id()].pstor["abc_wishgranter_desire5"] = "yes"
	db.storage[db.actor:id()].pstor["abc_wishgranter_des5_count"] = 0
    turnwgoff = "yes"
	-- preciso remover abaixo
	-- abc.wishnews("abc_wish_vendetta_5")
 end
 if what == "desire_6" then
	-- logf("mov_desire_6")
	db.storage[db.actor:id()].pstor["abc_wishgranter_desire6"] = "yes"
    turnwgoff = "yes"
	abc.mov_desire_6()
	-- preciso remover abaixo
	-- abc.wishnews("abc_wish_granted")
 end
 if what == "desire_7" then
	-- logf("mov_desire_7")
	db.storage[db.actor:id()].pstor["abc_wishgranter_desire7"] = "yes"
    turnwgoff = "yes"
	abc.mov_desire_7()
	-- preciso remover abaixo
	-- abc.wishnews("abc_wish_granted")
 end

  if turnwgoff == "yes" then 
		db.storage[db.actor:id()].pstor["abc_wishgranter_disable"] = "yes" 
		db.storage[db.actor:id()].pstor["abc_wishgranter_dis_count"] = 0
		db.storage[db.actor:id()].pstor["abc_wishgranter_used"] = "yes"
  end

end

function wisher_ui: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
end

function wisher_ui:no_desire()
	self:on_quit()
end
function wisher_ui:desire_1()
	self:on_quit("desire_1")
end
function wisher_ui:desire_2()
	self:on_quit("desire_2")
end
function wisher_ui:desire_3()
	self:on_quit("desire_3")
end
function wisher_ui:desire_4()
	self:on_quit("desire_4")
end
function wisher_ui:desire_5()
	self:on_quit("desire_5")
end
function wisher_ui:desire_6()
	self:on_quit("desire_6")
end
function wisher_ui:desire_7()
	self:on_quit("desire_7")
end
function wisher_ui:Onload()

end