Ejemplo n.º 1
0
    public void TrySave()
    {
        if (loadoutEditor.GetUnitCount() > 14)
        {
            InfoText.Show("Loadouts may only have 16 Units");
            return;
        }
        if (loadoutEditor.GetLeaderCount() < 1)
        {
            InfoText.Show("Loadouts must contain at least 1 Leader");
            return;
        }
        string loadoutName = loadoutNameInput.text;

        if (fileManager.LoadoutWithNameExistsInFolder(loadoutName, "DefaultLoadouts"))
        {
            InfoText.Show($"Can't use {loadoutName} as a name");
            return;
        }

        if (fileManager.LoadoutWithNameExistsInFolder(loadoutName, "Loadouts"))
        {
            Show();
        }
        else
        {
            loadoutEditor.Save();
        }
    }
Ejemplo n.º 2
0
 public bool PrintIfInvalid()
 {
     if (!valid)
     {
         InfoText.Show(error);
     }
     return(valid);
 }
Ejemplo n.º 3
0
    private void UnitOptionsFlow()
    {
        Field fieldHit;

        // 1) Selecting
        if (fieldHit = ray.FieldWithUnitSelector(MouseAction.Down))    // Button Down
        {
            unitSelected = fieldHit.unit;
            unitValidity = CheckUnitValidity(unitSelected);
            if (unitValidity.Valid)
            {
                HighlightUnits(player, false);
                Invoke("HighlightLegalMoves", 0.0f);
                drag.SetArrowStart(fieldHit);
                OnUnitSelected?.Invoke(unitSelected);
            }
            return;
        }

        // 2) Holding -> Only for Drag animation
        if (fieldHit = ray.Selector <Field>(MouseAction.Held))
        {
            if (unitSelected == null)
            {
                return;
            }
            if (!unitValidity.Valid)
            {
                return;
            }
            drag.SetArrowTarget(fieldHit);
            return;
        }
        else if (Input.GetMouseButton(0))
        {
            drag.Pause();
            return;
        }

        // 3) Releasing
        if (Input.GetMouseButtonUp(0) && unitSelected != null)
        {
            UnhighlightLegalMoves();
        }
        if (fieldHit = ray.Selector <Field>(MouseAction.Up))
        {
            if (fieldHit != null && unitSelected != null)
            {
                Action action = new Action(unitSelected.field, fieldHit);
                if (unitValidity.Valid && IsMoveLegal(unitSelected, fieldHit))
                {
                    // Making the actual Move
                    player.MakeAction(action);
                }
                else if (fieldHit != unitSelected.field)
                {
                    // Error message printing
                    Validity worseValidity = unitValidity.GetIfWorse(action.Move.CheckValidity(board));
                    if (worseValidity.PrintIfInvalid())
                    {
                        InfoText.Show(unitSelected.unitName + " can't move like that");
                    }
                    HighlightUnits(player, true);
                }
                else
                {
                    HighlightUnits(player, true);
                }
            }
        }
        if (Input.GetMouseButtonUp(0))
        {
            drag.Stop();
            OnUnitDeselected?.Invoke(unitSelected);
            unitSelected = null;
            unitValidity = null;
            if (fieldHit == null)
            {
                HighlightUnits(player, true);
            }
        }
    }