Exemplo n.º 1
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 Redo()
        {
            LevelEditorLogger.Log("Redo");

            if (counter < actionHistory.Count)
            {
                IUndoAction action = actionHistory[counter];
                action.Redo(this);
                counter++;

                OnRedo?.Invoke(action);
            }
        }
Exemplo n.º 3
0
        internal bool TryRedo(out string message, out bool sound)
        {
            sound   = false;
            message = "";
            if (redoStack.Count <= 0)
            {
                sound   = true;
                message = "RedoHistoryEmptyMessage";
                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 = redoStack.Pop();

            bool success = false;

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

            if (success)
            {
                message = "RedoSuccessText";
                undoStack.Push(action);
            }
            else
            {
                sound   = true;
                message = "RedoFailureText";
                notifyBuildListeners.Remove(action);
                notifyDismantleListeners.Remove(action);
            }

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