Skip to content

Commit

Permalink
refactor(radialmenu): Move logic to separate files for each framework (
Browse files Browse the repository at this point in the history
…#297)

* refactor(radialmenu): Move to logic separate files for each framework

* refactor(client): Remove unused variable
  • Loading branch information
TheiLLeniumStudios authored Apr 24, 2023
1 parent db5090d commit def920a
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 67 deletions.
73 changes: 6 additions & 67 deletions client/client.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
local client = client

local currentZone = nil
local radialOptionAdded = false

local reloadSkinTimer = GetGameTimer()

Expand Down Expand Up @@ -114,17 +113,6 @@ local function LoadPlayerUniform()
end)
end

local function RemoveRadialMenuOption()
if radialOptionAdded then
if Config.UseOxRadial then
lib.removeRadialItem("open_clothing_menu")
else
exports["qb-radialmenu"]:RemoveOption("open_clothing_menu")
end
radialOptionAdded = false
end
end

function InitAppearance()
Framework.UpdatePlayerData()
lib.callback("illenium-appearance:server:getAppearance", false, function(appearance)
Expand Down Expand Up @@ -159,9 +147,9 @@ AddEventHandler("onResourceStop", function(resource)
end
if Config.UseRadialMenu then
if Config.UseOxRadial and GetResourceState('ox_lib') == "started" then
RemoveRadialMenuOption()
Radial.RemoveOption()
elseif GetResourceState("qb-radialmenu") == "started" then
RemoveRadialMenuOption()
Radial.RemoveOption()
end
end
if Config.BossManagedOutfits then
Expand Down Expand Up @@ -878,55 +866,6 @@ RegisterNetEvent("illenium-appearance:client:ClearStuckProps", function()
end
end)

local function AddRadialMenuOption()
if not Config.UseRadialMenu then return end
if not currentZone then
RemoveRadialMenuOption()
return
end
local event, title
if currentZone.name == "clothingRoom" then
event = "illenium-appearance:client:OpenClothingRoom"
title = _L("menu.title")
elseif currentZone.name == "playerOutfitRoom" then
event = "illenium-appearance:client:OpenPlayerOutfitRoom"
title = _L("menu.outfitsTitle")
elseif currentZone.name == "clothing" then
event = "illenium-appearance:client:openClothingShopMenu"
title = _L("menu.clothingShopTitle")
elseif currentZone.name == "barber" then
event = "illenium-appearance:client:OpenBarberShop"
title = _L("menu.barberShopTitle")
elseif currentZone.name == "tattoo" then
event = "illenium-appearance:client:OpenTattooShop"
title = _L("menu.tattooShopTitle")
elseif currentZone.name == "surgeon" then
event = "illenium-appearance:client:OpenSurgeonShop"
title = _L("menu.surgeonShopTitle")
end
if Config.UseOxRadial then
lib.addRadialItem({
id = "open_clothing_menu",
icon = "shirt",
label = title,
event = event,
onSelect = function()
TriggerEvent(event)
end
})
else
exports["qb-radialmenu"]:AddOption({
id = "open_clothing_menu",
title = title,
icon = "shirt",
type = "client",
event = event,
shouldClose = true
}, "open_clothing_menu")
end
radialOptionAdded = true
end

local function isPlayerAllowedForOutfitRoom(outfitRoom)
local isAllowed = false
local count = #outfitRoom.citizenIDs
Expand Down Expand Up @@ -1023,7 +962,7 @@ local function onStoreEnter(data)
elseif currentZone.name == "surgeon" then
lib.showTextUI(prefix .. string.format(_L("textUI.surgeon"), Config.SurgeonCost), Config.TextUIOptions)
end
AddRadialMenuOption()
Radial.AddOption(currentZone)
end
end

Expand All @@ -1040,7 +979,7 @@ local function onClothingRoomEnter(data)
}
local prefix = Config.UseRadialMenu and "" or "[E] "
lib.showTextUI(prefix .. _L("textUI.clothingRoom"), Config.TextUIOptions)
AddRadialMenuOption()
Radial.AddOption(currentZone)
end
end
end
Expand All @@ -1057,13 +996,13 @@ local function onPlayerOutfitRoomEnter(data)
}
local prefix = Config.UseRadialMenu and "" or "[E] "
lib.showTextUI(prefix .. _L("textUI.playerOutfitRoom"), Config.TextUIOptions)
AddRadialMenuOption()
Radial.AddOption(currentZone)
end
end

local function onZoneExit()
currentZone = nil
RemoveRadialMenuOption()
Radial.RemoveOption()
lib.hideTextUI()
end

Expand Down
17 changes: 17 additions & 0 deletions client/radial/ox.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
if not Radial.IsOX() then return end

function Radial.Add(title, event)
lib.addRadialItem({
id = Radial.MenuID,
icon = "shirt",
label = title,
event = event,
onSelect = function()
TriggerEvent(event)
end
})
end

function Radial.Remove()
lib.removeRadialItem(Radial.MenuID)
end
16 changes: 16 additions & 0 deletions client/radial/qb.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
if not Radial.IsQB() then return end

function Radial.Add(title, event)
exports["qbx-radialmenu"]:AddOption({
id = Radial.MenuID,
title = title,
icon = "shirt",
type = "client",
event = event,
shouldClose = true
}, Radial.MenuID)
end

function Radial.Remove()
exports["qbx-radialmenu"]:RemoveOption(Radial.MenuID)
end
44 changes: 44 additions & 0 deletions client/radial/radial.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
Radial = {}

Radial.MenuID = "open_clothing_menu"

local radialOptionAdded = false

function Radial.IsOX()
return GetResourceState("ox_lib") ~= "missing" and Config.UseOxRadial
end

function Radial.IsQB()
return GetResourceState("qb-radialmenu") ~= "missing"
end

function Radial.AddOption(currentZone)
if not Config.UseRadialMenu then return end

if not currentZone then
Radial.Remove()
return
end
local event, title
local zoneEvents = {
clothingRoom = {"illenium-appearance:client:OpenClothingRoom", _L("menu.title")},
playerOutfitRoom = {"illenium-appearance:client:OpenPlayerOutfitRoom", _L("menu.outfitsTitle")},
clothing = {"illenium-appearance:client:openClothingShopMenu", _L("menu.clothingShopTitle")},
barber = {"illenium-appearance:client:OpenBarberShop", _L("menu.barberShopTitle")},
tattoo = {"illenium-appearance:client:OpenTattooShop", _L("menu.tattooShopTitle")},
surgeon = {"illenium-appearance:client:OpenSurgeonShop", _L("menu.surgeonShopTitle")},
}
if zoneEvents[currentZone.name] then
event, title = table.unpack(zoneEvents[currentZone.name])
end

Radial.Add(title, event)
radialOptionAdded = true
end

function Radial.RemoveOption()
if radialOptionAdded then
Radial.Remove()
radialOptionAdded = false
end
end
3 changes: 3 additions & 0 deletions fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ client_scripts {
"client/management/management.lua",
"client/management/qb.lua",
"client/management/qbx.lua",
"client/radial/radial.lua",
"client/radial/qb.lua",
"client/radial/ox.lua",
"client/stats.lua",
"client/defaults.lua",
"client/blips.lua",
Expand Down

0 comments on commit def920a

Please sign in to comment.