示例#1
0
 protected TileToolBase(Application application, Tileset Tileset, TileSelection selection)
 {
     this.application = application;
     this.Tileset = Tileset;
     this.selection = selection;
     selection.Changed += OnSelectionChanged;
 }
示例#2
0
        public EditCopyCommand(Layer layer, TileSelection tileSelection)
        {
            m_layer = layer;
            m_tileSelection = tileSelection;

            m_description = "Copy selection from layer \"" + m_layer.Id + "\"";
        }
    public TileListWidget(Application application, TileSelection selection, Adjustment adjv)
    {
        this.selection = selection;
        selection.Changed += OnSelectionChanged;
        this.application = application;

        Tileset.LoadEditorImages = true;
        SetSizeRequest((TILE_WIDTH + SPACING_X) * TILES_PER_ROW, -1);

        ButtonPressEvent += OnButtonPress;
        ButtonReleaseEvent += OnButtonRelease;
        MotionNotifyEvent += OnMotionNotify;
        ScrollEvent += OnScroll;

        AddEvents((int) Gdk.EventMask.ButtonPressMask);
        AddEvents((int) Gdk.EventMask.ButtonReleaseMask);
        AddEvents((int) Gdk.EventMask.PointerMotionMask);
        AddEvents((int) Gdk.EventMask.ScrollMask);

        SizeAllocated += OnSizeAllocated;
        application.LevelChanged += OnLevelChanged;

        vadjustment = adjv;
        vadjustment.ValueChanged += OnVAdjustmentChangedValue;
    }
示例#4
0
        public EditCutCommand(Layer layer, TileSelection tileSelection)
        {
            m_layer = layer;
            m_selectionLocation = tileSelection.Bounds.Location;
            m_tileSelection = tileSelection;
            m_oldTiles = null;

            m_description = "Cut selection from layer \"" + m_layer.Id + "\"";
        }
示例#5
0
        public EditDeleteCommand(Layer layer, TileSelection tileSelection)
        {
            m_layer = layer;
            m_selectionLocation = tileSelection.Bounds.Location;
            m_tileSelection = tileSelection;
            m_tileBrush = null;

            m_description = "Erase selection from layer \"" + m_layer.Id + "\"";
        }
示例#6
0
        public override void Do()
        {
            TileSelection tileSelection = new TileSelection();
            m_tileBrush.GenerateSelection(m_brushLocation, tileSelection);
            m_oldTiles = new TileBrush(m_layer, tileSelection);

            m_tileBrush.ApplyTo(m_layer, m_brushLocation, m_tileSelection);
            if (!m_fromClipboard)
                m_tileSelection.Clear();
        }
示例#7
0
        public ToolsSelectCommand(Layer layer,
            TileSelection currentTileSelection, TileSelection newTileSelection,
            bool replace)
        {
            m_layer = layer;
            m_currentTileSelection = currentTileSelection;
            m_oldTileSelection = new TileSelection(currentTileSelection);
            m_newTileSelection = new TileSelection(newTileSelection);
            m_replace = replace;

            if (m_replace)
                m_description = newTileSelection.IsEmpty() ? "Clear selection" : "Select tiles";
            else
                m_description = "Select more tiles";
        }
示例#8
0
        public EditPasteCommand(Layer layer,
            TileBrush tileBrush, Location brushLocation,
            TileSelection tileSelection, bool fromClipboard)
        {
            m_layer = layer;
            m_tileBrush = tileBrush;
            m_brushLocation = brushLocation;
            m_tileSelection = tileSelection;
            m_fromClipboard = fromClipboard;
            m_oldTiles = null;

            m_description = fromClipboard
                ? "Paste copied tiles" : "Paste tile brush \"" + tileBrush.Id + "\"";
            m_description += " at " + m_brushLocation + " in layer \"" + m_layer.Id + "\"";
        }
        public EditChangeSelectionCommand(Layer layer,
            TileSelection currentTileSelection,
            ChangeSelectionType changeSelectionType)
        {
            m_layer = layer;
            m_currentTileSelection = currentTileSelection;
            m_oldTileSelection = new TileSelection(currentTileSelection);
            m_changeSelectionType = changeSelectionType;

            switch (m_changeSelectionType)
            {
                case ChangeSelectionType.SelectAll:
                    m_description = "Select all tiles";
                    break;
                case ChangeSelectionType.Clear:
                    m_description = "Clear tile selection";
                    break;
                case ChangeSelectionType.Invert:
                    m_description = "Invert tile selection";
                    break;
            }
        }
示例#10
0
        internal TileBrush(string id, Layer layer, TileSelection tileSelection)
        {
            m_id = id;
            xTile.Dimensions.Rectangle selectionBounds = tileSelection.Bounds;

            m_brushSize = selectionBounds.Size;
            m_tileSize = layer.TileSize;
            m_displaySize = new xTile.Dimensions.Size(
                m_brushSize.Width * m_tileSize.Width,
                m_brushSize.Height * m_tileSize.Height);

            m_tileBrushElements = new List<TileBrushElement>();
            foreach (Location location in tileSelection.Locations)
            {
                if (!layer.IsValidTileLocation(location))
                    continue;

                Tile tile = layer.Tiles[location];
                Tile tileClone = tile == null ? null : tile.Clone(layer);
                TileBrushElement tileBrushElement = new TileBrushElement(
                    tileClone, location - selectionBounds.Location);
                m_tileBrushElements.Add(tileBrushElement);
            }
        }
示例#11
0
文件: MapPanel.cs 项目: dekk7/xEngine
        public MapPanel()
        {
            InitializeComponent();

            m_commandHistory = CommandHistory.Instance;

            m_singleTileCursor = new Cursor(new MemoryStream(Properties.Resources.ToolsSingleTileCursor));
            m_tileBlockCursor = new Cursor(new MemoryStream(Properties.Resources.ToolsTileBlockCursor));
            m_eraserCursor = new Cursor(new MemoryStream(Properties.Resources.ToolsEraserCursor));
            m_dropperCursor = new Cursor(new MemoryStream(Properties.Resources.ToolsDropperCursor));

            m_viewport = new xTile.Dimensions.Rectangle(
                xTile.Dimensions.Location.Origin, xTile.Dimensions.Size.Zero);
            m_autoScaleViewport = true;

            m_zoomIndex = 5;
            m_zoom = 1.0f;

            m_layerCompositing = LayerCompositing.DimUnselected;

            m_editTool = EditTool.SingleTile;
            m_innerPanel.Cursor = m_singleTileCursor;
            m_mouseInside = false;
            m_mouseLocation = new Location();
            m_tileLayerLocation = xTile.Dimensions.Location.Origin;
            m_dragTileStart = xTile.Dimensions.Location.Origin;

            m_tileSelection = new TileSelection();
            m_ctrlKeyPressed = false;

            m_random = new Random();
            m_textureDistribution = new List<Tile>();

            m_tileGuides = false;

            m_veilBrush = new SolidBrush(Color.FromArgb(192, SystemColors.InactiveCaption));
            m_imageAttributes = new ImageAttributes();
            m_colorMatrix = new ColorMatrix();
            m_tileSelectionPen = new Pen(SystemColors.ActiveCaption);
            m_tileSelectionBrush = new SolidBrush(
                Color.FromArgb(128, SystemColors.ActiveCaption));

            m_dashPattern = new float[] { 1.0f, 1.0f, 1.0f, 1.0f };
            m_tileGuidePen = new Pen(Color.Black);
            m_tileGuidePen.DashPattern = m_dashPattern;

            m_animationTimer.Enabled = !this.DesignMode;

            m_dtStart = DateTime.Now;

            this.MouseWheel += new MouseEventHandler(OnMouseWheel);
        }
示例#12
0
文件: MapPanel.cs 项目: dekk7/xEngine
        private void SelectTiles()
        {
            if (m_selectedLayer == null)
                return;

            xTile.Dimensions.Size layerSize = m_selectedLayer.LayerSize;
            int minX = Math.Max(0, Math.Min(m_tileLayerLocation.X, m_dragTileStart.X));
            int minY = Math.Max(0, Math.Min(m_tileLayerLocation.Y, m_dragTileStart.Y));
            int maxX = Math.Min(layerSize.Width - 1, Math.Max(m_tileLayerLocation.X, m_dragTileStart.X));
            int maxY = Math.Min(layerSize.Height - 1, Math.Max(m_tileLayerLocation.Y, m_dragTileStart.Y));

            Location tileLocation = new Location(minX, minY);
            TileSelection tileSelection = new TileSelection();
            for (; tileLocation.Y <= maxY; tileLocation.Y++)
                for (tileLocation.X = minX; tileLocation.X <= maxX; tileLocation.X++)
                    tileSelection.AddLocation(tileLocation);

            Command command = new ToolsSelectCommand(
                m_selectedLayer, m_tileSelection, tileSelection,
                !m_ctrlKeyPressed);
            m_commandHistory.Do(command);

            m_innerPanel.Invalidate();

            if (SelectionChanged != null)
                SelectionChanged(this, EventArgs.Empty);
        }
示例#13
0
 public virtual void SelectionDoneAction(TileSelection selection)
 {
 }
示例#14
0
        public static Tileset CreateTilesetFromTmx(string tmxFilePath, string dstPath)
        {
            string     tmxFileName = Path.GetFileNameWithoutExtension(tmxFilePath);
            TmxTilemap tilemap     = TmxTilemap.LoadFromFile(tmxFilePath);

            if (tilemap.DicTilesetTex2D.Values.Count == 0)
            {
                return(null);
            }

            //NOTE: calling this after PackTextures will make the atlasTexture to be null sometimes
            Tileset tilesetAsset     = ScriptableObject.CreateInstance <Tileset>();
            string  tilesetAssetPath = Path.Combine(dstPath, tmxFileName + "Tileset.asset");

            AssetDatabase.CreateAsset(tilesetAsset, tilesetAssetPath);
            Texture2D atlasTexture;

            Rect[] tilesetRects;
            if (tilemap.DicTilesetTex2D.Values.Count == 1)
            {
                atlasTexture = tilemap.DicTilesetTex2D.Values.ToArray()[0].tilesetTexture;
                tilesetRects = new Rect[] { new Rect(0, 0, atlasTexture.width, atlasTexture.height) };
            }
            else
            {
                atlasTexture = new Texture2D(8192, 8192, TextureFormat.ARGB32, false, false);
                tilesetRects = atlasTexture.PackTextures(tilemap.DicTilesetTex2D.Values.Select(x => x.tilesetTexture).ToArray(), 0, 8192);
            }
            string atlasPath = Path.GetDirectoryName(AssetDatabase.GetAssetPath(tilesetAsset)) + "/" + tmxFileName + "Atlas.png";

            atlasTexture.hideFlags = HideFlags.None;
            AssetDatabase.CreateAsset(atlasTexture, atlasPath);
            atlasTexture.hideFlags = HideFlags.DontSave;
            File.WriteAllBytes(atlasPath, atlasTexture.EncodeToPNG());
            ImportTexture(atlasPath);
            AssetDatabase.Refresh();

            //NOTE: tilesetAsset is sometimes nulled after calling Refresh
            tilesetAsset = AssetDatabase.LoadAssetAtPath <Tileset>(tilesetAssetPath);
            // Link Atlas with asset to be able to save it in the prefab
            tilesetAsset.AtlasTexture = (Texture2D)AssetDatabase.LoadAssetAtPath(atlasPath, typeof(Texture2D));

            tilesetAsset.TilePxSize = new Vector2(tilemap.Map.Tilesets[0].TileWidth, tilemap.Map.Tilesets[0].TileHeight);
            int         tilesetIdx = 0;
            List <Tile> tileList   = new List <Tile>();

            foreach (TmxTilemap.TilesetTextureData tilesetTextureData in tilemap.DicTilesetTex2D.Values)
            {
                TmxTileset tmxTileset = tilemap.Map.Tilesets[tilesetIdx];
                Vector2    tileSize   = new Vector2(tilemap.Map.Tilesets[tilesetIdx].TileWidth, tilemap.Map.Tilesets[tilesetIdx].TileHeight);
                Rect[]     tileRects  = tilesetTextureData.isCollectionOfSprites?
                                        tilesetTextureData.tileRects
                    :
                                        GenerateGridSpriteRectangles(tilesetTextureData.tilesetTexture, new Vector2(tmxTileset.Margin, tmxTileset.Margin), tileSize, new Vector2(tmxTileset.Spacing, tmxTileset.Spacing));
                TileSelection tilesetSelection = tilesetTextureData.isCollectionOfSprites?
                                                 new TileSelection(tilesetTextureData.tileIds.Select(i => (uint)i).ToList(), tmxTileset.Columns)
                    :
                                                 new TileSelection(Enumerable.Range(tileList.Count, tileRects.Length).Select(i => (uint)i).ToList(), tmxTileset.Columns);
                for (int i = 0; i < tileRects.Length; ++i)
                {
                    // fill with padding tiles the spaces between tiles. In tiled you can remove and add tiles to sprite collections tileset, so the ids could not be consecutive.
                    if (tilesetTextureData.isCollectionOfSprites)
                    {
                        int paddingTiles = i == 0? tilesetTextureData.tileIds[i] : (tilesetTextureData.tileIds[i] - tilesetTextureData.tileIds[i - 1]) - 1;
                        if (paddingTiles > 0)
                        {
                            tileList.AddRange(Enumerable.Repeat(default(Tile), paddingTiles));
                        }
                    }
                    Rect tileRect = tileRects[i];
                    Rect uv       = tileRect;
                    uv.xMin     /= tilesetAsset.AtlasTexture.width;
                    uv.xMax     /= tilesetAsset.AtlasTexture.width;
                    uv.yMin     /= tilesetAsset.AtlasTexture.height;
                    uv.yMax     /= tilesetAsset.AtlasTexture.height;
                    uv.position += tilesetRects[tilesetIdx].position;
                    tileList.Add(new Tile()
                    {
                        uv = uv
                    });
                }
                tilesetIdx++;
                tilesetAsset.TileViews.Add(new TileView(tilesetTextureData.tilesetTexture.name, tilesetSelection));
            }
            tilesetAsset.SetTiles(tileList);
            //NOTE: sometimes, the asset is not saved, this makes sure tilesetAsset is saved with the new data
            TilemapUtilsEditor.CreateOrReplaceAsset <Tileset>(tilesetAsset, tilesetAssetPath);
            return(tilesetAsset);
        }
示例#15
0
        //Effect bloomExtractEffect;
        //Effect bloomCombineEffect;
        //Effect gaussianBlurEffect;

        //RenderTarget2D sceneRenderTarget;
        //RenderTarget2D renderTarget1;
        //RenderTarget2D renderTarget2;

        // Choose what display settings the bloom should use.
        //public BloomSettings Settings
        //{
        //    get { return settings; }
        //    set { settings = value; }
        //}

        //BloomSettings settings = BloomSettings.PresetSettings[0];


        // Optionally displays one of the intermediate buffers used
        // by the bloom postprocess, so you can see exactly what is
        // being drawn into each rendertarget.
        //public enum IntermediateBuffer
        // {
        //    PreBloom,
        //    BlurredHorizontally,
        //    BlurredBothWays,
        //    FinalResult,
        //}

        public GameVSState(BaseGame game, IComponent parent, GameType gameType, Player[] players)
            : base(game, parent)
        {
            UnifiedInput.TapListeners.Add(Tap);
            GameType        = gameType;
            _players        = players;
            _scoreParticles = new List <ScoreParticle>();
            _tileSelection  = TileSelection.X;
            _cpuPlayerTween = new Tween(new TimeSpan(0, 0, 0, 0, 500), 0, 1);
            _gameOverFade   = new Tween(new TimeSpan(0, 0, 0, 8), 0, 1);
            _gameOverScale  = new Tween(new TimeSpan(0, 0, 0, 8), 1, 2.5f);
            _players        = players;
            _x = 0;
            _y = 0;
            try
            {
                _offset = new Vector2(
                    Center.X -
                    (Game.GameData.Data.GameGridsVsMode[GameType.Grid].XTiles * Game.GameData.Data.GameGridsVsMode[GameType.Grid].TileSize / 2f),
                    Center.Y -
                    (Game.GameData.Data.GameGridsVsMode[GameType.Grid].YTiles * Game.GameData.Data.GameGridsVsMode[GameType.Grid].TileSize) / 2f);
            }
            catch (Exception e)
            {
                throw e;
            }
            _colorLerp    = new Tween(new TimeSpan(2000L), 1f, 0f);
            CurrentTiles  = new Tile[Game.GameData.Data.GameGridsVsMode[GameType.Grid].YTiles][];
            PreviousTiles = new Tile[Game.GameData.Data.GameGridsVsMode[GameType.Grid].YTiles][];
            for (var i = 0; i < CurrentTiles.Count(); i++)
            {
                CurrentTiles[i]  = new Tile[Game.GameData.Data.GameGridsVsMode[GameType.Grid].XTiles];
                PreviousTiles[i] = new Tile[Game.GameData.Data.GameGridsVsMode[GameType.Grid].XTiles];
            }
            for (var i = 0; i < CurrentTiles.Count(); i++)
            {
                for (var j = 0; j < CurrentTiles[i].Count(); j++)
                {
                    CurrentTiles[i][j] = new Tile {
                        Bottom = false, Top = false, Left = false, Right = false, Color = -1
                    };
                    PreviousTiles[i][j] = new Tile {
                        Bottom = false, Top = false, Left = false, Right = false, Color = -1
                    };
                }
            }

            //bloomExtractEffect = new Effect(Game.GraphicsDevice,
            //        BaseGame.LoadStream(@"Content\Effects\BloomExtract.mgfxo"));
            //bloomCombineEffect = new Effect(Game.GraphicsDevice,
            //       BaseGame.LoadStream(@"Content\Effects\BloomCombine.mgfxo"));
            //gaussianBlurEffect = new Effect(Game.GraphicsDevice,
            //        BaseGame.LoadStream(@"Content\Effects\GaussianBlur.mgfxo"));


            // Look up the resolution and format of our main backbuffer.
            //PresentationParameters pp = game.GraphicsDevice.PresentationParameters;

            //int width = pp.BackBufferWidth;
            //int height = pp.BackBufferHeight;

            //SurfaceFormat format = pp.BackBufferFormat;

            // Create a texture for rendering the main scene, prior to applying bloom.
            //sceneRenderTarget = new RenderTarget2D(game.GraphicsDevice, width, height, false,
            //                                       format, pp.DepthStencilFormat, pp.MultiSampleCount,
            //                                       RenderTargetUsage.DiscardContents);

            // Create two rendertargets for the bloom processing. These are half the
            // size of the backbuffer, in order to minimize fillrate costs. Reducing
            // the resolution in this way doesn't hurt quality, because we are going
            // to be blurring the bloom images in any case.
            //width /= 2;
            //height /= 2;

            //renderTarget1 = new RenderTarget2D(game.GraphicsDevice, width, height, false, format, DepthFormat.None);
            //renderTarget2 = new RenderTarget2D(game.GraphicsDevice, width, height, false, format, DepthFormat.None);
        }
示例#16
0
        public static Tileset CreateTilesetFromTmx(string tmxFilePath, string dstPath)
        {
            string     tmxFileName = Path.GetFileNameWithoutExtension(tmxFilePath);
            TmxTilemap tilemap     = TmxTilemap.LoadFromFile(tmxFilePath);

            if (tilemap.DicTilesetTex2D.Values.Count == 0)
            {
                return(null);
            }

            //NOTE: calling this after PackTextures will make the atlasTexture to be null sometimes
            Tileset tilesetAsset = ScriptableObject.CreateInstance <Tileset>();

            AssetDatabase.CreateAsset(tilesetAsset, Path.Combine(dstPath, tmxFileName + "Tileset.asset"));
            Texture2D atlasTexture;

            Rect[] tilesetRects;
            if (tilemap.DicTilesetTex2D.Values.Count == 1)
            {
                atlasTexture = tilemap.DicTilesetTex2D.Values.ToArray()[0];
                tilesetRects = new Rect[] { new Rect(0, 0, atlasTexture.width, atlasTexture.height) };
            }
            else
            {
                atlasTexture = new Texture2D(8192, 8192, TextureFormat.ARGB32, false, false);
                tilesetRects = atlasTexture.PackTextures(tilemap.DicTilesetTex2D.Values.ToArray(), 0);
            }
            string atlasPath = Path.GetDirectoryName(AssetDatabase.GetAssetPath(tilesetAsset)) + "/" + tmxFileName + "Atlas.png";

            AssetDatabase.CreateAsset(atlasTexture, atlasPath);
            File.WriteAllBytes(atlasPath, atlasTexture.EncodeToPNG());
            ImportTexture(atlasPath);
            AssetDatabase.Refresh();

            // Link Atlas with asset to be able to save it in the prefab
            tilesetAsset.AtlasTexture = (Texture2D)AssetDatabase.LoadAssetAtPath(atlasPath, typeof(Texture2D));

            tilesetAsset.TilePxSize = new Vector2(tilemap.Map.Tilesets[0].TileWidth, tilemap.Map.Tilesets[0].TileHeight);
            int         tilesetIdx = 0;
            List <Tile> tileList   = new List <Tile>();

            foreach (Texture2D tilesetTexture in tilemap.DicTilesetTex2D.Values)
            {
                TmxTileset    tmxTileset       = tilemap.Map.Tilesets[tilesetIdx];
                Vector2       tileSize         = new Vector2(tilemap.Map.Tilesets[tilesetIdx].TileWidth, tilemap.Map.Tilesets[tilesetIdx].TileHeight);
                Rect[]        tileRects        = GenerateGridSpriteRectangles(tilesetTexture, new Vector2(tmxTileset.Margin, tmxTileset.Margin), tileSize, new Vector2(tmxTileset.Spacing, tmxTileset.Spacing));
                TileSelection tilesetSelection = new TileSelection(Enumerable.Range(tileList.Count, tileRects.Length).Select(i => (uint)i).ToList(), tmxTileset.Columns);
                foreach (Rect tileRect in tileRects)
                {
                    Rect uv = tileRect;
                    uv.xMin     /= tilesetAsset.AtlasTexture.width;
                    uv.xMax     /= tilesetAsset.AtlasTexture.width;
                    uv.yMin     /= tilesetAsset.AtlasTexture.height;
                    uv.yMax     /= tilesetAsset.AtlasTexture.height;
                    uv.position += tilesetRects[tilesetIdx].position;
                    tileList.Add(new Tile()
                    {
                        uv = uv
                    });
                }
                tilesetIdx++;
                tilesetAsset.TileViews.Add(new TileView(tilesetTexture.name, tilesetSelection));
            }
            tilesetAsset.SetTiles(tileList);
            return(tilesetAsset);
        }
示例#17
0
 public TileFillTool(Application application, Tileset Tileset, TileSelection selection)
     : base(application, Tileset, selection)
 {
     ActionName = "Flood Fill";
 }
示例#18
0
        public override IComponent Update(GameTime gameTime, BaseGame game)
        {
            if (NextComponent != null)
            {
                return(NextComponent);
            }

            _cpuPlayerTween.Update(gameTime.ElapsedGameTime);
            _rotation += 0.05f;
            _rotation  = MathHelper.WrapAngle(_rotation);
            _colorLerp.Update(new TimeSpan(50L));

            #region Human
            if (CurrentPlayer.Type == PlayerType.Human && !_gameOver)
            {
                var positions = new List <Vector2>();

                for (var y = 0; y < Game.GameData.Data.GameGridsVsMode[GameType.Grid].YTiles + 1; y++)
                {
                    for (var x = 0; x < Game.GameData.Data.GameGridsVsMode[GameType.Grid].XTiles + 1; x++)
                    {
                        positions.Add(new Vector2((x * Game.GameData.Data.GameGridsVsMode[GameType.Grid].TileSize) + _offset.X,
                                                  (y * Game.GameData.Data.GameGridsVsMode[GameType.Grid].TileSize) + _offset.Y));
                    }
                }
                if (!Game.Mouse.Hidden || Game.Touch.IsTouched)
                {
                    Vector2 loc = Game.Touch.IsTouched
                        ? Game.Touch.Location
                        : Game.Mouse.Location;
                    Vector2?closest1         = null;
                    var     closestDistance1 = float.MaxValue;
                    foreach (var position in positions)
                    {
                        var distance = Vector2.DistanceSquared(position, loc);
                        if (closest1.HasValue && distance >= closestDistance1)
                        {
                            continue;
                        }
                        closest1         = position;
                        closestDistance1 = distance;
                    }
                    _cm1 = closest1 ?? Vector2.Zero;
                    Vector2?closest2         = null;
                    var     closestDistance2 = float.MaxValue;
                    foreach (var position in positions)
                    {
                        if (position == _cm1)
                        {
                            continue;
                        }
                        var distance = Vector2.DistanceSquared(position, loc);
                        if (closest2.HasValue && (distance >= closestDistance2))
                        {
                            continue;
                        }
                        closest2         = position;
                        closestDistance2 = distance;
                    }
                    _cm2 = closest2 ?? Vector2.Zero;

                    _mx1 = (int)(((_cm1.X - _offset.X) / Game.GameData.Data.GameGridsVsMode[GameType.Grid].TileSize));
                    _my1 = (int)(((_cm1.Y - _offset.Y) / Game.GameData.Data.GameGridsVsMode[GameType.Grid].TileSize));
                    _mx2 = (int)(((_cm2.X - _offset.X) / Game.GameData.Data.GameGridsVsMode[GameType.Grid].TileSize));
                    _my2 = (int)(((_cm2.Y - _offset.Y) / Game.GameData.Data.GameGridsVsMode[GameType.Grid].TileSize));
                    if (_mx2 != _mx1)
                    {
                        var nx = Math.Min(_mx1, _mx2);
                        var ny = Math.Min(_my1, _my2);
                        if (_x != nx || _y != ny)
                        {
                            Game.Audio.Play(Cues.Move02);
                        }
                        _x             = nx;
                        _y             = ny;
                        _tileSelection = TileSelection.Y;
                    }
                    else
                    {
                        var nx = Math.Min(_mx1, _mx2);
                        var ny = Math.Min(_my1, _my2);
                        if (_x != nx || _y != ny)
                        {
                            Game.Audio.Play(Cues.Move01);
                        }
                        _x             = nx;
                        _y             = ny;
                        _tileSelection = TileSelection.X;
                    }


                    var xy = new Vector2((_x * Game.GameData.Data.GameGridsVsMode[GameType.Grid].TileSize) + _offset.X,
                                         (_y * Game.GameData.Data.GameGridsVsMode[GameType.Grid].TileSize) + _offset.Y);
                    var d = Vector2.Distance(xy, loc);

                    if ((Game.Mouse.LeftSingleClick || TapLoaction != Vector2.Zero) &&
                        (d <= (Game.GameData.Data.GameGridsVsMode[GameType.Grid].TileSize * .75)))
                    {
                        Game.Audio.Play(Cues.Move02);
                        Game.Mouse.ComponentChange();
                        TapLoaction = Vector2.Zero;
                        if (EndTurn(false))
                        {
                            //do something
                        }
                    }
                }
                if (Game.KeyboardInput.TypedKey(Keys.Enter) || Game.KeyboardInput.TypedKey(Keys.Space))
                {
                    Game.Audio.Play(Cues.Move02);
                    if (EndTurn(false))
                    {
                        //do something
                    }
                }
                if (Game.KeyboardInput.TypedKey(Keys.Up))
                {
                    Game.Audio.Play(Cues.Move02);
                    MoveUp();
                }
                if (Game.KeyboardInput.TypedKey(Keys.Down))
                {
                    Game.Audio.Play(Cues.Move02);
                    MoveDown();
                }
                if (Game.KeyboardInput.TypedKey(Keys.Left))
                {
                    Game.Audio.Play(Cues.Move01);
                    MoveLeft();
                }
                if (Game.KeyboardInput.TypedKey(Keys.Right))
                {
                    Game.Audio.Play(Cues.Move01);
                    MoveRight();
                }
            }
            #endregion

            else if (!_gameOver)
            {
                DoAI();
            }
            if (_gameOver)
            {
                _gameOverFade.Update(gameTime.ElapsedGameTime);
                _gameOverScale.Update(gameTime.ElapsedGameTime);
            }
            else
            {
                _gameOver = true;
                for (var i = 0; i < CurrentTiles.Count(); i++)
                {
                    for (var j = 0; j < CurrentTiles[i].Count(); j++)
                    {
                        if (CurrentTiles[i][j].IsClosed)
                        {
                            continue;
                        }
                        _gameOver = false;
                        break;
                    }
                }

                if (_gameOver & !_scored)
                {
                    var hs = _players.Max(ps => ps.Score);

                    for (var index = 0; index < _players.Length; index++)
                    {
                        var p = _players[index];
                        if (p.Score == hs)
                        {
                            _currentPlayer = index;
                        }
                    }
                    var s = 5;
                    for (var i = 0; i < CurrentTiles.Count(); i++)
                    {
                        for (var j = 0; j < CurrentTiles[i].Count(); j++)
                        {
                            if (CurrentTiles[i][j].Color != CurrentPlayer.Color)
                            {
                                continue;
                            }
                            AddScoreParticle(j, i, s);
                            _players[_currentPlayer].Score += s;
                            s += 5;
                        }
                    }
                    if (CurrentPlayer.Type == PlayerType.Human)
                    {
                        _unlock = true;
                    }
                    _scored = true;
                }
            }
            foreach (var scoreParticle in _scoreParticles)
            {
                scoreParticle.Update(gameTime);
            }
            _scoreParticles.RemoveAll(p => p.IsDead());
            if (_gameOverFade.IsComplete)
            {
                Back();
            }
            return(this);
        }
示例#19
0
    private Application(string[] args)
    {
        selection = new TileSelection();

        Glade.XML.CustomHandler = GladeCustomWidgetHandler;
        Glade.XML gxml = new Glade.XML("editor.glade", "MainWindow");
        gxml.Autoconnect(this);

        if (MainWindow == null)
            throw new Exception("Couldn't resolve all widgets");

        ((GameObjectListWidget)ToolGObjectsProps).SetGtkFrame(fGObjects);

        Tileset.LoadEditorImages = true;

        // Initialize status bar for PrintStatus()
        printStatusContextID = sbMain.GetContextId("PrintStatus");
        printStatusMessageID = sbMain.Push(printStatusContextID, "Welcome to Supertux-Editor.");

        MainWindow.DeleteEvent += OnDelete;

        MainWindow.SetSizeRequest(900, 675);
        MainWindowTitlePrefix = MainWindow.Title;
        UpdateTitlebar();
        UpdateRecentDocuments();
        MainWindow.Icon = EditorStock.WindowIcon;
        //HACK: not a typo, EditorStock adds icons to the stock only when called 2x or more..
        MainWindow.Icon = EditorStock.WindowIcon;
        MainWindow.ShowAll();

        // Manually set icons for Tools, automatic stock initialization is broken on some systems
        ToolSelect.StockId = EditorStock.ToolSelect;
        ToolTiles.StockId = EditorStock.ToolTiles;
        ToolObjects.StockId = EditorStock.ToolObjects;
        ToolBrush.StockId = EditorStock.ToolBrush;
        ToolFill.StockId = EditorStock.ToolFill;
        ToolReplace.StockId = EditorStock.ToolReplace;
        ToolPath.StockId = EditorStock.ToolPath;
        ToolButtonCamera.StockId = EditorStock.Camera;

        // Hide some extra widgets (because MainWindow.ShowAll(); showed them all)
        fGObjects.Visible = false;
        if (Settings.Instance.ToolboxOnRight)
        {
            aTools.Reparent(fToolsRight);
            fToolsLeft.Hide();
        } else {
            aTools.Reparent(fToolsLeft);
            fToolsRight.Hide();
        }

        // Tool "Select" is selected by default - call its event handler
        OnToolSelect(null, null);

        //Setup drag destination for "files"
        Gtk.Drag.DestSet(MainWindow, Gtk.DestDefaults.All, target_table,
                 Gdk.DragAction.Default |
                 Gdk.DragAction.Copy |
                 Gdk.DragAction.Move |
                 Gdk.DragAction.Link |
                 Gdk.DragAction.Private |
                 Gdk.DragAction.Ask);
        MainWindow.DragDataReceived += OnDragDataReceived;

        fileChooser = new Gtk.FileChooserDialog("Choose a Level", MainWindow, Gtk.FileChooserAction.Open, new object[] {});
        if (!Directory.Exists(Settings.Instance.LastDirectoryName)) {	//noexistent (or null) LastDirectoryName, resetting to default
            if( Settings.Instance.SupertuxData != null ) {
                Settings.Instance.LastDirectoryName = System.IO.Path.Combine(Settings.Instance.SupertuxData, "levels") + System.IO.Path.DirectorySeparatorChar;
            } else {
                Settings.Instance.LastDirectoryName = Environment.ExpandEnvironmentVariables("%HOME%");
            }
        }
        fileChooser.SetCurrentFolder(Settings.Instance.LastDirectoryName);
        fileChooser.AddButton(Gtk.Stock.Cancel, Gtk.ResponseType.Cancel);
        fileChooser.AddButton(Gtk.Stock.Ok, Gtk.ResponseType.Ok);
        fileChooser.DefaultResponse = Gtk.ResponseType.Ok;
        Gtk.FileFilter filter = new Gtk.FileFilter();
        filter.Name = "Supertux Levels and Worldmaps";
        filter.AddPattern("*.stl");
        filter.AddPattern("*.stwm");
        fileChooser.AddFilter( filter );
        Gtk.FileFilter levelfilter = new Gtk.FileFilter();
        levelfilter.Name = "Supertux Levels";
        levelfilter.AddPattern("*.stl");
        fileChooser.AddFilter( levelfilter );
        Gtk.FileFilter worldmapfilter = new Gtk.FileFilter();
        worldmapfilter.Name = "Supertux Worldmaps";
        worldmapfilter.AddPattern("*.stwm");
        fileChooser.AddFilter( worldmapfilter );
        Gtk.FileFilter brushfilter = new Gtk.FileFilter();
        brushfilter.Name = "Supertux-Editor Brushes";
        brushfilter.AddPattern("*.csv");
        fileChooser.AddFilter(brushfilter);
        Gtk.FileFilter all = new Gtk.FileFilter();
        all.Name = "All Files";
        all.AddPattern("*");
        fileChooser.AddFilter( all );
        if( Settings.Instance.SupertuxData != null ){
            try {
                fileChooser.AddShortcutFolder(System.IO.Path.Combine(Settings.Instance.SupertuxData, "levels"));
            } catch (Exception e) {
                LogManager.Log(LogLevel.Warning, "Couldn't add supertux level directory to File Chooser: " + e.Message);
            }
        }

        if (args.Length > 0) {
            Load(args[0]);
        }

        UndoManager.OnAddCommand += OnUndoManager;
        UndoManager.OnRedo += OnUndoManager;
        UndoManager.OnUndo += OnUndoManager;

        editorApplication = this;

        PrintStatus("Welcome to Supertux-Editor.");
    }
示例#20
0
 public TileFillTool(Application application, Tileset Tileset, TileSelection selection)
     : base(application, Tileset, selection)
 {
     ActionName = "Flood Fill";
 }
示例#21
0
 public virtual void SelectionDoneAction(TileSelection selection)
 {
 }
示例#22
0
        internal void ApplyTo(Layer layer, Location brushLocation,
            TileSelection tileSelection)
        {
            Map map = layer.Map;
            xTile.Dimensions.Size layerTileSize = layer.TileSize;

            if (layerTileSize != m_tileSize)
                return;

            tileSelection.Clear();
            foreach (TileBrushElement tileBrushElement in m_tileBrushElements)
            {
                Location tileLocation = brushLocation + tileBrushElement.Location;
                if (!layer.IsValidTileLocation(tileLocation))
                    continue;

                Tile tile = tileBrushElement.Tile;
                Tile tileClone = null;
                if (tile != null)
                {
                    TileSheet tileSheet = tile.TileSheet;

                    if (!map.TileSheets.Contains(tile.TileSheet))
                        continue;

                    tileClone = tile.Clone(layer);
                }

                layer.Tiles[tileLocation] = tileClone;
                tileSelection.AddLocation(tileLocation);
            }
        }
 public TileReplaceTool(Application application, Tileset Tileset, TileSelection selection)
     : base(application, Tileset, selection)
 {
     ActionName = "Replace Tiles";
 }
示例#24
0
 internal TileBrush(Layer layer, TileSelection tileSelection)
     : this("Clipboard", layer, tileSelection)
 {
 }
示例#25
0
 internal void GenerateSelection(Location brushLocation,
     TileSelection tileSelection)
 {
     tileSelection.Clear();
     foreach (TileBrushElement tileBrushElement in m_tileBrushElements)
         tileSelection.AddLocation(brushLocation + tileBrushElement.Location);
 }
示例#26
0
 internal TileBrush(Layer layer, TileSelection tileSelection)
     : this("Clipboard", layer, tileSelection)
 {
 }
示例#27
0
    public void Split(Region r, int fraction = 2)
    {
        var target             = this.tiles.Count() / (float)fraction;
        var i                  = 0;
        var original_fragments = MapGen.SeperateContiguous(this.tiles).Count();
        var open               = new TileSelection();
        var start              = tiles.Sample();

        open.Add(start);
        while (r.tiles.Count() < target && open.Count() > 0)
        {
            i++;
            var t = open.Sample();
            open.Remove(t);

            r.Assign(t);
            if (i % 10 == 1)
            {
                JoinCutOffAreas(r, original_fragments);
            }
            foreach (var n in t.adjacent.tiles)
            {
                if (n.region == this)
                {
                    if (n.land)
                    {
                        open.Add(n);
                    }
                }
            }
        }

        this.JoinCutOffAreas(r, original_fragments);
        var core = r.tiles;
        //core = MapGen.Shrink(core);
        var original_core = this.tiles;
        //original_core = MapGen.Shrink(original_core);

        var to_switch_back = new TileSelection();

        foreach (var t in r.tiles.tiles)
        {
            if (core.DoesNotContain(t))
            {
                to_switch_back.Add(t);
            }
        }
        foreach (var t in this.tiles.tiles)
        {
            if (original_core.DoesNotContain(t))
            {
                to_switch_back.Add(t);
            }
        }

        Dictionary <Tile, Region> switchMap = new Dictionary <Tile, Region>();
        var allowed_regions = new HashSet <Region>();

        allowed_regions.Add(r);
        allowed_regions.Add(this);
        foreach (var t in to_switch_back.tiles)
        {
            t.region = null;
            r.tiles.Remove(t);
            TileSelection t_as_list = new TileSelection();
            t_as_list.Add(t);
            try{
                switchMap.Add(t, MapGen.ClosestRegion(t_as_list, null, allowed_regions));
            }catch (Exception e) {
                Debug.LogError(e); // Swallow
            }
        }
        foreach (KeyValuePair <Tile, Region> entry in switchMap)
        {
            entry.Value.Assign(entry.Key);
        }
        r.JoinCutOffAreas(this, 1);
        this.JoinCutOffAreas(r, original_fragments);
    }
示例#28
0
 public override void SelectionDoneAction(TileSelection selection)
 {
     brush.LearnPatterns(selection);
 }
示例#29
0
 public TilePaintTool(Application application, Tileset Tileset, TileSelection selection)
     : base(application, Tileset, selection)
 {
     ActionName = "Change Tiles";
 }