Skip to content

Commit

Permalink
fix(Menu): fix container context in items
Browse files Browse the repository at this point in the history
  • Loading branch information
Iam1337 committed Dec 13, 2021
1 parent 2850bee commit 62a39fc
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Assets/extDebug/Scripts/Menu/DMAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected override void OnEvent(EventArgs eventArgs)

if (eventArgs.Key == EventKey.Left)
{
DM.Back();
Container.Back();
}
else if (eventArgs.Key == EventKey.Right && _action != null)
{
Expand Down
10 changes: 5 additions & 5 deletions Assets/extDebug/Scripts/Menu/DMBranch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,8 @@ protected override void OnEvent(EventArgs eventArgs)
var currentItem = Current;
if (currentItem is DMBranch)
{
if (DM.IsVisible)
DM.Back();
if (Container.IsVisible)
Container.Back();
}
else
{
Expand All @@ -264,8 +264,8 @@ protected override void OnEvent(EventArgs eventArgs)
var currentItem = Current;
if (currentItem is DMBranch currentBranch)
{
if (DM.IsVisible)
DM.Open(currentBranch);
if (Container.IsVisible)
Container.Open(currentBranch);
}
else
{
Expand All @@ -286,7 +286,7 @@ protected override void OnEvent(EventArgs eventArgs)
}
else if (eventArgs.Key == EventKey.Back)
{
DM.Back();
Container.Back();
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions Assets/extDebug/Scripts/Menu/DMBranchRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,19 @@ protected override DMItem BuildItem(DMBranch parent, T @object, string name, int
void OnOpenCallback(DMBranch branch)
{
foreach (var item in _items)
{
item.Data = branch.Data;
item.Container = branch.Container;
}
}

void OnCloseCallback(DMBranch branch)
{
foreach (var item in _items)
{
item.Data = null;
item.Container = null;
}
}

var branch = DM.Add(parent, name, GetDescription(@object), order);
Expand Down
1 change: 1 addition & 0 deletions Assets/extDebug/Scripts/Menu/DMContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public void Open(DMBranch branch)
}

_currentBranch = branch;
_currentBranch.Container = this;
_currentBranch.SendEvent(EventArgs.OpenBranch);
_currentBranch.RequestRepaint();

Expand Down
10 changes: 5 additions & 5 deletions Assets/extDebug/Scripts/Menu/DMEnum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public DMEnum(DMBranch parent, string path, Func<T> getter, Action<T> setter = n
}, i);
}

DM.Add(_flagBranch, "Back", _ => DM.Back(), string.Empty, int.MaxValue);
DM.Add(_flagBranch, "Back", a => a.Container.Back(), string.Empty, int.MaxValue);
}
}
}
Expand All @@ -82,13 +82,13 @@ protected override void OnEvent(EventArgs eventArgs)
{
if (_flagBranch != null && eventArgs.Tag == EventTag.Input && eventArgs.Key == EventKey.Left)
{
if (DM.IsVisible)
DM.Back();
if (Container.IsVisible)
Container.Back();
}
else if (_flagBranch != null && eventArgs.Tag == EventTag.Input && eventArgs.Key == EventKey.Right)
{
if (DM.IsVisible)
DM.Open(_flagBranch);
if (Container.IsVisible)
Container.Open(_flagBranch);
}
else
{
Expand Down
12 changes: 10 additions & 2 deletions Assets/extDebug/Scripts/Menu/DMItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,24 @@ public Color ValueColor

public object Data
{
get => _data ?? _parent?._data;
get => _data ?? _parent?.Data;
set => _data = value;
}

#endregion
public DMContainer Container
{
get => _container ?? _parent?.Container;
set => _container = value;
}

#endregion

#region Protected Vars

protected readonly DMBranch _parent;

protected DMContainer _container;

protected string _name;

protected Color _nameColor = DM.Colors.Name;
Expand Down
1 change: 1 addition & 0 deletions Assets/extDebug/Scripts/Menu/DMRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ internal override List<DMItem> BuildItems(DMBranch parent)
var @object = objects[i];
var @objectItem = BuildItem(parent, @object, GetName(@object), i);
@objectItem.Data = @object;
@objectItem.Container = parent.Container;

branches.Add(@objectItem);
}
Expand Down

0 comments on commit 62a39fc

Please sign in to comment.