void combinedContainerControl_ContainedControlRemovedEvent(CombinedContainerControl container, Control control)
        {
            PlatformComponent component = null;

            // First, catch the component before uninitializing the control.
            if (_platform != null && control.Tag != null && control is PlatformComponentControl &&
                _platform.GetComponentByIdentification((((PlatformComponentControl)control).Component).SubscriptionClientID.Id, true) != null)
            {
                component = ((PlatformComponentControl)control).Component;
                ((PlatformComponentControl)control).SetApplicationStatusStrip(null);
            }

            if (control is CommonBaseControl)
            {
                (control as CommonBaseControl).SaveState();
            }

            if (component != null)
            {// Remove component from platform.
                if (_platform.IsMandatoryComponent(component) == false)
                {
                    _platform.UnRegisterComponent(component);
                }

                component.UISerializationInfo.AddValue("componentVisible", false);
            }

            if (control is CommonBaseControl)
            {
                (control as CommonBaseControl).UnInitializeControl();
            }

            UpdateComponentsMenues();
        }
        void uiThread_ActiveComponentUpdateEvent(PlatformComponent component, bool added, bool isInitial)
        {
            if (added)
            {
                bool visible = true;
                if (component.UISerializationInfo.ContainsValue("componentVisible"))
                {
                    visible = component.UISerializationInfo.GetBoolean("componentVisible");
                }

                if (visible)
                {
                    CommonBaseControl control = CommonBaseControl.CreateCorrespondingControl(component, true);
                    AddComponentControl(control, isInitial == false);
                }
            }
            else
            {
                CommonBaseControl control = combinedContainerControl.GetControlByTag(component);
                if (control != null)
                {
                    combinedContainerControl.RemoveControl(control);
                }
            }

            UpdateComponentsMenues();
        }
        public override void UnInitializeControl()
        {
            if (_component != null)
            {
                _component = null;
            }

            base.UnInitializeControl();
        }
        /// <summary>
        /// Handles player versus platform collision
        /// </summary>
        /// <param name="Player"> Id of the player entity </param>
        /// <param name="Platform"> Id of the platform entity </param>
        private void PlayerVsPlatformColl(int Player, int Platform, GameTime gameTime)
        {
            PlayerComponent             playComp = ComponentManager.Instance.GetEntityComponent <PlayerComponent>(Player);
            DirectionComponent          dc       = ComponentManager.Instance.GetEntityComponent <DirectionComponent>(Player);
            VelocityComponent           pvc      = ComponentManager.Instance.GetEntityComponent <VelocityComponent>(Player);
            PositionComponent           ppc      = ComponentManager.Instance.GetEntityComponent <PositionComponent>(Player);
            CollisionRectangleComponent pcrc     = ComponentManager.Instance.GetEntityComponent <CollisionRectangleComponent>(Player);
            PlatformComponent           pc       = ComponentManager.Instance.GetEntityComponent <PlatformComponent>(Platform);
            HealthComponent             hc       = ComponentManager.Instance.GetEntityComponent <HealthComponent>(Player);

            if (!playComp.isFalling)
            {
                if (pcrc.CollisionRec.Intersects(pc.TopRec)) // @TODO tänk om gällande pixlePerfect, kanske
                {
                    //@todo hur fan ska man ta bort n om spelarn hoppar ifrån eller blir nerputtad
                    if (!ComponentManager.Instance.CheckIfEntityHasComponent <TTLComponent>(Player))
                    {
                        TTLComponent ttl = new TTLComponent(5f);
                        ComponentManager.Instance.AddComponentToEntity(Player, ttl);
                    }
                    else
                    {
                        TTLComponent ttl = ComponentManager.Instance.GetEntityComponent <TTLComponent>(Player);
                        if (ttl.curTime >= ttl.maxTime)
                        {
                            playComp.isFalling = true;
                            //hc.health -= 1;
                            ComponentManager.Instance.RemoveComponentFromEntity(Player, ttl);
                        }
                    }

                    changeDir(dc);
                    if (dc.directio != Direction.Still)
                    {
                        dc.preDir   = dc.directio;
                        dc.directio = Direction.Still;
                    }
                    pvc.velocity.Y  = 0;
                    pvc.velocity.Y -= 500 * (float)gameTime.ElapsedGameTime.TotalSeconds;
                }
                else
                {
                    if (dc.directio != Direction.Still)
                    {
                        changeDir(dc);
                        dc.preDir   = dc.directio;
                        dc.directio = Direction.Still;
                    }
                    pvc.velocity.Y     = 0;
                    pvc.velocity.Y    += 500 * (float)gameTime.ElapsedGameTime.TotalSeconds;
                    playComp.isFalling = true;

                    ComponentManager.Instance.AddComponentToEntity(Player, new SoundEffectComponent("pfhit"));
                    //hc.health -= 1;
                }
            }
        }
 void UpdateFormText(PlatformComponent activeComponent)
 {
     if (activeComponent == null)
     {
         this.Text = "Open Forex Platform [v." + GeneralHelper.ApplicationVersion + "]";
     }
     else
     {
         this.Text = "Open Forex Platform [v." + GeneralHelper.ApplicationVersion + "] - " + activeComponent.Name;
     }
 }
        /// <summary>
        ///
        /// </summary>
        public PlatformComponentControl(PlatformComponent component)
        {
            InitializeComponent();

            if (this.DesignMode)
            {
                return;
            }

            _component = component;

            if (_component != null)
            {
                base._persistenceData = _component.UISerializationInfo;
                this.Name             = _component.Name;
            }
        }
示例#7
0
    void CreatePlatforms()
    {
        float totalSpaceingLength = Spacing * (NumPlatforms);
        float sumPlatformsLength  = NumPlatforms * (NumPlatforms + 1) / 2;
        float SCALE = (WidthHeight.x - totalSpaceingLength) / (sumPlatformsLength);

        platforms = new Platform[NumPlatforms];
        float currentX = Spacing * .5f;

        List <int> lengths = new List <int>();

        // Create list
        for (int i = 0; i < NumPlatforms; i++)
        {
            lengths.Add(i + 1);
        }

        // Randomize lengths in list
        for (int i = 0; i < lengths.Count; i++)
        {
            int length = lengths[i];
            lengths.RemoveAt(i);
            lengths.Insert((int)Random.Range(0, (float)lengths.Count), length);
        }

        // Create the platforms
        for (int i = 0; i < NumPlatforms; i++)
        {
            int     length       = lengths[i];
            float   scaledLength = (length) * SCALE;
            Vector2 position     = new Vector2(currentX, Random.Range(MinHeight, WidthHeight.y));
            float   points       = (1 + (NumPlatforms) - length) * PointsMultiplier;

            platforms[i] = new Platform(scaledLength, position, (int)points);
            currentX    += scaledLength + Spacing;
        }

        // Instantiate the platform prefabs
        for (int i = 0; i < platforms.Length; i++)
        {
            GameObject        platform = Instantiate(PlatformPrefab, (Vector2)transform.position - WidthHeight * .5f + (platforms[i].Position + Vector2.right * platforms[i].Length / 2), Quaternion.identity);
            PlatformComponent pc       = platform.GetComponent <PlatformComponent>();
            pc.SetValue(platforms[i].Points);
            pc.SetLength(platforms[i].Length);
        }
    }
        /// <summary>
        /// Creates a platform at the specified position with the specified lenght, width and Texture;
        /// </summary>
        /// <param name="pos"></param>
        /// <param name="texture"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <returns> the id of the created platform identity </returns>
        public int CreatePlatform(Vector2 pos, string texture, int width, int height)
        {
            PositionComponent           Pc  = new PositionComponent(pos);
            DrawableComponent           DC  = new DrawableComponent(Game.Instance.GetContent <Texture2D>("Pic/" + texture), SpriteEffects.None);
            CollisionRectangleComponent CRC = new CollisionRectangleComponent(new Rectangle((int)pos.X, (int)pos.Y, width, height));
            CollisionComponent          CC  = new CollisionComponent(false);
            PlatformComponent           Plc = new PlatformComponent(pos, width, height);

            Plc.RedoRecs(pos, DC.texture.Width, DC.texture.Height);

            int id = ComponentManager.Instance.CreateID();


            ComponentManager.Instance.AddComponentToEntity(id, CRC);
            ComponentManager.Instance.AddComponentToEntity(id, CC);
            ComponentManager.Instance.AddComponentToEntity(id, Pc);
            ComponentManager.Instance.AddComponentToEntity(id, DC);
            ComponentManager.Instance.AddComponentToEntity(id, Plc);
            return(id);
        }
    private void SpawnPlatform()
    {
        if (lastSpawnedPosition == Vector3.zero)
        {
            lastSpawnedPosition = spawnStart.position;
        }

        GameObject        objectToSpawn     = nextObjectToSpawn == null ? platformConfig.Platforms[Random.Range(0, platformConfig.Platforms.Length)] : endArea;
        PlatformComponent platformComponent = objectToSpawn.GetComponent <PlatformComponent>();
        GameObject        spawnedGameObject;

        int randomNumber = Random.Range(1, 101);

        moveThresholdToSpawn = platformComponent.platformWidth;

        if (randomNumber <= platformConfig.ChanceToSpawnGap * 100)
        {
            moveThresholdToSpawn += Random.Range(1, 4);
        }

        spawnedGameObject = Instantiate(objectToSpawn);

        int yMax = Convert.ToInt32(Math.Floor(Mathf.Clamp(lastSpawnedPosition.y + characterConfig.JumpHeight - 1,
                                                          spawnEnd.position.y,
                                                          spawnStart.position.y)));
        int yPositionToSpawn = Random.Range(Convert.ToInt32(spawnEnd.position.y), yMax);

        int xPos = Convert.ToInt32(Math.Floor(spawnStart.position.x + platformComponent.platformWidth / 2f));

        spawnedGameObject.transform.SetPositionAndRotation(
            new Vector3(xPos, yPositionToSpawn, 0), objectToSpawn.transform.rotation);

        lastSpawnedPosition = spawnedGameObject.transform.position;
        gameObject.transform.Translate(new Vector3(moveThresholdToSpawn, 1, 0));
        nextObjectToSpawn = null;

        SpawnEnemy(spawnedGameObject);
    }
示例#10
0
    void OnCollisionEnter2D(Collision2D col)
    {
        if (!landed)
        {
            if (col.contacts[0].normal == Vector2.up && velocity.magnitude < maxLandingVelocityMagnitude && IsShipUpright())
            {
                PlatformComponent pc = col.gameObject.GetComponentInParent <PlatformComponent>();;

                int PlatformScore = pc.ScoreValue;
                scoreManager.AddScore(PlatformScore);

                //ScoreSystem.GetInstance().AddToScore(PlatformScore);

                onSuccesfulLanding.Invoke();
            }
            else
            {
                Explode();
                scoreManager.CheckNewHighscore();
            }
            landed = true;
        }
    }
 void platform_ActiveComponentRemovedEvent(PlatformComponent component, bool isInitial)
 {
     WinFormsHelper.BeginManagedInvoke(this, new GeneralHelper.GenericDelegate <PlatformComponent, bool, bool>(
                                           uiThread_ActiveComponentUpdateEvent), component, false, isInitial);
 }
 void _platform_ActiveComponentChangedOperationalStateEvent(Platform platform, PlatformComponent component, OperationalStateEnum previousState)
 {
     //WinFormsHelper.BeginFilteredManagedInvoke(this, new EventHandler(tabControl_SelectedIndexChanged), null, EventArgs.Empty);
 }
        void createItem_Click(object sender, EventArgs e)
        {
            ToolStripMenuItem item = (ToolStripMenuItem)sender;
            Type componentType     = (Type)item.Tag;

            PlatformComponent component = null;

            bool showPropertiesForm = ComponentManagementAttribute.GetTypeAttribute(componentType).RequestPreStartSetup;

            if (ComponentManagementAttribute.GetTypeAttribute(componentType).IsMandatory)
            {// Mandatory components we do not create, only show / hide.
                component = _platform.GetFirstComponentByType(componentType);
                component.UISerializationInfo.AddValue("componentVisible", true);

                platform_ActiveComponentAddedEvent(component, false);
                return;
            }

            if (componentType.IsSubclassOf(typeof(Expert)))
            {
                component          = new LocalExpertHost(UserFriendlyNameAttribute.GetTypeAttributeName(componentType), componentType);
                showPropertiesForm = showPropertiesForm || ComponentManagementAttribute.GetTypeAttribute(typeof(LocalExpertHost)).RequestPreStartSetup;
            }
            else if (componentType.IsSubclassOf(typeof(WizardControl)))
            {// Wizards are run in Hosting forms.
                ConstructorInfo info = componentType.GetConstructor(new Type[] { typeof(Platform) });

                if (info != null)
                {
                    WizardControl wizardControl = (WizardControl)info.Invoke(new object[] { _platform });
                    HostingForm   hostingForm   = new HostingForm(UserFriendlyNameAttribute.GetTypeAttributeName(componentType), wizardControl);
                    hostingForm.Icon = Resources.magic_wand1;
                    hostingForm.Show();
                    return;
                }
            }
            else if (componentType.IsSubclassOf(typeof(CommonBaseControl)))
            {// Tester/editor etc. controls have no components, they are standalone UI components.
                ConstructorInfo info = componentType.GetConstructor(new Type[] { });
                // If failed to find orderInfo, just fall trough to failed to create component (which remains null).
                if (info != null)
                {// Since this is a UI only component, just create and return.
                    CommonBaseControl testerControl = (CommonBaseControl)info.Invoke(new object[] { });
                    /*tabControl.SelectedTab = */ AddComponentControl(testerControl, true);

                    return;
                }
            }
            else
            {
                ConstructorInfo info = componentType.GetConstructor(new Type[] { });
                if (info != null)
                {
                    component = (PlatformComponent)info.Invoke(new object[] { });
                }
            }

            // ...
            if (component == null)
            {
                MessageBox.Show("Failed to create component.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // Set settings for component.
            if (component.SetInitialState(_platform.Settings) == false)
            {
                MessageBox.Show("Component failed to initialize from initial state.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }


            if (showPropertiesForm)
            {
                // Show properties for the user to configure.
                PropertiesForm form = new PropertiesForm("Properties", component);
                if (form.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
            }

            // Register to platform.
            _platform.RegisterComponent(component);
        }
 void Component_UnInitializing(PlatformComponent component)
 {
     SaveState();
 }
 void Component_Initializing(PlatformComponent component)
 {
 }