Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into experiments/moonsharp
Browse files Browse the repository at this point in the history
  • Loading branch information
andybak committed Jul 18, 2023
2 parents 817d2fd + 51921dd commit fa9c434
Show file tree
Hide file tree
Showing 13 changed files with 381 additions and 546 deletions.
787 changes: 265 additions & 522 deletions Assets/Prefabs/Panels/AdminPanel.prefab

Large diffs are not rendered by default.

17 changes: 16 additions & 1 deletion Assets/Prefabs/PopUps/PopUpWindow_SketchbookMenu.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,7 @@ MonoBehaviour:
m_GameObject: {fileID: 8366139741319417911}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 6c6859eec74651247968d56b594ac313, type: 3}
m_Script: {fileID: 11500000, guid: 68ab65faed9850448927b196242878d7, type: 3}
m_Name:
m_EditorClassIdentifier:
m_DescriptionType: 0
Expand Down Expand Up @@ -997,6 +997,21 @@ MonoBehaviour:
m_ToggleOnTexture: {fileID: 0}
m_AllowUnavailable: 0
m_LinkedUIObject: {fileID: 0}
m_BeforePopupAction:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 114000011997523446}
m_TargetAssemblyTypeName: TiltBrush.MenuPopUpWindow, Assembly-CSharp
m_MethodName: SetInitialKeyboardText
m_Mode: 0
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
references:
version: 2
RefIds: []
Expand Down
10 changes: 10 additions & 0 deletions Assets/Scenes/Main.unity
Original file line number Diff line number Diff line change
Expand Up @@ -23282,6 +23282,16 @@ PrefabInstance:
m_Modification:
m_TransformParent: {fileID: 694338411}
m_Modifications:
- target: {fileID: 3477360781772463332, guid: e845ea7f1bc1b144f8087e425d81fb6f,
type: 3}
propertyPath: m_HintDescription.m_TableEntryReference.m_KeyId
value: 251895636725760
objectReference: {fileID: 0}
- target: {fileID: 3477360781772463332, guid: e845ea7f1bc1b144f8087e425d81fb6f,
type: 3}
propertyPath: m_HintDescription.m_TableReference.m_TableCollectionName
value: GUID:c84355079ab3f3e4f8f3812258805f86
objectReference: {fileID: 0}
- target: {fileID: 6335177387058214085, guid: e845ea7f1bc1b144f8087e425d81fb6f,
type: 3}
propertyPath: m_Name
Expand Down
20 changes: 7 additions & 13 deletions Assets/Scripts/GUI/KeyboardPopUpWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@

using System;
using System.IO;
using UnityEngine;

namespace TiltBrush
{
public class KeyboardPopUpWindow : OptionsPopUpWindow
{
private KeyboardUI m_KeyboardUI;
[NonSerialized] public static string m_InitialText;
[NonSerialized] public static string m_LastInput;

public bool m_SanitizeFilename;
Expand All @@ -30,20 +32,11 @@ void Awake()
m_KeyboardUI.KeyPressed += KeyPressed;
}

override public void SetPopupCommandParameters(int commandParam, int commandParam2)
override public void Init(GameObject rParent, string sText)
{
if (commandParam2 != (int)SketchSetType.User)
{
return;
}
var sketchSet = SketchCatalog.m_Instance.GetSet(SketchSetType.User) as FileSketchSet;
var sceneFileInfo = sketchSet.GetSketchSceneFileInfo(commandParam);
var currentName = Path.GetFileName(sceneFileInfo.FullPath);
if (currentName.EndsWith(SaveLoadScript.TILT_SUFFIX))
{
currentName = currentName.Substring(0, currentName.Length - SaveLoadScript.TILT_SUFFIX.Length);
}
m_KeyboardUI.AddConsoleContent(currentName);
base.Init(rParent, sText);
m_KeyboardUI.AddConsoleContent(m_InitialText);
m_LastInput = m_InitialText;
}

private void OnDestroy()
Expand All @@ -56,6 +49,7 @@ private void KeyPressed(object sender, KeyboardKeyEventArgs e)
switch (e.Key.KeyType)
{
case KeyboardKeyType.Enter:
// Logic will been to be updated if we ever have a multi-line keyboard
m_LastInput = m_KeyboardUI.ConsoleContent;
if (m_ParentPanel)
{
Expand Down
32 changes: 32 additions & 0 deletions Assets/Scripts/GUI/KeyboardPopupButton.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2023 The Tilt Brush Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using UnityEngine;
using UnityEngine.Events;

namespace TiltBrush
{

public class KeyboardPopupButton : OptionButton
{
[SerializeField]
private UnityEvent<KeyboardPopupButton> m_BeforePopupAction;

override protected void OnButtonPressed()
{
m_BeforePopupAction.Invoke(this);
base.OnButtonPressed();
}
}
} // namespace TiltBrush
11 changes: 11 additions & 0 deletions Assets/Scripts/GUI/KeyboardPopupButton.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions Assets/Scripts/GUI/MenuPopUpWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

using System.IO;
using UnityEngine;
namespace TiltBrush
{

Expand All @@ -25,6 +27,27 @@ public override void SetPopupCommandParameters(int iCommandParam, int iCommandPa
{
button.SetCommandParameters(iCommandParam, iCommandParam2);
}

// The rename button should only be enabled for categories that support renaming
var renameButton = GetComponentInChildren<KeyboardPopupButton>();
SketchSetType sketchSetType = (SketchSetType)iCommandParam2;
renameButton.SetButtonAvailable(sketchSetType == SketchSetType.User);
}

// This code is specific to the "Rename" button in the Sketchbook menu
// This popup class is currently only used for the Sketchbook menu
// If that changes then this probably belongs in a subclass
public void SetInitialKeyboardText(KeyboardPopupButton btn)
{
SketchSetType sketchSetType = (SketchSetType)btn.m_CommandParam2;
var sketchSet = SketchCatalog.m_Instance.GetSet(SketchSetType.User) as FileSketchSet;
var sceneFileInfo = sketchSet.GetSketchSceneFileInfo(btn.m_CommandParam);
var currentName = Path.GetFileName(sceneFileInfo.FullPath);
if (currentName.EndsWith(SaveLoadScript.TILT_SUFFIX))
{
currentName = currentName.Substring(0, currentName.Length - SaveLoadScript.TILT_SUFFIX.Length);
}
KeyboardPopUpWindow.m_InitialText = currentName;
}
}

Expand Down
11 changes: 6 additions & 5 deletions Assets/Scripts/Save/DiskSceneFileInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,10 @@ public void Delete()
}
}

public void Rename(string newName)
public string Rename(string newName)
{
if (!Valid) { return; }

//look to delete the file version first
if (File.Exists(m_fullpath))
// Look to delete the file version first
if (Valid && File.Exists(m_fullpath))
{
string dirPath = Path.GetDirectoryName(m_fullpath);
string newPath = Path.Combine(dirPath, $"{newName}{SaveLoadScript.TILT_SUFFIX}");
Expand All @@ -261,7 +259,10 @@ public void Rename(string newName)
{
Debug.LogFormat("IO Exception: Can't Rename {0}", m_fullpath);
}

return newPath;
}
return m_fullpath;
}

/// Returns a readable stream to a pre-existing subfile,
Expand Down
5 changes: 4 additions & 1 deletion Assets/Scripts/Save/FileSketchSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,10 @@ public virtual void RenameSketch(int toRename, string newName)
driveSet.NotifySketchChanged(m_Sketches[toRename].SceneFileInfo.FullPath);
}

m_Sketches[toRename].SceneFileInfo.Rename(newName);
var newPath = m_Sketches[toRename].SceneFileInfo.Rename(newName);

m_FileWatcher.NotifyCreated(newPath);

}

public virtual void Init()
Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/Save/SceneFileInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public interface SceneFileInfo

void Delete();

void Rename(string newName);
string Rename(string newName);

bool IsHeaderValid();

Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/Sharing/GoogleDriveSketchSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public void Delete()
throw new NotImplementedException();
}

public void Rename(string newName)
public string Rename(string newName)
{
throw new NotImplementedException();
}
Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/Sharing/PolySketchSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,7 @@ public void Delete()
throw new NotImplementedException();
}

public void Rename(string newName)
public string Rename(string newName)
{
throw new NotImplementedException();
}
Expand Down
5 changes: 4 additions & 1 deletion Assets/Scripts/SketchControlsScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4576,7 +4576,10 @@ public void LoadSketch(SceneFileInfo fileInfo, bool quickload = false, bool addi
{
var sketchSetType = (SketchSetType)iParam2;
SketchSet sketchSet = SketchCatalog.m_Instance.GetSet(sketchSetType);
sketchSet.RenameSketch(iParam1, KeyboardPopUpWindow.m_LastInput);
if (sketchSetType == SketchSetType.User)
{
sketchSet.RenameSketch(iParam1, KeyboardPopUpWindow.m_LastInput);
}
DismissPopupOnCurrentGazeObject(false);
break;
}
Expand Down

0 comments on commit fa9c434

Please sign in to comment.