public MainWindow() { InitializeComponent(); RouteController = new RouteController(this); UpdateRoute(RouteController.Route); // MapControl.Map.Layers.Add(GetKaagTileLayer()); MapControl.Map.Layers.Add(new TileLayer(KnownTileSources.Create(KnownTileSource.OpenStreetMap))); MapControl.Map.Layers.Add(RouteLayer); MapControl.Map.Layers.Add(RoutePointsLayer); MapControl.Map.Layers.Add(SectionsLayer); MapControl.Map.Layers.Add(SectionPointsLayer); MapControl.Map.Home = navigator => navigator.NavigateTo(SphericalMercator.FromLonLat(4.55835, 52.22002), 6); var wayPointEditor = new WaypointEditor(MapControl, RouteController); var sectionEditor = new SectionEditor(MapControl, RouteController); sectionEditor.OnDeselected(); WaypointModeOption.Checked += (sender, args) => SetEditor(wayPointEditor); SectionModeOption.Checked += (sender, args) => SetEditor(sectionEditor); ScreenshotButton.Click += (sender, args) => Screenshot(); WaypointModeOption.IsChecked = true; }
public static void DrawWaypoints(List <Waypoint> waypoints) { foreach (Waypoint waypoint in waypoints) { WaypointEditor.DrawSelector(waypoint, showTimestamps); } if (showEndpoints) { Waypoint firstWaypoint = waypoints[0]; Waypoint lastWaypoint = waypoints[waypoints.Count - 1]; Vector3 endOffset = (waypoints.Count < 2) ? AlternateLabelOffset : LabelOffset; Handles.Label(GlobalTransform.Transfomed(firstWaypoint.Position) + LabelOffset, "START", CustomGUI.TitleStyle); Handles.Label(GlobalTransform.Transfomed(lastWaypoint.Position) + endOffset, "END", CustomGUI.TitleStyle); } }
private void toolstripEditWaypoint_Click(object sender, EventArgs e) { if (listboxWaypoints.SelectedIndex < 0) return; WaypointEditor wpEditor = new WaypointEditor(this.Client, (Modules.Cavebot.Waypoint)listboxWaypoints.SelectedItem); wpEditor.StartPosition = FormStartPosition.Manual; wpEditor.Location = Cursor.Position; wpEditor.Show(); }
public void BuildFor(SerializableData.SerializablePed actor) { Clear(); #region SpawnAfter { var item = new MenuListItem("Spawn After Objective", StaticData.StaticLists.NumberMenu, actor.SpawnAfter); item.OnListChanged += (sender, index) => { actor.SpawnAfter = index; }; AddItem(item); } #endregion #region RemoveAfter { var item = new MenuListItem("Remove After Objective", StaticData.StaticLists.RemoveAfterList, actor.RemoveAfter); item.OnListChanged += (sender, index) => { actor.RemoveAfter = index; }; AddItem(item); } #endregion // TODO: Change NumberMenu to max num of objectives in mission // Note: if adding items before weapons, change item order in VehiclePropertiesMenu #region Weapons { var item = new NativeMenuItem("Weapon"); var dict = StaticData.WeaponsData.Database.ToDictionary(k => k.Key, k => k.Value.Select(x => x.Item1).ToArray()); var menu = new CategorySelectionMenu(dict, "Weapon", true, "SELECT WEAPON"); menu.Build("Melee"); Children.Add(menu); AddItem(item); BindMenuToItem(menu, item); menu.SelectionChanged += (sender, eventargs) => { GameFiber.StartNew(delegate { var hash = StaticData.WeaponsData.Database[menu.CurrentSelectedCategory].First( tuple => tuple.Item1 == menu.CurrentSelectedItem).Item2; NativeFunction.CallByName <uint>("REMOVE_ALL_PED_WEAPONS", actor.GetEntity().Handle.Value, true); ((Ped)actor.GetEntity()).GiveNewWeapon(hash, actor.WeaponAmmo == 0 ? 9999 : actor.WeaponAmmo, true); actor.WeaponHash = hash; }); }; } { var listIndex = actor.WeaponAmmo == 0 ? StaticData.StaticLists.AmmoChoses.FindIndex(n => n == (dynamic)9999) : StaticData.StaticLists.AmmoChoses.FindIndex(n => n == (dynamic)actor.WeaponAmmo); var item = new MenuListItem("Ammo Count", StaticData.StaticLists.AmmoChoses, listIndex); item.OnListChanged += (sender, index) => { int newAmmo = int.Parse(((MenuListItem)sender).IndexToItem(index).ToString(), CultureInfo.InvariantCulture); actor.WeaponAmmo = newAmmo; if (actor.WeaponHash == 0) { return; } NativeFunction.CallByName <uint>("REMOVE_ALL_PED_WEAPONS", actor.GetEntity().Handle.Value, true); ((Ped)actor.GetEntity()).GiveNewWeapon(actor.WeaponHash, newAmmo, true); }; AddItem(item); } #endregion #region Health { var listIndex = actor.Health == 0 ? StaticData.StaticLists.HealthArmorChoses.FindIndex(n => n == (dynamic)200) : StaticData.StaticLists.HealthArmorChoses.FindIndex(n => n == (dynamic)actor.Health); var item = new MenuListItem("Health", StaticData.StaticLists.HealthArmorChoses, listIndex); item.OnListChanged += (sender, index) => { int newAmmo = int.Parse(((MenuListItem)sender).IndexToItem(index).ToString(), CultureInfo.InvariantCulture); actor.Health = newAmmo; }; AddItem(item); } #endregion #region Armor { var listIndex = StaticData.StaticLists.HealthArmorChoses.FindIndex(n => n == (dynamic)actor.Armor); var item = new MenuListItem("Armor", StaticData.StaticLists.HealthArmorChoses, listIndex); item.OnListChanged += (sender, index) => { int newAmmo = int.Parse(((MenuListItem)sender).IndexToItem(index).ToString(), CultureInfo.InvariantCulture); actor.Armor = newAmmo; }; AddItem(item); } #endregion #region Accuracy { var listIndex = StaticData.StaticLists.AccuracyList.FindIndex(n => n == (dynamic)actor.Accuracy); var item = new MenuListItem("Accuracy", StaticData.StaticLists.AccuracyList, listIndex); item.OnListChanged += (sender, index) => { int newAmmo = int.Parse(((MenuListItem)sender).IndexToItem(index).ToString(), CultureInfo.InvariantCulture); actor.Accuracy = newAmmo; }; AddItem(item); } #endregion #region Relationship { var item = new MenuListItem("Relationship", StaticData.StaticLists.RelationshipGroups, actor.RelationshipGroup); item.OnListChanged += (sender, index) => { actor.RelationshipGroup = index; }; AddItem(item); } #endregion #region Behaviour { var wpyItem = new NativeMenuItem("Waypoints"); { var waypMenu = new WaypointEditor(actor); BindMenuToItem(waypMenu.CreateWaypointMenu, wpyItem); Vector3 camPos = new Vector3(); Rotator camRot = new Rotator(); wpyItem.Activated += (sender, selectedItem) => { camPos = Editor.MainCamera.Position; camRot = Editor.MainCamera.Rotation; waypMenu.Enter(); Editor.WaypointEditor = waypMenu; }; waypMenu.OnEditorExit += (sender, args) => { Editor.WaypointEditor = null; Editor.DisableControlEnabling = true; if (camPos != new Vector3()) { Editor.MainCamera.Position = camPos; Editor.MainCamera.Rotation = camRot; } }; } if (actor.Behaviour != 4) // Follow Waypoints { wpyItem.Enabled = false; } var item = new MenuListItem("Behaviour", StaticData.StaticLists.Behaviour, actor.Behaviour); item.OnListChanged += (sender, index) => { actor.Behaviour = index; wpyItem.Enabled = index == 4; }; AddItem(item); AddItem(wpyItem); } #endregion #region FailOnDeath { var item = new MenuCheckboxItem("Mission Fail On Death", actor.FailMissionOnDeath); item.CheckboxEvent += (sender, @checked) => { actor.FailMissionOnDeath = @checked; }; AddItem(item); } #endregion RefreshIndex(); }
void OnEnable() { wpEditor = FindObjectOfType <WaypointEditor>(); }
public override void OnInspectorGUI() { DrawDefaultInspector(); WaypointGraphGenerator instance = (WaypointGraphGenerator)target; if (GUILayout.Button("Generate")) { var w = instance.GetWaypointGraph(); foreach (var componentInChild in w.GetComponentsInChildren <WaypointEditor>()) { DestroyImmediate(componentInChild.gameObject); } var offset = instance.GetOffset(); var width = instance.GetWidth(); var height = instance.GetHeight(); var spaceBetweenWaypoint = instance.GetSpace(); int minX = (int)(offset.x - width * 0.5f); int maxX = (int)(offset.x + width * 0.5f); int minY = (int)(offset.y - height * 0.5f); int maxY = (int)(offset.y + height * 0.5f); int sizeX = (int)((maxX - minX) / spaceBetweenWaypoint) + 1; int sizeY = (int)((maxY - minY) / spaceBetweenWaypoint) + 1; WaypointEditor[,] waypoints = new WaypointEditor[sizeX, sizeY]; int i = 0, j = 0; for (float x = minX; x < maxX; x += spaceBetweenWaypoint) { for (float y = minY; y < maxY; y += spaceBetweenWaypoint) { var obj = new GameObject(); obj.AddComponent <WaypointEditor>(); obj.transform.parent = w.transform; obj.transform.position = new Vector3(x, 0, y); waypoints[i, j] = obj.GetComponent <WaypointEditor>(); j++; } i++; j = 0; } BoundsInt bounds = new BoundsInt(-1, 0, -1, 3, 1, 3); for (int k = 0; k < sizeX; k++) { for (int l = 0; l < sizeY; l++) { waypoints[k, l].neighbors = new List <WaypointEditor>(); foreach (var index in bounds.allPositionsWithin) { if (index.x == 0 && index.z == 0) { continue; } if (k + index.x < 0 || k + index.x >= sizeX || l + index.z < 0 || l + index.z >= sizeY) { continue; } waypoints[k, l].neighbors.Add(waypoints[k + index.x, l + index.z]); } } } } }
void OnEnable() { editor = target as WaypointEditor; waypointPrefab = editor.WaypointPrefab; }
public void BuildFor(SerializableData.Objectives.SerializableActorObjective actor) { Clear(); #region SpawnAfter { var item = new MenuListItem("Spawn After Objective", StaticData.StaticLists.NumberMenu, actor.SpawnAfter); item.OnListChanged += (sender, index) => { actor.SpawnAfter = index; }; AddItem(item); } #endregion #region ObjectiveIndex { var item = new MenuListItem("Objective Index", StaticData.StaticLists.ObjectiveIndexList, actor.ActivateAfter); item.OnListChanged += (sender, index) => { actor.ActivateAfter = index; if (string.IsNullOrEmpty(Editor.CurrentMission.ObjectiveNames[actor.ActivateAfter])) { MenuItems[4].SetRightBadge(NativeMenuItem.BadgeStyle.Alert); MenuItems[4].SetRightLabel(""); } else { var title = Editor.CurrentMission.ObjectiveNames[actor.ActivateAfter]; MenuItems[4].SetRightLabel(title.Length > 20 ? title.Substring(0, 20) + "..." : title); MenuItems[4].SetRightBadge(NativeMenuItem.BadgeStyle.None); } }; AddItem(item); } #endregion // TODO: Change NumberMenu to max num of objectives in mission // Note: if adding items before weapons, change item order in VehiclePropertiesMenu #region Weapons { var item = new NativeMenuItem("Weapon"); var dict = StaticData.WeaponsData.Database.ToDictionary(k => k.Key, k => k.Value.Select(x => x.Item1).ToArray()); var menu = new CategorySelectionMenu(dict, "Weapon", true, "SELECT WEAPON"); menu.Build("Melee"); Children.Add(menu); AddItem(item); BindMenuToItem(menu, item); menu.SelectionChanged += (sender, eventargs) => { GameFiber.StartNew(delegate { var hash = StaticData.WeaponsData.Database[menu.CurrentSelectedCategory].First( tuple => tuple.Item1 == menu.CurrentSelectedItem).Item2; NativeFunction.CallByName <uint>("REMOVE_ALL_PED_WEAPONS", actor.GetPed().Handle.Value, true); actor.GetPed().GiveNewWeapon(hash, actor.WeaponAmmo == 0 ? 9999 : actor.WeaponAmmo, true); actor.WeaponHash = hash; }); }; } { var listIndex = actor.WeaponAmmo == 0 ? StaticData.StaticLists.AmmoChoses.FindIndex(n => n == (dynamic)9999) : StaticData.StaticLists.AmmoChoses.FindIndex(n => n == (dynamic)actor.WeaponAmmo); var item = new MenuListItem("Ammo Count", StaticData.StaticLists.AmmoChoses, listIndex); item.OnListChanged += (sender, index) => { int newAmmo = int.Parse(((MenuListItem)sender).IndexToItem(index).ToString(), CultureInfo.InvariantCulture); actor.WeaponAmmo = newAmmo; if (actor.WeaponHash == 0) { return; } NativeFunction.CallByName <uint>("REMOVE_ALL_PED_WEAPONS", actor.GetPed().Handle.Value, true); ((Ped)actor.GetPed()).GiveNewWeapon(actor.WeaponHash, newAmmo, true); }; AddItem(item); } #endregion #region Objective Name { var item = new NativeMenuItem("Objective Name"); if (string.IsNullOrEmpty(Editor.CurrentMission.ObjectiveNames[actor.ActivateAfter])) { item.SetRightBadge(NativeMenuItem.BadgeStyle.Alert); } else { var title = Editor.CurrentMission.ObjectiveNames[actor.ActivateAfter]; item.SetRightLabel(title.Length > 20 ? title.Substring(0, 20) + "..." : title); } item.Activated += (sender, selectedItem) => { GameFiber.StartNew(delegate { ResetKey(Common.MenuControls.Back); Editor.DisableControlEnabling = true; string title = Util.GetUserInput(); if (string.IsNullOrEmpty(title)) { item.SetRightBadge(NativeMenuItem.BadgeStyle.Alert); Editor.CurrentMission.ObjectiveNames[actor.ActivateAfter] = ""; SetKey(Common.MenuControls.Back, GameControl.CellphoneCancel, 0); Editor.DisableControlEnabling = false; return; } item.SetRightBadge(NativeMenuItem.BadgeStyle.None); title = Regex.Replace(title, "-=", "~"); Editor.CurrentMission.ObjectiveNames[actor.ActivateAfter] = title; selectedItem.SetRightLabel(title.Length > 20 ? title.Substring(0, 20) + "..." : title); SetKey(Common.MenuControls.Back, GameControl.CellphoneCancel, 0); }); }; AddItem(item); } #endregion #region Health { var listIndex = actor.Health == 0 ? StaticData.StaticLists.HealthArmorChoses.FindIndex(n => n == (dynamic)200) : StaticData.StaticLists.HealthArmorChoses.FindIndex(n => n == (dynamic)actor.Health); var item = new MenuListItem("Health", StaticData.StaticLists.HealthArmorChoses, listIndex); item.OnListChanged += (sender, index) => { int newAmmo = int.Parse(((MenuListItem)sender).IndexToItem(index).ToString(), CultureInfo.InvariantCulture); actor.Health = newAmmo; }; AddItem(item); } #endregion #region Armor { var listIndex = StaticData.StaticLists.HealthArmorChoses.FindIndex(n => n == (dynamic)actor.Armor); var item = new MenuListItem("Armor", StaticData.StaticLists.HealthArmorChoses, listIndex); item.OnListChanged += (sender, index) => { int newAmmo = int.Parse(((MenuListItem)sender).IndexToItem(index).ToString(), CultureInfo.InvariantCulture); actor.Armor = newAmmo; }; AddItem(item); } #endregion #region Accuracy { var listIndex = StaticData.StaticLists.AccuracyList.FindIndex(n => n == (dynamic)actor.Accuracy); var item = new MenuListItem("Accuracy", StaticData.StaticLists.AccuracyList, listIndex); item.OnListChanged += (sender, index) => { int newAmmo = int.Parse(((MenuListItem)sender).IndexToItem(index).ToString(), CultureInfo.InvariantCulture); actor.Accuracy = newAmmo; }; AddItem(item); } #endregion #region Relationship { var item = new MenuListItem("Relationship", StaticData.StaticLists.RelationshipGroups, actor.RelationshipGroup); item.OnListChanged += (sender, index) => { actor.RelationshipGroup = index; }; AddItem(item); } #endregion #region Behaviour { var wpyItem = new NativeMenuItem("Waypoints"); { var waypMenu = new WaypointEditor(actor); BindMenuToItem(waypMenu.CreateWaypointMenu, wpyItem); Vector3 camPos = new Vector3(); Rotator camRot = new Rotator(); wpyItem.Activated += (sender, selectedItem) => { camPos = Editor.MainCamera.Position; camRot = Editor.MainCamera.Rotation; waypMenu.Enter(); Editor.WaypointEditor = waypMenu; }; waypMenu.OnEditorExit += (sender, args) => { Editor.WaypointEditor = null; Editor.DisableControlEnabling = true; if (camPos != new Vector3()) { Editor.MainCamera.Position = camPos; Editor.MainCamera.Rotation = camRot; } }; } if (actor.Behaviour != 4) // Follow Waypoints { wpyItem.Enabled = false; } var item = new MenuListItem("Behaviour", StaticData.StaticLists.Behaviour, actor.Behaviour); item.OnListChanged += (sender, index) => { actor.Behaviour = index; wpyItem.Enabled = index == 4; }; AddItem(item); AddItem(wpyItem); } #endregion #region Show Health Bar { var item = new MenuCheckboxItem("Show Healthbar", actor.ShowHealthBar); AddItem(item); item.CheckboxEvent += (sender, @checked) => { actor.ShowHealthBar = @checked; MenuItems[12].Enabled = @checked; }; } #endregion #region Bar Name { var item = new NativeMenuItem("Healthbar Label"); AddItem(item); if (!actor.ShowHealthBar) { item.Enabled = false; } if (string.IsNullOrEmpty(actor.Name) && actor.ShowHealthBar) { actor.Name = "HEALTH"; } if (actor.ShowHealthBar) { item.SetRightLabel(actor.Name.Length > 20 ? actor.Name.Substring(0, 20) : actor.Name); } item.Activated += (sender, selectedItem) => { GameFiber.StartNew(delegate { ResetKey(Common.MenuControls.Back); Editor.DisableControlEnabling = true; string title = Util.GetUserInput(); if (string.IsNullOrEmpty(title)) { actor.Name = "HEALTH"; item.SetRightLabel(actor.Name.Length > 20 ? actor.Name.Substring(0, 20) : actor.Name); SetKey(Common.MenuControls.Back, GameControl.CellphoneCancel, 0); Editor.DisableControlEnabling = false; return; } title = Regex.Replace(title, "-=", "~"); actor.Name = title; item.SetRightLabel(actor.Name.Length > 20 ? actor.Name.Substring(0, 20) : actor.Name); SetKey(Common.MenuControls.Back, GameControl.CellphoneCancel, 0); }); }; } #endregion RefreshIndex(); }
//called whenever the inspector gui gets rendered public override void OnInspectorGUI() { //this pulls the relative variables from unity runtime and stores them in the object targetClass.Update(); //get waypoint array var waypoints = GetWaypointArray(); //don't draw inspector fields if the path contains less than 2 points //(a path with less than 2 points really isn't a path) if (waypointsCount.intValue < 2) { //button to create path manually if (GUILayout.Button("Create Path from Children")) { Undo.RecordObjects(waypoints, "Create Path"); (targetClass.targetObject as PathManager).Create(); SceneView.RepaintAll(); } return; } //create new checkboxes for path gizmo property check1.boolValue = EditorGUILayout.Toggle("Draw Smooth Lines", check1.boolValue); //create new property fields for editing waypoint gizmo colors EditorGUILayout.PropertyField(color1); EditorGUILayout.PropertyField(color2); //calculate path length of all waypoints Vector3[] wpPositions = new Vector3[waypoints.Length]; for (int i = 0; i < waypoints.Length; i++) { wpPositions[i] = waypoints[i].position; } //button for switching over to the WaypointManager for further path editing if (GUILayout.Button("Continue Editing")) { Selection.activeGameObject = (GameObject.FindObjectOfType(typeof(WaypointManager)) as WaypointManager).gameObject; WaypointEditor.ContinuePath(targetClass.targetObject as PathManager); } EditorGUILayout.Space(); //waypoint index header GUILayout.Label("Waypoints: ", EditorStyles.boldLabel); float pathLength = WaypointManager.GetPathLength(wpPositions); //path length label, show calculated path length GUILayout.Label("Path Length: " + pathLength); //loop through the waypoint array for (int i = 0; i < waypoints.Length; i++) { GUILayout.BeginHorizontal(); //indicate each array slot with index number in front of it GUILayout.Label(i + ".", GUILayout.Width(20)); //create an object field for every waypoint EditorGUILayout.ObjectField(waypoints[i], typeof(Transform), true); //display an "Add Waypoint" button for every array row except the last one if (i < waypoints.Length && GUILayout.Button("+", GUILayout.Width(30f))) { AddWaypointAtIndex(i); break; } //display an "Remove Waypoint" button for every array row except the first and last one if (i > 0 && i < waypoints.Length - 1 && GUILayout.Button("-", GUILayout.Width(30f))) { RemoveWaypointAtIndex(i); break; } GUILayout.EndHorizontal(); } EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Place To Ground", GUILayout.Height(35))) { PlaceToGround(waypoints); } if (GUILayout.Button("Rename Now", GUILayout.Height(35))) { RenameWaypoints(waypoints); } if (GUILayout.Button("Invert Direction", GUILayout.Height(35))) { InvertDirection(waypoints); } if (GUILayout.Button("Repath (Children Based)", GUILayout.Height(35))) { (targetClass.targetObject as PathManager).Create(); SceneView.RepaintAll(); } EditorGUILayout.EndHorizontal(); //we push our modified variables back to our serialized object targetClass.ApplyModifiedProperties(); }