示例#1
0
    // 特定のピースがマッチしている場合、ほかのマッチしたピースとともに削除する
    private void DestroyMatchDrop(Vector2 pos, DropKind kind)
    {
        // ピースの場所が盤面以外だったら何もしない
        if (!IsInBoard(pos))
        {
            return;
        }

        // ピースが無効であったり削除フラグが立っていたりそもそも、種別がちがうならば何もしない
        var drop = board[(int)pos.x, (int)pos.y];

        if (drop == null || drop.deleteFlag || drop.GetKind() != kind)
        {
            return;
        }

        // ピースが同じ種類でもマッチングしてなければ何もしない
        if (!IsMatchDrop(drop))
        {
            return;
        }

        // 削除フラグをたてて、周り4方のピースを判定する
        drop.deleteFlag = true;
        foreach (var dir in directions)
        {
            DestroyMatchDrop(pos + dir, kind);
        }

        // ピースを削除する
        Destroy(drop.gameObject);
    }
示例#2
0
        private static bool IsAllowedDropKind(object sender, DragEventArgs e)
        {
            bool    isAllowedDropKind = false;
            TextBox text = sender as TextBox;

            if (text == null)
            {
                return(isAllowedDropKind);
            }

            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                string[] files = e.Data.GetData(DataFormats.FileDrop) as string[];
                if (files != null && files.Length > 0)
                {
                    string   file = files[0];
                    DropKind kind = GetKind(text);
                    if (kind == DropKind.Directory && Directory.Exists(file))
                    {
                        isAllowedDropKind = true;
                    }
                    else if (kind == DropKind.File && File.Exists(file))
                    {
                        isAllowedDropKind = true;
                    }
                }
            }
            return(isAllowedDropKind);
        }
示例#3
0
        private static void OnDrop(object sender, DragEventArgs e)
        {
            TextBox text = sender as TextBox;

            if (text == null)
            {
                return;
            }

            e.Handled = e.Data.GetDataPresent(DataFormats.FileDrop);
            if (e.Handled)
            {
                string[] files = e.Data.GetData(DataFormats.FileDrop) as string[];
                if (files != null && files.Length > 0)
                {
                    string   file = files[0];
                    DropKind kind = GetKind(text);
                    if (kind == DropKind.Directory && Directory.Exists(file))
                    {
                        text.SetValue(TextBox.TextProperty, file);
                        BindingExpression exp = text.GetBindingExpression(TextBox.TextProperty);
                        if (exp != null)
                        {
                            exp.UpdateSource();
                            ICommand droppedCommand = GetDroppedCommand(text);
                            if (droppedCommand != null && droppedCommand.CanExecute(null))
                            {
                                droppedCommand.Execute(null);
                            }
                        }
                    }
                    else if (kind == DropKind.File && File.Exists(file))
                    {
                        text.SetValue(TextBox.TextProperty, file);
                        // UpdateSourceTrigger が既定値の場合 TextはLostFocus
                        // が発生するまで ソースプロパティが変更されない。
                        // UpdateSourceTrigger を PropertyChangted にするか、
                        // 下例のように強制的に更新
                        BindingExpression exp = text.GetBindingExpression(TextBox.TextProperty);
                        if (exp != null)
                        {
                            exp.UpdateSource();
                            ICommand droppedCommand = GetDroppedCommand(text);
                            if (droppedCommand != null && droppedCommand.CanExecute(null))
                            {
                                droppedCommand.Execute(null);
                            }
                        }
                    }
                    System.Windows.Input.CommandManager.InvalidateRequerySuggested();
                }
            }
        }
示例#4
0
    // 対象の方向に引数で指定したの種類のピースがいくつあるかを返す
    private int GetSameKindDropNum(DropKind kind, Vector2 dropPos, Vector2 searchDir)
    {
        var count = 0;

        while (true)
        {
            dropPos += searchDir;
            if (IsInBoard(dropPos) && board[(int)dropPos.x, (int)dropPos.y].GetKind() == kind)
            {
                count++;
            }
            else
            {
                break;
            }
        }
        return(count);
    }
示例#5
0
 //-------------------------------------------------------
 // Public Function
 //-------------------------------------------------------
 // ピースの種類とそれに応じた色をセットする
 public void SetKind(DropKind dropKind)
 {
     kind = dropKind;
     SetColor();
 }
示例#6
0
        private bool LowerLiftedBuildingHelper(SmartEntity buildingInSelection, DropKind dropKind, bool affectBoard, bool sendLoweredEvent, bool playLoweredSound, bool showContextButtons, string tag)
        {
            this.lifted = false;
            this.moved  = false;
            BuildingTypeVO buildingTypeVO = null;
            int            num            = 0;
            int            num2           = 0;

            if ((this.canOccupy || dropKind != DropKind.JustDrop) && this.prevValidBoardAnchorX.ContainsKey(buildingInSelection) && this.prevValidBoardAnchorZ.ContainsKey(buildingInSelection))
            {
                num  = this.prevValidBoardAnchorX[buildingInSelection];
                num2 = this.prevValidBoardAnchorZ[buildingInSelection];
            }
            else if (this.prevValidBoardAnchorX.ContainsKey(buildingInSelection) && this.prevValidBoardAnchorZ.ContainsKey(buildingInSelection))
            {
                num  = this.prevValidBoardAnchorX[buildingInSelection];
                num2 = this.prevValidBoardAnchorZ[buildingInSelection];
            }
            else if (this.buildingSelector.AdditionalSelectedBuildings.Count == 0)
            {
                if (buildingInSelection != null)
                {
                    Service.Logger.Warn("Something went wrong placing " + buildingInSelection.ToString() + " we should not be hitting this case where prevValidBoardAnchorX and prevValidBoardAnchorZ do not contain buildingInSelection");
                }
                else
                {
                    Service.Logger.Warn("Something went wrong, we should not be hitting this case where prevValidBoardAnchorX and prevValidBoardAnchorZ do not contain buildingInSelection");
                }
            }
            if (affectBoard)
            {
                BoardCell boardCell = this.buildingController.OnLowerLiftedBuilding(buildingInSelection, num, num2, dropKind == DropKind.ConfirmPurchase, ref buildingTypeVO, tag);
                if (boardCell == null)
                {
                    this.buildingSelector.DeselectSelectedBuilding();
                    Service.EventManager.SendEvent(EventId.UserLoweredBuilding, buildingInSelection);
                    this.DestroyBuilding(buildingInSelection);
                    return(false);
                }
                BoardItemComponent boardItemComponent = buildingInSelection.Get <BoardItemComponent>();
                if (boardItemComponent.BoardItem.Filter == CollisionFilters.BUILDING_GHOST)
                {
                    boardItemComponent.BoardItem.Filter = CollisionFilters.BUILDING;
                }
                else if (boardItemComponent.BoardItem.Filter == CollisionFilters.TRAP_GHOST)
                {
                    boardItemComponent.BoardItem.Filter = CollisionFilters.TRAP;
                }
                else if (boardItemComponent.BoardItem.Filter == CollisionFilters.WALL_GHOST)
                {
                    boardItemComponent.BoardItem.Filter = CollisionFilters.WALL;
                }
                else if (boardItemComponent.BoardItem.Filter == CollisionFilters.BLOCKER_GHOST)
                {
                    boardItemComponent.BoardItem.Filter = CollisionFilters.BLOCKER;
                }
                else if (boardItemComponent.BoardItem.Filter == CollisionFilters.PLATFORM_GHOST)
                {
                    boardItemComponent.BoardItem.Filter = CollisionFilters.PLATFORM;
                }
                else
                {
                    Service.Logger.ErrorFormat("LowerLiftedBuilding : Unexpected filter type {0}", new object[]
                    {
                        boardItemComponent.BoardItem.Filter
                    });
                    boardItemComponent.BoardItem.Filter = CollisionFilters.BUILDING;
                }
                num  = boardCell.X;
                num2 = boardCell.Z;
            }
            else
            {
                float x;
                float z;
                EditBaseController.BuildingBoardToWorld(this.buildingSelector.SelectedBuilding, num, num2, out x, out z);
                Vector3 worldGroundPosition = new Vector3(x, 0f, z);
                worldGroundPosition.x += this.buildingSelector.GrabPoint.x;
                worldGroundPosition.z += this.buildingSelector.GrabPoint.z;
                this.MoveLiftedBuilding(this.buildingSelector.SelectedBuilding, worldGroundPosition);
            }
            GameObjectViewComponent gameObjectViewComponent = buildingInSelection.Get <GameObjectViewComponent>();

            if (gameObjectViewComponent != null)
            {
                TransformComponent transformComponent = buildingInSelection.Get <TransformComponent>();
                gameObjectViewComponent.SetXYZ(Units.BoardToWorldX(transformComponent.CenterX()), 0f, Units.BoardToWorldZ(transformComponent.CenterZ()));
            }
            Service.EntityViewManager.SetCollider(buildingInSelection, true);
            if (sendLoweredEvent)
            {
                Service.EventManager.SendEvent(EventId.UserLoweredBuilding, buildingInSelection);
            }
            if (playLoweredSound)
            {
                Service.EventManager.SendEvent(EventId.UserLoweredBuildingAudio, buildingInSelection);
            }
            this.buildingSelector.ApplySelectedEffect(buildingInSelection);
            if (buildingTypeVO != null)
            {
                this.buildingController.StartPurchaseBuilding(buildingTypeVO, -1);
            }
            else if (showContextButtons)
            {
                Service.UXController.HUD.ShowContextButtons(buildingInSelection);
            }
            Service.BuildingTooltipController.EnsureBuildingTooltip(buildingInSelection);
            return(true);
        }
示例#7
0
        private void LowerLiftedBuilding(DropKind dropKind, bool affectBoard, bool sendLoweredEvent, bool playLoweredSound, bool showContextButtons)
        {
            SmartEntity selectedBuilding = this.buildingSelector.SelectedBuilding;

            if (selectedBuilding == null)
            {
                this.lifted = false;
                this.moved  = false;
                return;
            }
            UXController uXController = Service.UXController;

            if (dropKind != DropKind.JustDrop)
            {
                uXController.MiscElementsManager.HideConfirmGroup();
            }
            if (affectBoard && dropKind == DropKind.ConfirmPurchase)
            {
                BuildingTypeVO buildingType  = selectedBuilding.BuildingComp.BuildingType;
                int            credits       = buildingType.Credits;
                int            materials     = buildingType.Materials;
                int            contraband    = buildingType.Contraband;
                string         value         = StringUtils.ToLowerCaseUnderscoreSeperated(buildingType.Type.ToString());
                StringBuilder  stringBuilder = new StringBuilder();
                stringBuilder.Append(value);
                stringBuilder.Append("|");
                stringBuilder.Append(buildingType.BuildingID);
                stringBuilder.Append("|");
                stringBuilder.Append(buildingType.Lvl);
                if (PayMeScreen.ShowIfNotEnoughCurrency(credits, materials, contraband, stringBuilder.ToString(), new OnScreenModalResult(this.OnPayMeForCurrencyResult)))
                {
                    return;
                }
                if (buildingType.Type != BuildingType.DroidHut && PayMeScreen.ShowIfNoFreeDroids(new OnScreenModalResult(this.OnPayMeForDroidResult), null))
                {
                    return;
                }
                if (buildingType.Type == BuildingType.NavigationCenter && buildingType.Lvl == 1)
                {
                    Service.UXController.HUD.InitialNavigationCenterPlanetSelect(selectedBuilding, buildingType, new OnScreenModalResult(this.OnPickPlanetResult));
                    return;
                }
            }
            BuildingTypeVO buildingType2 = selectedBuilding.Get <BuildingComponent>().BuildingType;

            if (buildingType2.Time == 0 && dropKind != DropKind.JustDrop)
            {
                showContextButtons = false;
            }
            if (dropKind != DropKind.JustDrop)
            {
                uXController.HUD.ToggleExitEditModeButton(true);
            }
            this.canOccupy = this.EntireSelectionIsPlaceable();
            if (!this.canOccupy)
            {
                this.LiftSelectedBuilding(selectedBuilding, false, false);
                int i     = 0;
                int count = this.buildingSelector.AdditionalSelectedBuildings.Count;
                while (i < count)
                {
                    this.LiftSelectedBuilding(this.buildingSelector.AdditionalSelectedBuildings[i], false, false);
                    i++;
                }
            }
            bool flag   = !this.LowerLiftedBuildingHelper(selectedBuilding, dropKind, affectBoard, sendLoweredEvent, playLoweredSound, showContextButtons, string.Empty);
            int  j      = 0;
            int  count2 = this.buildingSelector.AdditionalSelectedBuildings.Count;

            while (j < count2)
            {
                this.LowerLiftedBuildingHelper(this.buildingSelector.AdditionalSelectedBuildings[j], dropKind, affectBoard, false, false, false, string.Empty);
                j++;
            }
            if (sendLoweredEvent)
            {
                for (int k = 0; k < this.buildingSelector.AdditionalSelectedBuildings.Count; k++)
                {
                    Service.EventManager.SendEvent(EventId.UserLoweredBuilding, this.buildingSelector.AdditionalSelectedBuildings[k]);
                }
                Service.EventManager.SendEvent(EventId.UserLoweredBuilding, flag ? null : selectedBuilding);
            }
            if (affectBoard && dropKind == DropKind.JustDrop && this.ShouldSaveAfterEveryMove())
            {
                BuildingMultiMoveRequest buildingMultiMoveRequest = new BuildingMultiMoveRequest();
                buildingMultiMoveRequest.PositionMap = new PositionMap();
                Position position = new Position();
                position.X = selectedBuilding.Get <TransformComponent>().X;
                position.Z = selectedBuilding.Get <TransformComponent>().Z;
                buildingMultiMoveRequest.PositionMap.AddPosition(selectedBuilding.Get <BuildingComponent>().BuildingTO.Key, position);
                for (int l = 0; l < this.buildingSelector.AdditionalSelectedBuildings.Count; l++)
                {
                    Entity entity = this.buildingSelector.AdditionalSelectedBuildings[l];
                    position   = new Position();
                    position.X = entity.Get <TransformComponent>().X;
                    position.Z = entity.Get <TransformComponent>().Z;
                    buildingMultiMoveRequest.PositionMap.AddPosition(entity.Get <BuildingComponent>().BuildingTO.Key, position);
                }
                BuildingMultiMoveCommand command = new BuildingMultiMoveCommand(buildingMultiMoveRequest);
                Service.ServerAPI.Sync(command);
            }
            if (dropKind == DropKind.ConfirmPurchase || dropKind == DropKind.CancelPurchase)
            {
                Service.EventManager.SendEvent(EventId.BuildingPurchaseModeEnded, null);
            }
        }
示例#8
0
 public static void SetKind(UIElement element, DropKind value)
 {
     element.SetValue(KindProperty, value);
 }