Exemplo n.º 1
0
        private void OnActionDone(IUndoAction action)
        {
            if (Session == null)
            {
                return;
            }

            // Don't send actions during play mode
            if (IsPlayMode)
            {
                return;
            }

            if (action is SelectionChangeAction selectionAction)
            {
                if (selectionAction.Data.After.Length != 0 && !Session.CanSelect(selectionAction.Data.After[0].ID))
                {
                    action.Undo();
                    return;
                }
            }

            Packet p = new GenericUndoActionPacket(action);

            Session.SendPacket(p);
        }
Exemplo n.º 2
0
        private void UndoRedo(Stack <IUndoAction> pop_from, Stack <IUndoAction> push_to, bool is_undo)
        {
            if (pop_from.Count == 0)
            {
                return;
            }

            IUndoAction action = pop_from.Pop();

            frozen_count++;
            if (is_undo)
            {
                action.Undo();
            }
            else
            {
                action.Redo();
            }
            frozen_count--;

            push_to.Push(action);

            try_merge = true;

            if (pop_from.Count == 0 || push_to.Count == 1)
            {
                OnUndoChanged();
            }
        }
        public void Undo()
        {
            LevelEditorLogger.Log("Undo");

            if (counter > 0)
            {
                counter--;
                IUndoAction action = actionHistory[counter];
                action.Undo(this);

                OnUndo?.Invoke(action);
            }
        }
Exemplo n.º 4
0
        internal bool TryUndo(out string message, out bool sound)
        {
            sound   = false;
            message = "";
            if (undoStack.Count <= 0)
            {
                sound   = true;
                message = "UndoHistoryEmptyMessage";
                return(true);
            }
            if (GameMain.localPlanet?.factory == null)
            {
                return(false);
            }
            if (GameMain.mainPlayer?.controller == null)
            {
                return(false);
            }

            PlanetFactory      factory     = GameMain.localPlanet.factory;
            PlayerAction_Build actionBuild = GameMain.mainPlayer.controller.actionBuild;

            IUndoAction action = undoStack.Pop();

            bool success = false;

            try
            {
                success = action.Undo(factory, actionBuild);
            }
            catch (Exception e)
            {
                BlueprintTweaksPlugin.logger.LogWarning($"Failed to undo, message: {e.Message}, stacktrace:\n{e.StackTrace}");
            }

            if (success)
            {
                message = "UndoSuccessText";
                redoStack.Push(action);
            }
            else
            {
                message = "UndoFailureText";
                sound   = true;
                notifyBuildListeners.Remove(action);
                notifyDismantleListeners.Remove(action);
            }

            return(true);
        }
Exemplo n.º 5
0
 public void Undo()
 {
     try
     {
         if (undoStack.Count > 0)
         {
             IUndoAction action = undoStack.Pop();
             redoStack.Push(action);
             action.Undo();
         }
     }
     catch (Exception ex)
     {
         _log.Error(ex.Message, ex);
     }
 }