private void addButton_Click(object sender, EventArgs e)
        {
            using (ComposedForm composed = new ComposedForm("Select name and direction",
                ComposedForm.Parts.Name | ComposedForm.Parts.Direction,
                ComposedForm.Parts.Name)) {
                foreach (string groupName in groups.Keys) {
                    composed.AddNameChecker(s => s.Trim() != groupName.Split('.')[0]);
                }
                composed.AddNameChecker(s => !s.Contains("."));
                if (composed.ShowDialog(this) == DialogResult.OK) {

                    using (AnimationSelector selector = new AnimationSelector(CurrentSheet, project)) {
                        if (selector.ShowDialog(this) == DialogResult.OK) {
                            string name = composed.GetName();
                            if (composed.GetDirection() == "") {
                                AddAnimationGroup(name + ".down", selector.SelectedFrames);
                                AddAnimationGroup(name + ".left", selector.SelectedFrames);
                                AddAnimationGroup(name + ".right", selector.SelectedFrames);
                                AddAnimationGroup(name + ".up", selector.SelectedFrames);
                            }
                            else {
                                AddAnimationGroup(name + "." + composed.GetDirection(), selector.SelectedFrames);
                            }
                        }
                    }
                }
            }
        }
Beispiel #2
0
 private void resizeToolStripMenuItem_Click(object sender, EventArgs e)
 {
     Size thisSize = new Size(currentMap.width, currentMap.height);
     using(ComposedForm form = new ComposedForm("Resize map", ComposedForm.Parts.Size)) {
         form.SetSize(thisSize);
         if (form.ShowDialog() == DialogResult.OK) {
             Size newSize = form.GetSize();
             if (thisSize != newSize) {
                 currentMap.Resize(newSize.Width, newSize.Height);
             }
             mainPanel.Invalidate();
         }
     }
 }
Beispiel #3
0
        public EditorForm()
        {
            Application.ThreadException += this.UnhandledExceptionHandler;

            InitializeComponent();

            MainPanelForm mainPanelForm = new MainPanelForm();
            mainPanel = mainPanelForm.mainPanel;
            hScrollBar = mainPanelForm.hScrollBar;
            vScrollBar = mainPanelForm.vScrollBar;
            mainPanelForm.DockHandler.Show(dockPanel, WeifenLuo.WinFormsUI.Docking.DockState.Document);
            mainPanel.MouseClick += this.mainPanel_MouseClick;
            mainPanel.Paint += this.mainPanel_Paint;
            mainPanel.MouseDown += this.mainPanel_MouseDown;
            mainPanel.MouseUp += this.mainPanel_MouseUp;
            mainPanel.MouseMove += this.mainPanel_MouseMove;

            layers = new LayersToolbar();
            BindFormWithMenuItem(layers, layersToolStripMenuItem);
            layers.checkedListBox.ItemCheck += UpdateEventHandler;
            layers.checkedListBox.SelectedIndexChanged += UpdateEventHandler;
            layers.addbutton.Click += (sender, args) => {
                using(ComposedForm form = new ComposedForm("New layer", ComposedForm.Parts.Name)) {
                    if (form.ShowDialog() == DialogResult.OK) {
                        currentMap.CreateNewLayer(form.GetName());
                        layers.Load(currentMap);
                        mainPanel.Invalidate();
                    }
                }
            };
            layers.deletebutton.Click += (sender, args) => {
                if (currentMap.layerGroups.Count == 1) {
                    MessageBox.Show("Cannot remove last layer!", "Last layer");
                }
                else {
                    int count = 0;
                    for (int i = 0; i < currentMap.ladders.GetLength(0); ++i) {
                        for (int j = 0; j < currentMap.ladders.GetLength(1); ++j) {
                            Map.Ladder ladder = currentMap.ladders[i, j];
                            if (ladder != null && (ladder.baseLayer == CurrentLayer[0] || ladder.topLayer == CurrentLayer[0])) ++count;
                        }
                    }
                    string message;
                    if (count == 0) {
                        message = string.Format("Do you want to remove layer \"{0}\"?", layers.checkedListBox.SelectedItem);
                    }
                    else {
                        message = string.Format("Do you want to remove layer \"{0}\"? The layer contains {1} ladder(s), they will be removed!", layers.checkedListBox.SelectedItem, count);
                    }
                    if (MessageBox.Show(layers, message, "Remove layer", MessageBoxButtons.YesNo) == DialogResult.Yes) {
                        for (int i = 0; i < currentMap.ladders.GetLength(0); ++i) {
                            for (int j = 0; j < currentMap.ladders.GetLength(1); ++j) {
                                Map.Ladder ladder = currentMap.ladders[i, j];
                                if (ladder != null && (ladder.baseLayer == CurrentLayer[0] || ladder.topLayer == CurrentLayer[0])) currentMap.ladders[i, j] = null;
                            }
                        }
                        currentMap.layerGroups.Remove(CurrentLayer);
                        layers.Load(currentMap);
                        mainPanel.Invalidate();
                    }
                }
            };
            layers.upbutton.Click += (sender, args) => {
                int index = layers.checkedListBox.SelectedIndex;
                if (index == 0) return;
                int lindex = currentMap.layerGroups.Count - index - 1;
                LayerGroup layer = currentMap.layerGroups[lindex];
                currentMap.layerGroups.RemoveAt(lindex);
                currentMap.layerGroups.Insert(lindex + 1, layer);
                layers.Load(currentMap);
                layers.checkedListBox.SelectedIndex = index - 1;
                mainPanel.Invalidate();
            };
            layers.downbutton.Click += (sender, args) => {
                int index = layers.checkedListBox.SelectedIndex;
                if (index == currentMap.layerGroups.Count - 1) return;
                int lindex = currentMap.layerGroups.Count - index - 1;
                LayerGroup layer = currentMap.layerGroups[lindex];
                currentMap.layerGroups.RemoveAt(lindex);
                currentMap.layerGroups.Insert(lindex - 1, layer);
                layers.Load(currentMap);
                layers.checkedListBox.SelectedIndex = index + 1;
                mainPanel.Invalidate();
            };

            var audio = new AudioLibrary();
            projectLoadables.Add(audio);
            BindFormWithMenuItem(audio, audioLibraryToolStripMenuItem);

            var images = new ImageLibrary();
            projectLoadables.Add(images);
            BindFormWithMenuItem(images, imageLibraryToolStripMenuItem);

            var palette = new Palette();
            projectLoadables.Add(palette);
            BindFormWithMenuItem(palette, paletteToolStripMenuItem);
            palette.PaletteSelectionChanged += (sender, args) => {
                this.cursor = args.Cursor;
            };

            var animations = new AnimationLibrary();
            projectLoadables.Add(animations);
            BindFormWithMenuItem(animations, animationLibraryToolStripMenuItem);

            specialViewComboBox.SelectedIndex = 0;

            mainPanel.Resize += (sender, args) => CalculateScrollbars();
            CalculateScrollbars();
            vScrollBar.ValueChanged += UpdateEventHandler;
            hScrollBar.ValueChanged += UpdateEventHandler;

            mru.Changed += (sender, args) => RecreateMRUList();
            RecreateMRUList();

            cursor = new TileCursor();

            this.ProjectLoaded += (sender, args) => {
                EnableControls();
                mainPanel.Invalidate();
            };
            this.Disposed += this.OnDisposed;
        }
Beispiel #4
0
 private void newMapToolStripMenuItem_Click(object sender, EventArgs e)
 {
     using(ComposedForm form = new ComposedForm("New map", ComposedForm.Parts.Name | ComposedForm.Parts.Size)) {
         if (form.ShowDialog() == DialogResult.OK) {
             string name = form.GetName();
             Size size = form.GetSize();
             Map map = new Map(name, size);
             currentProject.maps.Add(name, map);
             mapComboBox.Items.Add(name);
             ChangeCurrentMap(name);
         }
     }
 }
Beispiel #5
0
 private void locationMenuItem_Click(object sender, EventArgs e)
 {
     using(ComposedForm form = new ComposedForm("Location name", ComposedForm.Parts.Name, ComposedForm.Parts.None)) {
         string originalName = CurrentLayer[0].tiles[tileLocation.Value.X, tileLocation.Value.Y].locationName;
         form.SetName(originalName);
         if (form.ShowDialog(this) == DialogResult.OK) {
             var undoName = string.Format("Changed location: {0} -> {1}", originalName, form.GetName());
             currentProject.Undo.DoCommand(new UndoCommandList(undoName, new UndoCommand(
                                               delegate() {
                                                   CurrentLayer[0].tiles[tileLocation.Value.X, tileLocation.Value.Y].locationName = form.GetName();
                                               },
                                               delegate() {
                                                   CurrentLayer[0].tiles[tileLocation.Value.X, tileLocation.Value.Y].locationName = originalName;
                                               }
                                           )));
         }
     }
 }