feat: page locking, external page changing

This commit is contained in:
Chris
2025-08-26 13:50:57 -04:00
parent b1b8a5b957
commit acf2e23d71
2 changed files with 72 additions and 2 deletions

View File

@@ -94,6 +94,15 @@
"processors": "",
"interactions": "",
"initialStateCheck": false
},
{
"name": "Debug Lock Page",
"type": "Button",
"id": "ad725c08-41d1-45b5-b5c9-3db391721b66",
"expectedControlType": "",
"processors": "",
"interactions": "",
"initialStateCheck": false
}
],
"bindings": [
@@ -305,6 +314,39 @@
"action": "Debug Next Page",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "One Modifier",
"id": "e3076387-3607-4c5a-ac2d-11e2e03565b0",
"path": "OneModifier",
"interactions": "",
"processors": "",
"groups": "",
"action": "Debug Lock Page",
"isComposite": true,
"isPartOfComposite": false
},
{
"name": "modifier",
"id": "aea9379f-fc0f-4ee8-affa-13b9f4cf1775",
"path": "<Gamepad>/select",
"interactions": "",
"processors": "",
"groups": "",
"action": "Debug Lock Page",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "Binding",
"id": "e9c97b2b-23b4-4cde-bfe2-451ddf093b27",
"path": "<Gamepad>/dpad/down",
"interactions": "",
"processors": "",
"groups": "",
"action": "Debug Lock Page",
"isComposite": false,
"isPartOfComposite": true
}
]
}

View File

@@ -28,6 +28,7 @@ namespace Reset.Core.Tools{
[Space]
public string pageNamePrefix = "Debug Page: ";
public static bool Locked;
private static float defaultLabelAlpha;
private static float defaultValueAlpha;
@@ -77,7 +78,7 @@ namespace Reset.Core.Tools{
}
// Otherwise, this will make a new one and add it
UIDocument thisDocument = null;
UIDocument thisDocument;
if (thisPageObject == null) {
// Create a new object
@@ -102,7 +103,7 @@ namespace Reset.Core.Tools{
// If this is the only page, set it to the current page
if (Instance.Pages.Count == 1) {
Instance.currentPage = new KeyValuePair<GameObject, List<string>>(thisPageObject, new List<string>());
ChangeToPage(pageName);
SetCurrentPageVisible();
}
@@ -144,6 +145,21 @@ namespace Reset.Core.Tools{
labelBG.style.backgroundColor = ((newColor / 1.2f + Color.gray * .3f)* .7f).Alpha(defaultLabelAlpha);
valueBG.style.backgroundColor = ((newColor / 1.5f + Color.gray * .4f) * .6f) .Alpha(defaultValueAlpha);
}
// Change to a specific page
public static void ChangeToPage(string pageName){
if (Locked) {
Debug.LogWarning($"Can't switch to page {pageName}: Page is currently locked");
return;
}
try {
Instance.currentPage = Instance.Pages.Where(pair => pair.Key.name == Instance.pageNamePrefix + pageName).First();
} catch (Exception e) {
Debug.LogError($"Couldn't switch page to {pageName}: {e.Message}");
throw;
}
}
// Back a page
public static void PreviousPage(){
@@ -152,6 +168,12 @@ namespace Reset.Core.Tools{
return;
}
// Lock check
if (Locked) {
Debug.LogWarning($"Attempted to switch to a new page but the page is locked.");
return;
}
// Get the index of the current page
int currentIndex = Instance.Pages.ToList().IndexOf(Instance.currentPage);
@@ -172,6 +194,12 @@ namespace Reset.Core.Tools{
return;
}
// Lock check
if (Locked) {
Debug.LogWarning($"Attempted to switch to a new page but the page is locked.");
return;
}
// Get the index of the current page
int currentIndex = Instance.Pages.ToList().IndexOf(Instance.currentPage);