using System.Collections; using System.Collections.Generic; using UnityEngine; /// /// This class defines the methods to be called by views to control a ShopModel. You can make concrete /// controllers like a mouse controller, keyboard controller, gamepad controller, etc from this interface. /// public abstract class ShopController : MonoBehaviour { public ShopModel Model => model;//Public getter for the model protected ShopModel model; //Ties this controller to a ShopModel protected List items; // List of items we know we can select. The view may only show some items, so this is important public List Items { get => items; set => items = value; } public abstract void HandleInput(); //Concrete controllers override this method and handle input in different ways. //------------------------------------------------------------------------------------------------------------------------ // Initialize() //------------------------------------------------------------------------------------------------------------------------ //Used as the equivalence of a constructor since we can't use new to create a MonoBehaviour, marked as virtual so that //concrete controllers can add their own Initialize methods public virtual ShopController Initialize(ShopModel pModel) { model = pModel; items = new List(); return this; } //------------------------------------------------------------------------------------------------------------------------ // SelectItem() //------------------------------------------------------------------------------------------------------------------------ //Called when a certain item is selected public void SelectItem(Item item) { model.SelectItem(item); } //------------------------------------------------------------------------------------------------------------------------ // SelectItemByIndex() //------------------------------------------------------------------------------------------------------------------------ //Select an item by its index public void SelectItemByIndex(int index) { model.SelectItemByIndex(index); } //------------------------------------------------------------------------------------------------------------------------ // ConfirmSelectedItem() //------------------------------------------------------------------------------------------------------------------------ //Tells the model to confirm the current selected item public void ConfirmSelectedItem() { model.ConfirmSelectedItem(); } public void AddSelectableItem(Item selectable) { items.Add(selectable); } public void RemoveSelectableItem(Item selectable) { items.Remove(selectable); } // Sometimes there's a chance the controller needs to know which items are even selectable in the view //public virtual List AvailableItems { get; set; } }