Exemplo n.º 1
0
    void ActivateHireUnitButtonsIfNeeded()
    {
        // get city screen
        EditPartyScreen cityScreen = transform.root.GetComponentInChildren <UIManager>().GetComponentInChildren <EditPartyScreen>();

        // verify if we are in city view mode
        if (cityScreen != null)
        {
            // activate hire unit pnl button
            cityScreen.SetHireUnitPnlButtonActive(true);
        }
    }
Exemplo n.º 2
0
    public void OnDrop(PointerEventData eventData)
    {
        // verify if we are in city edit mode and not in hero edit mode
        EditPartyScreen cityScreen = transform.root.GetComponentInChildren <UIManager>().GetComponentInChildren <EditPartyScreen>();

        if (cityScreen != null)
        {
            // activate hire unit buttons again, after it was disabled
            cityScreen.SetHireUnitPnlButtonActive(true);
        }
        // verify if it is item being dragged
        if (InventoryItemDragHandler.itemBeingDragged != null)
        {
            // raise on item drop event (pass this slot as argument)
            itemHasBeenDroppedIntoTheUnitSlotEvent.Raise(this);
            //// verify if there is a unit in the slot
            //if (GetComponentInChildren<PartyUnitUI>() != null)
            //{
            //    // try to apply item to the unit
            //    GetComponentInChildren<PartyUnitUI>().ActOnItemDrop(InventoryItemDragHandler.itemBeingDragged);
            //}
            // reset cursor to normal
            // CursorController.Instance.SetNormalCursor();
        }
        // verify if it is party unit being dragged
        else if (UnitDragHandler.unitBeingDraggedUI != null)
        {
            // raise on unit drop event
            unitUIHasBeenDroppedIntoTheUnitSlotEvent.Raise(this);
            // act based on the previously set by OnDrag condition
            if (isDropAllowed)
            {
                // drop is allowed
                // act based on then draggable unit size
                // get actual unit, structure Cell-UnitCanvas(dragged->Unit link)
                PartyUnit draggedUnit = UnitDragHandler.unitBeingDraggedUI.GetComponent <PartyUnitUI>().LPartyUnit;
                Transform srcCellTr   = UnitDragHandler.unitBeingDraggedUI.transform.parent.parent;
                Transform dstCellTr   = transform.parent;
                if (draggedUnit.UnitSize == UnitSize.Single)
                {
                    // single unit
                    // possible states
                    // src  dst                                 result
                    // 1    free or occupied by single unit     swap single cells
                    // 1    occupied by double                  swap cells in horizontal panels
                    // act based on destination cell size
                    if (UnitSize.Single == cellSize)
                    {
                        // swap single cells
                        SwapTwoCellsContent(srcCellTr, dstCellTr);
                    }
                    else
                    {
                        // swap 2 single cells in src panel with double cell in dest panel
                        SwapSingleWithDouble(srcCellTr, dstCellTr, true);
                    }
                }
                else
                {
                    // double unit
                    if (UnitSize.Single == cellSize)
                    {
                        // swap single with double cells
                        SwapSingleWithDouble(srcCellTr, dstCellTr, false);
                    }
                    else
                    {
                        // swap 2 double cells
                        SwapTwoCellsContent(srcCellTr, dstCellTr);
                    }
                }
                // Instruct focus panels to be updated
                foreach (FocusPanel focusPanel in transform.root.GetComponentInChildren <UIManager>().GetComponentsInChildren <FocusPanel>())
                {
                    focusPanel.OnChange(FocusPanel.ChangeType.UnitsPositionChange);
                }
                //// drop unit if there is no other unit already present
                //if (!unit)
                //{
                //    PartyPanelMode panelMode = UnitDragHandler.unitBeingDragged.transform.parent.parent.parent.parent.GetComponent<PartyPanel>().GetPanelMode();
                //    if (PartyPanelMode.Garnizon == panelMode)
                //    {
                //        // enable hire unit button in the original parent cell and bring it to the front
                //        // and it is not wide
                //        // todo: add not wide condition check
                //    }
                //    // change parent of the dragged unit
                //    Debug.Log("Drop unit from " + UnitDragHandler.unitBeingDraggedParentTr.parent.gameObject.name);
                //    UnitDragHandler.unitBeingDragged.transform.SetParent(transform);
                //    // disable hire unit button in the destination (this) cell, if it is garnizon panel
                //    // structure 3PartyPanel-2Top/Middle/Bottom-1Front/Back/Wide-(this)UnitSlot
                //    panelMode = transform.parent.parent.parent.GetComponent<PartyPanel>().GetPanelMode();
                //    if (PartyPanelMode.Garnizon == panelMode)
                //    {
                //        // todo: add not wide condition check
                //    }
                //    // trigger event
                //    // ExecuteEvents.ExecuteHierarchy<IHasChanged>(gameObject, null, (x, y) => x.HasChanged());
                //}
            }
            else
            {
                // drop is not allowed
                // display error message
                NotificationPopUp.Instance().DisplayMessage(errorMessage);
            }
        }
        else
        {
            Debug.LogWarning("Unknown object is being dragged");
        }
    }