All handler classes that wants to register for the events generated by UIView must extend this class It ensures proper binding and unbinding of event listeners and other initialization and cleanup
Inheritance: MonoBehaviour
Exemple #1
0
        public void DisposesEventHandlersWhenAttributeValueChanged()
        {
            // Arrange
            var            renderer         = new TestRenderer();
            var            eventCount       = 0;
            UIEventHandler origEventHandler = args => { eventCount++; };
            var            component        = new EventComponent {
                Handler = origEventHandler
            };
            var componentId = renderer.AssignComponentId(component);

            component.TriggerRender();
            var origEventHandlerId = renderer.Batches.Single()
                                     .ReferenceFrames
                                     .Where(f => f.FrameType == RenderTreeFrameType.Attribute)
                                     .Single(f => f.AttributeEventHandlerId != 0)
                                     .AttributeEventHandlerId;

            // Act/Assert 1: Event handler fires when we trigger it
            Assert.Equal(0, eventCount);
            renderer.DispatchEvent(componentId, origEventHandlerId, args: null);
            Assert.Equal(1, eventCount);

            // Now change the attribute value
            var newEventCount = 0;

            component.Handler = args => { newEventCount++; };
            component.TriggerRender();

            // Act/Assert 2: Can no longer fire the original event, but can fire the new event
            Assert.Throws <ArgumentException>(() =>
            {
                renderer.DispatchEvent(componentId, origEventHandlerId, args: null);
            });
            Assert.Equal(1, eventCount);
            Assert.Equal(0, newEventCount);
            renderer.DispatchEvent(componentId, origEventHandlerId + 1, args: null);
            Assert.Equal(1, newEventCount);
        }
Exemple #2
0
    public void EquipWeapon(Item itemToEquip)
    {
        if (EquippedWeapon != null)
        {
            UnequipWeapon();
        }

        EquippedWeapon = (GameObject)Instantiate(Resources.Load <GameObject>("Weapons/" + itemToEquip.ObjectSlug), playerHand.transform.position, playerHand.transform.rotation);
        equippedWeapon = EquippedWeapon.GetComponent <IWeapon>();
        if (EquippedWeapon.GetComponent <IProjectileWeapon>() != null)
        {
            EquippedWeapon.GetComponent <IProjectileWeapon>().ProjectileSpawn = spawnProjectile;
        }

        EquippedWeapon.transform.SetParent(playerHand.transform);
        equippedWeapon.Stats  = itemToEquip.Stats;
        currentlyEquippedItem = itemToEquip;
        characterStats.AddStatBonus(itemToEquip.Stats);

        UIEventHandler.ItemEquipped(itemToEquip);
        UIEventHandler.StatsChanged();
    }
Exemple #3
0
 public virtual void OnApplicationQuit()
 {
     this.onClick                   = null;
     this.onDown                    = null;
     this.onUp                      = null;
     this.onDownDetail              = null;
     this.onUpDetail                = null;;
     this.onDrag                    = null;
     this.onExit                    = null;
     this.onDrop                    = null;
     this.onSelect                  = null;
     this.onDeSelect                = null;
     this.onMove                    = null;
     this.onBeginDrag               = null;
     this.onEndDrag                 = null;
     this.onEnter                   = null;
     this.onSubmit                  = null;
     this.onScroll                  = null;
     this.onCancel                  = null;
     this.onUpdateSelected          = null;
     this.onInitializePotentialDrag = null;
     this.onEvent                   = null;
 }
Exemple #4
0
        public void ActivateContext(UIEventHandler UIPromptContext_EventTriggered, VALUE[] values, ROW[] rows)
        {
            promptForm.EventTriggered += new UIEventHandler(UIPromptContext_EventTriggered);
            promptForm.SetPromptFocus();
            mainWin.setActiveToolBarKeys(KeyList, onActionList);    //, false);

            if (!_contextIsActive)
            {
                _contextIsActive = true;
            }

            if (promptStyle == "WINDOW")
            {
                promptForm.ShowDialog();
            }
            else
            {
                Control promptPanel;
                promptPanel         = promptForm.GetPromptControls();
                promptPanel.Enabled = true;
                mainWin.ActivatePrompt(UIPromptContext_EventTriggered);
            }
        }
Exemple #5
0
        static int _m_OnDrag(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);


                UIEventHandler gen_to_be_invoked = (UIEventHandler)translator.FastGetCSObj(L, 1);



                {
                    UnityEngine.EventSystems.PointerEventData _eventData = (UnityEngine.EventSystems.PointerEventData)translator.GetObject(L, 2, typeof(UnityEngine.EventSystems.PointerEventData));

                    gen_to_be_invoked.OnDrag(_eventData);



                    return(0);
                }
            } catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }
        }
Exemple #6
0
    public void EquipWeapon(Item itemToEquip)
    {
        if (EquippedWeapon != null)
        {
            InventoryController.Instance.GiveItem(currentlyEquippedWeapon.ObjectSlug);
            characterStats.RemoveStatBonus(EquippedWeapon.GetComponent <IWeapon>().Stats);
            Destroy(playerHand.transform.GetChild(0).gameObject);
        }

        EquippedWeapon = Instantiate(Resources.Load <GameObject>("Weapons/" + itemToEquip.ObjectSlug),
                                     playerHand.transform.position, playerHand.transform.rotation);

        equippedWeapon = EquippedWeapon.GetComponent <IWeapon>();

        //스테프일때
        if (EquippedWeapon.GetComponent <IProjectileWeapon>() != null)
        {
            //무기에 spawnProjectile을 넣어둔다
            EquippedWeapon.GetComponent <IProjectileWeapon>().ProjectileSpawn = spawnProjectile;
        }
        else if (EquippedWeapon.GetComponent <Sword>() != null)
        {
            EquippedWeapon.GetComponent <Sword>().CharacterStats = characterStats;
        }

        EquippedWeapon.transform.SetParent(playerHand.transform);

        equippedWeapon.Stats = itemToEquip.Stats;

        currentlyEquippedWeapon = itemToEquip;

        List <BaseStat> tmpBase = itemToEquip.Stats;

        characterStats.AddStatBonus(tmpBase);

        UIEventHandler.ItemEquipped(itemToEquip);
    }
Exemple #7
0
    public void EquipWeapon(Item itemToEquip)
    {
        Item previousWeaponItem = currentlyEquipedWeaponItem;

        UnequipCurrentWeapon();
        currentlyEquipedWeaponItem = itemToEquip;

        equippedWeapon = (GameObject)Instantiate(
            Resources.Load("Weapons/" + itemToEquip.ObjectSlug),
            playerHand.transform.position,
            playerHand.transform.rotation
            );


        weaponComponent = equippedWeapon.GetComponent <IWeapon>();

        if (equippedWeapon.GetComponent <IProjectileWeapon>() != null)
        {
            equippedWeapon.GetComponent <IProjectileWeapon>().projectileSpawn = spawnProjectile;
        }


        equippedWeapon.GetComponent <IWeapon>().Stats = itemToEquip.Stats;
        equippedWeapon.transform.SetParent(playerHand.transform, false);

        Animator animator = equippedWeapon.GetComponent <Animator>();

        if (animator != null)
        {
            animator.enabled = true;
        }

        characterStats.AddStatBonus(itemToEquip.Stats);

        UIEventHandler.ItemEquipped(currentlyEquipedWeaponItem);
        UIEventHandler.StatsChanged();
    }
Exemple #8
0
    public void RemoveItem(string itemSlug)
    {
        Item item = itemdatabase.GetItem(itemSlug);

        if (playerItems.Contains(item))
        {
            Debug.Log("Removing " + itemSlug + " -----------------------");

            item.ItemCount--;
            Debug.Log(item.ObjectSlug + " Count is : " + item.ItemCount);
            UIEventHandler.ItemAddedToInventoryOrCount(item, true, false);

            if (item.ItemCount == 0)
            {
                playerItems.Remove(item);
                Debug.Log(playerItems.Count + " items in inventory. Removed: " + itemSlug);
                UIEventHandler.ItemAddedToInventoryOrCount(item, false, true);
            }
        }
        else
        {
            Debug.Log("playerItems does not have " + item.ItemName);
        }
    }
Exemple #9
0
 void Update()
 {
     if (numOfUnits == 0)
     {
         ResetPath();
         Destroy(this.gameObject);
     }
     timeToGetWood = timeToGetWood >= 0 ? timeToGetWood : 2f;
     colliders     = Physics.OverlapSphere(transform.position, 1, npcLayer);
     foreach (Collider col in colliders)
     {
         if (this.transform.name == col.GetComponent <Peasant>().target)
         {
             timeToGetWood -= Time.deltaTime;
             if (timeToGetWood <= 0)
             {
                 col.GetComponent <Peasant>().inventory.Add(new Wood());
                 StartCoroutine(col.GetComponent <Peasant>().GetBackHome());
                 numOfUnits--;
                 UIEventHandler.UnitGathered(numOfUnits * 10, transform);
             }
         }
     }
 }
Exemple #10
0
        /// <summary>
        /// Set a event handler to the callback of a  specific  interface implemention
        /// </summary>
        /// <param name="_inputType"></param>
        /// <param name="_handler"></param>
        /// <param name="_params"></param>
        public void SetEventHandler(EnumUIinputType _inputType, UIEventHandler _handler, params object[] _params)
        {
            switch (_inputType)
            {
            case EnumUIinputType.OnClick:
                if (null == onClick)
                {
                    onClick = new UIHandler();
                    onClick.SetUIHandler(_handler, _params);
                }
                break;

            case EnumUIinputType.OnDown:
                if (null == onDown)
                {
                    onDown = new UIHandler();
                    onDown.SetUIHandler(_handler, _params);
                }
                break;

            case EnumUIinputType.OnUp:
                if (null == onUp)
                {
                    onUp = new UIHandler();
                    onUp.SetUIHandler(_handler, _params);
                }
                break;

            case EnumUIinputType.OnEnter:
                if (null == onEnter)
                {
                    onEnter = new UIHandler();
                    onEnter.SetUIHandler(_handler, _params);
                }
                break;

            case EnumUIinputType.OnExit:
                if (null == onExit)
                {
                    onExit = new UIHandler();
                    onExit.SetUIHandler(_handler, _params);
                }
                break;

            case EnumUIinputType.OnSelect:
                if (null == onSelect)
                {
                    onSelect = new UIHandler();
                    onSelect.SetUIHandler(_handler, _params);
                }
                break;

            case EnumUIinputType.OnUpdateSelect:
                if (null == onUpdateSelect)
                {
                    onUpdateSelect = new UIHandler();
                    onUpdateSelect.SetUIHandler(_handler, _params);
                }
                break;

            case EnumUIinputType.OnDeselect:
                if (null == onDeSelect)
                {
                    onDeSelect = new UIHandler();
                    onDeSelect.SetUIHandler(_handler, _params);
                }
                break;

            case EnumUIinputType.OnDrag:
                if (null == onDrag)
                {
                    onDrag = new UIHandler();
                    onDrag.SetUIHandler(_handler, _params);
                }
                break;

            case EnumUIinputType.OnEndDrag:
                if (null == onEndDrag)
                {
                    onEndDrag = new UIHandler();
                    onEndDrag.SetUIHandler(_handler, _params);
                }
                break;

            case EnumUIinputType.OnDrop:
                if (null == onDrop)
                {
                    onDrop = new UIHandler();
                    onDrop.SetUIHandler(_handler, _params);
                }
                break;

            case EnumUIinputType.OnScroll:
                if (null == onScroll)
                {
                    onScroll = new UIHandler();
                    onScroll.SetUIHandler(_handler, _params);
                }
                break;

            case EnumUIinputType.OnMove:
                if (null == onMove)
                {
                    onMove = new UIHandler();
                    onMove.SetUIHandler(_handler, _params);
                }
                break;
            }
        }
 // Use this for initialization
 void Awake()
 {
     Ins = this;
 }
Exemple #12
0
 void Start()
 {
     UIEventHandler.PlayerSkillsChanged(this);
 }
 internal static RenderTreeFrame Attribute(int sequence, string name, UIEventHandler value)
 => new RenderTreeFrame(sequence, attributeName: name, attributeValue: value);
 public void RemoveItem(Item item)
 {
     playerWeaponController.UnequipCurrentWeaponIfMatches(item);
     playerItems.Remove(item);
     UIEventHandler.ItemRemovedFromInventory(item);
 }
Exemple #15
0
 void PickUpCash()
 {
     UIEventHandler.MoneyAdded(cashAmount);
     //EventNotifier.Instance.MakeEventNotifier(string.Format("Obtained: {0} Cash", cashAmount));
     Destroy(gameObject);
 }
Exemple #16
0
 public void GetInventory()
 {
     UIEventHandler.InventoryUpdated(materials);
 }
Exemple #17
0
    void Update()
    {
        Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hitInfo;

        if (Input.GetMouseButtonDown(0) && !blockChosen)
        {
            if (Physics.Raycast(ray, out hitInfo, Mathf.Infinity))
            {
                if (hitInfo.collider.tag != "Ground" && hitInfo.collider.tag != "NPC")
                {
                    UIEventHandler.BuildingSelect(hitInfo.collider.transform);
                }
            }
        }

        if (Input.GetMouseButtonDown(1))
        {
            UIEventHandler.BuildingDeselect();
        }

        if (Input.GetKeyDown(KeyCode.Alpha1))
        {
            toPlace = cube;
            placementSize.SetSize(cube.transform.localScale);
            ToggleBlockChosen();
            TogglePlaceObjectSize();
        }
        else if (Input.GetKeyDown(KeyCode.Alpha2))
        {
            toPlace = sphere;
            placementSize.SetSize(sphere.transform.localScale);
            ToggleBlockChosen();
            TogglePlaceObjectSize();
        }
        else if (Input.GetKeyDown(KeyCode.Alpha3))
        {
            toPlace = cylinder;
            placementSize.SetSize(cylinder.transform.localScale);
            ToggleBlockChosen();
            TogglePlaceObjectSize();
        }
        else if (Input.GetKeyDown(KeyCode.Alpha4))
        {
            toPlace = peasant;
            placementSize.SetSize(new Vector3(1, 1, 1));
            ToggleBlockChosen();
            TogglePlaceObjectSize();
        }
        else if (Input.GetKeyDown(KeyCode.Alpha5))
        {
            toPlace = road;
            placementSize.SetSize(road.transform.localScale);
            ToggleBlockChosen();
            TogglePlaceObjectSize();
        }
        if (Input.GetMouseButtonDown(0) && blockChosen)
        {
            PlaceUnit(toPlace);
        }
    }
Exemple #18
0
 public UIHandler(UIEventHandler _handler, params object[] _params)
 {
     SetUIHandler(_handler, _params);
 }
        public void ActivateContext(UIEventHandler UIDisplayArrayContext_EventTriggered, VALUE[] values, ROW[] rows)
        {
            //mainWin.SetContext(FGLContextType.ContextNone);
            mainWin.SetContext(FGLContextType.ContextDisplayArray, activeFields, this, KeyList, onActionList, UIDisplayArrayContext_EventTriggered);

            foreach (ON_ACTION_EVENT e in onActionList)
            {
                foreach (FGLFoundField ffield in mainWin.FindAction(e.ACTION))
                {
                    ffield.fglField.onActionID  = e.ID;
                    ffield.fglField.onUIEvent   = onActionTriggered;
                    ffield.fglField.Enabled     = true;
                    ffield.fglField.ContextType = FGLContextType.ContextDisplayArray;
                }
            }

            mainWin.setActiveToolBarKeys(KeyList, onActionList); //, true,true,false);
            if (nextMove == MoveType.MoveTypeNoPendingMovement)
            {
                setFocusToCurrentRow();
            }

            if (nextMove != MoveType.MoveTypeNoPendingMovement)
            {
                // Theres a pending movement...
                switch (nextMove)
                {
                case MoveType.MoveTypeUp:
                    moveUp();
                    if (beforeRow != null)
                    {
                        this.EventTriggered(null, beforeRow.ID, "<TRIGGERED ID=\"" + beforeRow.ID + "\" ARRLINE=\"" + this.arrLine + "\" SCRLINE=\"" + this.scrLine + "\"></TRIGGERED>", this);
                    }
                    nextMove = MoveType.MoveTypeNoPendingMovement;
                    break;

                case MoveType.MoveTypePageUp:
                    movePgUp();
                    if (beforeRow != null)
                    {
                        this.EventTriggered(null, beforeRow.ID, "<TRIGGERED ID=\"" + beforeRow.ID + "\" ARRLINE=\"" + this.arrLine + "\" SCRLINE=\"" + this.scrLine + "\"></TRIGGERED>", this);
                    }
                    nextMove = MoveType.MoveTypeNoPendingMovement;
                    break;

                case MoveType.MoveTypePageDown:
                    movePgDown();
                    if (beforeRow != null)
                    {
                        this.EventTriggered(null, beforeRow.ID, "<TRIGGERED ID=\"" + beforeRow.ID + "\" ARRLINE=\"" + this.arrLine + "\" SCRLINE=\"" + this.scrLine + "\"></TRIGGERED>", this);
                    }
                    nextMove = MoveType.MoveTypeNoPendingMovement;
                    break;

                case MoveType.MoveTypeDown:
                    moveDown();
                    if (beforeRow != null)
                    {
                        this.EventTriggered(null, beforeRow.ID, "<TRIGGERED ID=\"" + beforeRow.ID + "\" ARRLINE=\"" + this.arrLine + "\" SCRLINE=\"" + this.scrLine + "\"></TRIGGERED>", this);
                    }
                    nextMove = MoveType.MoveTypeNoPendingMovement;
                    break;
                }
            }
            redisplay_arr(true);

            this.EventTriggered = UIDisplayArrayContext_EventTriggered;

            if (finishing)
            {
                finishing = false;
                // ACCEPT was pressed and there was an AFTER DISPLAY processed..
                this.EventTriggered(null, "ACCEPT", "<TRIGGERED ID=\"ACCEPT\" ARRLINE=\"" + this.arrLine + "\" SCRLINE=\"" + this.scrLine + "\"></TRIGGERED>", this);
                return;
            }
            if (!_contextIsActive)
            {
                _contextIsActive = true;
            }
        }
Exemple #20
0
 /// <summary>
 /// You can set a handler for the implements of the UnityEngile.System and transfer some params
 /// </summary>
 /// <param name="_handler"></param>
 /// <param name="_params"></param>
 public void SetUIHandler(UIEventHandler _handler, params object[] _params)
 {
     ClearHandler();
     this.eventHandler += _handler;
     this.handlerparams = _params;
 }
Exemple #21
0
 public void StatsUpdate()
 {
     Stats.UpdateStats(PlayerLevel.Level);
     UIEventHandler.HealthChanged();
     UIEventHandler.ManaChanged();
 }
 public void GiveItem(Item item)
 {
     playerItems.Add(item);
     UIEventHandler.ItemAddedToInventory(item);
 }
Exemple #23
0
 public void HealFullMP()
 {
     CurrentMana = Stats.MaxMana;
     UIEventHandler.ManaChanged();
 }
 private void AddItemToInventory(Item item)
 {
     playerItems.Add(item);
     UIEventHandler.ItemAddedToInventory(item);
 }
 // Use this for initialization
 void Awake()
 {
     Ins = this;
 }
Exemple #26
0
 public override void Die()
 {
     Debug.Log("Player dead. reset health");
     Stats.CurrentHealth = Stats.MaxHealth;
     UIEventHandler.HealthChanged();
 }
 public void ConsumeItem(Item itemToConsume)
 {
     consumableController.consumeItem(itemToConsume);
     playerItems.Remove(itemToConsume);
     UIEventHandler.ItemRemovedFromInventory(itemToConsume);
 }
Exemple #28
0
 public void HealFullHP()
 {
     Stats.CurrentHealth = Stats.MaxHealth;
     UIEventHandler.HealthChanged();
 }
Exemple #29
0
 public void NotifyStatsChanged()
 {
     UIEventHandler.StatsChanged();
 }
Exemple #30
0
 private void Die()
 {
     Debug.Log("Player Dead. Reset Health.");
     this.currentHealth = this.maxHealth;
     UIEventHandler.HealthChanged(this.currentHealth, this.maxHealth);
 }
Exemple #31
0
 public override void NotifyHealthChanged()
 {
     UIEventHandler.PlayerHealthChanged(health.CurrentHealth, health.MaxHealth);
 }