示例#1
0
 public static void Main()
 {
     var viewModel = new ViewModel();
     var mainForm = new MainForm(viewModel);
     var mainFormPresenter = new MainFormPresenter(mainForm, viewModel);
     mainFormPresenter.Run();
 }
示例#2
0
        public MainForm(ViewModel viewModel)
        {
            this.InitializeComponent();

            this.SuspendLayout();

            this.mapTreeView = new MapTreeView();
            this.LeftSplitContainer.Panel2.Controls.Add(this.mapTreeView);
            this.mapTreeView.BorderStyle = BorderStyle.None;
            this.mapTreeView.Dock = DockStyle.Fill;
            this.mapTreeView.DrawMode = TreeViewDrawMode.OwnerDrawAll;
            this.mapTreeView.FullRowSelect = true;
            this.mapTreeView.HideSelection = false;
            this.mapTreeView.ImageKey = "PageWhite"; // unused?
            this.mapTreeView.ItemHeight = 21;
            this.mapTreeView.ShowLines = false;
            this.mapTreeView.ShowRootLines = false;

            this.mapEditor = new MapEditor();
            this.mapEditor.BorderStyle = BorderStyle.Fixed3D;
            this.mapEditor.Dock = DockStyle.Fill;
            this.MainSplitContainer.Panel2.Controls.Add(this.mapEditor);

            this.tileSetPalette = new Shrimp.Views.TileSetPalette();
            this.tileSetPalette.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left;
            this.tileSetPalette.AutoScroll = true;
            this.LeftSplitContainer.Panel1.Controls.Add(this.tileSetPalette);

            this.ToolStrip.Renderer = new CustomToolStripSystemRenderer();
            this.TileSetPaletteToolStrip.Renderer = new CustomToolStripSystemRenderer();
            this.tileSetPalette.Size = new Size
            {
                Width = Util.PaletteGridSize * Util.PaletteHorizontalCount
                    + SystemInformation.VerticalScrollBarWidth,
                Height = this.tileSetPalette.Parent.ClientSize.Height
                    - this.TileSetPaletteToolStrip.Height,
            };
            this.MainSplitContainer.SplitterDistance -=
                this.tileSetPalette.Parent.ClientSize.Width - this.tileSetPalette.Width;

            this.ResumeLayout(false);

            this.Layer1ToolStripButton.Tag = LayerMode.Layer1;
            this.Layer2ToolStripButton.Tag = LayerMode.Layer2;
            this.LayerEventToolStripButton.Tag = LayerMode.Event;
            foreach (var item in this.LayerModeSwitchers)
            {
                item.Click += (sender, e) =>
                {
                    LayerMode layerMode = (LayerMode)((ToolStripButton)sender).Tag;
                    this.OnLayerModeSwitcherClick(new LayerModeSwitcherClickEventArgs(layerMode));
                };
            }

            this.PenToolStripButton.Tag = DrawingMode.Pen;
            foreach (var item in this.DrawingModeSwitchers)
            {
                item.Click += (sender, e) =>
                {
                    DrawingMode drawingMode = (DrawingMode)((ToolStripButton)sender).Tag;
                    this.OnDrawingModeSwitcherClick(new DrawingModeSwitcherClickEventArgs(drawingMode));
                };
            }

            this.Scale1ToolStripButton.Tag = ScaleMode.Scale1;
            this.Scale2ToolStripButton.Tag = ScaleMode.Scale2;
            this.Scale4ToolStripButton.Tag = ScaleMode.Scale4;
            this.Scale8ToolStripButton.Tag = ScaleMode.Scale8;
            foreach (var item in this.ScaleModeSwitchers)
            {
                item.Click += (sender, e) =>
                {
                    ScaleMode scaleMode = (ScaleMode)((ToolStripButton)sender).Tag;
                    this.OnScaleModeSwitcherClick(new ScaleModeSwitcherClickEventArgs(scaleMode));
                };
            }
        }
示例#3
0
        public MainFormPresenter(IMainForm mainForm, ViewModel viewModel)
        {
            this.MainForm = mainForm;
            this.ViewModel = viewModel;
            this.MainForm.CloseButtonClick += this.MainForm_CloseButtonClick;
            this.MainForm.DrawingModeSwitcherClick += this.MainForm_DrawingModeSwitcherClick;
            this.MainForm.FormClosing += (sender, e) =>
            {
                if (this.ViewModel.IsDirty)
                {
                    DialogResult result = MessageBox.Show("Save?", "",
                        MessageBoxButtons.YesNoCancel,
                        MessageBoxIcon.Question,
                        MessageBoxDefaultButton.Button1);
                    switch (result)
                    {
                    case DialogResult.Yes:
                        this.ViewModel.Save();
                        break;
                    case DialogResult.No:
                        break;
                    case DialogResult.Cancel:
                        e.Cancel = true;
                        return;
                    }
                }
            };
            this.MainForm.LayerModeSwitcherClick += this.MainForm_LayerModeSwitcherClick;
            this.MainForm.NewButtonClick += this.MainForm_NewButtonClick;
            this.MainForm.OpenButtonClick += this.MainForm_OpenButtonClick;
            this.MainForm.PassageButtonClick += this.MainForm_PassageButtonClick;
            this.MainForm.SaveButtonClick += this.MainForm_SaveButtonClick;
            this.MainForm.ScaleModeSwitcherClick += this.MainForm_ScaleModeSwitcherClick;
            this.MainForm.TileSetSelectorSelectedIndexChanged += this.MainForm_TileSetSelectorSelectedIndexChanged;
            this.MainForm.UndoButtonClick += this.MainForm_UndoButtonClick;

            this.ViewModel.IsOpenedChanged += delegate
            {
                this.IsOpenedChanged();
            };
            this.ViewModel.IsUndoableChanged += delegate
            {
                this.IsUndoableChanged();
            };
            this.ViewModel.Project.Updated += (sender, e) =>
            {
                Project project = (Project)sender;
                if (e.Property == project.GetProperty(_ => _.GameTitle))
                {
                    this.GameTitleChanged();
                }
            };
            this.ViewModel.EditorState.Updated += (sender, e) =>
            {
                EditorState editorState = (EditorState)sender;
                if (e.Property == editorState.GetProperty(_ => _.MapId))
                {
                    this.MapIdChanged();
                }
                else if (e.Property == editorState.GetProperty(_ => _.SelectedTileSetIds))
                {
                    this.SelectedTileSetIdsChanged();
                }
                else if (e.Property == editorState.GetProperty(_ => _.LayerMode))
                {
                    this.LayerModeChanged();
                }
                else if (e.Property == editorState.GetProperty(_ => _.DrawingMode))
                {
                    this.DrawingModeChanged();
                }
                else if (e.Property == editorState.GetProperty(_ => _.ScaleMode))
                {
                    this.ScaleModeChanged();
                }
                else if (e.Property == editorState.GetProperty(_ => _.TileSetMode))
                {
                    this.TileSetModeChanged();
                }
            };
            this.IsOpenedChanged();
            this.MapTreeViewPresenter = new MapTreeViewPresenter(this.MainForm.MapTreeView, this.ViewModel);
            this.MapEditorPresenter = new MapEditorPresenter(this.MainForm.MapEditor, this.ViewModel);
            this.TileSetPalettePresenter = new TileSetPalettePresenter(this.MainForm.TileSetPalette, this.ViewModel);
        }