Base class for RAGENativeUI. Calls the next events: OnIndexChange, OnListChanged, OnCheckboxChange, OnItemSelect, OnMenuClose, OnMenuchange.
        private WaypointEditor()
        {
            CreateWaypointMenu = new UIMenu("", "WAYPOINTS", new Point(0, -107));
            _waypointPropertiesMenu = new UIMenu("", "EDIT WAYPOINT", new Point(0, -107));
            _children = new List<UIMenu>();

            CreateWaypointMenu.SetBannerType(new ResRectangle());
            CreateWaypointMenu.MouseControlsEnabled = false;
            //CreateWaypointMenu.ResetKey(Common.MenuControls.Back);
            CreateWaypointMenu.ResetKey(Common.MenuControls.Up);
            CreateWaypointMenu.ResetKey(Common.MenuControls.Down);
            CreateWaypointMenu.SetKey(Common.MenuControls.Up, GameControl.CellphoneUp, 0);
            CreateWaypointMenu.SetKey(Common.MenuControls.Down, GameControl.CellphoneDown, 0);

            CreateWaypointMenu.OnMenuClose += sender =>
            {
                IsInEditor = false;
                OnEditorExit?.Invoke(this, EventArgs.Empty);
            };

            _waypointPropertiesMenu.SetBannerType(new ResRectangle());
            _waypointPropertiesMenu.MouseControlsEnabled = false;
            _waypointPropertiesMenu.ResetKey(Common.MenuControls.Up);
            _waypointPropertiesMenu.ResetKey(Common.MenuControls.Down);
            _waypointPropertiesMenu.SetKey(Common.MenuControls.Up, GameControl.CellphoneUp, 0);
            _waypointPropertiesMenu.SetKey(Common.MenuControls.Down, GameControl.CellphoneDown, 0);

            BuildCreateWaypointMenu();

            _waypointPropertiesMenu.OnMenuClose += sender =>
            {
                CreateWaypointMenu.Visible = true;
            };
        }
Example #2
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;
 }
Example #3
0
        public CutsceneUi()
        {
            #region NativeUI Init
            {
                CutsceneMenus = new UIMenu("Cutscene Creator", "CUTSCENES");
                CutsceneMenus.MouseControlsEnabled = false;
                CutsceneMenus.ResetKey(Common.MenuControls.Up);
                CutsceneMenus.ResetKey(Common.MenuControls.Down);
                CutsceneMenus.SetKey(Common.MenuControls.Up, GameControl.CellphoneUp, 0);
                CutsceneMenus.SetKey(Common.MenuControls.Down, GameControl.CellphoneDown, 0);

                MarkerMenu = new TimelineMarkerMenu(this);
                
                EditCutsceneMenu = new EditCutsceneMenu(this);
                EditCutsceneMenu.ParentMenu = CutsceneMenus;
            }
            #endregion

            _children = new List<UIMenu>();
        }
        public void BuildFor(SerializableData.Objectives.SerializableVehicleObjective actor)
        {
            Clear();

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

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

                AddItem(item);
            }
            #endregion

            #region ObjectiveIndex
            {
                var item = new MenuListItem("Objective Index", StaticData.StaticLists.ObjectiveIndexList, actor.ActivateAfter);

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


                    if (string.IsNullOrEmpty(Editor.CurrentMission.ObjectiveNames[actor.ActivateAfter]))
                    {
                        MenuItems[2].SetRightBadge(NativeMenuItem.BadgeStyle.Alert);
                        MenuItems[2].SetRightLabel("");
                    }
                    else
                    {
                        var title = Editor.CurrentMission.ObjectiveNames[actor.ActivateAfter];
                        MenuItems[2].SetRightLabel(title.Length > 20 ? title.Substring(0, 20) + "..." : title);
                        MenuItems[2].SetRightBadge(NativeMenuItem.BadgeStyle.None);
                    }
                };

                AddItem(item);
            }
            #endregion 
            // TODO: Change NumberMenu to max num of objectives in mission

            // Note: if adding items before weapons, change item order in VehiclePropertiesMenu
            
            #region Objective Name
            {
                var item = new NativeMenuItem("Objective Name");
                if (string.IsNullOrEmpty(Editor.CurrentMission.ObjectiveNames[actor.ActivateAfter]))
                    item.SetRightBadge(NativeMenuItem.BadgeStyle.Alert);
                else
                {
                    var title = Editor.CurrentMission.ObjectiveNames[actor.ActivateAfter];
                    item.SetRightLabel(title.Length > 20 ? title.Substring(0, 20) + "..." : title);
                }

                item.Activated += (sender, selectedItem) =>
                {
                    GameFiber.StartNew(delegate
                    {
                        ResetKey(Common.MenuControls.Back);
                        Editor.DisableControlEnabling = true;
                        string title = Util.GetUserInput();
                        if (string.IsNullOrEmpty(title))
                        {
                            item.SetRightBadge(NativeMenuItem.BadgeStyle.Alert);
                            Editor.CurrentMission.ObjectiveNames[actor.ActivateAfter] = "";
                            SetKey(Common.MenuControls.Back, GameControl.CellphoneCancel, 0);
                            Editor.DisableControlEnabling = false;
                            return;
                        }
                        item.SetRightBadge(NativeMenuItem.BadgeStyle.None);
                        title = Regex.Replace(title, "-=", "~");
                        Editor.CurrentMission.ObjectiveNames[actor.ActivateAfter] = title;
                        selectedItem.SetRightLabel(title.Length > 20 ? title.Substring(0, 20) + "..." : title);
                        SetKey(Common.MenuControls.Back, GameControl.CellphoneCancel, 0);
                    });
                };
                AddItem(item);
            }
            #endregion

            #region Health
            {
                var listIndex = actor.Health == 0
                    ? StaticData.StaticLists.VehicleHealthChoses.FindIndex(n => n == (dynamic)1000)
                    : StaticData.StaticLists.VehicleHealthChoses.FindIndex(n => n == (dynamic)actor.Health);

                var item = new MenuListItem("Health", StaticData.StaticLists.VehicleHealthChoses, listIndex);

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

                AddItem(item);
            }
            #endregion
            
            #region Passengers
            {
                var item = new NativeMenuItem("Occupants");
                AddItem(item);
                if (((Vehicle)actor.GetVehicle()).HasOccupants)
                {
                    var newMenu = new UIMenu("", "OCCUPANTS", new Point(0, -107));
                    newMenu.MouseControlsEnabled = false;
                    newMenu.SetBannerType(new ResRectangle());
                    var occupants = ((Vehicle)actor.GetVehicle()).Occupants;
                    for (int i = 0; i < occupants.Length; i++)
                    {
                        var ped = occupants[i];
                        var type = Editor.GetEntityType(ped);
                        if (type == Editor.EntityType.NormalActor)
                        {
                            var act = Editor.CurrentMission.Actors.FirstOrDefault(a => a.GetEntity().Handle.Value == ped.Handle.Value);
                            if (act == null) continue;
                            var routedItem = new NativeMenuItem(i == 0 ? "Driver" : "Passenger #" + i);
                            routedItem.Activated += (sender, selectedItem) =>
                            {
                                Editor.DisableControlEnabling = true;
                                Editor.EnableBasicMenuControls = true;
                                var propMenu = new ActorPropertiesMenu();
                                propMenu.BuildFor(act);
                                propMenu.MenuItems[2].Enabled = false;
                                propMenu.OnMenuClose += _ =>
                                {
                                    newMenu.Visible = true;
                                };

                                newMenu.Visible = false;
                                propMenu.Visible = true;
                                GameFiber.StartNew(delegate
                                {
                                    while (propMenu.Visible)
                                    {
                                        propMenu.ProcessControl();
                                        propMenu.Draw();
                                        propMenu.Process();
                                        GameFiber.Yield();
                                    }
                                });

                            };
                            newMenu.AddItem(routedItem);
                        }
                        else if (type == Editor.EntityType.ObjectiveActor)
                        {
                            var act = Editor.CurrentMission.Objectives
                                .OfType<SerializableActorObjective>()
                                .FirstOrDefault(a => a.GetPed().Handle.Value == ped.Handle.Value);
                            if (act == null) continue;
                            var routedItem = new NativeMenuItem(i == 0 ? "Objective Driver" : "Objective Passenger #" + i);
                            routedItem.Activated += (sender, selectedItem) =>
                            {
                                Editor.DisableControlEnabling = true;
                                Editor.EnableBasicMenuControls = true;
                                var propMenu = new ActorObjectivePropertiesMenu();
                                propMenu.BuildFor(act);
                                propMenu.MenuItems[2].Enabled = false;
                                propMenu.OnMenuClose += _ =>
                                {
                                    newMenu.Visible = true;
                                };

                                newMenu.Visible = false;
                                propMenu.Visible = true;
                                GameFiber.StartNew(delegate
                                {
                                    while (propMenu.Visible)
                                    {
                                        propMenu.ProcessControl();
                                        propMenu.Draw();
                                        propMenu.Process();
                                        GameFiber.Yield();
                                    }
                                });

                            };
                            newMenu.AddItem(routedItem);
                        }
                        
                    }
                    BindMenuToItem(newMenu, item);
                    newMenu.RefreshIndex();
                    Children.Add(newMenu);
                }
                else
                {
                    item.Enabled = false;
                }

            }
            #endregion

            #region Show Health Bar
            {
                var item = new MenuCheckboxItem("Show Healthbar", actor.ShowHealthBar);
                AddItem(item);

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

            #region Bar Name
            {
                var item = new NativeMenuItem("Healthbar Label");
                AddItem(item);

                if (!actor.ShowHealthBar)
                    item.Enabled = false;

                if (string.IsNullOrEmpty(actor.Name) && actor.ShowHealthBar)
                    actor.Name = "HEALTH";
                if (actor.ShowHealthBar)
                    item.SetRightLabel(actor.Name.Length > 20 ? actor.Name.Substring(0, 20) : actor.Name);


                item.Activated += (sender, selectedItem) =>
                {
                    GameFiber.StartNew(delegate
                    {
                        ResetKey(Common.MenuControls.Back);
                        Editor.DisableControlEnabling = true;
                        string title = Util.GetUserInput();
                        if (string.IsNullOrEmpty(title))
                        {
                            actor.Name = "HEALTH";
                            item.SetRightLabel(actor.Name.Length > 20 ? actor.Name.Substring(0, 20) : actor.Name);
                            SetKey(Common.MenuControls.Back, GameControl.CellphoneCancel, 0);
                            Editor.DisableControlEnabling = false;
                            return;
                        }
                        title = Regex.Replace(title, "-=", "~");
                        actor.Name = title;
                        item.SetRightLabel(actor.Name.Length > 20 ? actor.Name.Substring(0, 20) : actor.Name);
                        SetKey(Common.MenuControls.Back, GameControl.CellphoneCancel, 0);
                    });
                };
            }
            #endregion

            #region Objective Type
            {
                var item = new MenuListItem("Objective Type", StaticData.StaticLists.ObjectiveTypeList, actor.ObjectiveType);

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

            RefreshIndex();
        }
Example #5
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();
        }
Example #6
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);
                    }
                });
            }
        }
Example #7
0
 public static void OnListChange(UIMenu sender, UIMenuListItem list, int index)
 {
     if (sender != mainMenu || list != dishesListItem) return; // We only want to detect changes from our menu.
     string dish = list.IndexToItem(index).ToString();
     Game.DisplayNotification("Preparing ~b~" + dish + "~w~...");
 }
Example #8
0
 public static void OnCheckboxChange(UIMenu sender, UIMenuCheckboxItem checkbox, bool Checked)
 {
     if (sender != mainMenu || checkbox != ketchupCheckbox) return; // We only want to detect changes from our menu.
     Game.DisplayNotification("~r~Ketchup status: ~b~" + Checked);
 }
Example #9
0
 /// <summary>
 /// Removes the specified menu from the pool
 /// </summary>
 /// <param name="menu"></param>
 public void Remove(UIMenu menu)
 {
     _menuList.Remove(menu);
 }
Example #10
0
        public void RebuildMissionMenu(MissionData data)
        {
            _missionMenu.Clear();
            Children.Clear();

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

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

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

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

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

            _missionMenu.RefreshIndex();
        }
Example #11
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 NativeMenuItem("Create a Mission", "Create a new mission.");
                menuItem.Activated += (sender, item) =>
                {
                    CreateNewMission();
                    EnterFreecam();
                };
                _mainMenu.AddItem(menuItem);
            }

            {
                var menuItem = new NativeMenuItem("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 NativeMenuItem("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 NativeMenuItem("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.");
                }
            }
        }
        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();
        }
Example #13
0
 /// <summary>
 /// Add your menu to the menu pool.
 /// </summary>
 /// <param name="menu"></param>
 public void Add(UIMenu menu)
 {
     _menuList.Add(menu);
 }
Example #14
0
        public static void OnItemSelect(UIMenu sender, NativeMenuItem 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 wich 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.Position + Game.LocalPlayer.Character.ForwardVector * 5.6f).Dismiss();
                });
            }
        }
Example #15
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();
        }
Example #16
0
 protected virtual void MenuChangeEv(UIMenu newmenu, bool forward)
 {
     OnMenuChange.Invoke(this, newmenu, forward);
 }
Example #17
0
 /// <summary>
 /// Bind a menu to a button. When the button is clicked that menu will open.
 /// </summary>
 public void BindMenuToItem(UIMenu menuToBind, NativeMenuItem itemToBindTo)
 {
     menuToBind.ParentMenu = this;
     menuToBind.ParentItem = itemToBindTo;
     if (Children.ContainsKey(itemToBindTo))
         Children[itemToBindTo] = menuToBind;
     else
         Children.Add(itemToBindTo, menuToBind);
 }
Example #18
0
 public static void OnItemChange(UIMenu sender, int index)
 {
     sender.MenuItems[index].SetLeftBadge(UIMenuItem.BadgeStyle.None);
 }