private IAvnMenuItem CreateNew(IAvaloniaNativeFactory factory, NativeMenuItemBase item) { var nativeItem = item is NativeMenuItemSeperator?factory.CreateMenuItemSeperator() : factory.CreateMenuItem(); nativeItem.ManagedMenuItem = item; return(nativeItem); }
private IAvnMenuItem CreateNewAt(IAvaloniaNativeFactory factory, int index, NativeMenuItemBase item) { var result = CreateNew(factory, item); result.Initialise(item); _menuItemLookup.Add(result.ManagedMenuItem, result); _menuItems.Insert(index, result); InsertItem(index, result); return(result); }
private int GetId(NativeMenuItemBase item) { if (_itemsToIds.TryGetValue(item, out var id)) { return(id); } id = _nextId++; _idsToItems[id] = item; _itemsToIds[item] = id; item.PropertyChanged += OnItemPropertyChanged; if (item is NativeMenuItem nmi) { EnsureSubscribed(nmi.Menu); } return(id); }
private void CreateMenuItemForFile(string fileName) { var level = Serializer.Deserialize <SpaceLevel>(fileName); if (level == null) { return; } level.FilePath = fileName; var menuItem = new NativeMenuItemBase(Path.GetFileNameWithoutExtension(fileName), "Select to create level from: " + fileName) { Tag = level }; MainMenu.MenuItems.Add(menuItem); }
private void CreateMenu() { MainMenu.MenuItems.Clear(); var addPlanetMenu = MenuManager.NativeMenuManager.AddSubMenu("Level Editor", "SELECT A MODEL", "Add Planet", "Add a planet that's defined in Planets.txt", MainMenu); addPlanetMenu.Init(); addPlanetMenu.MenuOpened += OnAddPlanetsMenuOpened; EntityDatabaseMenu = MenuManager.NativeMenuManager.AddSubMenu("Level Editor", "SELECT AN OBJECT", "Entity Database", "Select and edit the currently active entities.", MainMenu); EntityDatabaseMenu.Init(); EntityDatabaseMenu.MenuOpened += OnEntityDatabaseOpened; var saveItem = new NativeMenuItemBase("Save", "Save the current level.", null, ShopIcon.ShopHealthIcon); MainMenu.MenuItems.Add(saveItem); saveItem.Selected += OnSaveSelected; }
internal void Initialise(NativeMenuItemBase nativeMenuItem) { ManagedMenuItem = nativeMenuItem; if (ManagedMenuItem is NativeMenuItem item) { UpdateTitle(item.Header); UpdateGesture(item.Gesture); UpdateAction(ManagedMenuItem as NativeMenuItem); UpdateToggleType(item.ToggleType); UpdateIcon(item.Icon); UpdateIsChecked(item.IsChecked); _propertyDisposables.Add(ManagedMenuItem.GetObservable(NativeMenuItem.HeaderProperty) .Subscribe(x => UpdateTitle(x))); _propertyDisposables.Add(ManagedMenuItem.GetObservable(NativeMenuItem.GestureProperty) .Subscribe(x => UpdateGesture(x))); _propertyDisposables.Add(ManagedMenuItem.GetObservable(NativeMenuItem.CommandProperty) .Subscribe(x => UpdateAction(ManagedMenuItem as NativeMenuItem))); _propertyDisposables.Add(ManagedMenuItem.GetObservable(NativeMenuItem.ToggleTypeProperty) .Subscribe(x => UpdateToggleType(x))); _propertyDisposables.Add(ManagedMenuItem.GetObservable(NativeMenuItem.IsCheckedProperty) .Subscribe(x => UpdateIsChecked(x))); _propertyDisposables.Add(ManagedMenuItem.GetObservable(NativeMenuItem.IconProperty) .Subscribe(x => UpdateIcon(x))); } }
private void AddPlanetItems(NativeMenu menu) { const string textFile = "Planets.txt"; if (!Directory.Exists(Paths.Models)) { return; } if (!File.Exists(Paths.Models + textFile)) { return; } menu.MenuItems.Clear(); var text = File.ReadAllLines(Paths.Models + textFile); foreach (var line in text) { var model = new Model(line); if (!model.IsValid) { continue; } var menuItem = new NativeMenuItemBase(line, "Create " + line) { Tag = line }; menuItem.Selected += OnEntitySpawnItemSelected; menu.MenuItems.Add(menuItem); } }
public NativeMenuItemCheckboxEventArgs(NativeMenuItemBase menuItem, int menuItemIndex, bool check) : base( menuItem, menuItemIndex) { Checked = check; }
public NativeMenuIndexChangedEventArgs(NativeMenuItemBase menuItem, NativeMenuItemBase lastItem, int menuItemIndex) : base(menuItem, menuItemIndex) { LastItem = lastItem; }
private __MicroComIAvnMenuItemProxy CreateNew(IAvaloniaNativeFactory factory, NativeMenuItemBase item) { var nativeItem = (__MicroComIAvnMenuItemProxy)(item is NativeMenuItemSeparator ? factory.CreateMenuItemSeparator() : factory.CreateMenuItem()); nativeItem.ManagedMenuItem = item; return nativeItem; }
private NativeMenu CreateMenuForObject(object obj, string modelName) { var type = obj.GetType(); var properties = type.GetProperties(); var menu = new NativeMenu(modelName, "EDIT MODE", MainMenu.BannerType); foreach (var property in properties) { var pType = property.PropertyType; NativeMenuItemBase item = null; if (pType == typeof(int)) { item = new NativeMenuUnmanagedListItem(property.Name, string.Empty, property.GetValue(obj)); } else if (pType == typeof(float)) { item = new NativeMenuUnmanagedListItem(property.Name, string.Empty, property.GetValue(obj)); } else if (pType.IsEnum) { item = new NativeMenuUnmanagedListItem(property.Name, string.Empty, property.GetValue(obj)); } else if (pType == typeof(bool)) { item = new NativeMenuCheckboxItem(property.Name, string.Empty, (bool)property.GetValue(obj)); } else if (pType == typeof(Vector3)) { var subMenu = MenuManager.NativeMenuManager.AddSubMenu(property.Name, "EDIT VECTOR", property.Name + " ~g~>>", string.Empty, menu); var vector = (Vector3)property.GetValue(obj); var xItem = new NativeMenuUnmanagedListItem("X", string.Empty, vector.X); var yItem = new NativeMenuUnmanagedListItem("Y", string.Empty, vector.Y); var zItem = new NativeMenuUnmanagedListItem("Z", string.Empty, vector.Z); var persicionItem = new NativeMenuListItem("Precision", string.Empty, new object[] { 1000, 100, 10, 1, 0.1f, 0.01f, 0.001f, 0.0001f }, 3); #region Index Changed Event xItem.ChangedIndex += (sender, e) => { if (float.TryParse(persicionItem.CurrentValue, NumberStyles.Any, CultureInfo.InstalledUICulture, out var f)) { vector.X += (float)Math.Round(e.LeftRight * f, 4); xItem.Value = vector.X; property.SetValue(obj, vector); } }; yItem.ChangedIndex += (sender, e) => { if (float.TryParse(persicionItem.CurrentValue, NumberStyles.Any, CultureInfo.InstalledUICulture, out var f)) { vector.Y += (float)Math.Round(e.LeftRight * f, 4); yItem.Value = vector.Y; property.SetValue(obj, vector); } }; zItem.ChangedIndex += (sender, e) => { if (float.TryParse(persicionItem.CurrentValue, NumberStyles.Any, CultureInfo.InstalledUICulture, out var f)) { vector.Z += (float)Math.Round(e.LeftRight * f, 4); zItem.Value = vector.Z; property.SetValue(obj, vector); } }; #endregion #region Selected Event xItem.Selected += (sender, e) => { var input = Game.GetUserInput(vector.X.ToString(), 99); if (float.TryParse(input, NumberStyles.Any, CultureInfo.InvariantCulture, out var f)) { vector.X = f; xItem.Value = vector.X; property.SetValue(obj, vector); } }; yItem.Selected += (sender, e) => { var input = Game.GetUserInput(vector.Y.ToString(), 99); if (float.TryParse(input, NumberStyles.Any, CultureInfo.InvariantCulture, out var f)) { vector.Y = f; yItem.Value = vector.Y; property.SetValue(obj, vector); } }; zItem.Selected += (sender, e) => { var input = Game.GetUserInput(vector.Z.ToString(), 99); if (float.TryParse(input, NumberStyles.Any, CultureInfo.InvariantCulture, out var f)) { vector.Z = f; zItem.Value = vector.Z; property.SetValue(obj, vector); } }; #endregion subMenu.MenuItems.Add(xItem); subMenu.MenuItems.Add(yItem); subMenu.MenuItems.Add(zItem); subMenu.MenuItems.Add(persicionItem); subMenu.Init(); } else if (pType == typeof(string)) { item = new NativeMenuItemBase(property.Name, string.Empty, property.GetValue(obj)); } if (item != null) { item.Tag = new Tuple <PropertyInfo, object>(property, obj); if (item is NativeMenuUnmanagedListItem listItem) { listItem.ChangedIndex += OnEditMenuItemNavigated; } item.Selected += OnEditMenuItemSelected; menu.MenuItems.Add(item); } } return(menu); }
public NativeMenuItemUnmanagedNavigateIndexEventArgs(NativeMenuItemBase menuItem, int menuItemIndex, int leftRight) : base(menuItem, menuItemIndex) { LeftRight = leftRight; }
public NativeMenuItemNavigateIndexEventArgs(NativeMenuItemBase menuItem, int menuItemIndex, int navIndex) : base(menuItem, menuItemIndex) { NavigationIndex = navIndex; }