ui基本完毕,修了一大把的bug
This commit is contained in:
@@ -23,8 +23,10 @@ public class btmandtopController : MonoBehaviour, ICancelHandler
|
||||
public Text playerCoins_legacy;
|
||||
public Text player_mmrFragment;
|
||||
public Text player_rks;
|
||||
public Image rksProgressImage;
|
||||
[Header("put prefabs here")]
|
||||
public GameObject putPrefabsHere;
|
||||
public GameObject putSettingsPrefabHere;
|
||||
[Header("son buttons")]
|
||||
public Button settings_launch;
|
||||
public Button userInfo_launch;
|
||||
@@ -154,7 +156,9 @@ public class btmandtopController : MonoBehaviour, ICancelHandler
|
||||
PlayerRksService.OnRksChanged += HandleRksChanged;
|
||||
UpdatePlayerCoinsLegacyText(PlayerEconomyLedger.EnsureInstance().GetCoins());
|
||||
UpdatePlayerMmrFragmentText(PlayerEconomyLedger.EnsureInstance().GetMaterial());
|
||||
UpdatePlayerRksText(PlayerRksService.GetBestOverallRks(player_SO));
|
||||
float currentRks = PlayerRksService.GetBestOverallRks(player_SO);
|
||||
UpdatePlayerRksText(currentRks);
|
||||
UpdateRksProgressImage(currentRks);
|
||||
|
||||
if (button_Music == null)
|
||||
{
|
||||
@@ -223,7 +227,7 @@ public class btmandtopController : MonoBehaviour, ICancelHandler
|
||||
}
|
||||
|
||||
// Pre-instantiate settings prefab and keep it inactive, ensuring only one exists
|
||||
if (settings_prefab != null && putPrefabsHere != null)
|
||||
if (settings_prefab != null && GetSettingsParentTransform() != null)
|
||||
{
|
||||
// Try to find existing one in scene first
|
||||
if (settingsInstance == null)
|
||||
@@ -237,7 +241,8 @@ public class btmandtopController : MonoBehaviour, ICancelHandler
|
||||
|
||||
if (settingsInstance == null)
|
||||
{
|
||||
settingsInstance = Instantiate(settings_prefab, putPrefabsHere.transform);
|
||||
settingsInstance = Instantiate(settings_prefab, GetSettingsParentTransform());
|
||||
AttachManagedPanelVisibilityRelay(settingsInstance, true);
|
||||
EnsureSettingsEnterAnimator(settingsInstance);
|
||||
EnsureSettingsLastSibling();
|
||||
settingsInstance.SetActive(false);
|
||||
@@ -261,8 +266,9 @@ public class btmandtopController : MonoBehaviour, ICancelHandler
|
||||
}
|
||||
else
|
||||
{
|
||||
// ensure it's parented correctly under putPrefabsHere
|
||||
settingsInstance.transform.SetParent(putPrefabsHere.transform, false);
|
||||
// ensure it's parented correctly beside putPrefabsHere
|
||||
settingsInstance.transform.SetParent(GetSettingsParentTransform(), false);
|
||||
AttachManagedPanelVisibilityRelay(settingsInstance, true);
|
||||
EnsureSettingsLastSibling();
|
||||
EnsureSettingsEnterAnimator(settingsInstance);
|
||||
settingsInstance.SetActive(false);
|
||||
@@ -283,60 +289,106 @@ public class btmandtopController : MonoBehaviour, ICancelHandler
|
||||
if (userInfoInstance == null)
|
||||
{
|
||||
userInfoInstance = Instantiate(userInfo_prefab, putPrefabsHere.transform);
|
||||
AttachManagedPanelVisibilityRelay(userInfoInstance, false);
|
||||
userInfoInstance.SetActive(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
userInfoInstance.transform.SetParent(putPrefabsHere.transform, false);
|
||||
AttachManagedPanelVisibilityRelay(userInfoInstance, false);
|
||||
userInfoInstance.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
lastSettingsVisibilityState = IsSettingsPanelVisible;
|
||||
lastOverlayPanelsVisibilityState = AreOverlayPanelsVisible();
|
||||
CurrentOverlayPanelsVisible = lastOverlayPanelsVisibilityState;
|
||||
SyncManagedPanelVisibilityState(true);
|
||||
}
|
||||
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if(Input.GetKeyDown(KeyCode.Escape))
|
||||
{
|
||||
//ToggleSettingsPrefab();
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
private void OnTransformChildrenChanged()
|
||||
{
|
||||
if (!IsUiUiSceneActive())
|
||||
{
|
||||
if (CurrentSettingsVisible)
|
||||
{
|
||||
BroadcastSettingsVisibility(false);
|
||||
}
|
||||
if (CurrentOverlayPanelsVisible)
|
||||
{
|
||||
lastOverlayPanelsVisibilityState = false;
|
||||
CurrentOverlayPanelsVisible = false;
|
||||
GlobalOverlayPanelVisibilityChanged?.Invoke(false);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
bool visible = IsSettingsPanelVisible;
|
||||
if (visible != lastSettingsVisibilityState)
|
||||
topNavigationGeometryDirty = true;
|
||||
EnsureTopNavigationFront();
|
||||
}
|
||||
|
||||
internal void NotifyManagedPanelVisibilityChanged(bool includesSettingsPanel)
|
||||
{
|
||||
if (!ReferenceEquals(activeInstance, this))
|
||||
{
|
||||
BroadcastSettingsVisibility(visible);
|
||||
return;
|
||||
}
|
||||
|
||||
bool overlayVisible = AreOverlayPanelsVisible();
|
||||
if (overlayVisible != lastOverlayPanelsVisibilityState)
|
||||
if (!IsUiUiSceneActive())
|
||||
{
|
||||
lastOverlayPanelsVisibilityState = overlayVisible;
|
||||
CurrentOverlayPanelsVisible = overlayVisible;
|
||||
GlobalOverlayPanelVisibilityChanged?.Invoke(overlayVisible);
|
||||
SetSettingsVisibilityState(false);
|
||||
SetOverlayPanelsVisibilityState(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (includesSettingsPanel)
|
||||
{
|
||||
SetSettingsVisibilityState(IsSettingsPanelVisible);
|
||||
}
|
||||
|
||||
SetOverlayPanelsVisibilityState(AreOverlayPanelsVisible());
|
||||
}
|
||||
|
||||
private void SyncManagedPanelVisibilityState(bool forceNotify)
|
||||
{
|
||||
if (!IsUiUiSceneActive())
|
||||
{
|
||||
SetSettingsVisibilityState(false, forceNotify);
|
||||
SetOverlayPanelsVisibilityState(false, forceNotify);
|
||||
return;
|
||||
}
|
||||
|
||||
SetSettingsVisibilityState(IsSettingsPanelVisible, forceNotify);
|
||||
SetOverlayPanelsVisibilityState(AreOverlayPanelsVisible(), forceNotify);
|
||||
}
|
||||
|
||||
private void AttachManagedPanelVisibilityRelay(GameObject panel, bool includesSettingsPanel)
|
||||
{
|
||||
if (panel == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
btmandtopPanelVisibilityRelay relay = panel.GetComponent<btmandtopPanelVisibilityRelay>();
|
||||
if (relay == null)
|
||||
{
|
||||
relay = panel.AddComponent<btmandtopPanelVisibilityRelay>();
|
||||
}
|
||||
|
||||
relay.Initialize(this, includesSettingsPanel);
|
||||
}
|
||||
|
||||
private void SetSettingsVisibilityState(bool visible, bool forceNotify = false)
|
||||
{
|
||||
lastSettingsVisibilityState = visible;
|
||||
if (!forceNotify && CurrentSettingsVisible == visible)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
CurrentSettingsVisible = visible;
|
||||
SettingsVisibilityChanged?.Invoke(visible);
|
||||
GlobalSettingsVisibilityChanged?.Invoke(visible);
|
||||
}
|
||||
|
||||
private void SetOverlayPanelsVisibilityState(bool visible, bool forceNotify = false)
|
||||
{
|
||||
lastOverlayPanelsVisibilityState = visible;
|
||||
if (!forceNotify && CurrentOverlayPanelsVisible == visible)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
CurrentOverlayPanelsVisible = visible;
|
||||
GlobalOverlayPanelVisibilityChanged?.Invoke(visible);
|
||||
topNavigationGeometryDirty = true;
|
||||
EnsureTopNavigationFront();
|
||||
}
|
||||
|
||||
@@ -554,6 +606,7 @@ public class btmandtopController : MonoBehaviour, ICancelHandler
|
||||
private void HandleRksChanged(float rksAmount)
|
||||
{
|
||||
UpdatePlayerRksText(rksAmount);
|
||||
UpdateRksProgressImage(rksAmount);
|
||||
}
|
||||
|
||||
private void InitializeMailRedPot()
|
||||
@@ -644,6 +697,16 @@ public class btmandtopController : MonoBehaviour, ICancelHandler
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateRksProgressImage(float rksAmount)
|
||||
{
|
||||
if (rksProgressImage == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
rksProgressImage.fillAmount = Mathf.Clamp01(Mathf.InverseLerp(0f, 100f, rksAmount));
|
||||
}
|
||||
|
||||
private Text FindLegacyTextByLiteral(string literal)
|
||||
{
|
||||
if (string.IsNullOrEmpty(literal))
|
||||
@@ -802,12 +865,13 @@ public class btmandtopController : MonoBehaviour, ICancelHandler
|
||||
|
||||
private void ToggleSettingsPrefab()
|
||||
{
|
||||
if (settings_prefab == null || putPrefabsHere == null) return;
|
||||
if (settings_prefab == null || GetSettingsParentTransform() == null) return;
|
||||
|
||||
// If we don't have an instance (it may have been destroyed), instantiate one
|
||||
if (settingsInstance == null)
|
||||
{
|
||||
settingsInstance = Instantiate(settings_prefab, putPrefabsHere.transform);
|
||||
settingsInstance = Instantiate(settings_prefab, GetSettingsParentTransform());
|
||||
AttachManagedPanelVisibilityRelay(settingsInstance, true);
|
||||
EnsureSettingsEnterAnimator(settingsInstance);
|
||||
EnsureSettingsLastSibling();
|
||||
|
||||
@@ -830,22 +894,20 @@ public class btmandtopController : MonoBehaviour, ICancelHandler
|
||||
|
||||
settingsInstance.SetActive(true);
|
||||
EnsureSettingsLastSibling();
|
||||
BroadcastSettingsVisibility(true);
|
||||
BroadcastOverlayPanelsVisibility();
|
||||
RegisterManagedPanel(settingsInstance, () =>
|
||||
{
|
||||
if (settingsInstance != null)
|
||||
{
|
||||
settingsInstance.SetActive(false);
|
||||
BroadcastSettingsVisibility(false);
|
||||
BroadcastOverlayPanelsVisibility();
|
||||
}
|
||||
});
|
||||
NotifyManagedPanelVisibilityChanged(true);
|
||||
return;
|
||||
}
|
||||
|
||||
AttachManagedPanelVisibilityRelay(settingsInstance, true);
|
||||
EnsureSettingsEnterAnimator(settingsInstance);
|
||||
settingsInstance.transform.SetParent(putPrefabsHere.transform, false);
|
||||
settingsInstance.transform.SetParent(GetSettingsParentTransform(), false);
|
||||
EnsureSettingsLastSibling();
|
||||
|
||||
// Toggle active state
|
||||
@@ -859,13 +921,10 @@ public class btmandtopController : MonoBehaviour, ICancelHandler
|
||||
if (settingsInstance != null)
|
||||
{
|
||||
settingsInstance.SetActive(false);
|
||||
BroadcastSettingsVisibility(false);
|
||||
BroadcastOverlayPanelsVisibility();
|
||||
}
|
||||
});
|
||||
}
|
||||
BroadcastSettingsVisibility(settingsInstance.activeSelf);
|
||||
BroadcastOverlayPanelsVisibility();
|
||||
NotifyManagedPanelVisibilityChanged(true);
|
||||
}
|
||||
|
||||
public bool IsSettingsPanelVisible
|
||||
@@ -889,16 +948,7 @@ public class btmandtopController : MonoBehaviour, ICancelHandler
|
||||
|
||||
private void BroadcastSettingsVisibility(bool visible)
|
||||
{
|
||||
lastSettingsVisibilityState = visible;
|
||||
if (CurrentSettingsVisible == visible)
|
||||
{
|
||||
SettingsVisibilityChanged?.Invoke(visible);
|
||||
return;
|
||||
}
|
||||
|
||||
CurrentSettingsVisible = visible;
|
||||
SettingsVisibilityChanged?.Invoke(visible);
|
||||
GlobalSettingsVisibilityChanged?.Invoke(visible);
|
||||
SetSettingsVisibilityState(visible);
|
||||
}
|
||||
|
||||
private bool IsUiUiSceneActive()
|
||||
@@ -921,12 +971,7 @@ public class btmandtopController : MonoBehaviour, ICancelHandler
|
||||
|
||||
private void BroadcastOverlayPanelsVisibility()
|
||||
{
|
||||
bool visible = AreOverlayPanelsVisible();
|
||||
lastOverlayPanelsVisibilityState = visible;
|
||||
CurrentOverlayPanelsVisible = visible;
|
||||
GlobalOverlayPanelVisibilityChanged?.Invoke(visible);
|
||||
topNavigationGeometryDirty = true;
|
||||
EnsureTopNavigationFront();
|
||||
SetOverlayPanelsVisibilityState(AreOverlayPanelsVisible());
|
||||
}
|
||||
|
||||
private void RegisterManagedPanel(GameObject panel, System.Action closeAction)
|
||||
@@ -1071,6 +1116,7 @@ public class btmandtopController : MonoBehaviour, ICancelHandler
|
||||
instance.SetActive(true);
|
||||
}
|
||||
|
||||
AttachManagedPanelVisibilityRelay(instance, false);
|
||||
TryAssignCanvasCamera(instance);
|
||||
BroadcastOverlayPanelsVisibility();
|
||||
EnsureTopNavigationFront();
|
||||
@@ -1079,15 +1125,31 @@ public class btmandtopController : MonoBehaviour, ICancelHandler
|
||||
|
||||
private void EnsureSettingsLastSibling()
|
||||
{
|
||||
if (settingsInstance == null || putPrefabsHere == null)
|
||||
if (settingsInstance == null || GetSettingsParentTransform() == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
settingsInstance.transform.SetParent(putPrefabsHere.transform, false);
|
||||
settingsInstance.transform.SetParent(GetSettingsParentTransform(), false);
|
||||
settingsInstance.transform.SetAsLastSibling();
|
||||
}
|
||||
|
||||
private Transform GetSettingsParentTransform()
|
||||
{
|
||||
if (putSettingsPrefabHere != null)
|
||||
{
|
||||
return putSettingsPrefabHere.transform;
|
||||
}
|
||||
|
||||
if (putPrefabsHere == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
Transform siblingParent = putPrefabsHere.transform.parent;
|
||||
return siblingParent != null ? siblingParent : putPrefabsHere.transform;
|
||||
}
|
||||
|
||||
private void CloseInfoPanels(GameObject keep)
|
||||
{
|
||||
CloseInstance(ref userInfoInstance, keep);
|
||||
@@ -1147,7 +1209,7 @@ public class btmandtopController : MonoBehaviour, ICancelHandler
|
||||
{
|
||||
if (activeInstance != null)
|
||||
{
|
||||
activeInstance.BroadcastOverlayPanelsVisibility();
|
||||
activeInstance.SyncManagedPanelVisibilityState(false);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1387,6 +1449,7 @@ public class btmandtopController : MonoBehaviour, ICancelHandler
|
||||
{
|
||||
activeInstance.topNavigationGeometryDirty = true;
|
||||
activeInstance.EnsureTopNavigationFront();
|
||||
activeInstance.SyncManagedPanelVisibilityState(true);
|
||||
activeInstance.ScheduleDeferredUiRefresh();
|
||||
}
|
||||
}
|
||||
@@ -1587,3 +1650,31 @@ public class btmandtopController : MonoBehaviour, ICancelHandler
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class btmandtopPanelVisibilityRelay : MonoBehaviour
|
||||
{
|
||||
private btmandtopController owner;
|
||||
private bool includesSettingsPanel;
|
||||
|
||||
public void Initialize(btmandtopController controller, bool isSettingsPanel)
|
||||
{
|
||||
owner = controller;
|
||||
includesSettingsPanel = isSettingsPanel;
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
if (owner != null)
|
||||
{
|
||||
owner.NotifyManagedPanelVisibilityChanged(includesSettingsPanel);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
if (owner != null)
|
||||
{
|
||||
owner.NotifyManagedPanelVisibilityChanged(includesSettingsPanel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user