Example #1
0
        protected override void OnShown(EventArgs e)
        {
            base.OnShown(e);

            // Initialize the available editor modes and generate their toolbuttons
            TilesetEditorMode[] modeInstances = DualityEditorApp.GetAvailDualityEditorTypes(typeof(TilesetEditorMode))
                                                .Where(t => !t.IsAbstract)
                                                .Select(t => t.CreateInstanceOf() as TilesetEditorMode)
                                                .NotNull()
                                                .OrderBy(t => t.SortOrder)
                                                .ToArray();
            this.availableModes = new EditorModeInfo[modeInstances.Length];
            for (int i = 0; i < this.availableModes.Length; i++)
            {
                TilesetEditorMode mode = modeInstances[i];
                mode.Init(this);

                ToolStripButton modeItem = new ToolStripButton(mode.Name, mode.Icon);
                modeItem.AutoToolTip = false;
                modeItem.ToolTipText = null;
                modeItem.Tag         = HelpInfo.FromText(mode.Name, mode.Description);
                modeItem.Click      += this.modeToolButton_Click;

                this.toolStripModeSelect.Items.Add(modeItem);
                this.availableModes[i] = new EditorModeInfo
                {
                    Mode       = mode,
                    ToolButton = modeItem
                };
            }

            // If we have at least one mode available, activate it
            if (this.availableModes.Length > 0)
            {
                this.SetActiveEditorMode(this.availableModes[0].Mode);
            }

            // Subscribe for global editor events
            DualityEditorApp.ObjectPropertyChanged += this.DualityEditorApp_ObjectPropertyChanged;
            DualityEditorApp.SelectionChanged      += this.DualityEditorApp_SelectionChanged;

            // Apply editor-global tileset selection
            this.ApplyGlobalTilesetSelection(SelectionChangeReason.Unknown);

            // Start recording tileset changes for Apply / Revert support
            this.StartRecordTilesetChanges();
        }
Example #2
0
        private void SetActiveEditorMode(TilesetEditorMode mode)
        {
            UndoRedoManager.Finish();

            // Reset the layer view selection
            this.layerView.SelectedNode = null;

            if (this.activeMode != null)
            {
                this.activeMode.RaiseOnLeave();
            }

            this.activeMode = mode;

            // Assign the new data model to the layer view
            this.layerView.Model = (this.activeMode != null) ? this.activeMode.LayerModel : null;

            if (this.activeMode != null)
            {
                this.activeMode.RaiseOnEnter();
            }

            // Update tool buttons so the appropriate one is checked
            for (int i = 0; i < this.availableModes.Length; i++)
            {
                EditorModeInfo info = this.availableModes[i];
                info.ToolButton.Checked = (info.Mode == mode);
            }

            // Update Add / Remove layer buttons
            bool canAddRemove = (this.activeMode != null) ?
                                this.activeMode.AllowLayerEditing.HasFlag(LayerEditingCaps.AddRemove) :
                                false;

            this.buttonAddLayer.Visible    = canAddRemove;
            this.buttonRemoveLayer.Visible = canAddRemove;
            this.buttonRemoveLayer.Enabled = (this.layerView.SelectedNode != null);

            // Different editor modes might allow or disallow drawing tile indices
            this.ApplyTileIndexDrawMode();

            // Invalidate TilesetView because editor modes are likely to
            // draw custom overlays using its event handlers. Directly show
            // the effect of having a different editing mode selected.
            this.tilesetView.Invalidate();
        }