예제 #1
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");
    }
예제 #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");
    }