private void AddMenuItem(NativeMenuItem item) { if (item.Menu?.Items != null) { ((INotifyCollectionChanged)item.Menu.Items).CollectionChanged += OnMenuItemsChanged; } }
private void SetMenu(NativeMenu menu) { var appMenu = _factory.ObtainAppMenu(); if (appMenu is null) { appMenu = _factory.CreateMenu(); } var menuItem = menu.Parent; if (menu.Parent is null) { menuItem = new NativeMenuItem(); } menuItem.Menu = menu; appMenu.Clear(); AddItemsToMenu(appMenu, new List <NativeMenuItemBase> { menuItem }); _factory.SetAppMenu(appMenu); }
private static IList <IMainMenuItem> OnMenuChanged(IAvaloniaObject targetLocation, IList <IMainMenuItem> viewModel) { NativeMenuItemBase item; foreach (var m in viewModel) { NativeMenuItem topLevelItem = new NativeMenuItem(m.ItemName.Replace("_", "")); topLevelItem.Menu = new NativeMenu(); foreach (var subItem in m.SubItems) { if (subItem.ItemName == "Separator") { item = new NativeMenuItemSeperator(); } else { item = new NativeMenuItem(subItem.ItemName.Replace("_", "")); if (subItem is IMenuCommandItem cmd) { ((NativeMenuItem)item).Command = cmd.ItemCommand; } } topLevelItem.Menu.Add(item); } (targetLocation as NativeMenu).Add(topLevelItem); } return(viewModel); }
public void RebuildCutsceneMenu() { CutsceneMenus.Clear(); _children.Clear(); { var menu = new CreateCutsceneMenu(this); var item = new NativeMenuItem("Create Cutscene"); CutsceneMenus.AddItem(item); CutsceneMenus.BindMenuToItem(menu, item); _children.Add(menu); } foreach (var cutscene in Editor.Editor.CurrentMission.Cutscenes) { var item = new NativeMenuItem(cutscene.Name); CutsceneMenus.AddItem(item); item.Activated += (sender, selectedItem) => { CutsceneMenus.Visible = false; EditCutsceneMenu.Build(cutscene); EditCutsceneMenu.Visible = true; }; } CutsceneMenus.RefreshIndex(); }
public void RebuildMenu() { if (!Directory.Exists(basePath)) { return; } Clear(); var filePaths = Directory.GetFiles(basePath, "*.xml"); foreach (string path in filePaths) { var data = Editor.ReadMission(path); if (data == null) { continue; } var item = new NativeMenuItem(data.Name, data.Description); AddItem(item); item.Activated += (sender, selectedItem) => { ReturnedData = data; Visible = false; }; } RefreshIndex(); }
private IList <NativeMenuItemBase> GetNativeItems(IEnumerable <MenuItemModel> items, NativeMenu menu = null) { var result = new List <NativeMenuItemBase>(); foreach (var item in items) { if (item is MenuItemSeparatorModel) { if (menu != null) { menu.Add(new NativeMenuItemSeperator()); } else { result.Add(new NativeMenuItemSeperator()); } } else { var gesture = item.Gesture; var nativeItem = new NativeMenuItem { Header = item.Label, Command = item.Command, }; if (gesture != null) { nativeItem.Gesture = KeyGesture.Parse(gesture); } if (nativeItem.Header == null) { nativeItem.Header = ""; } if (item.Children != null && item.Children.Any()) { var nativeMenu = new NativeMenu(); GetNativeItems(item.Children, nativeMenu); nativeItem.Menu = nativeMenu; } if (menu != null) { menu.Add(nativeItem); } else { result.Add(nativeItem); } } } return(result); }
static IDisposable?InitMenuItems(NativeMenu menu) { #if !TRAY_INDEPENDENT_PROGRAM if (IViewModelManager.Instance.MainWindow is not MainWindowViewModel main) { return(null); } #else MainWindowViewModel main = new(); #endif var query = from x in main.AllTabItems let tabItem = x is TabItemViewModel item ? item : null where tabItem != null select tabItem; tabItems = new(); foreach (var item in query) { var menuItem = new NativeMenuItem { Header = item.Name, Command = ReactiveCommand.Create(() => { OnMenuClick(item.Id); }), }; tabItems.Add(item, menuItem); menu.Add(menuItem); } exitMenuItem = new NativeMenuItem { Header = Exit, Command = ReactiveCommand.Create(() => { OnMenuClick(TaskBarWindowViewModel.CommandExit); }), }; menu.Add(exitMenuItem); #if !TRAY_INDEPENDENT_PROGRAM return(R.Subscribe(() => { if (exitMenuItem != null) { exitMenuItem.Header = Exit; } foreach (var item in tabItems) { item.Value.Header = item.Key.Name; } })); #else return(null); #endif }
protected override void InitControls() { this.Text = "Little Editor"; this.Name = "MainWindow"; this.StatusBar = true; this._TextBox = new NativeRichTextBox { Left = 0, Top = 0, Width = 480, Height = 380 }; this.Width = 500; this.Height = 400; this.StartUpPosition = WindowsStartupPosition.CenterScreen; //Creating the File Menu NativeMenu menuFile = new NativeMenu("mnuFile", "&File"); //Create Sub-Items for File-Menu NativeMenuItem menuFileOpen = new NativeMenuItem("mnuOpen", "&Open"); NativeMenuItem menuFileClose = new NativeMenuItem("mnuSave", "&Save"); NativeMenuItem menuFileSep = new NativeMenuItem("mnuFileSep") { IsSeparator = true }; NativeMenuItem menFileExit = new NativeMenuItem("mnuExit", "E&xit"); //Add Menu Event Handlers menuFileClose.Click += FileSave_Click; menuFileOpen.Click += FileOpen_Click; menFileExit.Click += Menu_Exit; //Add The Sub-Items to File-Menu menuFile.Items.Add(menuFileOpen); menuFile.Items.Add(menuFileClose); menuFile.Items.Add(menuFileSep); menuFile.Items.Add(menFileExit); //Create Help-Menu NativeMenu menuHelp = new NativeMenu("&Help"); //Add Sub-Item to Help-Menu NativeMenuItem menuInfo = new NativeMenuItem("&Info"); //Add Event-Handler menuInfo.Click += MenuInfo_Click; //Add the Sub-Item to the Help-Menu menuHelp.Items.Add(menuInfo); //Add the Help-Menu to the File-Menu menuFile.Items.Add(menuHelp); //Add the first Element of the Menu to the Form this.Menu = menuFile; this.Controls.Add(this._TextBox); }
private static IList <IMainMenuItem> OnMenuChanged(IAvaloniaObject targetLocation, IList <IMainMenuItem> viewModel) { var systemWideControlModifier = AvaloniaLocator.Current .GetService <PlatformHotkeyConfiguration>()?.CommandModifiers ?? KeyModifiers.Control; NativeMenuItemBase item; foreach (var m in viewModel) { NativeMenuItem topLevelItem = new NativeMenuItem(m.ItemName.Replace("_", "")); topLevelItem.Menu = new NativeMenu(); foreach (var subItem in m.SubItems) { if (subItem.ItemName == "Separator") { item = new NativeMenuItemSeparator(); } else { var nativeMenuItem = new NativeMenuItem(subItem.ItemName.Replace("_", "")); if (subItem is IMenuCommandItem cmd) { nativeMenuItem.Command = WrapCommand(cmd.ItemCommand, cmd); if (cmd.Shortcut.HasValue && Enum.TryParse(cmd.Shortcut.Value.Key, out Key key)) { var modifier = cmd.Shortcut.Value.Control ? systemWideControlModifier : KeyModifiers.None; if (cmd.Shortcut.Value.Shift) { modifier |= KeyModifiers.Shift; } var keyGesture = new KeyGesture(key, modifier); nativeMenuItem.Gesture = keyGesture; } } if (subItem is ICheckableMenuItem checkable) { nativeMenuItem.ToggleType = NativeMenuItemToggleType.CheckBox; checkable.ToObservable(o => o.IsChecked) .SubscribeAction(@is => nativeMenuItem.IsChecked = @is); } item = nativeMenuItem; } topLevelItem.Menu.Add(item); } ((NativeMenu)targetLocation).Add(topLevelItem); } return(viewModel); }
private NativeMenu CreateDefaultAppMenu() { var result = new NativeMenu(); var aboutItem = new NativeMenuItem("About Avalonia"); aboutItem.Click += async(_, _) => { var dialog = new AboutAvaloniaDialog(); if (Application.Current is { ApplicationLifetime : IClassicDesktopStyleApplicationLifetime { MainWindow : { } mainWindow } }) { await dialog.ShowDialog(mainWindow); } };
public void BuildCreateWaypointMenu() { CreateWaypointMenu.Clear(); var list = new List <string>(Enum.GetNames(typeof(WaypointTypes))); _placingWaypointType = (WaypointTypes)Enum.Parse(typeof(WaypointTypes), list[0]); for (int i = 0; i < list.Count; i++) { var item = new NativeMenuItem("Create Waypoint of Type: " + list[i]); CreateWaypointMenu.AddItem(item); } CreateWaypointMenu.OnIndexChange += (sender, index) => { _placingWaypointType = (WaypointTypes)Enum.Parse(typeof(WaypointTypes), list[index]); }; CreateWaypointMenu.RefreshIndex(); }
private static IList <IMainMenuItem> OnMenuChanged(IAvaloniaObject targetLocation, IList <IMainMenuItem> viewModel) { var systemWideControlModifier = AvaloniaLocator.Current .GetService <PlatformHotkeyConfiguration>()?.CommandModifiers ?? KeyModifiers.Control; NativeMenuItemBase item; foreach (var m in viewModel) { NativeMenuItem topLevelItem = new NativeMenuItem(m.ItemName.Replace("_", "")); topLevelItem.Menu = new NativeMenu(); foreach (var subItem in m.SubItems) { if (subItem.ItemName == "Separator") { item = new NativeMenuItemSeperator(); } else { var nativeMenuItem = new NativeMenuItem(subItem.ItemName.Replace("_", "")); if (subItem is IMenuCommandItem cmd) { nativeMenuItem.Command = cmd.ItemCommand; if (cmd.Shortcut.HasValue && Enum.TryParse(cmd.Shortcut.Value.Key, out Key key)) { var keyGesture = new KeyGesture(key, cmd.Shortcut.Value.Control ? systemWideControlModifier : KeyModifiers.None); nativeMenuItem.Gesture = keyGesture; } } item = nativeMenuItem; } topLevelItem.Menu.Add(item); } ((NativeMenu)targetLocation).Add(topLevelItem); } return(viewModel); }
private static NativeMenu CreateDefaultAppMenu() { var result = new NativeMenu(); var aboutItem = new NativeMenuItem { Header = "About Avalonia", }; aboutItem.Click += async(sender, e) => { var dialog = new AboutAvaloniaDialog(); var mainWindow = (Application.Current.ApplicationLifetime as IClassicDesktopStyleApplicationLifetime)?.MainWindow; await dialog.ShowDialog(mainWindow); }; result.Add(aboutItem); return(result); }
private void SetMenu(NativeMenu menu) { var menuItem = menu.Parent; var appMenuHolder = menuItem?.Parent; if (menu.Parent is null) { menuItem = new NativeMenuItem(); } if (appMenuHolder is null) { appMenuHolder = new NativeMenu(); appMenuHolder.Add(menuItem); } menuItem.Menu = menu; var setMenu = false; if (_nativeMenu is null) { _nativeMenu = (__MicroComIAvnMenuProxy)__MicroComIAvnMenuProxy.Create(_factory); _nativeMenu.Initialise(this, appMenuHolder, ""); setMenu = true; } _nativeMenu.Update(_factory, appMenuHolder); if (setMenu) { _factory.SetAppMenu(_nativeMenu); } }
private void UpdateAction(NativeMenuItem item) { _currentActionDisposable?.Dispose(); var action = new PredicateCallback(() => { if (item.Command != null || item.HasClickHandlers) { return(item.IsEnabled); } return(false); }); var callback = new MenuActionCallback(() => { (item as INativeMenuItemExporterEventsImplBridge)?.RaiseClicked(); }); _currentActionDisposable = Disposable.Create(() => { action.Dispose(); callback.Dispose(); }); SetAction(action, callback); }
public void BuildFor(SerializableData.Objectives.SerializableActorObjective actor) { Clear(); #region SpawnAfter { var item = new MenuListItem("Spawn After Objective", StaticData.StaticLists.NumberMenu, actor.SpawnAfter); item.OnListChanged += (sender, index) => { actor.SpawnAfter = index; }; AddItem(item); } #endregion #region ObjectiveIndex { var item = new MenuListItem("Objective Index", StaticData.StaticLists.ObjectiveIndexList, actor.ActivateAfter); item.OnListChanged += (sender, index) => { actor.ActivateAfter = index; if (string.IsNullOrEmpty(Editor.CurrentMission.ObjectiveNames[actor.ActivateAfter])) { MenuItems[4].SetRightBadge(NativeMenuItem.BadgeStyle.Alert); MenuItems[4].SetRightLabel(""); } else { var title = Editor.CurrentMission.ObjectiveNames[actor.ActivateAfter]; MenuItems[4].SetRightLabel(title.Length > 20 ? title.Substring(0, 20) + "..." : title); MenuItems[4].SetRightBadge(NativeMenuItem.BadgeStyle.None); } }; AddItem(item); } #endregion // TODO: Change NumberMenu to max num of objectives in mission // Note: if adding items before weapons, change item order in VehiclePropertiesMenu #region Weapons { var item = new NativeMenuItem("Weapon"); var dict = StaticData.WeaponsData.Database.ToDictionary(k => k.Key, k => k.Value.Select(x => x.Item1).ToArray()); var menu = new CategorySelectionMenu(dict, "Weapon", true, "SELECT WEAPON"); menu.Build("Melee"); Children.Add(menu); AddItem(item); BindMenuToItem(menu, item); menu.SelectionChanged += (sender, eventargs) => { GameFiber.StartNew(delegate { var hash = StaticData.WeaponsData.Database[menu.CurrentSelectedCategory].First( tuple => tuple.Item1 == menu.CurrentSelectedItem).Item2; NativeFunction.CallByName <uint>("REMOVE_ALL_PED_WEAPONS", actor.GetPed().Handle.Value, true); actor.GetPed().GiveNewWeapon(hash, actor.WeaponAmmo == 0 ? 9999 : actor.WeaponAmmo, true); actor.WeaponHash = hash; }); }; } { var listIndex = actor.WeaponAmmo == 0 ? StaticData.StaticLists.AmmoChoses.FindIndex(n => n == (dynamic)9999) : StaticData.StaticLists.AmmoChoses.FindIndex(n => n == (dynamic)actor.WeaponAmmo); var item = new MenuListItem("Ammo Count", StaticData.StaticLists.AmmoChoses, listIndex); item.OnListChanged += (sender, index) => { int newAmmo = int.Parse(((MenuListItem)sender).IndexToItem(index).ToString(), CultureInfo.InvariantCulture); actor.WeaponAmmo = newAmmo; if (actor.WeaponHash == 0) { return; } NativeFunction.CallByName <uint>("REMOVE_ALL_PED_WEAPONS", actor.GetPed().Handle.Value, true); ((Ped)actor.GetPed()).GiveNewWeapon(actor.WeaponHash, newAmmo, true); }; AddItem(item); } #endregion #region Objective Name { var item = new NativeMenuItem("Objective Name"); if (string.IsNullOrEmpty(Editor.CurrentMission.ObjectiveNames[actor.ActivateAfter])) { item.SetRightBadge(NativeMenuItem.BadgeStyle.Alert); } else { var title = Editor.CurrentMission.ObjectiveNames[actor.ActivateAfter]; item.SetRightLabel(title.Length > 20 ? title.Substring(0, 20) + "..." : title); } item.Activated += (sender, selectedItem) => { GameFiber.StartNew(delegate { ResetKey(Common.MenuControls.Back); Editor.DisableControlEnabling = true; string title = Util.GetUserInput(); if (string.IsNullOrEmpty(title)) { item.SetRightBadge(NativeMenuItem.BadgeStyle.Alert); Editor.CurrentMission.ObjectiveNames[actor.ActivateAfter] = ""; SetKey(Common.MenuControls.Back, GameControl.CellphoneCancel, 0); Editor.DisableControlEnabling = false; return; } item.SetRightBadge(NativeMenuItem.BadgeStyle.None); title = Regex.Replace(title, "-=", "~"); Editor.CurrentMission.ObjectiveNames[actor.ActivateAfter] = title; selectedItem.SetRightLabel(title.Length > 20 ? title.Substring(0, 20) + "..." : title); SetKey(Common.MenuControls.Back, GameControl.CellphoneCancel, 0); }); }; AddItem(item); } #endregion #region Health { var listIndex = actor.Health == 0 ? StaticData.StaticLists.HealthArmorChoses.FindIndex(n => n == (dynamic)200) : StaticData.StaticLists.HealthArmorChoses.FindIndex(n => n == (dynamic)actor.Health); var item = new MenuListItem("Health", StaticData.StaticLists.HealthArmorChoses, listIndex); item.OnListChanged += (sender, index) => { int newAmmo = int.Parse(((MenuListItem)sender).IndexToItem(index).ToString(), CultureInfo.InvariantCulture); actor.Health = newAmmo; }; AddItem(item); } #endregion #region Armor { var listIndex = StaticData.StaticLists.HealthArmorChoses.FindIndex(n => n == (dynamic)actor.Armor); var item = new MenuListItem("Armor", StaticData.StaticLists.HealthArmorChoses, listIndex); item.OnListChanged += (sender, index) => { int newAmmo = int.Parse(((MenuListItem)sender).IndexToItem(index).ToString(), CultureInfo.InvariantCulture); actor.Armor = newAmmo; }; AddItem(item); } #endregion #region Accuracy { var listIndex = StaticData.StaticLists.AccuracyList.FindIndex(n => n == (dynamic)actor.Accuracy); var item = new MenuListItem("Accuracy", StaticData.StaticLists.AccuracyList, listIndex); item.OnListChanged += (sender, index) => { int newAmmo = int.Parse(((MenuListItem)sender).IndexToItem(index).ToString(), CultureInfo.InvariantCulture); actor.Accuracy = newAmmo; }; AddItem(item); } #endregion #region Relationship { var item = new MenuListItem("Relationship", StaticData.StaticLists.RelationshipGroups, actor.RelationshipGroup); item.OnListChanged += (sender, index) => { actor.RelationshipGroup = index; }; AddItem(item); } #endregion #region Behaviour { var wpyItem = new NativeMenuItem("Waypoints"); { var waypMenu = new WaypointEditor(actor); BindMenuToItem(waypMenu.CreateWaypointMenu, wpyItem); Vector3 camPos = new Vector3(); Rotator camRot = new Rotator(); wpyItem.Activated += (sender, selectedItem) => { camPos = Editor.MainCamera.Position; camRot = Editor.MainCamera.Rotation; waypMenu.Enter(); Editor.WaypointEditor = waypMenu; }; waypMenu.OnEditorExit += (sender, args) => { Editor.WaypointEditor = null; Editor.DisableControlEnabling = true; if (camPos != new Vector3()) { Editor.MainCamera.Position = camPos; Editor.MainCamera.Rotation = camRot; } }; } if (actor.Behaviour != 4) // Follow Waypoints { wpyItem.Enabled = false; } var item = new MenuListItem("Behaviour", StaticData.StaticLists.Behaviour, actor.Behaviour); item.OnListChanged += (sender, index) => { actor.Behaviour = index; wpyItem.Enabled = index == 4; }; AddItem(item); AddItem(wpyItem); } #endregion #region Show Health Bar { var item = new MenuCheckboxItem("Show Healthbar", actor.ShowHealthBar); AddItem(item); item.CheckboxEvent += (sender, @checked) => { actor.ShowHealthBar = @checked; MenuItems[12].Enabled = @checked; }; } #endregion #region Bar Name { var item = new NativeMenuItem("Healthbar Label"); AddItem(item); if (!actor.ShowHealthBar) { item.Enabled = false; } if (string.IsNullOrEmpty(actor.Name) && actor.ShowHealthBar) { actor.Name = "HEALTH"; } if (actor.ShowHealthBar) { item.SetRightLabel(actor.Name.Length > 20 ? actor.Name.Substring(0, 20) : actor.Name); } item.Activated += (sender, selectedItem) => { GameFiber.StartNew(delegate { ResetKey(Common.MenuControls.Back); Editor.DisableControlEnabling = true; string title = Util.GetUserInput(); if (string.IsNullOrEmpty(title)) { actor.Name = "HEALTH"; item.SetRightLabel(actor.Name.Length > 20 ? actor.Name.Substring(0, 20) : actor.Name); SetKey(Common.MenuControls.Back, GameControl.CellphoneCancel, 0); Editor.DisableControlEnabling = false; return; } title = Regex.Replace(title, "-=", "~"); actor.Name = title; item.SetRightLabel(actor.Name.Length > 20 ? actor.Name.Substring(0, 20) : actor.Name); SetKey(Common.MenuControls.Back, GameControl.CellphoneCancel, 0); }); }; } #endregion RefreshIndex(); }
public void BuildFor(SerializableData.SerializableVehicle veh) { Clear(); #region SpawnAfter { var item = new MenuListItem("Spawn After Objective", StaticData.StaticLists.NumberMenu, veh.SpawnAfter); item.OnListChanged += (sender, index) => { veh.SpawnAfter = index; }; AddItem(item); } #endregion #region RemoveAfter { var item = new MenuListItem("Remove After Objective", StaticData.StaticLists.RemoveAfterList, veh.RemoveAfter); item.OnListChanged += (sender, index) => { veh.RemoveAfter = index; }; AddItem(item); } #endregion // TODO: Change NumberMenu to max num of objectives in mission #region Health { var listIndex = veh.Health == 0 ? StaticData.StaticLists.VehicleHealthChoses.FindIndex(n => n == (dynamic)1000) : StaticData.StaticLists.VehicleHealthChoses.FindIndex(n => n == (dynamic)veh.Health); var item = new MenuListItem("Health", StaticData.StaticLists.VehicleHealthChoses, listIndex); item.OnListChanged += (sender, index) => { int newAmmo = int.Parse(((MenuListItem)sender).IndexToItem(index).ToString(), CultureInfo.InvariantCulture); veh.Health = newAmmo; }; AddItem(item); } #endregion #region FailOnDeath { var item = new MenuCheckboxItem("Mission Fail On Death", veh.FailMissionOnDeath); item.CheckboxEvent += (sender, @checked) => { veh.FailMissionOnDeath = @checked; }; AddItem(item); } #endregion #region Passengers { var item = new NativeMenuItem("Occupants"); AddItem(item); if (((Vehicle)veh.GetEntity()).HasOccupants) { var newMenu = new UIMenu("", "OCCUPANTS", new Point(0, -107)); newMenu.MouseControlsEnabled = false; newMenu.SetBannerType(new ResRectangle()); var occupants = ((Vehicle)veh.GetEntity()).Occupants; for (int i = 0; i < occupants.Length; i++) { var ped = occupants[i]; var type = Editor.GetEntityType(ped); if (type == Editor.EntityType.NormalActor) { var act = Editor.CurrentMission.Actors.FirstOrDefault(a => a.GetEntity().Handle.Value == ped.Handle.Value); if (act == null) { continue; } var routedItem = new NativeMenuItem(i == 0 ? "Driver" : "Passenger #" + i); routedItem.Activated += (sender, selectedItem) => { Editor.DisableControlEnabling = true; Editor.EnableBasicMenuControls = true; var propMenu = new ActorPropertiesMenu(); propMenu.BuildFor(act); propMenu.MenuItems[2].Enabled = false; propMenu.OnMenuClose += _ => { newMenu.Visible = true; }; newMenu.Visible = false; propMenu.Visible = true; GameFiber.StartNew(delegate { while (propMenu.Visible) { propMenu.ProcessControl(); propMenu.Draw(); propMenu.Process(); GameFiber.Yield(); } }); }; newMenu.AddItem(routedItem); } else if (type == Editor.EntityType.ObjectiveActor) { var act = Editor.CurrentMission.Objectives .OfType <SerializableActorObjective>() .FirstOrDefault(a => a.GetPed().Handle.Value == ped.Handle.Value); if (act == null) { continue; } var routedItem = new NativeMenuItem(i == 0 ? "Objective Driver" : "Objective Passenger #" + i); routedItem.Activated += (sender, selectedItem) => { Editor.DisableControlEnabling = true; Editor.EnableBasicMenuControls = true; var propMenu = new ActorObjectivePropertiesMenu(); propMenu.BuildFor(act); propMenu.MenuItems[2].Enabled = false; propMenu.OnMenuClose += _ => { newMenu.Visible = true; }; newMenu.Visible = false; propMenu.Visible = true; GameFiber.StartNew(delegate { while (propMenu.Visible) { propMenu.ProcessControl(); propMenu.Draw(); propMenu.Process(); GameFiber.Yield(); } }); }; newMenu.AddItem(routedItem); } } BindMenuToItem(newMenu, item); newMenu.RefreshIndex(); Children.Add(newMenu); } else { item.Enabled = false; } } #endregion RefreshIndex(); }
public void BuildFor(SerializableData.SerializableSpawnpoint actor) { Clear(); #region SpawnAfter { var item = new MenuListItem("Spawn Before Objective", StaticData.StaticLists.NumberMenu, actor.SpawnAfter); item.OnListChanged += (sender, index) => { actor.SpawnAfter = index; }; AddItem(item); } #endregion #region Weapons { var item = new NativeMenuItem("Weapon"); var dict = StaticData.WeaponsData.Database.ToDictionary(k => k.Key, k => k.Value.Select(x => x.Item1).ToArray()); var menu = new CategorySelectionMenu(dict, "Weapon", true, "SELECT WEAPON"); menu.Build("Melee"); Children.Add(menu); AddItem(item); BindMenuToItem(menu, item); menu.SelectionChanged += (sender, eventargs) => { GameFiber.StartNew(delegate { var hash = StaticData.WeaponsData.Database[menu.CurrentSelectedCategory].First( tuple => tuple.Item1 == menu.CurrentSelectedItem).Item2; NativeFunction.CallByName <uint>("REMOVE_ALL_PED_WEAPONS", actor.GetEntity().Handle.Value, true); ((Ped)actor.GetEntity()).GiveNewWeapon(hash, actor.WeaponAmmo == 0 ? 9999 : actor.WeaponAmmo, true); actor.WeaponHash = hash; }); }; } { var listIndex = actor.WeaponAmmo == 0 ? StaticData.StaticLists.AmmoChoses.FindIndex(n => n == (dynamic)9999) : StaticData.StaticLists.AmmoChoses.FindIndex(n => n == (dynamic)actor.WeaponAmmo); var item = new MenuListItem("Ammo Count", StaticData.StaticLists.AmmoChoses, listIndex); item.OnListChanged += (sender, index) => { int newAmmo = int.Parse(((MenuListItem)sender).IndexToItem(index).ToString(), CultureInfo.InvariantCulture); actor.WeaponAmmo = newAmmo; if (actor.WeaponHash == 0) { return; } NativeFunction.CallByName <uint>("REMOVE_ALL_PED_WEAPONS", actor.GetEntity().Handle.Value, true); ((Ped)actor.GetEntity()).GiveNewWeapon(actor.WeaponHash, newAmmo, true); }; AddItem(item); } #endregion #region Health { var listIndex = actor.Health == 0 ? StaticData.StaticLists.HealthArmorChoses.FindIndex(n => n == (dynamic)200) : StaticData.StaticLists.HealthArmorChoses.FindIndex(n => n == (dynamic)actor.Health); var item = new MenuListItem("Health", StaticData.StaticLists.HealthArmorChoses, listIndex); item.OnListChanged += (sender, index) => { int newAmmo = int.Parse(((MenuListItem)sender).IndexToItem(index).ToString(), CultureInfo.InvariantCulture); actor.Health = newAmmo; }; AddItem(item); } #endregion #region Armor { var listIndex = StaticData.StaticLists.HealthArmorChoses.FindIndex(n => n == (dynamic)actor.Armor); var item = new MenuListItem("Armor", StaticData.StaticLists.HealthArmorChoses, listIndex); item.OnListChanged += (sender, index) => { int newAmmo = int.Parse(((MenuListItem)sender).IndexToItem(index).ToString(), CultureInfo.InvariantCulture); actor.Armor = newAmmo; }; AddItem(item); } #endregion RefreshIndex(); }
internal void Update(AvaloniaNativeMenuExporter exporter, IAvaloniaNativeFactory factory, NativeMenuItem item) { if (item != ManagedMenuItem) { throw new ArgumentException("The item does not match the menuitem being updated.", nameof(item)); } if (item.Menu != null) { if (_subMenu == null) { _subMenu = __MicroComIAvnMenuProxy.Create(factory); _subMenu.Initialise(exporter, item.Menu, item.Header); SetSubMenu(_subMenu); } _subMenu.Update(factory, item.Menu); } if (item.Menu == null && _subMenu != null) { _subMenu.Deinitialise(); _subMenu.Dispose(); SetSubMenu(null); } }
public void BuildFor(SerializableData.Objectives.SerializableVehicleObjective actor) { Clear(); #region SpawnAfter { var item = new MenuListItem("Spawn After Objective", StaticData.StaticLists.NumberMenu, actor.SpawnAfter); item.OnListChanged += (sender, index) => { actor.SpawnAfter = index; }; AddItem(item); } #endregion #region ObjectiveIndex { var item = new MenuListItem("Objective Index", StaticData.StaticLists.ObjectiveIndexList, actor.ActivateAfter); item.OnListChanged += (sender, index) => { actor.ActivateAfter = index; if (string.IsNullOrEmpty(Editor.CurrentMission.ObjectiveNames[actor.ActivateAfter])) { MenuItems[2].SetRightBadge(NativeMenuItem.BadgeStyle.Alert); MenuItems[2].SetRightLabel(""); } else { var title = Editor.CurrentMission.ObjectiveNames[actor.ActivateAfter]; MenuItems[2].SetRightLabel(title.Length > 20 ? title.Substring(0, 20) + "..." : title); MenuItems[2].SetRightBadge(NativeMenuItem.BadgeStyle.None); } }; AddItem(item); } #endregion // TODO: Change NumberMenu to max num of objectives in mission // Note: if adding items before weapons, change item order in VehiclePropertiesMenu #region Objective Name { var item = new NativeMenuItem("Objective Name"); if (string.IsNullOrEmpty(Editor.CurrentMission.ObjectiveNames[actor.ActivateAfter])) { item.SetRightBadge(NativeMenuItem.BadgeStyle.Alert); } else { var title = Editor.CurrentMission.ObjectiveNames[actor.ActivateAfter]; item.SetRightLabel(title.Length > 20 ? title.Substring(0, 20) + "..." : title); } item.Activated += (sender, selectedItem) => { GameFiber.StartNew(delegate { ResetKey(Common.MenuControls.Back); Editor.DisableControlEnabling = true; string title = Util.GetUserInput(); if (string.IsNullOrEmpty(title)) { item.SetRightBadge(NativeMenuItem.BadgeStyle.Alert); Editor.CurrentMission.ObjectiveNames[actor.ActivateAfter] = ""; SetKey(Common.MenuControls.Back, GameControl.CellphoneCancel, 0); Editor.DisableControlEnabling = false; return; } item.SetRightBadge(NativeMenuItem.BadgeStyle.None); title = Regex.Replace(title, "-=", "~"); Editor.CurrentMission.ObjectiveNames[actor.ActivateAfter] = title; selectedItem.SetRightLabel(title.Length > 20 ? title.Substring(0, 20) + "..." : title); SetKey(Common.MenuControls.Back, GameControl.CellphoneCancel, 0); }); }; AddItem(item); } #endregion #region Health { var listIndex = actor.Health == 0 ? StaticData.StaticLists.VehicleHealthChoses.FindIndex(n => n == (dynamic)1000) : StaticData.StaticLists.VehicleHealthChoses.FindIndex(n => n == (dynamic)actor.Health); var item = new MenuListItem("Health", StaticData.StaticLists.VehicleHealthChoses, listIndex); item.OnListChanged += (sender, index) => { int newAmmo = int.Parse(((MenuListItem)sender).IndexToItem(index).ToString(), CultureInfo.InvariantCulture); actor.Health = newAmmo; }; AddItem(item); } #endregion #region Passengers { var item = new NativeMenuItem("Occupants"); AddItem(item); if (((Vehicle)actor.GetVehicle()).HasOccupants) { var newMenu = new UIMenu("", "OCCUPANTS", new Point(0, -107)); newMenu.MouseControlsEnabled = false; newMenu.SetBannerType(new ResRectangle()); var occupants = ((Vehicle)actor.GetVehicle()).Occupants; for (int i = 0; i < occupants.Length; i++) { var ped = occupants[i]; var type = Editor.GetEntityType(ped); if (type == Editor.EntityType.NormalActor) { var act = Editor.CurrentMission.Actors.FirstOrDefault(a => a.GetEntity().Handle.Value == ped.Handle.Value); if (act == null) { continue; } var routedItem = new NativeMenuItem(i == 0 ? "Driver" : "Passenger #" + i); routedItem.Activated += (sender, selectedItem) => { Editor.DisableControlEnabling = true; Editor.EnableBasicMenuControls = true; var propMenu = new ActorPropertiesMenu(); propMenu.BuildFor(act); propMenu.MenuItems[2].Enabled = false; propMenu.OnMenuClose += _ => { newMenu.Visible = true; }; newMenu.Visible = false; propMenu.Visible = true; GameFiber.StartNew(delegate { while (propMenu.Visible) { propMenu.ProcessControl(); propMenu.Draw(); propMenu.Process(); GameFiber.Yield(); } }); }; newMenu.AddItem(routedItem); } else if (type == Editor.EntityType.ObjectiveActor) { var act = Editor.CurrentMission.Objectives .OfType <SerializableActorObjective>() .FirstOrDefault(a => a.GetPed().Handle.Value == ped.Handle.Value); if (act == null) { continue; } var routedItem = new NativeMenuItem(i == 0 ? "Objective Driver" : "Objective Passenger #" + i); routedItem.Activated += (sender, selectedItem) => { Editor.DisableControlEnabling = true; Editor.EnableBasicMenuControls = true; var propMenu = new ActorObjectivePropertiesMenu(); propMenu.BuildFor(act); propMenu.MenuItems[2].Enabled = false; propMenu.OnMenuClose += _ => { newMenu.Visible = true; }; newMenu.Visible = false; propMenu.Visible = true; GameFiber.StartNew(delegate { while (propMenu.Visible) { propMenu.ProcessControl(); propMenu.Draw(); propMenu.Process(); GameFiber.Yield(); } }); }; newMenu.AddItem(routedItem); } } BindMenuToItem(newMenu, item); newMenu.RefreshIndex(); Children.Add(newMenu); } else { item.Enabled = false; } } #endregion #region Show Health Bar { var item = new MenuCheckboxItem("Show Healthbar", actor.ShowHealthBar); AddItem(item); item.CheckboxEvent += (sender, @checked) => { actor.ShowHealthBar = @checked; MenuItems[6].Enabled = @checked; }; } #endregion #region Bar Name { var item = new NativeMenuItem("Healthbar Label"); AddItem(item); if (!actor.ShowHealthBar) { item.Enabled = false; } if (string.IsNullOrEmpty(actor.Name) && actor.ShowHealthBar) { actor.Name = "HEALTH"; } if (actor.ShowHealthBar) { item.SetRightLabel(actor.Name.Length > 20 ? actor.Name.Substring(0, 20) : actor.Name); } item.Activated += (sender, selectedItem) => { GameFiber.StartNew(delegate { ResetKey(Common.MenuControls.Back); Editor.DisableControlEnabling = true; string title = Util.GetUserInput(); if (string.IsNullOrEmpty(title)) { actor.Name = "HEALTH"; item.SetRightLabel(actor.Name.Length > 20 ? actor.Name.Substring(0, 20) : actor.Name); SetKey(Common.MenuControls.Back, GameControl.CellphoneCancel, 0); Editor.DisableControlEnabling = false; return; } title = Regex.Replace(title, "-=", "~"); actor.Name = title; item.SetRightLabel(actor.Name.Length > 20 ? actor.Name.Substring(0, 20) : actor.Name); SetKey(Common.MenuControls.Back, GameControl.CellphoneCancel, 0); }); }; } #endregion #region Objective Type { var item = new MenuListItem("Objective Type", StaticData.StaticLists.ObjectiveTypeList, actor.ObjectiveType); item.OnListChanged += (sender, index) => { actor.ObjectiveType = index; }; AddItem(item); } #endregion RefreshIndex(); }
public void BuildFor(SerializableData.Objectives.SerializablePickupObjective actor) { Clear(); #region SpawnAfter { var item = new MenuListItem("Spawn After Objective", StaticData.StaticLists.NumberMenu, actor.SpawnAfter); item.OnListChanged += (sender, index) => { actor.SpawnAfter = index; }; AddItem(item); } #endregion #region ObjectiveIndex { var item = new MenuListItem("Objective Index", StaticData.StaticLists.ObjectiveIndexList, actor.ActivateAfter); item.OnListChanged += (sender, index) => { actor.ActivateAfter = index; if (string.IsNullOrEmpty(Editor.CurrentMission.ObjectiveNames[actor.ActivateAfter])) { MenuItems[2].SetRightBadge(NativeMenuItem.BadgeStyle.Alert); MenuItems[2].SetRightLabel(""); } else { var title = Editor.CurrentMission.ObjectiveNames[actor.ActivateAfter]; MenuItems[2].SetRightLabel(title.Length > 20 ? title.Substring(0, 20) + "..." : title); MenuItems[2].SetRightBadge(NativeMenuItem.BadgeStyle.None); } }; AddItem(item); } #endregion // TODO: Change NumberMenu to max num of objectives in mission // Note: if adding items before weapons, change item order in VehiclePropertiesMenu #region Objective Name { var item = new NativeMenuItem("Objective Name"); if (string.IsNullOrEmpty(Editor.CurrentMission.ObjectiveNames[actor.ActivateAfter])) { item.SetRightBadge(NativeMenuItem.BadgeStyle.Alert); } else { var title = Editor.CurrentMission.ObjectiveNames[actor.ActivateAfter]; item.SetRightLabel(title.Length > 20 ? title.Substring(0, 20) + "..." : title); } item.Activated += (sender, selectedItem) => { GameFiber.StartNew(delegate { ResetKey(Common.MenuControls.Back); Editor.DisableControlEnabling = true; string title = Util.GetUserInput(); if (string.IsNullOrEmpty(title)) { item.SetRightBadge(NativeMenuItem.BadgeStyle.Alert); Editor.CurrentMission.ObjectiveNames[actor.ActivateAfter] = ""; SetKey(Common.MenuControls.Back, GameControl.CellphoneCancel, 0); Editor.DisableControlEnabling = false; return; } item.SetRightBadge(NativeMenuItem.BadgeStyle.None); title = Regex.Replace(title, "-=", "~"); Editor.CurrentMission.ObjectiveNames[actor.ActivateAfter] = title; selectedItem.SetRightLabel(title.Length > 20 ? title.Substring(0, 20) + "..." : title); SetKey(Common.MenuControls.Back, GameControl.CellphoneCancel, 0); }); }; AddItem(item); } #endregion #region Weapons { var listIndex = actor.Ammo == 0 ? StaticData.StaticLists.AmmoChoses.FindIndex(n => n == (dynamic)9999) : StaticData.StaticLists.AmmoChoses.FindIndex(n => n == (dynamic)actor.Ammo); var item = new MenuListItem("Ammo Count", StaticData.StaticLists.AmmoChoses, listIndex); item.OnListChanged += (sender, index) => { int newAmmo = int.Parse(((MenuListItem)sender).IndexToItem(index).ToString(), CultureInfo.InvariantCulture); actor.Ammo = newAmmo; }; AddItem(item); } #endregion #region Respawn { var item = new MenuCheckboxItem("Respawn", actor.Respawn); item.CheckboxEvent += (sender, @checked) => { actor.Respawn = @checked; }; AddItem(item); } #endregion RefreshIndex(); }
public void BuildFor(SerializableData.Objectives.SerializableMarker actor) { Clear(); #region SpawnAfter { var item = new MenuListItem("Spawn After Objective", StaticData.StaticLists.NumberMenu, actor.SpawnAfter); item.OnListChanged += (sender, index) => { actor.SpawnAfter = index; }; AddItem(item); } #endregion #region ObjectiveIndex { var item = new MenuListItem("Objective Index", StaticData.StaticLists.ObjectiveIndexList, actor.ActivateAfter); item.OnListChanged += (sender, index) => { actor.ActivateAfter = index; if (string.IsNullOrEmpty(Editor.CurrentMission.ObjectiveNames[actor.ActivateAfter])) { MenuItems[2].SetRightBadge(NativeMenuItem.BadgeStyle.Alert); MenuItems[2].SetRightLabel(""); } else { var title = Editor.CurrentMission.ObjectiveNames[actor.ActivateAfter]; MenuItems[2].SetRightLabel(title.Length > 20 ? title.Substring(0, 20) + "..." : title); MenuItems[2].SetRightBadge(NativeMenuItem.BadgeStyle.None); } }; AddItem(item); } #endregion // TODO: Change NumberMenu to max num of objectives in mission // Note: if adding items before weapons, change item order in VehiclePropertiesMenu #region Objective Name { var item = new NativeMenuItem("Objective Name"); if (string.IsNullOrEmpty(Editor.CurrentMission.ObjectiveNames[actor.ActivateAfter])) { item.SetRightBadge(NativeMenuItem.BadgeStyle.Alert); } else { var title = Editor.CurrentMission.ObjectiveNames[actor.ActivateAfter]; item.SetRightLabel(title.Length > 20 ? title.Substring(0, 20) + "..." : title); } item.Activated += (sender, selectedItem) => { GameFiber.StartNew(delegate { ResetKey(Common.MenuControls.Back); Editor.DisableControlEnabling = true; string title = Util.GetUserInput(); if (string.IsNullOrEmpty(title)) { item.SetRightBadge(NativeMenuItem.BadgeStyle.Alert); Editor.CurrentMission.ObjectiveNames[actor.ActivateAfter] = ""; SetKey(Common.MenuControls.Back, GameControl.CellphoneCancel, 0); Editor.DisableControlEnabling = false; return; } item.SetRightBadge(NativeMenuItem.BadgeStyle.None); title = Regex.Replace(title, "-=", "~"); Editor.CurrentMission.ObjectiveNames[actor.ActivateAfter] = title; selectedItem.SetRightLabel(title.Length > 20 ? title.Substring(0, 20) + "..." : title); SetKey(Common.MenuControls.Back, GameControl.CellphoneCancel, 0); }); }; AddItem(item); } #endregion #region Color { var col = Color.FromArgb(actor.Alpha, (int)actor.Color.X, (int)actor.Color.Y, (int)actor.Color.Z).ToKnownColor(); var idx = StaticData.StaticLists.KnownColors.IndexOf(col); var item = new MenuListItem("Color", StaticData.StaticLists.KnownColors, idx == -1 ? 0 : idx); item.OnListChanged += (sender, index) => { var newCol = (Color)Color.FromKnownColor(StaticData.StaticLists.KnownColors[index]); actor.Alpha = newCol.A; actor.Color = new Vector3(newCol.R, newCol.G, newCol.B); }; AddItem(item); } #endregion // TODO: Change NumberMenu to max num of objectives in mission RefreshIndex(); }
private NativeMenu CreateDefaultAppMenu() { var result = new NativeMenu(); var aboutItem = new NativeMenuItem("About Avalonia"); aboutItem.Click += async(sender, e) => { var dialog = new AboutAvaloniaDialog(); var mainWindow = (Application.Current.ApplicationLifetime as IClassicDesktopStyleApplicationLifetime)?.MainWindow; await dialog.ShowDialog(mainWindow); }; result.Add(aboutItem); var macOpts = AvaloniaLocator.Current.GetService <MacOSPlatformOptions>(); if (macOpts == null || !macOpts.DisableDefaultApplicationMenuItems) { result.Add(new NativeMenuItemSeparator()); var servicesMenu = new NativeMenuItem("Services"); servicesMenu.Menu = new NativeMenu { [MacOSNativeMenuCommands.IsServicesSubmenuProperty] = true }; result.Add(servicesMenu); result.Add(new NativeMenuItemSeparator()); var hideItem = new NativeMenuItem("Hide " + Application.Current.Name) { Gesture = new KeyGesture(Key.H, KeyModifiers.Meta) }; hideItem.Click += (sender, args) => { _applicationCommands.HideApp(); }; result.Add(hideItem); var hideOthersItem = new NativeMenuItem("Hide Others") { Gesture = new KeyGesture(Key.Q, KeyModifiers.Meta | KeyModifiers.Alt) }; hideOthersItem.Click += (sender, args) => { _applicationCommands.HideOthers(); }; result.Add(hideOthersItem); var showAllItem = new NativeMenuItem("Show All"); showAllItem.Click += (sender, args) => { _applicationCommands.ShowAll(); }; result.Add(showAllItem); result.Add(new NativeMenuItemSeparator()); var quitItem = new NativeMenuItem("Quit") { Gesture = new KeyGesture(Key.Q, KeyModifiers.Meta) }; quitItem.Click += (sender, args) => { _applicationCommands.ShowAll(); }; result.Add(quitItem); } return(result); }
private void MainForm_Load(object sender, EventArgs e) { this._Panel1Window = new CoreWindowsWrapper.NativeWindow(this.panel1.Handle); this._Panel2Window = new CoreWindowsWrapper.NativeWindow(this.panel2.Handle); this._NativeWindow = new CoreWindowsWrapper.NativeWindow(this.Handle); this._Panel2Window.Size += OnSize; NativeMenu menuFile = new NativeMenu("mnuFile", "&File"); //Create Sub-Items for File-Menu NativeMenuItem menuFileOpen = new NativeMenuItem("mnuOpen", "&Open"); NativeMenuItem menuFileClose = new NativeMenuItem("mnuSave", "&Save"); NativeMenuItem menuFileSep = new NativeMenuItem("mnuFileSep") { IsSeparator = true }; NativeMenuItem menFileExit = new NativeMenuItem("mnuExit", "E&xit"); //Add Menu Event Handlers menuFileClose.Click += FileSave_Click; menuFileOpen.Click += FileOpen_Click; menFileExit.Click += Menu_Exit; //Add The Sub-Items to File-Menu menuFile.Items.Add(menuFileOpen); menuFile.Items.Add(menuFileClose); menuFile.Items.Add(menuFileSep); menuFile.Items.Add(menFileExit); //Create Help-Menu NativeMenu menuHelp = new NativeMenu("&Help"); //Add Sub-Item to Help-Menu NativeMenuItem menuInfo = new NativeMenuItem("&Info"); //Add Event-Handler menuInfo.Click += MenuInfo_Click; //Add the Sub-Item to the Help-Menu menuHelp.Items.Add(menuInfo); //Add the Help-Menu to the File-Menu menuFile.Items.Add(menuHelp); this._NativeWindow.Menu = menuFile; this._NativeWindow.BackColor = CoreWindowsWrapper.Tools.ColorTool.White; this._Button = new NativeButton { Left = 10, Top = 0, Width = 100, Height = 30, Text = "<", Font = new Font() { Name = "Segoe UI Symbol", Size = 15 }, Name = "bnTestA", BackColor = ColorTool.Blue, ForeColor = ColorTool.Green }; this._Button.Font.Name = "Segoe UI "; this._Button1 = new NativeButton { Left = 150, Top = 0, Width = 100, Height = 30, Text = ">", Name = "bnTestB" //, //ControlId = 505 }; this._Button.Clicked += button_OnClicked; this._Button1.Clicked += button1_OnClicked; this._WebBrowser = new NativeWebBrowser() { Width = this._NativeWindow.Width, Height = this._NativeWindow.Height, Url = "http://www.itagnesmeyer.de", IsStatusBarEnabled = true, DefaultContextMenusEnabled = false, DevToolsEnabled = false }; this._Panel2Window.Controls.Add(this._WebBrowser); this._Panel1Window.Controls.Add(this._Button); this._Panel1Window.Controls.Add(this._Button1); this._NativeWindow.PostCreateControls(); }
public void BuildFor(SerializableData.SerializablePed actor) { Clear(); #region SpawnAfter { var item = new MenuListItem("Spawn After Objective", StaticData.StaticLists.NumberMenu, actor.SpawnAfter); item.OnListChanged += (sender, index) => { actor.SpawnAfter = index; }; AddItem(item); } #endregion #region RemoveAfter { var item = new MenuListItem("Remove After Objective", StaticData.StaticLists.RemoveAfterList, actor.RemoveAfter); item.OnListChanged += (sender, index) => { actor.RemoveAfter = index; }; AddItem(item); } #endregion // TODO: Change NumberMenu to max num of objectives in mission // Note: if adding items before weapons, change item order in VehiclePropertiesMenu #region Weapons { var item = new NativeMenuItem("Weapon"); var dict = StaticData.WeaponsData.Database.ToDictionary(k => k.Key, k => k.Value.Select(x => x.Item1).ToArray()); var menu = new CategorySelectionMenu(dict, "Weapon", true, "SELECT WEAPON"); menu.Build("Melee"); Children.Add(menu); AddItem(item); BindMenuToItem(menu, item); menu.SelectionChanged += (sender, eventargs) => { GameFiber.StartNew(delegate { var hash = StaticData.WeaponsData.Database[menu.CurrentSelectedCategory].First( tuple => tuple.Item1 == menu.CurrentSelectedItem).Item2; NativeFunction.CallByName <uint>("REMOVE_ALL_PED_WEAPONS", actor.GetEntity().Handle.Value, true); ((Ped)actor.GetEntity()).GiveNewWeapon(hash, actor.WeaponAmmo == 0 ? 9999 : actor.WeaponAmmo, true); actor.WeaponHash = hash; }); }; } { var listIndex = actor.WeaponAmmo == 0 ? StaticData.StaticLists.AmmoChoses.FindIndex(n => n == (dynamic)9999) : StaticData.StaticLists.AmmoChoses.FindIndex(n => n == (dynamic)actor.WeaponAmmo); var item = new MenuListItem("Ammo Count", StaticData.StaticLists.AmmoChoses, listIndex); item.OnListChanged += (sender, index) => { int newAmmo = int.Parse(((MenuListItem)sender).IndexToItem(index).ToString(), CultureInfo.InvariantCulture); actor.WeaponAmmo = newAmmo; if (actor.WeaponHash == 0) { return; } NativeFunction.CallByName <uint>("REMOVE_ALL_PED_WEAPONS", actor.GetEntity().Handle.Value, true); ((Ped)actor.GetEntity()).GiveNewWeapon(actor.WeaponHash, newAmmo, true); }; AddItem(item); } #endregion #region Health { var listIndex = actor.Health == 0 ? StaticData.StaticLists.HealthArmorChoses.FindIndex(n => n == (dynamic)200) : StaticData.StaticLists.HealthArmorChoses.FindIndex(n => n == (dynamic)actor.Health); var item = new MenuListItem("Health", StaticData.StaticLists.HealthArmorChoses, listIndex); item.OnListChanged += (sender, index) => { int newAmmo = int.Parse(((MenuListItem)sender).IndexToItem(index).ToString(), CultureInfo.InvariantCulture); actor.Health = newAmmo; }; AddItem(item); } #endregion #region Armor { var listIndex = StaticData.StaticLists.HealthArmorChoses.FindIndex(n => n == (dynamic)actor.Armor); var item = new MenuListItem("Armor", StaticData.StaticLists.HealthArmorChoses, listIndex); item.OnListChanged += (sender, index) => { int newAmmo = int.Parse(((MenuListItem)sender).IndexToItem(index).ToString(), CultureInfo.InvariantCulture); actor.Armor = newAmmo; }; AddItem(item); } #endregion #region Accuracy { var listIndex = StaticData.StaticLists.AccuracyList.FindIndex(n => n == (dynamic)actor.Accuracy); var item = new MenuListItem("Accuracy", StaticData.StaticLists.AccuracyList, listIndex); item.OnListChanged += (sender, index) => { int newAmmo = int.Parse(((MenuListItem)sender).IndexToItem(index).ToString(), CultureInfo.InvariantCulture); actor.Accuracy = newAmmo; }; AddItem(item); } #endregion #region Relationship { var item = new MenuListItem("Relationship", StaticData.StaticLists.RelationshipGroups, actor.RelationshipGroup); item.OnListChanged += (sender, index) => { actor.RelationshipGroup = index; }; AddItem(item); } #endregion #region Behaviour { var wpyItem = new NativeMenuItem("Waypoints"); { var waypMenu = new WaypointEditor(actor); BindMenuToItem(waypMenu.CreateWaypointMenu, wpyItem); Vector3 camPos = new Vector3(); Rotator camRot = new Rotator(); wpyItem.Activated += (sender, selectedItem) => { camPos = Editor.MainCamera.Position; camRot = Editor.MainCamera.Rotation; waypMenu.Enter(); Editor.WaypointEditor = waypMenu; }; waypMenu.OnEditorExit += (sender, args) => { Editor.WaypointEditor = null; Editor.DisableControlEnabling = true; if (camPos != new Vector3()) { Editor.MainCamera.Position = camPos; Editor.MainCamera.Rotation = camRot; } }; } if (actor.Behaviour != 4) // Follow Waypoints { wpyItem.Enabled = false; } var item = new MenuListItem("Behaviour", StaticData.StaticLists.Behaviour, actor.Behaviour); item.OnListChanged += (sender, index) => { actor.Behaviour = index; wpyItem.Enabled = index == 4; }; AddItem(item); AddItem(wpyItem); } #endregion #region FailOnDeath { var item = new MenuCheckboxItem("Mission Fail On Death", actor.FailMissionOnDeath); item.CheckboxEvent += (sender, @checked) => { actor.FailMissionOnDeath = @checked; }; AddItem(item); } #endregion RefreshIndex(); }
public void Display(MissionData data) { Clear(); #region Title { var item = new NativeMenuItem("Title"); if (string.IsNullOrEmpty(data.Name)) { item.SetRightBadge(NativeMenuItem.BadgeStyle.Alert); } else { item.SetRightLabel(data.Name.Length > 20 ? data.Name.Substring(0, 20) + "..." : data.Name); } item.Activated += (sender, selectedItem) => { GameFiber.StartNew(delegate { ResetKey(Common.MenuControls.Back); Editor.DisableControlEnabling = true; string title = Util.GetUserInput(); if (string.IsNullOrEmpty(title)) { item.SetRightBadge(NativeMenuItem.BadgeStyle.Alert); Editor.CurrentMission.Name = ""; SetKey(Common.MenuControls.Back, GameControl.CellphoneCancel, 0); Editor.DisableControlEnabling = false; return; } item.SetRightBadge(NativeMenuItem.BadgeStyle.None); Editor.CurrentMission.Name = title; selectedItem.SetRightLabel(title.Length > 20 ? title.Substring(0, 20) + "..." : title); SetKey(Common.MenuControls.Back, GameControl.CellphoneCancel, 0); Editor.DisableControlEnabling = false; }); }; AddItem(item); } #endregion #region Description { var item = new NativeMenuItem("Description"); if (string.IsNullOrEmpty(data.Description)) { item.SetRightBadge(NativeMenuItem.BadgeStyle.Alert); } else { item.SetRightLabel(data.Description.Length > 20 ? data.Description.Substring(0, 20) + "..." : data.Description); } item.Activated += (sender, selectedItem) => { GameFiber.StartNew(delegate { ResetKey(Common.MenuControls.Back); Editor.DisableControlEnabling = true; string title = Util.GetUserInput(); if (string.IsNullOrEmpty(title)) { item.SetRightBadge(NativeMenuItem.BadgeStyle.Alert); Editor.CurrentMission.Description = ""; SetKey(Common.MenuControls.Back, GameControl.CellphoneCancel, 0); Editor.DisableControlEnabling = false; return; } item.SetRightBadge(NativeMenuItem.BadgeStyle.None); Editor.CurrentMission.Description = title; selectedItem.SetRightLabel(title.Length > 20 ? title.Substring(0, 20) + "..." : title); SetKey(Common.MenuControls.Back, GameControl.CellphoneCancel, 0); Editor.DisableControlEnabling = false; }); }; AddItem(item); } #endregion #region Author { var item = new NativeMenuItem("Author"); if (string.IsNullOrEmpty(data.Author)) { var name = (string)NativeFunction.CallByHash(0x198D161F458ECC7F, typeof(string)); if (!string.IsNullOrEmpty(name) && name != "UNKNOWN") { item.SetRightLabel(name.Length > 20 ? name.Substring(0, 20) + "..." : name); Editor.CurrentMission.Author = name; } else { item.SetRightBadge(NativeMenuItem.BadgeStyle.Alert); } } else { item.SetRightLabel(data.Author); } item.Activated += (sender, selectedItem) => { GameFiber.StartNew(delegate { ResetKey(Common.MenuControls.Back); Editor.DisableControlEnabling = true; string title = Util.GetUserInput(); if (string.IsNullOrEmpty(title)) { item.SetRightBadge(NativeMenuItem.BadgeStyle.Alert); Editor.CurrentMission.Author = ""; SetKey(Common.MenuControls.Back, GameControl.CellphoneCancel, 0); Editor.DisableControlEnabling = false; return; } item.SetRightBadge(NativeMenuItem.BadgeStyle.None); Editor.CurrentMission.Author = title; selectedItem.SetRightLabel(title.Length > 20 ? title.Substring(0, 20) + "..." : title); SetKey(Common.MenuControls.Back, GameControl.CellphoneCancel, 0); Editor.DisableControlEnabling = false; }); }; AddItem(item); } #endregion #region Weather { var item = new MenuListItem("Weather", StaticData.StaticLists.WeatherTypes, StaticData.StaticLists.WeatherTypes.IndexOf(data.Weather.ToString())); AddItem(item); item.OnListChanged += (sender, index) => { data.Weather = Enum.Parse(typeof(WeatherType), item.IndexToItem(index).ToString()); }; } #endregion #region Time of Day { var item = new MenuListItem("Time", StaticData.StaticLists.TimesList, StaticData.StaticLists.TimesList.IndexOf( StaticData.StaticLists.TimeTranslation.FirstOrDefault(p => p.Value == data.Time).Key)); AddItem(item); item.OnListChanged += (sender, index) => { data.Time = StaticData.StaticLists.TimeTranslation[item.IndexToItem(index).ToString()]; }; } #endregion #region Time Limit { var item = new MenuCheckboxItem("Time Limit", data.TimeLimit.HasValue); AddItem(item); var inputItem = new NativeMenuItem("Seconds"); AddItem(inputItem); if (data.TimeLimit.HasValue) { if (data.TimeLimit.Value == 0) { inputItem.SetRightBadge(NativeMenuItem.BadgeStyle.Alert); } else { inputItem.SetRightLabel(data.TimeLimit.Value.ToString()); } } else { inputItem.Enabled = false; } inputItem.Activated += (sender, selectedItem) => { GameFiber.StartNew(delegate { ResetKey(Common.MenuControls.Back); Editor.DisableControlEnabling = true; string title = Util.GetUserInput(); if (string.IsNullOrEmpty(title)) { inputItem.SetRightBadge(NativeMenuItem.BadgeStyle.Alert); data.TimeLimit = 0; SetKey(Common.MenuControls.Back, GameControl.CellphoneCancel, 0); Editor.DisableControlEnabling = false; return; } int seconds; if (!int.TryParse(title, NumberStyles.Integer, CultureInfo.InvariantCulture, out seconds)) { Game.DisplayNotification("~h~ERROR~h~: That is not a valid number."); inputItem.SetRightBadge(NativeMenuItem.BadgeStyle.Alert); data.TimeLimit = 0; SetKey(Common.MenuControls.Back, GameControl.CellphoneCancel, 0); Editor.DisableControlEnabling = false; return; } if (seconds == 0) { Game.DisplayNotification("~h~ERROR~h~: Time limit must be more than 0"); inputItem.SetRightBadge(NativeMenuItem.BadgeStyle.Alert); data.TimeLimit = 0; SetKey(Common.MenuControls.Back, GameControl.CellphoneCancel, 0); Editor.DisableControlEnabling = false; return; } data.TimeLimit = seconds; inputItem.SetRightBadge(NativeMenuItem.BadgeStyle.None); inputItem.SetRightLabel(title.Length > 20 ? title.Substring(0, 20) + "..." : title); SetKey(Common.MenuControls.Back, GameControl.CellphoneCancel, 0); Editor.DisableControlEnabling = false; }); }; item.CheckboxEvent += (sender, @checked) => { if (!@checked) { data.TimeLimit = null; inputItem.Enabled = false; inputItem.SetRightBadge(NativeMenuItem.BadgeStyle.None); inputItem.SetRightLabel(""); } else { inputItem.Enabled = true; inputItem.SetRightBadge(NativeMenuItem.BadgeStyle.Alert); inputItem.SetRightLabel(""); } }; } #endregion #region Max Wanted { var item = new MenuListItem("Maximum Wanted Level", StaticData.StaticLists.WantedList, data.MaxWanted); AddItem(item); item.OnListChanged += (sender, index) => { data.MaxWanted = index; }; } #endregion #region Min Wanted { var item = new MenuListItem("Minimum Wanted Level", StaticData.StaticLists.WantedList, data.MinWanted); AddItem(item); item.OnListChanged += (sender, index) => { data.MinWanted = index; }; } #endregion #region Interiors { var item = new NativeMenuItem("Interiors"); var newMenu = new InteriorsMenu(data); AddItem(item); BindMenuToItem(newMenu, item); Children.Add(newMenu); } #endregion RefreshIndex(); }
public void BuildFor(TimeMarker marker) { Clear(); Children.Clear(); if (marker == null) { #region CreateMarker { var item = new NativeMenuItem("Create new Camera Marker"); AddItem(item); item.Activated += (sender, selectedItem) => { CameraShutterAnimation(); var newM = new CameraMarker() { Time = GrandParent.CurrentTimestamp, CameraPos = Editor.Editor.MainCamera.Position, CameraRot = Editor.Editor.MainCamera.Rotation, }; GrandParent.Markers.Add(newM); BuildFor(newM); }; } { var item = new NativeMenuItem("Create new Subtitle Marker"); AddItem(item); item.Activated += (sender, selectedItem) => { var newM = new SubtitleMarker { Time = GrandParent.CurrentTimestamp, Duration = 3000 }; GrandParent.Markers.Add(newM); BuildFor(newM); }; } /* * { * var item = new NativeMenuItem("Create new Actor Marker"); * AddItem(item); * item.Activated += (sender, selectedItem) => * { * var newM = new ActorMarker() * { * Time = GrandParent.CurrentTimestamp, * }; * GrandParent.Markers.Add(newM); * BuildFor(newM); * }; * } * * { * var item = new NativeMenuItem("Create new Vehicle Marker"); * AddItem(item); * item.Activated += (sender, selectedItem) => * { * var newM = new ActorMarker() * { * Time = GrandParent.CurrentTimestamp, * }; * GrandParent.Markers.Add(newM); * BuildFor(newM); * }; * } */ #endregion RefreshIndex(); return; } var timeList = new List <dynamic>(Enumerable.Range(0, (int)(GrandParent.CurrentCutscene.Length / 100f) + 1).Select(n => (dynamic)(n / 10f))); { var item = new NativeMenuItem("Remove This Marker"); item.Activated += (sender, selectedItem) => { GrandParent.Markers.Remove(marker); BuildFor(null); }; AddItem(item); } if (marker is CameraMarker) { var objList = StaticData.StaticLists.InterpolationList.Select(x => (dynamic)(((InterpolationStyle)x).ToString())) .ToList(); var item = new MenuListItem("Interpolation", objList, StaticData.StaticLists.InterpolationList.IndexOf(((CameraMarker)marker).Interpolation)); AddItem(item); item.OnListChanged += (sender, index) => { ((CameraMarker)marker).Interpolation = (InterpolationStyle)StaticData.StaticLists.InterpolationList[index]; }; } else if (marker is SubtitleMarker) { { var indx = (dynamic)((SubtitleMarker)marker).Duration / 1000f; var item = new MenuListItem("Duration", timeList, timeList.IndexOf(indx == -1 ? 0 : indx)); AddItem(item); item.OnListChanged += (sender, index) => { var floatPointTime = float.Parse(((MenuListItem)sender).IndexToItem(index).ToString(), CultureInfo.InvariantCulture); ((SubtitleMarker)marker).Duration = (int)(floatPointTime * 1000); }; } #region Text { var item = new NativeMenuItem("Text"); if (string.IsNullOrEmpty(((SubtitleMarker)marker).Content)) { item.SetRightBadge(NativeMenuItem.BadgeStyle.Alert); } else { var title = ((SubtitleMarker)marker).Content; item.SetRightLabel(title.Length > 20 ? title.Substring(0, 20) + "..." : title); } item.Activated += (sender, selectedItem) => { GameFiber.StartNew(delegate { ResetKey(Common.MenuControls.Back); Editor.Editor.DisableControlEnabling = true; string title = Util.GetUserInput(); if (string.IsNullOrEmpty(title)) { item.SetRightBadge(NativeMenuItem.BadgeStyle.Alert); ((SubtitleMarker)marker).Content = null; SetKey(Common.MenuControls.Back, GameControl.CellphoneCancel, 0); Editor.Editor.DisableControlEnabling = false; return; } item.SetRightBadge(NativeMenuItem.BadgeStyle.None); title = Regex.Replace(title, "-=", "~"); ((SubtitleMarker)marker).Content = title; selectedItem.SetRightLabel(title.Length > 20 ? title.Substring(0, 20) + "..." : title); SetKey(Common.MenuControls.Back, GameControl.CellphoneCancel, 0); Editor.Editor.DisableControlEnabling = false; }); }; AddItem(item); } #endregion } { var indx = (dynamic)marker.Time / 1000f; var item = new MenuListItem("Time", timeList, timeList.IndexOf(indx == -1 ? 0 : indx)); AddItem(item); item.OnListChanged += (sender, index) => { var floatPointTime = float.Parse(((MenuListItem)sender).IndexToItem(index).ToString(), CultureInfo.InvariantCulture); marker.Time = (int)(floatPointTime * 1000); GrandParent.CurrentTimestamp = marker.Time; }; } RefreshIndex(); }
public void RebuildWaypointPropertiesMenu(SerializableWaypoint waypoint) { _children.Clear(); _waypointPropertiesMenu.Clear(); _waypointPropertiesMenu.Subtitle.Caption = waypoint.Type.ToString().ToUpper() + " PROPERTIES"; { var item = new NativeMenuItem("Duration", "Task duration in seconds. Leave blank to wait until the task is done."); _waypointPropertiesMenu.AddItem(item); item.SetRightLabel(waypoint.Duration == 0 ? "Wait Until Done" : waypoint.Duration.ToString()); item.Activated += (sender, selectedItem) => { GameFiber.StartNew(delegate { _waypointPropertiesMenu.ResetKey(Common.MenuControls.Back); Editor.Editor.DisableControlEnabling = true; string title = Util.GetUserInput(); Editor.Editor.DisableControlEnabling = false; _waypointPropertiesMenu.SetKey(Common.MenuControls.Back, GameControl.CellphoneCancel, 0); if (string.IsNullOrEmpty(title)) { waypoint.Duration = 0; selectedItem.SetRightLabel("Wait Until Done"); return; } float duration; if (!float.TryParse(title, NumberStyles.Float, CultureInfo.InvariantCulture, out duration)) { waypoint.Duration = 0; selectedItem.SetRightLabel("Wait Until Done"); Game.DisplayNotification("Incorrect format."); } waypoint.Duration = (int)(duration * 1000); selectedItem.SetRightLabel(duration.ToString()); }); }; } if (waypoint.Type == WaypointTypes.Animation) { var db = StaticData.AnimData.Database.ToDictionary(k => k.Key, k => k.Value.Select(x => x.Item1).ToArray()); var menu = new CategorySelectionMenu(db, "Animation", true, "SELECT ANIMATION"); var item = new NativeMenuItem("Select Animation"); menu.Build(db.ElementAt(0).Key); if (!string.IsNullOrEmpty(waypoint.AnimName)) { var categName = StaticData.AnimData.Database.FirstOrDefault(cats => { return(cats.Value.Any(v => v.Item3 == waypoint.AnimName)); }).Key; var humanName = StaticData.AnimData.Database[categName].FirstOrDefault(v => v.Item3 == waypoint.AnimName)?.Item1; if (!string.IsNullOrEmpty(humanName)) { item.SetRightLabel(humanName); } } menu.SelectionChanged += (sender, args) => { var pair = StaticData.AnimData.Database[menu.CurrentSelectedCategory].First( m => m.Item1 == menu.CurrentSelectedItem); waypoint.AnimDict = pair.Item2; waypoint.AnimName = pair.Item3; }; _waypointPropertiesMenu.AddItem(item); _waypointPropertiesMenu.BindMenuToItem(menu, item); _children.Add(menu); } if (waypoint.Type == WaypointTypes.Drive) { { var item = new NativeMenuItem("Driving Speed", "Driving speed in meters per second."); _waypointPropertiesMenu.AddItem(item); item.SetRightLabel(waypoint.VehicleSpeed == 0 ? "Default" : waypoint.VehicleSpeed.ToString()); item.Activated += (sender, selectedItem) => { GameFiber.StartNew(delegate { _waypointPropertiesMenu.ResetKey(Common.MenuControls.Back); Editor.Editor.DisableControlEnabling = true; string title = Util.GetUserInput(); Editor.Editor.DisableControlEnabling = false; _waypointPropertiesMenu.SetKey(Common.MenuControls.Back, GameControl.CellphoneCancel, 0); if (string.IsNullOrEmpty(title)) { waypoint.VehicleSpeed = 20; selectedItem.SetRightLabel("Default"); return; } float duration; if (!float.TryParse(title, NumberStyles.Float, CultureInfo.InvariantCulture, out duration)) { waypoint.VehicleSpeed = 20; selectedItem.SetRightLabel("Default"); Game.DisplayNotification("Incorrect format."); } waypoint.VehicleSpeed = duration; selectedItem.SetRightLabel(duration.ToString()); }); }; } { var parsedList = StaticData.StaticLists.DrivingStylesList.Select(t => (dynamic)t.Item1); var indexOf = StaticData.StaticLists.DrivingStylesList.FindIndex(tup => tup.Item2 == waypoint.DrivingStyle); var item = new MenuListItem("Driving Style", parsedList.ToList(), indexOf); _waypointPropertiesMenu.AddItem(item); item.OnListChanged += (sender, index) => { waypoint.DrivingStyle = StaticData.StaticLists.DrivingStylesList[index].Item2; }; } } _waypointPropertiesMenu.RefreshIndex(); }
public void Display(MissionData data) { Clear(); #region Player { var item = new NativeMenuItem("Player"); var dict = StaticData.PedData.Database.ToDictionary(k => k.Key, k => k.Value.Select(x => x.Item1).ToArray()); var menu = new CategorySelectionMenu(dict, "Player Skin", "PLACE SPAWNPOINT"); menu.Build("Main Characters"); Children.Add(menu); AddItem(item); BindMenuToItem(menu, item); item.Activated += (men, itm) => { Editor.PlayerSpawnOpen = true; Editor.RingData.Color = Color.MediumPurple; Editor.RingData.Type = RingType.HorizontalSplitArrowCircle; Editor.MarkerData.Display = true; Editor.MarkerData.MarkerType = "prop_mp_placement"; GameFiber.StartNew(delegate { var hash = StaticData.PedData.Database[menu.CurrentSelectedCategory].First( tuple => tuple.Item1 == menu.CurrentSelectedItem).Item2; var veh = new Ped(Util.RequestModel(hash), Game.LocalPlayer.Character.Position, 0f); veh.IsPositionFrozen = true; Editor.MarkerData.RepresentedBy = veh; NativeFunction.CallByName <uint>("SET_ENTITY_COLLISION", veh.Handle.Value, false, 0); }); }; menu.OnMenuClose += (men) => { if (Editor.MarkerData.RepresentedBy != null && Editor.MarkerData.RepresentedBy.IsValid()) { Editor.MarkerData.RepresentedBy.Delete(); } Editor.MarkerData.RepresentedBy = null; Editor.MarkerData.MarkerType = null; Editor.MarkerData.Display = false; Editor.MarkerData.HeightOffset = 0f; Editor.RingData.HeightOffset = 0f; Editor.RingData.Color = Color.Gray; Editor.RingData.Type = RingType.HorizontalCircleSkinny; Editor.PlayerSpawnOpen = false; }; menu.SelectionChanged += (sender, eventargs) => { GameFiber.StartNew(delegate { menu.ResetKey(Common.MenuControls.Right); menu.ResetKey(Common.MenuControls.Left); var heading = 0f; if (Editor.MarkerData.RepresentedBy != null && Editor.MarkerData.RepresentedBy.IsValid()) { heading = Editor.MarkerData.RepresentedBy.Heading; Editor.MarkerData.RepresentedBy.Model.Dismiss(); Editor.MarkerData.RepresentedBy.Delete(); } var hash = StaticData.PedData.Database[menu.CurrentSelectedCategory].First( tuple => tuple.Item1 == menu.CurrentSelectedItem).Item2; var veh = new Ped(Util.RequestModel(hash), Game.LocalPlayer.Character.Position, 0f); veh.Heading = heading; veh.IsPositionFrozen = true; Editor.MarkerData.RepresentedBy = veh; NativeFunction.CallByName <uint>("SET_ENTITY_COLLISION", veh.Handle.Value, false, 0); //var dims = Util.GetModelDimensions(veh.Model); //Editor.RingData.HeightOffset = 1f; //Editor.MarkerData.HeightOffset = 1f; menu.SetKey(Common.MenuControls.Left, GameControl.CellphoneLeft, 0); menu.SetKey(Common.MenuControls.Right, GameControl.CellphoneRight, 0); }); }; } #endregion #region Objectives { var item = new NativeMenuItem("Objectives"); var newMenu = new ObjectivePlacementMenu(data); Editor.Children.Add(newMenu); BindMenuToItem(newMenu, item); AddItem(item); } #endregion #region Actors { var item = new NativeMenuItem("Actors"); var dict = StaticData.PedData.Database.ToDictionary(k => k.Key, k => k.Value.Select(x => x.Item1).ToArray()); var menu = new CategorySelectionMenu(dict, "Actor"); menu.Build("Cops and Army"); Children.Add(menu); AddItem(item); BindMenuToItem(menu, item); item.Activated += (men, itm) => { Editor.RingData.Color = Color.MediumPurple; Editor.RingData.Type = RingType.HorizontalSplitArrowCircle; Editor.MarkerData.Display = true; Editor.MarkerData.MarkerType = "prop_mp_placement"; GameFiber.StartNew(delegate { var hash = StaticData.PedData.Database[menu.CurrentSelectedCategory].First( tuple => tuple.Item1 == menu.CurrentSelectedItem).Item2; var veh = new Ped(Util.RequestModel(hash), Game.LocalPlayer.Character.Position, 0f); veh.IsPositionFrozen = true; Editor.MarkerData.RepresentedBy = veh; NativeFunction.CallByName <uint>("SET_ENTITY_COLLISION", veh.Handle.Value, false, 0); }); }; menu.OnMenuClose += (men) => { if (Editor.MarkerData.RepresentedBy != null && Editor.MarkerData.RepresentedBy.IsValid()) { Editor.MarkerData.RepresentedBy.Delete(); } Editor.MarkerData.RepresentedBy = null; Editor.MarkerData.MarkerType = null; Editor.MarkerData.Display = false; Editor.MarkerData.HeightOffset = 0f; Editor.RingData.HeightOffset = 0f; Editor.RingData.Color = Color.Gray; Editor.RingData.Type = RingType.HorizontalCircleSkinny; }; menu.SelectionChanged += (sender, eventargs) => { GameFiber.StartNew(delegate { menu.ResetKey(Common.MenuControls.Right); menu.ResetKey(Common.MenuControls.Left); var heading = 0f; if (Editor.MarkerData.RepresentedBy != null && Editor.MarkerData.RepresentedBy.IsValid()) { heading = Editor.MarkerData.RepresentedBy.Heading; Editor.MarkerData.RepresentedBy.Model.Dismiss(); Editor.MarkerData.RepresentedBy.Delete(); } var hash = StaticData.PedData.Database[menu.CurrentSelectedCategory].First( tuple => tuple.Item1 == menu.CurrentSelectedItem).Item2; var veh = new Ped(Util.RequestModel(hash), Game.LocalPlayer.Character.Position, 0f); veh.Heading = heading; veh.IsPositionFrozen = true; Editor.MarkerData.RepresentedBy = veh; NativeFunction.CallByName <uint>("SET_ENTITY_COLLISION", veh.Handle.Value, false, 0); //var dims = Util.GetModelDimensions(veh.Model); //Editor.RingData.HeightOffset = 1f; //Editor.MarkerData.HeightOffset = 1f; menu.SetKey(Common.MenuControls.Left, GameControl.CellphoneLeft, 0); menu.SetKey(Common.MenuControls.Right, GameControl.CellphoneRight, 0); }); }; } #endregion #region Cars { var item = new NativeMenuItem("Cars"); var dict = StaticData.VehicleData.Database.ToDictionary(k => k.Key, k => k.Value.Select(x => x.Item1).ToArray()); var menu = new CategorySelectionMenu(dict, "Vehicle"); menu.Build("Muscle"); Children.Add(menu); AddItem(item); BindMenuToItem(menu, item); item.Activated += (men, itm) => { Editor.RingData.Color = Color.MediumPurple; Editor.RingData.Type = RingType.HorizontalSplitArrowCircle; Editor.MarkerData.Display = true; Editor.MarkerData.MarkerType = "prop_mp_placement"; Editor.RingData.HeightOffset = 1f; Editor.MarkerData.HeightOffset = 1f; GameFiber.StartNew(delegate { var hash = StaticData.VehicleData.Database[menu.CurrentSelectedCategory].First( tuple => tuple.Item1 == menu.CurrentSelectedItem).Item2; var veh = new Vehicle(Util.RequestModel(hash), Game.LocalPlayer.Character.Position); veh.IsPositionFrozen = true; Editor.MarkerData.RepresentedBy = veh; NativeFunction.CallByName <uint>("SET_ENTITY_COLLISION", veh.Handle.Value, false, 0); }); }; menu.OnMenuClose += (men) => { if (Editor.MarkerData.RepresentedBy != null && Editor.MarkerData.RepresentedBy.IsValid()) { Editor.MarkerData.RepresentedBy.Delete(); } Editor.MarkerData.RepresentedBy = null; Editor.MarkerData.MarkerType = null; Editor.MarkerData.Display = false; Editor.MarkerData.HeightOffset = 0f; Editor.RingData.HeightOffset = 0f; Editor.RingData.Color = Color.Gray; Editor.RingData.Type = RingType.HorizontalCircleSkinny; }; menu.SelectionChanged += (sender, eventargs) => { GameFiber.StartNew(delegate { menu.ResetKey(Common.MenuControls.Right); menu.ResetKey(Common.MenuControls.Left); var heading = 0f; if (Editor.MarkerData.RepresentedBy != null && Editor.MarkerData.RepresentedBy.IsValid()) { heading = Editor.MarkerData.RepresentedBy.Heading; Editor.MarkerData.RepresentedBy.Model.Dismiss(); Editor.MarkerData.RepresentedBy.Delete(); } var hash = StaticData.VehicleData.Database[menu.CurrentSelectedCategory].First( tuple => tuple.Item1 == menu.CurrentSelectedItem).Item2; var veh = new Vehicle(Util.RequestModel(hash), Game.LocalPlayer.Character.Position); veh.Heading = heading; veh.IsPositionFrozen = true; Editor.MarkerData.RepresentedBy = veh; NativeFunction.CallByName <uint>("SET_ENTITY_COLLISION", veh.Handle.Value, false, 0); Vector3 max; Vector3 min; Util.GetModelDimensions(veh.Model, out max, out min); Editor.RingData.HeightOffset = min.Z - max.Z + 0.2f; Editor.MarkerData.HeightOffset = min.Z - max.Z + 0.2f; menu.SetKey(Common.MenuControls.Left, GameControl.CellphoneLeft, 0); menu.SetKey(Common.MenuControls.Right, GameControl.CellphoneRight, 0); }); }; } #endregion #region Pickups { var item = new NativeMenuItem("Pickups"); var dict = StaticData.PickupData.Database.ToDictionary(k => k.Key, k => k.Value.Select(x => x.Item1).ToArray()); var menu = new CategorySelectionMenu(dict, "Weapon"); menu.Build("Pistols"); Children.Add(menu); AddItem(item); BindMenuToItem(menu, item); item.Activated += (men, itm) => { Editor.RingData.Color = Color.MediumPurple; Editor.RingData.Type = RingType.HorizontalSplitArrowCircle; Editor.MarkerData.Display = false; Editor.MarkerData.RepresentationHeightOffset = 1f; GameFiber.StartNew(delegate { var hash = StaticData.PickupData.Database[menu.CurrentSelectedCategory].First( tuple => tuple.Item1 == menu.CurrentSelectedItem).Item2; var pos = Game.LocalPlayer.Character.Position; var veh = new Rage.Object(Util.RequestModel("prop_mp_repair"), pos); Editor.PlacedWeaponHash = hash; veh.IsPositionFrozen = true; Editor.MarkerData.RepresentedBy = veh; NativeFunction.CallByName <uint>("SET_ENTITY_COLLISION", veh.Handle.Value, false, 0); }); }; menu.OnMenuClose += (men) => { if (Editor.MarkerData.RepresentedBy != null && Editor.MarkerData.RepresentedBy.IsValid()) { Editor.MarkerData.RepresentedBy.Delete(); } Editor.MarkerData.RepresentedBy = null; Editor.MarkerData.MarkerType = null; Editor.MarkerData.Display = false; Editor.MarkerData.HeightOffset = 0f; Editor.MarkerData.RepresentationHeightOffset = 0f; Editor.RingData.HeightOffset = 0f; Editor.RingData.Color = Color.Gray; Editor.RingData.Type = RingType.HorizontalCircleSkinny; Editor.PlacedWeaponHash = 0; }; menu.SelectionChanged += (sender, eventargs) => { GameFiber.StartNew(delegate { var hash = StaticData.PickupData.Database[menu.CurrentSelectedCategory].First( tuple => tuple.Item1 == menu.CurrentSelectedItem).Item2; Editor.PlacedWeaponHash = hash; //var dims = Util.GetModelDimensions(veh.Model); //Editor.RingData.HeightOffset = 1f; //Editor.MarkerData.HeightOffset = 1f; }); }; } #endregion #region Objects { { var item = new NativeMenuItem("Objects"); var dict = StaticData.ObjectData.Database.ToDictionary(k => k.Key, k => k.Value.Select(x => x.Item1).ToArray()); var menu = new CategorySelectionMenu(dict, "Model"); menu.Build("Ramps"); Children.Add(menu); AddItem(item); BindMenuToItem(menu, item); item.Activated += (men, itm) => { Editor.RingData.Color = Color.MediumPurple; Editor.RingData.Type = RingType.HorizontalSplitArrowCircle; Editor.MarkerData.Display = true; Editor.MarkerData.MarkerType = "prop_mp_placement"; Editor.MarkerData.RepresentationHeightOffset = 1f; GameFiber.StartNew(delegate { var hash = StaticData.ObjectData.Database[menu.CurrentSelectedCategory].First( tuple => tuple.Item1 == menu.CurrentSelectedItem).Item2; var pos = Game.LocalPlayer.Character.Position; var veh = new Rage.Object(Util.RequestModel(hash), pos); veh.IsPositionFrozen = true; Editor.MarkerData.RepresentedBy = veh; NativeFunction.CallByName <uint>("SET_ENTITY_COLLISION", veh.Handle.Value, false, 0); }); }; menu.OnMenuClose += (men) => { if (Editor.MarkerData.RepresentedBy != null && Editor.MarkerData.RepresentedBy.IsValid()) { Editor.MarkerData.RepresentedBy.Delete(); } Editor.MarkerData.RepresentedBy = null; Editor.MarkerData.MarkerType = null; Editor.MarkerData.Display = false; Editor.MarkerData.HeightOffset = 0f; Editor.MarkerData.RepresentationHeightOffset = 0f; Editor.RingData.HeightOffset = 0f; Editor.RingData.Color = Color.Gray; Editor.RingData.Type = RingType.HorizontalCircleSkinny; }; menu.SelectionChanged += (sender, eventargs) => { GameFiber.StartNew(delegate { menu.ResetKey(Common.MenuControls.Right); menu.ResetKey(Common.MenuControls.Left); var heading = 0f; if (Editor.MarkerData.RepresentedBy != null && Editor.MarkerData.RepresentedBy.IsValid()) { heading = Editor.MarkerData.RepresentedBy.Heading; Editor.MarkerData.RepresentedBy.Model.Dismiss(); Editor.MarkerData.RepresentedBy.Delete(); } var hash = StaticData.ObjectData.Database[menu.CurrentSelectedCategory].First( tuple => tuple.Item1 == menu.CurrentSelectedItem).Item2; var pos = Game.LocalPlayer.Character.Position; var veh = new Rage.Object(Util.RequestModel(hash), pos); veh.Heading = heading; veh.IsPositionFrozen = true; Editor.MarkerData.RepresentedBy = veh; NativeFunction.CallByName <uint>("SET_ENTITY_COLLISION", veh.Handle.Value, false, 0); //var dims = Util.GetModelDimensions(veh.Model); //Editor.RingData.HeightOffset = 1f; //Editor.MarkerData.HeightOffset = 1f; menu.SetKey(Common.MenuControls.Left, GameControl.CellphoneLeft, 0); menu.SetKey(Common.MenuControls.Right, GameControl.CellphoneRight, 0); }); }; } } #endregion RefreshIndex(); }
public void Build(SerializableCutscene cutscene) { Clear(); #region Name { var item = new NativeMenuItem("Name"); item.SetRightLabel(cutscene.Name); AddItem(item); item.Activated += (sender, selectedItem) => { GameFiber.StartNew(delegate { ResetKey(Common.MenuControls.Back); Editor.Editor.DisableControlEnabling = true; string title = Util.GetUserInput(); if (string.IsNullOrEmpty(title)) { item.SetRightBadge(NativeMenuItem.BadgeStyle.Alert); item.SetRightLabel(""); SetKey(Common.MenuControls.Back, GameControl.CellphoneCancel, 0); Editor.Editor.DisableControlEnabling = false; cutscene.Name = null; MenuItems[3].Enabled = false; return; } Editor.Editor.DisableControlEnabling = false; item.SetRightBadge(NativeMenuItem.BadgeStyle.None); cutscene.Name = title; selectedItem.SetRightLabel(title.Length > 20 ? title.Substring(0, 20) + "..." : title); SetKey(Common.MenuControls.Back, GameControl.CellphoneCancel, 0); if (cutscene.Length > 0 && !string.IsNullOrEmpty(cutscene.Name)) { MenuItems[3].Enabled = true; } }); }; } #endregion #region Play at Objective { var item = new MenuListItem("Play at Objective", StaticData.StaticLists.ObjectiveIndexList, cutscene.PlayAt); AddItem(item); item.OnListChanged += (sender, index) => { cutscene.PlayAt = index; }; } #endregion #region Duration { var item = new NativeMenuItem("Duration in Seconds"); item.SetRightLabel(((int)(cutscene.Length / 1000f)).ToString()); AddItem(item); item.Activated += (sender, selectedItem) => { GameFiber.StartNew(delegate { ResetKey(Common.MenuControls.Back); Editor.Editor.DisableControlEnabling = true; string title = Util.GetUserInput(); if (string.IsNullOrEmpty(title)) { item.SetRightBadge(NativeMenuItem.BadgeStyle.Alert); item.SetRightLabel(""); SetKey(Common.MenuControls.Back, GameControl.CellphoneCancel, 0); cutscene.Length = 0; Editor.Editor.DisableControlEnabling = false; MenuItems[3].Enabled = false; return; } int len; if (!int.TryParse(title, NumberStyles.Integer, CultureInfo.InvariantCulture, out len)) { item.SetRightBadge(NativeMenuItem.BadgeStyle.Alert); item.SetRightLabel(""); SetKey(Common.MenuControls.Back, GameControl.CellphoneCancel, 0); cutscene.Length = 0; Editor.Editor.DisableControlEnabling = false; MenuItems[3].Enabled = false; Game.DisplayNotification("Integer not in correct format."); return; } if (len <= 0) { item.SetRightBadge(NativeMenuItem.BadgeStyle.Alert); item.SetRightLabel(""); SetKey(Common.MenuControls.Back, GameControl.CellphoneCancel, 0); cutscene.Length = 0; Editor.Editor.DisableControlEnabling = false; Game.DisplayNotification("Duration must be more than 0"); MenuItems[3].Enabled = false; return; } Editor.Editor.DisableControlEnabling = false; item.SetRightBadge(NativeMenuItem.BadgeStyle.None); cutscene.Length = len * 1000; selectedItem.SetRightLabel(title.Length > 20 ? title.Substring(0, 20) + "..." : title); SetKey(Common.MenuControls.Back, GameControl.CellphoneCancel, 0); if (cutscene.Length > 0 && !string.IsNullOrEmpty(cutscene.Name)) { MenuItems[3].Enabled = true; } }); }; } #endregion #region Edit { var item = new NativeMenuItem("Continue"); AddItem(item); if (cutscene.Length == 0 || string.IsNullOrEmpty(cutscene.Name)) { MenuItems[3].Enabled = false; } item.Activated += (sender, selectedItem) => { GrandParent.EnterCutsceneEditor(cutscene); Visible = false; }; } #endregion RefreshIndex(); }