/// <summary> LocationDisambiguator implementation </summary>
 public bool isSelectable(Location loc)
 {
     // align to platforms or the ground
     if (anchor != UNPLACED)
     {
         // must be the same height with the anchor
         return(loc.z == anchor.z);
     }
     else
     {
         return(ThinPlatform.get(loc) != null || GroundDisambiguator.theInstance.isSelectable(loc));
     }
 }
Exemple #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="view"></param>
        /// <param name="loc"></param>
        /// <param name="ab"></param>
        public override void OnClick(MapViewWindow view, Location loc, Point ab)
        {
            switch (currentMode)
            {
            case Mode.Station:
                if (isPlacing)
                {
                    if (!selectedStation.CanBeBuilt(loc, ControlMode.Player))
                    {
                        MessageBox.Show(Translation.GetString("CONSTRUCTION_CANNOT_BUILD"));
                    }
                    else
                    {
                        selectedStation.Create(loc, true);
                    }
                }
                else
                {
                    Station s = Station.get(loc);
                    if (s != null)
                    {
                        s.remove();
                    }
                }
                return;

            case Mode.FatPlatform:
                if (isPlacing)
                {
                    if (!FatPlatform.canBeBuilt(loc, direction, length))
                    {
                        MessageBox.Show(Translation.GetString("CONSTRUCTION_CANNOT_BUILD"));
                        return;
                    }
                    new FatPlatform(loc, direction, length);
                }
                else
                {
                    Platform p = Platform.get(loc);
                    if (p != null)
                    {
                        if (p.canRemove)
                        {
                            p.remove();
                        }
                        else
                        {
                            MessageBox.Show(Translation.GetString("CONSTRUCTION_CANNOT_REMOVE"));
                        }
                    }
                }
                return;

            case Mode.ThinPlatform:
                if (isPlacing)
                {
                    if (!ThinPlatform.canBeBuilt(loc, direction, length))
                    {
                        MessageBox.Show(Translation.GetString("CONSTRUCTION_CANNOT_BUILD"));
                        return;
                    }
                    new ThinPlatform(loc, direction, length);
                }
                else
                {
                    Platform p = Platform.get(loc);
                    if (p != null)
                    {
                        if (p.canRemove)
                        {
                            p.remove();
                        }
                        else
                        {
                            MessageBox.Show(Translation.GetString("CONSTRUCTION_CANNOT_REMOVE"));
                        }
                    }
                }
                return;
            }
        }
Exemple #3
0
        /// <summary>
        /// Re-builds an alpha-blending preview.
        /// </summary>
        private void updateAlphaSprites()
        {
            if (direction == null)
            {
                return;                         // during the initialization, this method can be called in a wrong timing.
            }
            if (alphaSprites != null)
            {
                alphaSprites.Dispose();
            }


            ISprite[, ,] alphas = null;

            switch (this.currentMode)
            {
            case Mode.Station:
                // builds a new alpha blended preview
                alphas = selectedStation.Sprites;
                break;

            case Mode.ThinPlatform:
                ISprite spr = ThinPlatform.getSprite(direction, false);

                // build sprite set
                // TODO: use the correct sprite
                if (direction == Direction.NORTH || direction == Direction.SOUTH)
                {
                    alphas = new ISprite[1, length, 1];
                    for (int i = 0; i < length; i++)
                    {
                        alphas[0, i, 0] = spr;
                    }
                }
                else
                {
                    alphas = new ISprite[length, 1, 1];
                    for (int i = 0; i < length; i++)
                    {
                        alphas[i, 0, 0] = spr;
                    }
                }

                alphaSprites = new AlphaBlendSpriteSet(alphas);
                break;

            case Mode.FatPlatform:
                RailPattern rp = this.railPattern;


                // build sprite set
                if (direction == Direction.NORTH || direction == Direction.SOUTH)
                {
                    alphas = new ISprite[2, length, 1];
                    int j = direction == Direction.SOUTH ? 1 : 0;
                    for (int i = 0; i < length; i++)
                    {
                        alphas[j, i, 0]     = FatPlatform.getSprite(direction);
                        alphas[j ^ 1, i, 0] = railPattern;
                    }
                }
                else
                {
                    alphas = new ISprite[length, 2, 1];
                    int j = direction == Direction.WEST ? 1 : 0;
                    for (int i = 0; i < length; i++)
                    {
                        alphas[i, j, 0]     = FatPlatform.getSprite(direction);
                        alphas[i, j ^ 1, 0] = railPattern;
                    }
                }
                break;
            }

            alphaSprites = new AlphaBlendSpriteSet(alphas);
            WorldDefinition.World.OnAllVoxelUpdated();  // completely redraw the window
        }
        public override void onClick(MapViewWindow view, Location loc, Point ab)
        {
            switch (currentMode)
            {
            case Mode.Station:
                if (isPlacing)
                {
                    if (!selectedStation.canBeBuilt(loc, ControlMode.player))
                    {
                        MainWindow.showError("Can not build");
                        //! MainWindow.showError("設置できません");
                    }
                    else
                    {
                        selectedStation.create(loc, true);
                    }
                }
                else
                {
                    Station s = Station.get(loc);
                    if (s != null)
                    {
                        s.remove();
                    }
                }
                return;

            case Mode.FatPlatform:
                if (isPlacing)
                {
                    if (!FatPlatform.canBeBuilt(loc, direction, length))
                    {
                        MainWindow.showError("Can not build");
                        //! MainWindow.showError("設置できません");
                        return;
                    }
                    new FatPlatform(loc, direction, length);
                }
                else
                {
                    Platform p = Platform.get(loc);
                    if (p != null)
                    {
                        if (p.canRemove)
                        {
                            p.remove();
                        }
                        else
                        {
                            MainWindow.showError("Can not remove");
                        }
                        //! MainWindow.showError("撤去できません");
                    }
                }
                return;

            case Mode.ThinPlatform:
                if (isPlacing)
                {
                    if (!ThinPlatform.canBeBuilt(loc, direction, length))
                    {
                        MainWindow.showError("Can not build");
                        //! MainWindow.showError("設置できません");
                        return;
                    }
                    new ThinPlatform(loc, direction, length);
                }
                else
                {
                    Platform p = Platform.get(loc);
                    if (p != null)
                    {
                        if (p.canRemove)
                        {
                            p.remove();
                        }
                        else
                        {
                            MainWindow.showError("Can not remove");
                        }
                        //! MainWindow.showError("撤去できません");
                    }
                }
                return;
            }
        }