Example #1
0
    ////////////////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////////////////
    // State-dependent functions

    void SetState(MapEditorState newState)
    {
        if (this.state == MapEditorState.Normal)
        {
            this.mapDisplay.DisableHoveredTile();
        }
        else if (this.state == MapEditorState.SelectionPaint || this.state == MapEditorState.SelectionErase)
        {
            var he = (SelectionChangeHistoryEvent)this.inProgressHistoryEvent;
            he.newSelectedTiles = new List <Vector2i>(this.selectedTiles.Select(x => x.pos));
            if (he.oldSelectedTiles.SequenceEqual(he.newSelectedTiles) == false)
            {
                this.AddNewHistoryEvent(he);
            }

            this.inProgressHistoryEvent = null;
        }

        this.state = newState;

        if (newState == MapEditorState.SelectionPaint)
        {
            var he = new SelectionChangeHistoryEvent();
            he.oldSelectedTiles         = new List <Vector2i>(this.selectedTiles.Select(x => x.pos));
            this.inProgressHistoryEvent = he;

            if (
                this.lastEnteredTile != null &&
                this.selectedTiles.Contains(this.lastEnteredTile) == false
                )
            {
                this.selectedTiles.Add(this.lastEnteredTile);
                this.mapDisplay.SetSelectedTiles(this.selectedTiles);
            }
        }
        else if (newState == MapEditorState.SelectionErase)
        {
            var he = new SelectionChangeHistoryEvent();
            he.oldSelectedTiles         = new List <Vector2i>(this.selectedTiles.Select(x => x.pos));
            this.inProgressHistoryEvent = he;

            if (
                this.lastEnteredTile != null &&
                this.selectedTiles.Contains(this.lastEnteredTile) == true
                )
            {
                this.selectedTiles.Remove(this.lastEnteredTile);
                this.mapDisplay.SetSelectedTiles(this.selectedTiles);
            }
        }

        this.UpdateUI();
    }
Example #2
0
    ////////////////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////////////////
    // HistoryEvent functions

    void AddNewHistoryEvent(BaseHistoryEvent baseHistoryEvent)
    {
        while (this.historyEvents.Last != this.lastHistoryEventNode)
        {
            this.historyEvents.RemoveLast();
        }

        baseHistoryEvent.index = this.historyEvents.Count;

        this.lastHistoryEventNode = this.historyEvents.AddLast(baseHistoryEvent);

        this.DoHistoryEvent(baseHistoryEvent);

        this.UpdateUI();
    }
Example #3
0
    void UndoHistoryEvent(BaseHistoryEvent baseHistoryEvent)
    {
        if (baseHistoryEvent.GetType() == typeof(ResizeHistoryEvent))
        {
            var he = (ResizeHistoryEvent)baseHistoryEvent;
            this.map.size = he.oldSize;

            foreach (var tileOverride in he.removedTiles)
            {
                this.map.tileOverrides.Add(tileOverride);
            }

            foreach (var entity in he.removedEntities)
            {
                this.map.entities.Add(entity);
            }

            this.RebuildMapDisplay();

            foreach (var pos in he.deselectedTiles)
            {
                this.selectedTiles.Add(this.mapDisplay.GetTile(pos));
            }
            this.mapDisplay.SetSelectedTiles(this.selectedTiles);
        }
        else if (baseHistoryEvent.GetType() == typeof(SelectionChangeHistoryEvent))
        {
            var he = (SelectionChangeHistoryEvent)baseHistoryEvent;
            this.selectedTiles = new List <MapTile>(he.oldSelectedTiles.Select(x => this.mapDisplay.GetTile(x)));
            this.mapDisplay.SetSelectedTiles(this.selectedTiles);
        }
        else if (baseHistoryEvent.GetType() == typeof(TileChangeHistoryEvent))
        {
            var he = (TileChangeHistoryEvent)baseHistoryEvent;

            foreach (var tileOverride in he.oldTiles)
            {
                this.map.tileOverrides.RemoveAll(x => x.pos == tileOverride.pos);
                if (tileOverride.name != "")
                {
                    this.map.tileOverrides.Add(tileOverride);
                }
            }

            this.RebuildMapDisplay();
        }
        else if (baseHistoryEvent.GetType() == typeof(EntityChangeHistoryEvent))
        {
            var he = (EntityChangeHistoryEvent)baseHistoryEvent;

            foreach (var entity in he.oldEntities)
            {
                this.map.entities.RemoveAll(x => x.pos == entity.pos);
                if (entity.name != "None")
                {
                    this.map.entities.Add(entity);
                }
            }

            this.RebuildMapDisplay();
        }
    }
Example #4
0
    void DoHistoryEvent(BaseHistoryEvent baseHistoryEvent)
    {
        if (baseHistoryEvent.GetType() == typeof(ResizeHistoryEvent))
        {
            var he = (ResizeHistoryEvent)baseHistoryEvent;
            this.map.size = he.newSize;

            he.removedTiles = new List <BattleMap.TileOverride>();
            for (int n = this.map.tileOverrides.Count; n-- > 0;)
            {
                bool isOutsideBounds = (
                    this.map.tileOverrides[n].pos.x >= he.newSize.x ||
                    this.map.tileOverrides[n].pos.y >= he.newSize.y
                    );
                if (isOutsideBounds)
                {
                    he.removedTiles.Add(this.map.tileOverrides[n]);
                    this.map.tileOverrides.RemoveAt(n);
                }
            }

            he.removedEntities = new List <BattleMap.Entity>();
            for (int n = this.map.entities.Count; n-- > 0;)
            {
                bool isOutsideBounds = (
                    this.map.entities[n].pos.x >= he.newSize.x ||
                    this.map.entities[n].pos.y >= he.newSize.y
                    );
                if (isOutsideBounds)
                {
                    he.removedEntities.Add(this.map.entities[n]);
                    this.map.entities.RemoveAt(n);
                }
            }

            he.deselectedTiles = new List <Vector2i>();
            for (int n = this.selectedTiles.Count; n-- > 0;)
            {
                var  tile            = this.selectedTiles[n];
                bool isOutsideBounds = (
                    tile.pos.x >= he.newSize.x ||
                    tile.pos.y >= he.newSize.y
                    );
                if (isOutsideBounds)
                {
                    he.deselectedTiles.Add(tile.pos);
                    this.selectedTiles.RemoveAt(n);
                }
            }

            this.RebuildMapDisplay();
        }
        else if (baseHistoryEvent.GetType() == typeof(SelectionChangeHistoryEvent))
        {
            var he = (SelectionChangeHistoryEvent)baseHistoryEvent;
            this.selectedTiles = new List <MapTile>(he.newSelectedTiles.Select(x => this.mapDisplay.GetTile(x)));
            this.mapDisplay.SetSelectedTiles(this.selectedTiles);
        }
        else if (baseHistoryEvent.GetType() == typeof(TileChangeHistoryEvent))
        {
            var he = (TileChangeHistoryEvent)baseHistoryEvent;

            foreach (var tileOverride in he.newTiles)
            {
                this.map.tileOverrides.RemoveAll(x => x.pos == tileOverride.pos);
                if (tileOverride.name != "")
                {
                    this.map.tileOverrides.Add(tileOverride);
                }
            }

            this.RebuildMapDisplay();
        }
        else if (baseHistoryEvent.GetType() == typeof(EntityChangeHistoryEvent))
        {
            var he = (EntityChangeHistoryEvent)baseHistoryEvent;

            foreach (var entity in he.newEntities)
            {
                this.map.entities.RemoveAll(x => x.pos == entity.pos);
                if (entity.name != "None")
                {
                    this.map.entities.Add(entity);
                }
            }

            this.RebuildMapDisplay();
        }
    }