update
This commit is contained in:
48
Assets/Scripts/UI/Base/Dropdown.cs
Normal file
48
Assets/Scripts/UI/Base/Dropdown.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/UI/Base/Dropdown.cs.meta
Normal file
11
Assets/Scripts/UI/Base/Dropdown.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 63ac87ec6c134804c9cd877b8820d283
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,10 +1,4 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using I2.Loc;
|
||||
using Michsky.MUIP;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
namespace Ichni.UI
|
||||
{
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using I2.Loc;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
@@ -8,10 +10,12 @@ namespace Ichni.UI
|
||||
public class TextButton : SettingsUIElementBase
|
||||
{
|
||||
public Button button;
|
||||
|
||||
public void SetUp(string title = "")
|
||||
public TMP_Text buttonText;
|
||||
public void SetUp(string title, string subTitle, string textContent)
|
||||
{
|
||||
base.SetUp(title);
|
||||
base.SetUp(title, subTitle);
|
||||
|
||||
buttonText.GetComponent<Localize>().SetTerm(textContent);
|
||||
|
||||
button.onClick.AddListener(() =>
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user