public TreeControl(TreeViewModel treeInfo)
 {
     InitializeComponent();
     Width = 50;
     Height = 56;
     this.DataContext = treeInfo;
 }
        public NewTreeWindow(TreeViewModel newTree)
        {
            InitializeComponent();

            NewTreeViewModel newTreeViewModel = new NewTreeViewModel();
            newTreeViewModel.Tree = newTree;
            this.DataContext = newTreeViewModel;
            this.RegisterMessages();

            PlantingProcessViewControl.AnimationCompleted += new EventHandler(OnPlantingProcessAnimationCompleted);
        }
        /// <summary>
        /// Choose where to place the tree and launches planting dialog
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Hill_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (!IsPlanting)
            {
                return;
            }

            UIElement senerUIElement = sender as UIElement;
            Point mousePosition = e.GetPosition(senerUIElement);
            double mouseX = mousePosition.X;
            double mouseY = mousePosition.Y;

            TreeViewModel newTree = new TreeViewModel()
                {
                    CoordinateX = mouseX,
                    CoordinateY = mouseY,
                };

            //Messenger.Default.Send<RenderTreeMessage>(new RenderTreeMessage(newTree));
            Messenger.Default.Send<LaunchNewTreeMessage>(new LaunchNewTreeMessage(newTree));
            Messenger.Default.Send<EndPlantingModeMessage>(new EndPlantingModeMessage());

            TreeCursor.Hide();
        }
        /// <summary>
        /// Puts a tree on the hill
        /// </summary>
        /// <param name="treeInfo">TreeViewModel with the tree information</param>
        public void PlantTreeOnTheHill(TreeViewModel treeInfo)
        {
            double treeX = treeInfo.CoordinateX;
            double treeY = treeInfo.CoordinateY;
            var hill = Hill;

            double hillY = Canvas.GetTop(hill);
            double hillX = Canvas.GetLeft(hill);

            double newTreeX = hillX + treeX;//newTreeX is the X(left) referred to whole Nature (RootNatureCanvas)
            double newTreeY = hillY + treeY;//newTreeY is the Y(top) referred to whole Nature (RootNatureCanvas)

            double treeWidth = 50;
            double treeHeight = 56;

            PlantATree.Controls.TreeControl newTree = new PlantATree.Controls.TreeControl()
            {
                Height = treeWidth,
                Width = treeHeight,
                DataContext = treeInfo,
            };

            //Calculates the scale
            double hillHeight = Hill.ActualHeight;
            double senderTopToHill = newTreeY - hillY;

            double minScaleCoef = 0.25;
            double scaleCoef = minScaleCoef + (senderTopToHill / hillHeight) * (1 - minScaleCoef); ;

            this.NatureRootCanvas.Children.Add(newTree);

            CompositeTransform composite = new CompositeTransform();
            composite.TranslateX = newTreeX - treeWidth / 2;
            composite.TranslateY = newTreeY - treeHeight;

            composite.CenterX = 0.5;
            composite.CenterY = 1.0;
            composite.ScaleX = scaleCoef;
            composite.ScaleY = scaleCoef;

            newTree.RenderTransform = composite;
        }
Beispiel #5
0
 public LaunchNewTreeMessage(TreeViewModel tree)
 {
     this.Tree = tree;
 }
Beispiel #6
0
 public AddTreeToTreesListMessage(TreeViewModel treeToAdd)
     : base()
 {
     this.Tree = treeToAdd;
 }
Beispiel #7
0
 public UpdatedTreeMessage(TreeViewModel tree)
 {
     this.Tree = tree;
 }
Beispiel #8
0
 public TreeSaveUnsuccessfullMessage(TreeViewModel tree)
     : base()
 {
     this.Tree = tree;
 }
Beispiel #9
0
 public RenderTreeMessage(TreeViewModel tree)
     : base()
 {
     this.Tree = tree;
 }
 public override void Cleanup()
 {
     // Clean own resources if needed
     base.Cleanup();
     Tree = null;
 }
 public void OnGetTreesList(ObservableCollection<PlantATree.TreeService.Tree> trees)
 {
     foreach (var tree in trees)
     {
         TreeViewModel newTreeViewModel = new TreeViewModel(tree);
         this.AddNewTreeToList(newTreeViewModel);
     }
 }
        public void AddNewTreeToList(TreeViewModel treeVieModel)
        {
            Trees.Add(treeVieModel);

            var newTree = treeVieModel;
            RenderTreeMessage renderTreeMessage = new RenderTreeMessage(newTree);
            Messenger.Default.Send<RenderTreeMessage>(renderTreeMessage);
        }
Beispiel #13
0
 public void LaunchNewTreeWindow(TreeViewModel newTree)
 {
     NewTreeWindow newTreeView = new NewTreeWindow(newTree);
     newTreeView.Show();
 }