Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Lua: bugfixing + SwitchTo compatibility with radial menu
  • Loading branch information
manups4e committed Aug 3, 2023
1 parent 78f59b4 commit 039fb22
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 31 deletions.
54 changes: 54 additions & 0 deletions ScaleformUI_Lua/example.lua
Expand Up @@ -361,6 +361,57 @@ function CreateMenu()
exampleMenu:Visible(true)
end

function CreateRadialMenu()
local radialMenu = RadialMenu.New()
local txd = CreateRuntimeTxd("scaleformui")

local imgdui = CreateDui("https://giphy.com/embed/ckT59CvStmUsU", 64, 64)
CreateRuntimeTextureFromDuiHandle(txd, "item1", GetDuiHandle(imgdui))

local imgdui1 = CreateDui("https://giphy.com/embed/10bTCLE8GtHHS8", 96, 64)
CreateRuntimeTextureFromDuiHandle(txd, "item2", GetDuiHandle(imgdui1))

local imgdui2 = CreateDui("https://giphy.com/embed/nHyZigjdO4hEodq9fv", 64, 64)
CreateRuntimeTextureFromDuiHandle(txd, "item3", GetDuiHandle(imgdui2))

local item1 = SegmentItem.New("This is the label!", "~BLIP_INFO_ICON~ This is the description.. it's multiline so it can be very long!", "scaleformui", "item1", 64, 64, Colours.HUD_COLOUR_FREEMODE)
local item2 = SegmentItem.New("It's so long it scrolls automatically! Isn't this amazing?", "~BLIP_INFO_ICON~ This is the description.. it's multiline so it can be very long!", "scaleformui", "item2", 96, 64, Colours.HUD_COLOUR_GREEN)
local item3 = SegmentItem.New("Label 3", "~BLIP_INFO_ICON~ This is the description.. it's multiline so it can be very long!", "scaleformui", "item3", 64, 64, Colours.HUD_COLOUR_RED)

item1:SetQuantity(8000, 9999)
item2:SetQuantity(50, 100)
item3:SetQuantity(5000)

for i=1, 8 do
radialMenu.Segments[i]:AddItem(item1)
radialMenu.Segments[i]:AddItem(item2)
radialMenu.Segments[i]:AddItem(item3)
end

radialMenu.OnMenuOpen = function(menu, _)
ScaleformUI.Notifications:ShowSubtitle("Radial Menu opened!");
end

radialMenu.OnMenuClose = function(menu)
ScaleformUI.Notifications:ShowSubtitle("Radial Menu closed!");
end

radialMenu.OnSegmentHighlight = function(segment)
ScaleformUI.Notifications:ShowSubtitle("Segment ".. segment.Index .. " highlighted!");
end

radialMenu.OnSegmentIndexChange = function(segment, index)
ScaleformUI.Notifications:ShowSubtitle("Segment ".. segment.Index .. ", index changed to " .. index .. "!");
end

radialMenu.OnSegmentSelect = function(segment)
ScaleformUI.Notifications:ShowSubtitle("Segment ".. segment.Index .. " selected!");
end

radialMenu:Visible(true)

end

function CreatePauseMenu()
local pauseMenuExample = TabView.New("ScaleformUI LUA", "THE LUA API", GetPlayerName(PlayerId()), "String middle",
"String bottom")
Expand Down Expand Up @@ -1103,6 +1154,9 @@ CreateThread(function()
if IsControlJustPressed(0, 166) and not MenuHandler:IsAnyMenuOpen() then -- F5
CreateMenu()
end
if IsControlJustPressed(0, 57) and not MenuHandler:IsAnyMenuOpen() then -- F10
CreateRadialMenu()
end
if IsControlJustPressed(0, 167) and not MenuHandler:IsAnyMenuOpen() then -- F6
CreatePauseMenu()
end
Expand Down
4 changes: 2 additions & 2 deletions ScaleformUI_Lua/src/Menus/BreadcrumbsHandler.lua
Expand Up @@ -15,8 +15,8 @@ function BreadcrumbsHandler:PreviousMenu()
return self.breadcrumbs[#self.breadcrumbs-1]
end

function BreadcrumbsHandler:Forward(menu)
table.insert(self.breadcrumbs, menu)
function BreadcrumbsHandler:Forward(menu, data)
table.insert(self.breadcrumbs, {menu=menu, data=data})
end

function BreadcrumbsHandler:Clear()
Expand Down
61 changes: 35 additions & 26 deletions ScaleformUI_Lua/src/Menus/MenuHandler.lua
Expand Up @@ -13,45 +13,54 @@ end
---@field _currentPauseMenu table
---@field ableToDraw boolean

function MenuHandler:SwitchTo(currentMenu, newMenu, newMenuCurrentSelection, inheritOldMenuParams)
function MenuHandler:SwitchTo(currentMenu, newMenu, newMenuCurrentSelection, inheritOldMenuParams, data)
assert(currentMenu ~= nil, "The menu you're switching from cannot be null")
assert(currentMenu == self._currentMenu, "The menu you're switching from must be opened")
assert(newMenu ~= nil, "The menu you're switching to cannot be null")
assert(newMenu ~= currentMenu, "You cannot switch a menu to itself")
if BreadcrumbsHandler.SwitchInProgress then return end
BreadcrumbsHandler.SwitchInProgress = true

local current = currentMenu()
local new = newMenu()

if newMenuCurrentSelection == nil then newMenuCurrentSelection = 1 end
if inheritOldMenuParams == nil then inheritOldMenuParams = false end
if inheritOldMenuParams then
if currentMenu.TxtDictionary ~= "" and currentMenu.TxtDictionary ~= nil and currentMenu.TxtName ~= "" and currentMenu.TxtName ~= nil then
newMenu.TxtDictionary = currentMenu.TxtDictionary
newMenu.TxtName = currentMenu.TxtName
end
newMenu.Position = currentMenu.Position
if current == "UIMenu" and new == "UIMenu" then
if inheritOldMenuParams == nil then inheritOldMenuParams = false end
if inheritOldMenuParams then
if currentMenu.TxtDictionary ~= "" and currentMenu.TxtDictionary ~= nil and currentMenu.TxtName ~= "" and currentMenu.TxtName ~= nil then
newMenu.TxtDictionary = currentMenu.TxtDictionary
newMenu.TxtName = currentMenu.TxtName
end
newMenu.Position = currentMenu.Position

if currentMenu.Logo ~= nil then
newMenu.Logo = currentMenu.Logo
else
newMenu.Logo = nil
newMenu.Banner = currentMenu.Banner
end
if currentMenu.Logo ~= nil then
newMenu.Logo = currentMenu.Logo
else
newMenu.Logo = nil
newMenu.Banner = currentMenu.Banner
end

newMenu.Glare = currentMenu.Glare
newMenu.Settings.MouseControlsEnabled = currentMenu.Settings.MouseControlsEnabled
newMenu.Settings.MouseEdgeEnabled = currentMenu.Settings.MouseEdgeEnabled
newMenu:MaxItemsOnScreen(currentMenu:MaxItemsOnScreen())
newMenu:AnimationEnabled(currentMenu:AnimationEnabled())
newMenu:AnimationType(currentMenu:AnimationType())
newMenu:BuildingAnimation(currentMenu:BuildingAnimation())
newMenu:ScrollingType(currentMenu:ScrollingType())
newMenu.Glare = currentMenu.Glare
newMenu.Settings.MouseControlsEnabled = currentMenu.Settings.MouseControlsEnabled
newMenu.Settings.MouseEdgeEnabled = currentMenu.Settings.MouseEdgeEnabled
newMenu:MaxItemsOnScreen(currentMenu:MaxItemsOnScreen())
newMenu:AnimationEnabled(currentMenu:AnimationEnabled())
newMenu:AnimationType(currentMenu:AnimationType())
newMenu:BuildingAnimation(currentMenu:BuildingAnimation())
newMenu:ScrollingType(currentMenu:ScrollingType())
end
end
currentMenu:FadeOutMenu()
currentMenu:Visible(false)
newMenu:CurrentSelection(newMenuCurrentSelection)
if(current == "UIMenu") then
currentMenu:FadeOutMenu()
end
currentMenu:Visible(false)
newMenu:Visible(true)
currentMenu:FadeInMenu()
BreadcrumbsHandler:Forward(newMenu)
if(new == "UIMenu") then
newMenu:FadeInMenu()
end
BreadcrumbsHandler:Forward(newMenu, data)
BreadcrumbsHandler.SwitchInProgress = false
end

Expand Down
8 changes: 6 additions & 2 deletions ScaleformUI_Lua/src/Menus/RadialMenu/RadialMenu.lua
Expand Up @@ -121,7 +121,6 @@ function RadialMenu:Visible(bool)
ScaleformUI.Scaleforms.InstructionalButtons:ClearButtonList()
self.OnMenuClose(self)
ScaleformUI.Scaleforms._radialMenu:CallFunction("CLEAR_ALL", false)
MenuHandler._currentMenu = nil
MenuHandler.ableToDraw = false
end
else
Expand Down Expand Up @@ -215,6 +214,11 @@ function RadialMenu:ProcessControl()
end
end

function RadialMenu:SwitchTo(newMenu, newMenuCurrentSelection, inheritOldMenuParams)
MenuHandler:SwitchTo(self, newMenu, newMenuCurrentSelection, inheritOldMenuParams)
end


function RadialMenu:GoBack()
if BreadcrumbsHandler:CurrentDepth() == 1 then
self:Visible(false)
Expand All @@ -224,7 +228,7 @@ function RadialMenu:GoBack()
local prevMenu = BreadcrumbsHandler:PreviousMenu()
BreadcrumbsHandler:Backwards()
self:Visible(false)
prevMenu:Visible(true)
prevMenu.menu:Visible(true)
BreadcrumbsHandler.SwitchInProgress = false
end
end
Expand Down
2 changes: 1 addition & 1 deletion ScaleformUI_Lua/src/Menus/UIMenu/UIMenu.lua
Expand Up @@ -1185,7 +1185,7 @@ function UIMenu:GoBack(boolean)
local prevMenu = BreadcrumbsHandler:PreviousMenu()
BreadcrumbsHandler:Backwards()
self:Visible(false)
prevMenu:Visible(true)
prevMenu.menu:Visible(true)
BreadcrumbsHandler.SwitchInProgress = false
end
end
Expand Down

0 comments on commit 039fb22

Please sign in to comment.