private bool DestroyUIInternal(string p_name)
    {
        try
        {
            if (!m_UIItemMap.ContainsKey(p_name))
            {
                throw new KeyNotFoundException(string.Format("Cannot destroy UI: {0} cause key not found in UIItemMap",
                                                             p_name));
            }

            var item = m_UIItemMap[p_name];

            Object.Destroy(item.RootObject);
            if (item.Mediator != null)
            {
                MediatorManager.GetInstance().Remove(item.Mediator.GetType());
            }

            GameAssets.SubBundleRef(m_UIItemMap[p_name].BundlePath);

            m_UICategoryMap[item.CategoryName].RemoveItem(item);
            m_UIItemMap.Remove(p_name);

            return(true);
        }
        catch (Exception e)
        {
            LogModule.ErrorLog("Exception in destroy UI, {0}\n{1}", e.Message, e.StackTrace);
            return(false);
        }
    }
Beispiel #2
0
    public void ReceiveBattleInfor(object parm)
    {
        LogModule.DebugLog("ReceiveBattlerInfor");
        CBattleInfor tBattleInfor = GameFacade.GetProxy <BattleProxy>().BattleInfor;

        mCurrentCamp = (SquadCamp)tBattleInfor.camp;
        ServerBattleState tServerBattleState = (ServerBattleState)tBattleInfor.currentState;

        if (tServerBattleState == ServerBattleState.STATUS_SELECTTARGET ||
            tServerBattleState == ServerBattleState.STATUS_MARCH ||
            tServerBattleState == ServerBattleState.STATUS_COMBAT)
        {
            mBattleState = BattleState.Start;
        }
        else
        {
            mBattleState = BattleState.prepare;
        }
        if (mSceneID != tBattleInfor.sceneId)
        {
            return;
        }
        StartCoroutine(LoadUnitAssets(tBattleInfor));

        //Open Battle UI.
        MediatorManager.GetInstance().Add(new BattleUIController());
    }
Beispiel #3
0
 public override void Init()
 {
     mProxyMgr = new ProxyManager(this);
     mProxyMgr.Register();
     mMediatorMgr = new MediatorManager(this);
     mMediatorMgr.Register();
     mCommondMgr = new CommondManager(this);
     mCommondMgr.Register();
     Debug.Log("初始化PureMVC框架完成!!");
     base.Init();
 }
Beispiel #4
0
 static int OnDestroy(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         MediatorManager obj = (MediatorManager)ToLua.CheckObject(L, 1, typeof(MediatorManager));
         obj.OnDestroy();
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Beispiel #5
0
    static int GetInstance(IntPtr L)
    {
        try
        {
            ToLua.CheckArgsCount(L, 0);
            MediatorManager o = Singleton <MediatorManager> .GetInstance();

            ToLua.PushObject(L, o);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Beispiel #6
0
 static int Remove(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         MediatorManager obj  = (MediatorManager)ToLua.CheckObject(L, 1, typeof(MediatorManager));
         System.Type     arg0 = (System.Type)ToLua.CheckObject(L, 2, typeof(System.Type));
         obj.Remove(arg0);
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Beispiel #7
0
 static int Add(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         MediatorManager obj  = (MediatorManager)ToLua.CheckObject(L, 1, typeof(MediatorManager));
         IMediator       arg0 = (IMediator)ToLua.CheckObject(L, 2, typeof(IMediator));
         obj.Add(arg0);
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Beispiel #8
0
 static int Get(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         MediatorManager obj  = (MediatorManager)ToLua.CheckObject(L, 1, typeof(MediatorManager));
         string          arg0 = ToLua.CheckString(L, 2);
         object          o    = obj.Get(arg0);
         ToLua.Push(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
    void Awake()
    {
        EventManager.GetInstance().AddEventListener("Private_TroopTrainRefreshAll", RefreshAll);
        EventManager.GetInstance().AddEventListener("Private_TroopTrainRefreshHero", RefreshHero);
        EventManager.GetInstance().AddEventListener("Private_TroopTrainRefreshTroops", RefreshTrolls);

        _meditor = new TroopTrainUIMediator();
        MediatorManager.GetInstance().Add(_meditor);

        buildTimes = new BuildTime[buildSlot.Length];
        for (int i = 0; i < buildTimes.Length; i++)
        {
            buildTimes [i]         = new BuildTime();
            buildTimes [i].state   = TroopState.Null;
            buildTimes [i].endTime = 0;
        }
    }
Beispiel #10
0
    static int _CreateMediatorManager(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 0)
            {
                MediatorManager obj = new MediatorManager();
                ToLua.PushObject(L, obj);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to ctor method: MediatorManager.New"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
    /// <summary>
    /// Create a UI
    /// </summary>
    /// <param name="p_type">UI category: fullscreen, window, popup, etc</param>
    /// <param name="p_name">name you defined</param>
    /// <param name="p_mediatorType"></param>
    /// <param name="p_prefab">prefab to instantiate</param>
    /// <param name="p_viewInitCallBack"></param>
    /// <param name="p_viewRefreshCallBack"></param>
    /// <param name="p_allocateDepth">allocate several panel depth to ui</param>
    /// <param name="p_viewName"></param>
    /// <param name="isShowAnimation"></param>
    private void CreateUIInternal(UIItemConfig p_config, GameObject p_prefab, DelegateHelper.TableDelegate p_viewInitCallBack, DelegateHelper.TableDelegate p_viewRefreshCallBack = null, bool isShowAnimation = true)
    {
        try
        {
            if (!m_UICategoryMap.ContainsKey(p_config.Type))
            {
                throw new KeyNotFoundException(string.Format("Key: {0} not found in UI Category.", p_config.Type));
            }

            if (p_prefab == null)
            {
                throw new Exception("Cannot create UI cause no res provided.");
            }

            if (m_UICategoryMap[p_config.Type].RemainingDepth <= 0)
            {
                LogModule.WarningLog("Cannot create UI: {0} cause remaining depth of {1} is {2}", p_config.Name, p_config.Type, m_UICategoryMap[p_config.Type].RemainingDepth);
                return;
            }

            //Create UI
            var     root  = Utils.AddChild(m_UICategoryMap[p_config.Type].RootObject.transform, p_config.Name);
            UIPanel panel = root.AddComponent <UIPanel>();

            var ui       = NGUITools.AddChild(root, p_prefab);
            var viewBase = ui.AddComponent <UIViewBase>();
            viewBase.Name = p_config.Name;

            //Initialize UI
            LuaTable view     = null;
            object   mediator = null;

            if (!string.IsNullOrEmpty(p_config.ViewName))
            {
                view           = LuaHelper.GetOutletComponent(ui, p_config.ViewName).m_LuaTable;
                view["UIName"] = p_config.Name;
            }

            if (!string.IsNullOrEmpty(p_config.MediatorType))
            {
                mediator = Activator.CreateInstance(Type.GetType(p_config.MediatorType));
                MediatorManager.GetInstance().Add((IMediator)mediator);
                ((IUIMediator)mediator).m_UIName = p_config.Name;
            }

            if (!string.IsNullOrEmpty(p_config.ViewName) && !string.IsNullOrEmpty(p_config.MediatorType))
            {
                view["Mediator"] = mediator;
                ((IUIMediator)mediator).m_View = view;
            }

            m_UIItemMap.Add(p_config.Name, new UIItem()
            {
                CategoryName = p_config.Type,
                Name         = p_config.Name,
                PanelDepth   = panel.sortingOrder,
                RootObject   = root,
                ViewBase     = viewBase,
                ViewName     = p_config.ViewName,
                View         = view,
                Mediator     = mediator,
                UIObject     = ui,
                BundlePath   = p_config.BundleName
            });

            //Get depth and set.
            int minDepth = m_UICategoryMap[p_config.Type].GetNewItemDepth();
            panel.depth = minDepth;
            int maxDepth = Utils.SetUILayer(ui, minDepth);
            if (maxDepth > 0)
            {
                m_UICategoryMap[p_config.Type].AddItem(m_UIItemMap[p_config.Name], maxDepth - minDepth + 1);
            }
            else
            {
                m_UICategoryMap[p_config.Type].AddItem(m_UIItemMap[p_config.Name], 1);
            }

            //Add delegate
            if (isShowAnimation)
            {
                if (p_viewInitCallBack != null && m_UIItemMap[p_config.Name].View != null)
                {
                    Action removeInitAction = null;
                    Action initAction       = () =>
                    {
                        p_viewInitCallBack(m_UIItemMap[p_config.Name].View);
                        removeInitAction();
                    };

                    removeInitAction = () =>
                    {
                        m_UIItemMap[p_config.Name].ViewBase.OnOpenUIComplete -= initAction;
                    };

                    m_UIItemMap[p_config.Name].ViewBase.OnOpenUIComplete += initAction;
                }

                if (p_viewRefreshCallBack != null && m_UIItemMap[p_config.Name].View != null)
                {
                    m_UIItemMap[p_config.Name].ViewBase.OnOpenUIComplete += () =>
                    {
                        p_viewRefreshCallBack(m_UIItemMap[p_config.Name].View);
                    };
                }

                m_UIItemMap[p_config.Name].ViewBase.OnCloseUIComplete += () =>
                {
                    CloseUIInternal(p_config.Name);
                };
            }
            //Init
            else
            {
                if (p_viewInitCallBack != null && m_UIItemMap[p_config.Name].View != null)
                {
                    p_viewInitCallBack(m_UIItemMap[p_config.Name].View);
                }
            }

            ExeAfterOpenUI(p_config, p_viewRefreshCallBack, isShowAnimation);

            return;
        }
        catch (Exception e)
        {
            LogModule.ErrorLog("Exception in create UI intrenal, {0}\n{1}", e.Message, e.StackTrace);
            return;
        }
    }
 void OnDestroy()
 {
     //Close Battle UI.
     MediatorManager.GetInstance().Remove(typeof(BattleUIController));
 }