예제 #1
0
    public override void OnAwake()
    {
        base.OnAwake();

        CinchOptions.UseTopLeftSpriteSheetCoordinates = true;
        CinchOptions.DefaultPixelsPerMeter            = 100f;

        this.Name = "ParentingStage";
        AddSymbolDefinitions();

        AddEventListener <MouseEvent>(MouseEvent.MOUSE_DOWN, onStagePress);

        _everythingContainer              = Library.New <DisplayObjectContainer>();
        _everythingContainer.Name         = "Everything container";
        _everythingContainer.MouseEnabled = false;
        AddChild(_everythingContainer);

        _table = Library.New("Table");
        _table.MouseEnabled = true;
        ValidateNumberMouseObjects(0);
        _everythingContainer.AddChild(_table);
        ValidateNumberMouseObjects(1);
        _table.Name   = "Table";
        _table.Width  = ViewportWidth * .8f;
        _table.ScaleY = _table.ScaleX;

        var checkerBoard = Library.New("CheckerBoard");

        _table.AddChild(checkerBoard);
        checkerBoard.MouseEnabled = true;
        ValidateNumberMouseObjects(2);
        checkerBoard.Rotation = 30;
        checkerBoard.Name     = "Checkerboard";
        checkerBoard.Y        = checkerBoard.Height * .75f;

        var w = checkerBoard.Width;
        var h = checkerBoard.Height;

        var totalCheckers = 0;
        var isRed         = false;

        for (var __x = -3.5f; __x <= 3f; __x += 1f)
        {
            isRed = !isRed;
            for (var __y = -3.5f; __y <= 3.5f; __y += 1f)
            {
                isRed = !isRed;
                var checker = Library.New(isRed ? "RedChecker" : "BlackChecker");
                checker.Width = checker.Height = w / 8;
                checker.Name  = "Checker" + totalCheckers++;
                checkerBoard.AddChild(checker);
                checker.MouseEnabled = true;
                checker.X            = w * __x / 8f;
                checker.Y            = h * __y / 8f;

                checker.AddEventListener <MouseEvent>(MouseEvent.MOUSE_OVER, onAnythingOver);
                checker.AddEventListener <MouseEvent>(MouseEvent.MOUSE_OUT, onAnythingOut);
            }
        }

        _everythingContainer.AddEventListener <MouseEvent>(MouseEvent.MOUSE_DOWN, onAnythingPress);
        _everythingContainer.AddEventListener <MouseEvent>(MouseEvent.RELEASE_OUTSIDE, onAnythingUpOutside);
        AddEventListener <MouseEvent>(MouseEvent.MOUSE_DOWN, onStagePress);
    }
예제 #2
0
    private void TestEventListeners()
    {
        _country = Library.New<CinchSprite>("Country");
        _state = Library.New<CinchSprite>("Stage");
        _city = Library.New<CinchSprite>("City");
        _house = Library.New<CinchSprite>("House");
        _country.Name = "Country";
        _state.Name = "State";
        _city.Name = "City";
        _house.Name = "House";
        _country.MouseEnabled = _state.MouseEnabled = _city.MouseEnabled = _house.MouseEnabled;
        _country.AddChild(_state);
        _state.AddChild(_city);
        _city.AddChild(_house);

        AssertEverybodyWillTrigger(MouseEvent.MOUSE_DOWN, false);
        AssertOnlyCityHasEventListener(MouseEvent.MOUSE_DOWN, false);

        _city.AddEventListener<MouseEvent>(MouseEvent.MOUSE_DOWN, GenericEventHandler);
        _city.AddEventListener<MouseEvent>(MouseEvent.MOUSE_DOWN, GenericEventHandler);
        _city.AddEventListener<MouseEvent>(MouseEvent.MOUSE_DOWN, GenericEventHandler);
        AssertEverybodyWillTrigger(MouseEvent.MOUSE_DOWN, true);
        AssertOnlyCityHasEventListener(MouseEvent.MOUSE_DOWN, true);

        _city.RemoveEventListener<MouseEvent>(MouseEvent.MOUSE_DOWN, GenericEventHandler);
        AssertEverybodyWillTrigger(MouseEvent.MOUSE_DOWN, false);
        AssertOnlyCityHasEventListener(MouseEvent.MOUSE_DOWN, false);

        _eventRecord = new List<String>();
        AssertEventRecordIs("");
        _country.AddEventListener<MouseEvent>(MouseEvent.MOUSE_DOWN, StackRecordingEventHandler, true);
        _state.AddEventListener<MouseEvent>(MouseEvent.MOUSE_DOWN, StackRecordingEventHandler, false);
        _city.AddEventListener<MouseEvent>(MouseEvent.MOUSE_DOWN, StackRecordingEventHandler, true);
        _city.DispatchEvent(new MouseEvent(MouseEvent.MOUSE_DOWN, _city, new Vector2(0, 0), new Vector2(0, 0)));
        AssertEventRecordIs("CAP:Country,AT:City,BUB:State");

        //removed the wrong handler, so should still do all the dispatching
        _country.RemoveEventListener<MouseEvent>(MouseEvent.MOUSE_DOWN, GenericEventHandler);
        //removed the right handler with wrong capture setting, so should still do all the dispatching
        _country.RemoveEventListener<MouseEvent>(MouseEvent.MOUSE_DOWN, StackRecordingEventHandler, false);
        _city.DispatchEvent(new MouseEvent(MouseEvent.MOUSE_DOWN, _city, new Vector2(0, 0), new Vector2(0, 0)));
        AssertEventRecordIs("CAP:Country,AT:City,BUB:State");
        _state.DispatchEvent(new MouseEvent(MouseEvent.MOUSE_DOWN, _city, new Vector2(0, 0), new Vector2(0, 0)));
        AssertEventRecordIs("CAP:Country,AT:State");

        //removed the right handler, so should do no the dispatching
        _country.RemoveEventListener<MouseEvent>(MouseEvent.MOUSE_DOWN, StackRecordingEventHandler, true);
        _city.DispatchEvent(new MouseEvent(MouseEvent.MOUSE_DOWN, _city, new Vector2(0, 0), new Vector2(0, 0)));
        AssertEventRecordIs("AT:City,BUB:State");
        _state.DispatchEvent(new MouseEvent(MouseEvent.MOUSE_DOWN, _city, new Vector2(0, 0), new Vector2(0, 0)));
        AssertEventRecordIs("AT:State");

        //removed the right handler with wrong capture setting, so should still do all the dispatching
        _state.RemoveEventListener<MouseEvent>(MouseEvent.MOUSE_DOWN, StackRecordingEventHandler, true);
        _city.DispatchEvent(new MouseEvent(MouseEvent.MOUSE_DOWN, _city, new Vector2(0, 0), new Vector2(0, 0)));
        AssertEventRecordIs("AT:City,BUB:State");
        _state.DispatchEvent(new MouseEvent(MouseEvent.MOUSE_DOWN, _city, new Vector2(0, 0), new Vector2(0, 0)));
        AssertEventRecordIs("AT:State");

        _state.RemoveEventListener<MouseEvent>(MouseEvent.MOUSE_DOWN, StackRecordingEventHandler);
        _city.DispatchEvent(new MouseEvent(MouseEvent.MOUSE_DOWN, _city, new Vector2(0, 0), new Vector2(0, 0)));
        AssertEventRecordIs("AT:City");
        _state.DispatchEvent(new MouseEvent(MouseEvent.MOUSE_DOWN, _city, new Vector2(0, 0), new Vector2(0, 0)));
        AssertEventRecordIs("");

        Debug.Log("WIN: TestEventListeners");
    }
예제 #3
0
    public override void OnAwake()
    {
        base.OnAwake();

        CinchOptions.UseTopLeftSpriteSheetCoordinates = true;
        CinchOptions.DefaultPixelsPerMeter = 100f;

        this.Name = "ParentingStage";
        AddSymbolDefinitions();

        AddEventListener<MouseEvent>(MouseEvent.MOUSE_DOWN, onStagePress);

        _everythingContainer = Library.New<DisplayObjectContainer>();
        _everythingContainer.Name = "Everything container";
        _everythingContainer.MouseEnabled = false;
        AddChild(_everythingContainer);

        _table = Library.New ("Table");
        _table.MouseEnabled = true;
        ValidateNumberMouseObjects(0);
        _everythingContainer.AddChild(_table);
        ValidateNumberMouseObjects(1);
        _table.Name = "Table";
        _table.Width = ViewportWidth * .8f;
        _table.ScaleY = _table.ScaleX;

        var checkerBoard = Library.New ("CheckerBoard");
        _table.AddChild(checkerBoard);
        checkerBoard.MouseEnabled = true;
        ValidateNumberMouseObjects(2);
        checkerBoard.Rotation = 30;
        checkerBoard.Name = "Checkerboard";
        checkerBoard.Y = checkerBoard.Height * .75f;

        var w = checkerBoard.Width;
        var h = checkerBoard.Height;

        var totalCheckers = 0;
        var isRed = false;
        for (var __x = -3.5f; __x <= 3f; __x += 1f)
        {
            isRed = !isRed;
            for (var __y = -3.5f; __y <= 3.5f; __y += 1f)
            {
                isRed = !isRed;
                var checker = Library.New (isRed ? "RedChecker" : "BlackChecker");
                checker.Width = checker.Height = w/8;
                checker.Name = "Checker" + totalCheckers++;
                checkerBoard.AddChild(checker);
                checker.MouseEnabled = true;
                checker.X = w * __x/8f;
                checker.Y = h * __y/8f;

                checker.AddEventListener<MouseEvent>(MouseEvent.MOUSE_OVER, onAnythingOver);
                checker.AddEventListener<MouseEvent>(MouseEvent.MOUSE_OUT, onAnythingOut);
            }
        }

        _everythingContainer.AddEventListener<MouseEvent>(MouseEvent.MOUSE_DOWN, onAnythingPress);
        _everythingContainer.AddEventListener<MouseEvent>(MouseEvent.RELEASE_OUTSIDE, onAnythingUpOutside);
        AddEventListener<MouseEvent>(MouseEvent.MOUSE_DOWN, onStagePress);
    }
예제 #4
0
    private void TestEventListeners()
    {
        _country              = Library.New <CinchSprite>("Country");
        _state                = Library.New <CinchSprite>("Stage");
        _city                 = Library.New <CinchSprite>("City");
        _house                = Library.New <CinchSprite>("House");
        _country.Name         = "Country";
        _state.Name           = "State";
        _city.Name            = "City";
        _house.Name           = "House";
        _country.MouseEnabled = _state.MouseEnabled = _city.MouseEnabled = _house.MouseEnabled;
        _country.AddChild(_state);
        _state.AddChild(_city);
        _city.AddChild(_house);

        AssertEverybodyWillTrigger(MouseEvent.MOUSE_DOWN, false);
        AssertOnlyCityHasEventListener(MouseEvent.MOUSE_DOWN, false);

        _city.AddEventListener <MouseEvent>(MouseEvent.MOUSE_DOWN, GenericEventHandler);
        _city.AddEventListener <MouseEvent>(MouseEvent.MOUSE_DOWN, GenericEventHandler);
        _city.AddEventListener <MouseEvent>(MouseEvent.MOUSE_DOWN, GenericEventHandler);
        AssertEverybodyWillTrigger(MouseEvent.MOUSE_DOWN, true);
        AssertOnlyCityHasEventListener(MouseEvent.MOUSE_DOWN, true);

        _city.RemoveEventListener <MouseEvent>(MouseEvent.MOUSE_DOWN, GenericEventHandler);
        AssertEverybodyWillTrigger(MouseEvent.MOUSE_DOWN, false);
        AssertOnlyCityHasEventListener(MouseEvent.MOUSE_DOWN, false);

        _eventRecord = new List <String>();
        AssertEventRecordIs("");
        _country.AddEventListener <MouseEvent>(MouseEvent.MOUSE_DOWN, StackRecordingEventHandler, true);
        _state.AddEventListener <MouseEvent>(MouseEvent.MOUSE_DOWN, StackRecordingEventHandler, false);
        _city.AddEventListener <MouseEvent>(MouseEvent.MOUSE_DOWN, StackRecordingEventHandler, true);
        _city.DispatchEvent(new MouseEvent(MouseEvent.MOUSE_DOWN, _city, new Vector2(0, 0), new Vector2(0, 0)));
        AssertEventRecordIs("CAP:Country,AT:City,BUB:State");

        //removed the wrong handler, so should still do all the dispatching
        _country.RemoveEventListener <MouseEvent>(MouseEvent.MOUSE_DOWN, GenericEventHandler);
        //removed the right handler with wrong capture setting, so should still do all the dispatching
        _country.RemoveEventListener <MouseEvent>(MouseEvent.MOUSE_DOWN, StackRecordingEventHandler, false);
        _city.DispatchEvent(new MouseEvent(MouseEvent.MOUSE_DOWN, _city, new Vector2(0, 0), new Vector2(0, 0)));
        AssertEventRecordIs("CAP:Country,AT:City,BUB:State");
        _state.DispatchEvent(new MouseEvent(MouseEvent.MOUSE_DOWN, _city, new Vector2(0, 0), new Vector2(0, 0)));
        AssertEventRecordIs("CAP:Country,AT:State");

        //removed the right handler, so should do no the dispatching
        _country.RemoveEventListener <MouseEvent>(MouseEvent.MOUSE_DOWN, StackRecordingEventHandler, true);
        _city.DispatchEvent(new MouseEvent(MouseEvent.MOUSE_DOWN, _city, new Vector2(0, 0), new Vector2(0, 0)));
        AssertEventRecordIs("AT:City,BUB:State");
        _state.DispatchEvent(new MouseEvent(MouseEvent.MOUSE_DOWN, _city, new Vector2(0, 0), new Vector2(0, 0)));
        AssertEventRecordIs("AT:State");

        //removed the right handler with wrong capture setting, so should still do all the dispatching
        _state.RemoveEventListener <MouseEvent>(MouseEvent.MOUSE_DOWN, StackRecordingEventHandler, true);
        _city.DispatchEvent(new MouseEvent(MouseEvent.MOUSE_DOWN, _city, new Vector2(0, 0), new Vector2(0, 0)));
        AssertEventRecordIs("AT:City,BUB:State");
        _state.DispatchEvent(new MouseEvent(MouseEvent.MOUSE_DOWN, _city, new Vector2(0, 0), new Vector2(0, 0)));
        AssertEventRecordIs("AT:State");

        _state.RemoveEventListener <MouseEvent>(MouseEvent.MOUSE_DOWN, StackRecordingEventHandler);
        _city.DispatchEvent(new MouseEvent(MouseEvent.MOUSE_DOWN, _city, new Vector2(0, 0), new Vector2(0, 0)));
        AssertEventRecordIs("AT:City");
        _state.DispatchEvent(new MouseEvent(MouseEvent.MOUSE_DOWN, _city, new Vector2(0, 0), new Vector2(0, 0)));
        AssertEventRecordIs("");

        Debug.Log("WIN: TestEventListeners");
    }