protected ScreenController( IScreenModelFactory screenModelFactory, IScreenView screenView) { _screenModelFactory = screenModelFactory; _screenView = screenView; }
//委托的变量是函数指针,委托Action<Exception>里面的Exception就是函数的参数 /// <summary> /// 导航任务构造函数 /// </summary> /// <param name="type">导航任务类型枚举</param> /// <param name="view">导航任务关联的IScreenView</param> /// <param name="_callback">导航任务关联的回调函数</param> /// <param name="layer">导航任务关联的ScreenViewLayer</param> public NavTask(NavTaskType type, IScreenView view, Action <Exception> _callback, ScreenViewLayer layer) { this.type = type; this.view = view; this.callback = _callback; this.layer = layer; }
/// <summary> /// 通过名称获取IScreenView /// </summary> /// <param name="svName">IScreenView名称</param> /// <returns></returns> public IScreenView GetScreenView(string svName) { IScreenView sv = null; //遍历显示中的IScreenView列表,找到直接跳出 foreach (var _sv in views) { if (_sv.Name == svName) { sv = _sv; break; } } //如果没有找到 if (sv == null) { //遍历未显示的IScreenView列表,找到直接跳出 foreach (var _sv in unuseViews) { if (_sv.Key == svName) { sv = _sv.Value; break; } } } return(sv); }
/// <summary> /// 灵魂功能,导航到一个指定名称的ScreenView,可能是向前,也可能是向后 /// </summary> /// <param name="_name"></param> /// <param name="onLoad"></param> public void BeginNavTo(string name) { // if (currentView != null && currentView.Name == name) { Debugger.LogError("别闹,当前就是" + name); return; } // IScreenView view = null; if (this.allViews.TryGetValue(name, out view)) { view.BeginInit(); if (currentView != null) { currentView.BeginExit(); } // currentView = view; currentViewIndex = -1; // this.navViews.Add(view); if (navViews.Count > 10) { navViews.RemoveAt(0); } } }
/// <summary> /// ScreenViewLayer 向前导航(从未使用的IScreenView列表中查找,然后重新添加到显示中的IScreenView列表中) /// </summary> /// <param name="name">IScreenView名称</param> /// <param name="onLoad">异常回调</param> public void BeginNavForward(object name, Action <Exception> onLoad = null) { //获取IScreenView名称 string _name = name.ToString(); IScreenView view = null; //如果在未使用的IScreenView列表中找到这个IScreenView if (unuseViews.TryGetValue(_name, out view)) { //如果isLoad = true //if (view.isLoad) //{ // //如果有异常回调函数,抛出异常 // if (onLoad != null) // onLoad(new Exception("一个不在使用中的view 却显示并加载,这 很异常")); // return; //} //从未使用的IScreenView列表中移除这个IScreenView unuseViews.Remove(_name); //创建一个新的NavTask,入队 //实际就是重新将这个IScreenView添加到显示的IScreenView列表中 tasks.Enqueue(new NavTask(NavTaskType.InitAndAdd, view, onLoad, this)); } //如果没有找到 else { //如果有异常回调函数,抛出异常 if (onLoad != null) { onLoad(new Exception("找不到这个view")); } } }
public void OnScreenOpened(Notification n) { ScreenOpenedNotification screenOpenedNotification = (ScreenOpenedNotification)n; IScreenObject screenObject = screenOpenedNotification.Screen; IScreenView view = this.ServiceProxy.ScreenViewService.GetScreenView(screenObject); // Create a tab item from the template TabItem ti = new TabItem(); DataTemplate template = (DataTemplate)this.Resources["TabItemHeaderTemplate"]; UIElement element = (UIElement)template.LoadContent(); // Wrap the underlying screen object in a ScreenWrapper object ti.DataContext = new ScreenWrapper(screenObject); ti.Header = element; ti.HeaderTemplate = template; ti.Content = view.RootUI; // Add the tab item to the tab control. this.ScreenArea.Items.Add(ti); this.ScreenArea.SelectedItem = ti; // Set the currently active screen in the active screens view model. this.ServiceProxy.ActiveScreensViewModel.Current = screenObject; }
/// <summary> /// 获取一个sv /// </summary> /// <param name="svName"></param> /// <returns></returns> public IScreenView GetScreenView(string svName) { IScreenView sv = null; // foreach (var _sv in views) { if (_sv.name == svName) { sv = _sv; break; } } // if (sv == null) { foreach (var _sv in unuseViews) { if (_sv.Key == svName) { sv = _sv.Value; break; } } } return(sv); }
public void BeginNavForward(string name, Action <Exception> onLoad = null) { IScreenView view = null; if (unuseViews.TryGetValue(name, out view)) { if (view.isLoad) { if (onLoad != null) { onLoad(new Exception("一个不在使用中的view 却显示并加载,这 很异常")); } return; } unuseViews.Remove(name); //将对象添加到队列的末尾处 tasks.Enqueue(new NavTask(NavTaskType.InitAndAdd, view, onLoad, this)); } else { if (onLoad != null) { onLoad(new Exception("找不到这个view")); } } }
/// <summary> /// ScreenViewLayer 向后导航 /// </summary> /// <param name="onLoad">异常回调</param> public void BeginNavBack() { if (currentViewIndex == 0 || currentViewIndex - 1 >= navViews.Count) { BDebug.LogError("别闹,前方没有view"); return; } currentViewIndex--; IScreenView view = navViews[currentViewIndex]; view.BeginInit(); if (currentView != null) { currentView.BeginExit(); } // currentView = view; }
/// <summary> /// ScreenViewLayer 向前导航 /// </summary> /// <param name="name">IScreenView名称</param> /// <param name="onLoad">异常回调</param> public void BeginNavForward(string name) { if (currentViewIndex == -1 || currentViewIndex + 1 >= navViews.Count) { BDebug.LogError("别闹,前方没有view"); return; } currentViewIndex++; IScreenView view = navViews[currentViewIndex]; view.BeginInit(); if (currentView != null) { currentView.BeginExit(); } // currentView = view; }
public void OnScreenRefreshed(Notification n) { ScreenReloadedNotification srn = (ScreenReloadedNotification)n; foreach (TabItem ti in this.ScreenArea.Items) { IScreenObject realScreenObject = ((ScreenWrapper)ti.DataContext).RealScreenObject; if (realScreenObject == srn.OriginalScreen) { IScreenView view = this.ServiceProxy.ScreenViewService.GetScreenView( srn.NewScreen); ti.Content = view.RootUI; ti.DataContext = new ScreenWrapper(srn.NewScreen); break; } } }
public MenuScreenController( IScreenModelFactory screenModelFactory, IScreenView screenView) : base(screenModelFactory, screenView) { }
/// <summary> /// 增加一个Screen,Screen 虽然立即创建, /// Screen应设计为不执行BeginLoad不加载任何内容,完成后由回调通知 /// <para>注册IScreenView,默认添加到未使用的IScreenView列表</para> /// </summary> /// <param name="creator"></param> public void RegScreen(IScreenView view) { allViews.Add(view.Name, view); }
/// <summary> /// 灵魂功能,导航到一个指定名称的ScreenView,可能是向前,也可能是向后 /// </summary> /// <param name="_name"></param> /// <param name="onLoad"></param> public void BeginNavTo(object name, Action <Exception> onLoad = null) { //获取IScreenView名称 string _name = name.ToString(); curName = _name; // My JDeBug.Inst.Log("name:" + name); IScreenView view = null; //如果在未使用的IScreenView列表中找到 if (unuseViews.TryGetValue(_name, out view)) { //My JDeBug.Inst.Log("unuseViews: " + name); BeginNavForward(_name, onLoad); return; } else { //My JDeBug.Inst.Log("using : " + name); //有可能在队列中 bool bNeedBack = false; int navtoindex = -1; int navtobeginindex = -1; for (int i = views.Count - 1; i >= 0; i--) { if (views[i].Name == _name) { if (i == views.Count - 1) { //别闹,就在顶上,Nav个毛线 if (onLoad != null) { onLoad(new Exception("别闹,就在顶上,Nav个毛线")); } return; } else { //在队列中,NavBack直到达成目标 //My JDeBug.Inst.Log("在队列中,NavBack直到达成目标"); bNeedBack = true; navtobeginindex = navtoindex = i; break; } } } while (bNeedBack && views[navtobeginindex].IsTransparent && navtobeginindex >= 0) { navtobeginindex--; } // if (bNeedBack) { List <IScreenView> viewforexit = new List <IScreenView>(); List <IScreenView> viewforinit = new List <IScreenView>(); int exitcount = 0; int initcount = 0; Action <Exception> onnavinit = (err) => { //Debug.LogWarning("initone:" + initcount); if (err != null) { if (onLoad != null) { onLoad(err); } return; } initcount--; if (initcount == 0) { if (onLoad != null) { onLoad(err); } } }; Action <Exception> doinit = (err) => { if (viewforinit.Count == 0) { if (onLoad != null) { onLoad(null); } } foreach (var v in viewforinit) { v.BeginInit(onnavinit, this); } }; Action <Exception> onnav = (err) => { //Debug.LogWarning("exitone:" + exitcount); if (err != null) { if (onLoad != null) { onLoad(err); } return; } exitcount--; if (exitcount == 0) { doinit(err); } }; //Debug.LogWarning("from" + (views.Count - 1).ToString() + "to===" + navtoindex); for (int i = views.Count - 1; i > navtoindex; i--) { //Debug.LogWarning("begin exitone==" + views[i].name); if (views[i].IsLoad) { //Debug.LogWarning("begin exitone:" + views[i].name); viewforexit.Add(views[i]); } this.unuseViews.Add(views[i].Name, views[i]); views.RemoveAt(i); } for (int i = navtobeginindex; i <= navtoindex; i++) { if (!views[i].IsLoad) { viewforinit.Add(views[i]); } } initcount = viewforinit.Count; exitcount = viewforexit.Count; //Debug.LogWarning("exitcount:" + exitcount); foreach (var e in viewforexit) { e.BeginExit(onnav); } //Debug.LogWarning("need navto begin in:" + views[navtobeginindex].name + "-" + views[navtoindex].name); //Action<Exception> onnav = null; //onnav = (err) => //{ // if (err != null) // { // onLoad(err); // } // var vlast = views[views.Count - 1]; // My JDeBug.Inst.Log("vlast:" + vlast + ",now:" + name); // if (vlast.name == name) // { // if (onLoad != null) // onLoad(null); // } // else // { // BeginNavBack(onnav); // } //}; //BeginNavBack(onnav); return; } else { if (onLoad == null) { //Debug.LogError("onload is null"); } else { onLoad(new Exception("name: " + _name + "view 不存在.")); } } return; } }
public ScreenPresenter(IScreenView view) { screenview = view; }
/// <summary> /// 增加一个Screen,Screen 虽然立即创建,Screen应设计为不执行BeginLoad不加载任何内容,完成后由回调通知 /// </summary> /// <param name="creator"></param> public void RegScreen(IScreenView view) { unuseViews.Add(view.name, view); }