From 2ff524c9b7f7cca094f8261a3e1f2f361b3afbfe Mon Sep 17 00:00:00 2001 From: Baphomet <14003970+ImBaphomettt@users.noreply.github.com> Date: Wed, 5 Apr 2023 23:07:34 +0200 Subject: [PATCH 01/13] Update README.md --- README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/README.md b/README.md index 621a7f8..aaf889b 100644 --- a/README.md +++ b/README.md @@ -1,3 +1 @@ -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. +discontinued project. From ca410ccf85220272c5c7f9c689f832612c05a467 Mon Sep 17 00:00:00 2001 From: Baphomet <14003970+ImBaphomettt@users.noreply.github.com> Date: Mon, 17 Apr 2023 06:40:57 +0200 Subject: [PATCH 02/13] It's time to say goodbye. --- README.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index aaf889b..b130e7c 100644 --- a/README.md +++ b/README.md @@ -1 +1,11 @@ -discontinued project. +Dear developer, + +I wish to announce this final message to all users of my library. First of all, I want to express my gratitude to all the people who contributed to the development of this library. Unfortunately, I must inform you that it will no longer receive updates or additional content. Although I appreciate your support, I no longer find the pleasure I experienced during the creation of this open-source project. + +The development community has changed significantly and no longer aligns with my ambitions for the platform. Since the commercialization of scripts, the way of contributing to a platform that was once very close to its community of developers has radically changed. Now, there are multiple paid resources, between $10 and $20, for simple rage menus that call 2 GTA natives. I consider this to be theft, given that people are earning money by using our work, while these mediocre things are mainly a simple menu with options without any real work behind them. + +To answer many questions, yes, you can use this library for commercial purposes. Anyway, many people have not waited for my permission to do so. + +I want to thank everyone who helped create this reputation through their contributions or aggressive use of OUR work. I wish you all the best in the FiveM development community. + +Sincerely Baphomet (iTexZoz). From a370a6bcf487e144fe487c7f6a00925038a63055 Mon Sep 17 00:00:00 2001 From: GMW Scripts | Junior Developer <79488475+GermanWarthog@users.noreply.github.com> Date: Fri, 1 Mar 2024 01:19:15 +0100 Subject: [PATCH 03/13] updated RageUI and fixed some lint and code errors --- example.lua | 1 + src/Menu.lua | 10 +++++++--- src/components/Audio.lua | 6 ++---- src/components/Graphics.lua | 1 + src/components/Keys.lua | 1 - src/items/Items.lua | 7 ++++--- src/items/Panels.lua | 6 +++--- 7 files changed, 18 insertions(+), 14 deletions(-) diff --git a/example.lua b/example.lua index 8a134cc..f186837 100644 --- a/example.lua +++ b/example.lua @@ -1,3 +1,4 @@ +---@diagnostic disable: missing-parameter, inject-field, param-type-mismatch, need-check-nil --- --- @author Dylan MALANDAIN, Kalyptus --- @version 1.0.0 diff --git a/src/Menu.lua b/src/Menu.lua index 847ee9f..6015f7c 100644 --- a/src/Menu.lua +++ b/src/Menu.lua @@ -1,3 +1,4 @@ +---@diagnostic disable: missing-parameter, undefined-field, inject-field, param-type-mismatch --- --- @author Dylan MALANDAIN, Kalyptus --- @version 1.0.0 @@ -94,7 +95,7 @@ end ---@param G number ---@param B number ---@param A number ----@return RageUIMenus +---@return RageUIMenus | nil ---@public function RageUI.CreateSubMenu(ParentMenu, Title, Subtitle, X, Y, TextureDictionary, TextureName, R, G, B, A) if ParentMenu ~= nil then @@ -167,6 +168,7 @@ function RageUIMenus:RemoveInstructionButton(button) end end +---@param Visible boolean function RageUIMenus:UpdateInstructionalButtons(Visible) if not Visible then @@ -221,7 +223,7 @@ end ---IsVisible ---@param Item fun(Item:Items) ----@param Panel fun(Panel:Panels +---@param Panel fun(Panel:Panels) function RageUIMenus:IsVisible(Item, Panel) if (RageUI.Visible(self)) and (UpdateOnscreenKeyboard() ~= 0) and (UpdateOnscreenKeyboard() ~= 3) then RageUI.Banner() @@ -230,7 +232,9 @@ function RageUIMenus:IsVisible(Item, Panel) RageUI.Background(); RageUI.Navigation(); RageUI.Description(); - Panel(Panels); + if Panel then + Panel(Panels); + end RageUI.PoolMenus.Timer = 1 RageUI.Render() end diff --git a/src/components/Audio.lua b/src/components/Audio.lua index b2efb01..6199869 100644 --- a/src/components/Audio.lua +++ b/src/components/Audio.lua @@ -12,7 +12,7 @@ Audio = {} --- ---@param Library string ---@param Sound string ----@param IsLooped boolean +---@param IsLooped? boolean ---@return nil ---@public function Audio.PlaySound(Library, Sound, IsLooped) @@ -31,6 +31,4 @@ function Audio.PlaySound(Library, Sound, IsLooped) end) end end -end - - +end \ No newline at end of file diff --git a/src/components/Graphics.lua b/src/components/Graphics.lua index 3e947af..66d413e 100644 --- a/src/components/Graphics.lua +++ b/src/components/Graphics.lua @@ -1,3 +1,4 @@ +---@diagnostic disable: missing-parameter, redefined-local, undefined-field --- --- @author Dylan MALANDAIN, Kalyptus --- @version 1.0.0 diff --git a/src/components/Keys.lua b/src/components/Keys.lua index a69bd24..c391a05 100644 --- a/src/components/Keys.lua +++ b/src/components/Keys.lua @@ -11,7 +11,6 @@ Keys = {}; ---@param ControlName string ---@param Description string ---@param Action function ----@return Keys ---@public function Keys.Register(Controls, ControlName, Description, Action) RegisterKeyMapping(string.format('keys-%s', ControlName), Description, "keyboard", Controls) diff --git a/src/items/Items.lua b/src/items/Items.lua index d3d4c3d..82b7c30 100644 --- a/src/items/Items.lua +++ b/src/items/Items.lua @@ -1,3 +1,4 @@ +---@diagnostic disable: cast-local-type, undefined-global --- --- @author Dylan MALANDAIN, Kalyptus --- @version 1.0.0 @@ -55,7 +56,7 @@ Items = {} ---@param Actions fun(onSelected:boolean, onActive:boolean) ---@param Submenu any ---@public ----@return void +---@return nil function Items:AddButton(Label, Description, Style, Actions, Submenu) local CurrentMenu = RageUI.CurrentMenu local Option = RageUI.Options + 1 @@ -220,7 +221,7 @@ end --- ---@param Label string ---@public ----@return void +---@return nil function Items:AddSeparator(Label) local CurrentMenu = RageUI.CurrentMenu local Option = RageUI.Options + 1 @@ -251,7 +252,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, active:boolean)) ---@param Submenu any function Items:AddList(Label, Items, Index, Description, Style, Actions, Submenu) local CurrentMenu = RageUI.CurrentMenu; diff --git a/src/items/Panels.lua b/src/items/Panels.lua index eda8781..27acbe0 100644 --- a/src/items/Panels.lua +++ b/src/items/Panels.lua @@ -116,7 +116,7 @@ end ---@param Action fun(X:number, Y:number, CharacterX:number, CharacterY:number) ---@param Index number ---@public ----@return void +---@return nil function Panels:Grid(StartedX, StartedY, TopText, BottomText, LeftText, RightText, Action, Index) UIGridPanel(GridType.Default, StartedX, StartedY, TopText, BottomText, LeftText, RightText, Action, Index) end @@ -128,7 +128,7 @@ end ---@param Action fun(X:number, Y:number, CharacterX:number, CharacterY:number) ---@param Index number ---@public ----@return void +---@return nil function Panels:GridHorizontal(StartedX, LeftText, RightText, Action, Index) UIGridPanel(GridType.Horizontal, StartedX, nil, nil, nil, LeftText, RightText, Action, Index) end @@ -140,7 +140,7 @@ end ---@param Action fun(X:number, Y:number, CharacterX:number, CharacterY:number) ---@param Index number ---@public ----@return void +---@return nil function Panels:GridVertical(StartedY, TopText, BottomText, Action, Index) UIGridPanel(GridType.Vertical, nil, StartedY, TopText, BottomText, nil, nil, Action, Index) end From d04e239701aa67c2d859e84a57f00a19860e9370 Mon Sep 17 00:00:00 2001 From: GMW Scripts | Junior Developer <79488475+GermanWarthog@users.noreply.github.com> Date: Thu, 11 Apr 2024 14:46:29 +0200 Subject: [PATCH 04/13] resolved type issues (should be improved in the future) --- example.lua | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/example.lua b/example.lua index 8a134cc..f8a520f 100644 --- a/example.lua +++ b/example.lua @@ -7,7 +7,7 @@ local MainMenu = RageUI.CreateMenu("Title", "SUBTITLE"); MainMenu.EnableMouse = true; -local SubMenu = RageUI.CreateSubMenu(MainMenu, "Title", "SubTitle") +local SubMenu = RageUI.CreateSubMenu(MainMenu, "Title", "SubTitle") --[[@as RageUIMenus (change return vaules to mach type?)]] local Checked = false; local ListIndex = 1; @@ -18,7 +18,7 @@ function RageUI.PoolMenus:Example() MainMenu:IsVisible(function(Items) Items:Heritage(1, 2) Items:AddButton("Sub Menu", "Sub Menu", { IsDisabled = false }, function(onSelected) - + end, SubMenu) Items:AddButton("Hello world", "Hello world.", { IsDisabled = false }, function(onSelected) @@ -34,8 +34,6 @@ function RageUI.PoolMenus:Example() Checked = IsChecked end end) - - end, function(Panels) Panels:Grid(GridX, GridY, "Top", "Bottom", "Left", "Right", function(X, Y, CharacterX, CharacterY) GridX = X; From 8735919d6ffdb8252f9f40f1e8d676ee62f8f090 Mon Sep 17 00:00:00 2001 From: GMW Scripts | Junior Developer <79488475+GermanWarthog@users.noreply.github.com> Date: Thu, 11 Apr 2024 14:46:44 +0200 Subject: [PATCH 05/13] ignore .vscode --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0dc7b4b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/.vscode \ No newline at end of file From 7c6f3b3d6bf21eba54922ee8772da9abb573c08d Mon Sep 17 00:00:00 2001 From: GMW Scripts | Junior Developer <79488475+GermanWarthog@users.noreply.github.com> Date: Thu, 11 Apr 2024 14:47:36 +0200 Subject: [PATCH 06/13] updated param, return and field types; refactored some code; resolved issues --- src/Menu.lua | 84 +++++++++++++++++++++++++++------------------------- 1 file changed, 44 insertions(+), 40 deletions(-) diff --git a/src/Menu.lua b/src/Menu.lua index a71dde8..4e45f1e 100644 --- a/src/Menu.lua +++ b/src/Menu.lua @@ -8,14 +8,14 @@ ---CreateMenu ---@param Title string ---@param Subtitle string ----@param X number ----@param Y number ----@param TextureDictionary string ----@param TextureName string ----@param R number ----@param G number ----@param B number ----@param A number +---@param X number? +---@param Y number? +---@param TextureDictionary string? +---@param TextureName string? +---@param R number? +---@param G number? +---@param B number? +---@param A number? ---@return RageUIMenus ---@public function RageUI.CreateMenu(Title, Subtitle, X, Y, TextureDictionary, TextureName, R, G, B, A) @@ -79,42 +79,46 @@ function RageUI.CreateMenu(Title, Subtitle, X, Y, TextureDictionary, TextureName end end) - return setmetatable(Menu, RageUIMenus) + return setmetatable(Menu, RageUIMenus) --[[@as RageUIMenus]] end ---CreateSubMenu ----@param ParentMenu function +---@param ParentMenu function | RageUIMenus ---@param Title string ---@param Subtitle string ----@param X number ----@param Y number ----@param TextureDictionary string ----@param TextureName string ----@param R number ----@param G number ----@param B number ----@param A number ----@return RageUIMenus +---@param X number? +---@param Y number? +---@param TextureDictionary string? +---@param TextureName string? +---@param R number? +---@param G number? +---@param B number? +---@param A number? +---@return RageUIMenus | nil ---@public function RageUI.CreateSubMenu(ParentMenu, Title, Subtitle, X, Y, TextureDictionary, TextureName, R, G, B, A) - if ParentMenu ~= nil then - if ParentMenu() then - local Menu = RageUI.CreateMenu(Title or ParentMenu.Title, string.upper(Subtitle) or string.upper(ParentMenu.Subtitle), X or ParentMenu.X, Y or ParentMenu.Y) - Menu.Parent = ParentMenu - Menu.WidthOffset = ParentMenu.WidthOffset - Menu.Safezone = ParentMenu.Safezone - if ParentMenu.Sprite then - Menu.Sprite = { Dictionary = TextureDictionary or ParentMenu.Sprite.Dictionary, Texture = TextureName or ParentMenu.Sprite.Texture, Color = { R = R or ParentMenu.Sprite.Color.R, G = G or ParentMenu.Sprite.Color.G, B = B or ParentMenu.Sprite.Color.B, A = A or ParentMenu.Sprite.Color.A } } - else - Menu.Rectangle = ParentMenu.Rectangle - end - return setmetatable(Menu, RageUIMenus) - else - return nil - end + if ParentMenu == nil then + return + end + + -- Why is this a function & why do we call it here ??? + if not ParentMenu() then + return + end + + local Menu = RageUI.CreateMenu(Title or ParentMenu.Title --[[@as string (change ParentMenu behaviour)]], string.upper(Subtitle) or string.upper(ParentMenu.Subtitle --[[@as string (change ParentMenu behaviour)]]), X or ParentMenu.X --[[@as number (change ParentMenu behaviour)]], Y or ParentMenu.Y --[[@as number (change ParentMenu behaviour)]]) + + Menu.Parent = ParentMenu --[[@as RageUIMenus]] + Menu.WidthOffset = Menu.Parent.WidthOffset + Menu.Safezone = Menu.Parent.Safezone + + if Menu.Parent.Sprite then + Menu.Sprite = { Dictionary = TextureDictionary or Menu.Parent.Sprite.Dictionary, Texture = TextureName or Menu.Parent.Sprite.Texture, Color = { R = R or Menu.Parent.Sprite.Color.R, G = G or Menu.Parent.Sprite.Color.G, B = B or Menu.Parent.Sprite.Color.B, A = A or Menu.Parent.Sprite.Color.A } } else - return nil + Menu.Rectangle = Menu.Parent.Rectangle end + + return setmetatable(Menu, RageUIMenus) end ---SetSubtitle @@ -144,7 +148,7 @@ end function RageUIMenus:AddInstructionButton(button) if type(button) == "table" and #button == 2 then table.insert(self.InstructionalButtons, button) - self.UpdateInstructionalButtons(true); + self:UpdateInstructionalButtons(true); end end @@ -153,7 +157,7 @@ function RageUIMenus:RemoveInstructionButton(button) for i = 1, #self.InstructionalButtons do if button == self.InstructionalButtons[i] then table.remove(self.InstructionalButtons, i) - self.UpdateInstructionalButtons(true); + self:UpdateInstructionalButtons(true); break end end @@ -161,14 +165,14 @@ function RageUIMenus:RemoveInstructionButton(button) if tonumber(button) then if self.InstructionalButtons[tonumber(button)] then table.remove(self.InstructionalButtons, tonumber(button)) - self.UpdateInstructionalButtons(true); + self:UpdateInstructionalButtons(true); end end end end +---@param Visible boolean function RageUIMenus:UpdateInstructionalButtons(Visible) - if not Visible then return end @@ -221,7 +225,7 @@ end ---IsVisible ---@param Item fun(Item:Items) ----@param Panel fun(Panel:Panels +---@param Panel fun(Panel:Panels) function RageUIMenus:IsVisible(Item, Panel) if (RageUI.Visible(self)) and (UpdateOnscreenKeyboard() ~= 0) and (UpdateOnscreenKeyboard() ~= 3) then RageUI.Banner() From e07cd10432da7ca51d061798eb5c37c6f84d84b3 Mon Sep 17 00:00:00 2001 From: GMW Scripts | Junior Developer <79488475+GermanWarthog@users.noreply.github.com> Date: Thu, 11 Apr 2024 14:49:38 +0200 Subject: [PATCH 07/13] added new RageUIMenus field types --- src/RageUI.lua | 43 +++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/src/RageUI.lua b/src/RageUI.lua index 66094bd..b33ffb6 100644 --- a/src/RageUI.lua +++ b/src/RageUI.lua @@ -7,6 +7,17 @@ RageUI = {}; ---@class RageUIMenus +---@field InstructionalButtons table +---@field InstructionalScaleform number +---@field Closable boolean +---@field Parent RageUIMenus +---@field WidthOffset number +---@field Safezone number +---@field Sprite any (todo) +---@field Rectangle any (todo) +---@field X number +---@field Y number +---@field EnableMouse boolean RageUIMenus = setmetatable({}, RageUIMenus) ---@return boolean @@ -134,8 +145,8 @@ RageUI.Settings = { }, Enabled = { Controller = { - { 0, 2 }, -- Look Up and Down - { 0, 1 }, -- Look Left and Right + { 0, 2 }, -- Look Up and Down + { 0, 1 }, -- Look Left and Right { 0, 25 }, -- Aim { 0, 24 }, -- Attack }, @@ -153,20 +164,20 @@ RageUI.Settings = { { 0, 241 }, -- Scroll up { 0, 239 }, -- Cursor X { 0, 240 }, -- Cursor Y - { 0, 31 }, -- Move Up and Down - { 0, 30 }, -- Move Left and Right - { 0, 21 }, -- Sprint - { 0, 22 }, -- Jump - { 0, 23 }, -- Enter - { 0, 75 }, -- Exit Vehicle - { 0, 71 }, -- Accelerate Vehicle - { 0, 72 }, -- Vehicle Brake - { 0, 59 }, -- Move Vehicle Left and Right - { 0, 89 }, -- Fly Yaw Left - { 0, 9 }, -- Fly Left and Right - { 0, 8 }, -- Fly Up and Down - { 0, 90 }, -- Fly Yaw Right - { 0, 76 }, -- Vehicle Handbrake + { 0, 31 }, -- Move Up and Down + { 0, 30 }, -- Move Left and Right + { 0, 21 }, -- Sprint + { 0, 22 }, -- Jump + { 0, 23 }, -- Enter + { 0, 75 }, -- Exit Vehicle + { 0, 71 }, -- Accelerate Vehicle + { 0, 72 }, -- Vehicle Brake + { 0, 59 }, -- Move Vehicle Left and Right + { 0, 89 }, -- Fly Yaw Left + { 0, 9 }, -- Fly Left and Right + { 0, 8 }, -- Fly Up and Down + { 0, 90 }, -- Fly Yaw Right + { 0, 76 }, -- Vehicle Handbrake }, }, }, From 377107f7ba11be6a01042d19f8e7571aacebc7d7 Mon Sep 17 00:00:00 2001 From: GMW Scripts | Junior Developer <79488475+GermanWarthog@users.noreply.github.com> Date: Thu, 11 Apr 2024 14:49:48 +0200 Subject: [PATCH 08/13] updated param type --- src/components/Audio.lua | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/components/Audio.lua b/src/components/Audio.lua index b2efb01..f100c05 100644 --- a/src/components/Audio.lua +++ b/src/components/Audio.lua @@ -12,7 +12,7 @@ Audio = {} --- ---@param Library string ---@param Sound string ----@param IsLooped boolean +---@param IsLooped boolean? ---@return nil ---@public function Audio.PlaySound(Library, Sound, IsLooped) @@ -32,5 +32,3 @@ function Audio.PlaySound(Library, Sound, IsLooped) end end end - - From 92aff14c4a51d468f318879f954eb8f68555f9de Mon Sep 17 00:00:00 2001 From: GMW Scripts | Junior Developer <79488475+GermanWarthog@users.noreply.github.com> Date: Thu, 11 Apr 2024 14:50:11 +0200 Subject: [PATCH 09/13] resolved missing-param issue --- src/components/Graphics.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/Graphics.lua b/src/components/Graphics.lua index 3e947af..3bc189c 100644 --- a/src/components/Graphics.lua +++ b/src/components/Graphics.lua @@ -124,6 +124,7 @@ function Graphics.ScreenToWorld(distance, flags) local mouse = vector2(GetControlNormal(2, 239), GetControlNormal(2, 240)) local cam3DPos, forwardDir = Graphics.ScreenRelToWorld(camPos, camRot, mouse) local direction = camPos + forwardDir * distance + ---@diagnostic disable-next-line: missing-parameter local rayHandle = StartExpensiveSynchronousShapeTestLosProbe(cam3DPos, direction, flags, 0, 0) local _, hit, endCoords, surfaceNormal, entityHit = GetShapeTestResult(rayHandle) return (hit == 1 and true or false), endCoords, surfaceNormal, entityHit, (entityHit >= 1 and GetEntityType(entityHit) or 0), direction, mouse @@ -160,4 +161,4 @@ end function Graphics.World3DToScreen2D(pos) local _, sX, sY = GetScreenCoordFromWorldCoord(pos.x, pos.y, pos.z) return vector2(sX, sY) -end \ No newline at end of file +end From 0ed26976432c9fe5063bfa7362706bceae4b0880 Mon Sep 17 00:00:00 2001 From: GMW Scripts | Junior Developer <79488475+GermanWarthog@users.noreply.github.com> Date: Thu, 11 Apr 2024 14:50:27 +0200 Subject: [PATCH 10/13] removed unused return value --- src/components/Keys.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/components/Keys.lua b/src/components/Keys.lua index a69bd24..ad804e4 100644 --- a/src/components/Keys.lua +++ b/src/components/Keys.lua @@ -11,7 +11,6 @@ Keys = {}; ---@param ControlName string ---@param Description string ---@param Action function ----@return Keys ---@public function Keys.Register(Controls, ControlName, Description, Action) RegisterKeyMapping(string.format('keys-%s', ControlName), Description, "keyboard", Controls) @@ -20,4 +19,4 @@ function Keys.Register(Controls, ControlName, Description, Action) Action(); end end, false) -end \ No newline at end of file +end From 875fdb890bd6688ed3568e07e673b13857247f13 Mon Sep 17 00:00:00 2001 From: GMW Scripts | Junior Developer <79488475+GermanWarthog@users.noreply.github.com> Date: Thu, 11 Apr 2024 14:50:57 +0200 Subject: [PATCH 11/13] added clamp function & resolved duplicate var field warning --- src/components/Util.lua | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/components/Util.lua b/src/components/Util.lua index dc424b7..c9577ad 100644 --- a/src/components/Util.lua +++ b/src/components/Util.lua @@ -5,11 +5,19 @@ --- function math.round(num, numDecimalPlaces) - return tonumber(string.format("%." .. (numDecimalPlaces or 0) .. "f", num)) + return tonumber(string.format("%." .. (numDecimalPlaces or 0) .. "f", num)) end function string.starts(String, Start) - return string.sub(String, 1, string.len(Start)) == Start + return string.sub(String, 1, string.len(Start)) == Start +end + +---@param value number +---@param min number +---@param max number +---@return number +function math.clamp(value, min, max) + return math.max(min, math.min(value, max)) end local up_trans = { @@ -33,6 +41,9 @@ local up_trans = { } local old_upper = string.upper + + +---@diagnostic disable-next-line: duplicate-set-field function string.upper(str) local res = old_upper(str) for k, v in pairs(up_trans) do @@ -43,4 +54,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 147b81816be6fc36d7dada11514d194f2a673e75 Mon Sep 17 00:00:00 2001 From: GMW Scripts | Junior Developer <79488475+GermanWarthog@users.noreply.github.com> Date: Thu, 11 Apr 2024 14:52:01 +0200 Subject: [PATCH 12/13] replaced void with nil, refactored some code, resolved errors & updated typings --- src/items/Items.lua | 130 +++++++++++++++++++++----------------------- 1 file changed, 61 insertions(+), 69 deletions(-) diff --git a/src/items/Items.lua b/src/items/Items.lua index 8f02ac3..cefdc8f 100644 --- a/src/items/Items.lua +++ b/src/items/Items.lua @@ -9,13 +9,16 @@ local ItemsSettings = { CheckBox = { Textures = { "shop_box_blankb", -- 1 - "shop_box_tickb", -- 2 - "shop_box_blank", -- 3 - "shop_box_tick", -- 4 + "shop_box_tickb", -- 2 + "shop_box_blank", -- 3 + "shop_box_tick", -- 4 "shop_box_crossb", -- 5 - "shop_box_cross", -- 6 + "shop_box_cross", -- 6 }, - X = 380, Y = -6, Width = 50, Height = 50 + X = 380, + Y = -6, + Width = 50, + Height = 50 }, Rectangle = { Y = 0, Width = 431, Height = 38 @@ -55,7 +58,7 @@ Items = {} ---@param Actions fun(onSelected:boolean, onActive:boolean) ---@param Submenu any ---@public ----@return void +---@return nil function Items:AddButton(Label, Description, Style, Actions, Submenu) if Submenu then Style.RightLabel = '→' @@ -135,7 +138,6 @@ function Items:CheckBox(Label, Description, Checked, Style, Actions) local Option = RageUI.Options + 1 if CurrentMenu.Pagination.Minimum <= Option and CurrentMenu.Pagination.Maximum >= Option then - local Active = CurrentMenu.Index == Option; local Selected = false; local LeftBadgeOffset = ((Style.LeftBadge == RageUI.BadgeStyle.None or Style.LeftBadge == nil) and 0 or 27) @@ -184,12 +186,12 @@ function Items:CheckBox(Label, Description, Checked, Style, Actions) 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) - BoxOffset = MeasureStringWidth(Style.RightLabel, 0, 0.35) + BoxOffset = Graphics.MeasureStringWidth(Style.RightLabel, 0, 0.35) end else 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, 245, 245, 245, 255, 2) - BoxOffset = MeasureStringWidth(Style.RightLabel, 0, 0.35) + BoxOffset = Graphics.MeasureStringWidth(Style.RightLabel, 0, 0.35) end end @@ -228,7 +230,7 @@ end --- ---@param Label string ---@public ----@return void +---@return nil function Items:AddSeparator(Label) local CurrentMenu = RageUI.CurrentMenu local Option = RageUI.Options + 1 @@ -257,10 +259,10 @@ end ---@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 +---@param Description string? +---@param Style table +---@param Actions fun(Index:number, onSelected:boolean, onListChange:boolean, Active:boolean?, Items:table?) +---@param Submenu RageUIMenus? function Items:AddList(Label, Items, Index, Description, Style, Actions, Submenu) local CurrentMenu = RageUI.CurrentMenu; @@ -282,11 +284,11 @@ function Items:AddList(Label, Items, Index, Description, Style, Actions, Submenu 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) + RightOffset = Graphics.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) + RightOffset = Graphics.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 @@ -378,7 +380,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, Active:boolean?, Items:table?) ---@param Submenu any function Items:AddList2(Label, Items, Index, NameCB, Description, Style, Actions, Submenu) local CurrentMenu = RageUI.CurrentMenu; @@ -403,11 +405,11 @@ function Items:AddList2(Label, Items, Index, NameCB, Description, Style, Actions 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) + RightOffset = Graphics.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) + RightOffset = Graphics.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 @@ -493,7 +495,6 @@ function Items:AddList2(Label, Items, Index, NameCB, Description, Style, Actions RageUI.Options = RageUI.Options + 1 end - local list_stock = {} ---AddList @@ -536,11 +537,11 @@ function Items:AddAutoList(Label, Items, FirstIndex, Description, Style, Actions 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) + RightOffset = Graphics.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) + RightOffset = Graphics.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 @@ -633,10 +634,10 @@ local range_stock = {} ---AddList ---@param Label string ----@param Items table +---@param Range 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 Actions fun(Index:number, onSelected:boolean, onListChange:boolean, isActive:boolean, Item:any, Items:table, SetIndex: fun(newIndex:boolean)) ---@param Submenu any function Items:AddRange(Label, Range, FirstIndex, NameCB, Description, Style, Actions, Submenu) local CurrentMenu = RageUI.CurrentMenu; @@ -685,11 +686,11 @@ function Items:AddRange(Label, Range, FirstIndex, NameCB, Description, Style, Ac 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) + RightOffset = Graphics.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) + RightOffset = Graphics.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 @@ -778,61 +779,52 @@ function Items:AddRange(Label, Range, FirstIndex, NameCB, Description, Style, Ac 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) -]] +---> what is this for? Tests? +-- 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 function Items:Heritage(Mum, Dad) local CurrentMenu = RageUI.CurrentMenu; - if Mum < 0 or Mum > 21 then - Mum = 0 - end - if Dad < 0 or Dad > 23 then - Dad = 0 - end - if Mum == 21 then - Mum = "special_female_" .. (tonumber(string.sub(Mum, 2, 2)) - 1) - else - Mum = "female_" .. Mum - end - if Dad >= 21 then - Dad = "special_male_" .. (tonumber(string.sub(Dad, 2, 2)) - 1) - else - Dad = "male_" .. Dad - end + + Mum = math.clamp(Mum, 0, 21) + Dad = math.clamp(Dad, 0, 23) + + local mum = (Mum == 21) and "special_female_" .. (tonumber(string.sub(Mum, 2, 2)) - 1) or "female_" .. Mum + local dad = (Dad >= 21) and "special_male_" .. (tonumber(string.sub(Dad, 2, 2)) - 1) or "male_" .. Dad + Graphics.Sprite("pause_menu_pages_char_mom_dad", "mumdadbg", CurrentMenu.X, CurrentMenu.Y + CurrentMenu.SubtitleHeight + RageUI.ItemOffset, 431 + (CurrentMenu.WidthOffset / 1), 228) - 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) + 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 +-- What even is this for?? ---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 +-- ---@param Label string +-- ---@param Description string +-- ---@param Style table +-- ---@param Actions fun(onSelected:boolean, onActive:boolean, Text:string) +-- ---@public +-- ---@return nil +-- 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 From d1fb71a6f94c0f0442e5092bd2e7e5c608999044 Mon Sep 17 00:00:00 2001 From: GMW Scripts | Junior Developer <79488475+GermanWarthog@users.noreply.github.com> Date: Thu, 11 Apr 2024 14:52:22 +0200 Subject: [PATCH 13/13] replaced wring types --- src/items/Panels.lua | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/items/Panels.lua b/src/items/Panels.lua index 8c119b2..1fc81be 100644 --- a/src/items/Panels.lua +++ b/src/items/Panels.lua @@ -116,7 +116,7 @@ end ---@param Action fun(X:number, Y:number, CharacterX:number, CharacterY:number) ---@param Index number ---@public ----@return void +---@return nil function Panels:Grid(StartedX, StartedY, TopText, BottomText, LeftText, RightText, Action, Index) UIGridPanel(GridType.Default, StartedX, StartedY, TopText, BottomText, LeftText, RightText, Action, Index) end @@ -128,7 +128,7 @@ end ---@param Action fun(X:number, Y:number, CharacterX:number, CharacterY:number) ---@param Index number ---@public ----@return void +---@return nil function Panels:GridHorizontal(StartedX, LeftText, RightText, Action, Index) UIGridPanel(GridType.Horizontal, StartedX, nil, nil, nil, LeftText, RightText, Action, Index) end @@ -140,12 +140,11 @@ end ---@param Action fun(X:number, Y:number, CharacterX:number, CharacterY:number) ---@param Index number ---@public ----@return void +---@return nil 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 }, @@ -164,25 +163,23 @@ local Colour = { ---@param Callback function ---@return nil ---@public ----@return void +---@return nil 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 + ---@type boolean 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 + ---@type boolean 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 @@ -267,7 +264,6 @@ function Panels:Percent(Percent, HeaderText, MinText, MaxText, Callback, Index) 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) @@ -320,4 +316,4 @@ function Panels:Percent(Percent, HeaderText, MinText, MaxText, Callback, Index) Callback(Hovered, Selected, Percent) end end -end \ No newline at end of file +end