Dropdown Fixes + TryGetMinigame (#781)
* fix dropdowns + dropdown collapses man... * trygetminigame it's from a different branch but it's nice to have rn
This commit is contained in:
parent
5675e5daf4
commit
bc93a7ab94
File diff suppressed because it is too large
Load diff
|
@ -1243,6 +1243,17 @@ namespace HeavenStudio
|
||||||
return eventCaller.GetMinigame(name);
|
return eventCaller.GetMinigame(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool TryGetMinigame<T>(out T mg) where T : Minigame
|
||||||
|
{
|
||||||
|
if (minigame is T tempMinigame) {
|
||||||
|
mg = tempMinigame;
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
mg = null;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Color colMain;
|
Color colMain;
|
||||||
public void SetCurrentGame(string game, bool useMinigameColor = true)
|
public void SetCurrentGame(string game, bool useMinigameColor = true)
|
||||||
{
|
{
|
||||||
|
|
|
@ -19,6 +19,7 @@ namespace HeavenStudio.Editor
|
||||||
public LeftClickTMP_Dropdown dropdown;
|
public LeftClickTMP_Dropdown dropdown;
|
||||||
public Scrollbar scrollbar;
|
public Scrollbar scrollbar;
|
||||||
|
|
||||||
|
public int[] values;
|
||||||
private int _defaultValue;
|
private int _defaultValue;
|
||||||
|
|
||||||
private bool openedDropdown = false;
|
private bool openedDropdown = false;
|
||||||
|
@ -35,6 +36,14 @@ namespace HeavenStudio.Editor
|
||||||
// entity[propertyName].ChangeValues(dropdownEntity.Values);
|
// entity[propertyName].ChangeValues(dropdownEntity.Values);
|
||||||
_defaultValue = dropdownEntity.defaultValue;
|
_defaultValue = dropdownEntity.defaultValue;
|
||||||
EntityTypes.DropdownObj dropdownObj = entity[propertyName];
|
EntityTypes.DropdownObj dropdownObj = entity[propertyName];
|
||||||
|
|
||||||
|
int size = dropdownObj.Values.Count;
|
||||||
|
values = new int[size];
|
||||||
|
|
||||||
|
for (int i = 0; i < size; i++) {
|
||||||
|
values[i] = i;
|
||||||
|
}
|
||||||
|
|
||||||
selected = dropdownObj.value;
|
selected = dropdownObj.value;
|
||||||
dropdown.AddOptions(dropdownObj.Values);
|
dropdown.AddOptions(dropdownObj.Values);
|
||||||
dropdown.onValueChanged.AddListener(newVal => dropdownObj.value = newVal);
|
dropdown.onValueChanged.AddListener(newVal => dropdownObj.value = newVal);
|
||||||
|
@ -50,11 +59,11 @@ namespace HeavenStudio.Editor
|
||||||
case Enum enumEntity:
|
case Enum enumEntity:
|
||||||
Type enumType = enumEntity.GetType();
|
Type enumType = enumEntity.GetType();
|
||||||
_defaultValue = (int)type;
|
_defaultValue = (int)type;
|
||||||
int[] keys = Enum.GetValues(enumType).Cast<int>().ToArray();
|
values = Enum.GetValues(enumType).Cast<int>().ToArray();
|
||||||
selected = Array.FindIndex(keys, val => val == (int)entity[propertyName]);
|
selected = Array.FindIndex(values, val => val == (int)entity[propertyName]);
|
||||||
|
|
||||||
dropdown.AddOptions(Enum.GetNames(enumType).ToList());
|
dropdown.AddOptions(Enum.GetNames(enumType).ToList());
|
||||||
dropdown.onValueChanged.AddListener(val => entity[propertyName] = keys[val]);
|
dropdown.onValueChanged.AddListener(val => entity[propertyName] = values[val]);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -74,8 +83,8 @@ namespace HeavenStudio.Editor
|
||||||
|
|
||||||
public override void SetCollapses(object type)
|
public override void SetCollapses(object type)
|
||||||
{
|
{
|
||||||
dropdown.onValueChanged.AddListener(_ => UpdateCollapse(type));
|
dropdown.onValueChanged.AddListener(_ => UpdateCollapse(values[dropdown.value]));
|
||||||
UpdateCollapse(type);
|
UpdateCollapse(values[dropdown.value]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Update()
|
private void Update()
|
||||||
|
|
Loading…
Reference in a new issue