Beispiel #1
0
    public bool AddItem2Bag(uint dwTypeID, Int16 nNum, EItemQuality eQ, int nCmd)
    {
        if (m_pPocket.IsFull())
        {
            return(false);
        }

        CItem pNewItem  = null;
        Int16 nBagSpace = (Int16)CalSpaceUsed(dwTypeID, nNum);

        // check bag free grid is enongh
        int nFreeSpace = m_pPocket.GetFreeSpaceSize();

        if (nFreeSpace < nBagSpace - 1)
        {
            return(false);
        }

        for (int i = 0; i < nBagSpace; i++)
        {
            tagItem pNew = ItemCreator.Create(dwTypeID, nNum, EItemQuality.EIQ_White, 0);
            if (pNew != null)
            {
                if (ItemCreator.MIsEquipment(dwTypeID))
                {
                    pNewItem = new CEquipment((tagEquip)pNew);
                }
                else
                {
                    pNewItem = new CItem(pNew);
                }
            }


            if (pNewItem != null)
            {
                AddItem(m_pPocket, pNewItem, nNum);
            }
        }

        return(true);
    }
Beispiel #2
0
    public GameObject CreateButton(GameObject movableObject, int amount, int position, bool temporal)
    {
        GameObject newButton = Instantiate(button, gameObject.transform, false) as GameObject;

        newButton.GetComponent <RectTransform>().anchoredPosition = new Vector2(0, (position + 1) * -step);
        ItemCreator itemCreator = newButton.GetComponent <ItemCreator>();

        itemCreator.defaultAmount = amount;
        itemCreator.currentAmount = amount;
        itemCreator.prefab        = movableObject;
        itemCreator.UpdateText();
        itemCreator.OnDelete = DeleteButtonMapEntry;

        itemCreator.temporal = temporal;
        if (!temporal)
        {
            itemCreator.Create();
        }
        return(newButton);
    }
        public void Run()
        {
            Settings appSettings = new Settings(); //init settings  (hardcoded- can be .json too)

            IFileManager fileManager = new FileManager();

            UnitOfWork fileUnit = new UnitOfWork(fileManager);

            fileUnit.ReadFiles();                            //read all tables from files to storage

            ITopView topView = new TopView(appSettings);     //top menu plank view instance

            IKeyReader arrowsFull   = new ArrowsKeyReader(); //key reader for categories and lists
            IKeyReader arrowsSimple = new SimpleReader();    //key reader for main top menu

            ITreePrinter <TopCategory> topPrinter  = new TreeView <TopCategory>(appSettings);
            ITreePrinter <Category>    treePrinter = new TreeView <Category>(appSettings); //tree category printer
            IItemsView listPrinter = new ItemsView(appSettings);                           //list items printer

            RecipeView recipeView = new RecipeView(fileUnit, topView);                     //to show selected recipe
            TreeNavigator <TopCategory> topNavigator  = new TreeNavigator <TopCategory>();
            TreeNavigator <Category>    treeNavigator = new TreeNavigator <Category>();    //tree navigator
            ListNavigator listNavigator = new ListNavigator(arrowsFull, listPrinter);      //list navigator

            IItemChooseView
                ingredientChooserView =
                new ItemChooseView(fileUnit);                                          //view for choose ingredients new recipe
            IRecipeCreatorView recipeCreatorView = new RecipeCreatorView(fileUnit);    //all recipe creator view
            IItemCreator       itemCreator       = new ItemCreator(topView, fileUnit); //ingredient creator view

            while (true)
            {
                topView.ShowMenu(string.Empty);

                ICategory mainMenuItem = topNavigator.Navigate(fileUnit.TopMenu.GetAll(), arrowsSimple,
                                                               topPrinter, appSettings.AutoexpandTree);

                switch (mainMenuItem.Id)
                {
                case 1:     //working with recipes

                    ICategory recipeCategory = treeNavigator.Navigate(fileUnit.Categories.GetAll(),
                                                                      arrowsFull, treePrinter, appSettings.AutoexpandTree);

                    RecipesSelector recipesSelector = new RecipesSelector();     //recipes selector for displaying

                    if (recipeCategory == null)
                    {
                        break;
                    }

                    topView.ShowMenu(recipeCategory.Name);

                    var recipesIn = recipesSelector.SelectRecipes(recipeCategory,
                                                                  fileUnit.Recipes.GetAll(), fileUnit.Categories.GetAll());

                    var recipeChosen =
                        listNavigator.Navigate(recipesIn, out var action, false);

                    if (recipeChosen == null && action == Action.Create)
                    {
                        Recipe newRecipe = new Recipe();

                        topView.ShowMenu($"Категория {recipeCategory.Name} > Новый рецепт . " +
                                         $"Выберите ингридиенты c помощью Space", true);

                        var selectedIingredients =
                            ingredientChooserView.Choose(listNavigator, itemCreator);     //Get ingredients

                        topView.ShowMenu($"Категория {recipeCategory.Name} > Новый рецепт ");

                        recipeCreatorView.FillRecipe(newRecipe, selectedIingredients, recipeCategory);
                    }

                    if (recipeChosen != null && action == Action.Select)
                    {
                        recipeView.ShowRecipe(recipeChosen);
                    }

                    break;

                case 2:     // working with ingredients

                    Action action1;

                    do
                    {
                        topView.ShowMenu(mainMenuItem.Name);

                        var ingredientChosen = listNavigator.Navigate(fileUnit.Ingredients.GetListables(),
                                                                      out action1, false);

                        if (ingredientChosen == null && action1 == Action.Create)
                        {
                            topView.ShowMenu(string.Empty);

                            itemCreator.Create();
                        }
                    } while (action1 != Action.Esc);

                    break;

                case 3:
                    fileUnit.Dispose(true);

                    return;
                }
            }
        }
 void OnCreateInvoked(CreateItemEventArgs args)
 {
     itemCreator.Create(args.TemplateId, args.Position, args.Rotation);
 }