public override BehaviourResult Clicked(RayMeshGeometry3DHitTestResult rayMeshResult, BoardVisual board)
        {
            //find an appropriate visual user clicked,
            // can be hex or simply the chitnumber
            ResourceHex resourceHex = null;
            HexVisual hexVisual = rayMeshResult.VisualHit as HexVisual;
            if (hexVisual != null)
            {
                resourceHex = hexVisual.Hex as ResourceHex;
            }
            ChitVisual chitVisual = rayMeshResult.VisualHit as ChitVisual;
            if (chitVisual != null)
            {
                resourceHex = (ResourceHex)((HexVisual)chitVisual.Parent).Hex;
            }

            //when we found a suitable visual, update the chit number.
            if (resourceHex != null)
            {
                resourceHex.XmlChit = new Chit() { ChitNumber = _Number };
                return BehaviourResult.Success;
            }
            else
            {
                return BehaviourResult.NoSuccess;
            }
        }
 public override void Moved(RayMeshGeometry3DHitTestResult rayMeshResult, BoardVisual board)
 {
     if (rayMeshResult != null)
     {
         GeometryModel3D hitgeo = rayMeshResult.ModelHit as GeometryModel3D;
         HexVisual hex = rayMeshResult.VisualHit as HexVisual;
         if (hex != null)
         {
             // only show mouseover when we have a resourcehex
             if (hex.Hex is ResourceHex)
             {
                 // when we are removing chits, show mouseover when there is
                 // something to remove
                 if (_Number == EChitNumber.None)
                 {
                     ResourceHex resourceHex = hex.Hex as ResourceHex;
                     if (resourceHex.XmlChit.ChitNumber != EChitNumber.None)
                     {
                         SetSelectionState(hex);
                     }
                 }
                 else
                 {
                     //default on showing a mouseover
                     SetSelectionState(hex);
                 }
             }
         }
     }
 }
Exemple #3
0
        public override BehaviourResult Clicked(RayMeshGeometry3DHitTestResult rayMeshResult, BoardVisual board)
        {
            PortVisual port = rayMeshResult.VisualHit as PortVisual;
            if (port !=null)
            {
                board.ShowSideNeighbours(port.XmlPort.SideLocation);
                return BehaviourResult.NoSuccess;
            }

            HexVisual hex = rayMeshResult.VisualHit as HexVisual;
            if (hex != null)
            {
                List<HexPoint> temp = new List<HexPoint>();
                List<HexPoint> temp2 = hex.Hex.Location.GetNeighbourPoints();
                temp.Add(temp2[0]);
                temp.Add(temp2[1]);
                temp.Add(temp2[4]);
                board.ShowPoints(temp);
            }

            Road road = rayMeshResult.VisualHit as Road;
            if (road != null)
            {
                //board.Game.PlayerOnTurn.Towns.Add(buildPoint.Location);
                //board.ShowNeighbours(road.Location);
                board.ShowSideNeighbours(road.Location);
                return BehaviourResult.NoSuccess;
            }

            return BehaviourResult.NoSuccess;
        }
 public override BehaviourResult Clicked(RayMeshGeometry3DHitTestResult rayMeshResult, BoardVisual board)
 {
     Ship ship = rayMeshResult.VisualHit as Ship;
     if (ship != null)
     {
         _Location = ship.Location;
         return BehaviourResult.Success;
     }
     return BehaviourResult.NoSuccess;
 }
 public override BehaviourResult Clicked(RayMeshGeometry3DHitTestResult rayMeshResult, BoardVisual board)
 {
     HexSideVisual hexSideVisual = rayMeshResult.VisualHit as HexSideVisual;
     if (hexSideVisual != null)
     {
         _Location = hexSideVisual.Location;
         board.SetNeutral();
         ((BuildShipAction)_OriginatingAction).Intersection = hexSideVisual.Location;
         return BehaviourResult.Success;
     }
     return BehaviourResult.NoSuccess;
 }
 public override BehaviourResult Clicked(RayMeshGeometry3DHitTestResult rayMeshResult, BoardVisual board)
 {
     BuildPointVisual buildPoint = rayMeshResult.VisualHit as BuildPointVisual;
     if (buildPoint != null)
     {
         //board.Game.PlayerOnTurn.Towns.Add(buildPoint.Location);
         board.SetNeutral();
         ((BuildTownAction)_OriginatingAction).Location = buildPoint.Location;
         return BehaviourResult.Success;
     }
     return BehaviourResult.NoSuccess;
 }
 public override BehaviourResult Clicked(RayMeshGeometry3DHitTestResult rayMeshResult, BoardVisual board)
 {
     HexVisual hexVisual = rayMeshResult.VisualHit as HexVisual;
     if (hexVisual != null)
     {
         Hex newHex = _SelectedHexType.Copy();
         newHex.Location = hexVisual.Hex.Location;
         board.Board.Hexes[newHex.Location] = newHex;
         return BehaviourResult.Success;
     }
     return BehaviourResult.NoSuccess;
 }
 public override BehaviourResult Clicked(RayMeshGeometry3DHitTestResult rayMeshResult, BoardVisual board)
 {
     HexVisual hexVisual = rayMeshResult.VisualHit as HexVisual;
     if (hexVisual != null)
     {
         ResourceHex resourceHex = hexVisual.Hex as ResourceHex;
         if (resourceHex != null)
         {
             _Location = resourceHex.Location;
             return BehaviourResult.Success;
         }
     }
     return BehaviourResult.NoSuccess;
 }
        public override void Moved(RayMeshGeometry3DHitTestResult rayMeshResult, BoardVisual board)
        {
            HexVisual hex = rayMeshResult.VisualHit as HexVisual;
            if (hex != null)
            {
                if (hex.Hex is ITerritoryHex)
                {
                    if (_OldMouseOverHex != null)
                        _OldMouseOverHex.Selected = false;
                    hex.Selected = true;

                    _OldMouseOverHex = hex;
                }
            }
        }
 public override BehaviourResult Clicked(RayMeshGeometry3DHitTestResult rayMeshResult, BoardVisual board)
 {
     //Check if clicked hex is a LandHex, if so, put current territory
     //on the hex.
     HexVisual hexVisual = rayMeshResult.VisualHit as HexVisual;
     if (hexVisual != null)
     {
         ITerritoryHex terrHex = hexVisual.Hex as ITerritoryHex;
         if (terrHex != null)
         {
             terrHex.TerritoryID = _SelectedTerritory.ID;
             return BehaviourResult.Success;
         }
     }
     return BehaviourResult.NoSuccess;
 }
        public override void Moved(RayMeshGeometry3DHitTestResult rayMeshResult, BoardVisual board)
        {
            HexVisual hv = rayMeshResult.VisualHit as HexVisual;
            if (hv != null)
            {
                if (!_ForbiddenHexes.Contains(hv) ||
                    hv.Hex.Location.Equals(board.Game.Robber) ||
                    hv.Hex.Location.Equals(board.Game.Pirate))
                {
                    if (_OldMouseOverHex != null)
                        _OldMouseOverHex.Selected = false;
                    hv.Selected = true;

                    _OldMouseOverHex = hv;
                }
            }
        }
 public override BehaviourResult Clicked(RayMeshGeometry3DHitTestResult rayMeshResult, BoardVisual board)
 {
     Road hsv = rayMeshResult.VisualHit as Road;
     if (hsv != null)
     {
         hsv.IsRoadSelected = true;
     }
     BuildPointVisual buildPoint = rayMeshResult.VisualHit as BuildPointVisual;
     if (buildPoint != null)
     {
         //board.Game.PlayerOnTurn.Cities.Add(buildPoint.Location);
         _Location = buildPoint.Location;
         board.SetNeutral();
         ((BuildCityAction)_OriginatingAction).Location = buildPoint.Location;
         return BehaviourResult.Success;
     }
     return BehaviourResult.NoSuccess;
 }
        public override BehaviourResult Clicked(RayMeshGeometry3DHitTestResult rayMeshResult, BoardVisual board)
        {
            HexVisual hexVisual = rayMeshResult.VisualHit as HexVisual;
            if (hexVisual != null)
            {
                PlaceRobberPirateAction placeRobberPirate = _OriginatingAction as PlaceRobberPirateAction;
                if (placeRobberPirate != null)
                {
                    if (hexVisual.Hex is SeaHex)
                        _IsRobber = false;

                    placeRobberPirate.Location = hexVisual.Hex.Location;
                    RemoveStartState(board);
                    return BehaviourResult.Success;
                }
            }
            return BehaviourResult.NoSuccess;
        }
        public override BehaviourResult Clicked(RayMeshGeometry3DHitTestResult rayMeshResult, BoardVisual board)
        {
            Road side = rayMeshResult.VisualHit as Road;
            if (side != null)
            {
                List<BuildPointVisual> x = new List<BuildPointVisual>();
                foreach (BuildPointVisual bpv in board.Children.OfType<BuildPointVisual>())
                    x.Add(bpv);
                foreach (BuildPointVisual bp in x)
                    board.Children.Remove(bp);

                BuildPointVisual bpv1 = new BuildPointVisual(board.CalculatePosition(side.Location.HexPoint1), side.Location.HexPoint1);
                BuildPointVisual bpv2 = new BuildPointVisual(board.CalculatePosition(side.Location.HexPoint2), side.Location.HexPoint2);
                board.Children.Add(bpv1);
                board.Children.Add(bpv2);
            }
            return BehaviourResult.NoSuccess;
        }
        public override void Moved(RayMeshGeometry3DHitTestResult rayMeshResult, BoardVisual board)
        {
            HexSideVisual hexSideVisual = rayMeshResult.VisualHit as HexSideVisual;
            if (_OldMouseOver != null)
            {
                _OldMouseOver.Scale.ScaleX = 1;
                _OldMouseOver.Scale.ScaleY = 1;
                _OldMouseOver.Scale.ScaleZ = 1;
                _OldMouseOver = null;
            }
            if (hexSideVisual != null)
            {

                hexSideVisual.Scale.ScaleX = 2;
                hexSideVisual.Scale.ScaleY = 2;
                hexSideVisual.Scale.ScaleZ = 2;
                _OldMouseOver = hexSideVisual;
            }
        }
 public override void Moved(RayMeshGeometry3DHitTestResult rayMeshResult, BoardVisual board)
 {
     BuildPointVisual buildPoint = rayMeshResult.VisualHit as BuildPointVisual;
     if (buildPoint != null)
     {
         buildPoint.Scale.ScaleX = 2;
         buildPoint.Scale.ScaleY = 2;
         buildPoint.Scale.ScaleZ = 2;
         _OldBuildPoint = buildPoint;
     }
     else
     {
         if (_OldBuildPoint != null)
         {
             _OldBuildPoint.Scale.ScaleX = 1;
             _OldBuildPoint.Scale.ScaleY = 1;
             _OldBuildPoint.Scale.ScaleZ = 1;
         }
     }
 }
        public override BehaviourResult Clicked(RayMeshGeometry3DHitTestResult rayMeshResult, BoardVisual board)
        {
            HexVisual hexVisual = rayMeshResult.VisualHit as HexVisual;
            if (hexVisual != null)
            {
                SeaHex seaHex = hexVisual.Hex as SeaHex;
                if (seaHex != null)
                {
                    if (((SeaHex)seaHex).XmlPort != null)
                    {
                        // we confirmed the port here, make a small animation
                        hexVisual.AnimatePortSetted();
                        return BehaviourResult.Success;
                    }
                }
            }

            // we need a seahex to move on
            return BehaviourResult.Success;
        }
 public override BehaviourResult Clicked(RayMeshGeometry3DHitTestResult rayMeshResult, BoardVisual board)
 {
     HexVisual hexVisual = rayMeshResult.VisualHit as HexVisual;
     if (hexVisual != null)
     {
         SeaHex seaHex = hexVisual.Hex as SeaHex;
         if (seaHex != null)
         {
             if (_SelectedPortType == EPortType.None)
             {
                 seaHex.XmlPort = null;
                 return BehaviourResult.Success;
             }
             else
             {
                 if (seaHex.XmlPort == null)
                     seaHex.XmlPort = new Port()
                     {
                         Location = seaHex.Location,
                     };
                 seaHex.XmlPort.PortType = _SelectedPortType;
                 switch (rayMeshResult.VertexIndex3)
                 {
                     case 0: seaHex.XmlPort.PortPosition = ERotationPosition.Deg240; break;
                     case 1: seaHex.XmlPort.PortPosition = ERotationPosition.Deg180; break;
                     case 2: seaHex.XmlPort.PortPosition = ERotationPosition.Deg120; break;
                     case 3: seaHex.XmlPort.PortPosition = ERotationPosition.Deg60; break;
                     case 4: seaHex.XmlPort.PortPosition = ERotationPosition.Deg0; break;
                     case 5: seaHex.XmlPort.PortPosition = ERotationPosition.Deg300; break;
                 }
                 hexVisual.AnimatePortSetted();
                 if (_SelectedHex == null)
                     _SelectedHex = seaHex;
                 else
                     _SelectedHex = null;
                 return BehaviourResult.Success;
             }
         }
     }
     return BehaviourResult.NoSuccess;
 }
 public override BehaviourResult Clicked(RayMeshGeometry3DHitTestResult rayMeshResult, BoardVisual board)
 {
     HexSideVisual hexSide = rayMeshResult.VisualHit as HexSideVisual;
     if (hexSide != null)
     {
         if (_ShipToMove == null)
         {
             // player has not yet selected a ship to move. Show moveable ships
             //board.SetMoveShip();
             _ShipToMove = hexSide.Location;
             board.SetMoveToShip(_ShipToMove);
             return BehaviourResult.NoSuccess;
         }
         else
         {
             MoveShipAction moveShip = _OriginatingAction as MoveShipAction;
             moveShip.OldLocation = _ShipToMove;
             moveShip.NewLocation = hexSide.Location;
             board.SetNeutral();
             return BehaviourResult.Success;
         }
     }
     return BehaviourResult.NoSuccess;
 }
        public override void Moved(
            RayMeshGeometry3DHitTestResult rayMeshResult, BoardVisual board)
        {
            HexVisual hexVisual = rayMeshResult.VisualHit as HexVisual;
            if (hexVisual != null)
            {
                // make sure we are applying mouseovers only to sea hexes
                SeaHex seaHex = hexVisual.Hex as SeaHex;
                if (seaHex != null)
                {
                    // user has clicked a hex, and wants to set a port on a certain direction
                    if (_SelectedHex != null)
                    {
                        if (seaHex == _SelectedHex)
                        {
                            seaHex.XmlPort.PortType = _SelectedPortType;

                            // map the vertex to the RotationPosition
                            switch (rayMeshResult.VertexIndex3)
                            {
                                case 0: seaHex.XmlPort.PortPosition = ERotationPosition.Deg240; break;
                                case 1: seaHex.XmlPort.PortPosition = ERotationPosition.Deg180; break;
                                case 2: seaHex.XmlPort.PortPosition = ERotationPosition.Deg120; break;
                                case 3: seaHex.XmlPort.PortPosition = ERotationPosition.Deg60; break;
                                case 4: seaHex.XmlPort.PortPosition = ERotationPosition.Deg0; break;
                                case 5: seaHex.XmlPort.PortPosition = ERotationPosition.Deg300; break;
                            }
                        }
                    }
                    // user simply hovers over a hex
                    else
                    {
                        // user is removing ports, so only show mouseover when
                        // there is a port present
                        if (_SelectedPortType == EPortType.None &&
                            seaHex.XmlPort != null)
                        {
                            base.Moved(rayMeshResult, board);
                        }
                        // user is setting any other port type, so show mouseover
                        // on each seahex
                        if (_SelectedPortType != EPortType.None)
                        {
                            base.Moved(rayMeshResult, board);
                        }
                    }

                }
            }
        }
 public override void Moved(RayMeshGeometry3DHitTestResult rayMeshResult, BoardVisual board)
 {
 }
 private VideoSurface GetByHitTest(RayMeshGeometry3DHitTestResult result)
 {
     return this.videos.Where(v => v.ModelVisual3D == result.VisualHit as ModelVisual3D).First();
 }
Exemple #23
0
 /// <summary>
 /// Performs hit testing for this residue.
 /// </summary>
 /// <param name="rayHitTestResult">A 3D mesh hit test result from the WPF visual tree hit
 /// testing framework</param>
 /// <returns>True if the mesh hit belongs to this residue, otherwise false.</returns>
 internal virtual bool HoverHitTest(RayMeshGeometry3DHitTestResult rayHitTestResult)
 {
     if (this.cartoon != null)
         return this.cartoon.HoverHitTest(rayHitTestResult);
     else
         return false;
 }
Exemple #24
0
 /// <summary>
 /// Performs hit testing for this cartoon mesh.
 /// </summary>
 /// <param name="rayHitTestResult">A 3D mesh hit test result from the WPF visual tree hit
 /// testing framework</param>
 /// <returns>
 /// True if the mesh hit belongs to this residue, otherwise false.
 /// </returns>
 internal bool HoverHitTest(RayMeshGeometry3DHitTestResult rayHitTestResult)
 {
     return this.model.Children.Contains(rayHitTestResult.ModelHit);
 }
Exemple #25
0
        /// <summary>
        /// Performs a 3D hit test. Point pt is a 2D point in viewport space. 
        /// The object needs to be a Viewport3D or a ModelVisual3D.
        /// </summary>
        public static RayMeshGeometry3DHitTestResult HitTest(object obj, Point pt)
        {
            hitTestResult = null;

            Viewport3D viewport = obj as Viewport3D;
            if (viewport != null)
            {
                VisualTreeHelper.HitTest(viewport, null, HitTestResultCallback, new PointHitTestParameters(pt));
            }
            else
            {
                ModelVisual3D model = obj as ModelVisual3D;
                if (model != null)
                {
                    Point3D ptNear, ptFar;
                    if (GetRay(pt, model, out ptNear, out ptFar))
                    {
                        RayHitTestParameters paras = new RayHitTestParameters(ptNear, ptFar - ptNear);
                        VisualTreeHelper.HitTest(model, null, HitTestResultCallback, paras);
                    }
                }
            }

            return hitTestResult;
        }
 public void UpdateResultInfo(RayMeshGeometry3DHitTestResult rayMeshResult)
 {
     HitVisualInfo.Text = rayMeshResult.VisualHit.ToString();
     HitModelInfo.Text = rayMeshResult.ModelHit.ToString();
     HitMeshInfo.Text = rayMeshResult.MeshHit.ToString();
     //HitMaterialInfo.Text = (rayMeshResult.ModelHit as GeometryModel3D).Material.GetType().Name;
     //HitMaterialBrushInfo.Text = ((rayMeshResult.ModelHit as GeometryModel3D).Material as DiffuseMaterial).Brush.ToString();
     HitDistanceInfo.Text = rayMeshResult.DistanceToRayOrigin.ToString();
     Vertex1Info.Text = (rayMeshResult.VertexWeight1 * 100) + "%";
     Vertex2Info.Text = (rayMeshResult.VertexWeight2 * 100) + "%";
     Vertex3Info.Text = (rayMeshResult.VertexWeight3 * 100) + "%";
 }
 public virtual BehaviourResult Clicked(RayMeshGeometry3DHitTestResult rayMeshResult, BoardVisual board)
 {
     return BehaviourResult.NoSuccess;
 }
Exemple #28
0
 /// <summary>
 /// Performs hit testing for this atom.
 /// </summary>
 /// <param name="rayHitTestResult">A 3D mesh hit test result from the WPF visual tree hit
 /// testing framework</param>
 /// <returns>True if the mesh hit belongs to this atom, otherwise false.</returns>
 internal virtual bool HoverHitTest(RayMeshGeometry3DHitTestResult rayHitTestResult)
 {
     return (this.selectionModel == rayHitTestResult.ModelHit || (this.atomModel != null &&
         this.atomModel.Children.Contains(rayHitTestResult.ModelHit)));
 }
Exemple #29
0
        static HitTestResultBehavior HitTestResultCallback(HitTestResult result)
        {
            RayMeshGeometry3DHitTestResult htr = result as RayMeshGeometry3DHitTestResult;
            if (htr != null)
            {
                if (hitTestResult == null)
                    hitTestResult = htr;

                else if (htr.DistanceToRayOrigin < hitTestResult.DistanceToRayOrigin)
                    hitTestResult = htr;
            }
            return HitTestResultBehavior.Continue;
        }
 public MyHitTestResult(RayMeshGeometry3DHitTestResult modelHit)
 {
     this.ModelHit = modelHit;
 }