From 7b58f03f1ce4ff8727a779b6e957b49e3b0e8690 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 11 Apr 2021 21:27:51 +0100 Subject: [PATCH] Move ColorValidator logic into a new ColorPickerManager trait. --- OpenRA.Mods.Common/ServerTraits/LobbyCommands.cs | 8 ++++---- .../World/ColorPickerManager.cs} | 10 +++++++--- OpenRA.Mods.Common/Widgets/Logic/ColorPickerLogic.cs | 8 ++++---- mods/cnc/mod.yaml | 3 --- mods/cnc/rules/world.yaml | 2 ++ mods/d2k/mod.yaml | 3 --- mods/d2k/rules/world.yaml | 2 ++ mods/ra/mod.yaml | 3 --- mods/ra/rules/world.yaml | 2 ++ mods/ts/mod.yaml | 3 --- mods/ts/rules/world.yaml | 2 ++ 11 files changed, 23 insertions(+), 23 deletions(-) rename OpenRA.Mods.Common/{ColorValidator.cs => Traits/World/ColorPickerManager.cs} (94%) diff --git a/OpenRA.Mods.Common/ServerTraits/LobbyCommands.cs b/OpenRA.Mods.Common/ServerTraits/LobbyCommands.cs index 17c776e613..f2bd8a397a 100644 --- a/OpenRA.Mods.Common/ServerTraits/LobbyCommands.cs +++ b/OpenRA.Mods.Common/ServerTraits/LobbyCommands.cs @@ -385,11 +385,11 @@ namespace OpenRA.Mods.Common.Server }; // Pick a random color for the bot - var validator = server.ModData.Manifest.Get(); + var colorManager = server.ModData.DefaultRules.Actors[SystemActors.World].TraitInfo(); var terrainColors = server.ModData.DefaultTerrainInfo[server.Map.TileSet].RestrictedPlayerColors; var playerColors = server.LobbyInfo.Clients.Select(c => c.Color) .Concat(server.Map.Players.Players.Values.Select(p => p.Color)); - bot.Color = bot.PreferredColor = validator.RandomPresetColor(server.Random, terrainColors, playerColors); + bot.Color = bot.PreferredColor = colorManager.RandomPresetColor(server.Random, terrainColors, playerColors); server.LobbyInfo.Clients.Add(bot); } @@ -1089,7 +1089,7 @@ namespace OpenRA.Mods.Common.Server { lock (server.LobbyInfo) { - var validator = server.ModData.Manifest.Get(); + var colorManager = server.ModData.DefaultRules.Actors[SystemActors.World].TraitInfo(); var askColor = askedColor; Action onError = message => @@ -1102,7 +1102,7 @@ namespace OpenRA.Mods.Common.Server var playerColors = server.LobbyInfo.Clients.Where(c => c.Index != playerIndex).Select(c => c.Color) .Concat(server.Map.Players.Players.Values.Select(p => p.Color)).ToList(); - return validator.MakeValid(askColor, server.Random, terrainColors, playerColors, onError); + return colorManager.MakeValid(askColor, server.Random, terrainColors, playerColors, onError); } } diff --git a/OpenRA.Mods.Common/ColorValidator.cs b/OpenRA.Mods.Common/Traits/World/ColorPickerManager.cs similarity index 94% rename from OpenRA.Mods.Common/ColorValidator.cs rename to OpenRA.Mods.Common/Traits/World/ColorPickerManager.cs index 4716803089..04524e77ca 100644 --- a/OpenRA.Mods.Common/ColorValidator.cs +++ b/OpenRA.Mods.Common/Traits/World/ColorPickerManager.cs @@ -1,6 +1,6 @@ #region Copyright & License Information /* - * Copyright 2007-2020 The OpenRA Developers (see AUTHORS) + * Copyright 2007-2021 The OpenRA Developers (see AUTHORS) * This file is part of OpenRA, which is free software. It is made * available to you under the terms of the GNU General Public License * as published by the Free Software Foundation, either version 3 of @@ -14,10 +14,12 @@ using System.Collections.Generic; using System.Linq; using OpenRA.Primitives; using OpenRA.Support; +using OpenRA.Traits; -namespace OpenRA.Mods.Common +namespace OpenRA.Mods.Common.Traits { - public class ColorValidator : IGlobalModData + [Desc("Configuration options for the lobby player color picker. Attach this to the world actor.")] + public class ColorPickerManagerInfo : TraitInfo { // The bigger the color threshold, the less permissive is the algorithm public readonly int Threshold = 0x50; @@ -182,4 +184,6 @@ namespace OpenRA.Mods.Common return color; } } + + public class ColorPickerManager { } } diff --git a/OpenRA.Mods.Common/Widgets/Logic/ColorPickerLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/ColorPickerLogic.cs index 209e2dee12..395e724fb4 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/ColorPickerLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/ColorPickerLogic.cs @@ -65,8 +65,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic } // Set the initial state - var validator = modData.Manifest.Get(); - mixer.SetPaletteRange(validator.HsvSaturationRange[0], validator.HsvSaturationRange[1], validator.HsvValueRange[0], validator.HsvValueRange[1]); + var colorManager = world.WorldActor.Info.TraitInfo(); + mixer.SetPaletteRange(colorManager.HsvSaturationRange[0], colorManager.HsvSaturationRange[1], colorManager.HsvValueRange[0], colorManager.HsvValueRange[1]); mixer.Set(initialColor); hueSlider.Value = HueFromColor(initialColor); @@ -116,10 +116,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic for (var i = 0; i < paletteCols; i++) { var colorIndex = j * paletteCols + i; - if (colorIndex >= validator.TeamColorPresets.Length) + if (colorIndex >= colorManager.TeamColorPresets.Length) break; - var color = validator.TeamColorPresets[colorIndex]; + var color = colorManager.TeamColorPresets[colorIndex]; var newSwatch = (ColorBlockWidget)presetColorTemplate.Clone(); newSwatch.GetColor = () => color; diff --git a/mods/cnc/mod.yaml b/mods/cnc/mod.yaml index c8dbb076a7..cc8bd55427 100644 --- a/mods/cnc/mod.yaml +++ b/mods/cnc/mod.yaml @@ -263,9 +263,6 @@ GameSpeeds: Timestep: 20 OrderLatency: 6 -ColorValidator: - TeamColorPresets: f70606, ff7a22, f8d3b3, f8e947, 94b319, f335a0, a64d6c, ce08f9, f5b2db, 12b572, 502048, 1d06f7, 328dff, 78dbf8, cef6b1, 391d1d - ModContent: InstallPromptMessage: Tiberian Dawn requires artwork and audio from the original game.\n\nQuick Install will automatically download this content (without music\nor videos) from a mirror of the 2007 C&C Gold freeware release.\n\nAdvanced Install includes options for copying the music, videos, and\nother content from an original game disc or digital installation. QuickDownload: basefiles diff --git a/mods/cnc/rules/world.yaml b/mods/cnc/rules/world.yaml index db2e1f3f8a..8e8f170abd 100644 --- a/mods/cnc/rules/world.yaml +++ b/mods/cnc/rules/world.yaml @@ -254,6 +254,8 @@ World: ShellmapRoot: MENU_BACKGROUND ScriptTriggers: TimeLimitManager: + ColorPickerManager: + TeamColorPresets: f70606, ff7a22, f8d3b3, f8e947, 94b319, f335a0, a64d6c, ce08f9, f5b2db, 12b572, 502048, 1d06f7, 328dff, 78dbf8, cef6b1, 391d1d EditorWorld: Inherits: ^BaseWorld diff --git a/mods/d2k/mod.yaml b/mods/d2k/mod.yaml index 541db6d3d5..e7ec6f4976 100644 --- a/mods/d2k/mod.yaml +++ b/mods/d2k/mod.yaml @@ -238,9 +238,6 @@ GameSpeeds: Timestep: 20 OrderLatency: 6 -ColorValidator: - TeamColorPresets: 9023cd, f53333, ffae00, fff830, 87f506, f872ad, da06f3, ddb8ff, def7b2, 39c46f, 200738, 280df6, 2f86f2, 76d2f8, 498221, 392929 - ModContent: InstallPromptMessage: Dune 2000 requires artwork and audio from the original game.\n\nQuick Install will automatically download this content (without\nmusic or videos) from an online mirror of the game files.\n\nAdvanced Install includes options for copying the music, videos,\nand other content from an original game disc. HeaderMessage: The original game content may be copied from an original game disc,\nor downloaded from an online mirror of the game files. diff --git a/mods/d2k/rules/world.yaml b/mods/d2k/rules/world.yaml index ca464e7852..6dc0e9cf0f 100644 --- a/mods/d2k/rules/world.yaml +++ b/mods/d2k/rules/world.yaml @@ -235,6 +235,8 @@ World: ScriptTriggers: StartGameNotification: TimeLimitManager: + ColorPickerManager: + TeamColorPresets: 9023cd, f53333, ffae00, fff830, 87f506, f872ad, da06f3, ddb8ff, def7b2, 39c46f, 200738, 280df6, 2f86f2, 76d2f8, 498221, 392929 EditorWorld: Inherits: ^BaseWorld diff --git a/mods/ra/mod.yaml b/mods/ra/mod.yaml index 16fc371d99..f9320c8178 100644 --- a/mods/ra/mod.yaml +++ b/mods/ra/mod.yaml @@ -268,9 +268,6 @@ GameSpeeds: Timestep: 20 OrderLatency: 6 -ColorValidator: - TeamColorPresets: f7b3b3, f50606, 98331f, f57606, f7bb06, f861a4, da06f3, ddb8ff, 06f739, cef7b2, 200738, 280df6, 2f86f2, 76d2f8, 34ba93, 391d1d - ModContent: InstallPromptMessage: Red Alert requires artwork and audio from the original game.\n\nQuick Install will automatically download this content (without music\nor videos) from a mirror of the 2008 Red Alert freeware release.\n\nAdvanced Install includes options for copying the music, videos, and\nother content from an original game disc or digital installation. QuickDownload: quickinstall diff --git a/mods/ra/rules/world.yaml b/mods/ra/rules/world.yaml index 04560ff909..ea7df50199 100644 --- a/mods/ra/rules/world.yaml +++ b/mods/ra/rules/world.yaml @@ -280,6 +280,8 @@ World: 3: WarningThreeMinutesRemaining 2: WarningTwoMinutesRemaining 1: WarningOneMinuteRemaining + ColorPickerManager: + TeamColorPresets: f7b3b3, f50606, 98331f, f57606, f7bb06, f861a4, da06f3, ddb8ff, 06f739, cef7b2, 200738, 280df6, 2f86f2, 76d2f8, 34ba93, 391d1d EditorWorld: Inherits: ^BaseWorld diff --git a/mods/ts/mod.yaml b/mods/ts/mod.yaml index c3770b3052..0c9f2757d0 100644 --- a/mods/ts/mod.yaml +++ b/mods/ts/mod.yaml @@ -297,9 +297,6 @@ GameSpeeds: Timestep: 20 OrderLatency: 6 -ColorValidator: - TeamColorPresets: f70606, ff7a22, f8d3b3, f8e947, 94b319, f335a0, a64d6c, ce08f9, f5b2db, 12b572, 4A1948, 1d06f7, 328dff, 78dbf8, cef6b1, 391d1d - ModContent: InstallPromptMessage: Tiberian Sun requires artwork and audio from the original game.\n\nQuick Install will automatically download this content (without music\nor videos) from a mirror of the 2012 Tiberian Sun freeware release.\n\nAdvanced Install includes options for copying the music, videos, and\nother content from an original game disc or digital installation. QuickDownload: quickinstall diff --git a/mods/ts/rules/world.yaml b/mods/ts/rules/world.yaml index 660cb96389..923d722595 100644 --- a/mods/ts/rules/world.yaml +++ b/mods/ts/rules/world.yaml @@ -380,6 +380,8 @@ World: ShellmapRoot: MAINMENU_PRERELEASE_NOTIFICATION ScriptTriggers: TimeLimitManager: + ColorPickerManager: + TeamColorPresets: f70606, ff7a22, f8d3b3, f8e947, 94b319, f335a0, a64d6c, ce08f9, f5b2db, 12b572, 4A1948, 1d06f7, 328dff, 78dbf8, cef6b1, 391d1d EditorWorld: Inherits: ^BaseWorld