Example #1
0
    public void populate(EntityAction acter, EntityAction target)
    {
        gameObject.SetActive(true);
        mCancelled = false;
        mInUse     = true;
        //add options to the acter drop down
        //List<string> act_opts = new List<string> { "Item1", "Item2", "Item3", "Item4" };
        //mItemDropdown.AddOptions(act_opts);
        //make  lsit of potential options
        Dictionary <GameTypes.ItemType, int> act_items = acter.getInventoryDictionary();
        Dictionary <GameTypes.ItemType, int> tar_items = target.getInventoryDictionary();
        Dictionary <GameTypes.ItemType, KeyValuePair <int, int> > opts_dict = new Dictionary <GameTypes.ItemType, KeyValuePair <int, int> >();
        KeyValuePair <int, int> temp_kp = new KeyValuePair <int, int>();

        foreach (KeyValuePair <GameTypes.ItemType, int> it in act_items)
        {
            if (!opts_dict.ContainsKey(it.Key))
            {
                //the opt dict doesnt already contain this key
                //get the max value which is how much the acter can give
                temp_kp = new KeyValuePair <int, int>(0, it.Value);
                opts_dict.Add(it.Key, temp_kp);
            }
            else
            {
                Debug.LogError("Opts Dict already contains the ItemType key. This shoudln't be possible if the inventory only has one of each item as it should.");
            }
        }
        //now fill the min value with the target items
        foreach (KeyValuePair <GameTypes.ItemType, int> it in tar_items)
        {
            if (opts_dict.ContainsKey(it.Key))
            {
                //the acter also has this item type
                opts_dict[it.Key] = new KeyValuePair <int, int>(-1 * it.Value, opts_dict[it.Key].Value);
            }
            else
            {
                //the acter didnt contain this item and we need to make a ew entry
                temp_kp = new KeyValuePair <int, int>(-1 * it.Value, 0);
                opts_dict.Add(it.Key, temp_kp);
            }
        }
        //now make a string for each entry
        List <string> opt_strings = new List <string>();

        GameTypes.ItemType first_opt = GameTypes.ItemType.Unknown;
        int i = 0;

        foreach (GameTypes.ItemType type in opts_dict.Keys)
        {
            opt_strings.Add(string.Format("{0}({1}:{2})", type.ToString(), opts_dict[type].Key, opts_dict[type].Value));
            if (i == 0)
            {
                first_opt = type;
            }
            i++;
        }
        mOptDict    = opts_dict;
        mOptStrings = opt_strings;
        mItemDropdown.AddOptions(opt_strings);

        //set the first option as the chosen option
        if (first_opt != GameTypes.ItemType.Unknown)
        {
            mChoiceType  = first_opt;
            mChoiceMin   = mOptDict[first_opt].Key;
            mChoiceMax   = mOptDict[first_opt].Value;
            mChoiceValue = mChoiceMax;
        }

        //bring to front of the sidebar
        transform.SetAsLastSibling();
        mPopulated = true;
    }