Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Favorite Outfits System #439

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
49 changes: 44 additions & 5 deletions client/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,33 @@ local function RegisterChangeOutfitMenu(id, parent, outfits, mType)
menu = parent,
options = {}
}

local allOutfits, favoriteOutfits = {}, {}
local favoriteButton = {
title = _L("outfits.favorite.title"),
description = _L("outfits.favorite.description"),
icon = 'star',
onSelect = function()
local input = lib.inputDialog(_L("outfits.favorite.input"), {
{type = 'multi-select', clearable = true, searchable = true, default = favoriteOutfits, options = allOutfits}
})
if not input then return end
local newFavoriteOutfits = {}
for _, v in pairs(input[1]) do
for _, outfit in pairs(allOutfits) do
if v == outfit.value then
newFavoriteOutfits[#newFavoriteOutfits + 1] = outfit.value
end
end
end
TriggerServerEvent("illenium-appearance:server:favoriteOutfits", newFavoriteOutfits)
end
}

local favoritesSection, outfitsSection = {}, {}
for i = 1, #outfits, 1 do
changeOutfitMenu.options[#changeOutfitMenu.options + 1] = {
if not outfits[i].name then return end
local data = {
title = outfits[i].name,
description = outfits[i].model,
event = "illenium-appearance:client:changeOutfit",
Expand All @@ -334,14 +359,28 @@ local function RegisterChangeOutfitMenu(id, parent, outfits, mType)
model = outfits[i].model,
components = outfits[i].components,
props = outfits[i].props,
disableSave = mType and true or false
disableSave = mType and true or false,
favorite = outfits[i].favorite and true or false
}
}
allOutfits[#allOutfits + 1] = {value = outfits[i].name} -- {value: string, label?: string}
if outfits[i].favorite then
favoriteOutfits[#favoriteOutfits + 1] = outfits[i].name
favoritesSection[#favoritesSection + 1] = data
else
outfitsSection[#outfitsSection + 1] = data
end
end

table.sort(changeOutfitMenu.options, function(a, b)
return a.title < b.title
end)
table.sort(favoritesSection, function(a,b) return a.title:lower() < b.title:lower() end)
for _, v in pairs(favoritesSection) do
changeOutfitMenu.options[#changeOutfitMenu.options + 1] = v
end
changeOutfitMenu.options[#changeOutfitMenu.options + 1] = favoriteButton
table.sort(outfitsSection, function(a,b) return a.title:lower() < b.title:lower() end)
for _, v in pairs(outfitsSection) do
changeOutfitMenu.options[#changeOutfitMenu.options + 1] = v
end

lib.registerContext(changeOutfitMenu)
end
Expand Down
9 changes: 9 additions & 0 deletions locales/en.lua
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,15 @@ Locales["en"] = {
},
manage = {
title = "👔 | Manage %s Outfits"
},
favorite = {
title = "Favorites",
description = "Click here to add your outfits to the top of the list",
input = "Favorite Outfits",
success = {
title = "Success",
description = "Outfits added to favorites"
}
}
},
jobOutfits = {
Expand Down
9 changes: 9 additions & 0 deletions locales/es-ES.lua
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,15 @@ Locales["es-ES"] = {
},
manage = {
title = "👔 | Administrar trajes %s"
},
favorite = {
title = "Favoritos",
description = "Haz click aqúi para añadir tus atuendos al inicio de la lista",
input = "Atuendos favoritos",
success = {
title = "Éxito",
description = "Los atuendos han sido añadidos a favoritos"
}
}
},
jobOutfits = {
Expand Down
4 changes: 4 additions & 0 deletions server/database/playeroutfits.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ function Database.PlayerOutfits.Update(outfitID, model, components, props)
})
end

function Database.PlayerOutfits.Favorite(outfitName)
return MySQL.update.await("UPDATE player_outfits SET favorite = (favorite ^ 1) WHERE outfitname = ?", {outfitName})
end

function Database.PlayerOutfits.DeleteByID(id)
MySQL.query.await("DELETE FROM player_outfits WHERE id = ?", {id})
end
32 changes: 31 additions & 1 deletion server/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ local function getOutfitsForPlayer(citizenid)
name = result[i].outfitname,
model = result[i].model,
components = json.decode(result[i].components),
props = json.decode(result[i].props)
props = json.decode(result[i].props),
favorite = result[i].favorite
}
end
end
Expand Down Expand Up @@ -245,6 +246,35 @@ RegisterNetEvent("illenium-appearance:server:updateOutfit", function(id, model,
end
end)

RegisterNetEvent("illenium-appearance:server:favoriteOutfits", function(outfits)
local src = source
local citizenID = Framework.GetPlayerID(src)
if outfitCache[citizenID] == nil then
getOutfitsForPlayer(citizenID)
end

for i = 1, #outfitCache[citizenID], 1 do
local outfit = outfitCache[citizenID][i]
if outfit.favorite then
outfit.favorite = false
Database.PlayerOutfits.Favorite(outfit.name)
end
for _, v in pairs(outfits) do
if outfit.name == v then
outfit.favorite = true
Database.PlayerOutfits.Favorite(outfit.name)
end
end
end

lib.notify(src, {
title = _L("outfits.favorite.success.title"),
description = _L("outfits.favorite.success.description"),
type = "success",
position = Config.NotifyOptions.position
})
end)

RegisterNetEvent("illenium-appearance:server:saveManagementOutfit", function(outfitData)
local src = source
local id = Database.ManagementOutfits.Add(outfitData)
Expand Down
1 change: 1 addition & 0 deletions sql/player_outfits.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ CREATE TABLE IF NOT EXISTS `player_outfits` (
`model` varchar(50) DEFAULT NULL,
`props` varchar(1000) DEFAULT NULL,
`components` varchar(1500) DEFAULT NULL,
`favorite` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
UNIQUE KEY `citizenid_outfitname_model` (`citizenid`,`outfitname`,`model`),
KEY `citizenid` (`citizenid`)
Expand Down