Simple item with a label.
예제 #1
0
 /// <summary>
 /// Create and add a submenu to the menu pool.
 /// Adds an item with the given text to the menu, creates a corresponding submenu, and binds the submenu to the item.
 /// The submenu inherits its title from the menu, and its subtitle from the item text.
 /// </summary>
 /// <param name="menu">The parent menu to which the submenu must be added.</param>
 /// <param name="text">The name of the submenu.</param>
 /// <returns>The newly created submenu.</returns>
 public UIMenu AddSubMenu(UIMenu menu, string text)
 {
     var item = new UIMenuItem(text);
     menu.AddItem(item);
     var submenu = new UIMenu(menu.Title.Caption, text);
     this.Add(submenu);
     menu.BindMenuToItem(submenu, item);
     return submenu;
 }
예제 #2
0
 public UIMenuValueEntrySelector(UIMenuItem menuItem, T value)
 {
     // Must set MenuItem before setting ItemValue,
     // because ItemValue setter uses MenuItem getter
     this.MenuItem              = menuItem;
     this.ItemValue             = value;
     this.MenuItem.Activated   += ActivatedHandler;
     this.MenuItem.Description += "Press ~b~ENTER~w~ to set the name of the location you'd like to save";
 }
예제 #3
0
        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 UIMenuItem(data.Name, data.Description);
                AddItem(item);
                item.Activated += (sender, selectedItem) =>
                {
                    ReturnedData = data;
                    Visible = false;
                };
            }
            RefreshIndex();
        }
예제 #4
0
 protected virtual void ItemSelect(UIMenuItem selecteditem, int index)
 {
     OnItemSelect.Invoke(this, selecteditem, index);
 }
예제 #5
0
        public void BuildFor(SerializableData.SerializableVehicle veh)
        {
            Clear();

            #region SpawnAfter
            {
                var item = new UIMenuListItem("Spawn After Objective", StaticData.StaticLists.NumberMenu, veh.SpawnAfter);

                item.OnListChanged += (sender, index) =>
                {
                    veh.SpawnAfter = index;
                };

                AddItem(item);
            }
            #endregion

            #region RemoveAfter
            {
                var item = new UIMenuListItem("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 UIMenuListItem("Health", StaticData.StaticLists.VehicleHealthChoses, listIndex);

                item.OnListChanged += (sender, index) =>
                {
                    int newAmmo = int.Parse(((UIMenuListItem)sender).IndexToItem(index).ToString(), CultureInfo.InvariantCulture);
                    veh.Health = newAmmo;
                };

                AddItem(item);
            }
            #endregion

            #region FailOnDeath
            {
                var item = new UIMenuCheckboxItem("Mission Fail On Death", veh.FailMissionOnDeath);
                item.CheckboxEvent += (sender, @checked) =>
                {
                    veh.FailMissionOnDeath = @checked;
                };
                AddItem(item);
            }
            #endregion

            #region Passengers
            {
                var item = new UIMenuItem("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 UIMenuItem(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 UIMenuItem(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();
        }
예제 #6
0
        public void Build()
        {
            #region Name
            {
                var item = new UIMenuItem("Name");
                item.SetRightBadge(UIMenuItem.BadgeStyle.Alert);
                AddItem(item);
                item.Activated += (sender, selectedItem) =>
                {
                    GameFiber.StartNew(delegate
                    {
                        ResetKey(Common.MenuControls.Back);
                        Editor.Editor.DisableControlEnabling = true;

                        string title = Util.GetUserInput(this);
                        if (string.IsNullOrEmpty(title))
                        {
                            item.SetRightBadge(UIMenuItem.BadgeStyle.Alert);
                            item.SetRightLabel("");
                            SetKey(Common.MenuControls.Back, GameControl.CellphoneCancel, 0);
                            Editor.Editor.DisableControlEnabling = false;
                            CurrentCutscene.Name = null;
                            MenuItems[3].Enabled = false;
                            return;
                        }
                        Editor.Editor.DisableControlEnabling = false;
                        item.SetRightBadge(UIMenuItem.BadgeStyle.None);
                        CurrentCutscene.Name = title;
                        selectedItem.SetRightLabel(title.Length > 20 ? title.Substring(0, 20) + "..." : title);
                        SetKey(Common.MenuControls.Back, GameControl.CellphoneCancel, 0);

                        if (CurrentCutscene.Length > 0 && !string.IsNullOrEmpty(CurrentCutscene.Name))
                            MenuItems[3].Enabled = true;
                    });
                };
            }
            #endregion

            #region Play at Objective

            {
                CurrentCutscene.PlayAt = 0;
                var item = new UIMenuListItem("Play at Objective", StaticData.StaticLists.ObjectiveIndexList, 0);
                AddItem(item);
                item.OnListChanged += (sender, index) =>
                {
                    CurrentCutscene.PlayAt = index;
                };
            }
            #endregion

            #region Duration
            {
                var item = new UIMenuItem("Duration in Seconds");
                item.SetRightBadge(UIMenuItem.BadgeStyle.Alert);
                AddItem(item);
                item.Activated += (sender, selectedItem) =>
                {
                    GameFiber.StartNew(delegate
                    {
                        ResetKey(Common.MenuControls.Back);
                        Editor.Editor.DisableControlEnabling = true;

                        string title = Util.GetUserInput(this);
                        if (string.IsNullOrEmpty(title))
                        {
                            item.SetRightBadge(UIMenuItem.BadgeStyle.Alert);
                            item.SetRightLabel("");
                            SetKey(Common.MenuControls.Back, GameControl.CellphoneCancel, 0);
                            CurrentCutscene.Length = 0;
                            Editor.Editor.DisableControlEnabling = false;
                            return;
                        }
                        int len;
                        if (!int.TryParse(title, NumberStyles.Integer, CultureInfo.InvariantCulture, out len))
                        {
                            item.SetRightBadge(UIMenuItem.BadgeStyle.Alert);
                            item.SetRightLabel("");
                            SetKey(Common.MenuControls.Back, GameControl.CellphoneCancel, 0);
                            CurrentCutscene.Length = 0;
                            Editor.Editor.DisableControlEnabling = false;
                            Game.DisplayNotification("Integer not in correct format.");
                            return;
                        }

                        if (len <= 0)
                        {
                            item.SetRightBadge(UIMenuItem.BadgeStyle.Alert);
                            item.SetRightLabel("");
                            SetKey(Common.MenuControls.Back, GameControl.CellphoneCancel, 0);
                            CurrentCutscene.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(UIMenuItem.BadgeStyle.None);
                        CurrentCutscene.Length = len*1000;
                        selectedItem.SetRightLabel(title.Length > 20 ? title.Substring(0, 20) + "..." : title);
                        SetKey(Common.MenuControls.Back, GameControl.CellphoneCancel, 0);
                        if (CurrentCutscene.Length > 0 && !string.IsNullOrEmpty(CurrentCutscene.Name))
                            MenuItems[3].Enabled = true;
                    });
                };
            }
            #endregion

            #region Continue

            {
                var item = new UIMenuItem("Continue");
                AddItem(item);
                item.Enabled = false;
                item.Activated += (sender, selectedItem) =>
                {
                    Editor.Editor.CurrentMission.Cutscenes.Add(CurrentCutscene);
                    GrandParent.EnterCutsceneEditor(CurrentCutscene);
                    Visible = false;
                };
            }
            #endregion

            RefreshIndex();
        }
예제 #7
0
        public void RebuildCutsceneMenu()
        {
            CutsceneMenus.Clear();
            _children.Clear();

            {
                var menu = new CreateCutsceneMenu(this);
                var item = new UIMenuItem("Create Cutscene");
                CutsceneMenus.AddItem(item);
                CutsceneMenus.BindMenuToItem(menu, item);
                _children.Add(menu);
            }

            foreach (var cutscene in Editor.Editor.CurrentMission.Cutscenes)
            {
                var item = new UIMenuItem(cutscene.Name);
                CutsceneMenus.AddItem(item);
                item.Activated += (sender, selectedItem) =>
                {
                    CutsceneMenus.Visible = false;
                    EditCutsceneMenu.Build(cutscene);
                    EditCutsceneMenu.Visible = true;
                };
            }

            CutsceneMenus.RefreshIndex();
        }
예제 #8
0
        public static void OnItemSelect(UIMenu sender, UIMenuItem selectedItem, int index)
        {
            if (sender != mainMenu) return; // We only want to detect changes from our menu.
            // You can also detect the button by using index

            if (selectedItem == cookItem)   // We check which item has been selected and do different things for each.
            {
                string dish = dishesListItem.IndexToItem(dishesListItem.Index).ToString();
                bool ketchup = ketchupCheckbox.Checked;

                string output = ketchup
                    ? "You have ordered ~b~{0}~w~ ~r~with~w~ ketchup."
                    : "You have ordered ~b~{0}~w~ ~r~without~w~ ketchup.";
                Game.DisplaySubtitle(String.Format(output, dish), 5000);
            }
            else if (selectedItem == spawnCar)
            {
                GameFiber.StartNew(delegate
                {
                    new Vehicle(((string)carsList.IndexToItem(carsList.Index)).ToLower(), Game.LocalPlayer.Character.GetOffsetPositionFront(6f)).Dismiss();
                });
            }
            else if (selectedItem == coloredItem)
            {
                GameFiber.StartNew(delegate
                {
                    Game.DisplaySubtitle("~h~~r~COLOR", 500);
                    GameFiber.Sleep(500);
                    Game.DisplaySubtitle("~h~~b~COLOR", 500);
                    GameFiber.Sleep(500);
                    Game.DisplaySubtitle("~h~~g~COLOR", 500);
                    GameFiber.Sleep(500);
                    Game.DisplaySubtitle("~h~~o~COLOR", 500);
                    GameFiber.Sleep(500);
                    Game.DisplaySubtitle("~h~~d~COLOR", 500);
                });
                GameFiber.StartNew(delegate
                {
                    for (int i = 0; i < 100; i++)
                    {
                        coloredItem.HighlightColor = Color.FromArgb(MathHelper.GetRandomInteger(256), MathHelper.GetRandomInteger(256), MathHelper.GetRandomInteger(256));
                        coloredItem.HighlightedTextColor = Color.FromArgb(MathHelper.GetRandomInteger(256), MathHelper.GetRandomInteger(256), MathHelper.GetRandomInteger(256));
                        coloredItem.MainColor = Color.FromArgb(MathHelper.GetRandomInteger(256), MathHelper.GetRandomInteger(256), MathHelper.GetRandomInteger(256));
                        coloredItem.TextColor = Color.FromArgb(MathHelper.GetRandomInteger(256), MathHelper.GetRandomInteger(256), MathHelper.GetRandomInteger(256));
                        GameFiber.Sleep(10);
                    }
                });
            }
        }
예제 #9
0
 /// <summary>
 /// Remove menu binding from button.
 /// </summary>
 /// <param name="releaseFrom">Button to release from.</param>
 /// <returns>Returns true if the operation was successful.</returns>
 public bool ReleaseMenuFromItem(UIMenuItem releaseFrom)
 {
     if (!Children.ContainsKey(releaseFrom)) return false;
     Children[releaseFrom].ParentItem = null;
     Children[releaseFrom].ParentMenu = null;
     Children.Remove(releaseFrom);
     return true;
 }
        public void BuildFor(SerializableData.Objectives.SerializableVehicleObjective actor)
        {
            Clear();

            #region SpawnAfter
            {
                var item = new UIMenuListItem("Spawn After Objective", StaticData.StaticLists.NumberMenu, actor.SpawnAfter);

                item.OnListChanged += (sender, index) =>
                {
                    actor.SpawnAfter = index;
                };

                AddItem(item);
            }
            #endregion

            #region ObjectiveIndex
            {
                var item = new UIMenuListItem("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(UIMenuItem.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(UIMenuItem.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 UIMenuItem("Objective Name");
                if (string.IsNullOrEmpty(Editor.CurrentMission.ObjectiveNames[actor.ActivateAfter]))
                    item.SetRightBadge(UIMenuItem.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(this);
                        if (string.IsNullOrEmpty(title))
                        {
                            item.SetRightBadge(UIMenuItem.BadgeStyle.Alert);
                            Editor.CurrentMission.ObjectiveNames[actor.ActivateAfter] = "";
                            SetKey(Common.MenuControls.Back, GameControl.CellphoneCancel, 0);
                            Editor.DisableControlEnabling = false;
                            return;
                        }
                        item.SetRightBadge(UIMenuItem.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 UIMenuListItem("Health", StaticData.StaticLists.VehicleHealthChoses, listIndex);

                item.OnListChanged += (sender, index) =>
                {
                    int newAmmo = int.Parse(((UIMenuListItem)sender).IndexToItem(index).ToString(), CultureInfo.InvariantCulture);
                    actor.Health = newAmmo;
                };

                AddItem(item);
            }
            #endregion

            #region Passengers
            {
                var item = new UIMenuItem("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 UIMenuItem(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 UIMenuItem(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 UIMenuCheckboxItem("Show Healthbar", actor.ShowHealthBar);
                AddItem(item);

                item.CheckboxEvent += (sender, @checked) =>
                {
                    actor.ShowHealthBar = @checked;
                    MenuItems[6].Enabled = @checked;
                };
            }
            #endregion

            #region Bar Name
            {
                var item = new UIMenuItem("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(this);
                        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 UIMenuListItem("Objective Type", StaticData.StaticLists.ObjectiveTypeList, actor.ObjectiveType);

                item.OnListChanged += (sender, index) =>
                {
                    actor.ObjectiveType = index;
                };
                AddItem(item);
            }
            #endregion

            RefreshIndex();
        }
예제 #11
0
        public static void Main()
        {
            // Create a fiber to process our menus
            MenusProcessFiber = new GameFiber(ProcessLoop);

            // Create the MenuPool to easily process our menus
            _menuPool = new MenuPool();

            // Create our main menu
            mainMenu = new UIMenu("RAGENative UI", "~b~RAGENATIVEUI SHOWCASE");

            // Add our main menu to the MenuPool
            _menuPool.Add(mainMenu);

            // create our items and add them to our main menu
            mainMenu.AddItem(ketchupCheckbox = new UIMenuCheckboxItem("Add ketchup?", false, "Do you wish to add ketchup?"));

            var foods = new List<dynamic>
            {
                "Banana",
                "Apple",
                "Pizza",
                "Quartilicious",
                0xF00D, // Dynamic!
            };
            mainMenu.AddItem(dishesListItem = new UIMenuListItem("Food", foods, 0));
            mainMenu.AddItem(cookItem = new UIMenuItem("Cook!", "Cook the dish with the appropiate ingredients and ketchup."));

            var menuItem = new UIMenuItem("Go to another menu.");
            mainMenu.AddItem(menuItem);
            cookItem.SetLeftBadge(UIMenuItem.BadgeStyle.Star);
            cookItem.SetRightBadge(UIMenuItem.BadgeStyle.Tick);

            var carsModel = new List<dynamic>
            {
                "Adder",
                "Bullet",
                "Police",
                "Police2",
                "Asea",
                "FBI",
                "FBI2",
                "Firetruk",
                "Ambulance",
                "Rhino",
            };
            carsList = new UIMenuListItem("Cars Models", carsModel, 0);
            mainMenu.AddItem(carsList);

            spawnCar = new UIMenuItem("Spawn Car");
            mainMenu.AddItem(spawnCar);

            coloredItem = new UIMenuColoredItem("Color!", System.Drawing.Color.Red, System.Drawing.Color.Blue);
            mainMenu.AddItem(coloredItem);

            mainMenu.RefreshIndex();

            mainMenu.OnItemSelect += OnItemSelect;
            mainMenu.OnListChange += OnListChange;
            mainMenu.OnCheckboxChange += OnCheckboxChange;
            mainMenu.OnIndexChange += OnItemChange;

            // Create another menu
            newMenu = new UIMenu("RAGENative UI", "~b~RAGENATIVEUI SHOWCASE");
            newMenu.CounterOverride = "Counter Override";
            _menuPool.Add(newMenu); // add it to the menu pool
            for (int i = 0; i < 35; i++) // add items
            {
                newMenu.AddItem(new UIMenuItem("PageFiller " + i.ToString(), "Sample description that takes more than one line. More so, it takes way more than two lines since it's so long. Wow, check out this length!"));
            }
            newMenu.RefreshIndex();
            mainMenu.BindMenuToItem(newMenu, menuItem); // and bind it to an item in our main menu

            // Start our process fiber
            MenusProcessFiber.Start();

            // Continue with our plugin... in this example, hibernate to prevent it from being unloaded
            GameFiber.Hibernate();
        }
예제 #12
0
        public void BuildFor(TimeMarker marker)
        {
            Clear();
            Children.Clear();
            if (marker == null)
            {
                #region CreateMarker
                {
                    var item = new UIMenuItem("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 UIMenuItem("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 UIMenuItem("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 UIMenuItem("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 UIMenuItem("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 UIMenuListItem("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 UIMenuListItem("Duration", timeList, timeList.IndexOf(indx == -1 ? 0 : indx));
                    AddItem(item);

                    item.OnListChanged += (sender, index) =>
                    {
                        var floatPointTime = float.Parse(((UIMenuListItem)sender).IndexToItem(index).ToString(), CultureInfo.InvariantCulture);
                        ((SubtitleMarker)marker).Duration = (int)(floatPointTime * 1000);
                    };
                }

                #region Text
                {
                    var item = new UIMenuItem("Text");
                    if (string.IsNullOrEmpty(((SubtitleMarker)marker).Content))
                        item.SetRightBadge(UIMenuItem.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(this);
                            if (string.IsNullOrEmpty(title))
                            {
                                item.SetRightBadge(UIMenuItem.BadgeStyle.Alert);
                                ((SubtitleMarker)marker).Content = null;
                                SetKey(Common.MenuControls.Back, GameControl.CellphoneCancel, 0);
                                Editor.Editor.DisableControlEnabling = false;
                                return;
                            }
                            item.SetRightBadge(UIMenuItem.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 UIMenuListItem("Time", timeList, timeList.IndexOf(indx == -1 ? 0 : indx));
                AddItem(item);

                item.OnListChanged += (sender, index) =>
                {
                    var floatPointTime = float.Parse(((UIMenuListItem) sender).IndexToItem(index).ToString(), CultureInfo.InvariantCulture);
                    marker.Time = (int)(floatPointTime*1000);
                    GrandParent.CurrentTimestamp = marker.Time;
                };
            }

            RefreshIndex();
        }
        public void BuildFor(SerializableData.Objectives.SerializableActorObjective actor)
        {
            Clear();

            #region SpawnAfter
            {
                var item = new UIMenuListItem("Spawn After Objective", StaticData.StaticLists.NumberMenu, actor.SpawnAfter);

                item.OnListChanged += (sender, index) =>
                {
                    actor.SpawnAfter = index;
                };

                AddItem(item);
            }
            #endregion

            #region ObjectiveIndex
            {
                var item = new UIMenuListItem("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(UIMenuItem.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(UIMenuItem.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 UIMenuItem("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().Inventory.GiveNewWeapon(hash, (short)(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 UIMenuListItem("Ammo Count", StaticData.StaticLists.AmmoChoses, listIndex);

                item.OnListChanged += (sender, index) =>
                {
                    int newAmmo = int.Parse(((UIMenuListItem) 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()).Inventory.GiveNewWeapon(actor.WeaponHash, (short)newAmmo, true);
                };

                AddItem(item);
            }
            #endregion

            #region Objective Name
            {
                var item = new UIMenuItem("Objective Name");
                if (string.IsNullOrEmpty(Editor.CurrentMission.ObjectiveNames[actor.ActivateAfter]))
                    item.SetRightBadge(UIMenuItem.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(this);
                        if (string.IsNullOrEmpty(title))
                        {
                            item.SetRightBadge(UIMenuItem.BadgeStyle.Alert);
                            Editor.CurrentMission.ObjectiveNames[actor.ActivateAfter] = "";
                            SetKey(Common.MenuControls.Back, GameControl.CellphoneCancel, 0);
                            Editor.DisableControlEnabling = false;
                            return;
                        }
                        item.SetRightBadge(UIMenuItem.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 UIMenuListItem("Health", StaticData.StaticLists.HealthArmorChoses, listIndex);

                item.OnListChanged += (sender, index) =>
                {
                    int newAmmo = int.Parse(((UIMenuListItem)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 UIMenuListItem("Armor", StaticData.StaticLists.HealthArmorChoses, listIndex);

                item.OnListChanged += (sender, index) =>
                {
                    int newAmmo = int.Parse(((UIMenuListItem)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 UIMenuListItem("Accuracy", StaticData.StaticLists.AccuracyList, listIndex);

                item.OnListChanged += (sender, index) =>
                {
                    int newAmmo = int.Parse(((UIMenuListItem)sender).IndexToItem(index).ToString(), CultureInfo.InvariantCulture);
                    actor.Accuracy = newAmmo;
                };

                AddItem(item);
            }
            #endregion

            #region Relationship
            {
                var item = new UIMenuListItem("Relationship", StaticData.StaticLists.RelationshipGroups, actor.RelationshipGroup);

                item.OnListChanged += (sender, index) =>
                {
                    actor.RelationshipGroup = index;
                };

                AddItem(item);
            }
            #endregion

            #region Behaviour
            {
                var wpyItem = new UIMenuItem("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 UIMenuListItem("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 UIMenuCheckboxItem("Show Healthbar", actor.ShowHealthBar);
                AddItem(item);

                item.CheckboxEvent += (sender, @checked) =>
                {
                    actor.ShowHealthBar = @checked;
                    MenuItems[12].Enabled = @checked;
                };
            }
            #endregion

            #region Bar Name
            {
                var item = new UIMenuItem("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(this);
                        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();
        }
예제 #14
0
        public Editor()
        {
            Children = new List<INestedMenu>();

            #region NativeUI Initialization
            _menuPool = new MenuPool();
            #region Main Menu
            _mainMenu = new UIMenu("Mission Creator", "MAIN MENU");
            _mainMenu.ResetKey(Common.MenuControls.Back);
            _mainMenu.ResetKey(Common.MenuControls.Up);
            _mainMenu.ResetKey(Common.MenuControls.Down);
            _mainMenu.SetKey(Common.MenuControls.Up, GameControl.CellphoneUp, 0);
            _mainMenu.SetKey(Common.MenuControls.Down, GameControl.CellphoneDown, 0);
            _menuPool.Add(_mainMenu);

            {
                var menuItem = new UIMenuItem("Create a Mission", "Create a new mission.");
                menuItem.Activated += (sender, item) =>
                {
                    CreateNewMission();
                    EnterFreecam();
                };
                _mainMenu.AddItem(menuItem);
            }

            {
                var menuItem = new UIMenuItem("Play Mission", "Play a mission.");
                menuItem.Activated += (sender, item) =>
                {
                    GameFiber.StartNew(delegate
                    {
                        DisableControlEnabling = true;
                        var newMenu = new LoadMissionMenu();
                        _mainMenu.Visible = false;
                        newMenu.RebuildMenu();
                        newMenu.ParentMenu = _mainMenu;
                        newMenu.Visible = true;
                        while (newMenu.Visible)
                        {
                            newMenu.ProcessControl();
                            newMenu.Draw();
                            GameFiber.Yield();
                        }
                        DisableControlEnabling = false;
                        if (newMenu.ReturnedData == null) return;
                        LeaveEditor();
                        EntryPoint.MissionPlayer.Load(newMenu.ReturnedData);
                    });
                };
                _mainMenu.AddItem(menuItem);
            }

            {
                var menuItem = new UIMenuItem("Load Mission", "Load your mission for editing.");
                menuItem.Activated += (sender, item) =>
                {
                    GameFiber.StartNew(delegate
                    {
                        DisableControlEnabling = true;
                        _mainMenu.Visible = false;
                        var newMenu = new LoadMissionMenu();
                        newMenu.RebuildMenu();
                        newMenu.ParentMenu = _mainMenu;
                        newMenu.Visible = true;
                        while (newMenu.Visible)
                        {
                            newMenu.ProcessControl();
                            newMenu.Draw();
                            GameFiber.Yield();
                        }
                        DisableControlEnabling = false;
                        if (newMenu.ReturnedData == null) return;
                        LoadMission(newMenu.ReturnedData);
                    });
                };
                _mainMenu.AddItem(menuItem);
            }

            {
                var menuItem = new UIMenuItem("Exit to Grand Theft Auto V", "Leave the Mission Creator");
                menuItem.Activated += (sender, item) =>
                {
                    if(!EntryPoint.MissionPlayer.IsMissionPlaying)
                        LeaveEditor();
                    else
                    {
                        GameFiber.StartNew(delegate
                        {
                            _mainMenu.Visible = false;
                            EntryPoint.MissionPlayer.FailMission(reason: "You canceled the mission.");

                            IsInMainMenu = false;
                            _menuPool.CloseAllMenus();
                            BigMinimap = false;
                            IsInFreecam = false;
                            IsInEditor = false;
                        });
                    }
                };
                _mainMenu.AddItem(menuItem);
            }

            _menuPool.ToList().ForEach(menu =>
            {
                menu.RefreshIndex();
                menu.MouseControlsEnabled = false;
                menu.MouseEdgeEnabled = false;
            });
            #endregion

            #region Editor Menu
            _missionMenu = new UIMenu("Mission Creator", "MISSION MAIN MENU");
            _missionMenu.ResetKey(Common.MenuControls.Back);
            _missionMenu.MouseControlsEnabled = false;
            _missionMenu.ResetKey(Common.MenuControls.Up);
            _missionMenu.ResetKey(Common.MenuControls.Down);
            _missionMenu.SetKey(Common.MenuControls.Up, GameControl.CellphoneUp, 0);
            _missionMenu.SetKey(Common.MenuControls.Down, GameControl.CellphoneDown, 0);
            _menuPool.Add(_missionMenu);
            #endregion

            #endregion

            RingData = new RingData()
            {
                Display = true,
                Type = RingType.HorizontalCircleSkinny,
                Radius = 2f,
                Color = Color.Gray,
            };

            MarkerData = new MarkerData()
            {
                Display = false,
            };

            MarkerData.OnMarkerTypeChange += (sender, args) =>
            {
                if (string.IsNullOrEmpty(MarkerData.MarkerType))
                {
                    if (_mainObject != null && _mainObject.IsValid())
                        _mainObject.Delete();
                    return;
                }
                var pos = Game.LocalPlayer.Character.Position;
                if (_mainObject != null && _mainObject.IsValid())
                {
                    pos = _mainObject.Position;
                    _mainObject.Delete();
                }
                GameFiber.StartNew(delegate
                {
                    _mainObject = new Object(Util.RequestModel(MarkerData.MarkerType), pos);
                    NativeFunction.CallByName<uint>("SET_ENTITY_COLLISION", _mainObject.Handle.Value, false, 0);
                });
            };

            _cutsceneUi = new CutsceneUi();

            CameraClampMax = -30f;
            CameraClampMin = -85f;

            _blips = new List<Blip>();

            _instructButts = new Scaleform();

            if (!Directory.Exists(basePath))
            {
                try
                {
                    Directory.CreateDirectory(basePath);
                }
                catch (UnauthorizedAccessException)
                {
                    Game.DisplayNotification("~r~~h~ERROR~h~~n~~w~Access denied for folder creation. Run as administrator.");
                }
            }
        }
예제 #15
0
        public void RebuildMissionMenu(MissionData data)
        {
            _missionMenu.Clear();
            Children.Clear();

            {
                var nestMenu = new MissionInfoMenu(CurrentMission);
                var nestItem = new UIMenuItem("Mission Details");
                _missionMenu.AddItem(nestItem);
                _missionMenu.BindMenuToItem(nestMenu, nestItem);
                _menuPool.Add(nestMenu);
                Children.Add(nestMenu);
            }

            {
                var nestMenu = new PlacementMenu(CurrentMission);
                var nestItem = new UIMenuItem("Placement");
                _missionMenu.AddItem(nestItem);
                _missionMenu.BindMenuToItem(nestMenu, nestItem);
                _menuPool.Add(nestMenu);
                Children.Add(nestMenu);
                _placementMenu = nestMenu;
            }

            {
                var nestItem = new UIMenuItem("Cutscenes");
                _missionMenu.AddItem(nestItem);
                _missionMenu.BindMenuToItem(_cutsceneUi.CutsceneMenus, nestItem);
                nestItem.Activated += (sender, item) =>
                {
                    _cutsceneUi.Enter();
                };
            }

            {
                var item = new UIMenuItem("Save Mission");
                _missionMenu.AddItem(item);
                item.Activated += (sender, selectedItem) =>
                {
                    GameFiber.StartNew(delegate
                    {
                        DisableControlEnabling = true;
                        string path = Util.GetUserInput(_missionMenu);
                        if (string.IsNullOrEmpty(path))
                        {
                            DisableControlEnabling = false;
                            return;
                        }
                        DisableControlEnabling = false;
                        SaveMission(CurrentMission, path);
                    });
                };
            }

            {
                var exitItem = new UIMenuItem("Exit");
                exitItem.Activated += (sender, item) =>
                {
                    LeaveEditor();
                };
                _missionMenu.AddItem(exitItem);
            }

            _missionMenu.RefreshIndex();
        }
예제 #16
0
        /// <summary>
        /// Add an item to the menu.
        /// </summary>
        /// <param name="item">Item object to be added. Can be normal item, checkbox or list item.</param>
        public void AddItem(UIMenuItem item)
        {
            item.Offset = _offset;
            item.Parent = this;
            item.Position((MenuItems.Count * 25) - 37 + _extraYOffset);
            MenuItems.Add(item);

            RecaulculateDescriptionPosition();
        }
예제 #17
0
 /// <summary>
 /// Bind a menu to a button. When the button is clicked that menu will open.
 /// </summary>
 public void BindMenuToItem(UIMenu menuToBind, UIMenuItem itemToBindTo)
 {
     menuToBind.ParentMenu = this;
     menuToBind.ParentItem = itemToBindTo;
     if (Children.ContainsKey(itemToBindTo))
         Children[itemToBindTo] = menuToBind;
     else
         Children.Add(itemToBindTo, menuToBind);
 }
예제 #18
0
        public void BuildFor(SerializableData.SerializablePed actor)
        {
            Clear();

            #region SpawnAfter
            {
                var item = new UIMenuListItem("Spawn After Objective", StaticData.StaticLists.NumberMenu, actor.SpawnAfter);

                item.OnListChanged += (sender, index) =>
                {
                    actor.SpawnAfter = index;
                };

                AddItem(item);
            }
            #endregion

            #region RemoveAfter
            {
                var item = new UIMenuListItem("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 UIMenuItem("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()).Inventory.GiveNewWeapon(hash, (short)(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 UIMenuListItem("Ammo Count", StaticData.StaticLists.AmmoChoses, listIndex);

                item.OnListChanged += (sender, index) =>
                {
                    int newAmmo = int.Parse(((UIMenuListItem) 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()).Inventory.GiveNewWeapon(actor.WeaponHash, (short)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 UIMenuListItem("Health", StaticData.StaticLists.HealthArmorChoses, listIndex);

                item.OnListChanged += (sender, index) =>
                {
                    int newAmmo = int.Parse(((UIMenuListItem)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 UIMenuListItem("Armor", StaticData.StaticLists.HealthArmorChoses, listIndex);

                item.OnListChanged += (sender, index) =>
                {
                    int newAmmo = int.Parse(((UIMenuListItem)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 UIMenuListItem("Accuracy", StaticData.StaticLists.AccuracyList, listIndex);

                item.OnListChanged += (sender, index) =>
                {
                    int newAmmo = int.Parse(((UIMenuListItem)sender).IndexToItem(index).ToString(), CultureInfo.InvariantCulture);
                    actor.Accuracy = newAmmo;
                };

                AddItem(item);
            }
            #endregion

            #region Relationship
            {
                var item = new UIMenuListItem("Relationship", StaticData.StaticLists.RelationshipGroups, actor.RelationshipGroup);

                item.OnListChanged += (sender, index) =>
                {
                    actor.RelationshipGroup = index;
                };

                AddItem(item);
            }
            #endregion

            #region Behaviour
            {
                var wpyItem = new UIMenuItem("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 UIMenuListItem("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 UIMenuCheckboxItem("Mission Fail On Death", actor.FailMissionOnDeath);
                item.CheckboxEvent += (sender, @checked) =>
                {
                    actor.FailMissionOnDeath = @checked;
                };
                AddItem(item);
            }
            #endregion

            RefreshIndex();
        }
        public void BuildFor(SerializableData.SerializableSpawnpoint actor)
        {
            Clear();

            #region SpawnAfter
            {
                var item = new UIMenuListItem("Spawn Before Objective", StaticData.StaticLists.NumberMenu, actor.SpawnAfter);

                item.OnListChanged += (sender, index) =>
                {
                    actor.SpawnAfter = index;
                };

                AddItem(item);
            }
            #endregion

            #region Weapons
            {

                var item = new UIMenuItem("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()).Inventory.GiveNewWeapon(hash, (short)(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 UIMenuListItem("Ammo Count", StaticData.StaticLists.AmmoChoses, listIndex);

                item.OnListChanged += (sender, index) =>
                {
                    int newAmmo = int.Parse(((UIMenuListItem) 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()).Inventory.GiveNewWeapon(actor.WeaponHash, (short)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 UIMenuListItem("Health", StaticData.StaticLists.HealthArmorChoses, listIndex);

                item.OnListChanged += (sender, index) =>
                {
                    int newAmmo = int.Parse(((UIMenuListItem)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 UIMenuListItem("Armor", StaticData.StaticLists.HealthArmorChoses, listIndex);

                item.OnListChanged += (sender, index) =>
                {
                    int newAmmo = int.Parse(((UIMenuListItem)sender).IndexToItem(index).ToString(), CultureInfo.InvariantCulture);
                    actor.Armor = newAmmo;
                };

                AddItem(item);
            }
            #endregion

            RefreshIndex();
        }
예제 #20
0
 public void BindToItem(UIMenuItem item)
 {
     ItemBind       = item;
     CanBeDisplayed = (i) => item.Selected;
 }
예제 #21
0
        public static void Main()
        {
            Game.FrameRender += Process;

            _menuPool = new MenuPool();

            mainMenu = new UIMenu("RAGENative UI", "~b~RAGENATIVEUI SHOWCASE");
            mainMenu.SetKey(Common.MenuControls.Up, Keys.W);
            mainMenu.SetKey(Common.MenuControls.Down, Keys.S);
            mainMenu.SetKey(Common.MenuControls.Left, Keys.A);
            mainMenu.SetKey(Common.MenuControls.Right, Keys.D);


            _menuPool.Add(mainMenu);

            mainMenu.AddItem(ketchupCheckbox = new UIMenuCheckboxItem("Add ketchup?", false, "Do you wish to add ketchup?"));

            var foods = new List<dynamic>
            {
                "Banana",
                "Apple",
                "Pizza",
                "Quartilicious",
                0xF00D, // Dynamic!
            };
            mainMenu.AddItem(dishesListItem = new UIMenuListItem("Food", foods, 0));
            mainMenu.AddItem(cookItem = new UIMenuItem("Cook!", "Cook the dish with the appropiate ingredients and ketchup."));

            var menuItem = new UIMenuItem("Go to another menu.");
            mainMenu.AddItem(menuItem);
            cookItem.SetLeftBadge(UIMenuItem.BadgeStyle.Star);
            cookItem.SetRightBadge(UIMenuItem.BadgeStyle.Tick);

            var carsModel = new List<dynamic>
            {
                "Adder",
                "Bullet",
                "Police",
                "Police2",
                "Asea",
                "FBI",
                "FBI2",
                "Firetruk",
                "Ambulance",
                "Rhino",
            };
            carsList = new UIMenuListItem("Cars Models", carsModel, 0);
            mainMenu.AddItem(carsList);

            spawnCar = new UIMenuItem("Spawn Car");
            mainMenu.AddItem(spawnCar);

            coloredItem = new UIMenuColoredItem("Color!", System.Drawing.Color.Red, System.Drawing.Color.Blue);
            mainMenu.AddItem(coloredItem);


            mainMenu.RefreshIndex();

            mainMenu.OnItemSelect += OnItemSelect;
            mainMenu.OnListChange += OnListChange;
            mainMenu.OnCheckboxChange += OnCheckboxChange;
            mainMenu.OnIndexChange += OnItemChange;


            newMenu = new UIMenu("RAGENative UI", "~b~RAGENATIVEUI SHOWCASE");
            _menuPool.Add(newMenu);
            for (int i = 0; i < 35; i++)
            {
                newMenu.AddItem(new UIMenuItem("PageFiller " + i.ToString(), "Sample description that takes more than one line. Moreso, it takes way more than two lines since it's so long. Wow, check out this length!"));
            }
            newMenu.RefreshIndex();
            mainMenu.BindMenuToItem(newMenu, menuItem);

            while (true)
                GameFiber.Yield();
        }
        public void BuildFor(SerializableData.Objectives.SerializablePickupObjective actor)
        {
            Clear();

            #region SpawnAfter
            {
                var item = new UIMenuListItem("Spawn After Objective", StaticData.StaticLists.NumberMenu, actor.SpawnAfter);

                item.OnListChanged += (sender, index) =>
                {
                    actor.SpawnAfter = index;
                };

                AddItem(item);
            }
            #endregion

            #region ObjectiveIndex
            {
                var item = new UIMenuListItem("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(UIMenuItem.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(UIMenuItem.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 UIMenuItem("Objective Name");
                if (string.IsNullOrEmpty(Editor.CurrentMission.ObjectiveNames[actor.ActivateAfter]))
                    item.SetRightBadge(UIMenuItem.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(this);
                        if (string.IsNullOrEmpty(title))
                        {
                            item.SetRightBadge(UIMenuItem.BadgeStyle.Alert);
                            Editor.CurrentMission.ObjectiveNames[actor.ActivateAfter] = "";
                            SetKey(Common.MenuControls.Back, GameControl.CellphoneCancel, 0);
                            Editor.DisableControlEnabling = false;
                            return;
                        }
                        item.SetRightBadge(UIMenuItem.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 UIMenuListItem("Ammo Count", StaticData.StaticLists.AmmoChoses, listIndex);

                item.OnListChanged += (sender, index) =>
                {
                    int newAmmo = int.Parse(((UIMenuListItem) sender).IndexToItem(index).ToString(), CultureInfo.InvariantCulture);
                    actor.Ammo = newAmmo;
                };

                AddItem(item);
            }
            #endregion

            #region Respawn
            {
                var item = new UIMenuCheckboxItem("Respawn", actor.Respawn);
                item.CheckboxEvent += (sender, @checked) =>
                {
                    actor.Respawn = @checked;
                };
                AddItem(item);
            }
            #endregion

            RefreshIndex();
        }
예제 #23
0
        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 UIMenuItem("Create Waypoint of Type: " + list[i]);
                CreateWaypointMenu.AddItem(item);
            }

            CreateWaypointMenu.OnIndexChange += (sender, index) =>
            {
                _placingWaypointType = (WaypointTypes)Enum.Parse(typeof(WaypointTypes), list[index]);
            };

            CreateWaypointMenu.RefreshIndex();
        }
예제 #24
0
        public void RebuildWaypointPropertiesMenu(SerializableWaypoint waypoint)
        {
            _children.Clear();
            _waypointPropertiesMenu.Clear();
            _waypointPropertiesMenu.Subtitle.Caption = waypoint.Type.ToString().ToUpper() + " PROPERTIES";

            {
                var item = new UIMenuItem("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/1000).ToString());

                item.Activated += (sender, selectedItem) =>
                {
                    GameFiber.StartNew(delegate
                    {
                        _waypointPropertiesMenu.ResetKey(Common.MenuControls.Back);
                        Editor.Editor.DisableControlEnabling = true;
                        string title = Util.GetUserInput(_waypointPropertiesMenu);

                        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 UIMenuItem("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 || waypoint.Type == WaypointTypes.CruiseWithVehicle)
            {
                {
                    var item = new UIMenuItem("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(_waypointPropertiesMenu);

                            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 UIMenuListItem("Driving Style", parsedList.ToList(), indexOf);
                    _waypointPropertiesMenu.AddItem(item);

                    item.OnListChanged += (sender, index) =>
                    {
                        waypoint.DrivingStyle = StaticData.StaticLists.DrivingStylesList[index].Item2;
                    };
                }
            }

            _waypointPropertiesMenu.RefreshIndex();
        }
예제 #25
0
        public void Display(MissionData data)
        {
            Clear();

            #region Player
            {
                var item = new UIMenuItem("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 UIMenuItem("Objectives");
                var newMenu = new ObjectivePlacementMenu(data);
                Editor.Children.Add(newMenu);
                BindMenuToItem(newMenu, item);
                AddItem(item);
            }
            #endregion

            #region Actors
            {
                var item = new UIMenuItem("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 UIMenuItem("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 UIMenuItem("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 UIMenuItem("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();
        }
 /// <summary>
 /// Bind this button to an item, so it's only shown when that item is selected.
 /// </summary>
 /// <param name="item">Item to bind to.</param>
 public void BindToItem(UIMenuItem item)
 {
     ItemBind = item;
 }