コード例 #1
0
        // This switches to the mode with arguments
        public void SwitchToMode(object[] args)
        {
            // Only when a map is opened
            if (General.Map != null)
            {
                // Create instance
                EditMode newmode = plugin.CreateObjectA <EditMode>(type, args);

                // Switch mode
                if (!General.Editing.ChangeMode(newmode))
                {
                    // When cancelled, dispose mode
                    newmode.Dispose();
                }
            }
        }
コード例 #2
0
        //
        // This changes the editing mode.
        // Order in which events occur for the old and new modes:
        //
        // - Constructor of new mode is called
        // - Disengage of old mode is called
        // ----- Mode switches -----
        // - Engage of new mode is called
        // - Dispose of old mode is called
        //
        // Returns false when cancelled
        public bool ChangeMode(EditMode nextmode)
        {
            EditMode oldmode = mode;

            if (nextmode != null)
            {
                // Verify that this mode is usable
                bool allowuse = false;
                foreach (EditModeInfo emi in usedmodes)
                {
                    if (emi.Type.FullName == nextmode.GetType().FullName)
                    {
                        allowuse = true;
                        break;
                    }
                }

                if (!allowuse)
                {
                    General.Interface.MessageBeep(MessageBeepType.Error);
                    General.WriteLogLine("Attempt to switch to an invalid edit mode " + nextmode.GetType().Name + "!");
                    return(false);
                }
                else
                {
                    General.WriteLogLine("Preparing to change editing mode to " + nextmode.GetType().Name + "...");
                }
            }
            else
            {
                General.WriteLogLine("Stopping editing mode...");
            }

            // Remember previous mode
            newmode = nextmode;
            if (mode != null)
            {
                prevmode = mode.GetType();
                if (!mode.Attributes.Volatile)
                {
                    prevstablemode = prevmode;
                    if (mode is ClassicMode)
                    {
                        prevclassicmode = prevmode;
                    }
                }
            }
            else
            {
                prevmode        = null;
                prevstablemode  = null;
                prevclassicmode = null;
            }

            // Let the plugins know beforehand and check if not cancelled
            if (General.Plugins.ModeChanges(oldmode, newmode))
            {
                // Disenagage old mode
                disengaging = true;
                if (oldmode != null)
                {
                    General.Plugins.OnEditDisengage(oldmode, newmode);
                    oldmode.OnDisengage();
                }

                // Reset cursor
                General.Interface.SetCursor(Cursors.Default);

                // Apply new mode
                General.WriteLogLine("Editing mode changes from " + TypeNameOrNull(oldmode) + " to " + TypeNameOrNull(nextmode));
                General.WriteLogLine("Previous stable mode is " + TypeNameOrNull(prevstablemode) + ", previous classic mode is " + TypeNameOrNull(prevclassicmode));
                mode        = newmode;
                disengaging = false;

                // Engage new mode
                if (newmode != null)
                {
                    newmode.OnEngage();
                    General.Plugins.OnEditEngage(oldmode, newmode);
                }

                // Bind new switch actions
                UnbindSwitchActions();
                BindAvailableSwitchActions();

                // Update the interface
                General.MainWindow.EditModeChanged();

                // Dispose old mode
                if (oldmode != null)
                {
                    oldmode.Dispose();
                }

                // Done switching
                General.WriteLogLine("Editing mode change complete.");
                newmode = null;

                // Redraw the display
                General.MainWindow.RedrawDisplay();
                return(true);
            }
            else
            {
                // Cancelled
                General.WriteLogLine("Editing mode change cancelled.");
                return(false);
            }
        }