bge = {}

function bge.yes_no_action(_owner, _action, _child)
	if _action==_T("key_down_enter") then
		_owner.EndModal(1)
	elseif _action==_T("key_down_escape") then
		_owner.EndModal(0)
	elseif _child.GetId()==_T("yes") and _action==_T("pressed") then
		_owner.EndModal(1)
	elseif _child.GetId()==_T("no") and _action==_T("pressed") then
		_owner.EndModal(0)
	end
end

function bge.on_tile_object(_owner, _action, _child)
	local radio_button_group = sf.gui.CastCRadioButtonGroupWidget(_owner.GetWidget(_T("radio_group_tile")).get())
	if _action==_T("key_down_enter") then
		_owner.EndModal(radio_button_group.GetChecked()+1)
	elseif _action==_T("key_down_escape") then
		_owner.EndModal(0)
	elseif _child.GetId()==_T("yes") and _action==_T("pressed") then
		_owner.EndModal(radio_button_group.GetChecked()+1)
    elseif _child.GetId()==_T("cancel") and _action==_T("pressed") then
		_owner.EndModal(0)
	end
end

function bge.ok_action(_owner, _action, _child)
	if _action==_T("key_down_enter") then
		_owner.EndModal(1)
	elseif _child.GetId()==_T("ok") and _action==_T("pressed") then
		_owner.EndModal(1)
	end
end

function bge.save_before_exit(_owner, _action, _child)
	if _child.GetId()==_T("yes") and _action==_T("pressed") then
		_owner.EndModal(1)
	elseif _child.GetId()==_T("yes_for_all") and _action==_T("pressed") then
		_owner.EndModal(2)
	elseif _child.GetId()==_T("no") and _action==_T("pressed") then
		_owner.EndModal(3)
	elseif _child.GetId()==_T("no_for_all") and _action==_T("pressed") then
		_owner.EndModal(4)
	elseif _child.GetId()==_T("cancel") and _action==_T("pressed") then
		_owner.EndModal(0)
	end
end
