Esempio n. 1
0
        /// <summary>
        /// Populate allEntityDictonary for all instance of IProtoEntity with corresponding ViewModels.
        /// </summary>
        private static void SetAllEntitiesViewModels()
        {
            List <IProtoEntity> allEntitiesList = Api.FindProtoEntities <IProtoEntity>();

            foreach (IProtoEntity entity in allEntitiesList)
            {
                Type entityType = entity.GetType();
                //Api.Logger.Warning("CNEI: Looking types for " + entity);
                bool templateFound = false;
                ProtoEntityViewModel newEntityViewModel = null;
                do
                {
                    Type currentType = Type.GetType("CryoFall.CNEI.UI.Controls.Game.CNEImenu.Data." +
                                                    GetNameWithoutGenericArity(entityType.Name) + "ViewModel");
                    //Api.Logger.Info("CNEI: " + entityType.Name + "  " + GetNameWithoutGenericArity(entityType.Name)
                    //                + " " + currentType);
                    if (currentType != null && !currentType.IsAbstract)
                    {
                        try
                        {
                            newEntityViewModel = (ProtoEntityViewModel)Activator.CreateInstance(currentType, entity);
                        }
                        catch (MissingMethodException)
                        {
                            Api.Logger.Error("CNEI: Can not apply constructor of " + currentType + " type for " + entity);
                        }
                        if (newEntityViewModel != null)
                        {
                            if (newEntityViewModel is RecipeViewModel newRecipeViewModel)
                            {
                                AddRecipe(newRecipeViewModel);
                            }
                            EntityTypeHierarchy.Add(entity.GetType(), newEntityViewModel);
                            allEntityDictonary.Add(entity, newEntityViewModel);
                            resourceDictionaryNames.Add(newEntityViewModel.ResourceDictonaryName);
                            templateFound = true;
                        }
                    }
                    entityType = entityType.BaseType;
                } while (entityType != null && (entityType.BaseType != null) && (!templateFound));
                if (entityType == null)
                {
                    Api.Logger.Warning("CNEI: Template for " + entity + "not found");
                    newEntityViewModel = new ProtoEntityViewModel(entity);
                    EntityTypeHierarchy.Add(entity.GetType(), newEntityViewModel);
                    allEntityDictonary.Add(entity, newEntityViewModel);
                    resourceDictionaryNames.Add(newEntityViewModel.ResourceDictonaryName);
                }
            }

            allEntityCollection = new ObservableCollection <ProtoEntityViewModel>(allEntityDictonary.Values);
            allEntityWithTemplatesCollection = new ObservableCollection <ProtoEntityViewModel>(
                allEntityCollection.Where(vm => vm.GetType().IsSubclassOf(typeof(ProtoEntityViewModel))));
        }
Esempio n. 2
0
 public static void Open(ProtoEntityViewModel entityViewModel)
 {
     if (Instance == null)
     {
         var instance = new WindowCNEIdetails();
         instance.entityVMStack.Push(entityViewModel);
         Instance = instance;
         Api.Client.UI.LayoutRootChildren.Add(instance);
     }
     else
     {
         if (Instance.entityVMStack.Peek() != entityViewModel)
         {
             Instance.entityVMStack.Push(entityViewModel);
             Instance.UpdateCount();
             Instance.DataContext = Instance.entityVMStack.Peek();
         }
     }
 }