From b183366d5435f313fd9e4e4f86a33fc62a9557ab Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Mon, 16 May 2011 21:06:04 +1200 Subject: [PATCH] add ChromeMetrics for values we dont want to duplicate everywhere --- OpenRA.FileFormats/Manifest.cs | 3 +- OpenRA.Game/ModData.cs | 16 ++++++----- OpenRA.Game/OpenRA.Game.csproj | 1 + OpenRA.Game/Widgets/ButtonWidget.cs | 2 +- OpenRA.Game/Widgets/ChromeMetrics.cs | 43 ++++++++++++++++++++++++++++ OpenRA.Game/Widgets/WidgetLoader.cs | 2 +- mods/cnc/metrics.yaml | 4 +++ mods/cnc/mod.yaml | 3 ++ mods/ra/metrics.yaml | 4 +++ mods/ra/mod.yaml | 3 ++ 10 files changed, 71 insertions(+), 10 deletions(-) create mode 100644 OpenRA.Game/Widgets/ChromeMetrics.cs create mode 100644 mods/cnc/metrics.yaml create mode 100644 mods/ra/metrics.yaml diff --git a/OpenRA.FileFormats/Manifest.cs b/OpenRA.FileFormats/Manifest.cs index 1cf9c90537..6b0cc26335 100644 --- a/OpenRA.FileFormats/Manifest.cs +++ b/OpenRA.FileFormats/Manifest.cs @@ -20,7 +20,7 @@ namespace OpenRA.FileFormats public readonly string[] Mods, Folders, Packages, Rules, ServerTraits, Sequences, Cursors, Chrome, Assemblies, ChromeLayout, - Weapons, Voices, Music, Movies, TileSets; + Weapons, Voices, Music, Movies, TileSets, ChromeMetrics; public readonly string LoadScreen; public readonly int TileSize = 24; @@ -46,6 +46,7 @@ namespace OpenRA.FileFormats Music = YamlList(yaml, "Music"); Movies = YamlList(yaml, "Movies"); TileSets = YamlList(yaml, "TileSets"); + ChromeMetrics = YamlList(yaml, "ChromeMetrics"); LoadScreen = yaml.First( x => x.Key == "LoadScreen" ).Value.Value; diff --git a/OpenRA.Game/ModData.cs b/OpenRA.Game/ModData.cs index 95a62dd3e1..5e67f008fd 100755 --- a/OpenRA.Game/ModData.cs +++ b/OpenRA.Game/ModData.cs @@ -14,6 +14,7 @@ using System.Linq; using OpenRA.FileFormats; using OpenRA.Graphics; using OpenRA.Traits; +using OpenRA.Widgets; namespace OpenRA { @@ -44,22 +45,23 @@ namespace OpenRA { AvailableMaps = FindMaps( Manifest.Mods ); } - + public void LoadInitialAssets() { // all this manipulation of static crap here is nasty and breaks - // horribly when you use ModData in unexpected ways. + // horribly when you use ModData in unexpected ways. FileSystem.UnmountAll(); foreach (var dir in Manifest.Folders) FileSystem.Mount(dir); - + ReloadMaps(); Palette = new HardwarePalette(); - ChromeProvider.Initialize( Manifest.Chrome ); - SheetBuilder = new SheetBuilder( TextureChannel.Red ); - CursorSheetBuilder = new CursorSheetBuilder( this ); + ChromeMetrics.Initialize(Manifest.ChromeMetrics); + ChromeProvider.Initialize(Manifest.Chrome); + SheetBuilder = new SheetBuilder(TextureChannel.Red); + CursorSheetBuilder = new CursorSheetBuilder(this); CursorProvider.Initialize(Manifest.Cursors); - Palette.Update(new IPaletteModifier[]{}); + Palette.Update(new IPaletteModifier[] { }); } public Map PrepareMap(string uid) diff --git a/OpenRA.Game/OpenRA.Game.csproj b/OpenRA.Game/OpenRA.Game.csproj index 6f79fa88d0..f15001e27a 100755 --- a/OpenRA.Game/OpenRA.Game.csproj +++ b/OpenRA.Game/OpenRA.Game.csproj @@ -204,6 +204,7 @@ + diff --git a/OpenRA.Game/Widgets/ButtonWidget.cs b/OpenRA.Game/Widgets/ButtonWidget.cs index ea530bfc20..712d31e739 100644 --- a/OpenRA.Game/Widgets/ButtonWidget.cs +++ b/OpenRA.Game/Widgets/ButtonWidget.cs @@ -9,9 +9,9 @@ #endregion using System; +using System.Collections.Generic; using System.Drawing; using OpenRA.Graphics; -using System.Collections.Generic; namespace OpenRA.Widgets { diff --git a/OpenRA.Game/Widgets/ChromeMetrics.cs b/OpenRA.Game/Widgets/ChromeMetrics.cs new file mode 100644 index 0000000000..71cceb3fd7 --- /dev/null +++ b/OpenRA.Game/Widgets/ChromeMetrics.cs @@ -0,0 +1,43 @@ +#region Copyright & License Information +/* + * Copyright 2007-2011 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. For more information, + * see COPYING. + */ +#endregion + + +using System.Collections.Generic; +using System.Linq; +using OpenRA.FileFormats; + +namespace OpenRA.Widgets +{ + static class ChromeMetrics + { + static Dictionary data = new Dictionary(); + + public static void Initialize(string[] yaml) + { + data = new Dictionary(); + var metrics = yaml.Select(y => MiniYaml.FromFile(y)) + .Aggregate(MiniYaml.MergeLiberal); + + foreach (var m in metrics) + foreach (var n in m.Value.Nodes) + data[n.Key] = n.Value.Value; + } + + public static string GetString(string key) + { + return data[key]; + } + + public static int GetInt(string key) + { + return int.Parse(data[key]); + } + } +} diff --git a/OpenRA.Game/Widgets/WidgetLoader.cs b/OpenRA.Game/Widgets/WidgetLoader.cs index d01bd82318..190362aa85 100644 --- a/OpenRA.Game/Widgets/WidgetLoader.cs +++ b/OpenRA.Game/Widgets/WidgetLoader.cs @@ -9,10 +9,10 @@ #endregion using System.Collections.Generic; +using System.IO; using System.Linq; using OpenRA.FileFormats; using OpenRA.Widgets; -using System.IO; namespace OpenRA { diff --git a/mods/cnc/metrics.yaml b/mods/cnc/metrics.yaml new file mode 100644 index 0000000000..b6dbf4861a --- /dev/null +++ b/mods/cnc/metrics.yaml @@ -0,0 +1,4 @@ +# General dumping-ground for UI element sizes, etc. + +Metrics: + ButtonDepth: 1 \ No newline at end of file diff --git a/mods/cnc/mod.yaml b/mods/cnc/mod.yaml index 237583604a..082087ec89 100644 --- a/mods/cnc/mod.yaml +++ b/mods/cnc/mod.yaml @@ -92,3 +92,6 @@ ServerTraits: PlayerCommands LobbyCommands MasterServerPinger + +ChromeMetrics: + mods/cnc/metrics.yaml \ No newline at end of file diff --git a/mods/ra/metrics.yaml b/mods/ra/metrics.yaml new file mode 100644 index 0000000000..b6dbf4861a --- /dev/null +++ b/mods/ra/metrics.yaml @@ -0,0 +1,4 @@ +# General dumping-ground for UI element sizes, etc. + +Metrics: + ButtonDepth: 1 \ No newline at end of file diff --git a/mods/ra/mod.yaml b/mods/ra/mod.yaml index a2d12a01bb..a5989a417b 100644 --- a/mods/ra/mod.yaml +++ b/mods/ra/mod.yaml @@ -86,3 +86,6 @@ ServerTraits: PlayerCommands LobbyCommands MasterServerPinger + +ChromeMetrics: + mods/ra/metrics.yaml \ No newline at end of file