Skip to content

Commit

Permalink
change ui
Browse files Browse the repository at this point in the history
  • Loading branch information
poi-vrc committed May 1, 2024
1 parent 64d0199 commit da07e37
Show file tree
Hide file tree
Showing 11 changed files with 408 additions and 624 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* You should have received a copy of the GNU General Public License along with DressingFramework. If not, see <https://www.gnu.org/licenses/>.
*/

using System;
using Chocopoi.AvatarLib.Animations;
using Chocopoi.DressingTools.Components.OneConf;
using Chocopoi.DressingTools.OneConf;
Expand Down Expand Up @@ -71,7 +72,7 @@ public OneConfArmatureMappingModule(GameObject avatarGameObject, DTWearable wear

public override VisualElement CreateView()
{
return new ArmatureMappingWearableModuleEditor(null, null, null);
throw new NotImplementedException();
}
}
}
3 changes: 1 addition & 2 deletions Editor/UI/DTMainEditorWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

using System.Diagnostics.CodeAnalysis;
using Chocopoi.DressingFramework.Localization;
using Chocopoi.DressingTools.Components.OneConf;
using Chocopoi.DressingTools.Localization;
using Chocopoi.DressingTools.UI.Views;
using UnityEditor;
Expand Down Expand Up @@ -46,7 +45,7 @@ public static void ShowWindow()
window.Show();
}

public void SelectCabinet(DTCabinet cabinet) => _view.SelectCabinet(cabinet);
public void SelectAvatar(GameObject avatarGameObject) => _view.SelectAvatar(avatarGameObject);

public void StartDressing(GameObject avatarGameObject, GameObject wearableGameObject)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,20 @@
*/

using Chocopoi.DressingFramework.Localization;
using Chocopoi.DressingTools.Components.OneConf;
using Chocopoi.DressingTools.Localization;
using Chocopoi.DressingTools.OneConf;
using Chocopoi.DressingTools.OneConf.Cabinet;
using Chocopoi.DressingTools.OneConf.Cabinet.Modules.BuiltIn;
using Chocopoi.DressingTools.OneConf.Serialization;
using Chocopoi.DressingTools.UI.Views;
using UnityEditor;
using UnityEngine;

namespace Chocopoi.DressingTools.UI.Presenters
{
internal class CabinetPresenter
internal class AvatarPresenter
{
private static readonly I18nTranslator t = I18n.ToolTranslator;

private ICabinetSubView _view;
private CabinetConfig _cabinetConfig;
private IAvatarSubView _view;

public CabinetPresenter(ICabinetSubView view)
public AvatarPresenter(IAvatarSubView view)
{
_view = view;

Expand All @@ -47,13 +41,10 @@ private void SubscribeEvents()
_view.Load += OnLoad;
_view.Unload += OnUnload;

_view.AddWearableButtonClick += OnAddWearableButtonClick;
_view.AddOutfitButtonClick += OnAddOutfitButtonClick;
_view.ForceUpdateView += OnForceUpdateView;
_view.SelectedCabinetChange += OnSelectedCabinetChange;
_view.CabinetSettingsChange += OnCabinetSettingsChange;
_view.ToolbarCreateCabinetButtonClick += OnToolbarCreateCabinetButtonClick;
_view.CreateCabinetStartButtonClick += OnCreateCabinetStartButtonClick;
_view.CreateCabinetBackButtonClick += OnCreateCabinetBackButtonClick;
_view.SelectedAvatarChange += OnSelectedCabinetChange;
_view.AvatarSettingsChange += OnAvatarSettingsChange;

EditorApplication.hierarchyChanged += OnHierarchyChanged;
EditorApplication.playModeStateChanged += OnPlayModeStateChanged;
Expand All @@ -64,13 +55,10 @@ private void UnsubscribeEvents()
_view.Load -= OnLoad;
_view.Unload -= OnUnload;

_view.AddWearableButtonClick -= OnAddWearableButtonClick;
_view.AddOutfitButtonClick -= OnAddOutfitButtonClick;
_view.ForceUpdateView -= OnForceUpdateView;
_view.SelectedCabinetChange -= OnSelectedCabinetChange;
_view.CabinetSettingsChange -= OnCabinetSettingsChange;
_view.ToolbarCreateCabinetButtonClick -= OnToolbarCreateCabinetButtonClick;
_view.CreateCabinetStartButtonClick -= OnCreateCabinetStartButtonClick;
_view.CreateCabinetBackButtonClick -= OnCreateCabinetBackButtonClick;
_view.SelectedAvatarChange -= OnSelectedCabinetChange;
_view.AvatarSettingsChange -= OnAvatarSettingsChange;

EditorApplication.hierarchyChanged -= OnHierarchyChanged;
EditorApplication.playModeStateChanged -= OnPlayModeStateChanged;
Expand All @@ -84,32 +72,6 @@ private void OnPlayModeStateChanged(PlayModeStateChange change)
}
}

private void OnCreateCabinetBackButtonClick()
{
_view.ShowCreateCabinetPanel = false;
UpdateView();
}

private void OnCreateCabinetStartButtonClick()
{
if (_view.CreateCabinetAvatarGameObject == null)
{
return;
}
OneConfUtils.GetAvatarCabinet(_view.CreateCabinetAvatarGameObject, true);
_view.ShowCreateCabinetPanel = false;
UpdateView();
}

private void OnToolbarCreateCabinetButtonClick()
{
_view.ShowCreateCabinetPanel = true;
_view.ShowCreateCabinetBackButton = true;
_view.CreateCabinetAvatarGameObject = null;

UpdateView();
}

private void OnHierarchyChanged()
{
if (Application.isPlaying) return;
Expand All @@ -122,7 +84,7 @@ private void OnSelectedCabinetChange()
UpdateView();
}

private void OnCabinetSettingsChange()
private void OnAvatarSettingsChange()
{
var cabinets = OneConfUtils.GetAllCabinets();

Expand All @@ -134,7 +96,7 @@ private void OnCabinetSettingsChange()
}
_view.ShowCreateCabinetBackButton = true;

var cabinet = cabinets[_view.SelectedCabinetIndex];
var cabinet = cabinets[_view.SelectedAvatarIndex];

cabinet.RootGameObject = _view.CabinetAvatarGameObject;

Expand All @@ -147,7 +109,7 @@ private void OnCabinetSettingsChange()
_cabinetConfig.avatarArmatureName = _view.CabinetAvatarArmatureName;
_cabinetConfig.groupDynamics = _view.CabinetGroupDynamics;
_cabinetConfig.groupDynamicsSeparateGameObjects = _view.CabinetGroupDynamicsSeparateGameObjects;
_cabinetConfig.animationWriteDefaultsMode = (CabinetConfig.WriteDefaultsMode)_view.CabinetAnimationWriteDefaultsMode;
_cabinetConfig.animationWriteDefaultsMode = (CabinetConfig.WriteDefaultsMode)_view.SettingsAnimationWriteDefaultsMode;

var cabAnimConfig = _cabinetConfig.FindModuleConfig<CabinetAnimCabinetModuleConfig>();
if (cabAnimConfig == null)
Expand Down Expand Up @@ -196,7 +158,7 @@ public void SelectCabinet(DTCabinet cabinet)
{
if (cabinets[i] == cabinet)
{
_view.SelectedCabinetIndex = i;
_view.SelectedAvatarIndex = i;
break;
}
}
Expand All @@ -208,10 +170,10 @@ public void SelectCabinet(DTCabinet cabinet)
private void UpdateCabinetSelectionDropdown(DTCabinet[] cabinets)
{
// cabinet selection dropdown
_view.AvailableCabinetSelections.Clear();
_view.AvailableAvatarSelections.Clear();
for (var i = 0; i < cabinets.Length; i++)
{
_view.AvailableCabinetSelections.Add(cabinets[i].RootGameObject != null ? cabinets[i].RootGameObject.name : t._("cabinet.editor.cabinetContent.popup.cabinetOptions.cabinetNameNoGameObjectAttached", i + 1));
_view.AvailableAvatarSelections.Add(cabinets[i].RootGameObject != null ? cabinets[i].RootGameObject.name : t._("cabinet.editor.cabinetContent.popup.cabinetOptions.cabinetNameNoGameObjectAttached", i + 1));
}
}

Expand All @@ -229,17 +191,17 @@ private void UpdateCabinetContentView()

UpdateCabinetSelectionDropdown(cabinets);

if (_view.SelectedCabinetIndex < 0 || _view.SelectedCabinetIndex >= cabinets.Length)
if (_view.SelectedAvatarIndex < 0 || _view.SelectedAvatarIndex >= cabinets.Length)
{
// invalid selected cabinet index, setting it back to 0
_view.SelectedCabinetIndex = 0;
_view.SelectedAvatarIndex = 0;
}

// clear views
_view.InstalledWearablePreviews.Clear();
_view.InstalledOutfitPreviews.Clear();

// update selected cabinet view
var cabinet = cabinets[_view.SelectedCabinetIndex];
var cabinet = cabinets[_view.SelectedAvatarIndex];

// cabinet json is broken, ask user whether to make a new one or not
if (!CabinetConfigUtility.TryDeserialize(cabinet.ConfigJson, out _cabinetConfig) || !_cabinetConfig.IsValid())
Expand All @@ -253,15 +215,15 @@ private void UpdateCabinetContentView()
_view.CabinetAvatarArmatureName = _cabinetConfig.avatarArmatureName;
_view.CabinetGroupDynamics = _cabinetConfig.groupDynamics;
_view.CabinetGroupDynamicsSeparateGameObjects = _cabinetConfig.groupDynamicsSeparateGameObjects;
_view.CabinetAnimationWriteDefaultsMode = (int)_cabinetConfig.animationWriteDefaultsMode;
_view.SettingsAnimationWriteDefaultsMode = (int)_cabinetConfig.animationWriteDefaultsMode;
UpdateCabinetAnimationConfig();

var wearables = OneConfUtils.GetCabinetWearables(cabinet.RootGameObject);

foreach (var wearable in wearables)
{
var config = WearableConfigUtility.Deserialize(wearable.ConfigJson);
_view.InstalledWearablePreviews.Add(new WearablePreview()
_view.InstalledOutfitPreviews.Add(new OutfitPreview()
{
name = config != null ?
config.info.name :
Expand Down Expand Up @@ -289,17 +251,6 @@ private void UpdateCabinetContentView()
}
}

private void UpdateCabinetAnimationConfig()
{
var cabAnimConfig = _cabinetConfig.FindModuleConfig<CabinetAnimCabinetModuleConfig>() ?? new CabinetAnimCabinetModuleConfig();
_view.CabinetUseThumbnailsAsMenuIcons = cabAnimConfig.thumbnails;
_view.CabinetMenuInstallPath = cabAnimConfig.menuInstallPath;
_view.CabinetMenuItemName = cabAnimConfig.menuItemName;
_view.CabinetNetworkSynced = cabAnimConfig.networkSynced;
_view.CabinetSaved = cabAnimConfig.saved;
_view.CabinetResetCustomizablesOnSwitch = cabAnimConfig.resetCustomizablesOnSwitch;
}

private void UpdateView()
{
UpdateCabinetContentView();
Expand All @@ -316,17 +267,9 @@ private void OnUnload()
UnsubscribeEvents();
}

private void OnAddWearableButtonClick()
private void OnAddOutfitButtonClick()
{
var cabinets = OneConfUtils.GetAllCabinets();

if (cabinets.Length == 0 || _view.SelectedCabinetIndex < 0 || _view.SelectedCabinetIndex >= cabinets.Length)
{
return;
}

var cabinet = cabinets[_view.SelectedCabinetIndex];
_view.StartDressing(cabinet.RootGameObject);
_view.StartDressing(_view.SelectedAvatarGameObject);
}
}
}
Loading

0 comments on commit da07e37

Please sign in to comment.