void Start() { GameObject WeaponObject = Instantiate(Resources.Load("Prefabs/MeleeWeapon")) as GameObject; WeaponObject.name = "WeaponCrafting"; WeaponObject.transform.SetParent(transform, false); Recipes.Add(WeaponObject); foreach (KeyValuePair <string, bool> recipe in Recipes[0].GetComponent <IWeaponOutfit>().getRecipe()) { GameObject GUIRecipeSlot = Instantiate(Resources.Load("Prefabs/GUI/RecipeSlot")) as GameObject; RecipeSlot recipeSlot = GUIRecipeSlot.GetComponent <RecipeSlot>(); GUIRecipeSlot.name = recipe.Key; recipeSlot.setRecipeName(recipe.Key); recipeSlot.setRequired(recipe.Value); Button recipeSlotButton = recipeSlot.getButton(); GUIInventory inven = InventoryGUI.GetComponent <GUIInventory>(); Debug.Log("Bulilding Recipe with name: " + recipe.Key + "..."); recipeSlotButton.onClick.AddListener(() => { inven.FilterInventoryAndSetWorkbenchMode(GUIRecipeSlot.name, WeaponObject.transform.Find(GUIRecipeSlot.name).gameObject); inven.setMode("WorkBench"); InventoryGUI.SetActive(true); }); GUIRecipeSlot.transform.SetParent(WeaponRecipeGUI.transform, false); dButton.GetComponent <DoneButton>().setMadeWeapon(WeaponObject); } }
// Instantly moves card into slot public static void MoveStackIntoSlot(ElementStackToken elementStack, RecipeSlot slot) { // Make sure slot and stack are valid and empty and we have a match // Abort with feedback if we don't if (!(Validator.Available(elementStack) && Validator.Available(slot) && StackMatchesSlot(elementStack, slot))) { SoundManager.PlaySfx("CardDragFail"); return; } // Remove glow so that it won't flicker when moved elementStack.ShowGlow(false, true); // Force stack to remember its last position elementStack.lastTablePos = new Vector2?(elementStack.RectTransform.anchoredPosition); if (elementStack.Quantity != 1) { IElementStack newStack = elementStack.SplitAllButNCardsToNewStack(elementStack.Quantity - 1, new Context(Context.ActionSource.PlayerDrag)); slot.AcceptStack(newStack, new Context(Context.ActionSource.PlayerDrag)); } else { slot.AcceptStack(elementStack, new Context(Context.ActionSource.PlayerDrag)); } }
/// <summary> /// Create and add a new recipe in recipe display. /// </summary> public void AddRecipe(string title, string url) { GameObject go = Instantiate(recipeSlotPrefab, recipeGridContainer); RecipeSlot newSlot = go.GetComponent <RecipeSlot>(); newSlot.SetRecipe(title, url); }
static bool Prefix(RecipeSlot __instance) { return(Patcher.Run(() => { // If neither shift is down give back control to the game immediately if (!Input.GetKey(KeyCode.LeftShift) && !Input.GetKey(KeyCode.RightShift)) { return true; } var slot = __instance; var situation = GameBoard.GetOpenSituation(); if (situation == null || slot.GetElementStackInSlot() != null || !SituSlotController.GetAllEmptySlots(situation).Contains(slot)) { return true; } foreach (var stack in Positions.GetStacksRelativeTo(situation)) { if (SituSlotController.StackMatchesSlot(stack, slot)) { SituSlotController.MoveStackIntoSlot(stack as ElementStackToken, slot); break; } } return false; })); }
RecipeSlot ValidRecipeSlotOrNull(RecipeSlot slot) { if (slot.Defunct || slot.IsGreedy || slot.IsBeingAnimated) { return(null); } return(slot); }
public void ItemSlotEnter(PointerEventData pointer, RecipeSlot recipeSlot) { if (canMakeRecipe) { Color color = gameObject.GetComponent <Image>().color; gameObject.GetComponent <Image>().color = new Color(color.r + 0.075f, color.g + 0.075f, color.b + 0.075f, color.a); } MenuManager.SetDescriptor(new RecipeDescriptorUI(recipeSlot.recipe)); }
public static bool Available(RecipeSlot slot) { return(!( slot == null || slot.Equals(null) || slot.Defunct || slot.IsGreedy || slot.IsBeingAnimated || slot.GetElementStackInSlot() != null )); }
public void ItemSlotExit(PointerEventData pointer, RecipeSlot recipeSlot) { if (canMakeRecipe) { Color color = gameObject.GetComponent <Image>().color; gameObject.GetComponent <Image>().color = new Color(color.r - 0.075f, color.g - 0.075f, color.b - 0.075f, color.a); } if (MenuManager.descriptor != null) { MenuManager.descriptor.DestroyUI(); MenuManager.descriptor = null; } }
void PopulateSlot(RecipeSlot slot, ElementStackToken stack) { stack.lastTablePos = new Vector2?(stack.RectTransform.anchoredPosition); if (stack.Quantity != 1) { var newStack = stack.SplitAllButNCardsToNewStack(stack.Quantity - 1, new Context(Context.ActionSource.PlayerDrag)); slot.AcceptStack(newStack, new Context(Context.ActionSource.PlayerDrag)); } else { slot.AcceptStack(stack, new Context(Context.ActionSource.PlayerDrag)); } }
private void LeftClick(RecipeSlot recipeSlot) { if (recipeSlot.Recipe != null) { ingredients.AddIngredients(recipeSlot.Recipe.Ingredients); selectedRecipe.sprite = recipeSlot.Recipe.Food.Sprite; selectedRecipe.color = normalColor; } else { ingredients.AddIngredients(new Item[0]); selectedRecipe.color = disabledColor; } }
public void Show() { Clear(); recipeSlots = new List <RecipeSlot>(); foreach (Item item in recipe) { GameObject obj = Instantiate(ingredientPrefab); RecipeSlot slot = obj.GetComponent <RecipeSlot>(); slot.AddItem(item); obj.transform.SetParent(contentPanel.transform, false); recipeSlots.Add(slot); } UpdateRecipe(); }
bool TryPopulateSlot(RecipeSlot slot, string elementId) { if (slot.Defunct || slot.IsGreedy || slot.IsBeingAnimated) { return(false); } var stack = this.GetStackForElement(elementId); if (stack == null) { return(false); } this.PopulateSlot(slot, stack); return(true); }
bool TrySatisfySlot(RecipeSlot slot, IEnumerable <ElementStackToken> candidates) { if (slot.GetElementStackInSlot() != null) { // Already something in the slot. return(true); } var candidate = candidates.FirstOrDefault(x => slot.GetSlotMatchForStack(x).MatchType == SlotMatchForAspectsType.Okay); if (candidate == null) { return(false); } this.PopulateSlot(slot, candidate); return(true); }
public void CreateRecipeUI(Recipe recipe) { RecipeSlot recipeSlot = Instantiate(RecipeUiSlotModel); Button craftButton = PlayerShooting.getChildGameObject(recipeSlot.gameObject, "CraftingButton").GetComponent <Button>(); craftButton.onClick.AddListener(delegate { PlayerInfo.PlayerInventory.TryRecipe(recipe); }); Debug.LogError("Created for recipe " + recipe); foreach (Item component in recipe.Components) { ComponentSlot componentSlot = Instantiate(ComponentUiSlotModel); componentSlot.transform.SetParent(recipeSlot.ComponentsContainer, false); Image icon = PlayerShooting.getChildGameObject(componentSlot.gameObject, "Icon").GetComponent <Image>(); icon.sprite = component.icon; Text text = componentSlot.GetComponentInChildren <Text>(); int componentIndex = recipe.Components.IndexOf(component); int possessed = PlayerInfo.PlayerInventory.GetItemPossessedAmount(component); int needed = recipe.ComponentsAmounts[componentIndex]; text.text = possessed + "/" + needed; if (possessed >= needed) { text.color = Color.green; } else { text.color = Color.red; } } if (recipe.targetItem != null) { Debug.LogError("Recipe target item: " + recipe.targetItem.name); Image resultIcon = recipeSlot.Result.GetComponentInChildren <Image>(); resultIcon.sprite = recipe.targetItem.icon; } recipeSlot.transform.SetParent(recipesContainer, false); }
public RecipeUI(Recipe recipe, bool canMakeRecipe) { this.canMakeRecipe = canMakeRecipe; if (slotPrefab == null) { slotPrefab = Resources.Load("Prefabs/Recipe") as GameObject; } gameObject = GameObject.Instantiate(slotPrefab, Vector3.zero, Quaternion.identity); if (!canMakeRecipe) { Color color = gameObject.GetComponent <Image>().color; gameObject.GetComponent <Image>().color = new Color(1, color.g - 0.1f, color.b - 0.1f, color.a); } gameObject.transform.GetChild(0).GetComponent <Image>().sprite = recipe.result.GetItem().itemData.ItemSprite; gameObject.transform.GetChild(1).GetComponent <Text>().text = "x " + recipe.result.GetAmount().ToString(); RecipeSlot recipeSlot = gameObject.GetComponent <RecipeSlot>(); recipeSlot.recipe = recipe; recipeSlot.recipeUI = this; recipeSlot.OnClick = ItemSlotClick; recipeSlot.OnEnter = ItemSlotEnter; recipeSlot.OnExit = ItemSlotExit; OnSlotClick = new RecipeSlotEvent(); }
public void ItemSlotClick(PointerEventData pointer, RecipeSlot recipeSlot) { OnSlotClick.Invoke(pointer, recipeSlot); }
public static bool PopulateSlotWithNearbyStacks(SituationController situation, RecipeSlot slotToFill) { // Trying to fill all the slots var candidateStacks = Positions.GetAdjacentStacks(situation, Mod.AutomationDistance); foreach (var stack in candidateStacks) { if (SituSlotController.StackMatchesSlot(stack, slotToFill)) { var tokenAndSlot = new TokenAndSlot { RecipeSlot = slotToFill, Token = situation.situationToken as SituationToken }; SituSlotController.FillSlotEventually(tokenAndSlot, stack as ElementStackToken); return(true); // Successfully found a token for this slot } } return(false); // Failed to find a token for this slot }
public static bool StackMatchesSlot(IElementStack elementStack, RecipeSlot slot) { return(slot.GetSlotMatchForStack(elementStack).MatchType == SlotMatchForAspectsType.Okay); }