Commit 29de43a8 authored by ElderLich's avatar ElderLich

Fix Bug: Duel Selection Popup Scroll Jumps to Bottom on Mouse Wheel

In duel option popups like Declare Type, mouse-wheel scrolling jumped near the bottom instead of smooth incremental movement due to an overly high ScrollRect sensitivity (1000) in PopupDuelSelection. Lowering sensitivity fixed wheel scrolling, and additional navigation safeguards were added so keyboard/controller focus stays on list items instead of jumping to the scrollbar.
parent 79e0bff4
...@@ -384,7 +384,7 @@ MonoBehaviour: ...@@ -384,7 +384,7 @@ MonoBehaviour:
m_Elasticity: 0.1 m_Elasticity: 0.1
m_Inertia: 1 m_Inertia: 1
m_DecelerationRate: 0.135 m_DecelerationRate: 0.135
m_ScrollSensitivity: 1000 m_ScrollSensitivity: 10
m_Viewport: {fileID: 277287946404074816} m_Viewport: {fileID: 277287946404074816}
m_HorizontalScrollbar: {fileID: 0} m_HorizontalScrollbar: {fileID: 0}
m_VerticalScrollbar: {fileID: 277287947542810653} m_VerticalScrollbar: {fileID: 277287947542810653}
......
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI; using UnityEngine.UI;
namespace MDPro3.UI namespace MDPro3.UI
...@@ -17,13 +18,17 @@ namespace MDPro3.UI ...@@ -17,13 +18,17 @@ namespace MDPro3.UI
{ {
base.InitializeSelections(); base.InitializeSelections();
Program.instance.currentServant.returnAction = null; Program.instance.currentServant.returnAction = null;
var selectionButtons = new List<Button>();
for (int i = 1; i < selections.Count; i++) for (int i = 1; i < selections.Count; i++)
{ {
GameObject newSelection = Instantiate(item); GameObject newSelection = Instantiate(item);
newSelection.transform.SetParent(scrollRect.content, false); newSelection.transform.SetParent(scrollRect.content, false);
newSelection.transform.GetChild(0).GetChild(0).GetComponent<Text>().text = selections[i]; newSelection.transform.GetChild(0).GetChild(0).GetComponent<Text>().text = selections[i];
newSelection.transform.GetChild(0).name = responses[i - 1].ToString(); var buttonTransform = newSelection.transform.GetChild(0);
newSelection.transform.GetChild(0).GetComponent<Button>().onClick.AddListener(() => buttonTransform.name = responses[i - 1].ToString();
var button = buttonTransform.GetComponent<Button>();
button.onClick.AddListener(() =>
{ {
string selected = UnityEngine.EventSystems.EventSystem.current. string selected = UnityEngine.EventSystems.EventSystem.current.
currentSelectedGameObject.name; currentSelectedGameObject.name;
...@@ -35,14 +40,39 @@ namespace MDPro3.UI ...@@ -35,14 +40,39 @@ namespace MDPro3.UI
} }
Hide(); Hide();
}); });
selectionButtons.Add(button);
newSelection.GetComponent<RectTransform>().anchoredPosition = new Vector2(0, -20 - 90 * (i - 1)); newSelection.GetComponent<RectTransform>().anchoredPosition = new Vector2(0, -20 - 90 * (i - 1));
} }
for (int i = 0; i < selectionButtons.Count; i++)
{
var button = selectionButtons[i];
var navigation = button.navigation;
navigation.mode = Navigation.Mode.Explicit;
navigation.selectOnUp = selectionButtons[Mathf.Max(0, i - 1)];
navigation.selectOnDown = selectionButtons[Mathf.Min(selectionButtons.Count - 1, i + 1)];
navigation.selectOnLeft = button;
navigation.selectOnRight = button;
button.navigation = navigation;
}
if (scrollRect.verticalScrollbar != null)
{
var scrollbarNavigation = scrollRect.verticalScrollbar.navigation;
scrollbarNavigation.mode = Navigation.Mode.None;
scrollRect.verticalScrollbar.navigation = scrollbarNavigation;
}
scrollRect.content.sizeDelta = new Vector2(scrollRect.content.sizeDelta.x, 25 + (selections.Count - 1) * 90); scrollRect.content.sizeDelta = new Vector2(scrollRect.content.sizeDelta.x, 25 + (selections.Count - 1) * 90);
baseRect.sizeDelta = new Vector2(baseRect.sizeDelta.x, baseRect.sizeDelta = new Vector2(baseRect.sizeDelta.x,
scrollRect.content.sizeDelta.y + 50 > 800 ? scrollRect.content.sizeDelta.y + 50 > 800 ?
800 : 800 :
scrollRect.content.sizeDelta.y + 50 scrollRect.content.sizeDelta.y + 50
); );
scrollRect.verticalNormalizedPosition = 1f;
if (selectionButtons.Count > 0)
EventSystem.current.SetSelectedGameObject(selectionButtons[0].gameObject);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment