Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/Home.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@
- [`SceneTextureSaveType`](KKAPI.Studio.md#scenetexturesavetype)
- [`SceneTextureSaveTypeChangedEventArgs`](KKAPI.Studio.md#scenetexturesavetypechangedeventargs)
- [`StudioAPI`](KKAPI.Studio.md#studioapi)
- [`StudioContextMenuOrder`](KKAPI.Studio.md#studiocontextmenuorder)
- [`StudioContextMenus`](KKAPI.Studio.md#studiocontextmenus)
- [`StudioObjectExtensions`](KKAPI.Studio.md#studioobjectextensions)
- [`WorkspaceNodeClickedEventArgs`](KKAPI.Studio.md#workspacenodeclickedeventargs)

## [KKAPI.Studio.SaveLoad](KKAPI.Studio.SaveLoad.md)

Expand Down
65 changes: 64 additions & 1 deletion doc/KKAPI.Studio.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ Static Methods
| `IEnumerable<T>` | GetSelectedControllers() | Get all instances of this controller that belong to characters that are selected in Studio's Workspace. |
| `IEnumerable<ObjectCtrlInfo>` | GetSelectedObjects() | Get all objects (all types) currently selected in Studio's Workspace. |
| `TreeNodeObject[]` | GetSelectedTreeNodes() | Get all tree nodes currently selected in Studio's Workspace. Returns an empty array if called outside of studio or before studio finishes loading. |
| `IDisposable` | RegisterTreeNodeContextMenuItems(`MenuOrder` priority, `TreeNodeRightClickHandler` handler) | Subscribe to workspace tree node right click events to add custom context menu items. Only one menu can be shown at a time. Warning: This is called for every tree node right click, so make sure your handler is fast and doesn't allocate memory unnecessarily. Consider caching the entries. |


Static Events
Expand All @@ -96,6 +95,46 @@ Static Events
| `EventHandler` | StudioLoadedChanged | Fires once after studio finished loading the interface, right before custom controls are created. |


## `StudioContextMenuOrder`

Defines the order in which menu items appear in right click context menus. Menu items with the same StudioContextMenuOrder value are grouped together. Different groups are separated by a separator. Any custom value between -100 and 100 can be used. Lower values are called first and appear higher in the menu.
```csharp
public enum KKAPI.Studio.StudioContextMenuOrder
: Enum, IComparable, IFormattable, IConvertible

```

Enum

| Value | Name | Summary |
| --- | --- | --- |
| `-100` | Topmost | Always be at the top of the menu, above all other items. Use only if absolutely necessary. |
| `-70` | SuggestedActions | Actions that are most likely to be used by the user, e.g. "Edit text..." on a text node. |
| `-50` | Actions | Actions to perform on the node, e.g. "Set Vanilla+ shaders". |
| `0` | Default | Default order for menu items, consider using a different value. Appears in the middle of the menu. |
| `40` | Selection | Commands that change selection. |
| `50` | NodeEdit | Basic node editing like deleting or duplicating. |
| `80` | Properties | Opening various properties windows. |
| `100` | Bottommost | Always be at the bottom of the menu, below all other items. Use only if absolutely necessary. |


## `StudioContextMenus`

Provides functionality for adding custom context menu items to studio.
```csharp
public static class KKAPI.Studio.StudioContextMenus

```

Static Methods

| Type | Name | Summary |
| --- | --- | --- |
| `IDisposable` | AddWorkspaceContextMenuItem(`String` content, `Action<WorkspaceNodeClickedEventArgs>` onClick, `StudioContextMenuOrder` order = Default, `Func<WorkspaceNodeClickedEventArgs, EntryState>` checkState = null) | Add a menu item to the workspace context menu. |
| `IDisposable` | AddWorkspaceContextMenuItem(`GUIContent` content, `Action<WorkspaceNodeClickedEventArgs>` onClick, `StudioContextMenuOrder` order = Default, `Func<WorkspaceNodeClickedEventArgs, EntryState>` checkState = null) | Add a menu item to the workspace context menu. |
| `IDisposable` | AddWorkspaceContextMenuItem(`Entry` content, `StudioContextMenuOrder` order) | Add a menu item to the workspace context menu. |


## `StudioObjectExtensions`

Useful extensions for studio metaobjects
Expand All @@ -117,3 +156,27 @@ Static Methods
| `Boolean` | TryGetObjectCtrlInfo(this `TreeNodeObject` tno, `ObjectCtrlInfo&` objectCtrlInfo) | Try to get the ObjectCtrlInfo controlled by this TreeNodeObject. Returns null if the object is not found or if called outside of studio. |


## `WorkspaceNodeClickedEventArgs`

Event arguments for workspace tree node context menu events.
```csharp
public class KKAPI.Studio.WorkspaceNodeClickedEventArgs
: EventArgs

```

Properties

| Type | Name | Summary |
| --- | --- | --- |
| `TreeNodeObject` | ClickedInstance | The tree node that was right-clicked to open the context menu. |
| `ICollection<TreeNodeObject>` | SelectedInstances | All tree nodes currently selected in the workspace. |


Methods

| Type | Name | Summary |
| --- | --- | --- |
| `IEnumerable<ObjectCtrlInfo>` | GetSelectedObjects() | Get all objects currently selected in the workspace. |


3 changes: 3 additions & 0 deletions src/Shared.CharaStudio/Shared.CharaStudio.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
<Compile Include="$(MSBuildThisFileDirectory)Studio\SaveLoad\TestSceneFunctionController.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Studio\StudioAPI.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Studio\StudioAPI.Hooks.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Studio\StudioContextMenuOrder.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Studio\StudioContextMenus.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Studio\StudioObjectExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Studio\UI\BaseCurrentStateEditableGuiEntry.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Studio\UI\CurrentStateCategory.cs" />
Expand All @@ -47,5 +49,6 @@
<Compile Include="$(MSBuildThisFileDirectory)Studio\UI\Toolbars\ToolbarControlAdapter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Studio\UI\Toolbars\SimpleToolbarToggle.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Studio\UI\Toolbars\ToolbarPosition.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Studio\Events\WorkspaceNodeClickedEventArgs.cs" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using Studio;

#pragma warning disable 1591

namespace KKAPI.Studio
{
/// <summary>
/// Event arguments for workspace tree node context menu events.
/// </summary>
public sealed class WorkspaceNodeClickedEventArgs : EventArgs
{
/// <summary>
/// The tree node that was right-clicked to open the context menu.
/// </summary>
public TreeNodeObject ClickedInstance { get; }

/// <summary>
/// All tree nodes currently selected in the workspace.
/// </summary>
public ICollection<TreeNodeObject> SelectedInstances { get; }

/// <summary>
/// Get all objects currently selected in the workspace.
/// </summary>
public IEnumerable<ObjectCtrlInfo> GetSelectedObjects() => StudioAPI.GetSelectedObjects();

public WorkspaceNodeClickedEventArgs(TreeNodeObject clickedInstance)
{
ClickedInstance = clickedInstance;
SelectedInstances = StudioAPI.GetSelectedTreeNodes();
}
}
}
23 changes: 22 additions & 1 deletion src/Shared.CharaStudio/Studio/StudioAPI.Hooks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using KKAPI.Utilities;
using Studio;
using System.Collections;
using UnityEngine;
using UnityEngine.EventSystems;

namespace KKAPI.Studio
{
Expand All @@ -16,7 +18,7 @@ public static void SetupHooks()

[HarmonyPostfix]
[HarmonyPatch(typeof(MPCharCtrl), nameof(MPCharCtrl.OnClickRoot), typeof(int))]
public static void OnClickRoot(int _idx, OCIChar ___m_OCIChar)
private static void OnClickRoot(int _idx, OCIChar ___m_OCIChar)
{
IEnumerator DelayedUpdateTrigger()
{
Expand All @@ -32,6 +34,25 @@ IEnumerator DelayedUpdateTrigger()

KoikatuAPI.Instance.StartCoroutine(DelayedUpdateTrigger());
}

[HarmonyPostfix]
[HarmonyPatch(typeof(TreeNodeObject), nameof(TreeNodeObject.Start))]
private static void OnTreeNodeObjectStart(TreeNodeObject __instance)
{
if (!InsideStudio) return;

__instance.m_ButtonSelect.GetOrAddComponent<PointerDown>().Instance = __instance;
}

private sealed class PointerDown : MonoBehaviour, IPointerClickHandler
{
internal TreeNodeObject Instance;
public void OnPointerClick(PointerEventData eventData)
{
if (Instance && eventData.button == PointerEventData.InputButton.Right)
StudioContextMenus.OnShowWorkspaceContextMenu(Instance);
}
}
}
}
}
1 change: 1 addition & 0 deletions src/Shared.CharaStudio/Studio/StudioAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ internal static void Init(bool insideStudio)

Hooks.SetupHooks();
StudioSaveLoadApi.Init();
StudioContextMenus.Init();

SceneManager.sceneLoaded += SceneLoaded;

Expand Down
43 changes: 43 additions & 0 deletions src/Shared.CharaStudio/Studio/StudioContextMenuOrder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
namespace KKAPI.Studio
{
/// <summary>
/// Defines the order in which menu items appear in right click context menus.
/// Menu items with the same StudioContextMenuOrder value are grouped together. Different groups are separated by a separator.
/// Any custom value between -100 and 100 can be used. Lower values are called first and appear higher in the menu.
/// </summary>
public enum StudioContextMenuOrder
{
/// <summary>
/// Always be at the top of the menu, above all other items. Use only if absolutely necessary.
/// </summary>
Topmost = -100,
/// <summary>
/// Actions that are most likely to be used by the user, e.g. "Edit text..." on a text node.
/// </summary>
SuggestedActions = -70,
/// <summary>
/// Actions to perform on the node, e.g. "Set Vanilla+ shaders".
/// </summary>
Actions = -50,
/// <summary>
/// Default order for menu items, consider using a different value. Appears in the middle of the menu.
/// </summary>
Default = 0,
/// <summary>
/// Commands that change selection.
/// </summary>
Selection = 40,
/// <summary>
/// Basic node editing like deleting or duplicating.
/// </summary>
NodeEdit = 50,
/// <summary>
/// Opening various properties windows.
/// </summary>
Properties = 80,
/// <summary>
/// Always be at the bottom of the menu, below all other items. Use only if absolutely necessary.
/// </summary>
Bottommost = 100
}
}
Loading
Loading