Example #1
0
        private void onMouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                if (this.action == null)
                {
                    this.action = new MultiAction("Eraser");
                }

                int xt = (int)((e.X - EditorEngine.Instance.xCam) / EditorEngine.Instance.World.Camera.Scale / 16);
                int yt = (int)((e.Y - EditorEngine.Instance.yCam) / EditorEngine.Instance.World.Camera.Scale / 16);

                if (xt != lxt || yt != lyt)
                {
                    int tilesetIndex = TileEditorState.Instance.SelectedTileset;

                    MockupTile t = EditorEngine.Instance.CurrentMap.GetTile(xt, yt, EditorEngine.Instance.SelectedLayer);

                    if (t != null)
                    {
                        SetTileAction tileAction = new SetTileAction(xt, yt, EditorEngine.Instance.SelectedLayer, tilesetIndex, -1);
                        tileAction.Execute();

                        action.Actions.Add(tileAction);
                    }
                }

                lxt = xt;
                lyt = yt;
            }
        }
Example #2
0
        public void FillList()
        {
            if (logicindex >= 0)
            {
                SetTileAction action = TileLogicManager.Instance.logics[logicindex].Evaluate(xt, yt);
                if (action != null)
                {
                    action.Execute();
                }

                if (updateneighbors)
                {
                    List <MockupTile> neighbors = new List <MockupTile>();
                    neighbors.Add(EditorEngine.Instance.CurrentMap.GetTile(xt - 1, yt - 1, EditorEngine.Instance.SelectedLayer));
                    neighbors.Add(EditorEngine.Instance.CurrentMap.GetTile(xt, yt - 1, EditorEngine.Instance.SelectedLayer));
                    neighbors.Add(EditorEngine.Instance.CurrentMap.GetTile(xt + 1, yt - 1, EditorEngine.Instance.SelectedLayer));
                    neighbors.Add(EditorEngine.Instance.CurrentMap.GetTile(xt - 1, yt, EditorEngine.Instance.SelectedLayer));
                    neighbors.Add(EditorEngine.Instance.CurrentMap.GetTile(xt, yt, EditorEngine.Instance.SelectedLayer));
                    neighbors.Add(EditorEngine.Instance.CurrentMap.GetTile(xt + 1, yt, EditorEngine.Instance.SelectedLayer));
                    neighbors.Add(EditorEngine.Instance.CurrentMap.GetTile(xt - 1, yt + 1, EditorEngine.Instance.SelectedLayer));
                    neighbors.Add(EditorEngine.Instance.CurrentMap.GetTile(xt, yt + 1, EditorEngine.Instance.SelectedLayer));
                    neighbors.Add(EditorEngine.Instance.CurrentMap.GetTile(xt + 1, yt + 1, EditorEngine.Instance.SelectedLayer));

                    //sometime the ugliest solution is the best
                    List <Tuple <int, int> > positions = new List <Tuple <int, int> >();
                    positions.Add(new Tuple <int, int>(-1, -1));
                    positions.Add(new Tuple <int, int>(0, -1));
                    positions.Add(new Tuple <int, int>(+1, -1));
                    positions.Add(new Tuple <int, int>(-1, 0));
                    positions.Add(new Tuple <int, int>(0, 0));
                    positions.Add(new Tuple <int, int>(+1, 0));
                    positions.Add(new Tuple <int, int>(-1, +1));
                    positions.Add(new Tuple <int, int>(0, +1));
                    positions.Add(new Tuple <int, int>(+1, +1));

                    int i = 0;
                    foreach (MockupTile neighbor in neighbors)
                    {
                        if (neighbor != null)
                        {
                            if (TileLogicManager.Instance.logics[logicindex].isSameType(neighbor))
                            {
                                if (Options.Instance.LogicCorrectSameType)
                                {
                                    SetTileAction _action = TileLogicManager.Instance.logics[logicindex].Evaluate(xt + positions[i].Item1, yt + positions[i].Item2);
                                    if (_action != null)
                                    {
                                        this.Actions.Add(_action);
                                    }
                                }
                            }
                            else
                            {
                                if (Options.Instance.LogicCorrectOtherType)
                                {
                                    TileLogicScript logic = TileLogicManager.Instance.getLogicFromSameType(neighbor.Tileset.Name, neighbor.tileIndex);
                                    if (logic != null)
                                    {
                                        SetTileAction _action = TileLogicManager.Instance.logics[logic.index].Evaluate(xt + positions[i].Item1, yt + positions[i].Item2);
                                        if (_action != null)
                                        {
                                            this.Actions.Add(_action);
                                        }
                                    }
                                }
                            }
                        }
                        i++;
                    }
                }
                if (action != null)
                {
                    action.UnExecute();
                    Actions.Add(action);
                }
            }
        }