You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
76 lines
3.2 KiB
76 lines
3.2 KiB
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
/// <summary>
|
|
/// 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.
|
|
/// </summary>
|
|
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<Item> items; // List of items we know we can select. The view may only show some items, so this is important
|
|
|
|
public List<Item> 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<Item>();
|
|
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<Item> AvailableItems { get; set; }
|
|
}
|
|
|