Exemplo n.º 1
0
        /// <summary>
        /// Try to place the primitive in parameter
        /// </summary>
        /// <param name="primitive">Primitive to place</param>
        /// <param name="cursor">Cursor position</param>
        public virtual bool PushPrimitive(Primitive primitive, Vector2 cursor)
        {
//			Debug.Log ("PushPrimitive");
            if (this.GlobalArea.Contains(cursor))
            {
                PrimitiveContainer pc = this.FirstParentContainer();
                if (pc != null)
                {
                    if (pc is PrimitiveContainer)
                    {
//						Debug.Log ("est dans un PrimitiveContainer");
                        if (pc.Inner_Container && primitive.Instruction is Condition)
                        {
//							Debug.Log ("PushPrimitive condition ok");
                            this.Next = primitive;

                            List <Condition> conditions = new List <Condition> ();
                            Primitive        p          = pc.First.Next;
                            while (p != null)
                            {
                                conditions.Add((Condition)p.Instruction);
                                p = p.Next;
                            }

                            ((Control)((Primitive)pc.parent).Instruction).setConditions(conditions);

                            return(true);
                        }
                        else if (!pc.Inner_Container && (primitive.Instruction is Action || primitive.Instruction is If))
                        {
//							Debug.Log ("PushPrimitive action ok");
                            this.Next = primitive;

                            List <Instruction> actions = new List <Instruction> ();
                            Primitive          p       = pc.First.Next;
                            while (p != null)
                            {
                                if (p is Action || p is If)
                                {
                                    actions.Add((Action)p.Instruction);
                                }
                                p = p.Next;
                            }
                            if (((Primitive)pc.parent).Instruction is Task)
                            {
                                ((Task)((Primitive)pc.parent).Instruction).setActions(actions);
                            }
                            else if (((Primitive)pc.parent).Instruction is If)
                            {
                                if (pc.Equals(((Primitive)pc.parent).Outer))
                                {
                                    ((If)((Primitive)pc.parent).Instruction).setActions(actions);
                                }
                                else if (pc.Equals(((Primitive)pc.parent).ElseOuter))
                                {
                                    ((If)((Primitive)pc.parent).Instruction).setElseActions(actions);
                                }
                            }

                            return(true);
                        }
                        else
                        {
//							Debug.Log ("Primitive au mauvais endroit...");
                            return(false);
                        }
                    }
                }
//				Debug.Log ("Pas dans un PrimitiveContainer PushPrimitive ok");
                this.Next = primitive;
                return(true);
            }
            else
            {
                foreach (Widget w in this.childs)
                {
                    if (typeof(Primitive).Equals(w.GetType()))
                    {
//						Debug.Log ("PushPrimitive fils ?");
                        if (((Primitive)w).PushPrimitive(primitive, cursor))
                        {
                            return(true);
                        }
                    }
                    else if (typeof(PrimitiveContainer).Equals(w.GetType()))
                    {
//						Debug.Log ("PushPrimitiveContainer fils ?");
                        if (((PrimitiveContainer)w).PushPrimitive(primitive, cursor))
                        {
                            return(true);
                        }
                    }
                }
            }
//			Debug.Log ("Primitive tombée dans le vide...");
            return(false);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Base constructor
        /// </summary>
        /// <param name="position">position of the primitive</param>
        /// <param name="name">nom of the primitive</param>
        public Primitive(Vector2 position, string name, Instruction instruction)
        {
            this.instruction = instruction;
            if (name == NAME_PRIMITIVE_BEGIN)
            {
                this.LocalArea = new Rect(position.x, position.y, DIM_WIDTH, DIM_TITLE_HEIGHT);
            }
            else if (instruction.GetType().Equals(typeof(Task)))
            {
                Task a = (Task)instruction;
                this.LocalArea = new Rect(position.x, position.y, DIM_WIDTH, 200);

                this.inner = (new PrimitiveContainer(new Vector2(this.area.width, 0), "CONDITION", this, true));
                this.AddChild(this.inner);
                this.inner.SetConditions(a.getConditions());

                this.outer = (new PrimitiveContainer(new Vector2(this.area.width, 0), "THEN", this, false));
                this.AddChild(this.outer);
                this.outer.SetActions(a.getActions());


                this.inner.ExtendHeight += this.OnPrimitiveContainerExtend;
                this.outer.ExtendHeight += this.OnPrimitiveContainerExtend;
            }
            else if (instruction.GetType().Equals(typeof(If)))
            {
                If a = (If)instruction;
                this.LocalArea = new Rect(position.x, position.y, DIM_WIDTH, 200);

                this.inner = (new PrimitiveContainer(new Vector2(this.area.width, 0), "CONDITION", this, true));
                this.AddChild(this.inner);
                this.inner.SetConditions(a.getConditions());

                this.outer = (new PrimitiveContainer(new Vector2(this.area.width, 0), "THEN", this, false));
                this.AddChild(this.outer);
                this.outer.SetActions(a.getActions());

                this.elseOuter = (new PrimitiveContainer(new Vector2(this.area.width, 0), "ELSE", this, false));
                this.AddChild(this.elseOuter);
                this.elseOuter.SetActions(a.getElseActions());


                this.inner.ExtendHeight     += this.OnPrimitiveContainerExtend;
                this.outer.ExtendHeight     += this.OnPrimitiveContainerExtend;
                this.elseOuter.ExtendHeight += this.OnPrimitiveContainerExtend;
            }
            else
            {
                this.LocalArea      = new Rect(position.x, position.y, DIM_WIDTH, DIM_TITLE_HEIGHT * 2);
                this.minimum_height = DIM_TITLE_HEIGHT * 2;
            }

            // Handle long titles
            if (name.Length > MAX_NAME_LENGTH)
            {
                char[] nameChar = name.ToCharArray();
                nameChar [MAX_NAME_LENGTH - 1] = '.';
                string newName = new string(nameChar, 0, MAX_NAME_LENGTH);
                name = newName;
            }

            this.title       = new Label(new Rect(0, 0, this.area.width, DIM_TITLE_HEIGHT), name);
            this.title.Color = COLOR_2;
            this.AddChild(this.title);

            if (this.instruction != null && this.instruction.needTextInput())
            {
                string textToAdd = this.instruction.AddText;
                this.text       = new Label(new Rect(0, DIM_TITLE_HEIGHT + MARGIN_ICN, this.area.width, (textToAdd.Length / 18 + 1) * 20), textToAdd);
                this.text.Color = COLOR_2;
                this.AddChild(this.text);
                this.minimum_height = DIM_TITLE_HEIGHT * 2 + MARGIN_ICN + (int)this.text.GlobalArea.height;
            }

            this.OnPrimitiveContainerExtend(null, null);
        }