public Theme(ColorScheme colorScheme, PieceSet pieceSet, int nSquareColors, string customThemeName) { ColorScheme = colorScheme; PieceSet = pieceSet; NSquareColors = nSquareColors; CustomThemeName = customThemeName; }
// *** EVENT HANDLERS *** // private void AppearanceSettingsForm_Load(object sender, EventArgs e) { // copy Theme settings into temporary variables so that we don't change // the actual Theme object unless the user actually applies the settings originalSchemeBeingEdited = theme.ColorScheme; colorScheme = theme.ColorScheme.Clone(); nSquareColors = theme.NSquareColors; // initialize the color schemes pick list bool colorSchemeInList = false; foreach (KeyValuePair <string, ColorScheme> scheme in ColorSchemeLibrary.ColorSchemes) { pickColorScheme.Items.Add(scheme.Value); if (scheme.Value == theme.ColorScheme) { colorSchemeInList = true; } } if (!colorSchemeInList) { pickColorScheme.Items.Add(theme.ColorScheme); } pickColorScheme.SelectedItem = theme.ColorScheme; // initialize color controls for scheme UpdateColorScheme(); // if this is an existing scheme and hasn't been // modified yet, disable the Save button if (colorScheme.Name != "(custom)") { btnSaveScheme.Enabled = false; } // populate list of piece sets foreach (KeyValuePair <string, PieceSet> pair in PieceSetLibrary.PieceSets) { PieceSet pieceset = pair.Value; pickPieceSet.Items.Add(pieceset); } pickPieceSet.SelectedItem = theme.PieceSet; }
public static Theme CreateTheme(Game game) { // Load theme from RegistryKey if it exists. This will restore // the theme used last time this game was played RegistryKey gameKey = getKeyForGame(game, false); if (gameKey != null) { game.RegistryKey = gameKey; return(loadThemeFromRegistry(game, gameKey)); } // Defaults ColorScheme colorScheme = ColorSchemeLibrary.Default; PieceSet pieceSet = PieceSetLibrary.Default; int numColors = 2; // Find AppearanceAttribute and update defaults (if it exists) object[] attrs = null; if (Program.Manager.AppearanceAttributes.ContainsKey(game.Name)) { attrs = new object[] { Program.Manager.AppearanceAttributes[game.Name] } } ; else { attrs = game.GetType().GetCustomAttributes(typeof(AppearanceAttribute), false); } if (attrs != null && attrs.Length >= 1) { AppearanceAttribute appearance = (AppearanceAttribute)attrs[0]; if (appearance.Game != null && appearance.Game != game.Name) { appearance = null; } numColors = appearance != null ? appearance.NumberOfSquareColors : 2; if (appearance != null && appearance.ColorScheme != null) { if (ColorSchemeLibrary.Contains(appearance.ColorScheme)) { colorScheme = ColorSchemeLibrary.Lookup(appearance.ColorScheme); } } if (appearance != null && appearance.PieceSet != null) { if (PieceSetLibrary.Contains(appearance.PieceSet)) { pieceSet = PieceSetLibrary.Lookup(appearance.PieceSet); } } bool colorSchemeChanged = false; if (appearance != null && appearance.Player1Color != null) { string[] colorNumbers = appearance.Player1Color.Split(','); colorScheme.PlayerColors[0] = Color.FromArgb(Convert.ToInt32(colorNumbers[0]), Convert.ToInt32(colorNumbers[1]), Convert.ToInt32(colorNumbers[2])); colorSchemeChanged = true; } if (appearance != null && appearance.Player2Color != null) { string[] colorNumbers = appearance.Player2Color.Split(','); colorScheme.PlayerColors[1] = Color.FromArgb(Convert.ToInt32(colorNumbers[0]), Convert.ToInt32(colorNumbers[1]), Convert.ToInt32(colorNumbers[2])); colorSchemeChanged = true; } if (colorSchemeChanged) { colorScheme.Modified = true; colorScheme.Name = "(custom)"; } game.NumberOfSquareColors = numColors; } gameKey = getKeyForGame(game, true); string customThemeName = null; if (game.GetCustomThemes() != null) { customThemeName = game.GetDefaultCustomTheme(); } Theme theme = new Theme(colorScheme, pieceSet, numColors, customThemeName); theme.SaveToRegistry(gameKey); return(theme); }
private static Theme loadThemeFromRegistry(Game game, RegistryKey gameKey) { // find AppearanceAttribute (if any) to fill in any data missing // from the registry key with game defaults AppearanceAttribute appearance = null; object[] attrs; if (Program.Manager.AppearanceAttributes.ContainsKey(game.Name)) { attrs = new object[] { Program.Manager.AppearanceAttributes[game.Name] } } ; else { attrs = game.GetType().GetCustomAttributes(typeof(AppearanceAttribute), true); } if (attrs.Length >= 1) { appearance = (AppearanceAttribute)attrs[0]; if (appearance.Game != null && appearance.Game != game.Name) { appearance = null; } } // get number of colors object objNSquareColors = gameKey.GetValue("NSquareColors"); if (objNSquareColors == null) { if (appearance != null) { objNSquareColors = appearance.NumberOfSquareColors; } else { objNSquareColors = 2; } gameKey.SetValue("NSquareColors", objNSquareColors); } // get color scheme object objColorSchemeName = gameKey.GetValue("ColorScheme"); ColorScheme scheme; if (objColorSchemeName == null) { scheme = new ColorScheme(gameKey); } else { if (ColorSchemeLibrary.Contains((string)objColorSchemeName)) { scheme = ColorSchemeLibrary.Lookup((string)objColorSchemeName); } else { scheme = ColorSchemeLibrary.Default; } } // get piece set object objPieceSetName = gameKey.GetValue("PieceSet"); PieceSet pieceSet = null; if (objPieceSetName == null) { if (appearance != null) { if (PieceSetLibrary.Contains(appearance.PieceSet)) { pieceSet = PieceSetLibrary.Lookup(appearance.PieceSet); } else { pieceSet = PieceSetLibrary.Default; } } else { pieceSet = PieceSetLibrary.Default; } gameKey.SetValue("PieceSet", pieceSet.Name); } else if (PieceSetLibrary.Contains((string)objPieceSetName)) { pieceSet = PieceSetLibrary.Lookup((string)objPieceSetName); } else { pieceSet = PieceSetLibrary.Default; } // get custom theme name string customThemeName = (string)gameKey.GetValue("CustomTheme"); // create the Theme and return return(new Theme(scheme, pieceSet, (int)objNSquareColors, customThemeName)); }