Exemple #1
0
        /// <summary>
        /// Invoked by "Level => Change player name". Allows the user to change the
        /// name used to identify them in highscore lists.
        /// </summary>
        private void changePlayer(object sender, EventArgs e)
        {
            var newName = ChoosePlayerNameForm.GetPlayerName(ChoosePlayerNameForm.FormType.Standard, Program.Settings.PlayerName);

            if (newName != null && newName != Program.Settings.PlayerName)
            {
                Program.Settings.PlayerName = newName;
                Program.Settings.SaveThreaded();
                lstLevels.RefreshItems();
            }
        }
Exemple #2
0
        public static string GetPlayerName(FormType type, string defaultValue, LanguageHelperWinForms <Translation> translationHelper = null)
        {
            using (var dlg = new ChoosePlayerNameForm(type, defaultValue))
            {
                if (translationHelper != null)
                {
                    translationHelper.TranslationChanged += dlg.translationChanged;
                    translationHelper.MakeLanguageComboBox(dlg.cmbLanguage);
                }

                var result = dlg.ShowDialog();
                if (translationHelper != null)
                {
                    translationHelper.TranslationChanged -= dlg.translationChanged;
                }
                if (result == DialogResult.Cancel)
                {
                    return(null);
                }
                return(dlg.txtPlayerName.Text);
            }
        }
Exemple #3
0
        /// <summary>
        /// Invoked whenever the user solves the level. Remembers the solved level and
        /// tells the level list to update itself.
        /// </summary>
        private void levelSolved(object sender, EventArgs e)
        {
            // Set the LevelListBox to JustSolved state
            lstLevels.JustSolved();

            // If the user hasn't chosen a name for themselves yet, ask them
            if (string.IsNullOrWhiteSpace(Program.Settings.PlayerName))
            {
                Program.Settings.PlayerName = ChoosePlayerNameForm.GetPlayerName(ChoosePlayerNameForm.FormType.SolvedLevel, "");
            }

            // If they still haven't chosen a name, discard the high score
            if (string.IsNullOrWhiteSpace(Program.Settings.PlayerName))
            {
                return;
            }

            Program.Settings.UpdateHighscore(lstLevels.ActiveLevel.ToString(), ctMainArea.Moves, ctMainArea.Pushes);
            Program.Settings.SaveThreaded();

            lstLevels.RefreshItems();
        }
Exemple #4
0
        /// <summary>
        /// Constructor. Constructs the main form for the application.
        /// </summary>
        public Mainform()
            : base(Program.Settings.MainFormSettings)
        {
            InitializeComponent();
            mnuMain.Renderer    = new NativeToolStripRenderer();
            mnuContext.Renderer = new NativeToolStripRenderer();

#if DEBUG
            // Auto-generate the translation classes for automated form translation
            using (var generator = new Lingo.TranslationFileGenerator(@"..\..\main\ExpSok\Translation.g.cs"))
            {
                using (var form = new AboutBox(false))
                    generator.TranslateControl(form, Program.Tr.AboutBox);

                using (var form = new HighscoresForm(false))
                    generator.TranslateControl(form, Program.Tr.Highscores);

                using (var form = new ChoosePlayerNameForm(false))
                    generator.TranslateControl(form, Program.Tr.ChoosePlayerName);

                generator.TranslateControl(this, Program.Tr.Mainform);
                generator.TranslateControl(mnuContext, Program.Tr.Context);
            }
#else
            Lingo.TranslateControl(this, Program.Tr.Mainform);
            Lingo.TranslateControl(mnuContext, Program.Tr.Context);
#endif

            _translationHelper = new LanguageHelperWinForms <Translation>("Expert Sokoban", "ExpSok", Program.TranslationEnabled,
                                                                          Program.Settings.TranslationFormSettings, Icon, () => Program.Tr.Language);
            _translationHelper.TranslationChanged += translationChanged;
            _translationHelper.MakeLanguageMenu(mnuOptionsChangeLanguage);

            // Restore saved settings
            mnuOptionsPlayingToolbar.Checked   = Program.Settings.DisplayPlayingToolbar;
            mnuOptionsFileToolbars.Checked     = Program.Settings.DisplayFileToolbars;
            mnuOptionsEditLevelToolbar.Checked = Program.Settings.DisplayEditLevelToolbar;
            ctStatusBar.Visible = mnuOptionsStatusBar.Checked = Program.Settings.DisplayStatusBar;
            grpMovePathOptions.SetValue(Program.Settings.MoveDrawMode);
            grpPushPathOptions.SetValue(Program.Settings.PushDrawMode);
            grpEditTool.SetValue(Program.Settings.LastUsedTool);
            mnuOptionsEndPos.Checked        = ctMainArea.ShowEndPos = Program.Settings.ShowEndPos;
            mnuOptionsAreaSokoban.Checked   = ctMainArea.ShowAreaSokoban = Program.Settings.ShowAreaSokoban;
            mnuOptionsAreaPiece.Checked     = ctMainArea.ShowAreaPiece = Program.Settings.ShowAreaPiece;
            mnuOptionsSound.Checked         = ctMainArea.SoundEnabled = Program.Settings.SoundEnabled;
            mnuOptionsAnimation.Checked     = ctMainArea.AnimationEnabled = Program.Settings.AnimationEnabled;
            mnuOptionsLetterControl.Checked = ctMainArea.LetteringEnabled = Program.Settings.LetteringEnabled;

            if (string.IsNullOrWhiteSpace(Program.Settings.PlayerName))
            {
                Program.Settings.PlayerName = ChoosePlayerNameForm.GetPlayerName(ChoosePlayerNameForm.FormType.FirstRun, "", _translationHelper);
            }

            // Restore the last used level file
            try
            {
                lstLevels.LoadLevelPack(Program.Settings.LevelFilename);
            }
            catch
            {
                lstLevels.NewList();
                lstLevels.AddLevelListItem(SokobanLevel.TestLevel);
                lstLevels.Modified = false;
            }

            showLevelList(Program.Settings.DisplayLevelList);
            lstLevels.PlayFirstUnsolved();
            updateControls();

            // ManagedForm sets the form's Font in the Load event. This potentially changes the width of the level list, which in turn causes its Resize event, which in turn updates Program.Settings.LevelListWidth.
            // To work around this, remember the width from the settings file and defer setting the level list's width until the Load event.
            int levelListWidth = Program.Settings.LevelListWidth < 50 ? 50 : Program.Settings.LevelListWidth;
            Load += (s, e) => pnlLevelList.Width = levelListWidth;
        }