Exemplo n.º 1
0
        public static IsoGUI getGUICapturing(ControllerEventArgs args)
        {
            if (EventSystem.current && EventSystem.current.IsPointerOverGameObject())
            {
                return(legacy == null ? legacy = new LegacyGUI() : legacy);
            }

            isInTick = true;
            foreach (IsoGUI gui in guis)
            {
                if (gui.captureEvent(args))
                {
                    return(gui);
                }
            }
            isInTick = false;
            // Normally this things should not happen, but for prevent...
            foreach (IsoGUI gui in toRemove)
            {
                removeGUI(gui);
            }
            toRemove.Clear();
            foreach (IsoGUI gui in toAdd)
            {
                addGUI(gui);
            }
            toAdd.Clear();
            return(null);
        }
Exemplo n.º 2
0
        private static void insertKeyboardConditions(ControllerEventArgs args)
        {
            float vertical   = Input.GetAxisRaw("Vertical"),
                  horizontal = Input.GetAxisRaw("Horizontal");

            if (vertical != 0)
            {
                if (vertical > 0)
                {
                    args.UP = true;
                }
                else
                {
                    args.DOWN = true;
                }
            }

            if (horizontal != 0)
            {
                if (horizontal > 0)
                {
                    args.RIGHT = true;
                }
                else
                {
                    args.LEFT = true;
                }
            }
        }
Exemplo n.º 3
0
 public override void fillControllerEvent(ControllerEventArgs args)
 {
     foreach (Map map in activeMaps)
     {
         map.fillControllerEvent(args);
     }
 }
Exemplo n.º 4
0
 public override void fillControllerEvent(ControllerEventArgs args)
 {
     args.UP    |= upPressed;
     args.DOWN  |= downPressed;
     args.RIGHT |= rightPressed;
     args.LEFT  |= leftPressed;
     args.send   = true;
 }
Exemplo n.º 5
0
        private static void insertMouseConditions(ControllerEventArgs args)
        {
            args.mousePos   = Input.mousePosition;
            args.leftStatus = Input.GetMouseButton(0);
            args.isLeftDown = left == false && args.leftStatus == true;
            args.isLeftUp   = left == true && args.leftStatus == false;

            left = args.leftStatus;
        }
Exemplo n.º 6
0
        public override void Tick()
        {
            base.Tick();

            /**
             * -Evento de control
             *  -> Controllador:
             *      -> Iniciamos un nuevo ControllerEventArgs
             *      ->
             *      -> Recopila:
             *          -> Posicion y estado del raton
             *          -> Posicion y estado del teclado
             *      -> Pregunta GUI si quiere el evento
             *          -> Si la GUI no lo captura
             *              -> Le da el evento al mapa para que:
             *                  -> Detecte la celda
             *                  -> Detecte la entidad
             *                  -> Detecte las opciones
             *          -> Si la GUI lo captura
             *              -> Le da el evento a la GUI para que lo termine.
             *      -> Si el evento se tiene que enviar
             *          -> Se manda el nuevo evento.
             */

            if (work)
            {
                //Tactil = raton
                if (Input.simulateMouseWithTouches == false)
                {
                    Input.simulateMouseWithTouches = true;
                }

                ControllerEventArgs args = new ControllerEventArgs();

                // Recopilamos estado
                insertMouseConditions(args);
                insertKeyboardConditions(args);

                //Preguntamos a la GUI.
                IsoGUI gui = GUIManager.getGUICapturing(args);

                if (gui == null)
                {
                    MapManager.getInstance().fillControllerEvent(args);
                }
                else
                {
                    gui.fillControllerEvent(args);
                }

                if (args.send)
                {
                    onControllerEvent(args);
                }
            }
        }
Exemplo n.º 7
0
        public override bool captureEvent(ControllerEventArgs args)
        {
            bool was = upPressed || leftPressed || downPressed || rightPressed;

            backupUp    = args.UP;
            backupLeft  = args.LEFT;
            backupDown  = args.DOWN;
            backupRight = args.RIGHT;

            return(was);
        }
Exemplo n.º 8
0
        public override bool captureEvent(ControllerEventArgs args)
        {
            Vector2 mo = args.mousePos;

            mo.y = Screen.height - mo.y;

            bool enRango = (Vector2.Distance(mo, this.position) <= this.radius);

            if (!enRango && args.leftStatus == true)
            {
                survive = false;
            }

            return(enRango);
        }
Exemplo n.º 9
0
 public override void fillControllerEvent(ControllerEventArgs args)
 {
     if (returningOption != null && !sended)
     {
         args.options = returningOption;
         args.send    = true;
         args.cell    = this.args.cell;
         GUIManager.removeGUI(this);
         sended = true;
         ScriptableObject.Destroy(this);
     }
     else
     {
         args.send = false;
     }
 }
Exemplo n.º 10
0
        public void init(ControllerEventArgs args, Vector2 position, Option[] options)
        {
            this.args       = args;
            this.position   = position;
            this.position.y = Screen.height - position.y;
            this.options    = options;

            angle = (2f * Mathf.PI) / ((float)options.Length);
            float currentDist = (Mathf.Sin(angle / 2f) * (minRadius - (minDist / 2f))) * 2;

            this.radius = minRadius;
            if (angle < Mathf.PI && currentDist < minDist)
            {
                this.radius = ((minDist / 2f) / Mathf.Sin(angle / 2f)) + minDist / 2f;
            }
        }
Exemplo n.º 11
0
        public void fillControllerEvent(ControllerEventArgs args)
        {
            bool encontrado = false;

            if (args.isLeftDown)
            {
                RaycastHit[] hits = Physics.RaycastAll(Camera.main.ScreenPointToRay(args.mousePos));
                if (hits.Length > 0)
                {
                    Heap <float> pqHits = new Heap <float>(hits.Length);
                    for (int i = 0; i < hits.Length; i++)
                    {
                        if (hits[i].collider.transform.IsChildOf(this.transform))
                        {
                            pqHits.push(i + 1, hits[i].distance);
                        }
                    }
                    while (!encontrado && !pqHits.isEmpty())
                    {
                        RaycastHit hit = hits[pqHits.top().elem - 1];
                        pqHits.pop();
                        Cell c = hit.collider.GetComponent <Cell>();
                        if (c != null)
                        {
                            args.cell = c;
                            var entities = c.Entities;
                            if (entities.Count == 1)
                            {
                                fillEntity(entities[0], args);
                            }
                            encontrado = true;
                        }
                        else
                        {
                            Entity e = hit.collider.GetComponentInParent <Entity>();
                            if (e != null)
                            {
                                fillEntity(e, args);
                            }
                            encontrado = true;
                        }
                    }
                }
            }
            args.send = args.UP || args.DOWN || args.LEFT || args.RIGHT || encontrado;
        }
Exemplo n.º 12
0
        /***************
         * CONTROLLER ZONE
         * **************/

        private void fillEntity(Entity e, ControllerEventArgs args)
        {
            args.entity  = e;
            args.cell    = args.entity.Position;
            args.options = args.entity.getOptions();
        }
Exemplo n.º 13
0
 public override void fillControllerEvent(ControllerEventArgs args)
 {
 }
Exemplo n.º 14
0
 public abstract void fillControllerEvent(ControllerEventArgs args);
Exemplo n.º 15
0
 public virtual bool captureEvent(ControllerEventArgs args)
 {
     return(true);
 }
Exemplo n.º 16
0
    public void onControllerEvent(IsoUnity.ControllerEventArgs args)
    {
        // # Avoid responding controller event when inactive
        if (!active)
        {
            return;
        }

        // # Normal threatment
        // Multiple controller events only give one launch result per tick
        if (toLaunch == null)
        {
            if (args.cell != null)
            {
                var cell = args.cell;
                if (args.cell.VirtualNeighbors.Count > 0)
                {
                    cell = args.cell.VirtualNeighbors[0].Destination;
                }



                GameEvent ge = new GameEvent();
                ge.setParameter("mover", this.Entity.mover);
                ge.setParameter("cell", cell);
                ge.Name = "teleport";
                Game.main.enqueueEvent(ge);
            }
            // Otherwise, the controller event should contain keys pressed
            else
            {
                int to = -1;
                if (args.LEFT)
                {
                    to = 0;
                }
                else if (args.UP)
                {
                    to = 1;
                }
                else if (args.RIGHT)
                {
                    to = 2;
                }
                else if (args.DOWN)
                {
                    to = 3;
                }

                if (to > -1)
                {
                    if (movement == null || !movingArrow)
                    {
                        if (Entity == null)
                        {
                            Debug.Log("Null!");
                        }
                        IsoUnity.Cell destination = Entity.Position.Map.getNeightbours(Entity.Position)[to];
                        // Can move to checks if the entity can DIRECT move to this cells.
                        // This should solve bug #29
                        IsoUnity.Entities.Mover em = this.Entity.GetComponent <IsoUnity.Entities.Mover>();
                        if (em != null && em.CanMoveTo(destination))
                        {
                            IsoUnity.GameEvent ge = new IsoUnity.GameEvent();
                            ge.setParameter("mover", this.Entity.mover);
                            ge.setParameter("cell", destination);
                            ge.setParameter("synchronous", true);
                            ge.Name = "move";
                            IsoUnity.Game.main.enqueueEvent(ge);
                            movement = ge;
                        }
                        else
                        {
                            IsoUnity.GameEvent ge = new IsoUnity.GameEvent();
                            ge.setParameter("mover", this.Entity.mover);
                            ge.setParameter("direction", fromIndex(to));
                            ge.setParameter("synchronous", true);
                            ge.Name = "turn";
                            IsoUnity.Game.main.enqueueEvent(ge);
                            movement = ge;
                        }
                        movingArrow = true;
                    }
                }
            }
        }
    }