예제 #1
0
파일: MainView.cs 프로젝트: Evand3r/Gen-X
        /// <summary>
        /// Añadir nuevo campo.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BttnAddField_Click(object sender, EventArgs e)
        {
            int indx;

            FieldsTypeSelect fts = new FieldsTypeSelect();
            var result           = fts.ShowDialog();

            if (result == DialogResult.OK)
            {
                StackedPanel.SuspendLayout();

                FieldPanel p = CreateField(fts.Type);

                StackedPanel.Controls.Add(p);

                if (FocusedControl != null)
                {
                    indx = StackedPanel.Controls.IndexOf(FocusedControl);
                    StackedPanel.Controls.SetChildIndex(p, indx + 1);
                }

                StackedPanel.ResumeLayout();
                StackedPanel.ScrollControlIntoView(p);
            }
        }
예제 #2
0
 public void AddFieldContainer(IFieldControlContainer controlContainer)
 {
     if (FieldPanel != null)
     {
         FieldPanel.AddFieldContainer(controlContainer);
     }
 }
예제 #3
0
파일: MainView.cs 프로젝트: Evand3r/Gen-X
        /// <summary>
        /// Validar campos listados.
        /// </summary>
        /// <returns></returns>
        private bool ValidateFields()
        {
            HashSet <string> columnNames = new HashSet <string>();

            FieldPanels.Clear();
            bool valid = true;

            //TODO: pasar de 2 a 1 una vez terminado la fase de diseño de la interfaz.
            if (StackedPanel.Controls.Count < 2)
            {
                return(false);
            }

            foreach (Control fp in StackedPanel.Controls)
            {
                if (fp is FieldPanel)
                {
                    FieldPanel p = fp as FieldPanel;
                    //Añadir el panel a la lista
                    FieldPanels.Add(p);

                    columnNames.Add(p.TBFieldName.Text);

                    //Verificar valores nulos
                    if (!uint.TryParse(p.OptionsPanel.Nulls, out NumFilas))
                    {
                        ErrorHandler.ShowMessage($"El campo 'Nulos' es inválido en la columna.'{p.TBFieldName.Text}'", MessageType.error);
                        valid = false;
                    }

                    if (string.IsNullOrEmpty(p.FieldName))
                    {
                        ErrorHandler.ShowMessage("Los nombres de las columnas no pueden estar vacíos.", MessageType.error);
                        valid = false;
                    }
                }
            }

            //Validar que los nombres de las columnas no sean iguales.
            if (StackedPanel.Controls.Count - 1 > columnNames.Count)
            {
                ErrorHandler.ShowMessage("Los nombres de las columnas deben ser únicos.", MessageType.error);
                valid = false;
            }

            //Validar que el numero de fila es un entero.
            if (!uint.TryParse(TBNumFilas.Text, out NumFilas))
            {
                ErrorHandler.ShowMessage("El número de filas no es válido.", MessageType.error);
                valid = false;
            }
            else if (NumFilas < 1)
            {
                ErrorHandler.ShowMessage("El número de filas a generar debe ser mayor que cero.", MessageType.error);
                valid = false;
            }

            return(valid);
        }
예제 #4
0
 public void AddField(IFieldControl field)
 {
     if (field is IBlockControl)
     {
         SetBlockControl(field as IBlockControl);
     }
     else if (fieldPanel != null)
     {
         FieldPanel.AddField(field);
     }
 }
예제 #5
0
파일: MainView.cs 프로젝트: Evand3r/Gen-X
        /// <summary>
        /// Crear campo con el texto de nombre.
        /// </summary>
        /// <param name="type"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        private FieldPanel CreateField(FieldType type, string name = "")
        {
            FieldPanel p = new FieldPanel(StackedPanel, type, name);

            p.Paint += new PaintEventHandler(Style_Selected);
            p.Click += new EventHandler(Panel_Click);
            //Eliminar al hacer doblue click en el panel.
            //p.MouseDoubleClick += RemoveField;

            return(p);
        }
예제 #6
0
 public IFieldControl[] GetChildFields(int levels)
 {
     if (FieldPanel != null)
     {
         List <IFieldControl> controls = new List <IFieldControl>(FieldPanel.GetChildFields(levels));
         controls.Add(Block as IFieldControl);
         return(controls.ToArray());
     }
     else
     {
         return(new IFieldControl[0]);
     }
 }
예제 #7
0
        public FieldPanelGroup(Mesh mesh, Block[] blocks, Vector3 offset)
        {
            for (int i = 0; i < blocks.Length; i++)
            {
                if (blocks[i].position.x < 0 ||
                    blocks[i].position.y < 0 ||
                    blocks[i].position.z > 0)
                {
                    // マイナス位置にあるパネルは除外
                    continue;
                }

                FieldPanel fieldPanel = new FieldPanel();
                fieldPanel.originalPosition = blocks[i].position;
                fieldPanel.position.x       = Mathf.RoundToInt(blocks[i].position.x);
                fieldPanel.position.y       = Mathf.RoundToInt(blocks[i].position.y * 2.0f) + 1;
                fieldPanel.position.z       = Mathf.RoundToInt(blocks[i].position.z);

                fieldPanel.vertices = new Vector3[4];
                for (int j = 0; j < 4; j++)
                {
                    fieldPanel.vertices[j] = mesh.vertices[i * 4 + j] + offset;
                }
                fieldPanel.reversed = (blocks[i].direction == BlockDirection.Xplus) ||
                                      (blocks[i].direction == BlockDirection.Xminus);

                this.panels.Add(fieldPanel);
            }

            // 上から順にソート
            this.panels.Sort(delegate(FieldPanel a, FieldPanel b) {
                if (a.position.y * 10000 + a.position.z * 100 + a.position.x <
                    b.position.y * 10000 + b.position.z * 100 + b.position.x)
                {
                    return(1);
                }
                else
                {
                    return(-1);
                };
            });

            // IDを割り当て
            for (int i = 0; i < this.panels.Count; i++)
            {
                this.panels[i].id = i;
            }
        }
예제 #8
0
        public bool CanMoveTo(FieldPanel target, BlockGroup blockGroup)
        {
            bool movable = true;

            if (target.position.y == this.position.y)
            {
                // 同じ高さのパネル
            }
            else if (target.position.y > this.position.y)
            {
                // 上の方のパネル
                float dy = target.originalPosition.y;
                float sy = this.originalPosition.y;
                for (float j = sy + 0.5f; j <= dy + 1.5f; j += 0.5f)
                {
                    Block block = blockGroup.GetBlock(
                        new Vector3(this.originalPosition.x, j, this.originalPosition.z));
                    if (block != null)
                    {
                        movable = false;
                        break;
                    }
                }
            }
            else if (target.position.y < this.position.y)
            {
                // 下の方のパネル
                float dy = target.originalPosition.y;
                float sy = this.originalPosition.y;
                for (float j = sy + 1.5f; j >= dy + 0.5f; j -= 0.5f)
                {
                    Block block = blockGroup.GetBlock(
                        new Vector3(target.originalPosition.x, j, target.originalPosition.z));
                    if (block != null)
                    {
                        movable = false;
                        break;
                    }
                }
            }
            return(movable);
        }
예제 #9
0
        protected override void Load()
        {
            _fieldTexture = Resources.LoadAssetAtPath <Texture>(Consts.FIELD_TEXTURE_PATH);
            var types = Enum.GetValues(typeof(BlockType)).Cast <BlockType>();

            _blockTextures = types.ToDictionary(
                type => type,
                type => (Texture)AssetDatabase.LoadAssetAtPath(Consts.BLOCKS_TEXTURES_PATH + type + ".png", typeof(Texture))
                );

            _taskTab  = new TaskTab();
            _blockTab = new BlockTab(_blockTextures);
            _parmsTab = new ParametersTab();

            _tabs = new Tabs.Tabs(_parmsTab, _blockTab, _taskTab);

            _field = new FieldPanel(Consts.FIELD_WIDTH, Consts.FIELD_HEIGHT, new Vector2(Consts.BLOCK_WIDTH, Consts.BLOCK_HEIGHT), _blockTextures);

            Level = new LevelInfo();
        }
예제 #10
0
파일: MainView.cs 프로젝트: Evand3r/Gen-X
        /// <summary>
        /// Cambiar tipo de campo del campo seleccionado.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void ChangeField(object sender, EventArgs e)
        {
            int        indx;
            FieldPanel prevField = ((sender as Button).Parent as Panel).Parent as FieldPanel;

            FieldsTypeSelect fts = new FieldsTypeSelect();
            var result           = fts.ShowDialog();

            if (result == DialogResult.OK && prevField.FieldType.BName != fts.Type.BName)
            {
                StackedPanel.SuspendLayout();

                indx = StackedPanel.Controls.IndexOf(prevField);

                FieldPanel p = CreateField(fts.Type, prevField.TBFieldName.Text);

                StackedPanel.Controls.RemoveAt(indx);
                StackedPanel.Controls.Add(p);
                StackedPanel.Controls.SetChildIndex(p, indx);
                StackedPanel.ResumeLayout();
            }
        }
예제 #11
0
파일: Generador.cs 프로젝트: Evand3r/Gen-X
        private void GenerateJSON()
        {
            //Get options
            bool asArray     = (Options.Controls.Find("JsonAsArray", true)[0] as CheckBox).Checked;
            bool includeNull = (Options.Controls.Find("IncludeNull", true)[0] as CheckBox).Checked;

            DialogResult SaveResult  = DialogResult.OK;
            string       baseJsonStr = "\"+\": -";
            string       JsonLine    = "{_}" + (asArray ? "," : "");
            string       tmp;

            if (!Preview)
            {
                Save.Filter = "Json files (*.json)|*.json";
                Save.Title  = "Guardar archivo JSON";
                //Nombre del archivo por defecto.
                Save.FileName = "GEN_X.json";
                SaveResult    = Save.ShowDialog();
                Writer        = SaveResult == DialogResult.OK ? new StreamWriter(Save.OpenFile()) : null;
            }

            Result = (asArray ? "[" : "");

            for (int i = 0; i < Lines; i++)
            {
                tmp = "";
                for (int j = 0; j < Fields.Count; j++)
                {
                    FieldPanel p   = Fields.ElementAt(j);
                    var        str = p.OptionsPanel.Options.Generate(fkr, Convert.ToInt32(Lines), "\"", DefaultNullValue);

                    if (includeNull || str != DefaultNullValue)
                    {
                        tmp += (asArray ? identation : "") +
                               baseJsonStr.Replace("+", p.FieldName).Replace("-", str + ",") +
                               (asArray && j + 1 != Fields.Count ? nl : "");
                    }
                }

                tmp = !tmp.Equals(string.Empty) || !asArray ? (asArray ? nl : "") + tmp.TrimEnd(',') + (!asArray ? "" : nl) : nl;

                if (!Preview && SaveResult == DialogResult.OK && Save.FileName != "")
                {
                    string line = (asArray && i == 0 ? "[" : "") + JsonLine.Replace("_", tmp);

                    if (asArray && i + 1 == Lines)
                    {
                        //Elimiar ultima coma del array
                        line = line.TrimEnd(',') + (asArray ? "]" : "");
                    }

                    Writer.WriteLine(line);
                }
                else
                {
                    Result += JsonLine.Replace("_", tmp) + (!asArray ? nl : "");
                }
            }

            if (Preview)
            {
                Result = Result.TrimEnd(',') + (asArray ? "]" : "");
                PreviewForm PreviewFrm = new PreviewForm(Result);
                PreviewFrm.ShowDialog();
            }
        }