Skip to content

Commit

Permalink
perf: refine PrefsGUIEditorWindowRosettaUI
Browse files Browse the repository at this point in the history
  • Loading branch information
fuqunaga committed Sep 11, 2024
1 parent 03e4280 commit 7e6bb83
Showing 1 changed file with 78 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ private enum Order
[UnityEditor.MenuItem("Window/PrefsGUI")]
public static void ShowWindow() => GetWindow<PrefsGUIEditorWindowRosettaUI>("PrefsGUI");

public static Color NonDefaultPrefsBackgroundColor = new(0.5f, 0.2f, 0.2f, 0.8f);
public static Color nonDefaultPrefsBackgroundColor = new(0.5f, 0.2f, 0.2f, 0.8f);

private static string searchWord = "";
private static Order order;
Expand Down Expand Up @@ -68,7 +68,7 @@ protected override Element CreateElement()
new FieldOption() { delayInput = true }
).SetMinWidth(300f),
PrefsGUIEditorRosettaUIComponent.SpaceRowGap(),
UI.Field(UI.Label("Order").SetWidth(40f), () => order).SetWidth(130f),
UI.Field(UI.Label("Order").SetWidth(40f), () => order).SetWidth(154f),
// UI.Field("Include assets", () => includeAssets),
PrefsGUIEditorRosettaUIComponent.SpaceRowGap(),
UI.DynamicElementIf(
Expand Down Expand Up @@ -96,35 +96,7 @@ protected override Element CreateElement()
).SetFlexShrink(1f)
).SetFlexShrink(1f);

Element CreatePrefsUIAtoZ(string word)
{
var prefsObjAll = PrefsAssetUtility.GetPrefsObjEnumerable(includeAssets)
.Where(po => IsContainWord(po.prefs.key, word))
.OrderBy(po => po.prefs.key)
.ToList();

return UI.List(null,
() => prefsObjAll,
(binder, index) =>
{
var (prefs, obj) = ((IBinder<(PrefsParam, Object)>)binder).Get();

var prefsElement = new[]
{
PrefsGUIEditorRosettaUIComponent.CreateObjectField(obj),
prefs.CreateElement().Close()
};

return _objCheckExtension != null
? UI.Row(
_objCheckExtension.PrefsLeft(prefs),
UI.Indent(UI.Row(prefsElement))
)
: UI.Indent(UI.Row(prefsElement));
},
new ListViewOption(false, true, false)
);
}

}

private static bool IsContainWord(string word, string searchWordLower) => word.ToLower().Contains(searchWordLower);
Expand All @@ -149,6 +121,8 @@ private static Element CreateTopBar()
})
}
),
UI.Space().SetWidth(20f),
UI.FieldReadOnly("Total Prefs Key Count", () => PrefsParam.allDic.Count),
UI.Space(),
UI.Button("Open Set Current To Default Window",
() =>
Expand All @@ -166,6 +140,45 @@ private static Element CreateTopBar()
}


private static Element CreatePrefsUIAtoZ(string word)
{
var prefsObjAll = PrefsAssetUtility.GetPrefsObjEnumerable(includeAssets)
.Where(po => IsContainWord(po.prefs.key, word))
.OrderBy(po => po.prefs.key)
.ToList();

return UI.List(null,
() => prefsObjAll,
(binder, index) =>
{
var (prefs, obj) = ((IBinder<(PrefsParam, Object)>)binder).Get();

var prefsElement = new[]
{
UI.Indent(
prefs.CreateElement().Close()
),
PrefsGUIEditorRosettaUIComponent.CreateObjectField(obj)
};

return _objCheckExtension != null
? UI.Row(
_objCheckExtension.PrefsLeft(prefs),
UI.Row(prefsElement)
)
: UI.Row(prefsElement);
},
new ListViewOption(false, true, false)
{
reorderable = false,
fixedSize = true,
header = false,
suppressAutoIndent = true
}
);
}


private static Element CreatePrefsGameObject(string word)
{
var objPrefsList = PrefsAssetUtility.GetObjPrefsList(includeAssets)
Expand All @@ -188,7 +201,13 @@ private static Element CreatePrefsGameObject(string word)
var typedBinder = (IBinder<PrefsAssetUtility.ObjPrefs>)binder;
return CreateObjPrefsElement(typedBinder.Get());
},
new ListViewOption(false, true, false)
new ListViewOption()
{
reorderable = false,
fixedSize = true,
header = false,
suppressAutoIndent = _objCheckExtension != null
}
);

Element CreateObjPrefsElement(PrefsAssetUtility.ObjPrefs objPrefs)
Expand All @@ -210,13 +229,14 @@ Element CreateObjPrefsElement(PrefsAssetUtility.ObjPrefs objPrefs)
: FilterPrefs(objPrefs.PrefsAll)
).ToList();


// Show component: off
if (!showComponent)
return UI.Column(
CreateObjFieldAndPrefsListElement(objPrefs.obj, prefsListForObj, 2)
);

{
return CreateObjFieldAndPrefsListElement(objPrefs.obj, prefsListForObj);
}

// Show component style
// Show component: on
return UI.Column(
UI.Row(
_objCheckExtension?.PrefsSetLeft(prefsListForObj),
Expand All @@ -234,7 +254,8 @@ Element CreateObjPrefsElement(PrefsAssetUtility.ObjPrefs objPrefs)
).ToList();

return CreateObjFieldAndPrefsListElement(holder.component, prefsList);
})
}),
2
)
);
}
Expand All @@ -244,17 +265,25 @@ IEnumerable<PrefsParam> FilterPrefs(IEnumerable<PrefsParam> prefsSet) =>

Element CreateObjFieldAndPrefsListElement(Object obj, IReadOnlyCollection<PrefsParam> prefsList, int indentLevel = 1)
{
return UI.Fold(
CreateObjectFieldAndEditKeyPrefix(obj, prefsList),
new[]
{
UI.Indent(
prefsList.Select(CreatePrefsElement),
indentLevel
)
}
if (_objCheckExtension == null)
{
return UI.Fold(
CreateObjectFieldAndEditKeyPrefix(obj, prefsList),
prefsList.Select(CreatePrefsElement)
);
}

return UI.Row(
UI.Column(
_objCheckExtension?.PrefsSetLeft(prefsList),
UI.Space()
).SetFlexGrow(0),
// UI.Fold()で自動的に付くIndentを避けるため new FoldElement() する
new FoldElement(
CreateObjectFieldAndEditKeyPrefix(obj, prefsList),
prefsList.Select(CreatePrefsElement)
)
);


Element CreatePrefsElement(PrefsParam prefs)
{
Expand All @@ -274,7 +303,6 @@ Element CreatePrefsElement(PrefsParam prefs)
Element CreateObjectFieldAndEditKeyPrefix(Object obj, IReadOnlyCollection<PrefsParam> prefsList)
{
return UI.Row(
_objCheckExtension?.PrefsSetLeft(prefsList),
PrefsGUIEditorRosettaUIComponent.CreateObjectField(obj),
PrefsGUIEditorRosettaUIComponent.SpaceRowGap(),
UI.Field(
Expand All @@ -288,7 +316,7 @@ Element CreateObjectFieldAndEditKeyPrefix(Object obj, IReadOnlyCollection<PrefsP
).RegisterUpdateCallback(row =>
{
var hasNonDefaultValue = prefsList.Any(p => !p.IsDefault);
row.SetBackgroundColor(hasNonDefaultValue ? NonDefaultPrefsBackgroundColor : null);
row.SetBackgroundColor(hasNonDefaultValue ? nonDefaultPrefsBackgroundColor : null);
});
}
}
Expand Down

0 comments on commit 7e6bb83

Please sign in to comment.