public void ClearEventInvocationList()
        {
            if (ErrorOccured != null)
            {
                foreach (var subscribedDelegate in ErrorOccured.GetInvocationList())
                {
                    ErrorOccured -= (EventHandler <BaseErrorResponseInfo>)subscribedDelegate;
                }
            }

            if (LoadingStarted != null)
            {
                foreach (var subscribedDelegate in LoadingStarted.GetInvocationList())
                {
                    LoadingStarted -= (EventHandler <EventArgs>)subscribedDelegate;
                }
            }

            if (LoadingCompleted != null)
            {
                foreach (var subscribedDelegate in LoadingCompleted.GetInvocationList())
                {
                    LoadingCompleted -= (EventHandler <EventArgs>)subscribedDelegate;
                }
            }
        }
Esempio n. 2
0
    /// <summary>
    /// 转到加载:家园数据、搜索敌人数据、加载回放数据(需要参数)、加载本地关卡数据(需要参数)(REMARK:开始游戏时加载关卡不走该接口)
    /// </summary>
    public void ChangeLoading(WorldType worldType, LoadingCompleted callback = null, object args = null)
    {
        //  先停止先前的loading
        StopLoading();

        //  设置加载中标记
        _loading = true;

        //  显示云动画&&延迟1秒开始加载资源
        LoadingManager.Instance.ShowLoading();
        DelayManager.Instance.AddDelayCall(() =>
        {
            switch (worldType)
            {
            case WorldType.Home:
                ChangeLoadingHome(callback, args);
                break;

            case WorldType.Battle:
                ChangeLoadingBattle(callback, args);
                break;

            case WorldType.Replay:
                ChangeLoadingReplay(callback, args);
                break;

            case WorldType.Visit:
                ChangeLoadingVisit(callback, args);
                break;

            default:
                break;
            }
        }, 1.0f);
    }
Esempio n. 3
0
 /// <summary>
 /// 加载回放
 /// </summary>
 /// <param name="callback"></param>
 /// <param name="args"></param>
 private void ChangeLoadingReplay(LoadingCompleted callback = null, object args = null)
 {
     if (Constants.ISCLIENT)
     {
         var vo = ExtensionMethods.DeSerialize <BattleReplayVO>(Application.streamingAssetsPath + "/record.pbd");
         LoadingManager.Instance.CloseLoading();
         DelayManager.Instance.AddDelayCall(() =>
         {
             _loading = false;
             if (callback != null)
             {
                 callback(true);
             }
             Create(WorldType.Replay, vo.defender, vo.attacker, vo);
         }, 1.0f);
     }
     else
     {
         GameManager.Instance.RequestPlayReplay((long)args);
         LoadingManager.Instance.CloseLoading();
         DelayManager.Instance.AddDelayCall(() => { _loading = false; if (callback != null)
                                                    {
                                                        callback(true);
                                                    }
                                            }, 1.0f);
     }
 }
 private void OnLoadingCompleted(ImageSource imageSource)
 {
     this.IsLoading = false;
     if (LoadingCompleted != null)
     {
         LoadingCompleted.Invoke(this, new LoadingCompletedEventArgs(this.PixelWidth, this.PixelWidth));
     }
 }
Esempio n. 5
0
 private void OnLoadingCompleted()
 {
     this.IsLoading = false;
     if (LoadingCompleted != null)
     {
         LoadingCompleted.Invoke(this, EventArgs.Empty);
     }
 }
Esempio n. 6
0
        private void Update()
        {
            var progress = _progress.GetProgress();

            SetProgress(progress);
            if (progress >= 1)
            {
                LoadingCompleted?.Invoke();
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Sets the file that is used as the image's source with async.
        /// </summary>
        /// <param name="file">The path to the file that is used as an image source.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>(true = success, false = error)</returns>
        /// <since_tizen> preview </since_tizen>
        public async Task <bool> LoadAsync(string file, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (file == null)
            {
                throw new ArgumentNullException(nameof(file));
            }

            Interop.Elementary.elm_image_async_open_set(RealHandle, true);
            Interop.Elementary.elm_image_preload_disabled_set(RealHandle, false);

            var tcs = new TaskCompletionSource <bool>();

            cancellationToken.Register(() =>
            {
                if (tcs != null && !tcs.Task.IsCompleted)
                {
                    tcs.SetCanceled();
                }
            });

            SmartEvent loadReady = new SmartEvent(this, RealHandle, "load,ready");

            loadReady.On += (s, e) =>
            {
                LoadingCompleted?.Invoke(this, EventArgs.Empty);
                if (tcs != null && !tcs.Task.IsCompleted)
                {
                    tcs.SetResult(true);
                }
            };

            SmartEvent loadError = new SmartEvent(this, RealHandle, "load,error");

            loadError.On += (s, e) =>
            {
                LoadingFailed?.Invoke(this, EventArgs.Empty);
                if (tcs != null && !tcs.Task.IsCompleted)
                {
                    tcs.SetResult(false);
                }
            };

            using (loadReady)
                using (loadError)
                {
                    bool ret = Interop.Elementary.elm_image_file_set(RealHandle, file, null);
                    if (!ret)
                    {
                        throw new InvalidOperationException("Failed to set file to Image");
                    }
                    // it should be return on main thread, because SmartEvent should be disposed on main thread
                    return(await tcs.Task.ConfigureAwait(true));
                }
        }
Esempio n. 8
0
        /// <summary>
        /// Sets the file that is used as the image's source with async.
        /// </summary>
        /// <param name="file">The path to the file that is used as an image source.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>(true = success, false = error)</returns>
        /// <since_tizen> preview </since_tizen>
        public Task <bool> LoadAsync(string file, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (file == null)
            {
                throw new ArgumentNullException("file");
            }

            Interop.Elementary.elm_image_async_open_set(RealHandle, true);
            Interop.Elementary.elm_image_preload_disabled_set(RealHandle, false);

            var tcs = new TaskCompletionSource <bool>();

            cancellationToken.Register(() =>
            {
                if (tcs != null && !tcs.Task.IsCompleted)
                {
                    tcs.SetCanceled();
                }
            });

            SmartEvent loadReady = new SmartEvent(this, RealHandle, "load,ready");

            loadReady.On += (s, e) =>
            {
                loadReady.Dispose();
                LoadingCompleted?.Invoke(this, EventArgs.Empty);
                if (tcs != null && !tcs.Task.IsCompleted)
                {
                    tcs.SetResult(true);
                }
            };

            SmartEvent loadError = new SmartEvent(this, RealHandle, "load,error");

            loadError.On += (s, e) =>
            {
                loadError.Dispose();
                LoadingFailed?.Invoke(this, EventArgs.Empty);
                if (tcs != null && !tcs.Task.IsCompleted)
                {
                    tcs.SetResult(false);
                }
            };

            bool ret = Interop.Elementary.elm_image_file_set(RealHandle, file, null);

            if (!ret)
            {
                throw new InvalidOperationException("Failed to set file to Image");
            }

            return(tcs.Task);
        }
Esempio n. 9
0
 /// <summary>
 /// 加载家园
 /// </summary>
 /// <param name="callback"></param>
 /// <param name="args"></param>
 private void ChangeLoadingHome(LoadingCompleted callback = null, object args = null)
 {
     if (Constants.ISCLIENT)
     {
         Create(WorldType.Home, LoadMockPlayerData(1));
     }
     else
     {
         GameManager.Instance.RequestHomeLandData(DataCenter.Instance.myUserId, WorldType.Home);
     }
     LoadingManager.Instance.CloseLoading();
     DelayManager.Instance.AddDelayCall(() => { _loading = false; if (callback != null)
                                                {
                                                    callback(true);
                                                }
                                        }, 1.0f);
 }
Esempio n. 10
0
 /// <summary>
 /// 加载战斗(本地或服务器)
 /// </summary>
 /// <param name="callback"></param>
 /// <param name="args"></param>
 private void ChangeLoadingBattle(LoadingCompleted callback = null, object args = null)
 {
     if (args != null)
     {
         if (Constants.ISCLIENT)
         {
             Create(WorldType.Battle, LoadMockPlayerData(2), DataCenter.Instance.Defender);
         }
         else
         {
             int[] info = (int[])args;
             CurSearchType = (FightSearchReq.SearchType)info[0];
             GameManager.Instance.RequestFightSearch(info[0], info[1], resp =>
             {
                 if (resp == null)
                 {
                     //  超时 TODO:考虑添加返回按钮咯
                 }
                 else if (resp.errorType > 0)
                 {
                     GameTipsManager.Instance.ShowGameTips("搜索失败");//TODO:考虑添加返回按钮咯
                     return;
                 }
                 else
                 {
                     //  TODO:
                     Create(WorldType.Battle, resp.respWrapper.campResp.campVO, null);
                 }
             });
         }
     }
     //  加载本地关卡 TODO
     LoadingManager.Instance.CloseLoading();
     DelayManager.Instance.AddDelayCall(() => { _loading = false; if (callback != null)
                                                {
                                                    callback(true);
                                                }
                                        }, 1.0f);
 }
Esempio n. 11
0
 void IImageSourcePartEvents.LoadingCompleted(bool successful)
 {
     IsLoading = false;
     LoadingCompleted?.Invoke(successful);
 }
Esempio n. 12
0
 void IImageSourcePartEvents.LoadingCompleted(bool successful) =>
 LoadingCompleted?.Invoke(successful);
Esempio n. 13
0
        /// <summary>
        /// Sets the stream that is used as the image's source with async.
        /// </summary>
        /// <param name="stream">The stream that is used as an image source.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>(true = success, false = error)</returns>
        /// <since_tizen> preview </since_tizen>
        public async Task <bool> LoadAsync(Stream stream, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            Interop.Elementary.elm_image_async_open_set(RealHandle, true);
            Interop.Elementary.elm_image_preload_disabled_set(RealHandle, false);

            var tcs = new TaskCompletionSource <bool>();

            cancellationToken.Register(() =>
            {
                if (tcs != null && !tcs.Task.IsCompleted)
                {
                    tcs.SetCanceled();
                }
            });

            SmartEvent loadReady = new SmartEvent(this, RealHandle, "load,ready");

            loadReady.On += (s, e) =>
            {
                loadReady.Dispose();
                LoadingCompleted?.Invoke(this, EventArgs.Empty);
                if (tcs != null && !tcs.Task.IsCompleted)
                {
                    tcs.SetResult(true);
                }
            };

            SmartEvent loadError = new SmartEvent(this, RealHandle, "load,error");

            loadError.On += (s, e) =>
            {
                loadError.Dispose();
                LoadingFailed?.Invoke(this, EventArgs.Empty);
                if (tcs != null && !tcs.Task.IsCompleted)
                {
                    tcs.SetResult(false);
                }
            };

            using (MemoryStream memstream = new MemoryStream())
            {
                await stream.CopyToAsync(memstream);

                unsafe
                {
                    byte[] dataArr = memstream.ToArray();
                    fixed(byte *data = &dataArr[0])
                    {
                        bool ret = Interop.Elementary.elm_image_memfile_set(RealHandle, data, dataArr.Length, IntPtr.Zero, IntPtr.Zero);

                        if (!ret)
                        {
                            return(false);
                        }
                    }
                }
            }

            return(await tcs.Task);
        }
Esempio n. 14
0
 /// <summary>
 /// 加载好友家园
 /// </summary>
 /// <param name="callback"></param>
 /// <param name="args"></param>
 private void ChangeLoadingVisit(LoadingCompleted callback = null, object args = null)
 {
     Assert.Should(args != null);
     //  加载好友
     Assert.Fail("unsupport now");
 }
Esempio n. 15
0
 protected void HideLoading()
 {
     LoadingCompleted?.Invoke(this, EventArgs.Empty);
 }