Farming Patches

OK, so then we get a little more compicated.

  1. Create a new interface
public interface IFarmingPatch : ICraftingTable
{
}
  1. Go to your farming ‘crafting table’ and replace ICraftingTable with this new interface.
  2. Go to the CraftingSystem and update the code we just added
private void OnCraftingInteraction(ICraftingTable craftingTable)
{
    // somewhere between the other code that makes sense
    quantityHolder.ActivateQuantityUI(craftingTable is IFarmingPatch);
}

I can’t remember if this would work because it’s up-casting. Lemme check and get back to you

We are now ‘tagging’ the specific crafting table as a farming patch, and checking if it is one before activating quantity. In an ideal scenario, you’d call it something like IControlQuantity so that it can go on anything that wants to use the quantity controller

I’ll wait for this before doing anything :smiley:

It’s good. You can go. I was thinking of something else

With this, you can also remove the HoldsCraftedItems from ICraftingTable again, and just do this same check instead, since it’s only the farming patches that won’t hold the items.

This interface also extends the crafting table so anything farming patch related that the crafting system should know about can go in here

is that done through code, or…?! I’m confused by this step

no, you can’t replace interfaces with code (you can, but angels fear to tread). Go to the farming crafting table script and change it from ICraftingTable to IFarmingPatch

like this? Won’t that make this the case for literally every other script holder that’s not a farming table?

and since we’re at the topic of “I don’t fully understand what’s going on”, I didn’t fully grasp these two points either :sweat_smile: (I’m sorry for taking up so much time)

No, that makes all the crafting tables farming patches. Don’t you have a farming patch crafting table?

  1. Create a game object
  2. Put the QuantityHolder script on it
  3. Put the Crafting Quantity object inside it

So I just copy-paste the ‘CraftingTable’ code into a duplicate of the script that I just renamed to ‘FarmingTable’?

Yes I do have a farming patch crafting table, but I don’t know how to classify them apart outside of code. I’m slightly confused now :sweat_smile:

*Sigh* So we can’t do any of this then.

  1. Open ICraftingTable and add
bool UseQuantity { get; }
  1. Open the CraftingTable and add
[field: SerializeField] public bool UseQuantity { get; private set; }
  1. Go to CraftingSystem and
private void OnCraftingInteraction(ICraftingTable craftingTable)
{
    // somewhere between the other code that makes sense
    quantityHolder.ActivateQuantityUI(craftingTable.UseQuantity);
}
  1. Go to your farming patch in the inspector and check the Use Quantity box

Well that was quite the world tour, but I’m happy it’s clean, so thank you :smiley:

(by the time I get this quantity to work based on how many plant growth handlers are available for use, I’ll probably be 52 lol. I’m just joking btw)

Jokes aside:

  1. Can I delete ‘IFarmingPatch’ now? Interfaces can be really confusing to me at times
  2. Why didn’t we just use the ‘HoldCraftedItems’ to toggle it, since they both are purely for farming in ‘ICraftingTable.cs’? (Now that I think of it a little, I think for future-proofing, this is much better with a slight rename to “ShowQuantityUI”)

Yes, we can’t do anything with it

You could, but it’s technically not the same thing. HoldCraftedItems doesn’t tell me that it controls the display of the quantity stuff

Alright that was amazing. Again, I apologize for taking up so much of your time for something relatively small, but it was essential :slight_smile: - I’ll go catch a short break and then see what can be done about making this whole Quantity thing functional. It will rely solely on maxing out the number of the quantity to how many Plant Growth Handler Patches are available for use (I’ll see what can be done about it solo first)

Tbh it should not have taken this long but I got stuck in a ‘let’s find the PlantGrowthHolders’ rut and then went off on a tangent that should’ve just been this from the start

(Honestly, at the start, I was lowkey wishing I just lived with the bug lol… For now I’m just glad I got this thing working relatively bug-free)

But trust me, I wouldn’t have figured this one on my own. Anything with interfaces is dead complicated to me

Alright so @bixarrio @Brian_Trotter if anyone wants to hop on board, please be my guest :slight_smile: - I’m giving my idea a try, and will probably update you as I go

So, I wanted to develop a Quantity counter very specifically for the Farming system, and there’s a reason for this: I want each patch to have an ‘x’ number of slots on it, and each slot will have the ‘PlantGrowthHandler.cs’ script on it. The idea is simple, each plant will consume 1 slot, and each time we want to hit that ‘Farm’ key, we want to consume one of the empty slots, and the ‘maxQuantity’ on the quantity counting algorithm (CraftingQuantity.cs) should be limited to the available slots. Needless to say, the ‘Farm’ button must be disabled if we don’t have enough slots for usage.

For future-proofing purposes, it might be a good idea to give the developer an option of how many slots he wants that plant to consume

Once the product on that slot has become a pickup, i.e: it has reached its final state, that slot will then be available for re-use, and the player can pickup his fruit, vegetable or whatever that thing is from there

And the idea is simple, the timer, the demands for the item and what not will multiply, along with the final product as well. Each item involved in farming will have its own slot

Anyway, that’s just a little update of what I want to do. If you got better ideas for a better approach, please let me know, but I figured that this would be a great, yet simple, idea to implement

Maybe (not sure yet) I might allow for all craftable items to be quantity-driven, but for now let’s get the farming out of the way first :slight_smile: (sorry if I sound insane)

Why are you updating the timer? If the farming patch has 4 slots it should take the same amount of time to grow 1 item as it will take to grow 3 or 4 items

I wasn’t thinking straight there, my bad :sweat_smile:

Anyway, where do I start with this?

OK so there’s a bit of a weird bug that we probably introduced somewhere (it didn’t exist before this thread), but why is it that when I hit the - button to reduce the quantity, it gets reduced in 3 numbers at a time, whereas the + button increases 1 at a time? Anything suspicious here? (Some of them lose 2, some lose 3, some lose 4… the value is all over the place):

using RPG.Crafting;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

public class CraftingQuantity : MonoBehaviour
{
    public int maxQuantity = 100;
    public int minQuantity = 1;
    private int currentQuantity;

    public TextMeshProUGUI quantityText;
    public Button plusButton;
    public Button minusButton;

    private Image plusButtonImage;
    private Image minusButtonImage;

    void OnEnable() 
    {
        // Happens for a millisecond when the game scene starts, and then disabled 
        // by 'OnDisable', unless commanded by the 'Crafting UI' to open up
        Debug.Log($"Quantity Controller has been enabled");
        // Initialize the Quantity to the minimum value
        currentQuantity = minQuantity;
        UpdateQuantityText();

        // Add listeners to the buttons
        plusButton.onClick.AddListener(AddQuantity);
        minusButton.onClick.AddListener(SubtractQuantity);

        // Buttons' Image Components
        plusButtonImage = plusButton.GetComponent<Image>();
        minusButtonImage = minusButton.GetComponent<Image>();

        // Update button transparency
        UpdateButtonState();
    }

    void OnDisable() 
    {
        // Quickly disables 'OnEnable' when the game scene starts, 
        // and also called when 'Crafting UI' Quit Button commands a shut down
        Debug.Log($"Quantity Controller has been disabled");
        plusButton.onClick.RemoveListener(AddQuantity);
        plusButton.onClick.RemoveListener(SubtractQuantity);
    }

    void AddQuantity() 
    {
        if (currentQuantity < maxQuantity) 
        {
            currentQuantity++;
            UpdateQuantityText();
            UpdateButtonState();
        }
    }

    void SubtractQuantity() 
    {
        if (currentQuantity > minQuantity) 
        {
            currentQuantity--;
            UpdateQuantityText();
            UpdateButtonState();
        }
    }

    void UpdateQuantityText() 
    {
        quantityText.text = currentQuantity.ToString();
    }

    void UpdateButtonState() 
    {
        // Update the Plus Button state
        if (currentQuantity >= maxQuantity) 
        {
            plusButton.interactable = false;
            Color plusColor = plusButtonImage.color;
            plusColor.a = 0.5f;
            plusButtonImage.color = plusColor;
        }
        else 
        {
            plusButton.interactable = true;
            var plusColor = plusButtonImage.color;
            plusColor.a = 1f;
            plusButtonImage.color = plusColor;
        }

        // Update the Minus Button state
        if (currentQuantity <= minQuantity) 
        {
            minusButton.interactable = false;
            var minusColor = minusButtonImage.color;
            minusColor.a = 0.5f;
            minusButtonImage.color = minusColor;
        }
        else 
        {
            minusButton.interactable = true;
            var minusColor = minusButtonImage.color;
            minusColor.a = 1f;
            minusButtonImage.color = minusColor;
        }
    }
}

(And I’m not so sure on how to start making this quantity counter effective yet :sweat_smile:)

Perhaps because you are binding to the listener in the code. Just bind in the inspector. There’s no need to bind/unbind repeatedly

That’s… exactly what went wrong I believe :sweat_smile: - thank you @bixarrio

I’m still investigating (and kinda lost a little bit, considering I have to be careful on what to add, since I wasn’t keeping track of the script dependencies) of who to add, and where, but I want to make these buttons effective to the game from ‘CraftingSystem.cs’ itself. If you’re available and would like to add in, please do :slight_smile:

So far I added a boolean in ‘PlantGrowthHandler’ called ‘isOccupied’, and a gameObject called ‘currentPlant’. They will both get filled up when a plant takes this spot, as a way of saying “This spot isn’t available”, then I started messing things up… (I’m still trying anyway)

Privacy & Terms