예제 #1
0
    public static void HandleAction(EditorAction action, bool redo)
    {
        if (redo)
        {
            switch (action.type)
            {
            case EditorAction.ActionType.EnvironmentChanged:
                // set map environment settings to new settings
                EnvironmentChanged ec = action as EnvironmentChanged;
                EditorMain.instance.LoadedMap.AmbientColor   = ec.newAmbientColor;
                EditorMain.instance.LoadedMap.BaseplateColor = ec.newBaseplateColor;
                EditorMain.instance.LoadedMap.SkyColor       = ec.newSkyColor;
                EditorMain.instance.LoadedMap.BaseplateSize  = ec.newBaseplateSize;
                EditorMain.instance.LoadedMap.SunIntensity   = ec.newSunIntensity;
                MapBuilder.instance.UpdateEnvironment(EditorMain.instance.LoadedMap);
                break;

            case EditorAction.ActionType.ElementsAdded:
                // add elements
                ElementsAdded ea = action as ElementsAdded;
                if (ea.bricksAdded != null)
                {
                    for (int i = 0; i < ea.bricksAdded.Length; i++)
                    {
                        EditorUI.instance.ImportBrick(ea.bricksAdded[i].ToBrick(false));
                    }
                }
                if (ea.groupsAdded != null)
                {
                    for (int i = 0; i < ea.groupsAdded.Length; i++)
                    {
                        EditorUI.instance.ImportGroup(ea.groupsAdded[i].ToGroup(false));
                    }
                }
                break;

            case EditorAction.ActionType.ElementsChanged:
                // set element settings to new settings
                ElementsChanged elc = action as ElementsChanged;
                for (int i = 0; i < elc.oldBricks.Length; i++)
                {
                    EditorMain.instance.SetBrickProperties(elc.newBricks[i], elc.oldBricks[i].ID);
                    EditorUI.instance.UpdateElement(elc.oldBricks[i].ID);
                }
                EditorUI.instance.UpdateInspector();
                break;

            case EditorAction.ActionType.ElementsRemoved:
                // remove elements
                ElementsRemoved er = action as ElementsRemoved;
                if (er.bricksRemoved != null)
                {
                    for (int i = 0; i < er.bricksRemoved.Length; i++)
                    {
                        EditorUI.instance.DeleteElement(er.bricksRemoved[i].ID);
                    }
                }
                if (er.groupsRemoved != null)
                {
                    for (int i = 0; i < er.groupsRemoved.Length; i++)
                    {
                        EditorUI.instance.DeleteElement(er.groupsRemoved[i].ID);
                    }
                }
                break;

            case EditorAction.ActionType.GenericMapChange:
                // load new saved map
                break;
            }
        }
        else
        {
            switch (action.type)
            {
            case EditorAction.ActionType.EnvironmentChanged:
                // revert map environment settings to old settings
                EnvironmentChanged ec = action as EnvironmentChanged;
                EditorMain.instance.LoadedMap.AmbientColor   = ec.oldAmbientColor;
                EditorMain.instance.LoadedMap.BaseplateColor = ec.oldBaseplateColor;
                EditorMain.instance.LoadedMap.SkyColor       = ec.oldSkyColor;
                EditorMain.instance.LoadedMap.BaseplateSize  = ec.oldBaseplateSize;
                EditorMain.instance.LoadedMap.SunIntensity   = ec.oldSunIntensity;
                MapBuilder.instance.UpdateEnvironment(EditorMain.instance.LoadedMap);
                break;

            case EditorAction.ActionType.ElementsAdded:
                // remove added elements
                ElementsAdded ea = action as ElementsAdded;
                if (ea.bricksAdded != null)
                {
                    for (int i = 0; i < ea.bricksAdded.Length; i++)
                    {
                        EditorUI.instance.DeleteElement(ea.bricksAdded[i].ID);
                    }
                }
                if (ea.groupsAdded != null)
                {
                    for (int i = 0; i < ea.groupsAdded.Length; i++)
                    {
                        EditorUI.instance.DeleteElement(ea.groupsAdded[i].ID);
                    }
                }
                break;

            case EditorAction.ActionType.ElementsChanged:
                // revert element settings to old settings
                ElementsChanged elc = action as ElementsChanged;
                for (int i = 0; i < elc.newBricks.Length; i++)
                {
                    EditorMain.instance.SetBrickProperties(elc.oldBricks[i], elc.newBricks[i].ID);
                    EditorUI.instance.UpdateElement(elc.newBricks[i].ID);
                }
                EditorUI.instance.UpdateInspector();
                break;

            case EditorAction.ActionType.ElementsRemoved:
                // add removed elements
                ElementsRemoved er = action as ElementsRemoved;
                if (er.bricksRemoved != null)
                {
                    for (int i = 0; i < er.bricksRemoved.Length; i++)
                    {
                        EditorUI.instance.ImportBrick(er.bricksRemoved[i].ToBrick(false));
                    }
                }
                if (er.groupsRemoved != null)
                {
                    for (int i = 0; i < er.groupsRemoved.Length; i++)
                    {
                        EditorUI.instance.ImportGroup(er.groupsRemoved[i].ToGroup(false));
                    }
                }
                break;

            case EditorAction.ActionType.GenericMapChange:
                // load old saved map
                GenericMapChange gmc = action as GenericMapChange;
                break;
            }
        }
    }
예제 #2
0
 /// <summary>
 /// Fires the ElementsRemoved event
 /// </summary>
 public void FireElementsRemoved(List <ProjectLayoutElement> listRemovedElements)
 {
     ElementsRemoved?.Invoke(this, new ElementEventArgs(listRemovedElements));
 }