Example #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);
        }
    }
Example #2
0
    public void DimissUnit(UnitSlot unitSlot)
    {
        Debug.Log("Dismiss unit");
        PartyUnit unit      = unitSlot.GetComponentInChildren <PartyUnitUI>().LPartyUnit;
        bool      wasLeader = unit.IsLeader;

        if (wasLeader)
        {
            DismissPartyLeader(unitSlot);
        }
        else
        {
            DismissGenericUnit(unitSlot);
        }
        // disable dismiss mode and return to normal mode
        //ReturnToNomalState();
    }
Example #3
0
    // context is destination unit slot
    public void OnUnitSlotLeftClickEvent(System.Object context)
    {
        // verify if context is correct
        if (context is UnitSlot)
        {
            // init unit slot from context
            UnitSlot unitSlot = (UnitSlot)context;
            Debug.Log("UnitSlot ActOnClick in City");
            // Get city state
            EditPartyScreenActiveState cityState = EditPartyScreenActiveState;
            // Verify if city state is not normal
            if (EditPartyScreenActiveState.Normal != cityState)
            {
                DeactivateActiveToggle();
            }
            // Get party unit UI in this slot
            PartyUnitUI unitUI = unitSlot.GetComponentInChildren <PartyUnitUI>();
            // Verify if unit is found
            if (unitUI)
            {
                // act based on the city (and cursor) state
                switch (cityState)
                {
                case EditPartyScreenActiveState.Normal:
                    // do nothing for now
                    break;

                case EditPartyScreenActiveState.ActiveDismiss:
                    // cache unit slot to dismiss (it is used in OnDismissYesConfirmation())
                    unitSlotToDismissCache = unitSlot;
                    // try to dismiss unit, if it is possible
                    TryToDismissUnit(unitUI.LPartyUnit);
                    break;

                case EditPartyScreenActiveState.ActiveHeal:
                    // try to heal unit, if it is possible
                    Debug.Log("Show Heal Unit confirmation box");
                    break;

                case EditPartyScreenActiveState.ActiveResurect:
                    // try to resurect unit, if it is possible
                    Debug.Log("Show Resurect Unit confirmation box");
                    break;

                case EditPartyScreenActiveState.ActiveUnitDrag:
                    // ??
                    break;

                case EditPartyScreenActiveState.ActiveItemDrag:
                    // this should not be triggered here, because it should be triggered in the unit slot drop handler when item is being dropped in it
                    Debug.LogWarning("Unpredicted condition");
                    break;

                default:
                    Debug.LogError("Unknown state");
                    break;
                }
            }
            else
            {
                Debug.LogWarning("Unit no found");
            }
            // Verify if city state is not normal
            if (EditPartyScreenActiveState.Normal != cityState)
            {
                // disable previous city state
                SetActiveState(cityState, false);
            }
        }
    }