コード例 #1
0
        /// <summary>Overridden from <see cref="Engine.EntitySystem.Entity.OnPostCreate(Boolean)"/>.</summary>
        protected override void OnPostCreate(bool loaded)
        {
            base.OnPostCreate(loaded);

            foreach (MapObjectAttachedObject attachedObject in AttachedObjects)
            {
                attachedGuiObject = attachedObject as MapObjectAttachedGui;
                if (attachedGuiObject != null)
                {
                    controlManager = attachedGuiObject.ControlManager;
                    break;
                }
            }

            CreateMainControl();
        }
コード例 #2
0
ファイル: GameGuiObject.cs プロジェクト: whztt07/SDK
        /// <summary>Overridden from <see cref="Engine.EntitySystem.Entity.OnPostCreate(Boolean)"/>.</summary>
        protected override void OnPostCreate( bool loaded )
        {
            base.OnPostCreate( loaded );

            foreach( MapObjectAttachedObject attachedObject in AttachedObjects )
            {
                attachedGuiObject = attachedObject as MapObjectAttachedGui;
                if( attachedGuiObject != null )
                {
                    controlManager = attachedGuiObject.ControlManager;
                    break;
                }
            }

            CreateMainControl();
        }
コード例 #3
0
        /// <summary>
        /// Updates objects on which the player can to operate.
        /// Such as which the player can supervise switches, ingameGUI or control units.
        /// </summary>
        void UpdateCurrentPlayerUseObjects()
        {
            Camera camera = RendererWorld.Instance.DefaultCamera;

            Unit playerUnit = GetPlayerUnit();

            float maxDistance = ( GetRealCameraType() == CameraType.FPS ) ?
                playerUseDistance : playerUseDistanceTPS;

            Ray ray = camera.GetCameraToViewportRay( new Vec2( .5f, .5f ) );
            ray.Direction = ray.Direction.GetNormalize() * maxDistance;

            //currentAttachedGuiObject
            {
                MapObjectAttachedGui attachedGuiObject = null;
                Vec2 screenPosition = Vec2.Zero;

                if( GetRealCameraType() != CameraType.Free && !IsCutSceneEnabled() &&
                    EntitySystemWorld.Instance.Simulation )
                {
                    Map.Instance.GetObjectsAttachedGuiObject( ray,
                        out attachedGuiObject, out screenPosition );
                }

                //ignore empty gui objects
                if( attachedGuiObject != null )
                {
                    In3dControlManager manager = attachedGuiObject.ControlManager;

                    if( manager.Controls.Count == 0 ||
                        ( manager.Controls.Count == 1 && !manager.Controls[ 0 ].Enable ) )
                    {
                        attachedGuiObject = null;
                    }
                }

                if( attachedGuiObject != currentAttachedGuiObject )
                {
                    if( currentAttachedGuiObject != null )
                        currentAttachedGuiObject.ControlManager.LostManagerFocus();
                    currentAttachedGuiObject = attachedGuiObject;
                }

                if( currentAttachedGuiObject != null )
                    currentAttachedGuiObject.ControlManager.DoMouseMove( screenPosition );
            }

            //currentFloatSwitch
            {
                GameEntities.Switch overSwitch = null;

                Map.Instance.GetObjects( ray, delegate( MapObject obj, float scale )
                {
                    GameEntities.Switch s = obj as GameEntities.Switch;
                    if( s != null )
                    {
                        if( s.UseAttachedMesh != null )
                        {
                            Bounds bounds = ( (MapObjectAttachedMesh)s.UseAttachedMesh ).SceneNode.
                                GetWorldBounds();

                            if( bounds.RayIntersection( ray ) )
                            {
                                overSwitch = s;
                                return false;
                            }
                        }
                        else
                        {
                            overSwitch = s;
                            return false;
                        }
                    }

                    return true;
                } );

                //draw border
                if( overSwitch != null )
                {
                    camera.DebugGeometry.Color = new ColorValue( 1, 1, 1 );
                    if( overSwitch.UseAttachedMesh != null )
                    {
                        camera.DebugGeometry.AddBounds( overSwitch.UseAttachedMesh.SceneNode.
                            GetWorldBounds() );
                    }
                    else
                        camera.DebugGeometry.AddBounds( overSwitch.MapBounds );
                }

                if( overSwitch != currentSwitch )
                {
                    FloatSwitch floatSwitch = currentSwitch as FloatSwitch;
                    if( floatSwitch != null )
                        floatSwitch.UseEnd();

                    currentSwitch = overSwitch;
                }
            }

            //Use player control unit
            if( playerUnit != null )
            {
                currentSeeUnitAllowPlayerControl = null;

                if( PlayerIntellect.Instance != null &&
                    PlayerIntellect.Instance.MainNotActiveUnit == null &&
                    GetRealCameraType() != CameraType.Free )
                {
                    Ray unitFindRay = ray;

                    //special ray for TPS camera
                    if( GetRealCameraType() == CameraType.TPS )
                    {
                        unitFindRay = new Ray( playerUnit.Position,
                            playerUnit.Rotation * new Vec3( playerUseDistance, 0, 0 ) );
                    }

                    Map.Instance.GetObjects( unitFindRay, delegate( MapObject obj, float scale )
                    {
                        Dynamic dynamic = obj as Dynamic;

                        if( dynamic == null )
                            return true;

                        if( !dynamic.Visible )
                            return true;

                        Unit u = dynamic.GetParentUnit();
                        if( u == null )
                            return true;

                        if( u == GetPlayerUnit() )
                            return true;

                        if( !u.Type.AllowPlayerControl )
                            return true;

                        if( u.Intellect != null )
                            return true;

                        if( !u.MapBounds.RayIntersection( unitFindRay ) )
                            return true;

                        currentSeeUnitAllowPlayerControl = u;

                        return false;
                    } );
                }

                //draw border
                if( currentSeeUnitAllowPlayerControl != null )
                {
                    camera.DebugGeometry.Color = new ColorValue( 1, 1, 1 );
                    camera.DebugGeometry.AddBounds( currentSeeUnitAllowPlayerControl.MapBounds );
                }
            }

            //draw "Press Use" text
            if( currentSwitch != null || currentSeeUnitAllowPlayerControl != null )
            {
                ColorValue color;
                if( ( Time % 2 ) < 1 )
                    color = new ColorValue( 1, 1, 0 );
                else
                    color = new ColorValue( 0, 1, 0 );

                string text;
                {
                    text = "Press \"Use\"";

                    //get binded keyboard key or mouse button
                    GameControlsManager.GameControlItem controlItem = GameControlsManager.Instance.
                        GetItemByControlKey( GameControlKeys.Use );
                    if( controlItem != null && controlItem.DefaultKeyboardMouseValues.Length != 0 )
                    {
                        GameControlsManager.SystemKeyboardMouseValue value =
                            controlItem.DefaultKeyboardMouseValues[ 0 ];
                        text += string.Format( " ({0})", value.ToString() );
                    }
                }

                EngineApp.Instance.ScreenGuiRenderer.AddText( text, new Vec2( .5f, .9f ),
                    HorizontalAlign.Center, VerticalAlign.Center, color );
            }
        }