Esempio n. 1
0
        public ToolboxViewModel(IEventAggregator eventAggregator, IAmeSession session)
        {
            this.eventAggregator = eventAggregator ?? throw new ArgumentNullException("eventAggregator");
            this.session         = session ?? throw new ArgumentNullException("session");

            this.Title.Value = "Tool";

            this.DrawingTool.PropertyChanged      += DrawingToolChanged;
            this.IsEraser.PropertyChanged         += IsEraserChanged;
            this.BrushColumns.PropertyChanged     += BrushColumnsChanged;
            this.BrushRows.PropertyChanged        += BrushRowsChanged;
            this.BrushTileWidth.PropertyChanged   += BrushTileWidthChanged;
            this.BrushTileHeight.PropertyChanged  += BrushTileHeightChanged;
            this.BrushTileOffsetX.PropertyChanged += BrushTileOffsetXChanged;
            this.BrushTileOffsetY.PropertyChanged += BrushTileOffsetYChanged;

            this.BrushModel.PropertyChanged += BrushModelChanged;

            this.ToolButtonCommand = new DelegateCommand <Type>((brush) =>
            {
                this.DrawingTool.Value = Activator.CreateInstance(brush) as IDrawingTool;
            });

            this.eventAggregator.GetEvent <NewPaddedBrushEvent>().Subscribe((brushModel) =>
            {
                this.BrushModel.Value = brushModel;
            }, ThreadOption.PublisherThread);
        }
        public LayerListGroupViewModel(IEventAggregator eventAggregator, IAmeSession session, IActionHandler handler, LayerGroup layer)
        {
            this.eventAggregator = eventAggregator ?? throw new ArgumentNullException("eventAggregator");
            this.session         = session ?? throw new ArgumentNullException("session is null");
            this.layer           = layer ?? throw new ArgumentNullException("layer");
            this.actionHandler   = handler ?? throw new ArgumentNullException("handler is null");

            this.LayerNodes = new ObservableCollection <ILayerListNodeViewModel>();
            this.isDragging = false;

            DrawingGroup drawingGroup = new DrawingGroup();
            DrawingGroup filled       = new DrawingGroup();

            using (DrawingContext context = filled.Open())
            {
                Rect drawingRect = new Rect(0, 0, layer.GetPixelWidth(), layer.GetPixelHeight());
                context.DrawRectangle(Brushes.Transparent, new Pen(Brushes.Transparent, 0), drawingRect);
            }
            drawingGroup.Children.Add(filled);
            drawingGroup.Children.Add(layer.Group);
            this.layerPreview = new DrawingImage(drawingGroup);

            this.layer.Layers.CollectionChanged += LayersChanged;

            this.EditTextboxCommand         = new DelegateCommand(() => EditTextbox());
            this.StopEditingTextboxCommand  = new DelegateCommand(() => StopEditingTextbox());
            this.MouseLeftButtonDownCommand = new DelegateCommand <object>((point) => HandleLeftClickDown((MouseEventArgs)point));
            this.MouseMoveCommand           = new DelegateCommand <object>((point) => HandleMouseMove((MouseEventArgs)point));
            this.DropCommand      = new DelegateCommand <object>((point) => HandleDropCommand((DragEventArgs)point));
            this.DragOverCommand  = new DelegateCommand <object>((args) => HandleDragOverCommand((DragEventArgs)args));
            this.DragEnterCommand = new DelegateCommand <object>((args) => HandleDragEnterCommand((DragEventArgs)args));
            this.DragLeaveCommand = new DelegateCommand <object>((args) => HandleDragLeaveCommand((DragEventArgs)args));
        }
        public LayerListNodeViewModel(IEventAggregator eventAggregator, IAmeSession session, IActionHandler actionHandler, Layer layer)
        {
            this.eventAggregator = eventAggregator ?? throw new ArgumentNullException("eventAggregator");
            this.session         = session ?? throw new ArgumentNullException("session is null");
            this.Layer           = layer ?? throw new ArgumentNullException("layer");
            this.actionHandler   = actionHandler ?? throw new ArgumentNullException("handler is null");

            this.drawingGroup = new DrawingGroup();
            this.filled       = new DrawingGroup();
            this.drawingGroup.Children.Add(filled);
            this.drawingGroup.Children.Add(layer.Group);
            this.layerPreview = new DrawingImage(drawingGroup);
            this.isDragging   = false;

            RefreshPreview();

            layer.PixelHeight.PropertyChanged += LayerSizeChanged;
            layer.PixelWidth.PropertyChanged  += LayerSizeChanged;

            this.EditPropertiesCommand      = new DelegateCommand(() => EditProperties());
            this.EditCollisionsCommand      = new DelegateCommand(() => this.actionHandler.EditCollisions());
            this.MoveLayerDownCommand       = new DelegateCommand(() => this.actionHandler.MoveLayerDown(this.Layer));
            this.MoveLayerUpCommand         = new DelegateCommand(() => this.actionHandler.MoveLayerUp(this.Layer));
            this.LayerToMapSizeCommand      = new DelegateCommand(() => this.actionHandler.LayerToMapSize());
            this.DuplicateLayerCommand      = new DelegateCommand(() => this.actionHandler.DuplicateLayer(this.Layer));
            this.RemoveLayerCommand         = new DelegateCommand(() => this.actionHandler.DeleteLayer(this.Layer));
            this.EditTextboxCommand         = new DelegateCommand(() => EditTextbox());
            this.StopEditingTextboxCommand  = new DelegateCommand(() => StopEditingTextbox());
            this.MouseLeftButtonDownCommand = new DelegateCommand <object>((args) => HandleLeftClickDown((MouseEventArgs)args));
            this.MouseMoveCommand           = new DelegateCommand <object>((args) => HandleMouseMove((MouseEventArgs)args));
            this.DropCommand      = new DelegateCommand <object>((args) => HandleDropCommand((DragEventArgs)args));
            this.DragOverCommand  = new DelegateCommand <object>((args) => HandleDragOverCommand((DragEventArgs)args));
            this.DragEnterCommand = new DelegateCommand <object>((args) => HandleDragEnterCommand((DragEventArgs)args));
            this.DragLeaveCommand = new DelegateCommand <object>((args) => HandleDragLeaveCommand((DragEventArgs)args));
        }
        public void UpdateMissingContent(IAmeSession session)
        {
            this.session = session;
            this.Map     = this.Map ?? session.CurrentMap.Value;
            this.Title   = "New Layer";
            string newLayerName = string.Format("Layer #{0}", this.Map.GetLayerCount());

            this.layer    = new Layer(this.Map, newLayerName, this.Map.TileWidth.Value, this.Map.TileHeight.Value, this.Map.Rows.Value, this.Map.Columns.Value);
            this.Callback = this.Callback ?? OnNewLayerWindowClosed;
        }
        public SessionViewerViewModel(IEventAggregator eventAggregator, IAmeSession session)
        {
            this.eventAggregator = eventAggregator ?? throw new ArgumentNullException("eventAggregator is null");
            this.session         = session ?? throw new ArgumentNullException("session is null");

            this.Title.Value = "Session Viewer";

            this.Nodes = new ObservableCollection <NodeViewBuilder>();
            this.Nodes.Add(new NodeViewBuilder("Ame Session", this.session));

            this.RefreshTreeCommand = new DelegateCommand(() => RefreshTree());
        }
Esempio n. 6
0
        public MinimapViewModel(IEventAggregator eventAggregator, IAmeSession session, IScrollModel scrollModel)
        {
            this.eventAggregator = eventAggregator ?? throw new ArgumentNullException("eventAggregator");
            this.session         = session ?? throw new ArgumentNullException("session");
            this.ScrollModel     = scrollModel ?? throw new ArgumentNullException("scrollModel");

            this.Title.Value = "Minimap";

            this.Scale.Value        = ScaleType.Tile;
            this.PositionText.Value = "0, 0";

            // TODO ensure this works for non-square maps
            this.minimapLayers = new DrawingGroup();
            if (this.session.CurrentMap != null)
            {
                Map          currentMap = this.session.CurrentMap.Value;
                DrawingGroup filled     = new DrawingGroup();
                using (DrawingContext context = filled.Open())
                {
                    Rect drawingRect = new Rect(0, 0, currentMap.PixelWidth.Value, currentMap.PixelHeight.Value);
                    context.DrawRectangle(Brushes.Transparent, new Pen(Brushes.Transparent, 0), drawingRect);
                }
                this.minimapLayers.Children.Add(filled);
                foreach (ILayer layer in this.session.CurrentLayers.Value)
                {
                    this.minimapLayers.Children.Add(layer.Group);
                }
            }
            this.minimapPreview = new DrawingImage(this.minimapLayers);

            this.session.CurrentMap.PropertyChanged += CurrentMapChanged;

            this.FitMinimapCommand       = new DelegateCommand(() => FitMinimap());
            this.ToggleGridCommand       = new DelegateCommand(() => ToggleGrid());
            this.ToggleCollisionsCommand = new DelegateCommand(() => ToggleCollisions());
            this.CenterOnPointCommand    = new DelegateCommand(() => CenterOnPoint());
            this.ZoomInCommand           = new DelegateCommand(() => this.ScrollModel.ZoomIn());
            this.ZoomOutCommand          = new DelegateCommand(() => this.ScrollModel.ZoomOut());
            this.SetZoomCommand          = new DelegateCommand <ZoomLevel>((zoomLevel) => this.ScrollModel.SetZoom(zoomLevel));
            this.UpdatePositionCommand   = new DelegateCommand <object>((point) => UpdatePosition((Point)point));
            this.SetRatioCommand         = new DelegateCommand <object>((ratio) => UpdateRatio(Convert.ToDouble(ratio)));
        }