Skip to content

Commit

Permalink
refactor(ui): make UI element-aware, respond to attach detach
Browse files Browse the repository at this point in the history
  • Loading branch information
poi-vrc committed Jan 1, 2025
1 parent fdbfc44 commit a95cdde
Show file tree
Hide file tree
Showing 29 changed files with 328 additions and 589 deletions.
1 change: 0 additions & 1 deletion .github/workflows/unity-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ on:
push:
branches:
- master
- upgrade-u22-cs8
paths:
- "**/*.cs"
- ".github/unity-project/**/*"
Expand Down
4 changes: 1 addition & 3 deletions Editor/Configurator/Cabinet/OneConfCabinetProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ public OneConfCabinetProvider(GameObject avatarGameObject)

public VisualElement CreateView()
{
var view = new OneConfCabinetView(_avatarGameObject);
view.OnEnable();
return view;
return new OneConfCabinetView(_avatarGameObject);
}

public List<IConfigurableOutfit> GetOutfits()
Expand Down
9 changes: 2 additions & 7 deletions Editor/Configurator/Views/OneConfCabinetView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ internal class OneConfCabinetView : ElementView, IOneConfCabinetView
public OneConfCabinetView(GameObject avatarGameObject)
{
_presenter = new OneConfCabinetPresenter(this, avatarGameObject);
InitVisualTree();
t.LocalizeElement(this);
}

private void InitVisualTree()
Expand Down Expand Up @@ -98,13 +100,6 @@ private void InitVisualTree()
Add(_savedToggle);
}

public override void OnEnable()
{
InitVisualTree();
t.LocalizeElement(this);
RaiseLoadEvent();
}

public override void Repaint()
{
_armatureNameField.value = ArmatureName;
Expand Down
3 changes: 0 additions & 3 deletions Editor/Inspector/EditorBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ private void CleanUp()
{
if (_view != null)
{
_view.OnDisable();
if (_viewContainer != null && _viewContainer.Contains(_view))
{
_viewContainer.Remove(_view);
Expand Down Expand Up @@ -123,7 +122,6 @@ private void CreateNewView()

_view = CreateView();
_viewContainer.Add(_view);
_view.OnEnable();
_view.Bind(new SerializedObject(target));
}

Expand All @@ -132,7 +130,6 @@ private void CreateNewView()
public void OnDisable()
{
_view?.Unbind();
_view?.OnDisable();
_view = null;
}
}
Expand Down
28 changes: 8 additions & 20 deletions Editor/Inspector/Views/AnimatorParametersView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ public AnimatorParametersView()
Configs = new List<AnimatorParametersConfig>();
_presenter = new AnimatorParametersPresenter(this);
_animParamTextFields = new List<AnimatorParameterTextField>();

InitVisualTree();
RegisterCallback<MouseEnterEvent>(evt => MouseEnter?.Invoke());
RegisterCallback<MouseLeaveEvent>(evt => MouseLeave?.Invoke());
t.LocalizeElement(this);
}

private void InitVisualTree()
Expand All @@ -64,30 +69,13 @@ private void InitVisualTree()
styleSheets.Add(styleSheet);
}

_helpBoxContainer = Q<VisualElement>("helpbox-container").First();
_helpBoxContainer = Q<VisualElement>("helpbox-container");
_helpBoxContainer.Add(CreateHelpBox(t._("inspector.animParams.helpbox.description"), MessageType.Info));
_configsContainer = Q<VisualElement>("configs-container").First();
var addConfigBtn = Q<Button>("add-config-btn").First();
_configsContainer = Q<VisualElement>("configs-container");
var addConfigBtn = Q<Button>("add-config-btn");
addConfigBtn.clicked += AddConfig;
}

public override void OnEnable()
{
InitVisualTree();

t.LocalizeElement(this);

RegisterCallback<MouseEnterEvent>(evt => MouseEnter?.Invoke());
RegisterCallback<MouseLeaveEvent>(evt => MouseLeave?.Invoke());

RaiseLoadEvent();
}

public override void OnDisable()
{
base.OnDisable();
}

private Box MakeConfigBox(int idx, AnimatorParametersConfig config)
{
var box = new Box();
Expand Down
34 changes: 12 additions & 22 deletions Editor/Inspector/Views/GroupDynamicsView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ public GroupDynamicsView()
SearchMode = 0;
IncludeTransforms = new List<Transform>();
ExcludeTransforms = new List<Transform>();

InitVisualTree();
InitSearchModePopup();
InitIncludes();
InitExcludes();

t.LocalizeElement(this);
}

private void InitVisualTree()
Expand Down Expand Up @@ -89,7 +96,7 @@ private void MakeAddField<T>(VisualElement container, Action<T> newCompAction) w

private void InitSearchModePopup()
{
var popupContainer = Q<VisualElement>("search-mode-popup-container").First();
var popupContainer = Q<VisualElement>("search-mode-popup-container");
var choices = new List<string>() { t._("inspector.groupDynamics.searchMode.controlRoot"), t._("inspector.groupDynamics.searchMode.componentRoot") };
_searchModePopup = new PopupField<string>(t._("inspector.groupDynamics.popup.searchMode"), choices, 0);
_searchModePopup.RegisterValueChangedCallback(evt =>
Expand All @@ -102,35 +109,18 @@ private void InitSearchModePopup()

private void InitIncludes()
{
_includesListContainer = Q<VisualElement>("includes-list-container").First();
var addFieldContainer = Q<VisualElement>("includes-add-field-container").First();
_includesListContainer = Q<VisualElement>("includes-list-container");
var addFieldContainer = Q<VisualElement>("includes-add-field-container");
MakeAddField<Transform>(addFieldContainer, (t) => AddInclude?.Invoke(t));
}

private void InitExcludes()
{
_excludesListContainer = Q<VisualElement>("excludes-list-container").First();
var addFieldContainer = Q<VisualElement>("excludes-add-field-container").First();
_excludesListContainer = Q<VisualElement>("excludes-list-container");
var addFieldContainer = Q<VisualElement>("excludes-add-field-container");
MakeAddField<Transform>(addFieldContainer, (t) => AddExclude?.Invoke(t));
}

public override void OnEnable()
{
InitVisualTree();
InitSearchModePopup();
InitIncludes();
InitExcludes();

t.LocalizeElement(this);

RaiseLoadEvent();
}

public override void OnDisable()
{
base.OnDisable();
}

private void RepaintSearchModePopup()
{
_searchModePopup.index = SearchMode;
Expand Down
30 changes: 6 additions & 24 deletions Editor/Inspector/Views/MenuGroupView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ public MenuGroupView()
{
_subViews = new List<MenuItemView>();
_presenter = new MenuGroupPresenter(this);

InitVisualTree();
t.LocalizeElement(this);
}

private void InitVisualTree()
Expand All @@ -59,29 +62,15 @@ private void InitVisualTree()
styleSheets.Add(styleSheet);
}

_itemsContainer = Q<VisualElement>("items-container").First();
_itemsContainer = Q<VisualElement>("items-container");

_addItemBtn = Q<Button>("add-item-btn").First();
_addItemBtn = Q<Button>("add-item-btn");
_addItemBtn.clicked += AddItem;

_addSmartControlBtn = Q<Button>("add-smart-control-btn").First();
_addSmartControlBtn = Q<Button>("add-smart-control-btn");
_addSmartControlBtn.clicked += AddSmartControl;
}

public override void OnEnable()
{
InitVisualTree();

t.LocalizeElement(this);

RaiseLoadEvent();
}

public override void OnDisable()
{
base.OnDisable();
}

private Box MakeMenuItemBox<T>(int i, T comp) where T : Component
{
var box = new Box();
Expand Down Expand Up @@ -112,12 +101,6 @@ private Box MakeMenuItemBox<T>(int i, T comp) where T : Component
private void UpdateItems()
{
_itemsContainer.Clear();

// disable existing views
foreach (var view in _subViews)
{
view.OnDisable();
}
_subViews.Clear();

var len = Target.transform.childCount;
Expand Down Expand Up @@ -153,7 +136,6 @@ private void UpdateItems()
else
{
var view = new MenuItemView() { Target = menuItem };
view.OnEnable();
_subViews.Add(view);
box.Add(view);
}
Expand Down
16 changes: 2 additions & 14 deletions Editor/Inspector/Views/MenuInstallView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ internal class MenuInstallView : ElementView, IMenuInstallView
public MenuInstallView()
{
_presenter = new MenuInstallPresenter(this);
InitVisualTree();
t.LocalizeElement(this);
}

private void InitVisualTree()
Expand All @@ -71,20 +73,6 @@ private void InitVisualTree()
Add(_installPathField);
}

public override void OnEnable()
{
InitVisualTree();

t.LocalizeElement(this);

RaiseLoadEvent();
}

public override void OnDisable()
{
base.OnDisable();
}

public override void Repaint()
{
_menuGroupControlledHelpbox.style.display = HasMenuGroupComponent ? DisplayStyle.Flex : DisplayStyle.None;
Expand Down
Loading

0 comments on commit a95cdde

Please sign in to comment.