Example #1
0
        public void finish(int flags = 0)
        {
            if ((flags & SessionFlags.INTERNAL) == 0)
            {
                if ((flags & SessionFlags.SUBTHREAD)!= 0)
                {
                    Debug.Assert(subsession != null);
                    subsession = null;
                }
                else
                {
                    Debug.Assert(session != null);
                    Debug.Assert(subsession != null);
                    // We need to exit the session before we do the action, else peril awaits us!
                    BatchAction tmp = session;
                    session = null;

                    tmp.addAndCommitAction(subsession);
                    editor.addBatch(tmp, 2);

                    session = null;
                    subsession = null;
                }
            }
            busy = false;
        }
Example #2
0
        public void addAction(ActionIdentifier ident, Action action, int stacking_delay)
        {
            BatchAction a = new BatchAction(ident);

            a.addAction(action);
            addBatch(a, stacking_delay);
        }
Example #3
0
        public void UpdateMap(MapUpdate mapUpdate, MapEditor editor)
        {
            lock (mapUpdateLock) // não permitir salvar ao atualizar o mapa.
            {
                BatchAction batchAction = mapUpdate.batchAction;

                if (mapUpdate.updateType == UpdateType.UPDATE_TYPE_UNDO)
                {
                    foreach (Action action in batchAction.actions.Reverse <Action>())
                    {
                        action.SetMap(this);
                        action.SetEditor(editor);
                        action.undo();
                    }
                }
                else
                {
                    foreach (Action action in batchAction.actions)
                    {
                        action.SetMap(this);
                        action.SetEditor(editor);
                        switch (mapUpdate.updateType)
                        {
                        case UpdateType.UPDATE_TYPE_COMMIT:
                            action.commit();
                            break;

                        case UpdateType.UPDATE_TYPE_REDO:
                            action.redo();
                            break;
                        }
                    }
                }
            }
        }
Example #4
0
        public BatchAction DeepCopy()
        {
            bool        isEmpty     = true;
            BatchAction batchAction = new BatchAction();

            batchAction.actions = new List <Action>();
            if (this.type != ActionIdentifier.ACTION_SELECT)
            {
                batchAction.type = this.type;
                foreach (Action action in actions)
                {
                    Action copyAction = action.deepCopy();
                    if (copyAction != null)
                    {
                        isEmpty = false;
                        batchAction.addAction(copyAction);
                    }
                }
            }
            if (!isEmpty)
            {
                return(batchAction);
            }
            else
            {
                return(null);
            }
        }
Example #5
0
 public Selection(MapEditor editor)
 {
     this.editor = editor;
     this.session = null;
     this.subsession = null;
     this.busy = false;
     tiles = new List<Tile>();
 }
Example #6
0
 public void merge(BatchAction other)
 {
     foreach (Action action in other.actions)
     {
         actions.Add(action);
     }
     //  other.actions.Clear();
 }
Example #7
0
 public void redo()
 {
     if (current < actions.Count)
     {
         BatchAction batch = actions[current];
         editor.UpdateServer(batch, UpdateType.UPDATE_TYPE_REDO);
         foreach (Action action in batch.actions)
         {
             action.redo();
         }
         current++;
     }
 }
Example #8
0
 public void undo()
 {
     if (current > 0)
     {
         current--;
         BatchAction batch = actions[current];
         editor.UpdateServer(batch, UpdateType.UPDATE_TYPE_UNDO);
         foreach (Action action in batch.actions.Reverse <Action>())
         {
             action.undo();
         }
     }
 }
Example #9
0
 public void commit()
 {
     if (session != null)
     {
         Debug.Assert(subsession != null);
         // We need to step out of the session before we do the action, else peril awaits us!
         BatchAction tmp = session;
         session = null;
         // Do the action
         tmp.addAndCommitAction(subsession);
         
         subsession = new Action(editor);
         session = tmp;
     }
 }
Example #10
0
 public void start(int flags = 0)
 {
     if ((flags & SessionFlags.INTERNAL) == 0)
     {
         if ((flags & SessionFlags.SUBTHREAD) != 0)
         {
             ;
         }
         else
         {
             session = new BatchAction(ActionIdentifier .ACTION_SELECT);
         }
         subsession = new Action(editor);
     }            
     busy = true;
 }
Example #11
0
        public void addBatch(BatchAction batchAction, int stacking_delay)
        {
            if (batchAction == null)
            {
                return;
            }
            batchAction.commitActions();

            while (current != actions.Count)
            {
                BatchAction action = actions.Last();
                actions.Remove(action);
            }

            int undoSize = Settings.GetInteger(Key.UNDO_SIZE);

            if (undoSize < actions.Count)
            {
                actions.RemoveAt(0);
                current--;
            }

            //aqui tu vai adicionar numa fila de batchs pra commit, se ele atualiza o mapa aqui.
            //tem que atualizar no servidor igual
            //se ele voltar aqui agrupado, terá que voltar agrupado la também.
            //as rotinas vão ser as mesmas

            editor.UpdateServer(batchAction, UpdateType.UPDATE_TYPE_COMMIT);

            if (actions.Count > 0)
            {
                BatchAction lastAction = actions.Last <BatchAction>();
                if ((lastAction.type == batchAction.type) &&
                    (Settings.GetBoolean(Key.GROUP_ACTIONS)) &&
                    (DateTime.Now.AddSeconds(-stacking_delay) < lastAction.datetime))
                {
                    lastAction.merge(batchAction);
                    lastAction.datetime = DateTime.Now;
                    return;
                }
            }
            batchAction.datetime = DateTime.Now;
            actions.Add(batchAction);
            current++;
        }
Example #12
0
        public void cut(MapEditor editor, int floor)
        {
            if (editor.selection.size() == 0)
            {
                // gui.SetStatusText(wxT("No tiles to cut."));
                return;
            }

            clear();
            tiles = new GameMap();

            int tile_count = 0;
            int item_count = 0;

            copyPos = new Position(0xFFFF, 0xFFFF, floor);

            BatchAction batch  = new BatchAction(ActionIdentifier.ACTION_CUT_TILES);
            Action      action = new Action(editor);

            List <Position> tilestoborder = new List <Position>();

            foreach (Tile tile in editor.selection.getTiles())
            {
                tile_count++;

                Tile newtile     = tile.deepCopy();
                Tile copied_tile = new Tile(tile.getPosition());

                if ((tile.Ground != null) && tile.Ground.isSelected())
                {
                    copied_tile.house_id = newtile.house_id;
                    newtile.house_id     = 0;
                    copied_tile.setMapFlags(tile.getMapFlags());
                    newtile.setMapFlags(TileState.TILESTATE_NONE);
                }

                List <Item> tile_selection = newtile.popSelectedItems();
                foreach (Item iit in tile_selection)
                {
                    item_count++;
                    // Add items to copybuffer
                    copied_tile.addItem(iit);
                }

                if ((newtile.creature != null) && newtile.creature.isSelected())
                {
                    copied_tile.creature = newtile.creature;
                    newtile.creature     = null;
                }

                if ((newtile.spawn != null) && newtile.spawn.isSelected())
                {
                    copied_tile.spawn = newtile.spawn;
                    newtile.spawn     = null;
                }

                tiles.setTile(copied_tile.getPosition(), copied_tile);

                if (copied_tile.Position.X < copyPos.x)
                {
                    copyPos.x = copied_tile.Position.X;
                }

                if (copied_tile.Position.Y < copyPos.y)
                {
                    copyPos.y = copied_tile.Position.Y;
                }

                if (Settings.GetBoolean(Key.USE_AUTOMAGIC))
                {
                    for (int y = -2; y <= 2; y++)
                    {
                        for (int x = -2; x <= 2; x++)
                        {
                            tilestoborder.Add(new Position(tile.getX() + x, tile.getY() + y, tile.getZ()));
                        }
                    }
                }
                action.addChange(new Change(newtile));
            }

            batch.addAndCommitAction(action);

            // Remove duplicates
            //      tilestoborder.sort();
            //tilestoborder.unique();

            if (Settings.GetBoolean(Key.USE_AUTOMAGIC))
            {
                action = new Action(editor);
                foreach (Position it in tilestoborder)
                {
                    Tile tile = editor.map.getTile(it);
                    if (tile != null)
                    {
                        Tile new_tile = tile.deepCopy();
                        new_tile.borderize(editor.map);
                        new_tile.wallize(editor.map);
                        action.addChange(new Change(new_tile));
                    }
                    else
                    {
                        Tile new_tile = new Tile(it);
                        new_tile.borderize(editor.map);
                        if (new_tile.size() != 0)
                        {
                            action.addChange(new Change(new_tile));
                        }
                        else
                        {
                            new_tile = null;
                        }
                    }
                }

                batch.addAndCommitAction(action);
            }

            editor.addBatch(batch);
            //   std.stringstream ss = new std.stringstream();
            //ss << "Cut out " << tile_count << " tile" << (tile_count > 1 ? "s" : "") << " (" << item_count << " item" << (item_count > 1 ? "s" : "") << ")";
            //gui.SetStatusText(wxstr(ss.str()));
        }
Example #13
0
        public void paste(MapEditor editor, Position topos)
        {
            if (tiles == null)
            {
                return;
            }

            BatchAction batchAction = new BatchAction(ActionIdentifier.ACTION_PASTE_TILES);

            Action action = new Action(editor);

            foreach (Tile buffer_tile in tiles.getTiles().Values)
            {
                Position pos = buffer_tile.getPosition() - copyPos + topos;

                if (pos.isValid() == false)
                {
                    continue;
                }

                Tile copy_tile     = buffer_tile.deepCopy();
                Tile old_dest_tile = editor.map.getTile(pos);
                Tile new_dest_tile = null;

                if (Settings.GetBoolean(Key.MERGE_PASTE) || !(copy_tile.Ground != null))
                {
                    if (old_dest_tile != null)
                    {
                        new_dest_tile = old_dest_tile.deepCopy();
                    }
                    else
                    {
                        new_dest_tile = new Tile(pos);
                    }
                    new_dest_tile.merge(copy_tile);
                    copy_tile = null;
                }
                else
                {
                    // If the copied tile has ground, replace target tile
                    new_dest_tile      = copy_tile;
                    copy_tile.Position = pos;
                }

                action.addChange(new Change(new_dest_tile));
            }
            batchAction.addAndCommitAction(action);

            if (Settings.GetBoolean(Key.USE_AUTOMAGIC) && Settings.GetBoolean(Key.BORDERIZE_PASTE))
            {
                /*
                 * action = new Action(editor);
                 *
                 * List<Position> posToBorder = new List<Position>();
                 * foreach (Tile it in tiles.getTiles().Values)
                 * {
                 *   posToBorder.AddRange(Generic.getTilesToBorder(it.Position));
                 *
                 *
                 * }
                 *
                 * posToBorder = Generic.removeSamePosition(posToBorder);
                 *
                 * foreach (Position pos in posToBorder)
                 * {
                 *  Tile tile = editor.map.getTile(pos);
                 *  if (tile != null)
                 *  {
                 *      Tile newTile = tile.deepCopy();
                 *      newTile.borderize(editor.map);
                 *      action.addChange(new Change(newTile));
                 *  }
                 *  else
                 *  {
                 *      Tile newTile = new Tile(pos);
                 *      newTile.borderize(editor.map);
                 *      if (newTile.Items.Count > 0)
                 *      {
                 *          action.addChange(new Change(newTile));
                 *      }
                 *  }
                 * } */

                /*
                 * List<Tile> borderize_tiles = new List<Tile>();
                 * // Go through all modified (selected) tiles (might be slow)
                 * foreach(Tile it in tiles.getTiles().Values)
                 * {
                 *  bool add_me = false; // If this tile is touched
                 *  Position pos = it.getPosition() - copyPos + topos;
                 *  if (pos.z < 0 || pos.z >= 16)
                 *  {
                 *      continue;
                 *  }
                 *
                 *  // Go through all neighbours
                 *  Tile t;
                 *  t = editor.map.getTile(pos.x - 1, pos.y - 1, pos.z);
                 *  if (t != null && !t.isSelected())
                 *  {
                 *      borderize_tiles.Add(t);
                 *      add_me = true;
                 *  }
                 *  t = editor.map.getTile(pos.x, pos.y - 1, pos.z);
                 *  if (t != null && !t.isSelected())
                 *  {
                 *      borderize_tiles.Add(t);
                 *      add_me = true;
                 *  }
                 *  t = editor.map.getTile(pos.x + 1, pos.y - 1, pos.z);
                 *  if (t != null && !t.isSelected())
                 *  {
                 *      borderize_tiles.Add(t);
                 *      add_me = true;
                 *  }
                 *  t = editor.map.getTile(pos.x - 1, pos.y, pos.z);
                 *  if (t != null && !t.isSelected())
                 *  {
                 *      borderize_tiles.Add(t);
                 *      add_me = true;
                 *  }
                 *  t = editor.map.getTile(pos.x + 1, pos.y, pos.z);
                 *  if (t != null && !t.isSelected())
                 *  {
                 *      borderize_tiles.Add(t);
                 *      add_me = true;
                 *  }
                 *  t = editor.map.getTile(pos.x - 1, pos.y + 1, pos.z);
                 *  if (t != null && !t.isSelected())
                 *  {
                 *      borderize_tiles.Add(t);
                 *      add_me = true;
                 *  }
                 *  t = editor.map.getTile(pos.x, pos.y + 1, pos.z);
                 *  if (t != null && !t.isSelected())
                 *  {
                 *      borderize_tiles.Add(t);
                 *      add_me = true;
                 *  }
                 *  t = editor.map.getTile(pos.x + 1, pos.y + 1, pos.z);
                 *  if (t != null && !t.isSelected())
                 *  {
                 *      borderize_tiles.Add(t);
                 *      add_me = true;
                 *  }
                 *  if (add_me)
                 *  {
                 *      borderize_tiles.Add(editor.map.getTile(pos));
                 *  }
                 * }
                 * // Remove duplicates
                 * //     borderize_tiles.sort();
                 * //borderize_tiles.unique();
                 *
                 * // Do le borders!
                 * foreach(Tile tile in borderize_tiles)
                 * {
                 *  if (tile.Ground != null)
                 *  {
                 *      if (tile.Ground.getGroundBrush() != null)
                 *      {
                 *          Tile new_tile = tile.deepCopy();
                 *          new_tile.borderize(editor.map);
                 *          if (tile.Ground.isSelected())
                 *          {
                 *              new_tile.selectGround();
                 *          }
                 *          new_tile.wallize(editor.map);
                 *          action.addChange(new Change(new_tile));
                 *      }
                 *  }
                 * }
                 * // Commit changes to map
                 */
                //   batchAction.addAndCommitAction(action);
            }

            editor.addBatch(batchAction);
        }