public override bool ExecuteObjectOperation(SceneNodeModel treeNode, ObjectOperation operation, int itemIndex)
        {
            var blockRef    = scenario.Sections[Section.StartProfiles];
            var blockEditor = scenario.MetadataStream.GetBlockEditor(blockRef.TagBlock.Pointer.Address);

            switch (operation)
            {
            case ObjectOperation.Add:
                blockEditor.Add();
                break;

            case ObjectOperation.Remove:
                if (itemIndex < 0 || itemIndex >= blockRef.TagBlock.Count)
                {
                    return(false);
                }

                blockEditor.Remove(itemIndex);
                break;

            case ObjectOperation.Copy:
                if (itemIndex < 0 || itemIndex >= blockRef.TagBlock.Count)
                {
                    return(false);
                }

                blockEditor.Copy(itemIndex, itemIndex + 1);
                break;
            }

            blockEditor.UpdateBlockReference(blockRef);
            return(true);
        }
Esempio n. 2
0
 private void OnMouseLeftClick(float x, float y)
 {
     if (ViewPortContains(x, y))
     {
         if (CurrentOperation == ObjectOperation.Placing && newObject != null)
         {
             newObject.Pos = new Vector2(x, y) - parent.camera.CurrentOffset;
             WorldObjects.Add(newObject);
             newObject = new WorldObject(newObject, newObject.Pos);
         }
         if (CurrentOperation == ObjectOperation.None && !parent.grid.EditModeEnabled)
         {
             currentSelection = null;
             MouseLeftPressed?.Invoke(x, y);
             ObjectSelection?.Invoke(ref currentSelection);
             if (currentSelection != null)
             {
                 InputStateChanged?.Invoke(false);
             }
             else
             {
                 InputStateChanged?.Invoke(true);
             }
         }
         if (CurrentOperation == ObjectOperation.Placing && currentSelection != null)
         {
             currentSelection.Pos = new Vector2(x, y) + mousePadding - parent.camera.CurrentOffset;
             parent.inputHandler.MouseMovedEvent -= OnMousePosChanged;
             CurrentOperation = ObjectOperation.None;
             InputStateChanged?.Invoke(true);
         }
     }
 }
Esempio n. 3
0
 public ObjectHandler(CellED parent)
 {
     this.parent = parent;
     InitializeObjects();
     CurrentOperation = ObjectOperation.None;
     EnableInput();
 }
        public override bool ExecuteObjectOperation(SceneNodeModel treeNode, ObjectOperation operation, int itemIndex)
        {
            var paletteKey = PaletteType.FromNodeType(treeNode.NodeType);
            var holder     = PaletteHolders[paletteKey];

            var blockEditor = scenario.MetadataStream.GetBlockEditor(holder.Definition.PlacementBlockRef.TagBlock.Pointer.Address);

            switch (operation)
            {
            case ObjectOperation.Add:
                blockEditor.Add();
                blockEditor.UpdateBlockReference(holder.Definition.PlacementBlockRef);

                var placement = holder.InsertPlacement(blockEditor.EntryCount - 1, scenario, paletteKey);

                //setting the palette index causes a refresh which builds an element for the new object
                //these also need to be set to -1 initially anyway
                placement.PaletteIndex = placement.NameIndex = -1;
                break;

            case ObjectOperation.Remove:
                if (itemIndex < 0 || itemIndex >= holder.Definition.Placements.Count)
                {
                    return(false);
                }

                ShiftObjectNames(paletteKey, itemIndex, holder.Definition.Placements.Count, true);

                blockEditor.Remove(itemIndex);
                blockEditor.UpdateBlockReference(holder.Definition.PlacementBlockRef);
                holder.RemovePlacement(itemIndex);

                UpdateBlockIndexes(paletteKey, itemIndex, holder.Definition.Placements.Count);
                break;

            case ObjectOperation.Copy:
                if (itemIndex < 0 || itemIndex >= holder.Definition.Placements.Count)
                {
                    return(false);
                }

                ShiftObjectNames(paletteKey, itemIndex, holder.Definition.Placements.Count, false);

                var destIndex = itemIndex + 1;
                blockEditor.Copy(itemIndex, destIndex);
                blockEditor.UpdateBlockReference(holder.Definition.PlacementBlockRef);

                placement = holder.InsertPlacement(destIndex, scenario, paletteKey);
                placement.CopyFrom(holder.Definition.Placements[itemIndex]);

                UpdateBlockIndexes(paletteKey, itemIndex, holder.Definition.Placements.Count);
                break;

            default:
                return(false);
            }

            return(true);
        }
Esempio n. 5
0
 private void DuplicateObject()
 {
     currentSelection = new WorldObject(currentSelection, parent.inputHandler.GetMousePos() + mousePadding - parent.camera.CurrentOffset);
     WorldObjects.Add(currentSelection);
     CurrentOperation = ObjectOperation.Placing;
     parent.inputHandler.MouseMovedEvent += OnMousePosChanged;
     InputStateChanged?.Invoke(false);
     ObjectSelection?.Invoke(ref currentSelection);
 }
Esempio n. 6
0
    private void InitOperation()
    {
        mInfoOperation    = new InfoOperation(this);
        mObjectOperation  = new ObjectOperation(this);
        mCommandOperation = new CommandOperation(this);

        mInfoOperation.Init();
        mObjectOperation.Init();
        mCommandOperation.Init();
    }
Esempio n. 7
0
        public override bool ExecuteObjectOperation(SceneNodeModel treeNode, ObjectOperation operation, int itemIndex)
        {
            var blockRef    = scenario.Sections[Section.TriggerVolumes];
            var blockEditor = scenario.MetadataStream.GetBlockEditor(blockRef.TagBlock.Pointer.Address);

            switch (operation)
            {
            case ObjectOperation.Add:
                blockEditor.Add();

                var vol = new TriggerVolume(scenario)
                {
                    //really should be reading these from the stream...
                    ForwardVector = new RealVector3D(1, 0, 0),
                    UpVector      = new RealVector3D(0, 0, 1),
                    Size          = new RealVector3D(1, 1, 1)
                };

                scenario.TriggerVolumes.Add(vol);
                AddTriggerVolumeElement(vol);
                break;

            case ObjectOperation.Remove:
                if (itemIndex < 0 || itemIndex >= blockRef.TagBlock.Count)
                {
                    return(false);
                }

                blockEditor.Remove(itemIndex);
                scenario.TriggerVolumes.RemoveAt(itemIndex);
                RemoveTriggerVolumeElement(itemIndex);

                UpdateBlockIndexes(itemIndex, scenario.TriggerVolumes.Count);
                break;

            case ObjectOperation.Copy:
                if (itemIndex < 0 || itemIndex >= blockRef.TagBlock.Count)
                {
                    return(false);
                }

                var destIndex = itemIndex + 1;
                blockEditor.Copy(itemIndex, destIndex);
                vol = new TriggerVolume(scenario);
                scenario.TriggerVolumes.Insert(destIndex, vol);
                InsertTriggerVolumeElement(vol, destIndex);
                vol.CopyFrom(scenario.TriggerVolumes[itemIndex]);

                UpdateBlockIndexes(itemIndex, scenario.TriggerVolumes.Count);
                break;
            }

            blockEditor.UpdateBlockReference(blockRef);
            return(true);
        }
Esempio n. 8
0
 public void EndObjectAddition()
 {
     if (!inputDisabled)
     {
         CurrentOperation = ObjectOperation.None;
         newObject.Destroy();
         newObject = null;
         parent.inputHandler.MouseMovedEvent -= OnMousePosChanged;
         InputStateChanged?.Invoke(true);
     }
 }
Esempio n. 9
0
 public void StartObjectAddition(WorldObject worldObj)
 {
     if (!inputDisabled)
     {
         CurrentOperation = ObjectOperation.Placing;
         currentSelection = null;
         newObject        = worldObj;
         parent.inputHandler.MouseMovedEvent += OnMousePosChanged;
         parent.grid.EditModeEnabled          = false;
         InputStateChanged?.Invoke(false);
     }
 }
Esempio n. 10
0
 private void MoveSelectedItem()
 {
     if (CurrentOperation == ObjectOperation.None && currentSelection != null)
     {
         CurrentOperation = ObjectOperation.Placing;
         mousePadding     = (currentSelection.Pos + parent.camera.CurrentOffset) - parent.inputHandler.GetMousePos();
         parent.inputHandler.MouseMovedEvent += OnMousePosChanged;
         InputStateChanged?.Invoke(false);
     }
     else if (CurrentOperation == ObjectOperation.Placing && currentSelection != null)
     {
         currentSelection.Pos = parent.inputHandler.GetMousePos() + mousePadding - parent.camera.CurrentOffset;
         parent.inputHandler.MouseMovedEvent -= OnMousePosChanged;
         CurrentOperation = ObjectOperation.None;
         InputStateChanged?.Invoke(true);
     }
 }
Esempio n. 11
0
        public override bool ExecuteObjectOperation(SceneNodeModel treeNode, ObjectOperation operation, int itemIndex)
        {
            var blockRef    = scenario.Sections[Section.StartPositions];
            var blockEditor = scenario.MetadataStream.GetBlockEditor(blockRef.TagBlock.Pointer.Address);

            switch (operation)
            {
            case ObjectOperation.Add:
                blockEditor.Add();
                var pos = new StartPosition(scenario);
                scenario.StartingPositions.Add(pos);
                AddStartPositionElement(pos);
                break;

            case ObjectOperation.Remove:
                if (itemIndex < 0 || itemIndex >= blockRef.TagBlock.Count)
                {
                    return(false);
                }

                blockEditor.Remove(itemIndex);
                scenario.StartingPositions.RemoveAt(itemIndex);
                RemoveStartPositionElement(itemIndex);
                break;

            case ObjectOperation.Copy:
                if (itemIndex < 0 || itemIndex >= blockRef.TagBlock.Count)
                {
                    return(false);
                }

                var destIndex = itemIndex + 1;
                blockEditor.Copy(itemIndex, destIndex);
                pos = new StartPosition(scenario);
                scenario.StartingPositions.Insert(destIndex, pos);
                InsertStartPositionElement(pos, destIndex);
                pos.CopyFrom(scenario.StartingPositions[itemIndex]);
                break;
            }

            blockEditor.UpdateBlockReference(blockRef);
            return(true);
        }
Esempio n. 12
0
        private static ObjectOperation[] GetObjectOperations()
        {
            var ops = new ObjectOperation[]
            {
                new AddDataTypeOperation("schema", "name", "from"),
                new AddStoredProcedureOperation("schema", "name", "definition"),
                new AddSynonymOperation("schema", "name", "targetSchemaName", "targetDatabaseName", "targetObjectName"),
                new AddTableOperation("schema", "name", new Column[0], false, "fileGroup", "textImageFileGroup",
                                      "fileStream", new string[0]),
                new AddTriggerOperation("schema", "name", "definition"),
                new AddUserDefinedFunctionOperation("schema", "name", "definition"),
                new AddViewOperation("schema", "name", "definition"),
                new UpdateCodeObjectMetadataOperation("schema", "name", "namespace"),
                new UpdateStoredProcedureOperation("schema", "name", "definition"),
                new UpdateTableOperation("schema", "name", new Column[0], new Column[0], new string[0]),
                new UpdateTriggerOperation("schema", "name", "definition"),
                new UpdateUserDefinedFunctionOperation("schema", "name", "definition"),
                new UpdateViewOperation("schema", "name", "definition"),
            };

            var expectedOps = AppDomain.CurrentDomain.GetAssemblies()
                              .Where(assembly => assembly.GetName().Name == "Rivet")
                              .SelectMany(assembly => assembly.GetTypes())
                              .Where(type => type.IsSubclassOf(typeof(ObjectOperation)))
                              .Where(type => !type.IsAbstract)
                              .Where(type => !type.Name.StartsWith("Remove", StringComparison.InvariantCultureIgnoreCase));

            Assert.That(expectedOps, Is.Not.Empty);
            foreach (var expectedOp in expectedOps)
            {
                var count = ops.Count(t => t.GetType() == expectedOp);
                Assert.That(count, Is.Not.EqualTo(0),
                            $"Class {expectedOp.FullName} is missing. Please add an instance of this type to this test.");
            }

            return(ops);
        }
Esempio n. 13
0
 //true if the add/remove buttons should be enabled for this node type
 public virtual bool SupportsObjectOperation(ObjectOperation operation, NodeType nodeType) => false;
Esempio n. 14
0
 /// <summary>Constructs the object operation attribute.</summary>
 /// <param name="_operation">The operation type.</param>
 public ObjectOperationAttribute(ObjectOperation _operation)
 {
     Operation = _operation;
 }
Esempio n. 15
0
 //only called if SupportsObjectOperation
 public virtual bool ExecuteObjectOperation(SceneNodeModel treeNode, ObjectOperation operation, int itemIndex)
 {
     throw new NotImplementedException();
 }
 public override bool SupportsObjectOperation(ObjectOperation operation, NodeType nodeType) => PaletteType.FromNodeType(nodeType) != null;
Esempio n. 17
0
 public override bool SupportsObjectOperation(ObjectOperation operation, NodeType nodeType) => nodeType == NodeType.StartPositions;
Esempio n. 18
0
 public override bool SupportsObjectOperation(ObjectOperation operation, NodeType nodeType) => nodeType == NodeType.TriggerVolumes;