private void AddNewEntity(object sender) { var addEntityViewModel = new AddEntityViewModel(); addEntityViewModel.AddedNewEntity += AddEntityViewModel_AddedNewEntity; _addEntityWindow = new AddEntityWindow(addEntityViewModel); _addEntityWindow.ShowDialog(); }
public static void HandleModifyAddEntityWindow(AddEntityWindow window) { var viewModel = new AdditionalEntitiesControlViewModel(); var control = new AdditionalEntitiesControls(); control.DataContext = viewModel; window.AddToStackPanel(control); }
internal static void ReactToNewEntityCreated(EntitySave newEntity, AddEntityWindow window) { var control = window.UserControlChildren.FirstOrDefault(item => item is AdditionalEntitiesControls); var viewModel = control?.DataContext as AdditionalEntitiesControlViewModel; if (viewModel?.InstantiateInTileMap == true) { // make it have a factory newEntity.CreatedByOtherEntities = true; GlueCommands.Self.PrintOutput($"Tiled Plugin marked entity {newEntity} as CreatedByOtherEntities=true"); if (viewModel.IncludeListsInScreens) { // loop through all screens that have a TMX object and add them. // be smart - if the base screen does, don't do it in the derived var allScreens = GlueState.Self.CurrentGlueProject.Screens; foreach (var screen in allScreens) { var needsList = GetIfScreenNeedsList(screen); if (needsList) { AddObjectViewModel addObjectViewModel = new AddObjectViewModel(); addObjectViewModel.ObjectName = $"{newEntity.GetStrippedName()}List"; addObjectViewModel.SourceType = SourceType.FlatRedBallType; addObjectViewModel.SourceClassType = "PositionedObjectList<T>"; addObjectViewModel.SourceClassGenericType = newEntity.Name; GlueCommands.Self.GluxCommands.AddNewNamedObjectTo( addObjectViewModel, screen, namedObject: null); GlueCommands.Self.PrintOutput( $"Tiled Plugin added {addObjectViewModel.ObjectName} to {screen}"); GlueCommands.Self.GenerateCodeCommands.GenerateElementCode(screen); } } } GlueCommands.Self.GenerateCodeCommands.GenerateElementCode(newEntity); GlueCommands.Self.ProjectCommands.SaveProjects(); GlueState.Self.CurrentEntitySave = newEntity; } }
internal static void ReactToNewEntityCreated(EntitySave newEntity, AddEntityWindow window) { var control = window .UserControlChildren .FirstOrDefault(item => item is AdditionalEntitiesControls); var viewModel = control?.DataContext as AdditionalEntitiesControlViewModel; if (viewModel != null) { if (viewModel.IsTopDownEntity) { GlueCommands.Self.DialogCommands.FocusTab("Top Down"); MainController.Self.MakeCurrentEntityTopDown(); } } }
public static void HandleModifyAddEntityWindow(AddEntityWindow window) { // See if any screens have tile maps var allScreens = GlueState.Self.CurrentGlueProject.Screens; bool IsRfsTiledMap(ReferencedFileSave rfs) { return(rfs.GetAssetTypeInfo() == AssetTypeInfoAdder.Self.TmxAssetTypeInfo); } var doesProjectContainAnyTmxFiles = allScreens.Any(item => item.ReferencedFiles.Any(IsRfsTiledMap)); if (doesProjectContainAnyTmxFiles) { var viewModel = new AdditionalEntitiesControlViewModel(); var control = new AdditionalEntitiesControls(); control.DataContext = viewModel; window.AddToStackPanel(control); } }
private static EntitySave CreateEntityAndObjects(AddEntityWindow window, string entityName, string directory) { var gluxCommands = GlueCommands.Self.GluxCommands; var newElement = gluxCommands.EntityCommands.AddEntity( directory + entityName, is2D: true); GlueState.Self.CurrentElement = newElement; if (window.SpriteChecked) { AddObjectViewModel addObjectViewModel = new AddObjectViewModel(); addObjectViewModel.ObjectName = "SpriteInstance"; addObjectViewModel.SourceClassType = "Sprite"; addObjectViewModel.SourceType = SourceType.FlatRedBallType; gluxCommands.AddNewNamedObjectToSelectedElement(addObjectViewModel); GlueState.Self.CurrentElement = newElement; } if (window.TextChecked) { AddObjectViewModel addObjectViewModel = new AddObjectViewModel(); addObjectViewModel.ObjectName = "TextInstance"; addObjectViewModel.SourceClassType = "Text"; addObjectViewModel.SourceType = SourceType.FlatRedBallType; gluxCommands.AddNewNamedObjectToSelectedElement(addObjectViewModel); GlueState.Self.CurrentElement = newElement; } if (window.CircleChecked) { AddObjectViewModel addObjectViewModel = new AddObjectViewModel(); addObjectViewModel.ObjectName = "CircleInstance"; addObjectViewModel.SourceClassType = "Circle"; addObjectViewModel.SourceType = SourceType.FlatRedBallType; gluxCommands.AddNewNamedObjectToSelectedElement(addObjectViewModel); GlueState.Self.CurrentElement = newElement; } if (window.AxisAlignedRectangleChecked) { AddObjectViewModel addObjectViewModel = new AddObjectViewModel(); addObjectViewModel.ObjectName = "AxisAlignedRectangleInstance"; addObjectViewModel.SourceClassType = "AxisAlignedRectangle"; addObjectViewModel.SourceType = SourceType.FlatRedBallType; gluxCommands.AddNewNamedObjectToSelectedElement(addObjectViewModel); GlueState.Self.CurrentElement = newElement; } // There are a few important things to note about this function: // 1. Whenever gluxCommands.AddNewNamedObjectToSelectedElement is called, Glue performs a full // refresh and save. The reason for this is that gluxCommands.AddNewNamedObjectToSelectedElement // is the standard way to add a new named object to an element, and it may be called by other parts // of the code (and plugins) that expect the add to be a complete set of logic (add, refresh, save, etc). // This is less efficient than adding all of them and saving only once, but that would require a second add // method, which would add complexity. For now, we deal with the slower calls because it's not really noticeable. // 2. Some actions, like adding Points to a polygon, are done after the polygon is created and added, and that requires // an additional save. Therefore, we do one last save/refresh at the end of this method in certain situations. // Again, this is less efficient than if we performed just a single call, but a single call would be more complicated. // because we'd have to suppress all the other calls. bool needsRefreshAndSave = false; if (window.PolygonChecked) { AddObjectViewModel addObjectViewModel = new AddObjectViewModel(); addObjectViewModel.ObjectName = "PolygonInstance"; addObjectViewModel.SourceClassType = "Polygon"; addObjectViewModel.SourceType = SourceType.FlatRedBallType; var nos = gluxCommands.AddNewNamedObjectToSelectedElement(addObjectViewModel); CustomVariableInNamedObject instructions = null; instructions = nos.GetCustomVariable("Points"); if (instructions == null) { instructions = new CustomVariableInNamedObject(); instructions.Member = "Points"; nos.InstructionSaves.Add(instructions); } var points = new List <Vector2>(); points.Add(new Vector2(-16, 16)); points.Add(new Vector2(16, 16)); points.Add(new Vector2(16, -16)); points.Add(new Vector2(-16, -16)); points.Add(new Vector2(-16, 16)); instructions.Value = points; needsRefreshAndSave = true; GlueState.Self.CurrentElement = newElement; } if (window.IVisibleChecked) { newElement.ImplementsIVisible = true; needsRefreshAndSave = true; } if (window.IClickableChecked) { newElement.ImplementsIClickable = true; needsRefreshAndSave = true; } if (window.IWindowChecked) { newElement.ImplementsIWindow = true; needsRefreshAndSave = true; } if (window.ICollidableChecked) { newElement.ImplementsICollidable = true; needsRefreshAndSave = true; } if (needsRefreshAndSave) { MainGlueWindow.Self.PropertyGrid.Refresh(); ElementViewWindow.GenerateSelectedElementCode(); GluxCommands.Self.SaveGlux(); } return(newElement); }
private static object DrawField( Entity entity, Tuple <FieldInfo, PropertyInfoAttribute> field, object currentValue) { object newValue = null; switch (field.Item2.Type) { case Core.PropertyInfoType.Int8: newValue = FoxKitUiUtils.SbyteField(field.Item1.Name, (sbyte)currentValue); break; case Core.PropertyInfoType.UInt8: newValue = FoxKitUiUtils.ByteField(field.Item1.Name, (byte)currentValue); break; case Core.PropertyInfoType.Int16: newValue = FoxKitUiUtils.ShortField(field.Item1.Name, (short)currentValue); break; case Core.PropertyInfoType.UInt16: newValue = FoxKitUiUtils.UShortField(field.Item1.Name, (ushort)currentValue); break; case Core.PropertyInfoType.Int32: if (field.Item2.Enum != null) { newValue = EditorGUILayout.EnumPopup(field.Item1.Name, (Enum)currentValue); } else { newValue = EditorGUILayout.IntField(field.Item1.Name, (int)currentValue); } break; case Core.PropertyInfoType.UInt32: newValue = FoxKitUiUtils.UIntField(field.Item1.Name, (uint)currentValue); break; case Core.PropertyInfoType.Int64: newValue = EditorGUILayout.LongField(field.Item1.Name, (long)currentValue); break; case Core.PropertyInfoType.UInt64: newValue = FoxKitUiUtils.ULongField(field.Item1.Name, (ulong)currentValue); break; case Core.PropertyInfoType.Float: newValue = EditorGUILayout.FloatField(field.Item1.Name, (float)currentValue); break; case Core.PropertyInfoType.Double: newValue = EditorGUILayout.DoubleField(field.Item1.Name, (double)currentValue); break; case Core.PropertyInfoType.Bool: newValue = EditorGUILayout.Toggle(field.Item1.Name, (bool)currentValue); break; case Core.PropertyInfoType.String: newValue = EditorGUILayout.TextField(field.Item1.Name, field.Item1.GetValue(entity) as string); break; case Core.PropertyInfoType.Path: newValue = EditorGUILayout.ObjectField( field.Item1.Name, field.Item1.GetValue(entity) as UnityEngine.Object, typeof(UnityEngine.Object), false); break; case Core.PropertyInfoType.EntityPtr: newValue = FoxKitUiUtils.EntityPtrField( field.Item1.Name, currentValue, field.Item2.PtrType, () => AddEntityWindow.Create(field.Item2.PtrType, true, type => field.Item1.SetValue(entity, CreateEntity(type, entity))), dataElement => DestroyEntity(dataElement, entity)); break; case Core.PropertyInfoType.Vector3: newValue = EditorGUILayout.Vector3Field( field.Item1.Name, (UnityEngine.Vector3)field.Item1.GetValue(entity)); break; case Core.PropertyInfoType.Vector4: newValue = EditorGUILayout.Vector4Field( field.Item1.Name, (UnityEngine.Vector4)field.Item1.GetValue(entity)); break; case Core.PropertyInfoType.Quat: newValue = FoxKitUiUtils.QuaternionField(field.Item1.Name, (UnityEngine.Quaternion)currentValue); break; case Core.PropertyInfoType.Matrix3: Assert.IsTrue(false, "There shouldn't be any Matrix3 properties. Report this."); break; case Core.PropertyInfoType.Matrix4: EditorGUILayout.HelpBox("Matrix4 properties are not currently supported.", MessageType.Error); break; case Core.PropertyInfoType.Color: newValue = EditorGUILayout.ColorField(field.Item1.Name, (Color)field.Item1.GetValue(entity)); break; case Core.PropertyInfoType.FilePtr: newValue = EditorGUILayout.ObjectField( field.Item1.Name, field.Item1.GetValue(entity) as UnityEngine.Object, typeof(UnityEngine.Object), false); break; case Core.PropertyInfoType.EntityHandle: newValue = FoxKitUiUtils.EntityHandleField(field.Item1.Name, currentValue, typeof(Entity)); break; case Core.PropertyInfoType.EntityLink: var link = field.Item1.GetValue(entity) as EntityLink; Action <Data> onEntitySelected = selected => link.Entity = selected; Action <DataIdentifier, string> onDataIdentifierEntitySelected = (identifier, key) => link.SetDataIdentifier(identifier, key); newValue = FoxKitUiUtils.EntityLinkField(field.Item1.Name, link, onEntitySelected, onDataIdentifierEntitySelected); break; default: throw new ArgumentOutOfRangeException(); } return(newValue); }
private static T DrawListItem <T>( Rect position, T itemValue, Core.PropertyInfoType type, Type @enum, Type ptrType, Action <Type> createEntityCallback = null) { object newValue = null; switch (type) { case Core.PropertyInfoType.Int8: newValue = FoxKitUiUtils.SbyteField(position, (sbyte)(object)itemValue); break; case Core.PropertyInfoType.UInt8: newValue = FoxKitUiUtils.ByteField(position, (byte)(object)itemValue); break; case Core.PropertyInfoType.Int16: newValue = FoxKitUiUtils.ShortField(position, (short)(object)itemValue); break; case Core.PropertyInfoType.UInt16: newValue = FoxKitUiUtils.UShortField(position, (ushort)(object)itemValue); break; case Core.PropertyInfoType.Int32: if (@enum != null) { // I'm sorry var enumValue = (Enum)Enum.ToObject(@enum, itemValue); newValue = EditorGUI.EnumPopup(position, enumValue); } else { newValue = EditorGUI.IntField(position, (int)(object)itemValue); } break; case Core.PropertyInfoType.UInt32: //newValue = FoxKitUiUtils.UIntField(position, (uint)(object)itemValue); if (@enum != null) { newValue = EditorGUI.EnumPopup(position, (Enum)(object)itemValue); } else { newValue = FoxKitUiUtils.UIntField(position, (uint)(object)itemValue); } break; case Core.PropertyInfoType.Int64: newValue = EditorGUI.LongField(position, (long)(object)itemValue); break; case Core.PropertyInfoType.UInt64: newValue = FoxKitUiUtils.ULongField(position, (ulong)(object)itemValue); break; case Core.PropertyInfoType.Float: newValue = EditorGUI.FloatField(position, (float)(object)itemValue); break; case Core.PropertyInfoType.Double: newValue = EditorGUI.DoubleField(position, (double)(object)itemValue); break; case Core.PropertyInfoType.Bool: newValue = EditorGUI.Toggle(position, (bool)(object)itemValue); break; case Core.PropertyInfoType.String: newValue = EditorGUI.TextField(position, (string)(object)itemValue); break; case Core.PropertyInfoType.Path: newValue = EditorGUI.ObjectField( position, itemValue as UnityEngine.Object, typeof(UnityEngine.Object), false); break; case Core.PropertyInfoType.EntityPtr: newValue = FoxKitUiUtils.EntityPtrField( position, itemValue, ptrType, () => AddEntityWindow.Create(ptrType, true, createEntityCallback)); break; case Core.PropertyInfoType.Vector3: newValue = EditorGUI.Vector3Field(position, string.Empty, (UnityEngine.Vector3)(object) itemValue); break; case Core.PropertyInfoType.Vector4: newValue = EditorGUI.Vector4Field(position, string.Empty, (UnityEngine.Vector4)(object) itemValue); break; case Core.PropertyInfoType.Quat: newValue = FoxKitUiUtils.QuaternionField(position, (UnityEngine.Quaternion)(object) itemValue); break; case Core.PropertyInfoType.Matrix3: Assert.IsTrue(false, "There shouldn't be any Matrix3 properties. Report this."); break; case Core.PropertyInfoType.Matrix4: // TODO //Debug.LogWarning("Matrix4 properties not currently supported."); EditorGUI.HelpBox(position, "Matrix4 properties are not currently supported.", MessageType.Error); newValue = itemValue; break; case Core.PropertyInfoType.Color: newValue = EditorGUI.ColorField(position, (Color)(object)itemValue); break; case Core.PropertyInfoType.FilePtr: newValue = EditorGUI.ObjectField( position, itemValue as UnityEngine.Object, typeof(UnityEngine.Object), false); break; case Core.PropertyInfoType.EntityHandle: newValue = FoxKitUiUtils.EntityHandleField(position, itemValue, typeof(Entity)); break; case Core.PropertyInfoType.EntityLink: var link = itemValue as EntityLink; Action <Data> entitySelected = selected => link.Entity = selected; Action <DataIdentifier, string> dataIdentifierEntitySelected = (identifier, key) => link.SetDataIdentifier(identifier, key); newValue = FoxKitUiUtils.EntityLinkField( position, (EntityLink)(object)itemValue, entitySelected, dataIdentifierEntitySelected); break; default: throw new ArgumentOutOfRangeException(); } return((T)newValue); }
private void CreateEntity(string key) { AddEntityWindow.Create(this.ptrType, true, type => this.CreateNewEntityAtKey(type, key)); }
private void CreateEntity(int index) { AddEntityWindow.Create(this.ptrType, true, type => this.CreateNewEntityAtIndex(type, index)); }