コード例 #1
0
 //	OK button clicked event handler
 private void btnOK_Click(object sender, EventArgs e)
 {
     if (optSaveAs.Checked)
     {
         //	If we're saving this as a new scheme ...
         if (txtNewSchemeName.Text.Length < 1)
         {
             MessageBox.Show("You must provide a name for the new color scheme");
             return;
         }
         if (ColorSchemeLibrary.Contains(txtNewSchemeName.Text))
         {
             MessageBox.Show("A color scheme with that name already exists");
             return;
         }
         else
         {
             colorScheme.Name     = txtNewSchemeName.Text;
             colorScheme.Modified = false;
             ColorSchemeLibrary.NewScheme(colorScheme);
             NewScheme = true;
         }
     }
     else
     {
         //	We're overwriting the existing color scheme (if it's been modified)
         //	NOTE: we shouldn't be here if the scheme has not been modified; in
         //	that case, the Save button on the AppearanceSettingsForm should
         //	have been disabled.
         if (colorScheme.Modified)
         {
             //	since we're now saving it, it's no longer modified
             colorScheme.Modified = false;
             //	remove the (modified) from the name
             colorScheme.Name = colorScheme.Name.Replace(" (modified)", "");
             //	update the color scheme in the library (which will
             //	update it in the registry)
             ColorSchemeLibrary.UpdateScheme(colorScheme);
         }
     }
     DialogResult = DialogResult.OK;
     Close();
 }
コード例 #2
0
ファイル: Program.cs プロジェクト: ColinSuess/ChessVFork
        static void Main()
        {
            // *** INITIALIZATION *** //

            Manager = new ChessV.Manager.Manager();

            //	Are we running on Windows?
            RunningOnWindows = Path.DirectorySeparatorChar == '\\';

            //	Base manager for registry key settings
            int currentRegistryVersion = RegistrySettings.Initialize();

            //	Factory object for dynamically creating a BoardPresentation for any Game object
            PresentationFactory.Initialize();

            //	Library object containing the collection of bitmap textures
            TextureLibrary.Initialize();

            //	Library object cointaining the collection of defined color schemes
            ColorSchemeLibrary.Initialize(currentRegistryVersion);

            //	Library object containing the collection of defined piece sets
            PieceSetLibrary.Initialize();
            //	Make sure we loaded at least a standard piece set successfully or
            //	else we'll need to inform the user to reinstall and then exit
            if (PieceSetLibrary.PieceSets == null)
            {
                MessageBox.Show("Directory of piece set graphics could not be found.\n" +
                                "Please re-install ChessV.", "Fatal Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                Application.Exit();
                return;
            }
            if (!PieceSetLibrary.PieceSets.ContainsKey("Standard"))
            {
                MessageBox.Show("The 'Standard' piece set  graphics could not be found.\n" +
                                "Please re-install ChessV.", "Fatal Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                Application.Exit();
                return;
            }


            // *** INITIALIZE GAME CATALOG *** //
            string gameCatalog =
                ".Chess" +
                "\n\tChess" +
                "\n\t.Shuffled Variants|Fischer Random Chess" +
                "\n\t\tFischer Random Chess" +
                "\n\t\tChess480" +
                "\n\t\tWild Castle" +
                "\n\t\tChess256" +
                "\n\tPocket Knight" +
                "\n\tChess with Different Armies" +
                "\n\tKnightmate" +
                "\n\tAlice Chess" +
                "\n.Medium" +
                "\n\t.Capablanca Variants|Capablanca Chess" +
                "\n\t\tCapablanca Chess" +
                "\n\t\tCarrera's Chess" +
                "\n\t\tBird's Chess" +
                "\n\t\tModern Carrera's Chess" +
                "\n\t\tGothic Chess" +
                "\n\t\tGrotesque Chess" +
                "\n\t\tEmbassy Chess" +
                "\n\t\tVictorian Chess" +
                "\n\t\tLadorean Chess" +
                "\n\t\tSchoolbook Chess" +
                "\n\t\tUnivers Chess" +
                "\n\t\tOpti Chess" +
                "\n\tGrand Chess" +
                "\n\tFalcon Chess" +
                "\n\tOdin's Rune Chess" +
                "\n\tEurasian Chess" +
                "\n\tUnicorn Great Chess" +
                "\n.Large" +
                "\n\tWildebeest Chess" +
                "\n\tOmega Chess" +
                "\n\tGross Chess" +
                "\n\tDouble Chess (16 x 8)" +
                "\n\tOdyssey" +
                "\n\tChess on a 12 by 12 Board" +
                "\n.Historical" +
                "\n\tShatranj" +
                "\n\tCourier Chess" +
                "\n\tArchchess" +
                "\n\tEmperor's Game";

            byte[]     gameCatalogBytes = Encoding.ASCII.GetBytes(gameCatalog);
            TextReader textReader       = new StreamReader(new MemoryStream(gameCatalogBytes));

            GameCatalog.LoadIndex(textReader);


            // *** START APPLICATION *** //

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            try
            {
                Application.Run(new MainForm());
            }
            catch (Exception ex)
            {
                ExceptionForm exform;
                if (ex is ChessV.Exceptions.ChessVException)
                {
                    exform = new ExceptionForm(((ChessV.Exceptions.ChessVException)ex).InnerException, ((ChessV.Exceptions.ChessVException)ex).Game);
                }
                else
                {
                    exform = new ExceptionForm(ex, null);
                }
                exform.ShowDialog();
                return;
            }
        }
コード例 #3
0
ファイル: ThemeFactory.cs プロジェクト: ColinSuess/ChessVFork
        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);
        }
コード例 #4
0
ファイル: ThemeFactory.cs プロジェクト: ColinSuess/ChessVFork
        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));
        }