From 16685ec4610c077f61acd1d6310f0b7dbde3e12e Mon Sep 17 00:00:00 2001 From: Djoe_ <43145127+PourrezJ@users.noreply.github.com> Date: Wed, 24 Jun 2020 09:49:55 +0200 Subject: [PATCH 1/5] add Herritage menu for character creator. --- MenuAPI/HerritageMenu.cs | 26 ++++++++++++++++++++++++++ MenuAPI/Menu.cs | 22 +++++++++++++++++++++- MenuAPI/MenuController.cs | 4 +++- TestMenu/ExampleMenu.cs | 24 ++++++++++++++++++++++++ 4 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 MenuAPI/HerritageMenu.cs diff --git a/MenuAPI/HerritageMenu.cs b/MenuAPI/HerritageMenu.cs new file mode 100644 index 0000000..ef22e99 --- /dev/null +++ b/MenuAPI/HerritageMenu.cs @@ -0,0 +1,26 @@ +namespace MenuAPI +{ + public enum Dad + { + Benjamin, Daniel, Joshua, Noah, Andrew, Juan, Alex, Isaac, Evan, Ethan, Vincent, Angel, Diego, Adrian, Gabriel, Michael, Santiago, Kevin, Louis, Samuel, Anthony, Claude, Niko + } + + public enum Mum + { + Hannah, Aubrey, Jasmine, Gisele, Amelia, Isabella, Zoe, Ava, Camila, Violet, Sophia, Evelyn, Nicole, Ashley, Gracie, Brianna, Natalie, Olivia, Elizabeth, Charlotte, Emma, Misty + } + + public class HerritageMenu : MenuAPI.Menu + { + public Mum CurrentMum; + public Dad CurrentDad; + + public HerritageMenu(string name) : base(name) + { + } + + public HerritageMenu(string name, string subtitle) : base(name, subtitle) + { + } + } +} diff --git a/MenuAPI/Menu.cs b/MenuAPI/Menu.cs index fef9b34..74f6d7c 100644 --- a/MenuAPI/Menu.cs +++ b/MenuAPI/Menu.cs @@ -10,6 +10,8 @@ namespace MenuAPI { + //DrawSprite("char_creator_portraits", "female_1", x, y, width, height, 0f, 255, 255, 255, 255); + public class Menu { #region Setting up events @@ -1292,7 +1294,6 @@ internal async void Draw() } ResetScriptGfxAlign(); - MenuItemsYOffset = headerSize.Value; #endif @@ -1479,6 +1480,24 @@ internal async void Draw() #if FIVEM float bgHeight = 38f * MathUtil.Clamp(Size, 0, MaxItemsOnScreen); + if (this is HerritageMenu) + { + HerritageMenu menu = this as HerritageMenu; + float htexheight = 300f; + + float hx = (Position.Key + (headerSize.Key / 2f)) / MenuController.ScreenWidth; + float hy = ((Position.Value + MenuItemsYOffset + ((htexheight - 75f) / 2f) + ((bgHeight + 1f) / 2f)) / MenuController.ScreenHeight); + float hwidth = headerSize.Key / MenuController.ScreenWidth; + float hheight = (bgHeight + (htexheight / 2)) / MenuController.ScreenHeight; + + DrawSprite("pause_menu_pages_char_mom_dad", "mumdadbg", hx, hy, hwidth, hheight, 0f, 255, 255, 255, 255); + + DrawSprite("char_creator_portraits", ((int)menu.CurrentDad < 21) ? $"male_{(int)menu.CurrentDad}" : $"special_male_{(int)(menu.CurrentDad - 21)}", (hx * 1.3f), hy, hwidth / 2, hheight, 0f, 255, 255, 255, 255); + DrawSprite("char_creator_portraits", ((int)menu.CurrentMum < 21) ? $"female_{(int)menu.CurrentMum}" : $"special_female_{(int)(menu.CurrentMum - 21)}", (hx / 1.8f), hy, hwidth / 2, hheight, 0f, 255, 255, 255, 255); + + MenuItemsYOffset += htexheight; + } + float x = (Position.Key + (headerSize.Key / 2f)) / MenuController.ScreenWidth; float y = ((Position.Value + MenuItemsYOffset + ((bgHeight + 1f) / 2f)) / MenuController.ScreenHeight); float width = headerSize.Key / MenuController.ScreenWidth; @@ -1487,6 +1506,7 @@ internal async void Draw() DrawRect(x, y, width, height, 0, 0, 0, 180); MenuItemsYOffset += bgHeight - 1f; ResetScriptGfxAlign(); + #endif #if REDM //float x = (Position.Key + ((headerSize.Key) / 2f)) / MenuController.ScreenWidth; diff --git a/MenuAPI/MenuController.cs b/MenuAPI/MenuController.cs index 87495c0..7e6b728 100644 --- a/MenuAPI/MenuController.cs +++ b/MenuAPI/MenuController.cs @@ -33,7 +33,9 @@ public class MenuController : BaseScript "mprankbadge", "mpcarhud", "mpcarhud2", - "shared" + "shared", + "char_creator_portraits", + "pause_menu_pages_char_mom_dad" #endif #if REDM "menu_textures", diff --git a/TestMenu/ExampleMenu.cs b/TestMenu/ExampleMenu.cs index d18b782..07c6644 100644 --- a/TestMenu/ExampleMenu.cs +++ b/TestMenu/ExampleMenu.cs @@ -149,6 +149,30 @@ string ChangeCallback(MenuDynamicListItem item, bool left) menu.AddMenuItem(menuButton); MenuController.BindMenuItem(menu, submenu, menuButton); +#if FIVEM + var herritageMenu = new HerritageMenu("Herritage"); + herritageMenu.AddMenuItem(new MenuListItem("Father", ((Dad[])Enum.GetValues(typeof(Dad))).Select(c => c.ToString()).ToList(), 0, "Choose the father of your character.")); + herritageMenu.AddMenuItem(new MenuListItem("Mother", ((Mum[])Enum.GetValues(typeof(Mum))).Select(c => c.ToString()).ToList(), 0, "Choose the mother of your character.")); + + menu.OnListIndexChange += (_menu, _listItem, _oldIndex, _newIndex, _itemIndex) => + { + if (_listItem.Text == "Father") + { + (menu as HerritageMenu).CurrentDad = ((Dad)_itemIndex); + } + else if (_listItem.Text == "Mother") + { + (menu as HerritageMenu).CurrentMum = ((Mum)_itemIndex); + } + }; + + var bindmenu = new MenuItem("Héritage"); + menu.AddMenuItem(bindmenu); + + MenuController.BindMenuItem(menu, herritageMenu, bindmenu); +#endif + + // Adding items with sprites left & right to the submenu. for (var i = 0; i < Enum.GetValues(typeof(MenuItem.Icon)).Length; i++) { From 96cc0c66cd0914aa68815b019904be9b7ebb07f0 Mon Sep 17 00:00:00 2001 From: Djoe_ <43145127+PourrezJ@users.noreply.github.com> Date: Wed, 24 Jun 2020 09:52:30 +0200 Subject: [PATCH 2/5] Remove reminder --- MenuAPI/Menu.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/MenuAPI/Menu.cs b/MenuAPI/Menu.cs index 74f6d7c..342bf4d 100644 --- a/MenuAPI/Menu.cs +++ b/MenuAPI/Menu.cs @@ -10,8 +10,6 @@ namespace MenuAPI { - //DrawSprite("char_creator_portraits", "female_1", x, y, width, height, 0f, 255, 255, 255, 255); - public class Menu { #region Setting up events From d27b1495df3e8c1b64345c0f4bec231695a917ba Mon Sep 17 00:00:00 2001 From: Djoe_ <43145127+PourrezJ@users.noreply.github.com> Date: Wed, 24 Jun 2020 18:30:22 +0200 Subject: [PATCH 3/5] Fix calcul position. --- MenuAPI/Menu.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/MenuAPI/Menu.cs b/MenuAPI/Menu.cs index 342bf4d..4ea5740 100644 --- a/MenuAPI/Menu.cs +++ b/MenuAPI/Menu.cs @@ -1321,13 +1321,13 @@ internal async void Draw() #endregion #region Draw Subtitle + float bgHeight = 38f; { #if FIVEM #region draw subtitle background SetScriptGfxAlign(LeftAligned ? 76 : 82, 84); SetScriptGfxAlignParams(0f, 0f, 0f, 0f); - float bgHeight = 38f; float x = (Position.Key + (headerSize.Key / 2f)) / MenuController.ScreenWidth; float y = ((Position.Value + MenuItemsYOffset + (bgHeight / 2f)) / MenuController.ScreenHeight); @@ -1476,30 +1476,30 @@ internal async void Draw() //DrawSprite(MenuController._texture_dict, "gradient_bgd", x, y, width, height, 0f, 255, 255, 255, 255); #if FIVEM - float bgHeight = 38f * MathUtil.Clamp(Size, 0, MaxItemsOnScreen); if (this is HerritageMenu) { HerritageMenu menu = this as HerritageMenu; - float htexheight = 300f; + float htexheight = 25f * MathUtil.Clamp(Size, 0, MaxItemsOnScreen); float hx = (Position.Key + (headerSize.Key / 2f)) / MenuController.ScreenWidth; - float hy = ((Position.Value + MenuItemsYOffset + ((htexheight - 75f) / 2f) + ((bgHeight + 1f) / 2f)) / MenuController.ScreenHeight); + float hy = ((Position.Value + MenuItemsYOffset + ((htexheight + 1f) / 2f)) / MenuController.ScreenHeight); float hwidth = headerSize.Key / MenuController.ScreenWidth; - float hheight = (bgHeight + (htexheight / 2)) / MenuController.ScreenHeight; + float hheight = (htexheight + 1f) / MenuController.ScreenHeight; DrawSprite("pause_menu_pages_char_mom_dad", "mumdadbg", hx, hy, hwidth, hheight, 0f, 255, 255, 255, 255); - DrawSprite("char_creator_portraits", ((int)menu.CurrentDad < 21) ? $"male_{(int)menu.CurrentDad}" : $"special_male_{(int)(menu.CurrentDad - 21)}", (hx * 1.3f), hy, hwidth / 2, hheight, 0f, 255, 255, 255, 255); DrawSprite("char_creator_portraits", ((int)menu.CurrentMum < 21) ? $"female_{(int)menu.CurrentMum}" : $"special_female_{(int)(menu.CurrentMum - 21)}", (hx / 1.8f), hy, hwidth / 2, hheight, 0f, 255, 255, 255, 255); - MenuItemsYOffset += htexheight; + MenuItemsYOffset += htexheight - 1f; } + bgHeight = 38f * MathUtil.Clamp(Size, 0, MaxItemsOnScreen); + float x = (Position.Key + (headerSize.Key / 2f)) / MenuController.ScreenWidth; float y = ((Position.Value + MenuItemsYOffset + ((bgHeight + 1f) / 2f)) / MenuController.ScreenHeight); float width = headerSize.Key / MenuController.ScreenWidth; - float height = (bgHeight + 1f) / MenuController.ScreenHeight; + float height = bgHeight / MenuController.ScreenHeight; DrawRect(x, y, width, height, 0, 0, 0, 180); MenuItemsYOffset += bgHeight - 1f; From fd60d5c357388fabd9e571ec17377aad2f07cd77 Mon Sep 17 00:00:00 2001 From: Djoe_ <43145127+PourrezJ@users.noreply.github.com> Date: Wed, 24 Jun 2020 18:36:04 +0200 Subject: [PATCH 4/5] Mistakenly withdraw an float value adjustment --- MenuAPI/Menu.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MenuAPI/Menu.cs b/MenuAPI/Menu.cs index 4ea5740..443961f 100644 --- a/MenuAPI/Menu.cs +++ b/MenuAPI/Menu.cs @@ -1499,7 +1499,7 @@ internal async void Draw() float x = (Position.Key + (headerSize.Key / 2f)) / MenuController.ScreenWidth; float y = ((Position.Value + MenuItemsYOffset + ((bgHeight + 1f) / 2f)) / MenuController.ScreenHeight); float width = headerSize.Key / MenuController.ScreenWidth; - float height = bgHeight / MenuController.ScreenHeight; + float height = (bgHeight + 1f) / MenuController.ScreenHeight; DrawRect(x, y, width, height, 0, 0, 0, 180); MenuItemsYOffset += bgHeight - 1f; From 6f4f1bd9aaab1b7edcf569cd4639e6e7900095a3 Mon Sep 17 00:00:00 2001 From: Djoe_ <43145127+PourrezJ@users.noreply.github.com> Date: Wed, 24 Jun 2020 18:50:11 +0200 Subject: [PATCH 5/5] Fix another one of my mistakes. --- MenuAPI/Menu.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MenuAPI/Menu.cs b/MenuAPI/Menu.cs index 443961f..231ae3b 100644 --- a/MenuAPI/Menu.cs +++ b/MenuAPI/Menu.cs @@ -1480,7 +1480,7 @@ internal async void Draw() if (this is HerritageMenu) { HerritageMenu menu = this as HerritageMenu; - float htexheight = 25f * MathUtil.Clamp(Size, 0, MaxItemsOnScreen); + float htexheight = 250f; float hx = (Position.Key + (headerSize.Key / 2f)) / MenuController.ScreenWidth; float hy = ((Position.Value + MenuItemsYOffset + ((htexheight + 1f) / 2f)) / MenuController.ScreenHeight);