Esempio n. 1
0
        /// <summary>
        /// レシピ追加ボタン
        /// </summary>
        private void AddRecipeButtonClicked(object sender, EventArgs e)
        {
            RecipeSelectWindowController recipeSelectController = new RecipeSelectWindowController();

            recipeSelectController.ShowRecipeSelectWindow(parentWindow);

            ProductionRecipe productionRecipe = recipeSelectController.ProductionRecipe;

            if (productionRecipe != null)
            {
                AddRecipe(productionRecipe);
            }

            recipeSelectController = null;
        }
Esempio n. 2
0
        /// <summary>
        /// 生産物と要求物のリストを生成して表示まで
        /// </summary>
        private void CreateProductionAndRequiredList()
        {
            List <string[]> materialList = new List <string[]>();

            // レシピのリストを逆転したものを用意
            List <ProductionRecipe> reversed = new List <ProductionRecipe>(productionRecipes);

            reversed.Reverse();

            foreach (ProductionRecipe recipe in reversed)
            {
                int i = 0;
                // 要求素材から検索して同名があれば数値だけ追加、なければ名前と追加
                foreach (RequiredMaterial requiredMaterial in recipe.RequiredMaterials)
                {
                    bool flag = false;
                    foreach (string[] material in materialList)
                    {
                        if (material[0].Equals(requiredMaterial.Name) && !material[1].Equals("0"))
                        {
                            flag        = true;
                            material[1] = Math.Round(double.Parse(material[1]) - recipe.ActualRequiredNumberOfMaterialsPerMin[i], 2).ToString();
                        }
                    }

                    if (!flag)
                    {
                        materialList.Add(new string[] { requiredMaterial.Name, (-recipe.ActualRequiredNumberOfMaterialsPerMin[i]).ToString() });
                    }
                    i++;
                }

                i = 0;
                bool exist = false;
                foreach (string[] production in materialList)
                {
                    if (production[0].Equals(recipe.ProductionMaterial.Name) && double.TryParse(production[1], out double pro) && pro > 0)
                    {
                        exist = true;
                        break;
                    }
                    i++;
                }

                if (exist)
                {
                    Console.WriteLine("Name:" + materialList[i][0]);
                    Console.WriteLine("Number:" + materialList[i][1]);
                    Console.WriteLine("Production:" + recipe.NumberOfMaterialProduction);
                    Console.WriteLine("Result:" + double.Parse(materialList[i][1]) + recipe.NumberOfMaterialProduction);
                    materialList[i][1] = (double.Parse(materialList[i][1]) + recipe.NumberOfMaterialProduction).ToString();
                }
                else
                {
                    materialList.Add(new string[] { recipe.ProductionMaterial.Name, recipe.NumberOfMaterialProduction.ToString() });
                }
            }

            // 表示用のリストとか作成
            List <MaterialWithNumOnButton> productionList = new List <MaterialWithNumOnButton>();
            List <MaterialWithNumOnButton> requiredList   = new List <MaterialWithNumOnButton>();

            foreach (string[] value in materialList)
            {
                if (double.Parse(value[1]) < 0)
                {
                    MaterialWithNumOnButton material = new MaterialWithNumOnButton();

                    // 名前と数値の設定
                    material.TextBlock_Name.Text   = value[0];
                    material.TextBlock_Number.Text = (-(double.Parse(value[1]))).ToString();

                    // ボタンイベントの追加
                    void RequiredListClicked(object sender, EventArgs e)
                    {
                        RecipeSelectWindowController recipeSelectController = new RecipeSelectWindowController();

                        recipeSelectController.ShowRecipeSelectWindow(value[0], -(double.Parse(value[1])), parentWindow);

                        ProductionRecipe productionRecipe = recipeSelectController.ProductionRecipe;

                        if (productionRecipe != null)
                        {
                            AddRecipe(productionRecipe);
                        }

                        recipeSelectController = null;
                    }

                    material.Button_RequestRecipeSelect.Click += RequiredListClicked;

                    requiredList.Add(material);
                }
                else if (double.Parse(value[1]) > 0)
                {
                    MaterialWithNumOnButton material = new MaterialWithNumOnButton();

                    // 名前と数値の設定
                    material.TextBlock_Name.Text   = value[0];
                    material.TextBlock_Number.Text = (double.Parse(value[1])).ToString();
                    productionList.Add(material);
                }
            }

            // 表示させる
            productionBlockTab.AddMaterialsToProductionListPanel(productionList);
            productionBlockTab.AddMaterialsToRequiredListPanel(requiredList);
        }