Example #1
0
        public void updateFieldInfoFromText()
        {
            //If no entity or property is selected, return
            if (lstSelectedEntProperties.SelectedIndex == -1)
            {
                return;
            }
            if (creationGame.getCurrentLevel().vars.selectedEntity == null)
            {
                return;
            }

            FieldInfoListItem item = ( FieldInfoListItem )lstSelectedEntProperties.Items[lstSelectedEntProperties.SelectedIndex];

            //Have to use movement system if position component
            if (item.obj.GetType() == typeof(PositionComponent))
            {
                PositionComponent posComp = ( PositionComponent )item.obj;
                if (item.fieldInfo.Name == "x")
                {
                    creationGame.getCurrentLevel().getMovementSystem().changePosition(posComp, float.Parse(txtVar.Text), posComp.y, false, false);
                    posComp.startingX = float.Parse(txtVar.Text);
                }
                else if (item.fieldInfo.Name == "y")
                {
                    creationGame.getCurrentLevel().getMovementSystem().changePosition(posComp, posComp.x, float.Parse(txtVar.Text), false, false);
                    posComp.startingY = float.Parse(txtVar.Text);
                }
                else if (item.fieldInfo.Name == "width")
                {
                    creationGame.getCurrentLevel().getMovementSystem().changeWidth(posComp, float.Parse(txtVar.Text));
                    posComp.startingWidth = float.Parse(txtVar.Text);

                    Entity e = posComp.myEntity;
                    if (e.hasComponent(GlobalVars.DRAW_COMPONENT_NAME))
                    {
                        DrawComponent drawComp = ( DrawComponent )e.getComponent(GlobalVars.DRAW_COMPONENT_NAME);
                        if (drawComp.sizeLocked)
                        {
                            drawComp.resizeImages(int.Parse(txtVar.Text), ( int )drawComp.height);
                        }
                    }
                }
                else if (item.fieldInfo.Name == "height")
                {
                    creationGame.getCurrentLevel().getMovementSystem().changeHeight(posComp, float.Parse(txtVar.Text));
                    posComp.startingHeight = float.Parse(txtVar.Text);

                    Entity e = posComp.myEntity;
                    if (e.hasComponent(GlobalVars.DRAW_COMPONENT_NAME))
                    {
                        DrawComponent drawComp = ( DrawComponent )e.getComponent(GlobalVars.DRAW_COMPONENT_NAME);
                        if (drawComp.sizeLocked)
                        {
                            drawComp.resizeImages(( int )drawComp.width, int.Parse(txtVar.Text));
                        }
                    }
                }
            }
            else if (item.fieldInfo.FieldType == typeof(float))
            {
                item.fieldInfo.SetValue(item.obj, float.Parse(txtVar.Text));
            }
            else if (item.fieldInfo.FieldType == typeof(int))
            {
                item.fieldInfo.SetValue(item.obj, int.Parse(txtVar.Text));
            }
            else if (item.fieldInfo.FieldType == typeof(bool))
            {
                if (txtVar.Text.ToLower() == "false" || txtVar.Text == "0")
                {
                    item.fieldInfo.SetValue(item.obj, false);
                }
                else
                {
                    item.fieldInfo.SetValue(item.obj, true);
                }
            }
            else if (item.fieldInfo.FieldType != typeof(string))
            {
                item.fieldInfo.SetValue(item.obj, new StringConverter().ConvertTo(txtVar.Text, item.fieldInfo.FieldType));
            }
            else
            {
                item.fieldInfo.SetValue(item.obj, txtVar.Text);
            }
            txtVar.SelectionStart  = 0;
            txtVar.SelectionLength = 0;
            pnlMain.Focus();
        }