Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.vscode
7 changes: 3 additions & 4 deletions example.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---@diagnostic disable: missing-parameter, inject-field, param-type-mismatch, need-check-nil
---
--- @author Dylan MALANDAIN, Kalyptus
--- @version 1.0.0
Expand All @@ -7,7 +8,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?)]]

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vaules -> values


local Checked = false;
local ListIndex = 1;
Expand All @@ -18,7 +19,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)

Expand All @@ -34,8 +35,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;
Expand Down
85 changes: 45 additions & 40 deletions src/Menu.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---@diagnostic disable: missing-parameter, undefined-field, inject-field, param-type-mismatch
---
--- @author Dylan MALANDAIN, Kalyptus
--- @version 1.0.0
Expand All @@ -8,14 +9,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)
Expand Down Expand Up @@ -79,42 +80,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
Expand Down Expand Up @@ -144,7 +149,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

Expand All @@ -153,22 +158,22 @@ 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
else
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
Expand Down Expand Up @@ -221,7 +226,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()
Expand Down
43 changes: 27 additions & 16 deletions src/RageUI.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
},
Expand All @@ -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
},
},
},
Expand Down
4 changes: 1 addition & 3 deletions src/components/Audio.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -32,5 +32,3 @@ function Audio.PlaySound(Library, Sound, IsLooped)
end
end
end


4 changes: 3 additions & 1 deletion src/components/Graphics.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---@diagnostic disable: missing-parameter, redefined-local, undefined-field
---
--- @author Dylan MALANDAIN, Kalyptus
--- @version 1.0.0
Expand Down Expand Up @@ -124,6 +125,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
Expand Down Expand Up @@ -160,4 +162,4 @@ end
function Graphics.World3DToScreen2D(pos)
local _, sX, sY = GetScreenCoordFromWorldCoord(pos.x, pos.y, pos.z)
return vector2(sX, sY)
end
end
3 changes: 1 addition & 2 deletions src/components/Keys.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -20,4 +19,4 @@ function Keys.Register(Controls, ControlName, Description, Action)
Action();
end
end, false)
end
end
17 changes: 14 additions & 3 deletions src/components/Util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,19 @@
---

function math.round(num, numDecimalPlaces)

@RocwoDev RocwoDev Apr 16, 2024

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New round function is :

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

Pull request : #3

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 = {
Expand All @@ -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
Expand All @@ -43,4 +54,4 @@ end

function string.FirstUp(str)
return string.upper(string.sub(str, 1, 1)) .. string.sub(str, 2)
end
end
Loading