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:
AstrlJelly 2024-03-11 16:18:40 -04:00 committed by GitHub
parent 5675e5daf4
commit bc93a7ab94
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 62 additions and 5810 deletions

File diff suppressed because it is too large Load diff

View file

@ -1243,6 +1243,17 @@ namespace HeavenStudio
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;
public void SetCurrentGame(string game, bool useMinigameColor = true)
{

View file

@ -19,6 +19,7 @@ namespace HeavenStudio.Editor
public LeftClickTMP_Dropdown dropdown;
public Scrollbar scrollbar;
public int[] values;
private int _defaultValue;
private bool openedDropdown = false;
@ -35,6 +36,14 @@ namespace HeavenStudio.Editor
// entity[propertyName].ChangeValues(dropdownEntity.Values);
_defaultValue = dropdownEntity.defaultValue;
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;
dropdown.AddOptions(dropdownObj.Values);
dropdown.onValueChanged.AddListener(newVal => dropdownObj.value = newVal);
@ -50,11 +59,11 @@ namespace HeavenStudio.Editor
case Enum enumEntity:
Type enumType = enumEntity.GetType();
_defaultValue = (int)type;
int[] keys = Enum.GetValues(enumType).Cast<int>().ToArray();
selected = Array.FindIndex(keys, val => val == (int)entity[propertyName]);
values = Enum.GetValues(enumType).Cast<int>().ToArray();
selected = Array.FindIndex(values, val => val == (int)entity[propertyName]);
dropdown.AddOptions(Enum.GetNames(enumType).ToList());
dropdown.onValueChanged.AddListener(val => entity[propertyName] = keys[val]);
dropdown.onValueChanged.AddListener(val => entity[propertyName] = values[val]);
break;
default:
break;
@ -74,8 +83,8 @@ namespace HeavenStudio.Editor
public override void SetCollapses(object type)
{
dropdown.onValueChanged.AddListener(_ => UpdateCollapse(type));
UpdateCollapse(type);
dropdown.onValueChanged.AddListener(_ => UpdateCollapse(values[dropdown.value]));
UpdateCollapse(values[dropdown.value]);
}
private void Update()