Ejemplo n.º 1
0
        public void RedrawBackground()
        {
            TilesetModel model        = this.TilesetModel.Value;
            Size         extendedSize = new Size();

            extendedSize.Width  = model.PixelWidth.Value + model.TileWidth.Value;
            extendedSize.Height = model.PixelHeight.Value + model.TileHeight.Value;
            Point extendedPoint = new Point();

            extendedPoint.X = -model.TileWidth.Value / 2;
            extendedPoint.Y = -model.TileHeight.Value / 2;
            Rect drawingRect = new Rect(extendedPoint, extendedSize);

            Size backgroundSize = new Size();

            backgroundSize.Width  = model.PixelWidth.Value;
            backgroundSize.Height = model.PixelHeight.Value;
            Point backgroundPoint = new Point();

            backgroundPoint.X = 0;
            backgroundPoint.Y = 0;
            Rect backgroundRectangle = new Rect(backgroundPoint, backgroundSize);

            Application.Current.Dispatcher.BeginInvoke(new Action(() =>
            {
                using (DrawingContext context = this.extendedBorder.Open())
                {
                    context.DrawRectangle(Brushes.Transparent, new Pen(Brushes.Transparent, 0), drawingRect);
                    context.DrawRectangle(this.BackgroundBrush.Value, this.BackgroundPen.Value, backgroundRectangle);
                }
            }), DispatcherPriority.Render);
        }
Ejemplo n.º 2
0
        private void UpdateTilesetModel()
        {
            TilesetModel model = this.TilesetModel.Value;

            this.itemTransform.SetPixelToTile(model.TileWidth.Value, model.TileHeight.Value, model.OffsetX.Value, model.OffsetY.Value, model.PaddingX.Value, model.PaddingY.Value);
            RedrawGrid();
        }
Ejemplo n.º 3
0
        public Map Generate(string path)
        {
            // TODO use a loader for tileset models
            IList <TilesetModel> tilesets = new List <TilesetModel>();

            foreach (TilesetJson tilesetJson in this.TilesetJsons)
            {
                TilesetModel tileset = tilesetJson.Generate();
                tilesets.Add(tileset);
                tileset.RefreshTilesetImage();
            }

            IList <ILayer> layers = new List <ILayer>();

            foreach (LayerJson layer in this.LayerJsons)
            {
                layers.Add(layer.Generate(tilesets));
            }

            Map map = new Map(this.Name, this.Columns, this.Rows, layers, tilesets);

            map.Version.Value         = this.Version;
            map.Author.Value          = this.Author;
            map.TileWidth.Value       = this.TileWidth;
            map.TileHeight.Value      = this.TileHeight;
            map.Scale.Value           = this.Scale;
            map.BackgroundColor.Value = this.BackgroundColor;
            map.Description.Value     = this.Description;
            map.SourcePath.Value      = path;
            return(map);
        }
Ejemplo n.º 4
0
        public void UpdateMissingContent(IAmeSession session)
        {
            this.session = session;
            this.Title   = "New Tileset";
            string newTilesetName = string.Format("Tileset #{0}", session.CurrentTilesetCount);

            this.tilesetModel = new TilesetModel(session.CurrentTilesetCount, newTilesetName);
            this.Callback     = this.Callback ?? OnNewTilesetWindowClosed;
        }
Ejemplo n.º 5
0
 public TilesetJson(TilesetModel model)
 {
     this.ID               = model.ID;
     this.Name             = model.Name.Value;
     this.SourcePath       = model.SourcePath.Value;
     this.TileWidth        = model.TileWidth.Value;
     this.TileHeight       = model.TileHeight.Value;
     this.Scale            = model.Scale.Value;
     this.IsTransparent    = model.IsTransparent.Value;
     this.TransparentColor = model.TransparentColor.Value;
 }
Ejemplo n.º 6
0
        private void UpdateStampLimits()
        {
            TilesetModel tileset = this.session.CurrentTileset.Value;

            if (tileset != null)
            {
                this.MaxTileWidth.Value   = tileset.Columns.Value - this.BrushTileOffsetX.Value;
                this.MaxTileHeight.Value  = tileset.Rows.Value - this.BrushTileOffsetY.Value;
                this.MaxTileOffsetX.Value = tileset.Columns.Value - this.BrushColumns.Value;
                this.MaxTileOffsetY.Value = tileset.Rows.Value - this.BrushRows.Value;
            }
        }
Ejemplo n.º 7
0
        public TilesetModel Generate()
        {
            TilesetModel tileset = new TilesetModel();

            tileset.ID                     = this.ID;
            tileset.Name.Value             = this.Name;
            tileset.SourcePath.Value       = this.SourcePath;
            tileset.TileWidth.Value        = this.TileWidth;
            tileset.TileHeight.Value       = this.TileHeight;
            tileset.Scale.Value            = this.Scale;
            tileset.IsTransparent.Value    = this.IsTransparent;
            tileset.TransparentColor.Value = this.TransparentColor;
            return(tileset);
        }
Ejemplo n.º 8
0
        private void OnNewTilesetWindowClosed(INotification notification)
        {
            IConfirmation confirmation = notification as IConfirmation;

            if (Mouse.OverrideCursor == Cursors.Pen)
            {
                Mouse.OverrideCursor = null;
            }
            if (confirmation.Confirmed)
            {
                TilesetModel tilesetModel = confirmation.Content as TilesetModel;
                this.session.CurrentTilesets.Value.Add(tilesetModel);
            }
        }
Ejemplo n.º 9
0
        public void AddTileset()
        {
            int          tilesetCount = GetTilesetModelCount(this.Items);
            string       modelName    = string.Format("Tileset #{0}", tilesetCount + 1);
            TilesetModel model        = new TilesetModel(tilesetCount, modelName);

            if (this.Item != null && (this.Item is ItemGroup))
            {
                this.Item.Items.Add(model);
            }
            else
            {
                this.Items.Add(model);
            }
        }
Ejemplo n.º 10
0
        private void OnNewTilesetWindowClosed(INotification notification)
        {
            IConfirmation confirmation = notification as IConfirmation;

            if (Mouse.OverrideCursor == Cursors.Pen)
            {
                Mouse.OverrideCursor = null;
            }
            if (confirmation.Confirmed)
            {
                TilesetModel messageTilesetModel = confirmation.Content as TilesetModel;
                this.Session.CurrentTilesets.Value.Add(messageTilesetModel);
                this.TilesetModel.Value = messageTilesetModel;
                ChangeItemModel(this.TilesetModel.Value);
            }
        }
        private void UpdateTilesetModel()
        {
            TilesetModel model = this.TilesetModel.Value;

            model.Name.Value             = this.Name.Value;
            model.SourcePath.Value       = this.SourcePath.Value;
            model.IsTransparent.Value    = this.IsTransparent.Value;
            model.TransparentColor.Value = this.TransparentColor.Value;
            model.TileWidth.Value        = this.TileWidth.Value;
            model.TileHeight.Value       = this.TileHeight.Value;
            model.OffsetX.Value          = this.OffsetX.Value;
            model.OffsetY.Value          = this.OffsetY.Value;
            model.PaddingX.Value         = this.PaddingX.Value;
            model.PaddingY.Value         = this.PaddingY.Value;
            model.Columns.Value          = this.tilesetPixelWidth / this.TileWidth.Value;
            model.Rows.Value             = this.tilesetPixelHeight / this.TileHeight.Value;
        }
        private void UpdateUI()
        {
            TilesetModel model = this.TilesetModel.Value;

            this.Name.Value             = model.Name.Value;
            this.SourcePath.Value       = model.SourcePath.Value;
            this.TileWidth.Value        = model.TileWidth.Value;
            this.TileHeight.Value       = model.TileHeight.Value;
            this.OffsetX.Value          = model.OffsetX.Value;
            this.OffsetY.Value          = model.OffsetY.Value;
            this.PaddingX.Value         = model.PaddingX.Value;
            this.PaddingY.Value         = model.PaddingY.Value;
            this.IsTransparent.Value    = model.IsTransparent.Value;
            this.TransparentColor.Value = model.TransparentColor.Value;
            this.tilesetPixelWidth      = model.PixelWidth.Value;
            this.tilesetPixelHeight     = model.PixelHeight.Value;
        }
Ejemplo n.º 13
0
        private void OnNewTilesetWindowClosed(INotification notification)
        {
            IConfirmation confirmation = notification as IConfirmation;

            if (Mouse.OverrideCursor == Cursors.Pen)
            {
                Mouse.OverrideCursor = null;
            }
            if (confirmation.Confirmed)
            {
                TilesetModel tilesetModel = confirmation.Content as TilesetModel;
                this.Session.CurrentTilesets.Value.Add(tilesetModel);

                OpenDockMessage message = new OpenDockMessage(typeof(ItemEditorViewModel));
                message.IgnoreIfExists = true;
                message.Content        = tilesetModel;
                this.eventAggregator.GetEvent <OpenDockEvent>().Publish(message);
            }
        }
Ejemplo n.º 14
0
        public void ChangeItemModel(TilesetModel tilesetModel)
        {
            if (tilesetModel == null)
            {
                return;
            }
            if (!this.TilesetModels.Contains(tilesetModel))
            {
                return;
            }
            this.IsSourceLoaded.Value                = true;
            this.TilesetModel.Value                  = tilesetModel;
            this.TilesetModel.Value.IsTransparent    = tilesetModel.IsTransparent;
            this.TilesetModel.Value.TransparentColor = tilesetModel.TransparentColor;
            this.Session.CurrentTileset.Value        = this.TilesetModel.Value;
            this.ItemImage.Value = CvInvoke.Imread(this.TilesetModel.Value.SourcePath.Value, Emgu.CV.CvEnum.ImreadModes.Unchanged);

            this.itemTransform = new CoordinateTransform();
            this.itemTransform.SetPixelToTile(this.TilesetModel.Value.TileWidth.Value, this.TilesetModel.Value.TileHeight.Value);
            this.itemTransform.SetSelectionToPixel(this.TilesetModel.Value.TileWidth.Value / 2, this.TilesetModel.Value.TileHeight.Value / 2);

            this.TilesetModel.Value.IsTransparent.PropertyChanged += IsTransparentChanged;

            Mat drawingMat = this.ItemImage.Value;

            if (this.TilesetModel.Value.IsTransparent.Value)
            {
                drawingMat = ImageUtils.ColorToTransparent(this.ItemImage.Value, this.TilesetModel.Value.TransparentColor.Value);
            }

            Application.Current.Dispatcher.BeginInvoke(new Action(() =>
            {
                using (DrawingContext context = this.tilesetImage.Open())
                {
                    context.DrawDrawing(ImageUtils.MatToImageDrawing(drawingMat));
                }
            }), DispatcherPriority.Render);

            RedrawBackground();
            RedrawGrid();
        }
Ejemplo n.º 15
0
        public ItemEditorCreator(IEventAggregator eventAggregator, IConstants constants, IAmeSession session, TilesetModel tilesetModel, ScrollModel scrollModel)
        {
            this.eventAggregator = eventAggregator ?? throw new ArgumentNullException("eventAggregator is null");
            this.constants       = constants ?? throw new ArgumentNullException("constants is null");
            this.session         = session ?? throw new ArgumentNullException("session is null");

            this.TilesetModel = tilesetModel;
            this.ScrollModel  = scrollModel;
        }
Ejemplo n.º 16
0
 public ItemEditorCreator(IEventAggregator eventAggregator, IConstants constants, IAmeSession session, TilesetModel tilesetModel)
     : this(eventAggregator, constants, session, tilesetModel, null)
 {
 }
Ejemplo n.º 17
0
        public ItemEditorViewModel(IEventAggregator eventAggregator, IConstants constants, IAmeSession session, TilesetModel tilesetModel, IScrollModel scrollModel)
        {
            this.eventAggregator = eventAggregator ?? throw new ArgumentNullException("eventAggregator is null");
            this.Session         = session ?? throw new ArgumentNullException("session is null");
            this.ScrollModel     = scrollModel ?? throw new ArgumentNullException("scrollModel is null");

            this.Title.Value = "Item";

            this.drawingGroup   = new DrawingGroup();
            this.extendedBorder = new DrawingGroup();
            this.tilesetImage   = new DrawingGroup();
            this.gridLines      = new DrawingGroup();
            this.selectLines    = new DrawingGroup();

            this.drawingGroup.Children.Add(this.extendedBorder);
            this.drawingGroup.Children.Add(this.tilesetImage);
            this.drawingGroup.Children.Add(this.gridLines);
            this.drawingGroup.Children.Add(this.selectLines);
            this.TileImage.Value = new DrawingImage(this.drawingGroup);

            this.Scale.Value           = ScaleType.Tile;
            this.PositionText.Value    = "0, 0";
            this.IsGridOn.Value        = true;
            this.GridPen.Value         = new Pen(Brushes.Orange, 1);
            this.BackgroundBrush.Value = (SolidColorBrush)(new BrushConverter().ConvertFrom("#b8e5ed"));
            this.BackgroundPen.Value   = new Pen(Brushes.Transparent, 0);
            this.maxGridThickness      = constants.MaxGridThickness;

            this.TilesetModels = new ObservableCollection <TilesetModel>();
            foreach (TilesetModel model in this.Session.CurrentTilesets.Value)
            {
                this.TilesetModels.Add(model);
            }
            if (tilesetModel != null)
            {
                ChangeItemModel(tilesetModel);
            }

            this.updatePositionLabelMsDelay    = constants.DefaultUpdatePositionLabelMsDelay;
            this.updateSelectLineMsDelay       = constants.DefaultUpdatePositionLabelMsDelay;
            this.updateTransparentColorMsDelay = constants.DefaultUpdatePositionLabelMsDelay;

            this.updatePositionLabelStopWatch    = Stopwatch.StartNew();
            this.updateSelectLineStopWatch       = Stopwatch.StartNew();
            this.updateTransparentColorStopWatch = Stopwatch.StartNew();

            this.TilesetModel.PropertyChanged    += TilesetModelChanged;
            this.ItemImage.PropertyChanged       += ItemImageChanged;
            this.ScrollModel.PropertyChanged     += ScrollModelPropertyChanged;
            this.GridPen.PropertyChanged         += GridPenChanged;
            this.BackgroundBrush.PropertyChanged += BackgroundChanged;
            this.BackgroundPen.PropertyChanged   += BackgroundChanged;
            this.Session.CurrentTilesets.Value.CollectionChanged += TilesetsChanged;

            this.HandleLeftClickDownCommand = new DelegateCommand <object>((point) => HandleLeftClickDown((Point)point));
            this.HandleLeftClickUpCommand   = new DelegateCommand <object>((point) => HandleLeftClickUp((Point)point));
            this.HandleMouseMoveCommand     = new DelegateCommand <object>((point) => HandleMouseMove((Point)point));
            this.AddTilesetCommand          = new DelegateCommand(() => AddTileset());
            this.AddImageCommand            = new DelegateCommand(() => AddImage());
            this.RemoveItemCommand          = new DelegateCommand(() => RemoveItem());
            this.ViewPropertiesCommand      = new DelegateCommand(() => ViewProperties());
            this.EditCollisionsCommand      = new DelegateCommand(() => EditCollisions());
            this.CropCommand        = new DelegateCommand(() => Crop());
            this.ChangeItemCommand  = new DelegateCommand <object>((entry) => ChangeItemModel(entry as TilesetModel));
            this.UpdateModelCommand = new DelegateCommand(() => UpdateTilesetModel());
            this.ShowGridCommand    = new DelegateCommand(() => RedrawGrid());
            this.ShowRulerCommand   = new DelegateCommand(() => RefreshRuler());
            this.ZoomInCommand      = new DelegateCommand(() => ZoomIn());
            this.ZoomOutCommand     = new DelegateCommand(() => ZoomOut());
            this.SetZoomCommand     = new DelegateCommand <ZoomLevel>((zoomLevel) => SetZoom(zoomLevel));

            this.eventAggregator.GetEvent <UpdatePaddedBrushEvent>().Subscribe((brushModel) =>
            {
                UpdatePaddedBrushModel(brushModel);
            }, ThreadOption.PublisherThread);
        }
Ejemplo n.º 18
0
 public EditTilesetInteraction(TilesetModel tileset)
 {
     this.TilesetModel = tileset;
 }
Ejemplo n.º 19
0
 public ItemEditorViewModel(IEventAggregator eventAggregator, IConstants constants, IAmeSession session, TilesetModel tilesetModel)
     : this(eventAggregator, constants, session, tilesetModel, Components.Behaviors.ScrollModel.DefaultScrollModel())
 {
 }
Ejemplo n.º 20
0
 public EditTilesetInteraction(TilesetModel tileset, Action <INotification> callback)
 {
     this.TilesetModel = tileset;
     this.Callback     = callback;
 }
Ejemplo n.º 21
0
 public void CreateNewTileset(TilesetModel model)
 {
 }