Skip to content

Commit

Permalink
feat(esx/managementoutfits): Boss Managed Outfits support via Command (
Browse files Browse the repository at this point in the history
…#341)

* feat(esx/managementoutfits): Initial implementation

* Add missing translations for bossmanagedoutfits command

* Add grade check for command
  • Loading branch information
TheiLLeniumStudios authored Jul 23, 2023
1 parent b84fe2b commit 22062a1
Show file tree
Hide file tree
Showing 22 changed files with 134 additions and 26 deletions.
12 changes: 2 additions & 10 deletions client/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -413,11 +413,6 @@ local function RegisterDeleteOutfitMenu(id, parent, outfits, deleteEvent)
end

RegisterNetEvent("illenium-appearance:client:OutfitManagementMenu", function(args)
local bossMenuEvent = "qb-bossmenu:client:OpenMenu"
if args.type == "Gang" then
bossMenuEvent = "qb-gangmenu:client:OpenMenu"
end

local outfits = lib.callback.await("illenium-appearance:server:getManagementOutfits", false, args.type, Framework.GetGender())
local managementMenuID = "illenium_appearance_outfit_management_menu"
local changeManagementOutfitMenuID = "illenium_appearance_change_management_outfit_menu"
Expand All @@ -444,15 +439,12 @@ RegisterNetEvent("illenium-appearance:client:OutfitManagementMenu", function(arg
title = _L("outfits.delete.title"),
description = string.format(_L("outfits.delete.description"), args.type),
menu = deleteManagementOutfitMenuID,
},
{
title = _L("menu.returnTitle"),
icon = "fa-solid fa-angle-left",
event = bossMenuEvent
}
}
}

Management.AddBackMenuItem(managementMenu, args)

lib.registerContext(managementMenu)
lib.showContext(managementMenuID)
end)
Expand Down
14 changes: 12 additions & 2 deletions client/framework/esx/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ RegisterNetEvent("esx:setJob", function(job)
client.gang = Framework.PlayerData.job
end)

local function getRankInputValues(rankList)
local rankValues = {}
for k, v in pairs(rankList) do
rankValues[#rankValues + 1] = {
label = v.label,
value = v.grade
}
end
return rankValues
end

function Framework.GetPlayerGender()
Framework.PlayerData = ESX.GetPlayerData()
if Framework.PlayerData.sex == "f" then
Expand Down Expand Up @@ -52,10 +63,9 @@ function Framework.IsPlayerAllowed(citizenid)
return citizenid == Framework.PlayerData.identifier
end

-- Not implemented entirely
function Framework.GetRankInputValues(type)
local jobGrades = lib.callback.await("illenium-appearance:server:esx:getGradesForJob", false, client[type].name)
return jobGrades
return getRankInputValues(jobGrades)
end

function Framework.GetJobGrade()
Expand Down
27 changes: 27 additions & 0 deletions client/management/common.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
if not Config.BossManagedOutfits then return end

if Framework.ESX() then return end

function Management.RemoveItems()
if GetResourceState(Management.ResourceName) ~= "started" then return end

if Management.ItemIDs.Boss then
exports[Management.ResourceName]:RemoveBossMenuItem(Management.ItemIDs.Boss)
end
if Management.ItemIDs.Gang then
exports[Management.ResourceName]:RemoveGangMenuItem(Management.ItemIDs.Gang)
end
end

function Management.AddBackMenuItem(managementMenu, args)
local bossMenuEvent = "qb-bossmenu:client:OpenMenu"
if args.type == "Gang" then
bossMenuEvent = "qb-gangmenu:client:OpenMenu"
end

managementMenu.options[#managementMenu.options+1] = {
title = _L("menu.returnTitle"),
icon = "fa-solid fa-angle-left",
event = bossMenuEvent
}
end
15 changes: 15 additions & 0 deletions client/management/esx.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
if not Config.BossManagedOutfits then return end

if not Framework.ESX() then return end

function Management.RemoveItems()
-- Do nothing
end

function Management.AddItems()
-- Do nothing
end

function Management.AddBackMenuItem()
-- Do nothing
end
13 changes: 2 additions & 11 deletions client/management/management.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
if not Config.BossManagedOutfits then return end

Management = {}

Management.ItemIDs = {
Expand All @@ -22,14 +24,3 @@ function Management.IsQBX()
end
return false
end

function Management.RemoveItems()
if GetResourceState(Management.ResourceName) ~= "started" then return end

if Management.ItemIDs.Boss then
exports[Management.ResourceName]:RemoveBossMenuItem(Management.ItemIDs.Boss)
end
if Management.ItemIDs.Gang then
exports[Management.ResourceName]:RemoveGangMenuItem(Management.ItemIDs.Gang)
end
end
2 changes: 2 additions & 0 deletions client/management/qb.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
if not Config.BossManagedOutfits then return end

if not Management.IsQB() then return end

function Management.AddItems()
Expand Down
2 changes: 2 additions & 0 deletions client/management/qbx.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
if not Config.BossManagedOutfits then return end

if not Management.IsQBX() then return end

function Management.AddItems()
Expand Down
3 changes: 3 additions & 0 deletions fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ client_scripts {
"client/target/qb.lua",
"client/target/ox.lua",
"client/management/management.lua",
"client/management/common.lua",
"client/management/qb.lua",
"client/management/qbx.lua",
"client/management/esx.lua",
"client/radial/radial.lua",
"client/radial/qb.lua",
"client/radial/ox.lua",
Expand All @@ -53,6 +55,7 @@ server_scripts {
"server/framework/esx/main.lua",
"server/framework/esx/migrate.lua",
"server/framework/esx/callbacks.lua",
"server/framework/esx/management.lua",
"server/util.lua",
"server/server.lua",
"server/permissions.lua"
Expand Down
3 changes: 3 additions & 0 deletions locales/ar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,9 @@ Locales["ar"] = {
},
gangoutfits = {
title = "يفتح قائمة أزياء العصابات"
},
bossmanagedoutfits = {
title = "يفتح قائمة ملابس المدير"
}
},
textUI = {
Expand Down
3 changes: 3 additions & 0 deletions locales/bg.lua
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,9 @@ Locales["bg"] = {
},
gangoutfits = {
title = "Отваря менюто Gang Outfits"
},
bossmanagedoutfits = {
title = "Отваря менюто за управление на дрехи на шефа"
}
},
textUI = {
Expand Down
3 changes: 3 additions & 0 deletions locales/de.lua
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,9 @@ Locales["de"] = {
},
gangoutfits = {
title = "Öffnet das Gang-Outfits-Menü"
},
bossmanagedoutfits = {
title = "Öffnet das Menü für verwaltete Outfits des Chefs"
}
},
textUI = {
Expand Down
3 changes: 3 additions & 0 deletions locales/en.lua
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,9 @@ Locales["en"] = {
},
gangoutfits = {
title = "Opens Gang Outfits Menu"
},
bossmanagedoutfits = {
title = "Opens Boss Managed Outfits Menu"
}
},
textUI = {
Expand Down
3 changes: 3 additions & 0 deletions locales/es-ES.lua
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,9 @@ Locales["es-ES"] = {
},
gangoutfits = {
title = "Abre el menú de atuendos de pandillas"
},
bossmanagedoutfits = {
title = "Abre el menú de conjuntos gestionados por el jefe"
}
},
textUI = {
Expand Down
3 changes: 3 additions & 0 deletions locales/fr.lua
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,9 @@ Locales["fr"] = {
},
gangoutfits = {
title = "Ouvre le menu des tenues de gang"
},
bossmanagedoutfits = {
title = "Ouvre le menu des tenues gérées par le patron"
}
},
textUI = {
Expand Down
3 changes: 3 additions & 0 deletions locales/hu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,9 @@ Locales["hu"] = {
},
gangoutfits = {
title = "Megnyitja a Gang Outfits menüt"
},
bossmanagedoutfits = {
title = "Főnök által kezelt ruhák menü megnyitása"
}
},
textUI = {
Expand Down
3 changes: 3 additions & 0 deletions locales/it.lua
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,9 @@ Locales["it"] = {
},
gangoutfits = {
title = "Apre il menu degli abiti da gang"
},
bossmanagedoutfits = {
title = "Apre il menu delle outfit gestite dal capo"
}
},
textUI = {
Expand Down
3 changes: 3 additions & 0 deletions locales/nl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,9 @@ Locales["nl"] = {
},
gangoutfits = {
title = "Opent het menu Bende-outfits"
},
bossmanagedoutfits = {
title = "Opent het menu met door de baas beheerde outfits"
}
},
textUI = {
Expand Down
3 changes: 3 additions & 0 deletions locales/pt-BR.lua
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,9 @@ Locales["pt-BR"] = {
},
gangoutfits = {
title = "Abre o menu de trajes de gangue"
},
bossmanagedoutfits = {
title = "Abre o menu de roupas gerenciadas pelo chefe"
}
},
textUI = {
Expand Down
3 changes: 3 additions & 0 deletions locales/ro-RO.lua
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,9 @@ Locales["ro-RO"] = {
},
gangoutfits = {
title = "Deschide meniul Gang Outfits"
},
bossmanagedoutfits = {
title = "Deschide meniul pentru outfit-urile administrate de șef"
}
},
textUI = {
Expand Down
2 changes: 1 addition & 1 deletion server/framework/esx/callbacks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ ESX.RegisterServerCallback("esx_skin:getPlayerSkin", function(source, cb)
})
end)

lib.callback.register("illenium-appearance:server:esx:getGradesForJob", function(jobName)
lib.callback.register("illenium-appearance:server:esx:getGradesForJob", function(_, jobName)
return Database.JobGrades.GetByJobName(jobName)
end)
11 changes: 9 additions & 2 deletions server/framework/esx/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,21 @@ function Framework.RemoveMoney(src, type, money)
return false
end

function normalizeGrade(job)
job.grade = {
level = job.grade
}
return job
end

function Framework.GetJob(src)
local Player = ESX.GetPlayerFromId(src)
return Player.getJob()
return normalizeGrade(Player.getJob())
end

function Framework.GetGang(src)
local Player = ESX.GetPlayerFromId(src)
return Player.getJob()
return normalizeGrade(Player.getJob())
end

function Framework.SaveAppearance(appearance, citizenID)
Expand Down
26 changes: 26 additions & 0 deletions server/framework/esx/management.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
if Config.BossManagedOutfits then
function isBoss(grades, grade)
local highestGrade = grades[1].grade
for i = 2, #grades do
if grades[i].grade > highestGrade then
highestGrade = grades[i].grade
end
end
return highestGrade == grade
end
lib.addCommand("bossmanagedoutfits", { help = _L("commands.bossmanagedoutfits.title"), }, function(source)
local job = Framework.GetJob(source)
local grades = Database.JobGrades.GetByJobName(job.name)
if not grades then
return
end

if not isBoss(grades, job.grade.level) then
return
end

TriggerClientEvent("illenium-appearance:client:OutfitManagementMenu", source, {
type = "Job"
})
end)
end

0 comments on commit 22062a1

Please sign in to comment.