48 lines
1.3 KiB
C#
48 lines
1.3 KiB
C#
|
|
using System.Collections;
|
||
|
|
using System.Collections.Generic;
|
||
|
|
using Michsky.MUIP;
|
||
|
|
using UnityEngine;
|
||
|
|
|
||
|
|
namespace Ichni.UI
|
||
|
|
{
|
||
|
|
public class Dropdown : SettingsUIElementBase
|
||
|
|
{
|
||
|
|
public List<string> options;
|
||
|
|
public CustomDropdown dropdown;
|
||
|
|
public int selectedIndex;
|
||
|
|
public string selectedOption;
|
||
|
|
|
||
|
|
public void SetUp(int initialValue, List<string> options, string title = "")
|
||
|
|
{
|
||
|
|
base.SetUp(title);
|
||
|
|
|
||
|
|
this.options = options;
|
||
|
|
this.dropdown.items = new List<CustomDropdown.Item>();
|
||
|
|
foreach (string option in options)
|
||
|
|
{
|
||
|
|
dropdown.items.Add(new CustomDropdown.Item { itemName = option });
|
||
|
|
}
|
||
|
|
|
||
|
|
dropdown.onValueChanged.AddListener(value =>
|
||
|
|
{
|
||
|
|
SetValue(value);
|
||
|
|
updateValueAction?.Invoke();
|
||
|
|
});
|
||
|
|
|
||
|
|
SetValue(initialValue);
|
||
|
|
}
|
||
|
|
|
||
|
|
public int GetOptionIndex(string option)
|
||
|
|
{
|
||
|
|
return options.IndexOf(option);
|
||
|
|
}
|
||
|
|
|
||
|
|
public void SetValue(int index)
|
||
|
|
{
|
||
|
|
selectedIndex = index;
|
||
|
|
selectedOption = options[selectedIndex];
|
||
|
|
dropdown.selectedItemIndex = selectedIndex;
|
||
|
|
dropdown.UpdateItemLayout();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|