From 23163bd2a484338bb4fde968a2c250aceff3eb6b Mon Sep 17 00:00:00 2001 From: Ardent <61157993+ArdentLeKhey@users.noreply.github.com> Date: Thu, 27 Oct 2022 16:36:55 +0200 Subject: [PATCH 1/7] Update New items : - AutoList : List with auto-stock of Items, auto gestion of Index and callback SetIndex to set Index - Range : AutoList in a range and callback to set Label of list Item in Menu Updates : - Added new letters (letters with accent) to string.upper function in Util.lua --- src/Menu.lua | 4 +- src/components/Util.lua | 29 ++++ src/items/Items.lua | 304 +++++++++++++++++++++++++++++++++++++++- 3 files changed, 333 insertions(+), 4 deletions(-) diff --git a/src/Menu.lua b/src/Menu.lua index 847ee9f..a71dde8 100644 --- a/src/Menu.lua +++ b/src/Menu.lua @@ -230,7 +230,9 @@ function RageUIMenus:IsVisible(Item, Panel) RageUI.Background(); RageUI.Navigation(); RageUI.Description(); - Panel(Panels); + if Panel and type(Panel) == "function" then + Panel(Panels); + end RageUI.PoolMenus.Timer = 1 RageUI.Render() end diff --git a/src/components/Util.lua b/src/components/Util.lua index 5363067..91cdc09 100644 --- a/src/components/Util.lua +++ b/src/components/Util.lua @@ -10,4 +10,33 @@ end function string.starts(String, Start) return string.sub(String, 1, string.len(Start)) == Start +end + +local up_trans = { + ["é"] = "É", + ["è"] = "È", + ["â"] = "Â", + ["ê"] = "Ê", + ["î"] = "Î", + ["ô"] = "Ô", + ["û"] = "Û", + ["ä"] = "Ä", + ["ë"] = "Ë", + ["ï"] = "Ï", + ["ö"] = "Ö", + ["ü"] = "Ü", + ["à"] = "À", + ["æ"] = "Æ", + ["ç"] = "Ç", + ["œ"] = "Œ", + ["ù"] = "Ù", +} + +local old_upper = string.upper +function string.upper(str) + local res = old_upper(str) + for k, v in pairs(up_trans) do + res = string.gsub(res, k, v) + end + return res end \ No newline at end of file diff --git a/src/items/Items.lua b/src/items/Items.lua index d3d4c3d..979f712 100644 --- a/src/items/Items.lua +++ b/src/items/Items.lua @@ -251,7 +251,7 @@ end ---@param Index number ---@param Style table ---@param Description string ----@param Actions fun(Index:number, onSelected:boolean, onListChange:boolean)) +---@param Actions fun(Index:number, onSelected:boolean, onListChange:boolean) ---@param Submenu any function Items:AddList(Label, Items, Index, Description, Style, Actions, Submenu) local CurrentMenu = RageUI.CurrentMenu; @@ -346,11 +346,301 @@ function Items:AddList(Label, Items, Index, Description, Style, Actions, Submenu Audio.PlaySound(RageUI.Settings.Audio.LeftRight.audioName, RageUI.Settings.Audio.LeftRight.audioRef) end local Selected = (CurrentMenu.Controls.Select.Active) - Actions(Index, Selected, onListChange, Active) + Actions(Index, Selected, onListChange, Active, Items) if (Selected) then Audio.PlaySound(RageUI.Settings.Audio.Select.audioName, RageUI.Settings.Audio.Select.audioRef) - if Submenu ~= nil and type(Submenu) == "table" then + --if Submenu ~= nil and type(Submenu) == "table" then + -- RageUI.NextMenu = Submenu[Index] + --end + if Submenu ~= nil and type(Submenu) == "table" and Submenu[Index]() then RageUI.NextMenu = Submenu[Index] + elseif Submenu ~= nil and Submenu() then + RageUI.NextMenu = Submenu + end + end + end + end + end + RageUI.Options = RageUI.Options + 1 +end + + +local list_stock = {} + +---AddList +---@param Label string +---@param Items table +---@param Style table +---@param Description string +---@param Actions fun(Index:number, onSelected:boolean, onListChange:boolean, isActive:boolean, Items:table, SetIndex: fun(newIndex:boolean)) +---@param Submenu any +function Items:AddAutoList(Label, Items, FirstIndex, Description, Style, Actions, Submenu) + local CurrentMenu = RageUI.CurrentMenu; + local ItemID = Label .. "_" .. #Items + + if not list_stock[CurrentMenu] then + list_stock[CurrentMenu] = {} + end + + local Option = RageUI.Options + 1 + + if not list_stock[CurrentMenu][ItemID] then + list_stock[CurrentMenu][ItemID] = FirstIndex and FirstIndex or 1 + end + + local Index = list_stock[CurrentMenu][ItemID] + + if CurrentMenu.Pagination.Minimum <= Option and CurrentMenu.Pagination.Maximum >= Option then + local Active = CurrentMenu.Index == Option; + local onListChange = false; + RageUI.ItemsSafeZone(CurrentMenu) + local LeftBadgeOffset = ((Style.LeftBadge == RageUI.BadgeStyle.None or Style.LeftBadge == nil) and 0 or 27) + local RightBadgeOffset = ((Style.RightBadge == RageUI.BadgeStyle.None or Style.RightBadge == nil) and 0 or 32) + local RightOffset = 0 + local ListText = (type(Items[Index]) == "table") and string.format("← %s →", Items[Index].Name) or string.format("← %s →", Items[Index]) or "NIL" + + if (Active) then + Graphics.Sprite("commonmenu", "gradient_nav", CurrentMenu.X, CurrentMenu.Y + 0 + CurrentMenu.SubtitleHeight + RageUI.ItemOffset, 431 + CurrentMenu.WidthOffset, 38) + end + + if (not Style.IsDisabled) then + if Active then + if Style.RightLabel ~= nil and Style.RightLabel ~= "" then + Graphics.Text(Style.RightLabel, CurrentMenu.X + 420 - RightBadgeOffset + CurrentMenu.WidthOffset, CurrentMenu.Y + 4 + CurrentMenu.SubtitleHeight + RageUI.ItemOffset, 0, 0.35, 0, 0, 0, 255, 2) + RightOffset = Graphics.MeasureStringWidth(Style.RightLabel, 0, 0.35) + end + else + if Style.RightLabel ~= nil and Style.RightLabel ~= "" then + RightOffset = Graphics.MeasureStringWidth(Style.RightLabel, 0, 0.35) + Graphics.Text(Style.RightLabel, CurrentMenu.X + 420 - RightBadgeOffset + CurrentMenu.WidthOffset, CurrentMenu.Y + 4 + CurrentMenu.SubtitleHeight + RageUI.ItemOffset, 0, 0.35, 245, 245, 245, 255, 2) + end + end + end + RightOffset = RightBadgeOffset * 1.3 + RightOffset + if (not Style.IsDisabled) then + if (Active) then + Graphics.Text(Label, CurrentMenu.X + 8 + LeftBadgeOffset, CurrentMenu.Y + 3 + CurrentMenu.SubtitleHeight + RageUI.ItemOffset, 0, 0.33, 0, 0, 0, 255) + Graphics.Text(ListText, CurrentMenu.X + 403 + 15 + CurrentMenu.WidthOffset - RightOffset, CurrentMenu.Y + 3 + CurrentMenu.SubtitleHeight + RageUI.ItemOffset, 0, 0.35, 0, 0, 0, 255, 2) + else + Graphics.Text(Label, CurrentMenu.X + 8 + LeftBadgeOffset, CurrentMenu.Y + 3 + CurrentMenu.SubtitleHeight + RageUI.ItemOffset, 0, 0.33, 245, 245, 245, 255) + Graphics.Text(ListText, CurrentMenu.X + 403 + 15 + CurrentMenu.WidthOffset - RightOffset, CurrentMenu.Y + 3 + CurrentMenu.SubtitleHeight + RageUI.ItemOffset, 0, 0.35, 245, 245, 245, 255, 2) + end + else + Graphics.Text(Label, CurrentMenu.X + 8 + LeftBadgeOffset, CurrentMenu.Y + 3 + CurrentMenu.SubtitleHeight + RageUI.ItemOffset, 0, 0.33, 163, 159, 148, 255) + Graphics.Text(ListText, CurrentMenu.X + 403 + 15 + CurrentMenu.WidthOffset, CurrentMenu.Y + 3 + CurrentMenu.SubtitleHeight + RageUI.ItemOffset, 0, 0.35, 163, 159, 148, 255, 2) + end + + if type(Style) == "table" then + if Style.Enabled == true or Style.Enabled == nil then + if type(Style) == 'table' then + if Style.LeftBadge ~= nil then + if Style.LeftBadge ~= RageUI.BadgeStyle.None then + local BadgeData = Style.LeftBadge(Active) + Graphics.Sprite(BadgeData.BadgeDictionary or "commonmenu", BadgeData.BadgeTexture or "", CurrentMenu.X, CurrentMenu.Y + -2 + CurrentMenu.SubtitleHeight + RageUI.ItemOffset, 40, 40, 0, BadgeData.BadgeColour and BadgeData.BadgeColour.R or 255, BadgeData.BadgeColour and BadgeData.BadgeColour.G or 255, BadgeData.BadgeColour and BadgeData.BadgeColour.B or 255, BadgeData.BadgeColour and BadgeData.BadgeColour.A or 255) + end + end + + if Style.RightBadge ~= nil then + if Style.RightBadge ~= RageUI.BadgeStyle.None then + local BadgeData = Style.RightBadge(Active) + Graphics.Sprite(BadgeData.BadgeDictionary or "commonmenu", BadgeData.BadgeTexture or "", CurrentMenu.X + 385 + CurrentMenu.WidthOffset, CurrentMenu.Y + -2 + CurrentMenu.SubtitleHeight + RageUI.ItemOffset, 40, 40, 0, BadgeData.BadgeColour and BadgeData.BadgeColour.R or 255, BadgeData.BadgeColour and BadgeData.BadgeColour.G or 255, BadgeData.BadgeColour and BadgeData.BadgeColour.B or 255, BadgeData.BadgeColour and BadgeData.BadgeColour.A or 255) + end + end + end + else + local LeftBadge = RageUI.BadgeStyle.Lock + if LeftBadge ~= RageUI.BadgeStyle.None and LeftBadge ~= nil then + local BadgeData = LeftBadge(Active) + Graphics.Sprite(BadgeData.BadgeDictionary or "commonmenu", BadgeData.BadgeTexture or "", CurrentMenu.X, CurrentMenu.Y + -2 + CurrentMenu.SubtitleHeight + RageUI.ItemOffset, 40, 40, 0, BadgeData.BadgeColour.R or 255, BadgeData.BadgeColour.G or 255, BadgeData.BadgeColour.B or 255, BadgeData.BadgeColour.A or 255) + end + end + else + error("UICheckBox Style is not a `table`") + end + + RageUI.ItemOffset = RageUI.ItemOffset + 38 + + if (Active) then + RageUI.ItemsDescription(Description); + if (not Style.IsDisabled) then + if (CurrentMenu.Controls.Left.Active) and not (CurrentMenu.Controls.Right.Active) then + Index = Index - 1 + if Index < 1 then + Index = #Items + end + onListChange = true + list_stock[CurrentMenu][ItemID] = Index + Audio.PlaySound(RageUI.Settings.Audio.LeftRight.audioName, RageUI.Settings.Audio.LeftRight.audioRef) + elseif (CurrentMenu.Controls.Right.Active) and not (CurrentMenu.Controls.Left.Active) then + Index = Index + 1 + if Index > #Items then + Index = 1 + end + onListChange = true + list_stock[CurrentMenu][ItemID] = Index + Audio.PlaySound(RageUI.Settings.Audio.LeftRight.audioName, RageUI.Settings.Audio.LeftRight.audioRef) + end + local Selected = (CurrentMenu.Controls.Select.Active) + Actions(Index, Selected, onListChange, Active, Items, function(newIndex) + if newIndex <= #Items and newIndex > 1 then + list_stock[CurrentMenu][ItemID] = newIndex + end + end) + if (Selected) then + Audio.PlaySound(RageUI.Settings.Audio.Select.audioName, RageUI.Settings.Audio.Select.audioRef) + if Submenu ~= nil and type(Submenu) == "table" and Submenu[Index]() then + RageUI.NextMenu = Submenu[Index] + elseif Submenu ~= nil and Submenu() then + RageUI.NextMenu = Submenu + end + end + end + end + end + RageUI.Options = RageUI.Options + 1 +end + +local range_stock = {} + +---AddList +---@param Label string +---@param Items table +---@param Style table +---@param Description string +---@param Actions fun(Index:number, onSelected:boolean, onListChange:boolean, isActive:boolean, Items:table, SetIndex: fun(newIndex:boolean)) +---@param Submenu any +function Items:AddRange(Label, Range, NameCB, Description, Style, Actions, Submenu) + local CurrentMenu = RageUI.CurrentMenu; + local ItemID = Label .. "_" .. #Range + + if not range_stock[CurrentMenu] then + range_stock[CurrentMenu] = {} + end + + if not list_stock[CurrentMenu] then + list_stock[CurrentMenu] = {} + end + + local Option = RageUI.Options + 1 + + if not range_stock[CurrentMenu][ItemID] then + local items = {} + for i = Range[1] and Range[1] or 1, Range[2] and Range[2] or 2 do + table.insert(items, i) + end + range_stock[CurrentMenu][ItemID] = items + end + + if not list_stock[CurrentMenu][ItemID] then + list_stock[CurrentMenu][ItemID] = 1 + end + + local Items = range_stock[CurrentMenu][ItemID] + local Index = list_stock[CurrentMenu][ItemID] + + if CurrentMenu.Pagination.Minimum <= Option and CurrentMenu.Pagination.Maximum >= Option then + local Active = CurrentMenu.Index == Option; + local onListChange = false; + RageUI.ItemsSafeZone(CurrentMenu) + local LeftBadgeOffset = ((Style.LeftBadge == RageUI.BadgeStyle.None or Style.LeftBadge == nil) and 0 or 27) + local RightBadgeOffset = ((Style.RightBadge == RageUI.BadgeStyle.None or Style.RightBadge == nil) and 0 or 32) + local RightOffset = 0 + local IndexName = NameCB(Index, Items[Index]) + local ListText = IndexName and string.format("← %s →", IndexName) or string.format("← %s →", Items[Index]) or "NIL" + + if (Active) then + Graphics.Sprite("commonmenu", "gradient_nav", CurrentMenu.X, CurrentMenu.Y + 0 + CurrentMenu.SubtitleHeight + RageUI.ItemOffset, 431 + CurrentMenu.WidthOffset, 38) + end + + if (not Style.IsDisabled) then + if Active then + if Style.RightLabel ~= nil and Style.RightLabel ~= "" then + Graphics.Text(Style.RightLabel, CurrentMenu.X + 420 - RightBadgeOffset + CurrentMenu.WidthOffset, CurrentMenu.Y + 4 + CurrentMenu.SubtitleHeight + RageUI.ItemOffset, 0, 0.35, 0, 0, 0, 255, 2) + RightOffset = Graphics.MeasureStringWidth(Style.RightLabel, 0, 0.35) + end + else + if Style.RightLabel ~= nil and Style.RightLabel ~= "" then + RightOffset = Graphics.MeasureStringWidth(Style.RightLabel, 0, 0.35) + Graphics.Text(Style.RightLabel, CurrentMenu.X + 420 - RightBadgeOffset + CurrentMenu.WidthOffset, CurrentMenu.Y + 4 + CurrentMenu.SubtitleHeight + RageUI.ItemOffset, 0, 0.35, 245, 245, 245, 255, 2) + end + end + end + RightOffset = RightBadgeOffset * 1.3 + RightOffset + if (not Style.IsDisabled) then + if (Active) then + Graphics.Text(Label, CurrentMenu.X + 8 + LeftBadgeOffset, CurrentMenu.Y + 3 + CurrentMenu.SubtitleHeight + RageUI.ItemOffset, 0, 0.33, 0, 0, 0, 255) + Graphics.Text(ListText, CurrentMenu.X + 403 + 15 + CurrentMenu.WidthOffset - RightOffset, CurrentMenu.Y + 3 + CurrentMenu.SubtitleHeight + RageUI.ItemOffset, 0, 0.35, 0, 0, 0, 255, 2) + else + Graphics.Text(Label, CurrentMenu.X + 8 + LeftBadgeOffset, CurrentMenu.Y + 3 + CurrentMenu.SubtitleHeight + RageUI.ItemOffset, 0, 0.33, 245, 245, 245, 255) + Graphics.Text(ListText, CurrentMenu.X + 403 + 15 + CurrentMenu.WidthOffset - RightOffset, CurrentMenu.Y + 3 + CurrentMenu.SubtitleHeight + RageUI.ItemOffset, 0, 0.35, 245, 245, 245, 255, 2) + end + else + Graphics.Text(Label, CurrentMenu.X + 8 + LeftBadgeOffset, CurrentMenu.Y + 3 + CurrentMenu.SubtitleHeight + RageUI.ItemOffset, 0, 0.33, 163, 159, 148, 255) + Graphics.Text(ListText, CurrentMenu.X + 403 + 15 + CurrentMenu.WidthOffset, CurrentMenu.Y + 3 + CurrentMenu.SubtitleHeight + RageUI.ItemOffset, 0, 0.35, 163, 159, 148, 255, 2) + end + + if type(Style) == "table" then + if Style.Enabled == true or Style.Enabled == nil then + if type(Style) == 'table' then + if Style.LeftBadge ~= nil then + if Style.LeftBadge ~= RageUI.BadgeStyle.None then + local BadgeData = Style.LeftBadge(Active) + Graphics.Sprite(BadgeData.BadgeDictionary or "commonmenu", BadgeData.BadgeTexture or "", CurrentMenu.X, CurrentMenu.Y + -2 + CurrentMenu.SubtitleHeight + RageUI.ItemOffset, 40, 40, 0, BadgeData.BadgeColour and BadgeData.BadgeColour.R or 255, BadgeData.BadgeColour and BadgeData.BadgeColour.G or 255, BadgeData.BadgeColour and BadgeData.BadgeColour.B or 255, BadgeData.BadgeColour and BadgeData.BadgeColour.A or 255) + end + end + + if Style.RightBadge ~= nil then + if Style.RightBadge ~= RageUI.BadgeStyle.None then + local BadgeData = Style.RightBadge(Active) + Graphics.Sprite(BadgeData.BadgeDictionary or "commonmenu", BadgeData.BadgeTexture or "", CurrentMenu.X + 385 + CurrentMenu.WidthOffset, CurrentMenu.Y + -2 + CurrentMenu.SubtitleHeight + RageUI.ItemOffset, 40, 40, 0, BadgeData.BadgeColour and BadgeData.BadgeColour.R or 255, BadgeData.BadgeColour and BadgeData.BadgeColour.G or 255, BadgeData.BadgeColour and BadgeData.BadgeColour.B or 255, BadgeData.BadgeColour and BadgeData.BadgeColour.A or 255) + end + end + end + else + local LeftBadge = RageUI.BadgeStyle.Lock + if LeftBadge ~= RageUI.BadgeStyle.None and LeftBadge ~= nil then + local BadgeData = LeftBadge(Active) + Graphics.Sprite(BadgeData.BadgeDictionary or "commonmenu", BadgeData.BadgeTexture or "", CurrentMenu.X, CurrentMenu.Y + -2 + CurrentMenu.SubtitleHeight + RageUI.ItemOffset, 40, 40, 0, BadgeData.BadgeColour.R or 255, BadgeData.BadgeColour.G or 255, BadgeData.BadgeColour.B or 255, BadgeData.BadgeColour.A or 255) + end + end + else + error("UICheckBox Style is not a `table`") + end + + RageUI.ItemOffset = RageUI.ItemOffset + 38 + + if (Active) then + RageUI.ItemsDescription(Description); + if (not Style.IsDisabled) then + if (CurrentMenu.Controls.Left.Active) and not (CurrentMenu.Controls.Right.Active) then + Index = Index - 1 + if Index < 1 then + Index = #Items + end + onListChange = true + list_stock[CurrentMenu][ItemID] = Index + Audio.PlaySound(RageUI.Settings.Audio.LeftRight.audioName, RageUI.Settings.Audio.LeftRight.audioRef) + elseif (CurrentMenu.Controls.Right.Active) and not (CurrentMenu.Controls.Left.Active) then + Index = Index + 1 + if Index > #Items then + Index = 1 + end + onListChange = true + list_stock[CurrentMenu][ItemID] = Index + Audio.PlaySound(RageUI.Settings.Audio.LeftRight.audioName, RageUI.Settings.Audio.LeftRight.audioRef) + end + local Selected = (CurrentMenu.Controls.Select.Active) + Actions(Index, Selected, onListChange, Active, Items, function(newIndex) + if newIndex <= #Items and newIndex > 1 then + list_stock[CurrentMenu][ItemID] = newIndex + end + end) + if (Selected) then + Audio.PlaySound(RageUI.Settings.Audio.Select.audioName, RageUI.Settings.Audio.Select.audioRef) + if Submenu ~= nil and type(Submenu) == "table" and Submenu[Index]() then + RageUI.NextMenu = Submenu[Index] + elseif Submenu ~= nil and Submenu() then + RageUI.NextMenu = Submenu end end end @@ -359,6 +649,14 @@ function Items:AddList(Label, Items, Index, Description, Style, Actions, Submenu RageUI.Options = RageUI.Options + 1 end +--[[ + Items:AddRange("bla", { 5, 10 }, function(Index, Value) return Index .. " : " .. Value end, nil, { IsDisabled = false }, function(Index, onSelected, onListChange, isActive, Items, SetIndex) + if (onListChange) then + print(Items[Index]) + end + end) +]] + ---Heritage ---@param Mum number ---@param Dad number From be5dc5e0235df39212e370652c7f0450d2923dba Mon Sep 17 00:00:00 2001 From: Rocwo <61157993+ArdentLeKhey@users.noreply.github.com> Date: Sun, 27 Aug 2023 18:45:40 +0200 Subject: [PATCH 2/7] Update README.md --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 621a7f8..7502d59 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,2 @@ -In the next few days, I will release one of the latest versions of RageUI. This one will probably have no support from me, and you will have a commercial right on it without any counterpart, only a thank you. - -This version will be less customizable, and much more powerful, in order to meet MY requirements, and not those of the community. +A fixed version of Rage UI with new features to sue my projects... +You can use it for your projects but please make pull requests if you find bugs, that's the point of open source 😉 From 3945035ae4ec53f17227cf3234936fd582ec5d6c Mon Sep 17 00:00:00 2001 From: Rocwo <61157993+ArdentLeKhey@users.noreply.github.com> Date: Sun, 27 Aug 2023 19:04:33 +0200 Subject: [PATCH 3/7] Added few features to suit my projects --- src/RageUI.lua | 86 ++++++++--------- src/components/Util.lua | 4 + src/elements/ItemsColour.lua | 2 + src/elements/PanelColour.lua | 66 +++++++++++++ src/items/Items.lua | 161 ++++++++++++++++++++++++++++++- src/items/Panels.lua | 177 +++++++++++++++++++++++++++++++++++ 6 files changed, 450 insertions(+), 46 deletions(-) diff --git a/src/RageUI.lua b/src/RageUI.lua index 5fb8f11..66094bd 100644 --- a/src/RageUI.lua +++ b/src/RageUI.lua @@ -357,7 +357,7 @@ end function RageUI.Background() local CurrentMenu = RageUI.CurrentMenu; - if (CurrentMenu.Display.Background) then + if CurrentMenu and (CurrentMenu.Display.Background) then RageUI.ItemsSafeZone(CurrentMenu) SetScriptGfxDrawOrder(0) Graphics.Sprite(RageUI.Settings.Items.Background.Dictionary, RageUI.Settings.Items.Background.Texture, CurrentMenu.X, CurrentMenu.Y + RageUI.Settings.Items.Background.Y + CurrentMenu.SubtitleHeight, RageUI.Settings.Items.Background.Width + CurrentMenu.WidthOffset, RageUI.ItemOffset, 0, 0, 0, 0, 255) @@ -368,7 +368,7 @@ end function RageUI.Description() local CurrentMenu = RageUI.CurrentMenu; local Description = RageUI.Settings.Items.Description; - if CurrentMenu.Description ~= nil then + if CurrentMenu and CurrentMenu.Description ~= nil then RageUI.ItemsSafeZone(CurrentMenu) Graphics.Rectangle(CurrentMenu.X, CurrentMenu.Y + Description.Bar.Y + CurrentMenu.SubtitleHeight + RageUI.ItemOffset, Description.Bar.Width + CurrentMenu.WidthOffset, Description.Bar.Height, 0, 0, 0, 255) Graphics.Sprite(Description.Background.Dictionary, Description.Background.Texture, CurrentMenu.X, CurrentMenu.Y + Description.Background.Y + CurrentMenu.SubtitleHeight + RageUI.ItemOffset, Description.Background.Width + CurrentMenu.WidthOffset, CurrentMenu.DescriptionHeight, 0, 0, 0, 255) @@ -379,56 +379,58 @@ end function RageUI.Render() local CurrentMenu = RageUI.CurrentMenu; - if CurrentMenu.Safezone then - ResetScriptGfxAlign() - end - - if (CurrentMenu.Display.InstructionalButton) then - if not CurrentMenu.InitScaleform then - CurrentMenu:UpdateInstructionalButtons(true) - CurrentMenu.InitScaleform = true + if CurrentMenu then + if CurrentMenu.Safezone then + ResetScriptGfxAlign() end - DrawScaleformMovieFullscreen(CurrentMenu.InstructionalScaleform, 255, 255, 255, 255, 0) - end - CurrentMenu.Options = RageUI.Options - CurrentMenu.SafeZoneSize = nil - RageUI.Controls() - RageUI.Options = 0 - RageUI.StatisticPanelCount = 0 - RageUI.ItemOffset = 0 - if CurrentMenu.Controls.Back.Enabled then - if CurrentMenu.Controls.Back.Pressed and CurrentMenu.Closable then - CurrentMenu.Controls.Back.Pressed = false - - Audio.PlaySound(RageUI.Settings.Audio.Back.audioName, RageUI.Settings.Audio.Back.audioRef) - if CurrentMenu.Closed ~= nil then - collectgarbage() - CurrentMenu.Closed() + if (CurrentMenu.Display.InstructionalButton) then + if not CurrentMenu.InitScaleform then + CurrentMenu:UpdateInstructionalButtons(true) + CurrentMenu.InitScaleform = true end + DrawScaleformMovieFullscreen(CurrentMenu.InstructionalScaleform, 255, 255, 255, 255, 0) + end + CurrentMenu.Options = RageUI.Options + CurrentMenu.SafeZoneSize = nil + RageUI.Controls() + RageUI.Options = 0 + RageUI.StatisticPanelCount = 0 + RageUI.ItemOffset = 0 + if CurrentMenu.Controls.Back.Enabled then + if CurrentMenu.Controls.Back.Pressed and CurrentMenu.Closable then + CurrentMenu.Controls.Back.Pressed = false + + Audio.PlaySound(RageUI.Settings.Audio.Back.audioName, RageUI.Settings.Audio.Back.audioRef) + + if CurrentMenu.Closed ~= nil then + collectgarbage() + CurrentMenu.Closed() + end - if CurrentMenu.Parent ~= nil then - if CurrentMenu.Parent() then - RageUI.NextMenu = CurrentMenu.Parent + if CurrentMenu.Parent ~= nil then + if CurrentMenu.Parent() then + RageUI.NextMenu = CurrentMenu.Parent + else + RageUI.NextMenu = nil + RageUI.Visible(CurrentMenu, false) + end else RageUI.NextMenu = nil RageUI.Visible(CurrentMenu, false) end - else - RageUI.NextMenu = nil - RageUI.Visible(CurrentMenu, false) + elseif CurrentMenu.Controls.Back.Pressed and not CurrentMenu.Closable then + CurrentMenu.Controls.Back.Pressed = false end - elseif CurrentMenu.Controls.Back.Pressed and not CurrentMenu.Closable then - CurrentMenu.Controls.Back.Pressed = false end - end - if RageUI.NextMenu ~= nil then - if RageUI.NextMenu() then - RageUI.Visible(CurrentMenu, false) - RageUI.Visible(RageUI.NextMenu, true) - CurrentMenu.Controls.Select.Active = false - RageUI.NextMenu = nil - RageUI.LastControl = false + if RageUI.NextMenu ~= nil then + if RageUI.NextMenu() then + RageUI.Visible(CurrentMenu, false) + RageUI.Visible(RageUI.NextMenu, true) + CurrentMenu.Controls.Select.Active = false + RageUI.NextMenu = nil + RageUI.LastControl = false + end end end end diff --git a/src/components/Util.lua b/src/components/Util.lua index 91cdc09..dc424b7 100644 --- a/src/components/Util.lua +++ b/src/components/Util.lua @@ -39,4 +39,8 @@ function string.upper(str) res = string.gsub(res, k, v) end return res +end + +function string.FirstUp(str) + return string.upper(string.sub(str, 1, 1)) .. string.sub(str, 2) end \ No newline at end of file diff --git a/src/elements/ItemsColour.lua b/src/elements/ItemsColour.lua index bce2661..fd5dc1d 100644 --- a/src/elements/ItemsColour.lua +++ b/src/elements/ItemsColour.lua @@ -221,5 +221,7 @@ RageUI.ItemsColour = { DegenMagenta = { 255, 0, 255, 255 }, Stunt1 = { 38, 136, 234, 255 }, Stunt2 = { 224, 50, 50, 255 }, + BleuClairMenu = { 46, 105, 187, 255 }, + BleuFonceMenu = { 11, 60, 123, 255 }, } diff --git a/src/elements/PanelColour.lua b/src/elements/PanelColour.lua index e45e2a4..356a268 100644 --- a/src/elements/PanelColour.lua +++ b/src/elements/PanelColour.lua @@ -71,5 +71,71 @@ RageUI.PanelColour = { { 212, 185, 158 }, -- 62 { 213, 170, 115 }, -- 63 }, + MakeUp = { + { 153, 37, 50 }, -- 0 + { 200, 57, 93 }, -- 1 + { 189, 81, 108 }, -- 2 + { 184, 99, 122 }, -- 3 + { 166, 82, 107 }, -- 4 + { 177, 67, 76 }, -- 5 + { 127, 49, 51 }, -- 6 + { 164, 100, 93 }, -- 7 + { 193, 135, 121 }, -- 8 + { 203, 160, 150 }, -- 9 + { 198, 145, 143 }, -- 10 + { 171, 111, 99}, -- 11 + { 176, 96, 80 }, -- 12 + { 168, 76, 51 }, -- 13 + { 180, 113, 120 }, -- 14 + { 202, 127, 146 }, -- 15 + { 237, 156, 190 }, -- 16 + { 231, 117, 164 }, -- 17 + { 222, 62, 129 }, -- 18 + { 179, 76, 110 }, -- 19 + { 113, 39, 57 }, -- 20 + { 79, 31, 42 }, -- 21 + { 170, 34, 47 }, -- 22 + { 222, 32, 52 }, -- 23 + { 207, 8, 19 }, -- 24 + { 229, 84, 112 }, -- 25 + { 220, 63, 181 }, -- 26 + { 192, 39, 178 }, -- 27 + { 160, 28, 169 }, -- 28 + { 110, 24, 117 }, -- 29 + { 115, 20, 101 }, -- 30 + { 86, 22, 92 }, -- 31 + { 109, 26, 157 }, -- 32 + { 27, 55, 113 }, -- 33 + { 29, 78, 167 }, -- 34 + { 30, 116, 187 }, -- 35 + { 33, 163, 206 }, -- 36 + { 37, 194, 210 }, -- 37 + { 35, 204, 165 }, -- 38 + { 39, 192, 125 }, -- 39 + { 27, 156, 50 }, -- 40 + { 20, 134, 4 }, -- 41 + { 112, 208, 65 }, -- 42 + { 197, 234, 52 }, -- 43 + { 225, 227, 47 }, -- 44 + { 255, 221, 38 }, -- 45 + { 250, 192, 38 }, -- 46 + { 247, 138, 39 }, -- 47 + { 254, 89, 16 }, -- 48 + { 190, 110, 25 }, -- 49 + { 247, 201, 127 }, -- 50 + { 251, 229, 192 }, -- 51 + { 245, 245, 245 }, -- 52 + { 179, 180, 179 }, -- 53 + { 145, 145, 145 }, -- 54 + { 86, 78, 78 }, -- 55 + { 24, 14, 14 }, -- 56 + { 88, 150, 158 }, -- 57 + { 77, 111, 140 }, -- 58 + { 26, 43, 85 }, -- 59 + { 160, 126, 107 }, -- 60 + { 130, 99, 85 }, -- 61 + { 109, 83, 70 }, -- 62 + { 62, 45, 39 } -- 63 + } } diff --git a/src/items/Items.lua b/src/items/Items.lua index 979f712..8f02ac3 100644 --- a/src/items/Items.lua +++ b/src/items/Items.lua @@ -57,6 +57,9 @@ Items = {} ---@public ---@return void function Items:AddButton(Label, Description, Style, Actions, Submenu) + if Submenu then + Style.RightLabel = '→' + end local CurrentMenu = RageUI.CurrentMenu local Option = RageUI.Options + 1 if CurrentMenu.Pagination.Minimum <= Option and CurrentMenu.Pagination.Maximum >= Option then @@ -110,6 +113,11 @@ function Items:AddButton(Label, Description, Style, Actions, Submenu) RageUI.NextMenu = Submenu end end + else + local Selected = (CurrentMenu.Controls.Select.Active) + if Selected then + Audio.PlaySound(RageUI.Settings.Audio.Error.audioName, RageUI.Settings.Audio.Error.audioRef) + end end end end @@ -364,6 +372,127 @@ function Items:AddList(Label, Items, Index, Description, Style, Actions, Submenu RageUI.Options = RageUI.Options + 1 end +---AddList +---@param Label string +---@param Items table +---@param Index number +---@param Style table +---@param Description string +---@param Actions fun(Index:number, onSelected:boolean, onListChange:boolean) +---@param Submenu any +function Items:AddList2(Label, Items, Index, NameCB, Description, Style, Actions, Submenu) + local CurrentMenu = RageUI.CurrentMenu; + + local Option = RageUI.Options + 1 + if CurrentMenu.Pagination.Minimum <= Option and CurrentMenu.Pagination.Maximum >= Option then + local Active = CurrentMenu.Index == Option; + local onListChange = false; + RageUI.ItemsSafeZone(CurrentMenu) + local LeftBadgeOffset = ((Style.LeftBadge == RageUI.BadgeStyle.None or Style.LeftBadge == nil) and 0 or 27) + local RightBadgeOffset = ((Style.RightBadge == RageUI.BadgeStyle.None or Style.RightBadge == nil) and 0 or 32) + local RightOffset = 0 + local IndexName = NameCB and NameCB(Index, Items[Index]) or nil + local ListText = IndexName and string.format("← %s →", IndexName) or string.format("← %s →", Items[Index]) or "NIL" + + + if (Active) then + Graphics.Sprite("commonmenu", "gradient_nav", CurrentMenu.X, CurrentMenu.Y + 0 + CurrentMenu.SubtitleHeight + RageUI.ItemOffset, 431 + CurrentMenu.WidthOffset, 38) + end + + if (not Style.IsDisabled) then + if Active then + if Style.RightLabel ~= nil and Style.RightLabel ~= "" then + Graphics.Text(Style.RightLabel, CurrentMenu.X + 420 - RightBadgeOffset + CurrentMenu.WidthOffset, CurrentMenu.Y + 4 + CurrentMenu.SubtitleHeight + RageUI.ItemOffset, 0, 0.35, 0, 0, 0, 255, 2) + RightOffset = Graphics.MeasureStringWidth(Style.RightLabel, 0, 0.35) + end + else + if Style.RightLabel ~= nil and Style.RightLabel ~= "" then + RightOffset = Graphics.MeasureStringWidth(Style.RightLabel, 0, 0.35) + Graphics.Text(Style.RightLabel, CurrentMenu.X + 420 - RightBadgeOffset + CurrentMenu.WidthOffset, CurrentMenu.Y + 4 + CurrentMenu.SubtitleHeight + RageUI.ItemOffset, 0, 0.35, 245, 245, 245, 255, 2) + end + end + end + RightOffset = RightBadgeOffset * 1.3 + RightOffset + if (not Style.IsDisabled) then + if (Active) then + Graphics.Text(Label, CurrentMenu.X + 8 + LeftBadgeOffset, CurrentMenu.Y + 3 + CurrentMenu.SubtitleHeight + RageUI.ItemOffset, 0, 0.33, 0, 0, 0, 255) + Graphics.Text(ListText, CurrentMenu.X + 403 + 15 + CurrentMenu.WidthOffset - RightOffset, CurrentMenu.Y + 3 + CurrentMenu.SubtitleHeight + RageUI.ItemOffset, 0, 0.35, 0, 0, 0, 255, 2) + else + Graphics.Text(Label, CurrentMenu.X + 8 + LeftBadgeOffset, CurrentMenu.Y + 3 + CurrentMenu.SubtitleHeight + RageUI.ItemOffset, 0, 0.33, 245, 245, 245, 255) + Graphics.Text(ListText, CurrentMenu.X + 403 + 15 + CurrentMenu.WidthOffset - RightOffset, CurrentMenu.Y + 3 + CurrentMenu.SubtitleHeight + RageUI.ItemOffset, 0, 0.35, 245, 245, 245, 255, 2) + end + else + Graphics.Text(Label, CurrentMenu.X + 8 + LeftBadgeOffset, CurrentMenu.Y + 3 + CurrentMenu.SubtitleHeight + RageUI.ItemOffset, 0, 0.33, 163, 159, 148, 255) + Graphics.Text(ListText, CurrentMenu.X + 403 + 15 + CurrentMenu.WidthOffset, CurrentMenu.Y + 3 + CurrentMenu.SubtitleHeight + RageUI.ItemOffset, 0, 0.35, 163, 159, 148, 255, 2) + end + + if type(Style) == "table" then + if Style.Enabled == true or Style.Enabled == nil then + if type(Style) == 'table' then + if Style.LeftBadge ~= nil then + if Style.LeftBadge ~= RageUI.BadgeStyle.None then + local BadgeData = Style.LeftBadge(Active) + Graphics.Sprite(BadgeData.BadgeDictionary or "commonmenu", BadgeData.BadgeTexture or "", CurrentMenu.X, CurrentMenu.Y + -2 + CurrentMenu.SubtitleHeight + RageUI.ItemOffset, 40, 40, 0, BadgeData.BadgeColour and BadgeData.BadgeColour.R or 255, BadgeData.BadgeColour and BadgeData.BadgeColour.G or 255, BadgeData.BadgeColour and BadgeData.BadgeColour.B or 255, BadgeData.BadgeColour and BadgeData.BadgeColour.A or 255) + end + end + + if Style.RightBadge ~= nil then + if Style.RightBadge ~= RageUI.BadgeStyle.None then + local BadgeData = Style.RightBadge(Active) + Graphics.Sprite(BadgeData.BadgeDictionary or "commonmenu", BadgeData.BadgeTexture or "", CurrentMenu.X + 385 + CurrentMenu.WidthOffset, CurrentMenu.Y + -2 + CurrentMenu.SubtitleHeight + RageUI.ItemOffset, 40, 40, 0, BadgeData.BadgeColour and BadgeData.BadgeColour.R or 255, BadgeData.BadgeColour and BadgeData.BadgeColour.G or 255, BadgeData.BadgeColour and BadgeData.BadgeColour.B or 255, BadgeData.BadgeColour and BadgeData.BadgeColour.A or 255) + end + end + end + else + local LeftBadge = RageUI.BadgeStyle.Lock + if LeftBadge ~= RageUI.BadgeStyle.None and LeftBadge ~= nil then + local BadgeData = LeftBadge(Active) + Graphics.Sprite(BadgeData.BadgeDictionary or "commonmenu", BadgeData.BadgeTexture or "", CurrentMenu.X, CurrentMenu.Y + -2 + CurrentMenu.SubtitleHeight + RageUI.ItemOffset, 40, 40, 0, BadgeData.BadgeColour.R or 255, BadgeData.BadgeColour.G or 255, BadgeData.BadgeColour.B or 255, BadgeData.BadgeColour.A or 255) + end + end + else + error("UICheckBox Style is not a `table`") + end + + RageUI.ItemOffset = RageUI.ItemOffset + 38 + + if (Active) then + RageUI.ItemsDescription(Description); + if (not Style.IsDisabled) then + if (CurrentMenu.Controls.Left.Active) and not (CurrentMenu.Controls.Right.Active) then + Index = Index - 1 + if Index < 1 then + Index = #Items + end + onListChange = true + Audio.PlaySound(RageUI.Settings.Audio.LeftRight.audioName, RageUI.Settings.Audio.LeftRight.audioRef) + elseif (CurrentMenu.Controls.Right.Active) and not (CurrentMenu.Controls.Left.Active) then + Index = Index + 1 + if Index > #Items then + Index = 1 + end + onListChange = true + Audio.PlaySound(RageUI.Settings.Audio.LeftRight.audioName, RageUI.Settings.Audio.LeftRight.audioRef) + end + local Selected = (CurrentMenu.Controls.Select.Active) + Actions(Index, Selected, onListChange, Active, Items) + if (Selected) then + Audio.PlaySound(RageUI.Settings.Audio.Select.audioName, RageUI.Settings.Audio.Select.audioRef) + --if Submenu ~= nil and type(Submenu) == "table" then + -- RageUI.NextMenu = Submenu[Index] + --end + if Submenu ~= nil and type(Submenu) == "table" and Submenu[Index]() then + RageUI.NextMenu = Submenu[Index] + elseif Submenu ~= nil and Submenu() then + RageUI.NextMenu = Submenu + end + end + end + end + end + RageUI.Options = RageUI.Options + 1 +end + local list_stock = {} @@ -509,7 +638,7 @@ local range_stock = {} ---@param Description string ---@param Actions fun(Index:number, onSelected:boolean, onListChange:boolean, isActive:boolean, Items:table, SetIndex: fun(newIndex:boolean)) ---@param Submenu any -function Items:AddRange(Label, Range, NameCB, Description, Style, Actions, Submenu) +function Items:AddRange(Label, Range, FirstIndex, NameCB, Description, Style, Actions, Submenu) local CurrentMenu = RageUI.CurrentMenu; local ItemID = Label .. "_" .. #Range @@ -532,7 +661,7 @@ function Items:AddRange(Label, Range, NameCB, Description, Style, Actions, Subme end if not list_stock[CurrentMenu][ItemID] then - list_stock[CurrentMenu][ItemID] = 1 + list_stock[CurrentMenu][ItemID] = FirstIndex <= #range_stock[CurrentMenu][ItemID] and FirstIndex or 1 end local Items = range_stock[CurrentMenu][ItemID] @@ -545,7 +674,7 @@ function Items:AddRange(Label, Range, NameCB, Description, Style, Actions, Subme local LeftBadgeOffset = ((Style.LeftBadge == RageUI.BadgeStyle.None or Style.LeftBadge == nil) and 0 or 27) local RightBadgeOffset = ((Style.RightBadge == RageUI.BadgeStyle.None or Style.RightBadge == nil) and 0 or 32) local RightOffset = 0 - local IndexName = NameCB(Index, Items[Index]) + local IndexName = NameCB and NameCB(Index, Items[Index]) or nil local ListText = IndexName and string.format("← %s →", IndexName) or string.format("← %s →", Items[Index]) or "NIL" if (Active) then @@ -630,7 +759,7 @@ function Items:AddRange(Label, Range, NameCB, Description, Style, Actions, Subme Audio.PlaySound(RageUI.Settings.Audio.LeftRight.audioName, RageUI.Settings.Audio.LeftRight.audioRef) end local Selected = (CurrentMenu.Controls.Select.Active) - Actions(Index, Selected, onListChange, Active, Items, function(newIndex) + Actions(Index, Selected, onListChange, Active, Items[Index], Items, function(newIndex) if newIndex <= #Items and newIndex > 1 then list_stock[CurrentMenu][ItemID] = newIndex end @@ -682,4 +811,28 @@ function Items:Heritage(Mum, Dad) Graphics.Sprite("char_creator_portraits", Dad, CurrentMenu.X + 195 + (CurrentMenu.WidthOffset / 2), CurrentMenu.Y + CurrentMenu.SubtitleHeight + RageUI.ItemOffset, 228, 228) Graphics.Sprite("char_creator_portraits", Mum, CurrentMenu.X + 25 + (CurrentMenu.WidthOffset / 2), CurrentMenu.Y + CurrentMenu.SubtitleHeight + RageUI.ItemOffset, 228, 228) RageUI.ItemOffset = RageUI.ItemOffset + 228 +end + + +---Text +--- +--- Add items button. +--- +---@param Label string +---@param Description string +---@param Style table +---@param Actions fun(onSelected:boolean, onActive:boolean) +---@param Submenu any +---@public +---@return void +function Items:AddText(Label, Text, minChar, maxChar, Description, Style, Actions) + self:AddButton(Label .. " : " .. Text or "", "Appuyez sur Entrer pour compléter le champ\n" .. Description, Style, function(onSelected, isActive) + if onSelected then + local text = Game.KeyboardInput(Label, Text, maxChar) + if text ~= nil and #text >= minChar then + Text = text + end + end + Actions(onSelected, isActive, Text) + end) end \ No newline at end of file diff --git a/src/items/Panels.lua b/src/items/Panels.lua index eda8781..8c119b2 100644 --- a/src/items/Panels.lua +++ b/src/items/Panels.lua @@ -144,3 +144,180 @@ end function Panels:GridVertical(StartedY, TopText, BottomText, Action, Index) UIGridPanel(GridType.Vertical, nil, StartedY, TopText, BottomText, nil, nil, Action, Index) end + + +---@type table +local Colour = { + Background = { Dictionary = "commonmenu", Texture = "gradient_bgd", Y = 4, Width = 431, Height = 112 }, + LeftArrow = { Dictionary = "commonmenu", Texture = "arrowleft", X = 7.5, Y = 15, Width = 30, Height = 30 }, + RightArrow = { Dictionary = "commonmenu", Texture = "arrowright", X = 393.5, Y = 15, Width = 30, Height = 30 }, + Header = { X = 215.5, Y = 15, Scale = 0.35 }, + Box = { X = 15, Y = 55, Width = 44.5, Height = 44.5 }, + SelectedRectangle = { X = 15, Y = 47, Width = 44.5, Height = 8 }, +} + +---ColourPanel +---@param Title string +---@param Colours thread +---@param MinimumIndex number +---@param CurrentIndex number +---@param Callback function +---@return nil +---@public +---@return void +function Panels:Colour(Title, Colours, MinimumIndex, CurrentIndex, Callback, Index) + + ---@type table + local CurrentMenu = RageUI.CurrentMenu; + + if CurrentMenu ~= nil then + if (CurrentMenu.Index == Index) then + + ---@type number + local Maximum = (#Colours > 9) and 9 or #Colours + + ---@type boolean + local Hovered = Graphics.IsMouseInBounds(CurrentMenu.X + Colour.Box.X + CurrentMenu.SafeZoneSize.X + (CurrentMenu.WidthOffset / 2), CurrentMenu.Y + Colour.Box.Y + CurrentMenu.SafeZoneSize.Y + CurrentMenu.SubtitleHeight + RageUI.ItemOffset, (Colour.Box.Width * Maximum), Colour.Box.Height) + + ---@type number + local LeftArrowHovered = Graphics.IsMouseInBounds(CurrentMenu.X + Colour.LeftArrow.X + CurrentMenu.SafeZoneSize.X + (CurrentMenu.WidthOffset / 2), CurrentMenu.Y + Colour.LeftArrow.Y + CurrentMenu.SafeZoneSize.Y + CurrentMenu.SubtitleHeight + RageUI.ItemOffset, Colour.LeftArrow.Width, Colour.LeftArrow.Height) + + ---@type number + local RightArrowHovered = Graphics.IsMouseInBounds(CurrentMenu.X + Colour.RightArrow.X + CurrentMenu.SafeZoneSize.X + (CurrentMenu.WidthOffset / 2), CurrentMenu.Y + Colour.RightArrow.Y + CurrentMenu.SafeZoneSize.Y + CurrentMenu.SubtitleHeight + RageUI.ItemOffset, Colour.RightArrow.Width, Colour.RightArrow.Height) + + ---@type boolean + local Selected = false + + Graphics.Sprite(Colour.Background.Dictionary, Colour.Background.Texture, CurrentMenu.X, CurrentMenu.Y + Colour.Background.Y + CurrentMenu.SubtitleHeight + RageUI.ItemOffset, Colour.Background.Width + CurrentMenu.WidthOffset, Colour.Background.Height) + Graphics.Sprite(Colour.LeftArrow.Dictionary, Colour.LeftArrow.Texture, CurrentMenu.X + Colour.LeftArrow.X + (CurrentMenu.WidthOffset / 2), CurrentMenu.Y + Colour.LeftArrow.Y + CurrentMenu.SubtitleHeight + RageUI.ItemOffset, Colour.LeftArrow.Width, Colour.LeftArrow.Height) + Graphics.Sprite(Colour.RightArrow.Dictionary, Colour.RightArrow.Texture, CurrentMenu.X + Colour.RightArrow.X + (CurrentMenu.WidthOffset / 2), CurrentMenu.Y + Colour.RightArrow.Y + CurrentMenu.SubtitleHeight + RageUI.ItemOffset, Colour.RightArrow.Width, Colour.RightArrow.Height) + + Graphics.Rectangle(CurrentMenu.X + Colour.SelectedRectangle.X + (Colour.Box.Width * (CurrentIndex - MinimumIndex)) + (CurrentMenu.WidthOffset / 2), CurrentMenu.Y + Colour.SelectedRectangle.Y + CurrentMenu.SubtitleHeight + RageUI.ItemOffset, Colour.SelectedRectangle.Width, Colour.SelectedRectangle.Height, 245, 245, 245, 255) + + for Index = 1, Maximum do + Graphics.Rectangle(CurrentMenu.X + Colour.Box.X + (Colour.Box.Width * (Index - 1)) + (CurrentMenu.WidthOffset / 2), CurrentMenu.Y + Colour.Box.Y + CurrentMenu.SubtitleHeight + RageUI.ItemOffset, Colour.Box.Width, Colour.Box.Height, table.unpack(Colours[MinimumIndex + Index - 1])) + end + + Graphics.Text((Title and Title or "") .. " (" .. CurrentIndex .. " sur " .. #Colours .. ")", CurrentMenu.X + RageUI.Settings.Panels.Grid.Text.Top.X + (CurrentMenu.WidthOffset / 2), CurrentMenu.Y + RageUI.Settings.Panels.Grid.Text.Top.Y + CurrentMenu.SubtitleHeight + RageUI.ItemOffset, 0, RageUI.Settings.Panels.Grid.Text.Top.Scale, 245, 245, 245, 255, 1) + + + if Hovered or LeftArrowHovered or RightArrowHovered then + if RageUI.Settings.Controls.Click.Active then + Selected = true + if LeftArrowHovered then + CurrentIndex = CurrentIndex - 1 + if CurrentIndex < 1 then + CurrentIndex = #Colours + MinimumIndex = #Colours - Maximum + 1 + elseif CurrentIndex < MinimumIndex then + MinimumIndex = MinimumIndex - 1 + end + elseif RightArrowHovered then + CurrentIndex = CurrentIndex + 1 + if CurrentIndex > #Colours then + CurrentIndex = 1 + MinimumIndex = 1 + elseif CurrentIndex > MinimumIndex + Maximum - 1 then + MinimumIndex = MinimumIndex + 1 + end + elseif Hovered then + for Index = 1, Maximum do + if Graphics.IsMouseInBounds(CurrentMenu.X + Colour.Box.X + (Colour.Box.Width * (Index - 1)) + CurrentMenu.SafeZoneSize.X + (CurrentMenu.WidthOffset / 2), CurrentMenu.Y + Colour.Box.Y + CurrentMenu.SafeZoneSize.Y + CurrentMenu.SubtitleHeight + RageUI.ItemOffset, Colour.Box.Width, Colour.Box.Height) then + CurrentIndex = MinimumIndex + Index - 1 + end + end + end + end + end + + + RageUI.ItemOffset = RageUI.ItemOffset + Colour.Background.Height + Colour.Background.Y + + if (Hovered or LeftArrowHovered or RightArrowHovered) and RageUI.Settings.Controls.Click.Active then + --Audio.PlaySound(Audio[Audio.Use].Select.audioName, Audio[Audio.Use].Select.audioRef) + Audio.PlaySound(RageUI.Settings.Audio.Select.audioName, RageUI.Settings.Audio.Select.audioRef, true) + end + + Callback((Hovered or LeftArrowHovered or RightArrowHovered), Selected, MinimumIndex, CurrentIndex) + end + end +end + +local Percentage = { + Background = { Dictionary = "commonmenu", Texture = "gradient_bgd", Y = 4, Width = 431, Height = 76 }, + Bar = { X = 9, Y = 50, Width = 413, Height = 10 }, + Text = { + Left = { X = 25, Y = 15, Scale = 0.35 }, + Middle = { X = 215.5, Y = 15, Scale = 0.35 }, + Right = { X = 398, Y = 15, Scale = 0.35 }, + }, +} + +---PercentagePanel +---@param Percent number +---@param HeaderText string +---@param MinText string +---@param MaxText string +---@param Callback function +---@param Index number +---@return nil +---@public +function Panels:Percent(Percent, HeaderText, MinText, MaxText, Callback, Index) + local CurrentMenu = RageUI.CurrentMenu + + if CurrentMenu ~= nil then + if (CurrentMenu.Index == Index) then + + ---@type boolean + local Hovered = Graphics.IsMouseInBounds(CurrentMenu.X + Percentage.Bar.X + CurrentMenu.SafeZoneSize.X, CurrentMenu.Y + Percentage.Bar.Y + CurrentMenu.SafeZoneSize.Y + CurrentMenu.SubtitleHeight + RageUI.ItemOffset - 4, Percentage.Bar.Width + CurrentMenu.WidthOffset, Percentage.Bar.Height + 8) + + ---@type boolean + local Selected = false + + ---@type number + local Progress = Percentage.Bar.Width + + if Percent < 0.0 then + Percent = 0.0 + elseif Percent > 1.0 then + Percent = 1.0 + end + + Progress = Progress * Percent + + Graphics.Sprite(Percentage.Background.Dictionary, Percentage.Background.Texture, CurrentMenu.X, CurrentMenu.Y + Percentage.Background.Y + CurrentMenu.SubtitleHeight + RageUI.ItemOffset, Percentage.Background.Width + CurrentMenu.WidthOffset, Percentage.Background.Height) + Graphics.Rectangle(CurrentMenu.X + Percentage.Bar.X + (CurrentMenu.WidthOffset / 2), CurrentMenu.Y + Percentage.Bar.Y + CurrentMenu.SubtitleHeight + RageUI.ItemOffset, Percentage.Bar.Width, Percentage.Bar.Height, 87, 87, 87, 255) + Graphics.Rectangle(CurrentMenu.X + Percentage.Bar.X + (CurrentMenu.WidthOffset / 2), CurrentMenu.Y + Percentage.Bar.Y + CurrentMenu.SubtitleHeight + RageUI.ItemOffset, Progress, Percentage.Bar.Height, 245, 245, 245, 255) + + Graphics.Text(HeaderText or "Opacity", CurrentMenu.X + Percentage.Text.Middle.X + (CurrentMenu.WidthOffset / 2), CurrentMenu.Y + Percentage.Text.Middle.Y + CurrentMenu.SubtitleHeight + RageUI.ItemOffset, 0, Percentage.Text.Middle.Scale, 245, 245, 245, 255, 1) + Graphics.Text(MinText or "0%", CurrentMenu.X + Percentage.Text.Left.X + (CurrentMenu.WidthOffset / 2), CurrentMenu.Y + Percentage.Text.Left.Y + CurrentMenu.SubtitleHeight + RageUI.ItemOffset, 0, Percentage.Text.Left.Scale, 245, 245, 245, 255, 1) + Graphics.Text(MaxText or "100%", CurrentMenu.X + Percentage.Text.Right.X + (CurrentMenu.WidthOffset / 2), CurrentMenu.Y + Percentage.Text.Right.Y + CurrentMenu.SubtitleHeight + RageUI.ItemOffset, 0, Percentage.Text.Right.Scale, 245, 245, 245, 255, 1) + + if Hovered then + if IsDisabledControlPressed(0, 24) then + Selected = true + + Progress = math.round(GetControlNormal(0, 239) * 1920) - CurrentMenu.SafeZoneSize.X - (CurrentMenu.X + Percentage.Bar.X + (CurrentMenu.WidthOffset / 2)) + + if Progress < 0 then + Progress = 0 + elseif Progress > (Percentage.Bar.Width) then + Progress = Percentage.Bar.Width + end + + Percent = math.round(Progress / Percentage.Bar.Width, 2) + end + end + + RageUI.ItemOffset = RageUI.ItemOffset + Percentage.Background.Height + Percentage.Background.Y + + if Hovered and Selected then + --local Audio = RageUI.Settings.Audio + --RageUI.PlaySound(Audio[Audio.Use].Slider.audioName, Audio[Audio.Use].Slider.audioRef, true) + Audio.PlaySound(RageUI.Settings.Audio.Slider.audioName, RageUI.Settings.Audio.Slider.audioRef, true) + end + + Callback(Hovered, Selected, Percent) + end + end +end \ No newline at end of file From dbba7d726c40c9ca09d85b339a2c31fd98fbd2cd Mon Sep 17 00:00:00 2001 From: Rocwo <61157993+ArdentLeKhey@users.noreply.github.com> Date: Sun, 27 Aug 2023 19:05:05 +0200 Subject: [PATCH 4/7] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7502d59..a6cabab 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,2 @@ -A fixed version of Rage UI with new features to sue my projects... +A fixed version of Rage UI with new features to suit my projects... You can use it for your projects but please make pull requests if you find bugs, that's the point of open source 😉 From 5e77ee8cb4977256697c4bf537b2531289aa967d Mon Sep 17 00:00:00 2001 From: Rocwo <61157993+ArdentLeKhey@users.noreply.github.com> Date: Tue, 16 Apr 2024 20:03:06 +0200 Subject: [PATCH 5/7] Performance improvements in Util.lua --- src/components/Util.lua | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/components/Util.lua b/src/components/Util.lua index dc424b7..eaafc1d 100644 --- a/src/components/Util.lua +++ b/src/components/Util.lua @@ -4,8 +4,13 @@ --- File created at [24/05/2021 09:57] --- -function math.round(num, numDecimalPlaces) - return tonumber(string.format("%." .. (numDecimalPlaces or 0) .. "f", num)) +function math.round(value, numDecimalPlaces) + if numDecimalPlaces then + local power = 10^numDecimalPlaces + return math.floor((value * power) + 0.5) / (power) + else + return math.floor(value + 0.5) + end end function string.starts(String, Start) @@ -43,4 +48,4 @@ end function string.FirstUp(str) return string.upper(string.sub(str, 1, 1)) .. string.sub(str, 2) -end \ No newline at end of file +end From cec92c8d3999c6ee606c6fdeb4b06c05cea0d10c Mon Sep 17 00:00:00 2001 From: Rocwo <61157993+ArdentLeKhey@users.noreply.github.com> Date: Tue, 16 Apr 2024 20:24:20 +0200 Subject: [PATCH 6/7] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index a6cabab..5677135 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,3 @@ A fixed version of Rage UI with new features to suit my projects... You can use it for your projects but please make pull requests if you find bugs, that's the point of open source 😉 +[FiveM Topic](https://forum.cfx.re/t/maintened-and-improved-rageui-repository/5222341) From 6584328d8fe00b5669b435d6fd9ee7e2114c83c3 Mon Sep 17 00:00:00 2001 From: Rocwo <61157993+ArdentLeKhey@users.noreply.github.com> Date: Tue, 16 Apr 2024 20:24:36 +0200 Subject: [PATCH 7/7] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5677135..59e9851 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ -A fixed version of Rage UI with new features to suit my projects... -You can use it for your projects but please make pull requests if you find bugs, that's the point of open source 😉 +A fixed version of Rage UI with new features to suit my projects... +You can use it for your projects but please make pull requests if you find bugs, that's the point of open source 😉 [FiveM Topic](https://forum.cfx.re/t/maintened-and-improved-rageui-repository/5222341)