Exemplo n.º 1
0
 /// <summary>
 /// 移除一个事件
 /// </summary>
 /// <param name="type"></param>
 /// <param name="callback"></param>
 public void RemoveDelegate(EventType type, UIDelegate callback)
 {
     if (UIDelegateDic.ContainsKey(type))
     {
         UIDelegateDic[type] -= callback;
     }
 }
Exemplo n.º 2
0
    public void Init()
    {
        instance = this;

        //

        enterGame = Log;

        goPlay += GameManager.instance.charManager.move.Check;
        goPlay += delegate { GameManager.instance.itemManager.isPlaying = true; };
        goPlay += delegate { AudioManager.Instance.PlaySound(AudioManager.AudioName.StartGame, 0.9F); };

        restart += GameManager.instance.Reload;

        moveView += GameManager.instance.charManager.View;

        buyItem += GameManager.instance.itemManager.buyItem;

        setItemInCell += GameManager.instance.itemManager.setItemInCell_World;
        setItemInCell += delegate { AudioManager.Instance.PlaySound(AudioManager.AudioName.ItemDrop, 0.8F); };
        //setItemInCell += LogCellPos;

        lose += delegate { AudioManager.Instance.PlaySound(AudioManager.AudioName.GameOver, 0.8F); };

        win += delegate { AudioManager.Instance.PlaySound(AudioManager.AudioName.LevelClear1, 0.8F); };
        win += delegate { AudioManager.Instance.PlaySound(AudioManager.AudioName.LevelClear2, 0.8F); };
    }
Exemplo n.º 3
0
 // 为 Controller 设置UI线程(主线程)的函数委托
 public void SetFunctionDelegate(UIDelegate AI1Win, UIDelegate AI2Win,
                                 UIDelegate NoWiner, UIDelegate draw, errorNotifyDelegate error, errorNotifyDelegate errorAbort)
 {
     AI1Win_UpdateUI        = AI1Win;
     AI2Win_UpdateUI        = AI2Win;
     NoWiner_UpdateUI       = NoWiner;
     drawUI                 = draw;
     errorNotify            = error;
     errorNotifyAndStopGame = errorAbort;
 }
Exemplo n.º 4
0
 /// <summary>
 /// 触发一个事件
 /// </summary>
 /// <param name="type"></param>
 public void CallDelegate(EventType type, params object[] objs)
 {
     if (UIDelegateDic.ContainsKey(type))
     {
         UIDelegate uIDelegate = UIDelegateDic[type];
         if (null != uIDelegate)
         {
             uIDelegate.Invoke(objs);
         }
     }
 }
Exemplo n.º 5
0
 public void OnRestart()
 {
     UIColorChangeEvent         -= ChangeColor;
     GameManager.RestartEvent   -= OnRestart;
     GameManager.NextLevelEvent -= OnRestart;
     DeathTextEvent             -= UpdateDeathText;
     TimerEvent              -= UpdateTimer;
     BestTimerEvent          -= UpdateBestTimer;
     GameManager.PauseEvent  -= OnPause;
     GameManager.ResumeEvent -= OnResume;
 }
Exemplo n.º 6
0
 /// <summary>
 /// 注册一个事件
 /// </summary>
 /// <param name="type"></param>
 /// <param name="callback"></param>
 public void RegistDelegate(EventType type, UIDelegate callback)
 {
     if (UIDelegateDic.ContainsKey(type))
     {
         UIDelegateDic[type] += callback;
     }
     else
     {
         UIDelegateDic.Add(type, callback);
     }
 }
 void worker_DoWork(object sender, DoWorkEventArgs e)
 {
     if (this.InvokeRequired)
     {
         UIDelegate del = new UIDelegate(GetDistanceAndTime);
         this.BeginInvoke(del, Origen, Destination, time);
     }
     else
     {
         GetDistanceAndTime(Origen, Destination, time);
     }
 }
Exemplo n.º 8
0
        void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if (IsClosed)
            {
                return;
            }

            if (this.InvokeRequired)
            {
                UIDelegate del = new UIDelegate(PopulateUI);
                this.BeginInvoke(del, FareList);
            }
            else
            {
                PopulateUI(FareList, VehicleList);
            }
        }
Exemplo n.º 9
0
        void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if (IsClosed)
            {
                return;
            }



            if (this.InvokeRequired)
            {
                UIDelegate del = new UIDelegate(PopulateUI);
                this.BeginInvoke(del, listOfData);

                UIMessage del2 = new UIMessage(ShowUI);
                this.BeginInvoke(del2, false, "");
            }
            else
            {
                PopulateUI(listOfData);
                ShowUI(false, "");
            }
        }
Exemplo n.º 10
0
 public HexData(UIDelegate del)
 {
     hexString = string.Empty;
     isTurned  = true;
     this.del  = del;
 }
Exemplo n.º 11
0
 public TruckJob(UIDelegate delegate1)
     : base(delegate1)
 {
 }
Exemplo n.º 12
0
 private Article()
 {
     uiDelegate = new UIDelegate(this.SetSubItem);
 }
Exemplo n.º 13
0
 public MonitorJob(UIDelegate delegate1)
     : base(delegate1)
 {
 }
Exemplo n.º 14
0
 public PhotoJob(UIDelegate delegate1)
     : base(delegate1)
 {
 }
Exemplo n.º 15
0
 public Job(UIDelegate delegate1)
 {
     this.delegate1 = delegate1;
 }
Exemplo n.º 16
0
 public Background(UIDelegate del)
 {
     backgroundColor = Color.Empty;
     this.del        = del;
 }
Exemplo n.º 17
0
 public DispatchJob(UIDelegate delegate1)
     : base(delegate1)
 {
 }
Exemplo n.º 18
0
 public void InvokeDelegate(UIDelegate method)
 {
     try {
         Invoke(method);
     } catch (Exception) {}
 }
Exemplo n.º 19
0
 public HSLData(UIDelegate del)
 {
     HSLString = string.Empty;
     isTurned  = true;
     this.del  = del;
 }
Exemplo n.º 20
0
 public RGBData(UIDelegate del)
 {
     RGBString = string.Empty;
     isTurned  = true;
     this.del  = del;
 }
Exemplo n.º 21
0
 public DataJob(UIDelegate delegate1)
     : base(delegate1)
 {
 }
Exemplo n.º 22
0
 public Observable()
 {
     observersList = new List <Observer>();
     isLocked      = false;
     del           = null;
 }
Exemplo n.º 23
0
        private void refresh_OnTimer(object sender, EventArgs e)
        {
            UIDelegate uidel = new UIDelegate(RefreshOnTimer);

            this.Invoke(uidel, null);
        }
Exemplo n.º 24
0
 private Article()
 {
     uiDelegate = new UIDelegate(this.SetSubItem);
 }
Exemplo n.º 25
0
 public void InvokeDelegate(UIDelegate method)
 {
     try {
         Invoke(method);
     } catch(Exception) {}
 }
Exemplo n.º 26
0
 public ArchiveJob(UIDelegate delegate1)
     : base(delegate1)
 {
 }
Exemplo n.º 27
0
        /// <summary>
        /// http下载文件
        /// </summary>
        /// <param name="url">下载文件地址</param>
        /// <param name="path">文件存放地址,包含文件名</param>
        /// <returns></returns>
        public bool HttpDownload(string url, string path, out string msg)
        {
            msg = "";
            string tempPath = path;
            //Directory.CreateDirectory(tempPath);                                      //创建临时文件目录
            string ss = url.Split('=').Last();

            string tempFile = string.Format("{0}{1}.{2}", tempPath, ss, "temp"); //临时文件

            ProFile = tempFile.Replace(".temp", ".bin");                         // string.Format("{0}{1}", tempPath, ss);

            if (System.IO.File.Exists(tempFile))
            {
                System.IO.File.Delete(tempFile);    //存在则删除
            }
            try
            {
                #region
                FileStream fs = new FileStream(tempFile, FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
                // 设置参数
                HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
                //发送请求并获取相应回应数据
                HttpWebResponse response = request.GetResponse() as HttpWebResponse;
                //直到request.GetResponse()程序才开始向目标网页发送Post请求
                Stream responseStream = response.GetResponseStream();


                int contentLenth;
                contentLenth = (int)(response.ContentLength / 1024);

                string headers = response.Headers.ToString();
                if (!headers.Contains("filename"))
                {
                    using (StreamReader streamReader = new StreamReader(responseStream, Encoding.UTF8))
                    {
                        string httpRespose = streamReader.ReadToEnd();
                        int    start       = httpRespose.IndexOf("{");
                        int    end         = httpRespose.LastIndexOf("}");
                        int    length      = end - start + 1;
                        httpRespose = httpRespose.Substring(start, length);

                        ResponseInfo responseInfo = JsonConvert.DeserializeObject(httpRespose, typeof(ResponseInfo)) as ResponseInfo;
                        if (responseInfo.code == -1)
                        {
                            msg = responseInfo.msg + "\r\n";
                            return(false);
                        }
                    }
                }
                int    startIndex = headers.IndexOf('=');
                int    endIndex   = headers.IndexOf("\r\n");
                string fileName   = headers.Substring(startIndex + 1, endIndex - startIndex - 1).Replace("\"", "");

                ProFile      = ProFile.Replace(ss + ".bin", fileName);
                contentLenth = 20;                                     /*每个bin文件都是20K*/

                UIDelegate.setMaxUIControl(progressBar, contentLenth); //最大的基础上再加40

                //if (response.ContentLength<1)
                //{
                //    using (StreamReader streamReader = new StreamReader(responseStream, Encoding.UTF8))
                //    {
                //        string httpRespose = streamReader.ReadToEnd();
                //        int start = httpRespose.IndexOf("{");
                //        int end = httpRespose.LastIndexOf("}");
                //        int length = end - start + 1;
                //        httpRespose = httpRespose.Substring(start, length);

                //        ResponseInfo responseInfo = JsonConvert.DeserializeObject(httpRespose, typeof(ResponseInfo)) as ResponseInfo;
                //        if (responseInfo.code == -1)
                //        {
                //            msg = responseInfo.msg + "\r\n";
                //            return false;
                //        }
                //    }
                //}


                //创建本地文件写入流
                //Stream stream = new FileStream(tempFile, FileMode.Create);
                byte[] bArr       = new byte[1024];
                int    size       = responseStream.Read(bArr, 0, (int)bArr.Length);
                long   sizeAll    = 0;
                int    sizeAll_kb = 0;
                float  percent_kb = 0.0f;
                double testTime;
                int    downLoadSpeed;
                stopWatch.Start();
                while (size > 0)
                {
                    //stream.Write(bArr, 0, size);
                    fs.Write(bArr, 0, size);
                    size          = responseStream.Read(bArr, 0, (int)bArr.Length);
                    sizeAll      += size;
                    sizeAll_kb    = (int)(sizeAll / 1024);
                    percent_kb    = (int)(((float)sizeAll_kb / contentLenth) * 100);
                    testTime      = stopWatch.getTotoleSeconds();
                    downLoadSpeed = testTime > 0 ? (int)((float)sizeAll_kb / testTime) : 0;

                    //UIDelegate.writeUIControl(ctr3, string.Format("{0}kB/s ", downLoadSpeed.ToString()));
                    //UIDelegate.writeUIControl(ctr2, string.Format("已下载  {0}% ", percent_kb.ToString()));
                    //UIDelegate.writeUIControl(ctr, string.Format("已下载  {0}  kB", sizeAll_kb.ToString()));
                    //Form1.mainForm.Invoke((EventHandler) delegate{


                    //});

                    //System.Threading.Thread.Sleep(0);
                    //Form1.mainForm.Invoke((EventHandler)delegate {
                    //    Form1.mainForm.label1.Text = string.Format("{0}kB/s ", downLoadSpeed);
                    //    Form1.mainForm.label2.Text = string.Format("已下载  {0}% ", percent_kb);
                    //    Form1.mainForm.label3.Text = string.Format("已下载  {0}  kB", sizeAll_kb);
                    //});
                    AutoWriteProcess.autoWriteForm.label1.Text = string.Format("{0}kB/s ", downLoadSpeed);
                    AutoWriteProcess.autoWriteForm.label1.Update();
                    AutoWriteProcess.autoWriteForm.label2.Text = string.Format("已下载  {0}% ", percent_kb);
                    AutoWriteProcess.autoWriteForm.label2.Update();
                    AutoWriteProcess.autoWriteForm.label3.Text = string.Format("已下载  {0}  kB", sizeAll_kb);
                    AutoWriteProcess.autoWriteForm.label3.Update();
                    if (sizeAll_kb <= contentLenth)
                    {
                        UIDelegate.setValueUIControl(progressBar, sizeAll_kb);//在线程中不会出现显示不完的现象
                    }
                    Thread.Sleep(0);
                }
                stopWatch.Stop();

                //stream.Close();
                #endregion
                fs.Close();
                responseStream.Close();
                if (System.IO.File.Exists(ProFile))
                {
                    System.IO.File.Delete(ProFile);    //前面删除的是.temp
                }
                try
                {
                    System.IO.File.Move(tempFile, ProFile);
                }
                catch (Exception ex)
                {
                    UIDelegate.writeUIControl(ctr, ex.Message);
                    return(false);
                }
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }