Ejemplo n.º 1
0
    public void DismissGenericUnit(UnitSlot unitSlot)
    {
        // get PartyUnit UI
        PartyUnitUI unitUI = unitSlot.GetComponentInChildren <PartyUnitUI>();
        // get PartyUnit
        PartyUnit partyUnit = unitUI.LPartyUnit;
        // Get Unit size, because unit is going to be destroyed
        UnitSize unitSize = partyUnit.UnitSize;
        // Get Party Unit HeroParty
        //HeroParty heroParty = partyUnit.GetComponentInParent<HeroParty>();
        // 1 get all required variables, before removing unit
        Transform  unitCell   = unitSlot.transform.parent;
        PartyPanel partyPanel = GetUnitsParentPartyPanel(unitCell);

        // 2 and put it to recycle bin, because otherwise PartyPanel.GetNumberOfPresentUnits() will return wrong number of units, because object is actually destroyed after Update()
        // unitUI.transform.SetParent(transform.root.GetComponentInChildren<RecycleBin>().transform);
        // 3 destory unit canvas, where it is linked to
        // Destroy(unitUI.gameObject);
        // 4 and put it to recycle bin, because otherwise city.GetNumberOfPresentUnits() will return wrong number of units, because object is actually destroyed after Update()
        // partyUnit.transform.SetParent(transform.root.GetComponentInChildren<RecycleBin>().transform);
        // 5 and destory party unit itself
        // Destroy(partyUnit.gameObject);
        RecycleBin.Recycle(unitUI.gameObject);
        RecycleBin.Recycle(partyUnit.gameObject);
        // Update party panel
        // act based on the unit size
        if (unitSize == UnitSize.Single)
        {
            partyPanel.OnChange(PartyPanel.ChangeType.DismissSingleUnit, unitCell);
        }
        else
        {
            partyPanel.OnChange(PartyPanel.ChangeType.DismissDoubleUnit, unitCell);
        }
        // if parent Party panel is in Garnizon state, then update focus panel
        if (PartyMode.Garnizon == partyPanel.PartyMode)
        {
            // Instruct focus panel linked to a city to update information
            // act based on the unit size
            if (unitSize == UnitSize.Single)
            {
                GetComponentInParent <UIManager>().GetFocusPanelByCity(LCity).OnChange(FocusPanel.ChangeType.DismissSingleUnit);
            }
            else
            {
                GetComponentInParent <UIManager>().GetFocusPanelByCity(LCity).OnChange(FocusPanel.ChangeType.DismissDoubleUnit);
            }
            // Activate hire unit buttons again
            SetHireUnitPnlButtonActive(true);
        }
    }
    IEnumerator RemoveThisStatusIcon()
    {
        // hide symbol and duration left text
        yield return(FadeOutTexts(new Text[] { symbolText, durationLeftText }, config.onDisableFadeOutTextDuration));

        // wait while animation has not finished
        while (!animationHasFinished)
        {
            // skip to the next frame
            yield return(null);
        }
        // remove this status icon
        RecycleBin.Recycle(this.gameObject);
    }
Ejemplo n.º 3
0
    public void RemoveAllEmptySlots()
    {
        // get all children 1 level below the parent
        Transform[] children = new Transform[inventoryItemsGrid.transform.childCount];
        int         i        = 0;

        foreach (Transform tempTransform in inventoryItemsGrid.transform)
        {
            children[i] = tempTransform;
            i++;
        }
        // loop through all objects in reverse order
        for (int j = children.Length - 1; j >= 0; j--)
        {
            // verify if slot is empty
            if (children[j].GetComponentInChildren <InventoryItemDragHandler>() == null)
            {
                // Remove slot
                RecycleBin.Recycle(children[j].gameObject);
            }
        }
        //// loop through all slots in this inventory
        //foreach (InventorySlotDropHandler slot in GetComponentsInChildren<InventorySlotDropHandler>())
        //{
        //    // verify if slot is empty
        //    if (slot.GetComponentInChildren<InventoryItemDragHandler>() == null)
        //    {
        //        // Remove slot
        //        Destroy(slot.gameObject);
        //    }
        //}
        //// loop through all slots in this inventory
        //foreach (EquipmentSlotDropHandler slot in GetComponentsInChildren<EquipmentSlotDropHandler>())
        //{
        //    // verify if slot is empty
        //    if (slot.GetComponentInChildren<InventoryItemDragHandler>() == null)
        //    {
        //        // Remove slot
        //        Destroy(slot.gameObject);
        //    }
        //}
    }
Ejemplo n.º 4
0
    public void ReorganizeInventoryUI()
    {
        Debug.LogWarning("ReorganizeInventoryUI");
        // init empty slots list
        List <Transform> emptySlots = new List <Transform>();
        // init number of occupied slots
        int occupiedSlotsCount = 0;

        // loop through all slots in a grid
        foreach (Transform child in inventoryItemsGrid)
        {
            // verify if slot is empty
            if (child.GetComponentInChildren <InventoryItemDragHandler>() == null)
            {
                //// verify if this is not the parent of the item being dragged
                //// because this slot is unofficially still occupied (if we remove it, then exchange between other slot may not happen successfully)
                //Debug.LogWarning("child: " + child.gameObject.name + "[" + child.gameObject.GetInstanceID() + "]" + ", original parent: " + InventoryItemDragHandler.itemBeingDragged.ItemBeindDraggedSlot.gameObject.name + "[" + InventoryItemDragHandler.itemBeingDragged.ItemBeindDraggedSlot.gameObject.GetInstanceID() + "]");
                //if (InventoryItemDragHandler.itemBeingDragged.ItemBeindDraggedSlot.gameObject.GetInstanceID() != child.gameObject.GetInstanceID())
                //{
                //    // add new slot to the list of empty slots
                //    emptySlots.Add(child);
                //}
                //else
                //{
                //    // increment number of occupied slots
                //    occupiedSlotsCount += 1;
                //}
                // add new slot to the list of empty slots
                emptySlots.Add(child);
            }
            else
            {
                // increment number of occupied slots
                occupiedSlotsCount += 1;
            }
        }
        // get total number of slots
        int totalSlots = occupiedSlotsCount + emptySlots.Count;

        // verify if total number of slots is less than minimum
        if (totalSlots < minNumberOfSlots)
        {
            // add missing slots
            // get number of empty item slots
            int emptySlotsCountToAdd = minNumberOfSlots - totalSlots;
            // create an empty slot for each empty slot
            for (int i = 0; i < emptySlotsCountToAdd; i++)
            {
                // create slot in items list
                Debug.Log("Add new empty slot");
                AddSlot();
            }
        }
        // verify if total slots count is higher than min
        else if (totalSlots > minNumberOfSlots)
        {
            int emptySlotsCountToRemove = totalSlots - minNumberOfSlots;
            // verify if emptySlotsCountToRemove is higher than total number of empty slots
            if (emptySlotsCountToRemove > emptySlots.Count)
            {
                // reset emptySlotsCountToRemove to current number of empty slots
                emptySlotsCountToRemove = emptySlots.Count;
            }
            // Loop through empty slots in reverse order (so the strcture of List is not affected)
            // start from the emptySlotsCountToRemove
            for (int i = emptySlotsCountToRemove - 1; i >= 0; i--)
            {
                // remove extra empty slot
                Debug.Log("Remove extra empty slot");
                RecycleBin.Recycle(emptySlots[i].gameObject);
                emptySlots.RemoveAt(i);
            }
        }
        // verify if there is at least one occupied slot
        if (occupiedSlotsCount >= 1)
        {
            // move empty slots down
            foreach (Transform emptySlotTransform in emptySlots)
            {
                emptySlotTransform.SetAsLastSibling();
            }
        }
    }