Skip to content

Commit

Permalink
Merge pull request #3 from carmineos/feature
Browse files Browse the repository at this point in the history
Added OnMenuDynamicListItemCurrentItemChange event
  • Loading branch information
TomGrobbe authored Feb 7, 2019
2 parents fd4e60a + e6c8792 commit 65ce856
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
31 changes: 31 additions & 0 deletions MenuAPI/Menu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ public class Menu
/// <param name="sliderPosition">The current position of the slider bar.</param>
/// <param name="itemIndex">The index of this <see cref="MenuSliderItem"/>.</param>
public delegate void SliderItemSelectedEvent(Menu menu, MenuSliderItem sliderItem, int sliderPosition, int itemIndex);

/// <summary>
/// Triggered when a <see cref="MenuDynamicListItem"/>'s value was changed.
/// </summary>
/// <param name="menu">The <see cref="Menu"/> in which this <see cref="OnMenuDynamicListItemCurrentItemChange"/> event occurred.</param>
/// <param name="dynamicListItem">The <see cref="MenuDynamicListItem"/> that was changed.</param>
/// <param name="oldValue">The old <see cref="MenuDynamicListItem.CurrentItem"/> of the <see cref="MenuDynamicListItem"/>.</param>
/// <param name="newValue">The new <see cref="MenuDynamicListItem.CurrentItem"/> of the <see cref="MenuDynamicListItem"/>.</param>
public delegate void MenuDynamicListItemCurrentItemChangedEvent(Menu menu, MenuDynamicListItem dynamicListItem, string oldValue, string newValue);
#endregion

#region events
Expand Down Expand Up @@ -146,6 +155,12 @@ public class Menu
/// Parameters: <see cref="Menu"/> menu, <see cref="MenuSliderItem"/> sliderItem, <see cref="int"/> sliderPosition, <see cref="int"/> itemIndex.
/// </summary>
public event SliderItemSelectedEvent OnSliderItemSelect;

/// <summary>
/// Triggered when a <see cref="MenuDynamicListItem"/>'s value was changed.
/// Parameters: <see cref="Menu"/> menu, <see cref="MenuListItem"/> dynamicListItem, <see cref="MenuDynamicListItem.CurrentItem"/> oldValue, <see cref="MenuDynamicListItem.CurrentItem"/> newValue.
/// </summary>
public event MenuDynamicListItemCurrentItemChangedEvent OnMenuDynamicListItemCurrentItemChange;
#endregion

#region virtual voids
Expand Down Expand Up @@ -253,6 +268,18 @@ protected virtual void SliderSelectedEvent(Menu menu, MenuSliderItem sliderItem,
OnSliderItemSelect?.Invoke(menu, sliderItem, sliderPosition, itemIndex);
}

/// <summary>
/// Triggered when a <see cref="MenuDynamicListItem"/>'s value was changed.
/// </summary>
/// <param name="menu">The <see cref="Menu"/> in which this <see cref="OnMenuDynamicListItemCurrentItemChange"/> event occurred.</param>
/// <param name="dynamicListItem">The <see cref="MenuDynamicListItem"/> that was changed.</param>
/// <param name="oldValue">The old <see cref="MenuDynamicListItem.CurrentItem"/> of the <see cref="MenuDynamicListItem"/>.</param>
/// <param name="newValue">The new <see cref="MenuDynamicListItem.CurrentItem"/> of the <see cref="MenuDynamicListItem"/>.</param>
protected virtual void MenuDynamicListItemCurrentItemChanged(Menu menu, MenuDynamicListItem dynamicListItem, string oldValue, string newValue)
{
OnMenuDynamicListItemCurrentItemChange?.Invoke(menu, dynamicListItem, oldValue, newValue);
}

#endregion

#endregion
Expand Down Expand Up @@ -620,8 +647,10 @@ public void GoLeft()
}
else if (item.Enabled && item is MenuDynamicListItem dynList)
{
string oldValue = dynList.CurrentItem;
string newSelectedItem = dynList.Callback(dynList, true);
dynList.CurrentItem = newSelectedItem;
MenuDynamicListItemCurrentItemChanged(this, dynList, oldValue, newSelectedItem);
PlaySoundFrontend(-1, "NAV_LEFT_RIGHT", "HUD_FRONTEND_DEFAULT_SOUNDSET", false);
}
}
Expand Down Expand Up @@ -669,8 +698,10 @@ public void GoRight()
}
else if (item.Enabled && item is MenuDynamicListItem dynList)
{
string oldValue = dynList.CurrentItem;
string newSelectedItem = dynList.Callback(dynList, false);
dynList.CurrentItem = newSelectedItem;
MenuDynamicListItemCurrentItemChanged(this, dynList, oldValue, newSelectedItem);
PlaySoundFrontend(-1, "NAV_LEFT_RIGHT", "HUD_FRONTEND_DEFAULT_SOUNDSET", false);
}
}
Expand Down
5 changes: 5 additions & 0 deletions TestMenu/ExampleMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,11 @@ Event handlers
Debug.WriteLine($"OnMenuOpen: [{_menu}]");
};

menu.OnMenuDynamicListItemCurrentItemChange += ( _menu, _dynamicListItem, _oldCurrentItem, __newCurrentItem) =>
{
// Code in here would get executed whenever the value of the current item of a dynamic list item changes.
Debug.WriteLine($"OnMenuDynamicListItemCurrentItemChange: [{_menu}, {_dynamicListItem}, {_oldCurrentItem}, {__newCurrentItem}]");
};

}
}
Expand Down

0 comments on commit 65ce856

Please sign in to comment.