Esempio n. 1
0
    public void Add(UIObject newObj, UIDir dir)
    {
        Vector2 rel = Vector2.zero;

        if (list.Size() > 0)
        {
            UIObject last = list.Last();
            switch (dir)
            {
            case UIDir.W:
                rel = last.GetRelative() + new Vector2(last.GetWidth(), 0);
                break;

            case UIDir.S:
                rel = new Vector2(origin.x, last.GetRelative().y - last.GetHeight());
                break;

            default:
                UT.assert(false, "button: invalid direction");
                break;
            }
        }

        UT.print("REL: " + rel);

        newObj.SetRelative(rel);
        list.AddLast(newObj);

        UpdateBounds();

        UT.print("New bounds: " + bounds);
    }
Esempio n. 2
0
    private static void UtilTest()
    {
        Rect r1 = Rect.MinMaxRect(0, 0, 3, 5);
        Rect r2 = Rect.MinMaxRect(1, 1, 6, 2);
        Rect u  = AMenu.Union(r1, r2);

        UT.assert(u.x == 0 && u.y == 0 && u.width == 6f && u.height == 5f);
        UT.print("Union: " + u);
    }
Esempio n. 3
0
    public static void print <T>(MList <T> l)
    {
        int    n = 0;
        string s = "";

        foreach (T i in l)
        {
            s += "([" + (n++) + "] " + i + " )";
        }
        UT.print(s);
    }
Esempio n. 4
0
 public override bool Step()
 {
     if (UpdateTimer())
     {
         // update position
         seq.transform.position += velocity * Time.deltaTime;
         UT.print("MoveTo: " + seq.transform.position);
         return(true);
     }
     seq.transform.position = targetPosition;
     return(false);
 }
Esempio n. 5
0
    public void Clicked()
    {
        if (action != null)
        {
            action.Invoke();
        }
        else
        {
            UT.print("AButton: no action");
        }

        if (closeOnClick)
        {
            menu.Close();
        }
    }
Esempio n. 6
0
    public void toHexUnit(bool evenX, int dir)
    {
        switch (dir)
        {
        case 0: x = 0; y = -1; return;

        case 1: x = 1; y = evenX ? -1 : 0; return;

        case 2: x = 1; y = evenX ? 0 : 1; return;

        case 3: x = 0; y = 1; return;

        case 4: x = -1; y = evenX ? 0 : 1; return;

        case 5: x = -1; y = evenX ? -1 : 0; return;
        }
        UT.print("toHexUnit: invalid direction: " + dir);
    }
Esempio n. 7
0
 public void UpdateBounds()
 {
     if (list.Size() == 0)
     {
         bounds = new Rect();             // no objects, no bounds
     }
     else
     {
         var it = list.Iterator();
         it.Next();
         bounds = it.Value().GetRelativeRect();             // start with the first object
         UT.print("UpdateBounds: rect " + it.Value().GetRelativeRect() + ", bounds " + bounds);
         while (it.Next())
         {
             bounds = AMenu.Union(bounds, it.Value().GetRelativeRect());
             UT.print("UpdateBounds: rect " + it.Value().GetRelativeRect() + ", bounds " + bounds);
         }
     }
 }
Esempio n. 8
0
    public static Int2 hexUnit(bool evenX, int dir)
    {
        switch (dir)
        {
        case 0: return(new Int2(0, -1));

        case 1: return(new Int2(1, evenX ? -1 : 0));

        case 2: return(new Int2(1, evenX ? 0 : 1));

        case 3: return(new Int2(0, 1));

        case 4: return(new Int2(-1, evenX ? 0 : 1));

        case 5: return(new Int2(-1, evenX ? -1 : 0));
        }
        UT.print("toHexUnit: invalid direction: " + dir);
        return(null);
    }
Esempio n. 9
0
    private static void RunTest()
    {
        UT.print("-------- MListTest start --------");
        MList <int> l = new MList <int>();

        // insert first
        l.AddLast(1);
        l.AssertValid();
        print(l);
        l.AddFirst(2);
        l.AssertValid();
        print(l);
        l.AddFirst(3);
        print(l);

        // insert before
        var it = l.Iterator();

        it.AssertValid();
        it.Next();
        it.InsertBefore(-1);
        it.AssertValid();
        print(l);
        it.InsertBefore(0);
        it.AssertValid();
        l.AssertValid();
        print(l);         // "-1 0 1 2 3"
        while (it.HasNext())
        {
            it.Next();
        }
        it.InsertBefore(2);
        it.AssertValid();
        l.AssertValid();
        print(l);         // "-1 0 1 2 2 3"

        l = new MList <int>();
        // fill list
        for (int i = 0; i < FILL_SIZE; i++)
        {
            l.AddLast(100 + i);
        }
        print(l);
        UT.assert(l.Size() == FILL_SIZE);

        // iterator insert and remove
        it = l.Iterator();
        while (it.Next())
        {
            it.InsertAfter(555555);
            l.AssertValid();
            if (it.Next())
            {
                it.Remove();
            }
            l.AssertValid();
        }
        it.InsertAfter(123456);
        print(l);
        l.AssertValid();

        // remove last
        it = l.Iterator();
        while (it.HasNext())
        {
            it.Next();
        }
        it.Remove();

        l.AssertValid();
        l.RemoveAll();
        l.AssertValid();
        UT.assert(l.Size() == 0);

        // empty by iterator
        l = new MList <int>();
        for (int i = 0; i < 2; i++)
        {
            l.AddLast(10 + i);
        }
        it = l.Iterator();
        while (it.Next())
        {
            l.AssertValid();
            it.AssertValid();
            it.Remove();
            l.AssertValid();
            it.AssertValid();
        }

        // test remove last iterator
        l = new MList <int>();
        for (int i = 0; i < 2; i++)
        {
            l.AddLast(10 + i);
        }
        it = l.Iterator();
        it.Next();
        l.Remove(it);
        l.AssertValid();

        UT.print("-------- MListTest end --------");
    }