public InventoryRecord(GameObject f, int c, string pfn, InventoryWindowController par)
        {
            parent        = par;
            frame         = f;
            pieceFileName = pfn;
            validTypes    = PieceTemplateController.ValidTypes(pfn);
            GameObject t = Instantiate(Resources.Load("Prefabs/PieceTemplate")) as GameObject;

            template = t.GetComponent <PieceTemplateController>();
            if (c > 0)
            {
                template.transform.SetParent(frame.transform, true);
                t.transform.SetAsFirstSibling();
                template.transform.localPosition = new Vector3(templateX, 0f, 0.01f);
                template.UpdateHitRect();
                template.ConfigureFromJSON(pfn);
                UpdateDescriptiveText();
                template.SetCount(c);
            }
            else
            {
                template = null;
                Destroy(t);
            }
        }
        public void Reconstruct(GameObject f, int c, string pfn)
        {
            if (template != null && template.gameObject != null)
            {
                Destroy(template.gameObject);
            }
            frame         = f;
            pieceFileName = pfn;
            GameObject t = Instantiate(Resources.Load("Prefabs/PieceTemplate")) as GameObject;

            template = t.GetComponent <PieceTemplateController>();
            if (c > 0)
            {
                template.transform.SetParent(frame.transform, true);
                t.transform.SetAsFirstSibling();
                template.transform.localPosition = new Vector3(templateX, 0f, 0.01f);
                template.UpdateHitRect();
                template.ConfigureFromJSON(pfn);
                UpdateDescriptiveText();
                template.SetCount(c);
            }
            else
            {
                template = null;
                Destroy(t);
            }
            if (f != null && GetCount() > 0)
            {
                SetCount(c);
            }
        }
Beispiel #3
0
    public void HandleEvent(GameEvent ge)
    {
        if (ge.type.Equals("piece_tapped"))
        {
            PieceController tappedPiece = (PieceController)ge.args[0];
            if (tappedPiece.GetGridLock())
            {
                if (floatingPiece != null)
                {
                    bool success = grid.TryAddPiece(floatingPiece);
                    if (success)
                    {
                        floatingPiece.SetGridLock(true);
                        floatingPiece = null;
                    }
                }
                Activate(tappedPiece);
            }
            else
            {
                bool success = grid.TryAddPiece(tappedPiece);
                if (success)
                {
                    tappedPiece.SetGridLock(true);
                    floatingPiece = null;
                }
            }
        }
        else if (ge.type.Equals("piece_dropped_on_inventory"))
        {
            PieceController piece = (PieceController)ge.args[0];
            InventoryAdd(piece);
        }
        else if (ge.type.Equals("template_tapped"))
        {
            PieceTemplateController tappedPiece = (PieceTemplateController)ge.args[0];
            Vector3 loc = (Vector3)ge.args[1];
            if (floatingPiece != null)
            {
                bool success = grid.TryAddPiece(floatingPiece);
                if (success)
                {
                    floatingPiece.SetGridLock(true);
                    floatingPiece = null;
                }
            }

            GameObject go = Instantiate(Resources.Load("Prefabs/ExistingPiece")) as GameObject;
            go.transform.SetParent(canvas.transform, false);
            go.transform.position = new Vector3(loc.x, loc.y, go.transform.position.z);
            PieceController newPiece = go.GetComponent <PieceController>();
            newPiece.ConfigureFromJSON(tappedPiece.GetFilename());
            newPiece.SetRotation(0);
            newPiece.SetMoving(true);
            Activate(newPiece);
            iwc.RemovePiece(newPiece);
            //tappedPiece.SetCount(tappedPiece.GetCount()-1);
        }
    }
 public void SetCount(int count)
 {
     if (template != null)
     {
         template.SetCount(count);
         //Debug.Log(pieceFileName + " count is " + count);
     }
     else if (count > 0)
     {
         //create a temporary template to hold the thing
         GameObject t = Instantiate(Resources.Load("Prefabs/PieceTemplate")) as GameObject;
         template = t.GetComponent <PieceTemplateController>();
         template.SetCount(count);
     }
     //don't forget to update the frame's text element for tracking count
 }
        public InventoryRecord(GameObject f, int c, string pfn)
        {
            frame         = f;
            pieceFileName = pfn;
            GameObject t = Instantiate(Resources.Load("Prefabs/PieceTemplate")) as GameObject;

            template = t.GetComponent <PieceTemplateController>();
            if (c > 0)
            {
                template.transform.SetParent(frame.transform, true);
                template.transform.localPosition = new Vector3(98f, 0f, 0.01f);
                template.ConfigureFromJSON(pfn);
                template.SetCount(c);
            }
            else
            {
                template = null;
                Destroy(t);
            }
        }
 public void SetCount(int count)
 {
     if(template != null){
         template.SetCount(count);
         //Debug.Log(pieceFileName + " count is " + count);
     }else if(count > 0){
         //create a temporary template to hold the thing
         GameObject t = Instantiate (Resources.Load ("Prefabs/PieceTemplate")) as GameObject;
         t.transform.SetAsFirstSibling();
         template = t.GetComponent<PieceTemplateController>();
         template.SetCount(count);
     }
     //don't forget to update the frame's text element for tracking count
     if(frame != null)
         UpdateCountText (count);
 }
 public void Reconstruct(GameObject f,int c, string pfn)
 {
     if(template.gameObject != null)
         Destroy (template.gameObject);
     frame = f;
     pieceFileName = pfn;
     GameObject t = Instantiate (Resources.Load ("Prefabs/PieceTemplate")) as GameObject;
     template = t.GetComponent<PieceTemplateController>();
     if(c > 0){
         template.transform.SetParent(frame.transform,true);
         t.transform.SetAsFirstSibling();
         template.transform.localPosition = new Vector3(templateX,0f,0.01f);
         template.UpdateHitRect();
         template.ConfigureFromJSON(pfn);
         UpdateDescriptiveText();
         template.SetCount(c);
     }else{
         template = null;
         Destroy (t);
     }
     if(f != null && GetCount() > 0){
         SetCount (c);
     }
 }
 public InventoryRecord(GameObject f,int c, string pfn)
 {
     frame = f;
     pieceFileName = pfn;
     GameObject t = Instantiate (Resources.Load ("Prefabs/PieceTemplate")) as GameObject;
     template = t.GetComponent<PieceTemplateController>();
     if(c > 0){
         template.transform.SetParent(frame.transform,true);
         template.transform.localPosition = new Vector3(98f,0f,0.01f);
         template.ConfigureFromJSON(pfn);
         template.SetCount(c);
     }else{
         template = null;
         Destroy (t);
     }
 }
    public void HandleEvent(GameEvent ge)
    {
        if (ge.type.Equals("piece_tapped"))
        {
            PieceController tappedPiece = (PieceController)ge.args[0];
            if (tappedPiece.GetGridLock())
            {
                if (floatingPiece != null)
                {
                    bool success = grid.TryAddPiece(floatingPiece);
                    if (success)
                    {
                        floatingPiece.SetGridLock(true);
                        floatingPiece = null;
                    }
                }
                Activate(tappedPiece);
            }
            else
            {
                bool success = grid.TryAddPiece(tappedPiece);
                if (success)
                {
                    tappedPiece.SetGridLock(true);
                    floatingPiece = null;
                }
            }
        }
        else if (ge.type.Equals("piece_dropped_on_inventory"))
        {
            PieceController piece = (PieceController)ge.args[0];
            InventoryAdd(piece);
        }
        else if (ge.type.Equals("template_tapped"))
        {
            PieceTemplateController tappedPiece = (PieceTemplateController)ge.args[0];
            Vector3 loc = (Vector3)ge.args[1];
            if (floatingPiece != null)
            {
                bool success = grid.TryAddPiece(floatingPiece);
                if (success)
                {
                    floatingPiece.SetGridLock(true);
                    floatingPiece = null;
                }
            }

            GameObject go = Instantiate(Resources.Load("Prefabs/ExistingPiece")) as GameObject;
            go.transform.SetParent(canvas.transform, false);
            go.transform.position = new Vector3(loc.x, loc.y, go.transform.position.z);
            PieceController newPiece = go.GetComponent <PieceController>();
            newPiece.ConfigureFromJSON(tappedPiece.GetFilename());
            newPiece.SetRotation(0);
            newPiece.SetMoving(true);
            Activate(newPiece);
            iwc.RemovePiece(newPiece);
            //tappedPiece.SetCount(tappedPiece.GetCount()-1);
        }
        else if (ge.type.Equals("alt_click"))
        {
            if (floatingPiece == null)
            {
                return;
            }
            if (!finger1down)
            {
                return;
            }

            Vector3 altClickPos = (Vector3)ge.args[0];
            //check if the second click is on one of the rotate buttons
            float ymax = rotCounterclockwise.rect.y + (rotCounterclockwise.rect.height / 2f);
            float xmax = rotCounterclockwise.rect.x + (rotCounterclockwise.rect.width / 2f);
            if (altClickPos.x < xmax && altClickPos.y < ymax)             //then you're on the buttons
            {
                return;
            }

            Vector3 firstClickPos = InputWatcher.GetInputPosition();
            Vector3 direction     = altClickPos - firstClickPos;
            twoFingerAngle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
            pieceAngle     = floatingPiece.transform.eulerAngles.z;

            floatingPiece.SetTwoFingerMovement(true);
            finger2down = true;
        }
        else if (ge.type.Equals("alt_release"))
        {
            Debug.Log("alt release happened");
            if (floatingPiece == null)
            {
                return;
            }
            if (!finger2down)
            {
                return;
            }

            if (waitingForOtherFingerToReset)
            {
                floatingPiece.SetTwoFingerMovement(false);
                waitingForOtherFingerToReset = false;
            }
            else
            {
                waitingForOtherFingerToReset = true;
                floatingPiece.LockRotation();
            }
            finger2down = false;
        }
        else if (ge.type.Equals("mouse_click"))
        {
            Vector3 pos = (Vector3)ge.args[0];
            if (grid.TouchIsOnMe(pos))
            {
                finger1down = true;
            }
        }
        else if (ge.type.Equals("mouse_release"))
        {
            if (floatingPiece == null)
            {
                return;
            }
            if (waitingForOtherFingerToReset)
            {
                floatingPiece.SetTwoFingerMovement(false);
                waitingForOtherFingerToReset = false;
            }
            else
            {
                waitingForOtherFingerToReset = true;
                floatingPiece.LockRotation();
            }
            finger1down = false;
        }
    }