FreeSubCellAt() публичный Метод

public FreeSubCellAt ( CPos cell ) : SubCell
cell CPos
Результат SubCell
Пример #1
0
        void ITickRender.TickRender(WorldRenderer wr, Actor self)
        {
            if (wr.World.Type != WorldType.Editor)
            {
                return;
            }

            if (Type == EditorCursorType.TerrainTemplate || Type == EditorCursorType.Resource)
            {
                var cell = wr.Viewport.ViewToWorld(Viewport.LastMousePos);
                if (terrainOrResourceCell != cell || terrainOrResourceDirty)
                {
                    terrainOrResourceCell  = cell;
                    terrainOrResourceDirty = false;
                    terrainOrResourcePreview.Clear();
                    var pos = world.Map.CenterOfCell(cell);

                    if (Type == EditorCursorType.TerrainTemplate)
                    {
                        var i = 0;
                        for (var y = 0; y < TerrainTemplate.Size.Y; y++)
                        {
                            for (var x = 0; x < TerrainTemplate.Size.X; x++)
                            {
                                var tile     = new TerrainTile(TerrainTemplate.Id, (byte)i++);
                                var tileInfo = world.Map.Rules.TileSet.GetTileInfo(tile);

                                // Empty tile
                                if (tileInfo == null)
                                {
                                    continue;
                                }

                                var sprite  = wr.Theater.TileSprite(tile, 0);
                                var offset  = world.Map.Offset(new CVec(x, y), tileInfo.Height);
                                var palette = wr.Palette(TerrainTemplate.Palette ?? TileSet.TerrainPaletteInternalName);

                                terrainOrResourcePreview.Add(new SpriteRenderable(sprite, pos, offset, 0, palette, 1, false, false));
                            }
                        }
                    }
                    else
                    {
                        var variant  = Resource.Sequences.FirstOrDefault();
                        var sequence = wr.World.Map.Rules.Sequences.GetSequence("resources", variant);
                        var sprite   = sequence.GetSprite(Resource.MaxDensity - 1);
                        var palette  = wr.Palette(Resource.Palette);

                        terrainOrResourcePreview.Add(new SpriteRenderable(sprite, pos, WVec.Zero, 0, palette, 1, false, sequence.IgnoreWorldTint));
                    }
                }
            }
            else if (Type == EditorCursorType.Actor)
            {
                // Offset mouse position by the center offset (in world pixels)
                var worldPx = wr.Viewport.ViewToWorldPx(Viewport.LastMousePos) - wr.ScreenPxOffset(actorCenterOffset);
                var cell    = wr.Viewport.ViewToWorld(wr.Viewport.WorldToViewPx(worldPx));
                var subCell = actorSharesCell ? editorLayer.FreeSubCellAt(cell) : SubCell.Invalid;
                var updated = false;
                if (actorLocation != cell)
                {
                    actorLocation = cell;
                    Actor.ReplaceInit(new LocationInit(cell));
                    updated = true;
                }

                if (actorSubCell != subCell)
                {
                    actorSubCell = subCell;

                    if (Actor.RemoveInits <SubCellInit>() > 0)
                    {
                        updated = true;
                    }

                    var subcell = world.Map.Tiles.Contains(cell) ? editorLayer.FreeSubCellAt(cell) : SubCell.Invalid;
                    if (subcell != SubCell.Invalid)
                    {
                        Actor.AddInit(new SubCellInit(subcell));
                        updated = true;
                    }
                }

                if (updated)
                {
                    Actor = new EditorActorPreview(wr, null, Actor.Export(), Actor.Owner);
                }
            }
        }
Пример #2
0
        void ITickRender.TickRender(WorldRenderer wr, Actor self)
        {
            if (wr.World.Type != WorldType.Editor)
            {
                return;
            }

            if (Type == EditorCursorType.TerrainTemplate || Type == EditorCursorType.Resource)
            {
                var cell = wr.Viewport.ViewToWorld(Viewport.LastMousePos);
                if (terrainOrResourceCell != cell || terrainOrResourceDirty)
                {
                    terrainOrResourceCell  = cell;
                    terrainOrResourceDirty = false;
                    terrainOrResourcePreview.Clear();
                    var pos = world.Map.CenterOfCell(cell);

                    if (Type == EditorCursorType.TerrainTemplate)
                    {
                        terrainOrResourcePreview.AddRange(terrainRenderer.RenderPreview(wr, TerrainTemplate, pos));
                    }
                    else
                    {
                        var variant  = Resource.Sequences.FirstOrDefault();
                        var sequence = wr.World.Map.Rules.Sequences.GetSequence("resources", variant);
                        var sprite   = sequence.GetSprite(Resource.MaxDensity - 1);
                        var palette  = wr.Palette(Resource.Palette);
                        var alpha    = sequence.GetAlpha(Resource.MaxDensity - 1);

                        var tintModifiers = sequence.IgnoreWorldTint ? TintModifiers.IgnoreWorldTint : TintModifiers.None;
                        terrainOrResourcePreview.Add(new SpriteRenderable(sprite, pos, WVec.Zero, 0, palette, 1f, alpha, float3.Ones, tintModifiers, false));
                    }
                }
            }
            else if (Type == EditorCursorType.Actor)
            {
                // Offset mouse position by the center offset (in world pixels)
                var worldPx = wr.Viewport.ViewToWorldPx(Viewport.LastMousePos) - wr.ScreenPxOffset(actorCenterOffset);
                var cell    = wr.Viewport.ViewToWorld(wr.Viewport.WorldToViewPx(worldPx));
                var subCell = actorSharesCell ? editorLayer.FreeSubCellAt(cell) : SubCell.Invalid;
                var updated = false;
                if (actorLocation != cell)
                {
                    actorLocation = cell;
                    Actor.ReplaceInit(new LocationInit(cell));
                    updated = true;
                }

                if (actorSubCell != subCell)
                {
                    actorSubCell = subCell;

                    if (Actor.RemoveInits <SubCellInit>() > 0)
                    {
                        updated = true;
                    }

                    var subcell = world.Map.Tiles.Contains(cell) ? editorLayer.FreeSubCellAt(cell) : SubCell.Invalid;
                    if (subcell != SubCell.Invalid)
                    {
                        Actor.AddInit(new SubCellInit(subcell));
                        updated = true;
                    }
                }

                if (updated)
                {
                    Actor = new EditorActorPreview(wr, null, Actor.Export(), Actor.Owner);
                }
            }
        }
Пример #3
0
        void ITickRender.TickRender(WorldRenderer wr, Actor self)
        {
            if (wr.World.Type != WorldType.Editor)
            {
                return;
            }

            if (Type == EditorCursorType.TerrainTemplate || Type == EditorCursorType.Resource)
            {
                var cell = wr.Viewport.ViewToWorld(Viewport.LastMousePos);
                if (terrainOrResourceCell != cell || terrainOrResourceDirty)
                {
                    terrainOrResourceCell  = cell;
                    terrainOrResourceDirty = false;
                    terrainOrResourcePreview.Clear();

                    var pos = world.Map.CenterOfCell(cell);
                    if (Type == EditorCursorType.TerrainTemplate)
                    {
                        terrainOrResourcePreview.AddRange(terrainRenderer.RenderPreview(wr, TerrainTemplate, pos));
                    }
                    else
                    {
                        terrainOrResourcePreview.AddRange(resourceRenderers.SelectMany(r => r.RenderPreview(wr, ResourceType, pos)));
                    }
                }
            }
            else if (Type == EditorCursorType.Actor)
            {
                // Offset mouse position by the center offset (in world pixels)
                var worldPx = wr.Viewport.ViewToWorldPx(Viewport.LastMousePos) - wr.ScreenPxOffset(actorCenterOffset);
                var cell    = wr.Viewport.ViewToWorld(wr.Viewport.WorldToViewPx(worldPx));
                var subCell = actorSharesCell ? editorLayer.FreeSubCellAt(cell) : SubCell.Invalid;
                var updated = false;
                if (actorLocation != cell)
                {
                    actorLocation = cell;
                    Actor.ReplaceInit(new LocationInit(cell));
                    updated = true;
                }

                if (actorSubCell != subCell)
                {
                    actorSubCell = subCell;

                    if (Actor.RemoveInits <SubCellInit>() > 0)
                    {
                        updated = true;
                    }

                    var subcell = world.Map.Tiles.Contains(cell) ? editorLayer.FreeSubCellAt(cell) : SubCell.Invalid;
                    if (subcell != SubCell.Invalid)
                    {
                        Actor.AddInit(new SubCellInit(subcell));
                        updated = true;
                    }
                }

                if (updated)
                {
                    Actor = new EditorActorPreview(wr, null, Actor.Export(), Actor.Owner);
                }
            }
        }