/// <summary> /// Constructor. /// </summary> /// <param name="parent">The parent entity for this Component.</param> /// <note>The parent Entity MUST have a PositionComponent in order to construct this Component.</note> public CameraComponent_cl(Entity_cl parent) : base(parent) { // Ensure that the parent has a PositionComponent attached to it...otherwise assert Debug.Assert(mParentEntity.GetComponentOfType(typeof(PositionComponent_cl)) != null, "CameraComponents can only be added to Entities with PositionComponents!"); /************************************************************************ * TODO: * Cache off and store this position component? Is that kosher? * * Jerad Dunn - 2011/11/05 - 19:20 ************************************************************************/ // Create the projection matrix for this camera mProjectionMatrix = Matrix.Identity * Matrix.CreateTranslation(-0.5f, -0.5f, 0) * // Half-pixel offset Matrix.CreateOrthographicOffCenter(0, Game_cl.BaseInstance.WindowWidth, Game_cl.BaseInstance.WindowHeight, 0, 0, 1); // By default, there is no additional offset mScreenOffsetMatrix = Matrix.Identity; mParentEntity.AddComponent(this); mZoom = 1.0f; mRotation = 0.0f; RecalculateTransformationMatrix(); }
/// <summary> /// Shows a dialog box with a property grid. /// </summary> /// <param name="title"></param> /// <param name="value"></param> /// <returns></returns> public static DialogResult Show(string title, ref Entity_cl value) { Form mForm = new Form(); PropertyGrid mPropertyGrid = new PropertyGrid(); Button mOKButton = new Button(); mForm.Text = title + " Properties"; mPropertyGrid.SelectedObject = value; mOKButton.Text = "OK"; mOKButton.DialogResult = DialogResult.OK; mForm.ClientSize = new Size(320, 320); mPropertyGrid.SetBounds(4, 4, mForm.ClientSize.Width - 4, mForm.ClientSize.Height - 40); mOKButton.SetBounds(mForm.ClientSize.Width / 2 - 32, mForm.ClientSize.Height - 36, 64, 22); mPropertyGrid.Anchor = AnchorStyles.Top; mOKButton.Anchor = AnchorStyles.Bottom; mForm.Controls.AddRange(new Control[] { mPropertyGrid, mOKButton }); mForm.FormBorderStyle = FormBorderStyle.FixedSingle; mForm.StartPosition = FormStartPosition.CenterScreen; mForm.MinimizeBox = false; mForm.MaximizeBox = false; mForm.AcceptButton = mOKButton; DialogResult dialogResult = mForm.ShowDialog(); return dialogResult; }
/// <summary> /// Constructor. /// </summary> /// <param name="parent">The parent entity for this Component.</param> public HealthComponent_cl(Entity_cl parent) : base(parent) { mCurrentHealth = mMaxHealth; mParentEntity.AddComponent(this); }
/// <summary> /// Constructor. /// </summary> /// <param name="parent">The parent entity for this Component.</param> /// <param name="x">Initial X position.</param> /// <param name="y">Initial Y position.</param> /// <param name="z">Initial Z position.</param> public WaypointComponent_cl(Entity_cl parent, float x, float y, float z = 0.0f) : base(parent) { mPosition = new Vector3(x, y, z); mOffsetVector = new Vector3(0.0f, 0.0f, 0.0f); mParentEntity.AddComponent(this); WaypointManager_cl.AddWaypoint(this); }
/// <summary> /// Constructor with an entity. /// </summary> /// <param name="parent"></param> public InputComponent_cl(Entity_cl parent) : base(parent) { mKeys = new Dictionary<string, Keys>(); mButtons = new Dictionary<string, Buttons>(); mParentEntity.AddComponent(this); }
/// <summary> /// Constructor with no specified default position. /// </summary> /// <param name="parent">The parent entity for this Component.</param> public BirdAiComponent_cl(Entity_cl parent) : base(parent) { mParentEntity.AddComponent(this); Managers.EventManager.GroundPoundStartedEvent += new EventManager.GroundPoundStarted(EventManager_GroundPoundedEvent); Managers.EventManager.GroundPoundEndedEvent += new EventManager.GroundPoundEnded(EventManager_GroundPoundEndedEvent); Game_cl.BaseInstance.Bird = mParentEntity; }
/************************************************************************ * TODO: * What else goes into making a scene? * * Jay Sternfield - 2011/11/05 ************************************************************************/ /// <summary> /// Default constructor. /// </summary> public Scene_cl() { mAmbientLight = new Entity_cl(); AmbientLightComponent ambientComponent = new AmbientLightComponent(mAmbientLight, 0.0f, Color.White.ToVector3(), 1.0f); LightManager_cl.Instance.ActiveAmbientLight = ambientComponent; mLights = new List<Entity_cl>(); mEntities = new List<Entity_cl>(); mLayers = new List<Entity_cl>(); }
/// <summary> /// Constructor for deserialization. /// </summary> /// <param name="info">The serialization info to deserialize with.</param> /// <param name="context">The context in which to deserialize...?</param> protected Scene_cl(SerializationInfo info, StreamingContext context) { mAmbientLight = (Entity_cl)info.GetValue("AmbientLight", typeof(Entity_cl)); LightManager_cl.Instance.ActiveAmbientLight = (AmbientLightComponent)mAmbientLight.GetComponentOfType(typeof(AmbientLightComponent)); mLights = (List<Entity_cl>)info.GetValue("Lights", typeof(List<Entity_cl>)); mEntities = (List<Entity_cl>)info.GetValue("Prefabs", typeof(List<Entity_cl>)); mLayers = (List<Entity_cl>)info.GetValue("Layers", typeof(List<Entity_cl>)); }
/// <summary> /// /// </summary> /// <param name="parent"></param> /// <param name="colorTexture"></param> public RenderableComponent_cl(Entity_cl parent, string colorTexture) : base(parent) { RenderableManager_cl.Instance.RegisterComponent(this); mParentEntity.AddComponent(this); mSprite = new SunburnSprite_cl(); mSprite.LoadContent(colorTexture); mSprite.InitSunburnStuff(); }
/// <summary> /// Base constructor - registers the component and adds it to the entity. /// </summary> /// <param name="parent"></param> public SoundComponent_cl(Entity_cl parent) : base(parent) { mSoundEmitter = new AudioEmitter(); PositionComponent_cl emitterPosition = (PositionComponent_cl)mParentEntity.GetComponentOfType(typeof(PositionComponent_cl)); mSoundEmitter.Position = emitterPosition.Position3D; Managers.SoundManager_cl.Instance.RegisterComponent(this); mParentEntity.AddComponent(this); mSounds3DList = new List<Cue>(); }
/// <summary> /// /// </summary> /// <param name="parent"></param> /// <param name="colorTexture"></param> /// <param name="normalMap"></param> /// <param name="offsetMap"></param> public RenderableComponent_cl(Entity_cl parent, string colorTexture, string normalMap, string offsetMap) : base(parent) { ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // TODO: Add in a debug assert that the parent Entity has a PositionComponent. Make the RenderableComponent require that an Entity has // a PositionComponent before it can be added. // [JSD 09/28/11] ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// RenderableManager_cl.Instance.RegisterComponent(this); mParentEntity.AddComponent(this); mSprite = new SunburnSprite_cl(); mSprite.LoadContent(colorTexture); mSprite.InitSunburnStuff(); }
/// <summary> /// Constructor. /// </summary> /// <param name="parent">The parent entity for this Component.</param> /// <note>The parent Entity MUST have a PositionComponent in order to construct this Component.</note> /// <note>The parent Entity MUST have an InputComponent in order to construct this Component.</note> public TheFinaleCameraComponent_cl(Entity_cl parent) : base(parent) { // Asserting here to ensure that the TheFinaleCameraComponent has all the required Components // These will be compiled out of the Release build Debug.Assert(mParentEntity.GetComponentOfType(typeof(PositionComponent)) != null, "TheFinaleCameraComponent: No PositionComponent exists on parent Entity!"); Debug.Assert(mParentEntity.GetComponentOfType(typeof(InputComponent)) != null, "TheFinaleCameraComponent: No InputComponent exists on parent Entity!"); mPositionComponent = (PositionComponent)mParentEntity.GetComponentOfType(typeof(PositionComponent)); mInputComponent = (InputComponent)mParentEntity.GetComponentOfType(typeof(InputComponent)); mInputComponent.AddKey("moveN", Keys.W); mInputComponent.AddKey("moveW", Keys.A); mInputComponent.AddKey("moveS", Keys.S); mInputComponent.AddKey("moveE", Keys.D); // Items at the same position as the camera should appear at the bottom of the screen, horizontally centered mScreenOffsetMatrix = Matrix.CreateTranslation(new Vector3((float)FNA.Game.BaseInstance.WindowWidth * 0.5f, (float)FNA.Game.BaseInstance.WindowHeight, 0)); RecalculateTransformationMatrix(); }
/// <summary> /// /// </summary> protected Game_cl() : base() { mGraphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; // Required for lighting system. Components.Add(new SplashScreenGameComponent(this, mGraphics)); // Create the lighting system. mLightingSystemManager = new LightingSystemManager(Services, Content); mSceneState = new SceneState(); mEnvironment = new SceneEnvironment(); mSceneInterface = new SceneInterface(mGraphics); mSceneInterface.CreateDefaultManagers(false); mSceneInterface.AddManager(new ObjectManager_cl()); // Create the sprite manager used to create and organize sprite containers for 2D rendering. mSpriteManager = new SpriteManager(mGraphics); mSceneInterface.AddManager(mSpriteManager); mFrameBuffers = new FrameBuffers(mGraphics, DetailPreference.Low, DetailPreference.Low); mSceneInterface.ResourceManager.AssignOwnership(mFrameBuffers); mStaticSceneEffects = new List<SceneEffect>(); //mView = Matrix.CreateLookAt(Vector3.Zero, Vector3.Forward, Vector3.Up); //mProjection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver2, GraphicsDevice.Viewport.AspectRatio, 0.1f, 1000f); mCameraEntity = new Entity_cl(); #if WORLD_EDITOR mWorldEditor = new WorldEditor_cl(); #endif mManagers = new List<BaseManager_cl>(); mRandom = new Random(); mTimer = new FNA.Core.Timer_cl(); mBaseInstance = this; mIsPlayingGame = true; }
/// <summary> /// /// </summary> /// <param name="entity"></param> public void RemoveEntity(Entity_cl entity) { entity.RemoveAllComponents(); mEntities.Remove(entity); }
/// <summary> /// Sets the ambient light, given another light. /// </summary> /// <param name="light">The new ambient light.</param> public void SetAmbientLight(Entity_cl light) { if (light.Components.ContainsKey(typeof(AmbientLightComponent))) { mAmbientLight = light; } #if DEBUG else { System.Windows.Forms.MessageBox.Show("ERROR: Entity must contain AmbientLightComponent"); } #endif }
/// <summary> /// /// </summary> public void Clear() { mAmbientLight = null; mLights.Clear(); mEntities.Clear(); mLayers.Clear(); }
/// <summary> /// Use this when you have to remove a scene during the scene's update. /// </summary> /// <param name="entity"></param> public void QueueRemoveEntity(Entity_cl entity) { mEntitiesToRemove.Add(entity); }
/// <summary> /// /// </summary> /// <param name="name"></param> /// <param name="location"></param> public Entity_cl CreateNewParticle(string name, Vector2 location) { Entity_cl entity = new Entity_cl(); ParticleLocation = location; ParticleComponent_cl partyEffect; partyEffect = new ParticleComponent_cl(entity,ParticleLocation); partyEffect.particle = FNA.Game_cl.BaseInstance.Content.Load<ParticleEffect>((name)).DeepCopy(); partyEffect.particle.LoadContent(FNA.Game_cl.BaseInstance.Content); partyEffect.particle.Initialise(); RegisterNewParty(partyEffect); return entity; }
/// <summary> /// Adds a layer Entity to the Scene's list of Layers. /// </summary> /// <param name="layer">The layer Entity to add to the Scene.</param> public void AddLayer(Entity_cl layer) { /************************************************************************ * TODO: * What is a layer? * * Jay Sternfield - 2011/11/05 ************************************************************************/ mLayers.Add(layer); }
/// <summary> /// Add an Entity to the list displayed in the Object Panel. /// </summary> /// <param name="obj"></param> public void AddObjectToList(Entity_cl obj) { // If there is not already an entity of this same name, add this one. if (mObjectList.ContainsKey(obj.Name) == false) { mObjectList.Add(obj.Name, obj); } else // Append the next unused int to the end of the name, and add to the object list. { int suffix = 0; while (mObjectList.ContainsKey(obj.Name + suffix)) { suffix++; } obj.Name += suffix; mObjectList.Add(obj.Name, obj); } TreeNode node = new TreeNode(obj.Name); node.Name = obj.Name; mObjectPanelTree.Nodes.Add(node); }
/// <summary> /// /// </summary> /// <param name="entity"></param> public void SelectObject(Entity_cl entity) { if ((entity == null) || (!entity.ActiveForEditing)) { mObjectPanelTree.SelectedNode = null; return; } for (int i = 0; i < mObjectPanelTree.Nodes.Count; i++) { if (mObjectPanelTree.Nodes[i].Text == entity.Name) { mObjectPanelTree.SelectedNode = mObjectPanelTree.Nodes[i]; break; } } }
/// <summary> /// /// </summary> /// <param name="parent"></param> public RenderableComponent_cl(Entity_cl parent) : base(parent) { RenderableManager_cl.Instance.RegisterComponent(this); mParentEntity.AddComponent(this); mSprite = new SunburnSprite_cl(); mSprite.InitSunburnStuff(); }
/// <summary> /// Default constructor - registers this component with the system and adds to the entity. /// </summary> /// <param name="parent"></param> public AnimatedComponent_cl(Entity_cl parent) : base(parent) { mParentEntity.AddComponent(this); }
private void NewPrefabClicked(object sender, EventArgs e) { mEntity = new Entity_cl(); mComponentProperties.Show(); mComponentsPanel.Show(); }
/// <summary> /// /// </summary> /// <param name="parent"></param> public override void AssignOwnership(Entity_cl parent) { base.AssignOwnership(parent); RenderableManager_cl.Instance.RegisterComponent(this); }
public void DeserializePrefab() { OpenFileDialog loadPrefabDialog = new OpenFileDialog(); loadPrefabDialog.Filter = "Prefab File|*.fnPrefab"; loadPrefabDialog.Title = "Save a Prefab"; loadPrefabDialog.ShowDialog(); if (loadPrefabDialog.FileName != "") { mEntity = PrefabManager_cl.Instance.LoadPrefab(loadPrefabDialog.FileName); mComponents.Clear(); foreach (Button button in mComponentButtons) { mComponentsPanel.Controls.Remove(button); } mComponentButtons.Clear(); foreach (List<Component_cl> componentList in mEntity.Components.Values) { foreach (Component_cl component in componentList) { mComponents.Add(component.ToString(), component); } } foreach (Component_cl component in mComponents.Values) { Button newComponent = new Button(); newComponent.Location = new System.Drawing.Point(0, 0); newComponent.Size = new System.Drawing.Size(200, 20); newComponent.Text = component.ToString(); newComponent.UseVisualStyleBackColor = true; newComponent.Click += new EventHandler(ComponentClicked); mActiveComponentButton = newComponent; mComponentButtons.Add(newComponent); mComponentsPanel.Controls.Add(newComponent); } OrderComponents(); mComponentProperties.Show(); mComponentsPanel.Show(); } }
/// <summary> /// Remove an Entity from the list displayed in the Object Panel. /// </summary> /// <param name="obj"></param> public void RemoveObjectFromList(Entity_cl obj) { mObjectPanelTree.SelectedNode = null; if(mObjectPanelTree.Nodes.Contains(new TreeNode(obj.Name))) { } else if (mObjectPanelTree.Nodes.ContainsKey(obj.Name)) { } mObjectPanelTree.Nodes.RemoveByKey(obj.Name); mObjectList.Remove(obj.Name); }
/// <summary> /// Adds a non-light Entity to the Scene's list of Entities. /// </summary> /// <param name="entity">The Entity to add to the Scene.</param> public void AddEntity(Entity_cl entity) { /************************************************************************ * TODO: * What do we need to safeguard against here? * * Jay Sternfield - 2011/11/05 ************************************************************************/ if (entity.Components.ContainsKey(typeof(AmbientLightComponent))) { System.Windows.Forms.MessageBox.Show("ERROR: THere can only be one ambient light.\nUse SetAmbientLight to replace it."); } else if (entity.Components.ContainsKey(typeof(PointLightComponent)) || entity.Components.ContainsKey(typeof(DirectionalLightComponent))) { /************************************************************************ * TODO: * Do we need to put restrictions on the number of lights we can have? * * Jay Sternfield - 2011/11/05 ************************************************************************/ mLights.Add(entity); } else { mEntities.Add(entity); } }
/// <summary> /// /// </summary> /// <param name="entity"></param> public void ViewObjectProperties(Entity_cl entity) { SelectObject(entity); TreeNode selectedNode = mObjectPanelTree.SelectedNode; string oldName = entity.Name; mDialogOpen = true; FNA.GUI.PropertyDialog_cl.Show(entity.Name, ref entity); mDialogOpen = false; if (entity.Name != oldName) { selectedNode.Text = entity.Name; mObjectList.Remove(oldName); mObjectList.Add(entity.Name, entity); } }
/// <summary> /// /// </summary> /// <param name="parent"></param> /// <param name="location"></param> public ParticleComponent_cl(Entity_cl parent, Vector2 location) : base(parent) { particle = new ParticleEffect(); particlelocation = location; }