Esempio n. 1
0
        public static bool OnIngredientSelectorClicked(CraftingMenu __instance, int _selectorIndex)
        {
            try
            {
                IngredientSelector[] m_ingredientSelectors         = (IngredientSelector[])AccessTools.Field(typeof(CraftingMenu), "m_ingredientSelectors").GetValue(__instance);
                List <int>           ingredientSelectorCachedItems = (List <int>)AccessTools.Field(typeof(CraftingMenu), "ingredientSelectorCachedItems").GetValue(__instance);
                int m_lastRecipeIndex = (int)AccessTools.Field(typeof(CraftingMenu), "m_lastRecipeIndex").GetValue(__instance);
                List <KeyValuePair <int, Recipe> > m_complexeRecipes = (List <KeyValuePair <int, Recipe> >)AccessTools.Field(typeof(CraftingMenu), "m_complexeRecipes").GetValue(__instance);
                List <RecipeDisplay> m_recipeDisplays = (List <RecipeDisplay>)AccessTools.Field(typeof(CraftingMenu), "m_recipeDisplays").GetValue(__instance);
                DictionaryExt <int, CompatibleIngredient> m_availableIngredients = (DictionaryExt <int, CompatibleIngredient>)AccessTools.Field(typeof(CraftingMenu), "m_availableIngredients").GetValue(__instance);
                CharacterUI      m_characterUI        = (CharacterUI)AccessTools.Field(typeof(CraftingMenu), "m_characterUI").GetValue(__instance);
                ItemListSelector m_tempSelectorWindow = (ItemListSelector)AccessTools.Field(typeof(CraftingMenu), "m_tempSelectorWindow").GetValue(__instance);
                Transform        m_selectorWindowPos  = (Transform)AccessTools.Field(typeof(CraftingMenu), "m_selectorWindowPos").GetValue(__instance);
                bool             m_simpleMode         = (bool)AccessTools.Field(typeof(CraftingMenu), "m_simpleMode").GetValue(__instance);

                IngredientSelector ingredientSelector = m_ingredientSelectors[_selectorIndex];
                ingredientSelectorCachedItems.Clear();
                if (m_lastRecipeIndex != -1)
                {
                    if (m_complexeRecipes[m_lastRecipeIndex].Value.Ingredients[_selectorIndex].ActionType == RecipeIngredient.ActionTypes.AddGenericIngredient)
                    {
                        IList <int> stepCompatibleIngredients = m_recipeDisplays[m_lastRecipeIndex].GetStepCompatibleIngredients(_selectorIndex);
                        for (int i = 0; i < stepCompatibleIngredients.Count; i++)
                        {
                            if (m_availableIngredients.TryGetValue(stepCompatibleIngredients[i], out CompatibleIngredient _outValue) && _outValue.AvailableQty > 0)
                            {
                                ingredientSelectorCachedItems.Add(_outValue.ItemID);
                            }
                        }
                    }
                }
                else
                {
                    for (int j = 0; j < m_availableIngredients.Count; j++)
                    {
                        if (m_availableIngredients.Values[j].AvailableQty > 0 || ingredientSelector.AssignedIngredient == m_availableIngredients.Values[j])
                        {
                            // lasyan3 : Disallow cleaning water without cooking pot
                            if (m_availableIngredients.Values[j].IsWaterItem && m_simpleMode)
                            {
                                continue;
                            }
                            // lasyan3 : Disallow use of rancid water
                            //if (m_availableIngredients.Values[j].IsWaterItem && m_availableIngredients.Values[j].ItemPrefab.ItemID == (int)eItemIDs.RancidWater) continue;
                            ingredientSelectorCachedItems.Add(m_availableIngredients.Values[j].ItemID);
                        }
                    }
                }
                if (ingredientSelectorCachedItems.Count > 0)
                {
                    m_tempSelectorWindow = m_characterUI.GetListSelector();
                    if ((bool)m_tempSelectorWindow)
                    {
                        m_tempSelectorWindow.onItemHovered = __instance.RefreshItemDetailDisplay;
                        m_tempSelectorWindow.onItemClicked = delegate(IItemDisplay _display)
                        {
                            __instance.IngredientSelectorHasChanged(_selectorIndex, _display?.RefItem.ItemID ?? (-1));
                            m_tempSelectorWindow.Hide();
                        };
                        m_tempSelectorWindow.Position = (((bool)m_selectorWindowPos) ? m_selectorWindowPos.position : __instance.transform.position);
                        m_tempSelectorWindow.Title    = ingredientSelector.Text;
                        m_tempSelectorWindow.ShowSelector(ingredientSelectorCachedItems, ingredientSelector.gameObject, m_lastRecipeIndex == -1);
                    }
                }
            }
            catch (Exception ex)
            {
                WorkInProgress.Instance.MyLogger.LogError("OnIngredientSelectorClicked: " + ex.Message);
            }
            return(false);
        }