using UnityEngine;
using System.Collections.Generic;
using System.Collections;
using System;
namespace UIWidgets {
///
/// Dialog actions.
/// Key - button name.
/// Value - action on click.
///
public class DialogActions : IDictionary> {
List keys = new List();
List> values = new List>();
List>> elements = new List>>();
///
/// Gets the number of elements contained in the dictionary.
///
/// The count.
public int Count {
get {
return elements.Count;
}
}
///
/// Gets a value indicating whether this instance is read only.
///
/// true if this instance is read only; otherwise, false.
public bool IsReadOnly {
get {
return false;
}
}
///
/// Gets or sets the element with the specified key.
///
/// The element with the specified key.
/// The key of the element to get or set.
public Func this[string key] {
get {
var index = keys.IndexOf(key);
return elements[index].Value;
}
set {
var index = keys.IndexOf(key);
elements[index] = new KeyValuePair>(key, value);
}
}
///
/// Gets an ICollection containing the keys of the dictionary.
///
/// The keys.
public ICollection Keys {
get {
return elements.Convert>,string>(GetKey);
}
}
string GetKey(KeyValuePair> item)
{
return item.Key;
}
///
/// Gets an ICollection> containing the values in the dictionary.
///
/// The values.
public ICollection> Values {
get {
return elements.Convert>,Func>(GetValue);
}
}
Func GetValue(KeyValuePair> item)
{
return item.Value;
}
///
/// Add the specified item.
///
/// Item.
public void Add(KeyValuePair> item)
{
Add(item.Key, item.Value);
}
///
/// Add the specified key and value.
///
/// Key.
/// Value.
public void Add(string key, Func value)
{
if (key==null)
{
throw new ArgumentNullException("key", "Key is null.");
}
if (ContainsKey(key))
{
throw new ArgumentException(string.Format("An element with the same key ({0}) already exists.", key));
}
keys.Add(key);
values.Add(value);
elements.Add(new KeyValuePair>(key, value));
}
///
/// Removes all items.
///
public void Clear()
{
keys.Clear();
values.Clear();
elements.Clear();
}
///
/// Determines whether contains a specific value.
///
/// Item.
public bool Contains(KeyValuePair> item)
{
return elements.Contains(item);
}
///
/// Determines whether the IDictionary contains an element with the specified key.
///
/// Key.
/// true, if key was containsed, false otherwise.
public bool ContainsKey(string key)
{
if (key==null)
{
throw new ArgumentNullException("key", "Key is null.");
}
return keys.Contains(key);
}
///
/// Copies the elements of the KeyValuePair> to an Array, starting at a particular Array index.
///
/// Array.
/// Array index.
public void CopyTo(KeyValuePair>[] array, int arrayIndex)
{
elements.CopyTo(array, arrayIndex);
}
///
/// Returns an enumerator that iterates through the collection.
///
public IEnumerator>> GetEnumerator()
{
return elements.GetEnumerator();
}
///
/// Returns an enumerator that iterates through the collection.
///
IEnumerator IEnumerable.GetEnumerator()
{
return elements.GetEnumerator();
}
///
/// Removes the first occurrence of a specific object from the dictionary.
///
/// Item.
public bool Remove(KeyValuePair> item)
{
if (!elements.Contains(item))
{
return false;
}
var index = elements.IndexOf(item);
keys.RemoveAt(index);
values.RemoveAt(index);
elements.RemoveAt(index);
return true;
}
///
/// Removes the element with the specified key from the dictionary.
///
/// Key.
public bool Remove(string key)
{
if (key==null)
{
throw new ArgumentNullException("key", "Key is null.");
}
if (!ContainsKey(key))
{
return false;
}
var index = keys.IndexOf(key);
keys.RemoveAt(index);
values.RemoveAt(index);
elements.RemoveAt(index);
return true;
}
///
/// Gets the value associated with the specified key.
///
/// true, if get value was tryed, false otherwise.
/// Key.
/// Value.
public bool TryGetValue(string key, out Func value)
{
if (key==null)
{
throw new ArgumentNullException("key", "Key is null.");
}
if (!ContainsKey(key))
{
value = default(Func);
return false;
}
value = values[keys.IndexOf(key)];
return true;
}
}
}