/// <summary> /// Creates a new instance of the given SceneObject at the indicated position. /// </summary> /// <param name="sceneObject">Type of SceneObject to create an instance of.</param> /// <param name="position">Location to insert into the scene.</param> public void Add(RSDKv5.SceneObject sceneObject, RSDKv5.Position position) { var editorEntity = GenerateEditorEntity(new RSDKv5.SceneEntity(sceneObject, getFreeSlot(null))); editorEntity.Entity.Position = position; var newEntities = new List <EditorEntity> { editorEntity }; LastAction = new Actions.ActionAddDeleteEntities(newEntities, true, x => AddEntities(x), x => DeleteEntities(x)); AddEntities(newEntities); Deselect(); editorEntity.Selected = true; selectedEntities.Add(editorEntity); }
private void setEntitiyProperty(RSDKv5.SceneEntity entity, string tag, object value, object oldValue) { string[] parts = tag.Split('.'); string category = parts[0]; string name = parts[1]; if (category == "position") { float fvalue = (float)value; if (fvalue < Int16.MinValue || fvalue > Int16.MaxValue) { // Invalid var obj = (entityProperties.SelectedObject as LocalPropertyGridObject); obj.setValue(tag, oldValue); return; } var pos = entity.Position; if (name == "x") { pos.X.High = (short)fvalue; pos.X.Low = (ushort)(fvalue * 0x10000); } else if (name == "y") { pos.Y.High = (short)fvalue; pos.Y.Low = (ushort)(fvalue * 0x10000); } entity.Position = pos; if (entity == currentEntity) { UpdateCurrentEntityProperites(); } } else if (category == "object") { if (name == "name" && oldValue != value) { var info = RSDKv5.Objects.GetObjectInfo(new RSDKv5.NameIdentifier(value as string)); if (info == null) { MessageBox.Show("Unknown Object", "", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } var objects = ((BindingList <RSDKv5.SceneObject>)_bindingSceneObjectsSource.DataSource).ToList(); var obj = objects.FirstOrDefault(t => t.Name.Name == value as string); if (obj != null) { entity.Attributes.Clear(); entity.attributesMap.Clear(); foreach (var attb in info.Attributes) { var attributeValue = new RSDKv5.AttributeValue(attb.Type); entity.Attributes.Add(attributeValue); entity.attributesMap.Add(attb.Name.Name, attributeValue); } entity.Object.Entities.Remove(entity); entity.Object = obj; obj.Entities.Add(entity); } else { // The new object var sobj = new RSDKv5.SceneObject(info.Name, info.Attributes); entity.Attributes.Clear(); entity.attributesMap.Clear(); foreach (var attb in info.Attributes) { var attributeValue = new RSDKv5.AttributeValue(attb.Type); entity.Attributes.Add(attributeValue); entity.attributesMap.Add(attb.Name.Name, attributeValue); } entity.Object.Entities.Remove(entity); entity.Object = sobj; sobj.Entities.Add(entity); _bindingSceneObjectsSource.Add(sobj); } } // Update Properties currentEntity = null; UpdateEntitiesProperties(new List <RSDKv5.SceneEntity>() { entity }); } else { var attribute = entity.GetAttribute(category); switch (attribute.Type) { case RSDKv5.AttributeTypes.UINT8: attribute.ValueUInt8 = (byte)value; break; case RSDKv5.AttributeTypes.UINT16: attribute.ValueUInt16 = (ushort)value; break; case RSDKv5.AttributeTypes.UINT32: attribute.ValueUInt32 = (uint)value; break; case RSDKv5.AttributeTypes.INT8: attribute.ValueInt8 = (sbyte)value; break; case RSDKv5.AttributeTypes.INT16: attribute.ValueInt16 = (short)value; break; case RSDKv5.AttributeTypes.INT32: attribute.ValueInt32 = (int)value; break; case RSDKv5.AttributeTypes.VAR: attribute.ValueVar = (uint)value; break; case RSDKv5.AttributeTypes.BOOL: attribute.ValueBool = (bool)value; break; case RSDKv5.AttributeTypes.STRING: attribute.ValueString = (string)value; break; case RSDKv5.AttributeTypes.POSITION: float fvalue = (float)value; if (fvalue < Int16.MinValue || fvalue > Int16.MaxValue) { // Invalid var obj = (entityProperties.SelectedObject as LocalPropertyGridObject); obj.setValue(tag, oldValue); return; } var pos = attribute.ValuePosition; if (name == "x") { pos.X.High = (short)fvalue; pos.X.Low = (ushort)(fvalue * 0x10000); } else if (name == "y") { pos.Y.High = (short)fvalue; pos.Y.Low = (ushort)(fvalue * 0x10000); } attribute.ValuePosition = pos; if (entity == currentEntity) { UpdateCurrentEntityProperites(); } break; case RSDKv5.AttributeTypes.COLOR: Color c = (Color)value; attribute.ValueColor = new RSDKv5.Color(c.R, c.G, c.B, c.A); break; } } }