From 3d4fbb3784391ed24b3e850f2893b08efd32b7e4 Mon Sep 17 00:00:00 2001 From: hydrant Date: Sun, 3 May 2020 13:39:53 +0200 Subject: [PATCH 1/3] =?UTF-8?q?farben=20=C3=A4ndern=20im=20tuning=20system?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ReallifeGamemode.Client/Tuning/colors.ts | 143 +++++++++++++++ ReallifeGamemode.Client/Tuning/main.ts | 164 +++++++++++++++--- .../Managers/TuningManager.cs | 33 ++++ 3 files changed, 318 insertions(+), 22 deletions(-) create mode 100644 ReallifeGamemode.Client/Tuning/colors.ts diff --git a/ReallifeGamemode.Client/Tuning/colors.ts b/ReallifeGamemode.Client/Tuning/colors.ts new file mode 100644 index 00000000..38fb110b --- /dev/null +++ b/ReallifeGamemode.Client/Tuning/colors.ts @@ -0,0 +1,143 @@ +const vehicleColors = { + "Klassisch (Util)": { + "Schwarz": 15, + "Silber": 18, + "Dunkelsilber": 17, + "Schattensilber": 20, + "Metall": 19, + "Rot": 43, + "Hellrot": 44, + "Granatrot": 45, + "Gr\u00fcn": 57, + "Dunkelgr\u00fcn": 56, + "Blau": 77, + "Hellblau": 81, + "Dunkelblau": 75, + "Mitternachtsblau": 76, + "Meeresblau": 78, + "Leuchtendes Blau": 79, + "Braun": 108, + "Hellbraun": 109, + "Wei\u00df": 122 + }, + "Klassisch (Worn)": { + "Schwarz": 21, + "Graphit Schwarz": 22, + "Silber": 24, + "Silber Grau": 23, + "Silber Blau": 25, + "Schattensilber": 26, + "Rot": 46, + "Dunkelrot": 48, + "Goldrot": 47, + "Gr\u00fcn": 59, + "Dunkelgr\u00fcn": 58, + "Blau": 86, + "Hellblau": 87, + "Dunkelblau": 85, + "Babyblau": 157, + "Beige": 113, + "Braun": 114, + "Dunkelbraun": 115, + "Wei\u00df 1": 134, + "Wei\u00df 2": 121, + "Wei\u00df 3": 132, + "Orange": 123, + "Helleres Orange": 124 + }, + "Metallic": { + "Schwarz": 0, + "Graphit Schwarz": 1, + "Schwarzer Stahl": 2, + "Dunkles Silber": 3, + "Silber": 4, + "Blaues Silber": 5, + "Grauer Stahl": 6, + "Schattensilber": 7, + "Steinsilber": 8, + "Mitternachtssilber": 9, + "Metall": 10, + "Anthrazitgrau": 11, + "Rot": 27, + "Turin Rot": 28, + "Formel Rot": 29, + "Feuer Rot": 30, + "W\u00fcsten Rot": 33, + "Lava Rot": 150, + "Schwarz Rot": 143, + "Orange": 38, + "Helleres Orange": 138, + "Sonnenaufgang Orange": 36, + "Schokoorange": 104, + "Gr\u00fcn": 53, + "Hellgr\u00fcn": 139, + "Dunkelgr\u00fcn": 49, + "Renngr\u00fcn": 50, + "Meeresgr\u00fcn": 51, + "Olivgr\u00fcn": 52, + "Limettengr\u00fcn": 92, + "Blau": 64, + "Dunkelblau": 62, + "Hellblau": 70, + "Mitternachtsblau": 61, + "Babyblau": 140, + "Marineblau": 65, + "Hafenblau": 66, + "Diamantblau": 67, + "Surfblau": 68, + "Nautisches Blau": 69, + "Lila Blau": 71, + "Ultra Blau": 73, + "Schwarz Blau": 141, + "Gelb": 88, + "Renngelb": 89, + "Vogelgelb": 91, + "Champagner Grau": 93, + "Pueblo Beige": 94, + "Schokobraun": 96, + "Goldbraun": 97, + "Hellbraun": 98, + "Moosbraun": 100, + "Wei\u00df": 111, + "Sahnewei\u00df": 107, + "Frostwei\u00df": 112, + "Pink": 137, + "Lila": 145, + "Schwarz Lila": 142 + }, + "Matt": { + "Schwarz": 88, + "Grau": 13, + "Hellgrau": 14, + "Rot": 39, + "Dunkelrot": 40, + "Orange": 41, + "Gelb": 42, + "Limonengr\u00fcn": 55, + "Blau": 83, + "Dunkelblau": 82, + "Mitternachtsblau": 61, + "Gr\u00fcn": 128, + "Waldgr\u00fcn": 151, + "Laubgr\u00fcn": 155, + "Olivgr\u00fcn": 152, + "Braun": 129, + "Wei\u00df": 131, + "Lila": 148, + "Dunkellila": 149, + "W\u00fcstenbraun": 153, + "W\u00fcstenbräune": 154 + }, + "Spezial": { + "Geb\u00fcrsteter Stahl": 117, + "Geb\u00fcrsteter schwarzer Stahl": 118, + "Geb\u00fcrstetes Aluminium": 119, + "Geb\u00fcrstetes Gold": 159, + "Gold": 37, + "Pures Gold": 158, + "Chrome": 120, + "Bronze": 90 + } +}; + +export default vehicleColors; \ No newline at end of file diff --git a/ReallifeGamemode.Client/Tuning/main.ts b/ReallifeGamemode.Client/Tuning/main.ts index 16ded592..836e79d6 100644 --- a/ReallifeGamemode.Client/Tuning/main.ts +++ b/ReallifeGamemode.Client/Tuning/main.ts @@ -10,12 +10,18 @@ const UIMenuItem = NativeUI.UIMenuItem; const BadgeStyle = NativeUI.BadgeStyle; const Point = NativeUI.Point; +import vehicleColors from './colors'; +import game from '..'; + export default function tuning(globalData: IGlobalData) { var keyBound = false; + var currentPrimaryColor: number; + var currentSecondaryColor: number; + const disableInput = [75, 278, 279, 280, 281, 23, 59, 60, 71, 72, 74]; - const carModTypes = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 18, 22, 25, 27, 28, 33, 34, 35, 38, 39, 40, 41, 42, 43, 44, 46, 48, 69]; + const carModTypes = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 18, 22, -1, 25, 27, 28, 33, 34, 35, 38, 39, 40, 41, 42, 43, 44, 46, 48, 69]; const carModSlotName = [ { Slot: 0, Name: "Spoiler" }, @@ -37,6 +43,7 @@ export default function tuning(globalData: IGlobalData) { { Slot: 18, Name: "Turbo" }, { Slot: 22, Name: "Licht" }, { Slot: 23, Name: "Reifen" }, + { Slot: -1, Name: "Lackierung" }, { Slot: 25, Name: "Nummernschildhalter" }, { Slot: 27, Name: "Innenausstatung" }, { Slot: 28, Name: "Wackelkopf" }, @@ -169,9 +176,30 @@ export default function tuning(globalData: IGlobalData) { carModTypes.forEach((modType) => { + var mod = null; + + if (modType === 22) { // Lichter + var hlColor = localVehicle.getVariable("headlightColor"); + if (typeof hlColor !== "number" || isNaN(hlColor) || hlColor < 0 || hlColor === 255) { + mod = -1; + } else if (hlColor === 13) mod = 0; + else mod = hlColor + 1; + } else if (modType === 18) { // Turbo + var toggle = localVehicle.isToggleModOn(modType); + mod = toggle ? 0 : -1; + } else if (modType == -1) { // Lackierungen + var colorItem = new UIMenuItem("Lackierungen"); + var colorMenu = getColorMenu(); + + mainMenu.AddItem(colorItem); + mainMenu.BindMenuToItem(colorMenu, colorItem); + + return; + } + var num = localVehicle.getNumMods(modType); - if (num === 0 && modType !== 18 && modType !== 22) return; + if (num === 0 && modType !== 18 && modType !== 22 && modType !== -1) return; var modName = localVehicle.getModSlotName(modType) || "nix gefunden"; modName = mp.game.ui.getLabelText(modName); @@ -186,26 +214,21 @@ export default function tuning(globalData: IGlobalData) { } } - var modMenu = new Menu(modName, carName, new Point(50, 50), null, null); + if (mod === null) { + mod = localVehicle.getMod(modType); + } var modNum = localVehicle.getNumMods(modType); if (modType === 18) modNum = 1; if (modType === 22) modNum = 14; - - var mod = localVehicle.getMod(modType); - if (modType === 22) { - var hlColor = localVehicle.getVariable("headlightColor"); - if (typeof hlColor !== "number" || isNaN(hlColor) || hlColor < 0 || hlColor === 255) { - mod = -1; - } else if (hlColor === 13) mod = 0; - else mod = hlColor + 1; - } + var modMenu = new Menu(modName, carName, new Point(50, 50), null, null); - if (modType === 18) { - var toggle = localVehicle.isToggleModOn(modType); - mod = toggle ? 0 : -1; - } + modMenu.Visible = false; + + var menuItem = new UIMenuItem(modName); + mainMenu.AddItem(menuItem); + mainMenu.BindMenuToItem(modMenu, menuItem); currentMod[modType] = mod; @@ -260,12 +283,6 @@ export default function tuning(globalData: IGlobalData) { } localVehicle.setMod(modType, currentMod[modType]); }); - - modMenu.Visible = false; - - var menuItem = new UIMenuItem(modName); - mainMenu.AddItem(menuItem); - mainMenu.BindMenuToItem(modMenu, menuItem); }); mainMenu.Visible = true; @@ -315,6 +332,9 @@ export default function tuning(globalData: IGlobalData) { case 2: realModName = "Rennbremsen"; break; + case 3: + realModName = "Wettkampfbremsen"; + break; } } else if (slot === 13) { switch (mod) { @@ -414,4 +434,104 @@ export default function tuning(globalData: IGlobalData) { mp.game.invoke("0xE41033B25D003A07", vehicle.handle, color); } } + + function getColorMenu(): NativeUI.Menu { + var currentColors = mp.players.local.vehicle.getColours(0, 0); + + currentPrimaryColor = currentColors.colorPrimary; + currentSecondaryColor = currentColors.colorSecondary; + + mp.gui.chat.push("color1: " + currentPrimaryColor + ", color2: " + currentSecondaryColor); + + var primaryColor = getSingleColorMenu("Primärfarbe", currentPrimaryColor, primaryColorSelect, primaryColorChange); + var secondaryColor = getSingleColorMenu("Sekundärfarbe", currentSecondaryColor, secondaryColorSelect, secondaryColorChange); + + var menu = new Menu("Lackierungen", "Ă„ndere die Farbe deines Fahrzeugs", new Point(50, 50)); + + var primaryColorItem = new UIMenuItem("Primärfarbe"); + var secondaryColorItem = new UIMenuItem("Sekundärfarbe"); + + secondaryColor.MenuClose.on(() => { + mp.players.local.vehicle.setColours(currentPrimaryColor, currentSecondaryColor); + }); + + primaryColor.MenuClose.on(() => { + mp.players.local.vehicle.setColours(currentPrimaryColor, currentSecondaryColor); + }); + + menu.AddItem(primaryColorItem); + menu.AddItem(secondaryColorItem); + + menu.BindMenuToItem(primaryColor, primaryColorItem); + menu.BindMenuToItem(secondaryColor, secondaryColorItem); + + return menu; + } + + function getSingleColorMenu(title: string, currentColor: number, onSelect: (color: number) => void, onChange: (color: number) => void): NativeUI.Menu { + var menu = new Menu(title, "Ă„ndere die Farbe deines Fahrzeugs", new Point(50, 50)); + + var colorCategories = Object.keys(vehicleColors); + + var currentColorItem: NativeUI.UIMenuItem = null; + + colorCategories.forEach(category => { + var categoryItem = new UIMenuItem(category); + menu.AddItem(categoryItem); + + var categoryMenu = new Menu(category, "Ă„ndere die Farbe deines Fahrzeugs", new Point(50, 50)); + + var categoryColors = Object.keys(vehicleColors[category]); + categoryColors.forEach(categoryColor => { + var color = vehicleColors[category][categoryColor]; + + var colorItem = new UIMenuItem(cleanColorName); + colorItem.Data = color; + + if (color === currentColor) { + colorItem.SetRightBadge(BadgeStyle.Car); + currentColorItem = colorItem; + } + + categoryMenu.AddItem(colorItem); + }); + + menu.BindMenuToItem(categoryMenu, categoryItem); + + categoryMenu.IndexChange.on((index, item: NativeUI.UIMenuItem) => { + onChange(item.Data); + }); + + categoryMenu.ItemSelect.on((item: NativeUI.UIMenuItem, index: number) => { + currentColorItem.SetRightBadge(BadgeStyle.None); + + item.SetRightBadge(BadgeStyle.Car); + currentColorItem = item; + + onSelect(item.Data); + }); + }); + + return menu; + } + + function primaryColorChange(color: number) { + mp.players.local.vehicle.setColours(color, currentSecondaryColor); + } + + function primaryColorSelect(color: number) { + currentPrimaryColor = color; + + mp.events.callRemote("CLIENT:TuningManager_SetVehicleColor", true, color); + } + + function secondaryColorChange(color: number) { + mp.players.local.vehicle.setColours(currentPrimaryColor, color); + } + + function secondaryColorSelect(color: number) { + currentSecondaryColor = color; + + mp.events.callRemote("CLIENT:TuningManager_SetVehicleColor", false, color); + } } \ No newline at end of file diff --git a/ReallifeGamemode.Server/Managers/TuningManager.cs b/ReallifeGamemode.Server/Managers/TuningManager.cs index 0e77d79f..4430f782 100644 --- a/ReallifeGamemode.Server/Managers/TuningManager.cs +++ b/ReallifeGamemode.Server/Managers/TuningManager.cs @@ -157,5 +157,38 @@ namespace ReallifeGamemode.Server.Managers dbContext.SaveChanges(); } } + + [RemoteEvent("CLIENT:TuningManager_SetVehicleColor")] + public void TuningManagerSetVehicleColor(Player player, bool primarySecondary, int color) + { + Vehicle veh = player.Vehicle; + if (primarySecondary) + { + veh.PrimaryColor = color; + } + else + { + veh.SecondaryColor = color; + } + + using var dbContext = new DatabaseContext(true); + ServerVehicle serverVeh = VehicleManager.GetServerVehicleFromVehicle(veh, dbContext); + + if (serverVeh == null) + { + return; + } + + if (primarySecondary) + { + serverVeh.PrimaryColor = color; + } + else + { + serverVeh.SecondaryColor = color; + } + + dbContext.SaveChanges(); + } } } From 5731e6de0bcb50716169c58b41abef5fbea9ff1b Mon Sep 17 00:00:00 2001 From: hydrant Date: Sun, 3 May 2020 14:19:15 +0200 Subject: [PATCH 2/3] fehler fixxxxxx --- ReallifeGamemode.Client/Tuning/main.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/ReallifeGamemode.Client/Tuning/main.ts b/ReallifeGamemode.Client/Tuning/main.ts index 836e79d6..fa22b05f 100644 --- a/ReallifeGamemode.Client/Tuning/main.ts +++ b/ReallifeGamemode.Client/Tuning/main.ts @@ -441,8 +441,6 @@ export default function tuning(globalData: IGlobalData) { currentPrimaryColor = currentColors.colorPrimary; currentSecondaryColor = currentColors.colorSecondary; - mp.gui.chat.push("color1: " + currentPrimaryColor + ", color2: " + currentSecondaryColor); - var primaryColor = getSingleColorMenu("Primärfarbe", currentPrimaryColor, primaryColorSelect, primaryColorChange); var secondaryColor = getSingleColorMenu("Sekundärfarbe", currentSecondaryColor, secondaryColorSelect, secondaryColorChange); @@ -485,7 +483,7 @@ export default function tuning(globalData: IGlobalData) { categoryColors.forEach(categoryColor => { var color = vehicleColors[category][categoryColor]; - var colorItem = new UIMenuItem(cleanColorName); + var colorItem = new UIMenuItem(categoryColor); colorItem.Data = color; if (color === currentColor) { From 328951828afeb6714546ef6481fe018c6a280bd1 Mon Sep 17 00:00:00 2001 From: hydrant Date: Sun, 3 May 2020 14:46:31 +0200 Subject: [PATCH 3/3] mattschwarz war taxigelb habs behoben --- ReallifeGamemode.Client/Tuning/colors.ts | 2 +- ReallifeGamemode.Client/Tuning/main.ts | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/ReallifeGamemode.Client/Tuning/colors.ts b/ReallifeGamemode.Client/Tuning/colors.ts index 38fb110b..4b8ccefc 100644 --- a/ReallifeGamemode.Client/Tuning/colors.ts +++ b/ReallifeGamemode.Client/Tuning/colors.ts @@ -106,7 +106,7 @@ const vehicleColors = { "Schwarz Lila": 142 }, "Matt": { - "Schwarz": 88, + "Schwarz": 12, "Grau": 13, "Hellgrau": 14, "Rot": 39, diff --git a/ReallifeGamemode.Client/Tuning/main.ts b/ReallifeGamemode.Client/Tuning/main.ts index fa22b05f..c9fcab20 100644 --- a/ReallifeGamemode.Client/Tuning/main.ts +++ b/ReallifeGamemode.Client/Tuning/main.ts @@ -11,7 +11,6 @@ const BadgeStyle = NativeUI.BadgeStyle; const Point = NativeUI.Point; import vehicleColors from './colors'; -import game from '..'; export default function tuning(globalData: IGlobalData) { var keyBound = false;