Exemple #1
0
        /// <summary>
        /// Attempts to open the level at the specified index either for playing or editing.
        /// </summary>
        /// <param name="index">The index of the level to be opened, or null to deselect the current level.</param>
        /// <param name="state">Must be <see cref="LevelListBoxState.Playing"/> or <see cref="LevelListBoxState.Editing"/>. Ignored if index is null.</param>
        private void setActiveLevel(int?index, LevelListBoxState state)
        {
            if (LevelActivating != null)
            {
                // Confirm with the owner that the level can be changed
                ConfirmEventArgs args = new ConfirmEventArgs {
                    ConfirmOK = true
                };
                LevelActivating(this, args);
                if (!args.ConfirmOK)
                {
                    return;
                }
            }

            if (index == null)
            {
                _activeLevelIndex = null;
            }
            else if (index.Value < 0 || index.Value >= Items.Count || !(Items[index.Value] is SokobanLevel))
            {
                Ut.InternalError();
            }
            else
            {
                SokobanLevelStatus status;
                if (state == LevelListBoxState.Playing && (status = ((SokobanLevel)Items[index.Value]).Validity) != SokobanLevelStatus.Valid)
                {
                    string problem = status == SokobanLevelStatus.NotEnclosed
                        ? Program.Tr.Mainform_Validity_NotEnclosed
                        : Program.Tr.Mainform_Validity_WrongNumber;
                    if (DlgMessage.Show(Program.Tr.Mainform_Validity_CannotOpen + "\n\n" + problem + "\n\n" + Program.Tr.Mainform_Validity_CannotOpen_Fix,
                                        Program.Tr.Mainform_MessageTitle_OpenLevel, DlgType.Error, Program.Tr.Mainform_Validity_CannotOpen_btnEdit, Program.Tr.Dialogs_btnCancel) == 0)
                    {
                        _state            = LevelListBoxState.Editing;
                        _activeLevelIndex = index.Value;
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    _state            = state;
                    _activeLevelIndex = index.Value;
                }
            }

            RefreshItems();

            // Inform the owner that the level has changed
            LevelActivated(this, new EventArgs());

            // Make the active level selected
            SelectActiveLevel();
        }
Exemple #2
0
 /// <summary>
 /// Called by the level list to verify that it is OK to switch levels.
 /// </summary>
 private void levelActivating(object sender, ConfirmEventArgs e)
 {
     e.ConfirmOK = ctMainArea.MayDestroy(Program.Tr.Mainform_MessageTitle_OpenLevel);
 }