Ejemplo n.º 1
0
        public static void Open(MainWindow window, Model model)
        {
            bool goAhead = true;

            if (model != null && model.IsDirty && !CommandDoer.PromptSave(window, model))
            {
                goAhead = false;
            }

            if (goAhead)
            {
                System.Windows.Forms.OpenFileDialog ofd = new System.Windows.Forms.OpenFileDialog();
                ofd.InitialDirectory = CommandDoer.MapsDirectory;
                System.Windows.Forms.DialogResult result = ofd.ShowDialog();
                if (result == System.Windows.Forms.DialogResult.OK)
                {
                    string    filename  = ofd.FileName;
                    MapParser mapParser = new MapParser(filename, window.TileTemplateLookup);
                    window.ActiveModel         = mapParser.Parse();
                    window.ActiveModel.IsDirty = false;
                    window.InvalidateDrawing();
                    window.UpdateTitle();
                }
            }
        }
        private void Draw(MouseEventArgs e)
        {
            Point p     = e.GetPosition(this.clicker_catcher);
            int   x     = (int)p.X;
            int   y     = (int)p.Y;
            int   layer = Model.LayerCutoff;

            y -= this.RenderTop;
            x -= this.RenderMiddle;
            y += 8 * (layer + 1);
            int col = (y + x / 2) / 16;
            int row = (y - x / 2) / 16;

            this.LastX = col;
            this.LastY = row;

            if (this.isDrawing)
            {
                if (this.level.ModifyTile(col, row, layer, this.isErasing ? null : Model.ActiveTileSwatch))
                {
                    this.level.IsDirty = true;
                    this.Refresh(col, row);
                }
            }

            MainWindow.UpdateTitle();
        }
Ejemplo n.º 3
0
        // returns false if the user hit cancel or the document was not saved.
        public static bool Save(MainWindow window, Model model)
        {
            if (model == null)
            {
                return(false);
            }

            if (model.Path == null)
            {
                return(CommandDoer.SaveAs(window, model));
            }
            else
            {
                if (model.IsDirty)
                {
                    string fileContents = model.Serialize();
                    System.IO.File.WriteAllText(model.Path, fileContents);
                    model.IsDirty = false;
                    window.UpdateTitle();
                }
            }
            return(false);
        }
Ejemplo n.º 4
0
 public static void New(MainWindow window, Model model)
 {
     window.ActiveModel = new Model(16, 14);
     window.InvalidateDrawing();
     window.UpdateTitle();
 }