Skip to content

Commit

Permalink
SketchSets are now identified by type and instance
Browse files Browse the repository at this point in the history
Very Work In Progress!
  • Loading branch information
TimAidley committed Mar 1, 2023
1 parent ea24e65 commit a1ede70
Show file tree
Hide file tree
Showing 19 changed files with 208 additions and 119 deletions.
4 changes: 2 additions & 2 deletions Assets/Scripts/GUI/DownloadPopupWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ public class DownloadPopupWindow : PopUpWindow

override public void SetPopupCommandParameters(int commandParam, int commandParam2)
{
if (commandParam2 != (int)SketchSetType.Drive)
var sketchSet = SketchCatalog.m_Instance.GetSet(commandParam2);
if (sketchSet.SketchSetType != GoogleDriveSketchSet.TypeName)
{
return;
}
m_SketchIndex = commandParam;
var sketchSet = SketchCatalog.m_Instance.GetSet(SketchSetType.Drive) as GoogleDriveSketchSet;
m_SceneFileInfo =
sketchSet.GetSketchSceneFileInfo(commandParam) as GoogleDriveSketchSet.GoogleDriveFileInfo;

Expand Down
9 changes: 5 additions & 4 deletions Assets/Scripts/GUI/InspectSketchButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,20 @@ namespace TiltBrush
public class InspectSketchButton : BaseButton
{
private int m_SketchIndex;
private SketchSetType m_SketchSetType;
private string m_SketchSetId;

public void SetSketchDetails(int index, SketchSetType type)
public void SetSketchDetails(int index, string type)
{
m_SketchIndex = index;
m_SketchSetType = type;
m_SketchSetId = type;
}

override protected void OnButtonPressed()
{
BasePanel panel = m_Manager.GetPanelForPopUps();
int index = SketchCatalog.m_Instance.GetSetIndexById(m_SketchSetId);
panel.CreatePopUp(SketchControlsScript.GlobalCommands.SketchbookMenu,
m_SketchIndex, (int)m_SketchSetType);
m_SketchIndex, index);

// Position popup next to button.
panel.PositionPopUp(transform.position);
Expand Down
10 changes: 5 additions & 5 deletions Assets/Scripts/GUI/LoadSketchButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ public bool WarningVisible

void RefreshDetails()
{
m_MenuButton.SetSketchDetails(m_SketchIndex, SketchSet.Type);
m_MenuButton.SetSketchDetails(m_SketchIndex, SketchSet.SketchSetId);

m_SizeOk = true;
if (m_SketchSet.Type == SketchSetType.Liked)
if (m_SketchSet.SketchSetType == PolySketchSet.TypeName && m_SketchSet.SketchSetInstance == "Liked")
{
if (m_SketchSet.IsSketchIndexValid(m_SketchIndex))
{
Expand Down Expand Up @@ -151,7 +151,7 @@ override public void SetColor(Color color)
override protected void OnButtonPressed()
{
if (!m_SketchSet.GetSketchSceneFileInfo(m_SketchIndex).Available &&
m_SketchSet.Type != SketchSetType.Drive)
m_SketchSet.SketchSetType != GoogleDriveSketchSet.TypeName)
{
return;
}
Expand All @@ -160,7 +160,7 @@ override protected void OnButtonPressed()
// LoadConfirmUnsaved -> LoadWaitOnDownload -> LoadConfirmComplex -> LoadComplexHigh -> Load
SketchControlsScript.m_Instance.IssueGlobalCommand(
SketchControlsScript.GlobalCommands.LoadConfirmUnsaved,
m_SketchIndex, (int)m_SketchSet.Type);
m_SketchIndex, SketchCatalog.m_Instance.GetSetIndex(m_SketchSet));
ResetState();
}

Expand Down Expand Up @@ -196,7 +196,7 @@ override public void GainFocus()
{
base.GainFocus();
m_DynamicUvTransitionValue = 0.0f;
m_MenuButton.gameObject.SetActive(m_SketchSet.Type == SketchSetType.User);
m_MenuButton.gameObject.SetActive(m_SketchSet.SketchSetType == FileSketchSet.TypeName);
if (!m_SizeOk)
{
SetDescriptionVisualsAvailable(false);
Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/GUI/NewSketchButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected override void OnButtonPressed()

// Change the shown sketchset by simulating a press on the corresponding gallery button.
SketchbookPanel panel = m_Manager.GetComponent<SketchbookPanel>();
if (SketchCatalog.m_Instance.GetSet(SketchSetType.User).NumSketches == 0)
if (SketchCatalog.m_Instance.GetFirstSetOrDefault(FileSketchSet.TypeName).NumSketches == 0)
{
panel.ButtonPressed(GalleryButton.Type.Showcase);
}
Expand Down
98 changes: 52 additions & 46 deletions Assets/Scripts/GUI/SketchbookPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public class SketchbookPanel : ModalPanel

private bool m_AllIconTexturesAssigned;
private bool m_AllSketchesAreAvailable;
private SketchSetType m_CurrentSketchSet;
//private string m_CurrentSketchSet;
private ISketchSet m_SketchSet;
private OptionButton m_NewSketchButtonScript;
private OptionButton m_PaintButtonScript;
Expand Down Expand Up @@ -114,11 +114,13 @@ protected override List<BaseButton> Icons
public override bool IsInButtonMode(ModeButton button)
{
GalleryButton galleryButton = button as GalleryButton;
int index = SketchCatalog.m_Instance.GetSetIndex(m_SketchSet);
// TODO: There's gotta be a better way of doing this!
return galleryButton &&
((galleryButton.m_ButtonType == GalleryButton.Type.Liked && m_CurrentSketchSet == SketchSetType.Liked) ||
(galleryButton.m_ButtonType == GalleryButton.Type.Local && m_CurrentSketchSet == SketchSetType.User) ||
(galleryButton.m_ButtonType == GalleryButton.Type.Showcase && m_CurrentSketchSet == SketchSetType.Curated) ||
(galleryButton.m_ButtonType == GalleryButton.Type.Drive && m_CurrentSketchSet == SketchSetType.Drive));
((galleryButton.m_ButtonType == GalleryButton.Type.Liked && index == 2) ||
(galleryButton.m_ButtonType == GalleryButton.Type.Local && index == 0) ||
(galleryButton.m_ButtonType == GalleryButton.Type.Showcase && index == 1) ||
(galleryButton.m_ButtonType == GalleryButton.Type.Drive && index == 3));
}

override public void InitPanel()
Expand Down Expand Up @@ -160,12 +162,15 @@ protected override void OnStart()
m_NotLoggedInMessage.SetActive(false);
m_NotLoggedInDriveMessage.SetActive(false);

m_SketchSet = SketchCatalog.m_Instance.GetSet(2); // Poly sketches


// Dynamically position the gallery buttons.
OnDriveSetHasSketchesChanged();

// Set the sketch set var to Liked, then function set to force state.
m_CurrentSketchSet = SketchSetType.Liked;
SetVisibleSketchSet(SketchSetType.User);
SetVisibleSketchSet(SketchCatalog.m_Instance.GetSet(0));
RefreshPage();

Action refresh = () =>
{
Expand All @@ -178,9 +183,11 @@ protected override void OnStart()
RefreshPage();
}
};
SketchCatalog.m_Instance.GetSet(SketchSetType.Liked).OnSketchRefreshingChanged += refresh;
SketchCatalog.m_Instance.GetSet(SketchSetType.Curated).OnSketchRefreshingChanged += refresh;
SketchCatalog.m_Instance.GetSet(SketchSetType.Drive).OnSketchRefreshingChanged += refresh;

// TODO: We probably should just do a refresh when we enter a sketchset
SketchCatalog.m_Instance.GetSet(1).OnSketchRefreshingChanged += refresh;
SketchCatalog.m_Instance.GetSet(2).OnSketchRefreshingChanged += refresh;
SketchCatalog.m_Instance.GetSet(3).OnSketchRefreshingChanged += refresh;
App.GoogleIdentity.OnLogout += refresh;
}

Expand All @@ -201,9 +208,9 @@ override protected void OnEnablePanel()
}
}

void SetVisibleSketchSet(SketchSetType type)
void SetVisibleSketchSet(ISketchSet newSketchSet)
{
if (m_CurrentSketchSet != type)
if (newSketchSet != m_SketchSet)
{
// Clean up our old sketch set.
if (m_SketchSet != null)
Expand All @@ -212,7 +219,7 @@ void SetVisibleSketchSet(SketchSetType type)
}

// Cache new set.
m_SketchSet = SketchCatalog.m_Instance.GetSet(type);
m_SketchSet = newSketchSet;
m_SketchSet.OnChanged += OnSketchSetDirty;
m_SketchSet.RequestRefresh();

Expand All @@ -227,12 +234,12 @@ void SetVisibleSketchSet(SketchSetType type)

ComputeNumPages();
ResetPageIndex();
m_CurrentSketchSet = type;
RefreshPage();

switch (m_CurrentSketchSet)

switch (newSketchSet.SketchSetType)
{
case SketchSetType.User:
case FileSketchSet.TypeName:
if (m_PanelText)
{
m_PanelText.text = m_PanelTextStandard;
Expand All @@ -242,7 +249,7 @@ void SetVisibleSketchSet(SketchSetType type)
m_PanelTextPro.text = m_PanelTextStandard;
}
break;
case SketchSetType.Curated:
case ResourceCollectionSketchSet.TypeName:
if (m_PanelText)
{
m_PanelText.text = m_PanelTextShowcase;
Expand All @@ -252,7 +259,7 @@ void SetVisibleSketchSet(SketchSetType type)
m_PanelTextPro.text = m_PanelTextShowcase;
}
break;
case SketchSetType.Liked:
case PolySketchSet.TypeName:
if (m_PanelText)
{
m_PanelText.text = m_PanelTextLiked;
Expand All @@ -262,7 +269,7 @@ void SetVisibleSketchSet(SketchSetType type)
m_PanelTextPro.text = m_PanelTextLiked;
}
break;
case SketchSetType.Drive:
case GoogleDriveSketchSet.TypeName:
if (m_PanelText)
{
m_PanelText.text = m_PanelTextDrive;
Expand Down Expand Up @@ -322,7 +329,7 @@ protected override void RefreshPage()
// Base Refresh updates the modal parts of the panel, and we always want those refreshed.
base.RefreshPage();

bool requiresPoly = m_CurrentSketchSet == SketchSetType.Liked;
bool requiresPoly = m_SketchSet.SketchSetType == PolySketchSet.TypeName;

bool polyDown = VrAssetService.m_Instance.NoConnection && requiresPoly;
m_NoPolyConnectionMessage.SetActive(polyDown);
Expand All @@ -344,37 +351,35 @@ protected override void RefreshPage()
bool refreshIcons = m_SketchSet.NumSketches > 0;

// Show no sketches if we don't have sketches.
m_NoSketchesMessage.SetActive(
(m_CurrentSketchSet == SketchSetType.User) && (m_SketchSet.NumSketches <= 0));
m_NoDriveSketchesMessage.SetActive(
(m_CurrentSketchSet == SketchSetType.Drive) && (m_SketchSet.NumSketches <= 0));
bool isUser = m_SketchSet.SketchSetType == FileSketchSet.TypeName;
bool isLiked = m_SketchSet.SketchSetType == PolySketchSet.TypeName;
bool isCurated = m_SketchSet.SketchSetType == ResourceCollectionSketchSet.TypeName;
bool isDrive = m_SketchSet.SketchSetType == GoogleDriveSketchSet.TypeName;
m_NoSketchesMessage.SetActive(isUser && (m_SketchSet.NumSketches <= 0));
m_NoDriveSketchesMessage.SetActive(isDrive && (m_SketchSet.NumSketches <= 0));

// Show sign in popup if signed out for liked or drive sketchsets
bool showNotLoggedIn = !App.GoogleIdentity.LoggedIn &&
(m_CurrentSketchSet == SketchSetType.Liked ||
m_CurrentSketchSet == SketchSetType.Drive);
bool showNotLoggedIn = !App.GoogleIdentity.LoggedIn && (isLiked || isDrive);
refreshIcons = refreshIcons && !showNotLoggedIn;
m_NotLoggedInMessage.SetActive(showNotLoggedIn && m_CurrentSketchSet == SketchSetType.Liked);
m_NotLoggedInDriveMessage.SetActive(showNotLoggedIn &&
m_CurrentSketchSet == SketchSetType.Drive);
m_NotLoggedInMessage.SetActive(showNotLoggedIn && isLiked);
m_NotLoggedInDriveMessage.SetActive(showNotLoggedIn && isDrive);

// Show no likes text & gallery button if we don't have liked sketches.
m_NoLikesMessage.SetActive(
(m_CurrentSketchSet == SketchSetType.Liked) &&
isLiked &&
(m_SketchSet.NumSketches <= 0) &&
!m_SketchSet.IsActivelyRefreshingSketches &&
App.GoogleIdentity.LoggedIn);

// Show Contacting Server if we're talking to Poly.
m_ContactingServerMessage.SetActive(
(requiresPoly ||
m_CurrentSketchSet == SketchSetType.Drive) &&
(requiresPoly || isDrive) &&
(m_SketchSet.NumSketches <= 0) &&
(m_SketchSet.IsActivelyRefreshingSketches && App.GoogleIdentity.LoggedIn));

// Show Showcase error if we're in Showcase and don't have sketches.
m_NoShowcaseMessage.SetActive(
(m_CurrentSketchSet == SketchSetType.Curated) &&
isCurated &&
(m_SketchSet.NumSketches <= 0) &&
!m_SketchSet.IsActivelyRefreshingSketches);

Expand Down Expand Up @@ -462,27 +467,27 @@ void Update()
icon.UpdateUvOffsetAndScale(offset, m_SketchIconUvScale);
}

switch (m_CurrentSketchSet)
switch (m_SketchSet.SketchSetType)
{
case SketchSetType.Curated:
case ResourceCollectionSketchSet.TypeName:
m_LoadingGallery.SetActive(m_SketchSet.IsActivelyRefreshingSketches);
m_DriveSyncProgress.SetActive(false);
m_SyncingDriveIcon.SetActive(false);
m_DriveEnabledIcon.SetActive(false);
m_DriveDisabledIcon.SetActive(false);
m_DriveFullIcon.SetActive(false);
break;
case SketchSetType.Liked:
case PolySketchSet.TypeName:
m_LoadingGallery.SetActive(false);
m_DriveSyncProgress.SetActive(false);
m_SyncingDriveIcon.SetActive(false);
m_DriveEnabledIcon.SetActive(false);
m_DriveDisabledIcon.SetActive(false);
m_DriveFullIcon.SetActive(false);
break;
case SketchSetType.User:
case SketchSetType.Drive:
bool sketchSetRefreshing = m_CurrentSketchSet == SketchSetType.Drive &&
case FileSketchSet.TypeName:
case GoogleDriveSketchSet.TypeName:
bool sketchSetRefreshing = m_SketchSet.SketchSetType == GoogleDriveSketchSet.TypeName &&
m_SketchSet.IsActivelyRefreshingSketches;
bool driveSyncing = App.DriveSync.Syncing;
bool syncEnabled = App.DriveSync.SyncEnabled;
Expand All @@ -499,7 +504,7 @@ void Update()

// Check to see if whether "drive set has sketches" has changed.
bool driveSetHasSketches =
SketchCatalog.m_Instance.GetSet(SketchSetType.Drive).NumSketches != 0;
SketchCatalog.m_Instance.GetFirstSetOrDefault(GoogleDriveSketchSet.TypeName).NumSketches != 0;
if (m_DriveSetHasSketches != driveSetHasSketches)
{
m_DriveSetHasSketches = driveSetHasSketches;
Expand All @@ -524,7 +529,7 @@ private void OnDriveSetHasSketchesChanged()
m_GalleryButtons[m_ElementNumberGalleryButtonDrive].gameObject.SetActive(false);
galleryButtonN = galleryButtonAvailable - 1;

if (m_CurrentSketchSet == SketchSetType.Drive)
if (m_SketchSet.SketchSetType == GoogleDriveSketchSet.TypeName)
{
// We were on the Drive tab but it's gone away so switch to the local tab by simulating
// the user pressing the local tab button.
Expand Down Expand Up @@ -755,23 +760,24 @@ override public bool RaycastAgainstMeshCollider(Ray rRay, out RaycastHit rHitInf
// Works specifically with GalleryButtons.
public void ButtonPressed(GalleryButton.Type rType, BaseButton button = null)
{
// TODO: Just do this whole damn thing differently.
switch (rType)
{
case GalleryButton.Type.Exit:
SketchSurfacePanel.m_Instance.EnableDefaultTool();
PointerManager.m_Instance.EatLineEnabledInput();
break;
case GalleryButton.Type.Showcase:
SetVisibleSketchSet(SketchSetType.Curated);
SetVisibleSketchSet(SketchCatalog.m_Instance.GetSet(1));
break;
case GalleryButton.Type.Local:
SetVisibleSketchSet(SketchSetType.User);
SetVisibleSketchSet(SketchCatalog.m_Instance.GetSet(0));
break;
case GalleryButton.Type.Liked:
SetVisibleSketchSet(SketchSetType.Liked);
SetVisibleSketchSet(SketchCatalog.m_Instance.GetSet(2));
break;
case GalleryButton.Type.Drive:
SetVisibleSketchSet(SketchSetType.Drive);
SetVisibleSketchSet(SketchCatalog.m_Instance.GetSet(3));
if (!m_ReadOnlyShown)
{
CreatePopUp(SketchControlsScript.GlobalCommands.ReadOnlyNotice,
Expand Down
3 changes: 3 additions & 0 deletions Assets/Scripts/ResourceSystem/FilesystemSketchCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ public FilesystemSketchCollection(string path, string name)
Name = name;
}

public string CollectionType => "LocalFolderCollection";
public string CollectionInstance => m_Path;

public string Name { get; private set; }

public Uri Uri { get; private set; }
Expand Down
3 changes: 3 additions & 0 deletions Assets/Scripts/ResourceSystem/IResourceCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@ namespace TiltBrush
public interface IResourceCollection : IResource
{
IAsyncEnumerable<IResource> ContentsAsync();

string CollectionType { get; }
string CollectionInstance { get; }
}
}
3 changes: 3 additions & 0 deletions Assets/Scripts/ResourceSystem/IcosaSketchCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ public IcosaSketchCollection(HttpClient httpClient, string user = null)
m_httpClient = httpClient;
}

public string CollectionType => "Icosa";
public string CollectionInstance => m_User ?? "";

public string Name { get; private set; }
public Uri Uri { get; }
public Uri PreviewUri { get; }
Expand Down
5 changes: 4 additions & 1 deletion Assets/Scripts/ResourceSystem/ResourceCollectionSketchSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ public ResourceCollectionSketchSet(IResourceCollection collection)
m_Collection = collection;
m_ResourceEnumerator = m_Collection.ContentsAsync().GetAsyncEnumerator();
}
public SketchSetType Type => SketchSetType.Curated;

public const string TypeName = "ResourceCollection";
public string SketchSetType => m_Collection.CollectionType;
public string SketchSetInstance => m_Collection.CollectionInstance;

public bool IsReadyForAccess => m_Init is { IsCompleted: true };

Expand Down
Loading

0 comments on commit a1ede70

Please sign in to comment.