Пример #1
0
        private void ChangeProperty(object prop, Entity selection, object obj, object newval,
                                    ref bool committed, bool shouldUpdateVisual, bool destroyRenderModel, int arrayindex = -1)
        {
            if (prop == _changingPropery && _lastUncommittedAction != null && ContextActionManager.PeekUndoAction() == _lastUncommittedAction)
            {
                ContextActionManager.UndoAction();
            }
            else
            {
                _lastUncommittedAction = null;
            }

            if (_changingObject != null && selection != null && selection.WrappedObject != _changingObject)
            {
                committed = true;
            }
            else
            {
                PropertiesChangedAction action;
                if (arrayindex != -1)
                {
                    action = new PropertiesChangedAction((PropertyInfo)prop, arrayindex, obj, newval);
                }
                else
                {
                    action = new PropertiesChangedAction((PropertyInfo)prop, obj, newval);
                }
                if (shouldUpdateVisual && selection != null)
                {
                    action.SetPostExecutionAction((undo) =>
                    {
                        if (destroyRenderModel)
                        {
                            if (selection.RenderSceneMesh != null)
                            {
                                selection.RenderSceneMesh.Dispose();
                                selection.RenderSceneMesh = null;
                            }
                        }
                        selection.UpdateRenderModel();
                    });
                }
                ContextActionManager.ExecuteAction(action);

                _lastUncommittedAction = action;
                _changingPropery       = prop;
                // ChangingObject = selection.MsbObject;
                _changingObject = selection != null ? selection.WrappedObject : obj;
            }
        }
Пример #2
0
        public static MassEditResult PerformMassEdit(string commandsString, ActionManager actionManager, string contextActiveParam, List <PARAM.Row> contextActiveRows)
        {
            string[]      commands    = commandsString.Split('\n');
            int           changeCount = 0;
            List <Action> actions     = new List <Action>();

            foreach (string command in commands)
            {
                Match comm = commandRx.Match(command);
                if (comm.Success)
                {
                    Group  paramrx = comm.Groups["paramrx"];
                    Regex  fieldRx = new Regex($@"^{comm.Groups["fieldrx"].Value}$");
                    string op      = comm.Groups["op"].Value;
                    string opparam = comm.Groups["opparam"].Value;

                    List <PARAM> affectedParams = new List <PARAM>();
                    if (paramrx.Success)
                    {
                        affectedParams = GetMatchingParams(new Regex($@"^{paramrx.Value}$"));
                    }
                    else
                    {
                        affectedParams.Add(ParamBank.Params[contextActiveParam]);
                    }

                    List <PARAM.Row> affectedRows = new List <PARAM.Row>();
                    foreach (PARAM param in affectedParams)
                    {
                        if (!paramrx.Success)
                        {
                            affectedRows = contextActiveRows;
                        }
                        else
                        {
                            affectedRows.AddRange(GetMatchingParamRows(param, comm, false, false));
                        }
                    }

                    List <PARAM.Cell> affectedCells = GetMatchingCells(affectedRows, fieldRx);
                    changeCount += affectedCells.Count;
                    foreach (PARAM.Cell cell in affectedCells)
                    {
                        object newval = PerformOperation(cell, op, opparam);
                        if (newval == null)
                        {
                            return(new MassEditResult(MassEditResultType.OPERATIONERROR, $@"Could not perform operation {op} {opparam} on field {cell.Def.DisplayName}"));
                        }
                        actions.Add(new PropertiesChangedAction(cell.GetType().GetProperty("Value"), -1, cell, newval));
                    }
                }
                else
                {
                    return(new MassEditResult(MassEditResultType.PARSEERROR, $@"Unrecognised command {command}"));
                }
            }
            actionManager.ExecuteAction(new CompoundAction(actions));
            return(new MassEditResult(MassEditResultType.SUCCESS, $@"{changeCount} cells affected"));
        }
Пример #3
0
 private void ChangeProperty(object prop, object obj, object newval,
                             ref bool committed, int arrayindex = -1)
 {
     if (committed)
     {
         PropertiesChangedAction action;
         if (arrayindex != -1)
         {
             action = new PropertiesChangedAction((PropertyInfo)prop, arrayindex, obj, newval);
         }
         else
         {
             action = new PropertiesChangedAction((PropertyInfo)prop, obj, newval);
         }
         ContextActionManager.ExecuteAction(action);
     }
 }
Пример #4
0
        public void Update(Ray ray, bool canCaptureMouse)
        {
            if (IsTransforming)
            {
                if (!InputTracker.GetMouseButton(MouseButton.Left))
                {
                    IsTransforming = false;
                    var actlist = new List <Action>();
                    foreach (var sel in _selection.GetFilteredSelection <Entity>((o) => o.HasTransform))
                    {
                        sel.ClearTemporaryTransform(false);
                        actlist.Add(sel.GetUpdateTransformAction(ProjectTransformDelta(sel.GetLocalTransform())));
                    }
                    var action = new CompoundAction(actlist);
                    ActionManager.ExecuteAction(action);
                }
                else
                {
                    if (Mode == GizmosMode.Translate)
                    {
                        var delta = GetSingleAxisProjection(ray, OriginalTransform, TransformAxis) - OriginProjection;
                        CurrentTransform.Position = OriginalTransform.Position + delta;
                    }
                    else if (Mode == GizmosMode.Rotate)
                    {
                        Vector3 axis = Vector3.Zero;
                        switch (TransformAxis)
                        {
                        case Axis.PosX:
                            axis = Vector3.Transform(new Vector3(1.0f, 0.0f, 0.0f), OriginalTransform.Rotation);
                            break;

                        case Axis.PosY:
                            axis = Vector3.Transform(new Vector3(0.0f, 1.0f, 0.0f), OriginalTransform.Rotation);
                            break;

                        case Axis.PosZ:
                            axis = Vector3.Transform(new Vector3(0.0f, 0.0f, 1.0f), OriginalTransform.Rotation);
                            break;
                        }
                        axis = Vector3.Normalize(axis);
                        var   newproj   = GetAxisPlaneProjection(ray, OriginalTransform, TransformAxis);
                        var   delta     = Vector3.Normalize(newproj - OriginalTransform.Position);
                        var   deltaorig = Vector3.Normalize(OriginProjection - OriginalTransform.Position);
                        var   side      = Vector3.Cross(axis, deltaorig);
                        float y         = Math.Max(-1.0f, Math.Min(1.0f, Vector3.Dot(delta, deltaorig)));
                        float x         = Math.Max(-1.0f, Math.Min(1.0f, Vector3.Dot(delta, side)));
                        float angle     = (float)Math.Atan2(x, y);
                        DebugAxis  = axis;
                        DebugAngle = angle;
                        //CurrentTransform.EulerRotation.Y = OriginalTransform.EulerRotation.Y + angle;
                        CurrentTransform.Rotation = Quaternion.Normalize(Quaternion.CreateFromAxisAngle(axis, angle) * OriginalTransform.Rotation);
                    }
                    if (_selection.IsSelection())
                    {
                        //Selection.GetSingleSelection().SetTemporaryTransform(CurrentTransform);
                        foreach (var sel in _selection.GetFilteredSelection <Entity>((o) => o.HasTransform))
                        {
                            sel.SetTemporaryTransform(ProjectTransformDelta(sel.GetLocalTransform()));
                        }
                    }
                }
            }
            if (!IsTransforming)
            {
                if (_selection.IsFilteredSelection <Entity>((o) => o.HasTransform))
                {
                    if (_selection.IsSingleFilteredSelection <Entity>((o) => o.HasTransform))
                    {
                        var sel = _selection.GetSingleFilteredSelection <Entity>((o) => o.HasTransform);
                        OriginalTransform = sel.GetLocalTransform();
                        if (Origin == GizmosOrigin.BoundingBox && sel.RenderSceneMesh != null)
                        {
                            OriginalTransform.Position = sel.RenderSceneMesh.GetBounds().GetCenter();
                        }
                        if (Space == GizmosSpace.World)
                        {
                            OriginalTransform.Rotation = Quaternion.Identity;
                        }
                    }
                    else
                    {
                        // Average the positions of the selections and use a neutral rotation
                        Vector3 accumPos = Vector3.Zero;
                        foreach (var sel in _selection.GetFilteredSelection <Entity>((o) => o.HasTransform))
                        {
                            accumPos += sel.GetLocalTransform().Position;
                        }
                        OriginalTransform = new Transform(accumPos / (float)_selection.GetSelection().Count, Vector3.Zero);
                    }

                    Axis hoveredAxis = Axis.None;
                    switch (Mode)
                    {
                    case GizmosMode.Translate:
                        if (TranslateGizmoX.GetRaycast(ray, TranslateGizmoXProxy.World))
                        {
                            hoveredAxis = Axis.PosX;
                        }
                        else if (TranslateGizmoY.GetRaycast(ray, TranslateGizmoYProxy.World))
                        {
                            hoveredAxis = Axis.PosY;
                        }
                        else if (TranslateGizmoZ.GetRaycast(ray, TranslateGizmoZProxy.World))
                        {
                            hoveredAxis = Axis.PosZ;
                        }
                        TranslateGizmoXProxy.RenderSelectionOutline = (hoveredAxis == Axis.PosX);
                        TranslateGizmoYProxy.RenderSelectionOutline = (hoveredAxis == Axis.PosY);
                        TranslateGizmoZProxy.RenderSelectionOutline = (hoveredAxis == Axis.PosZ);
                        break;

                    case GizmosMode.Rotate:
                        if (RotateGizmoX.GetRaycast(ray, RotateGizmoXProxy.World))
                        {
                            hoveredAxis = Axis.PosX;
                        }
                        else if (RotateGizmoY.GetRaycast(ray, RotateGizmoYProxy.World))
                        {
                            hoveredAxis = Axis.PosY;
                        }
                        else if (RotateGizmoZ.GetRaycast(ray, RotateGizmoZProxy.World))
                        {
                            hoveredAxis = Axis.PosZ;
                        }
                        RotateGizmoXProxy.RenderSelectionOutline = (hoveredAxis == Axis.PosX);
                        RotateGizmoYProxy.RenderSelectionOutline = (hoveredAxis == Axis.PosY);
                        RotateGizmoZProxy.RenderSelectionOutline = (hoveredAxis == Axis.PosZ);
                        break;
                    }


                    if (canCaptureMouse && InputTracker.GetMouseButtonDown(MouseButton.Left))
                    {
                        if (hoveredAxis != Axis.None)
                        {
                            IsTransforming   = true;
                            TransformAxis    = hoveredAxis;
                            CurrentTransform = OriginalTransform;
                            if (Mode == GizmosMode.Rotate)
                            {
                                OriginProjection = GetAxisPlaneProjection(ray, OriginalTransform, TransformAxis);
                            }
                            else
                            {
                                OriginProjection = GetSingleAxisProjection(ray, OriginalTransform, TransformAxis);
                            }
                        }
                    }
                }
            }

            // Update gizmos transform and visibility
            if (_selection.IsSelection())
            {
                //var selected = MsbEditor.Selection.Selected;
                //var center = selected.RenderSceneMesh.GetBounds().GetCenter();
                //var center = selected.RenderSceneMesh.WorldMatrix.Translation;
                Vector3    center;
                Quaternion rot;
                if (IsTransforming)
                {
                    center = CurrentTransform.Position;
                    rot    = CurrentTransform.Rotation;
                }
                else
                {
                    center = OriginalTransform.Position;
                    rot    = OriginalTransform.Rotation;
                }
                float   dist  = (center - CameraPosition).Length();
                Vector3 scale = new Vector3(dist * 0.04f);
                TranslateGizmoXProxy.World = new Transform(center, rot, scale).WorldMatrix;
                TranslateGizmoYProxy.World = new Transform(center, rot, scale).WorldMatrix;
                TranslateGizmoZProxy.World = new Transform(center, rot, scale).WorldMatrix;
                RotateGizmoXProxy.World    = new Transform(center, rot, scale).WorldMatrix;
                RotateGizmoYProxy.World    = new Transform(center, rot, scale).WorldMatrix;
                RotateGizmoZProxy.World    = new Transform(center, rot, scale).WorldMatrix;

                if (Mode == GizmosMode.Translate)
                {
                    TranslateGizmoXProxy.Visible = true;
                    TranslateGizmoYProxy.Visible = true;
                    TranslateGizmoZProxy.Visible = true;
                    RotateGizmoXProxy.Visible    = false;
                    RotateGizmoYProxy.Visible    = false;
                    RotateGizmoZProxy.Visible    = false;
                }
                else
                {
                    TranslateGizmoXProxy.Visible = false;
                    TranslateGizmoYProxy.Visible = false;
                    TranslateGizmoZProxy.Visible = false;
                    RotateGizmoXProxy.Visible    = true;
                    RotateGizmoYProxy.Visible    = true;
                    RotateGizmoZProxy.Visible    = true;
                }
            }
            else
            {
                TranslateGizmoXProxy.Visible = false;
                TranslateGizmoYProxy.Visible = false;
                TranslateGizmoZProxy.Visible = false;
                RotateGizmoXProxy.Visible    = false;
                RotateGizmoYProxy.Visible    = false;
                RotateGizmoZProxy.Visible    = false;
            }
        }
Пример #5
0
 public static MassEditResult PerformMassEdit(string csvString, ActionManager actionManager, string param)
 {
     try
     {
         PARAM p = ParamBank.Params[param];
         if (p == null)
         {
             return(new MassEditResult(MassEditResultType.PARSEERROR, "No Param selected"));
         }
         int              csvLength   = p.AppliedParamdef.Fields.Count + 2;// Include ID and name
         string[]         csvLines    = csvString.Split('\n');
         int              changeCount = 0;
         int              addedCount  = 0;
         List <Action>    actions     = new List <Action>();
         List <PARAM.Row> addedParams = new List <PARAM.Row>();
         foreach (string csvLine in csvLines)
         {
             if (csvLine.Trim().Equals(""))
             {
                 continue;
             }
             string[] csvs = csvLine.Split(',');
             if (csvs.Length != csvLength || csvs.Length < 2)
             {
                 return(new MassEditResult(MassEditResultType.PARSEERROR, "CSV has wrong number of values"));
             }
             int       id   = int.Parse(csvs[0]);
             string    name = csvs[1];
             PARAM.Row row  = p[id];
             if (row == null)
             {
                 row = new PARAM.Row(id, name, p.AppliedParamdef);
                 addedParams.Add(row);
             }
             if (row.Name == null || !row.Name.Equals(name))
             {
                 actions.Add(new PropertiesChangedAction(row.GetType().GetProperty("Name"), -1, row, name));
             }
             int index = 2;
             foreach (PARAM.Cell c in row.Cells)
             {
                 string v = csvs[index];
                 index++;
                 // Array types are unhandled
                 if (c.Value.GetType().IsArray)
                 {
                     continue;
                 }
                 object newval = PerformOperation(c, "=", v);
                 if (newval == null)
                 {
                     return(new MassEditResult(MassEditResultType.OPERATIONERROR, $@"Could not assign {v} to field {c.Def.DisplayName}"));
                 }
                 if (!c.Value.Equals(newval))
                 {
                     actions.Add(new PropertiesChangedAction(c.GetType().GetProperty("Value"), -1, c, newval));
                 }
             }
         }
         changeCount = actions.Count;
         addedCount  = addedParams.Count;
         actions.Add(new AddParamsAction(p, "legacystring", addedParams, false));
         if (changeCount != 0 || addedCount != 0)
         {
             actionManager.ExecuteAction(new CompoundAction(actions));
         }
         return(new MassEditResult(MassEditResultType.SUCCESS, $@"{changeCount} cells affected, {addedCount} rows added"));
     }
     catch (FormatException e)
     {
         return(new MassEditResult(MassEditResultType.PARSEERROR, "Unable to parse CSV into correct data types"));
     }
 }
Пример #6
0
        public void OnGui()
        {
            ImGui.PushStyleColor(ImGuiCol.ChildBg, new Vector4(0.145f, 0.145f, 0.149f, 1.0f));
            if (_configuration == Configuration.MapEditor)
            {
                ImGui.PushStyleVar(ImGuiStyleVar.WindowPadding, new Vector2(0.0f, 0.0f));
            }
            else
            {
                ImGui.PushStyleVar(ImGuiStyleVar.WindowPadding, new Vector2(0.0f, 2.0f));
            }
            string titleString = _configuration == Configuration.MapEditor ? $@"Map Object List##{_id}" : $@"Model Hierarchy##{_id}";

            if (ImGui.Begin(titleString))
            {
                if (_initiatedDragDrop)
                {
                    _initiatedDragDrop = false;
                    _pendingDragDrop   = true;
                }
                if (_pendingDragDrop && ImGui.IsMouseReleased(ImGuiMouseButton.Left))
                {
                    _pendingDragDrop = false;
                }

                ImGui.PopStyleVar();
                ImGui.SetNextItemWidth(-1);
                if (_configuration == Configuration.MapEditor)
                {
                    int mode = (int)_viewMode;
                    if (ImGui.Combo("##typecombo", ref mode, _viewModeStrings, _viewModeStrings.Length))
                    {
                        _viewMode = (ViewMode)mode;
                    }
                }

                ImGui.BeginChild("listtree");
                Map pendingUnload = null;
                foreach (var lm in _universe.LoadedObjectContainers.OrderBy((k) => k.Key))
                {
                    var map       = lm.Value;
                    var mapid     = lm.Key;
                    var treeflags = ImGuiTreeNodeFlags.OpenOnArrow | ImGuiTreeNodeFlags.SpanAvailWidth;
                    if (map != null && _selection.GetSelection().Contains(map.RootObject))
                    {
                        treeflags |= ImGuiTreeNodeFlags.Selected;
                    }
                    bool   nodeopen = false;
                    string unsaved  = (map != null && map.HasUnsavedChanges) ? "*" : "";
                    if (map != null)
                    {
                        nodeopen = ImGui.TreeNodeEx($@"{ForkAwesome.Cube} {mapid}", treeflags, $@"{ForkAwesome.Cube} {mapid}{unsaved}");
                    }
                    else
                    {
                        ImGui.Selectable($@"   {ForkAwesome.Cube} {mapid}", false);
                    }
                    // Right click context menu
                    if (ImGui.BeginPopupContextItem($@"mapcontext_{mapid}"))
                    {
                        if (map == null)
                        {
                            if (ImGui.Selectable("Load Map"))
                            {
                                _universe.LoadMap(mapid);
                            }
                        }
                        else if (map is Map m)
                        {
                            if (ImGui.Selectable("Save Map"))
                            {
                                try
                                {
                                    _universe.SaveMap(m);
                                }
                                catch (SavingFailedException e)
                                {
                                    System.Windows.Forms.MessageBox.Show(e.Wrapped.Message, e.Message,
                                                                         System.Windows.Forms.MessageBoxButtons.OK,
                                                                         System.Windows.Forms.MessageBoxIcon.None);
                                }
                            }
                            if (ImGui.Selectable("Unload Map"))
                            {
                                _selection.ClearSelection();
                                _editorActionManager.Clear();
                                pendingUnload = m;
                            }
                        }
                        ImGui.EndPopup();
                    }
                    if (ImGui.IsItemClicked() && map != null)
                    {
                        _pendingClick = map.RootObject;
                    }
                    if (map != null && _pendingClick == map.RootObject && ImGui.IsMouseReleased(ImGuiMouseButton.Left))
                    {
                        if (ImGui.IsItemHovered())
                        {
                            // Only select if a node is not currently being opened/closed
                            if ((nodeopen && _treeOpenEntities.Contains(map.RootObject)) ||
                                (!nodeopen && !_treeOpenEntities.Contains(map.RootObject)))
                            {
                                if (InputTracker.GetKey(Key.ShiftLeft) || InputTracker.GetKey(Key.ShiftRight))
                                {
                                    _selection.AddSelection(map.RootObject);
                                }
                                else
                                {
                                    _selection.ClearSelection();
                                    _selection.AddSelection(map.RootObject);
                                }
                            }

                            // Update the open/closed state
                            if (nodeopen && !_treeOpenEntities.Contains(map.RootObject))
                            {
                                _treeOpenEntities.Add(map.RootObject);
                            }
                            else if (!nodeopen && _treeOpenEntities.Contains(map.RootObject))
                            {
                                _treeOpenEntities.Remove(map.RootObject);
                            }
                        }
                        _pendingClick = null;
                    }
                    if (nodeopen)
                    {
                        if (_pendingDragDrop)
                        {
                            ImGui.PushStyleVar(ImGuiStyleVar.ItemSpacing, new Vector2(8.0f, 0.0f));
                        }
                        else
                        {
                            ImGui.PushStyleVar(ImGuiStyleVar.ItemSpacing, new Vector2(8.0f, 3.0f));
                        }
                        if (_viewMode == ViewMode.Hierarchy)
                        {
                            HierarchyView(map.RootObject);
                        }
                        else if (_viewMode == ViewMode.Flat)
                        {
                            FlatView((Map)map);
                        }
                        else if (_viewMode == ViewMode.ObjectType)
                        {
                            TypeView((Map)map);
                        }
                        ImGui.PopStyleVar();
                        ImGui.TreePop();
                    }
                }
                if (_assetLocator.Type == GameType.Bloodborne && _configuration == Configuration.MapEditor)
                {
                    ChaliceDungeonImportButton();
                }
                ImGui.EndChild();

                if (_dragDropSources.Count > 0)
                {
                    if (_dragDropDestObjects.Count > 0)
                    {
                        var action = new ChangeEntityHierarchyAction(_universe, _dragDropSources, _dragDropDestObjects, _dragDropDests, false);
                        _editorActionManager.ExecuteAction(action);
                        _dragDropSources.Clear();
                        _dragDropDests.Clear();
                        _dragDropDestObjects.Clear();
                    }
                    else
                    {
                        var action = new ReorderContainerObjectsAction(_universe, _dragDropSources, _dragDropDests, false);
                        _editorActionManager.ExecuteAction(action);
                        _dragDropSources.Clear();
                        _dragDropDests.Clear();
                    }
                }

                if (pendingUnload != null)
                {
                    _universe.UnloadMap(pendingUnload);
                    GC.Collect();
                    GC.WaitForPendingFinalizers();
                    GC.Collect();
                    _GCNeedsCollection = true;
                    Resource.ResourceManager.UnloadUnusedResources();
                    GC.Collect();
                    GC.WaitForPendingFinalizers();
                    GC.Collect();
                }
            }
            else
            {
                ImGui.PopStyleVar();
            }
            ImGui.End();
            ImGui.PopStyleColor();
        }
Пример #7
0
        public override void DrawEditorMenu()
        {
            if (ImGui.BeginMenu("Edit"))
            {
                if (ImGui.MenuItem("Undo", "CTRL+Z", false, EditorActionManager.CanUndo()))
                {
                    EditorActionManager.UndoAction();
                }
                if (ImGui.MenuItem("Redo", "Ctrl+Y", false, EditorActionManager.CanRedo()))
                {
                    EditorActionManager.RedoAction();
                }
                if (ImGui.MenuItem("Delete", "Delete", false, _selection.IsSelection()))
                {
                    var action = new DeleteMapObjectsAction(Universe, RenderScene, _selection.GetFilteredSelection <MapEntity>().ToList(), true);
                    EditorActionManager.ExecuteAction(action);
                }
                if (ImGui.MenuItem("Duplicate", "Ctrl+D", false, _selection.IsSelection()))
                {
                    var action = new CloneMapObjectsAction(Universe, RenderScene, _selection.GetFilteredSelection <MapEntity>().ToList(), true);
                    EditorActionManager.ExecuteAction(action);
                }
                ImGui.EndMenu();
            }

            if (ImGui.BeginMenu("Display"))
            {
                if (ImGui.MenuItem("Grid", "", Viewport.DrawGrid))
                {
                    Viewport.DrawGrid = !Viewport.DrawGrid;
                }
                if (ImGui.BeginMenu("Object Types"))
                {
                    if (ImGui.MenuItem("Debug", "", RenderScene.DrawFilter.HasFlag(Scene.RenderFilter.Debug)))
                    {
                        RenderScene.ToggleDrawFilter(Scene.RenderFilter.Debug);
                    }
                    if (ImGui.MenuItem("Map Piece", "", RenderScene.DrawFilter.HasFlag(Scene.RenderFilter.MapPiece)))
                    {
                        RenderScene.ToggleDrawFilter(Scene.RenderFilter.MapPiece);
                    }
                    if (ImGui.MenuItem("Collision", "", RenderScene.DrawFilter.HasFlag(Scene.RenderFilter.Collision)))
                    {
                        RenderScene.ToggleDrawFilter(Scene.RenderFilter.Collision);
                    }
                    if (ImGui.MenuItem("Object", "", RenderScene.DrawFilter.HasFlag(Scene.RenderFilter.Object)))
                    {
                        RenderScene.ToggleDrawFilter(Scene.RenderFilter.Object);
                    }
                    if (ImGui.MenuItem("Character", "", RenderScene.DrawFilter.HasFlag(Scene.RenderFilter.Character)))
                    {
                        RenderScene.ToggleDrawFilter(Scene.RenderFilter.Character);
                    }
                    if (ImGui.MenuItem("Navmesh", "", RenderScene.DrawFilter.HasFlag(Scene.RenderFilter.Navmesh)))
                    {
                        RenderScene.ToggleDrawFilter(Scene.RenderFilter.Navmesh);
                    }
                    if (ImGui.MenuItem("Region", "", RenderScene.DrawFilter.HasFlag(Scene.RenderFilter.Region)))
                    {
                        RenderScene.ToggleDrawFilter(Scene.RenderFilter.Region);
                    }
                    ImGui.EndMenu();
                }
                if (ImGui.BeginMenu("Display Presets"))
                {
                    if (ImGui.MenuItem("Map Piece/Character/Objects", "Ctrl-1"))
                    {
                        RenderScene.DrawFilter = Scene.RenderFilter.MapPiece | Scene.RenderFilter.Object | Scene.RenderFilter.Character | Scene.RenderFilter.Region;
                    }
                    if (ImGui.MenuItem("Collision/Character/Objects", "Ctrl-2"))
                    {
                        RenderScene.DrawFilter = Scene.RenderFilter.Collision | Scene.RenderFilter.Object | Scene.RenderFilter.Character | Scene.RenderFilter.Region;
                    }
                    if (ImGui.MenuItem("Collision/Navmesh/Character/Objects", "Ctrl-3"))
                    {
                        RenderScene.DrawFilter = Scene.RenderFilter.Collision | Scene.RenderFilter.Navmesh | Scene.RenderFilter.Object | Scene.RenderFilter.Character | Scene.RenderFilter.Region;
                    }
                    ImGui.EndMenu();
                }
                if (ImGui.BeginMenu("Environment Map"))
                {
                    if (ImGui.MenuItem("Default"))
                    {
                        Viewport.SetEnvMap(0);
                    }
                    foreach (var map in Universe.EnvMapTextures)
                    {
                        if (ImGui.MenuItem(map))
                        {
                            var tex = ResourceManager.GetTextureResource($@"tex/{map}".ToLower());
                            if (tex.IsLoaded && tex.Get() != null && tex.TryLock())
                            {
                                if (tex.Get().GPUTexture.Resident)
                                {
                                    Viewport.SetEnvMap(tex.Get().GPUTexture.TexHandle);
                                }
                                tex.Unlock();
                            }
                        }
                    }
                    ImGui.EndMenu();
                }
                if (ImGui.BeginMenu("Scene Lighting"))
                {
                    Viewport.SceneParamsGui();
                    ImGui.EndMenu();
                }
                CFG.Current.LastSceneFilter = RenderScene.DrawFilter;
                ImGui.EndMenu();
            }
            if (ImGui.BeginMenu("Gizmos"))
            {
                if (ImGui.BeginMenu("Mode"))
                {
                    if (ImGui.MenuItem("Translate", "W", Gizmos.Mode == Gizmos.GizmosMode.Translate))
                    {
                        Gizmos.Mode = Gizmos.GizmosMode.Translate;
                    }
                    if (ImGui.MenuItem("Rotate", "E", Gizmos.Mode == Gizmos.GizmosMode.Rotate))
                    {
                        Gizmos.Mode = Gizmos.GizmosMode.Rotate;
                    }
                    ImGui.EndMenu();
                }
                if (ImGui.BeginMenu("Space"))
                {
                    if (ImGui.MenuItem("Local", "", Gizmos.Space == Gizmos.GizmosSpace.Local))
                    {
                        Gizmos.Space = Gizmos.GizmosSpace.Local;
                    }
                    if (ImGui.MenuItem("World", "", Gizmos.Space == Gizmos.GizmosSpace.World))
                    {
                        Gizmos.Space = Gizmos.GizmosSpace.World;
                    }
                    ImGui.EndMenu();
                }
                if (ImGui.BeginMenu("Origin"))
                {
                    if (ImGui.MenuItem("World", "", Gizmos.Origin == Gizmos.GizmosOrigin.World))
                    {
                        Gizmos.Origin = Gizmos.GizmosOrigin.World;
                    }
                    if (ImGui.MenuItem("Bounding Box", "", Gizmos.Origin == Gizmos.GizmosOrigin.BoundingBox))
                    {
                        Gizmos.Origin = Gizmos.GizmosOrigin.BoundingBox;
                    }
                    ImGui.EndMenu();
                }
                ImGui.EndMenu();
            }
        }
Пример #8
0
        private void ChangeProperty(object prop, Entity selection, object obj, object newval,
                                    bool changed, bool committed, bool shouldUpdateVisual, int arrayindex = -1)
        {
            if (changed)
            {
                if (prop == ChangingPropery && LastUncommittedAction != null)
                {
                    if (ContextActionManager.PeekUndoAction() == LastUncommittedAction)
                    {
                        ContextActionManager.UndoAction();
                    }
                    else
                    {
                        LastUncommittedAction = null;
                    }
                }
                else
                {
                    LastUncommittedAction = null;
                }

                if (ChangingObject != null && selection != null && selection.WrappedObject != ChangingObject)
                {
                    committed = true;
                }
                else
                {
                    PropertiesChangedAction action;
                    if (arrayindex != -1)
                    {
                        action = new PropertiesChangedAction((PropertyInfo)prop, arrayindex, obj, newval);
                    }
                    else
                    {
                        action = new PropertiesChangedAction((PropertyInfo)prop, obj, newval);
                    }
                    if (shouldUpdateVisual && selection != null)
                    {
                        action.SetPostExecutionAction((undo) =>
                        {
                            selection.UpdateRenderModel();
                        });
                    }
                    ContextActionManager.ExecuteAction(action);

                    LastUncommittedAction = action;
                    ChangingPropery       = prop;
                    //ChangingObject = selection.MsbObject;
                    ChangingObject = selection != null ? selection.WrappedObject : obj;
                }
            }
            if (committed)
            {
                // Invalidate name cache
                if (selection != null)
                {
                    selection.Name = null;
                }

                // Undo and redo the last action with a rendering update
                if (LastUncommittedAction != null && ContextActionManager.PeekUndoAction() == LastUncommittedAction)
                {
                    if (LastUncommittedAction is PropertiesChangedAction a)
                    {
                        // Kinda a hack to prevent a jumping glitch
                        a.SetPostExecutionAction(null);
                        ContextActionManager.UndoAction();
                        if (selection != null)
                        {
                            a.SetPostExecutionAction((undo) =>
                            {
                                selection.UpdateRenderModel();
                            });
                        }
                        ContextActionManager.ExecuteAction(a);
                    }
                }

                LastUncommittedAction = null;
                ChangingPropery       = null;
                ChangingObject        = null;
            }
        }
Пример #9
0
 public static MassEditResult PerformSingleMassEdit(string csvString, ActionManager actionManager, string param, string field, bool useSpace)
 {
     try
     {
         PARAM p = ParamBank.Params[param];
         if (p == null)
         {
             return(new MassEditResult(MassEditResultType.PARSEERROR, "No Param selected"));
         }
         string[]      csvLines    = csvString.Split('\n');
         int           changeCount = 0;
         List <Action> actions     = new List <Action>();
         foreach (string csvLine in csvLines)
         {
             if (csvLine.Trim().Equals(""))
             {
                 continue;
             }
             string[] csvs = csvLine.Split(useSpace ? ' ' : ',', 2, StringSplitOptions.RemoveEmptyEntries);
             if (csvs.Length != 2)
             {
                 return(new MassEditResult(MassEditResultType.PARSEERROR, "CSV has wrong number of values"));
             }
             int       id    = int.Parse(csvs[0]);
             string    value = csvs[1];
             PARAM.Row row   = p[id];
             if (row == null)
             {
                 return(new MassEditResult(MassEditResultType.OPERATIONERROR, $@"Could not locate row {id}"));
             }
             if (field.Equals("Name"))
             {
                 if (row.Name == null || !row.Name.Equals(value))
                 {
                     actions.Add(new PropertiesChangedAction(row.GetType().GetProperty("Name"), -1, row, value));
                 }
             }
             else
             {
                 PARAM.Cell cell = row[field];
                 if (cell == null)
                 {
                     return(new MassEditResult(MassEditResultType.OPERATIONERROR, $@"Could not locate field {field}"));
                 }
                 // Array types are unhandled
                 if (cell.Value.GetType().IsArray)
                 {
                     continue;
                 }
                 object newval = PerformOperation(cell, "=", value);
                 if (newval == null)
                 {
                     return(new MassEditResult(MassEditResultType.OPERATIONERROR, $@"Could not assign {value} to field {cell.Def.DisplayName}"));
                 }
                 if (!cell.Value.Equals(newval))
                 {
                     actions.Add(new PropertiesChangedAction(cell.GetType().GetProperty("Value"), -1, cell, newval));
                 }
             }
         }
         changeCount = actions.Count;
         if (changeCount != 0)
         {
             actionManager.ExecuteAction(new CompoundAction(actions));
         }
         return(new MassEditResult(MassEditResultType.SUCCESS, $@"{changeCount} rows affected"));
     }
     catch
     {
         return(new MassEditResult(MassEditResultType.PARSEERROR, "Unable to parse CSV into correct data types"));
     }
 }