Skip to content

Commit

Permalink
gear window fix, tabview scroll step
Browse files Browse the repository at this point in the history
  • Loading branch information
shnok committed Aug 16, 2024
1 parent 66f3b2f commit 46171ec
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 14 deletions.
1 change: 1 addition & 0 deletions l2-unity/Assets/Scripts/UI/Game/Chat/ChatTab.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public override void Initialize(VisualElement chatWindowEle, VisualElement tabCo
base.Initialize(chatWindowEle, tabContainer, tabHeader);
_content = tabContainer.Q<Label>("Content");
_content.text = "";
_scrollStepSize = 12f;
}

protected override void OnGeometryChanged() {
Expand Down
18 changes: 9 additions & 9 deletions l2-unity/Assets/Scripts/UI/Game/Inventory/InventorySlot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ public void ClearSlot() {
_tooltipManipulator = null;
}

if(_slotDragManipulator != null) {
_slotElement.RemoveManipulator(_slotDragManipulator);
_slotDragManipulator = null;
}

if(_slotClickSoundManipulator != null) {
_slotElement.RemoveManipulator(_slotClickSoundManipulator);
_slotClickSoundManipulator = null;
}
// if(_slotDragManipulator != null) {
// _slotElement.RemoveManipulator(_slotDragManipulator);
// _slotDragManipulator = null;
// }

// if(_slotClickSoundManipulator != null) {
// _slotElement.RemoveManipulator(_slotClickSoundManipulator);
// _slotClickSoundManipulator = null;
// }
}

protected override void HandleLeftClick() {
Expand Down
2 changes: 1 addition & 1 deletion l2-unity/Assets/Scripts/UI/Game/Inventory/InventoryTab.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public override void Initialize(VisualElement chatWindowEle, VisualElement tabCo
_selectedSlot = -1;
_contentContainer = tabContainer.Q<VisualElement>("Content");
}

public IEnumerator UpdateItemList(List<ItemInstance> items) {
// Clear slots
if(_inventorySlots != null) {
Expand Down
6 changes: 3 additions & 3 deletions l2-unity/Assets/Scripts/UI/L2GameUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ protected override void LoadUI() {
// SKillbar needs updates
//ShortCutPanelMinimal.Instance.AddWindow(rootVisualContainer);
//ShortCutPanel.Instance.AddWindow(rootVisualContainer);
if (ChatWindow.Instance != null) {
ChatWindow.Instance.AddWindow(_rootVisualContainer);
}
if (MenuWindow.Instance != null) {
MenuWindow.Instance.AddWindow(_rootVisualContainer);
}
Expand All @@ -64,9 +67,6 @@ protected override void LoadUI() {
// if (SkillLearn.Instance != null) {
// SkillLearn.Instance.AddWindow(_rootVisualContainer);
// }
if (ChatWindow.Instance != null) {
ChatWindow.Instance.AddWindow(_rootVisualContainer);
}
if (TargetWindow.Instance != null) {
TargetWindow.Instance.AddWindow(_rootVisualContainer);
}
Expand Down
29 changes: 28 additions & 1 deletion l2-unity/Assets/Scripts/UI/L2Tab.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
public abstract class L2Tab {
[SerializeField] string _tabName = "Tab";
[SerializeField] protected bool _autoscroll = true;
private ScrollView _scrollView;
protected ScrollView _scrollView;
protected Scroller _scroller;
private VisualElement _tabContainer;
private VisualElement _tabHeader;
Expand All @@ -14,6 +14,7 @@ public abstract class L2Tab {
public VisualElement TabContainer { get { return _tabContainer; } }
public VisualElement TabHeader { get { return _tabHeader; } }
public Scroller Scroller { get { return _scroller; } }
protected float _scrollStepSize = 32f;

public virtual void Initialize(VisualElement chatWindowEle, VisualElement tabContainer, VisualElement tabHeader) {
_windowEle = chatWindowEle;
Expand All @@ -35,6 +36,20 @@ public virtual void Initialize(VisualElement chatWindowEle, VisualElement tabCon
}
}

protected void AdjustScrollValue(int direction) {
if (_scrollView == null || _scroller == null) return;

float contentHeight = _scrollView.contentContainer.worldBound.height;
float viewportHeight = _scrollView.worldBound.height;

if (contentHeight <= viewportHeight) return; // No need to scroll if content fits in viewport

float scrollRange = contentHeight - viewportHeight;
float stepSize = _scrollStepSize / scrollRange;
float newValue = direction * (_scroller.value + stepSize) * _scroller.highValue;
_scroller.value = Mathf.Clamp(newValue, 0, _scroller.highValue);
}

protected virtual void OnSwitchTab() { }

protected virtual void RegisterAutoScrollEvent() { }
Expand All @@ -45,23 +60,35 @@ private void RegisterPlayerScrollEvent() {
var dragger = _scroller.Q<VisualElement>("unity-drag-container");

highBtn.RegisterCallback<MouseUpEvent>(evt => {
AdjustScrollValue(1);
VerifyScrollValue();
});
lowBtn.RegisterCallback<MouseUpEvent>(evt => {
AdjustScrollValue(-1);
VerifyScrollValue();
});

highBtn.AddManipulator(new ButtonClickSoundManipulator(highBtn));
lowBtn.AddManipulator(new ButtonClickSoundManipulator(lowBtn));

dragger.RegisterCallback<MouseUpEvent>(evt => {
VerifyScrollValue();
});

dragger.RegisterCallback<WheelEvent>(evt => {
VerifyScrollValue();
});

_windowEle.RegisterCallback<GeometryChangedEvent>(evt => {
OnGeometryChanged();
});

_scrollView.RegisterCallback<WheelEvent>(evt => {
int direction = evt.delta.y > 0 ? 1 : -1;
AdjustScrollValue(direction);
VerifyScrollValue();
evt.StopPropagation();
});
}

protected virtual void OnGeometryChanged() { }
Expand Down

0 comments on commit 46171ec

Please sign in to comment.