Ejemplo n.º 1
0
        /// <summary>
        /// 发送一个简易表单
        /// </summary>
        /// <param name="tout">超时时间</param>
        /// <param name="func">主选择处理函数</param>
        /// <param name="tofunc">超时处理函数</param>
        /// <returns></returns>
        public bool send(int tout, ONSELECT func, ONTIMEOUT tofunc)
        {
            timeout    = tout;
            onselected = func;
            ontimeout  = tofunc;
            fmcb       = (x) => {
                var e = BaseEvent.getFrom(x) as FormSelectEvent;
                if (e.formid == id)                     // 确定是当前表单
                {
                    mapi.removeBeforeActListener(EventKey.onFormSelect, fmcb);
                    cancelTimeout();
                    onselected(e.selected);
                }
                return(true);
            };
            mapi.addBeforeActListener(EventKey.onFormSelect, fmcb);
            string bts = "[]";

            if (buttons != null && buttons.Count > 0)
            {
                var ser = new JavaScriptSerializer();
                bts = ser.Serialize(buttons);
            }
            id = mapi.sendSimpleForm(uuid, title, content, bts);
            bool ret = (id != 0);

            if (timeout > 0)
            {
                startTimeout();
            }
            return(ret);
        }
Ejemplo n.º 2
0
 static bool checkFuncEquals(ScriptObject a, ScriptObject b, MCCSAPI.EventCab cb)
 {
     if (a != null && b != null)
     {
         var k = "" + Marshal.GetFunctionPointerForDelegate <MCCSAPI.EventCab>(cb);
         return((a.GetProperty(k).ToString() == k) && (b.GetProperty(k).ToString() == k));
     }
     return(false);
 }
Ejemplo n.º 3
0
        /// <summary>
        /// 发送一个自定义表单
        /// </summary>
        /// <param name="uuid">玩家 uuid</param>
        /// <param name="json">表单内容</param>
        /// <param name="function">回调函数</param>
        public static void sendCustomForm(string uuid, string str, ONSELECT function)
        {
            uint id = 0;

            callback = (x) =>
            {
                var json = BaseEvent.getFrom(x) as FormSelectEvent;
                if (json.formid == id && json.selected != "null")
                {
                    mcapi.removeAfterActListener(EventKey.onFormSelect, callback);
                    function(json);
                    return(false);
                }
                return(true);
            };
            mcapi.addAfterActListener(EventKey.onFormSelect, callback);
            id = mcapi.sendCustomForm(uuid, str);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 发送一个模式对话框
        /// </summary>
        /// <param name="uuid">玩家 uuid</param>
        /// <param name="title">表单标题</param>
        /// <param name="content">表单内容</param>
        /// <param name="button1">表单按钮</param>
        /// <param name="button2">表单按钮</param>
        /// <param name="function">回调函数</param>
        public static void sendModalForm(string uuid, string title, string content, string button1, string button2, ONSELECT function)
        {
            uint id = 0;

            callback = (x) =>
            {
                var json = BaseEvent.getFrom(x) as FormSelectEvent;
                if (json.formid == id && json.selected != "null")
                {
                    mcapi.removeAfterActListener(EventKey.onFormSelect, callback);
                    function(json);
                    return(false);
                }
                return(true);
            };
            mcapi.addAfterActListener(EventKey.onFormSelect, callback);
            id = mcapi.sendModalForm(uuid, title, content, button1, button2);
            Thread.Sleep(timeout);
            mcapi.releaseForm(id);
        }