diff --git a/client/client.lua b/client/client.lua index d419f821..74d0775d 100644 --- a/client/client.lua +++ b/client/client.lua @@ -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", @@ -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 diff --git a/locales/en.lua b/locales/en.lua index a6de1588..f1736cc4 100644 --- a/locales/en.lua +++ b/locales/en.lua @@ -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 = { diff --git a/locales/es-ES.lua b/locales/es-ES.lua index 812bb7df..4be80b7f 100644 --- a/locales/es-ES.lua +++ b/locales/es-ES.lua @@ -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 = { diff --git a/server/database/playeroutfits.lua b/server/database/playeroutfits.lua index 7a2aa1cf..a0d7b3bf 100644 --- a/server/database/playeroutfits.lua +++ b/server/database/playeroutfits.lua @@ -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 diff --git a/server/server.lua b/server/server.lua index 024906b8..019b5a23 100644 --- a/server/server.lua +++ b/server/server.lua @@ -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 @@ -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) diff --git a/sql/player_outfits.sql b/sql/player_outfits.sql index cdc5d056..9bc71fe1 100644 --- a/sql/player_outfits.sql +++ b/sql/player_outfits.sql @@ -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`)