コード例 #1
0
		public void DrawPortalSelector (Portal exit, Generator.InoutType type)
		{
			int entersNum = 0;
			for (int g=0; g<MapMagic.instance.gens.list.Length; g++)
			{
				Portal portal = MapMagic.instance.gens.list[g] as Portal;
				if (portal == null) continue;
				if (portal.form == Portal.PortalForm.Out) continue;
				if (portal.type != type) continue;

				entersNum++;
			}
			
			PopupMenu.MenuItem[] popupItems = new PopupMenu.MenuItem[entersNum];
			int counter = 0;
			for (int g=0; g<MapMagic.instance.gens.list.Length; g++)
			{
				Portal enter = MapMagic.instance.gens.list[g] as Portal;
				if (enter == null) continue;
				if (enter.form == Portal.PortalForm.Out) continue;
				if (enter.type != type) continue;

				popupItems[counter] = new PopupMenu.MenuItem( enter.input.guiName, delegate () { exit.input.Link(enter.output, enter); MapMagic.instance.gens.ChangeGenerator(exit); } );
				counter++;
			}

			PopupMenu.DrawPopup(popupItems, Event.current.mousePosition, closeAllOther:true);

		}
コード例 #2
0
		public void DrawPortalSelector (Portal exit, Generator.InoutType type)
		{
			//if (MapMagic.instance.guiGens == null) MapMagic.instance.guiGens = MapMagic.instance.gens;
			//GeneratorsAsset gens = MapMagic.instance.guiGens;
			//if (MapMagic.instance.guiGens != null) gens = MapMagic.instance.guiGens;

			int entersNum = 0;
			for (int g=0; g<gens.list.Length; g++)
			{
				Portal portal = gens.list[g] as Portal;
				if (portal == null) continue;
				if (portal.form == Portal.PortalForm.Out) continue;
				if (portal.type != type) continue;

				entersNum++;
			}
			
			PopupMenu.MenuItem[] popupItems = new PopupMenu.MenuItem[entersNum];
			int counter = 0;
			for (int g=0; g<gens.list.Length; g++)
			{
				Portal enter = gens.list[g] as Portal;
				if (enter == null) continue;
				if (enter.form == Portal.PortalForm.Out) continue;
				if (enter.type != type) continue;

				popupItems[counter] = new PopupMenu.MenuItem( enter.name, delegate () 
					{ 
						if (gens.CheckDependence(exit,enter)) { Debug.LogError("MapMagic: Linking portals this way will create dependency loop."); return; }
						exit.input.Link(enter.output, enter); 
						if (mapMagic!=null) 
						{
							mapMagic.ClearResults(exit);
							mapMagic.Generate();
						}
					} );
				counter++;
			}

			PopupMenu.DrawPopup(popupItems, Event.current.mousePosition, closeAllOther:true);

		}
コード例 #3
0
		public void DrawPopup ()
		{
			//if (MapMagic.instance.guiGens == null) MapMagic.instance.guiGens = MapMagic.instance.gens;
			//GeneratorsAsset gens = MapMagic.instance.guiGens;
			//if (MapMagic.instance.guiGens != null) gens = MapMagic.instance.guiGens;
			
			Vector2 mousePos = gens.layout.ToInternal(Event.current.mousePosition);
				
			//finding something that was clicked
			Generator clickedGenerator = null;
			Group clickedGroup = null;
			Generator.Output clickedOutput = null;

			for (int i=0; i<gens.list.Length; i++) 
			{
				Generator gen = gens.list[i];
				if (gen.guiRect.Contains(mousePos))
				{
					if (!(gen is Group)) clickedGenerator = gens.list[i];
					else clickedGroup = gens.list[i] as Group;
				}
				
				foreach (Generator.Output output in gens.list[i].Outputs())
					if (output.guiRect.Contains(mousePos)) clickedOutput = output; 
			}
			if (clickedGenerator == null) clickedGenerator = clickedGroup;
			
			//create
			Dictionary<string, PopupMenu.MenuItem> itemsDict = new Dictionary<string, PopupMenu.MenuItem>();
			
			foreach (System.Type type in typeof(Generator).Subtypes())
			{
				if (System.Attribute.IsDefined(type, typeof(GeneratorMenuAttribute)))
				{
					GeneratorMenuAttribute attribute = System.Attribute.GetCustomAttribute(type, typeof(GeneratorMenuAttribute)) as GeneratorMenuAttribute;
					System.Type genType = type;

					if (attribute.disabled) continue;

					PopupMenu.MenuItem item = new PopupMenu.MenuItem(attribute.name, delegate () { CreateGenerator(genType, mousePos); });
					item.priority = attribute.priority;

					if (attribute.menu.Length != 0)
					{
						if (!itemsDict.ContainsKey(attribute.menu)) itemsDict.Add(attribute.menu, new PopupMenu.MenuItem(attribute.menu, subs:new PopupMenu.MenuItem[0]));
						ArrayTools.Add(ref itemsDict[attribute.menu].subItems, createElement:() => item);
					}
					else itemsDict.Add(attribute.name, item);
				}
			} 

			itemsDict["Map"].priority = 1;
			itemsDict["Objects"].priority = 2;
			itemsDict["Output"].priority = 3;
			itemsDict["Portal"].priority = 4;
			itemsDict["Group"].priority = 5;
			itemsDict["Biome"].priority = 6;
			itemsDict["Legacy"].priority = 7;

			PopupMenu.MenuItem[] createItems = new PopupMenu.MenuItem[itemsDict.Count];
			itemsDict.Values.CopyTo(createItems, 0);

			//create group
			//PopupMenu.MenuItem createGroupItem = new PopupMenu.MenuItem("Group",  delegate () { CreateGroup(mousePos); });
			//Extensions.ArrayAdd(ref createItems, createItems.Length-1, createGroupItem);

			//additional name
			/*string additionalName = "All";
			if (clickedGenerator != null) 
			{
				additionalName = "Generator";
				if (clickedGenerator is Group) additionalName = "Group";
			}*/

			//preview
			PopupMenu.MenuItem[] previewSubs = new PopupMenu.MenuItem[]
			{
				new PopupMenu.MenuItem("On Terrain", delegate() {PreviewOutput(clickedGenerator, clickedOutput, false);}, disabled:clickedOutput==null||clickedGenerator==null, priority:0), 
				new PopupMenu.MenuItem("In Window", delegate() {PreviewOutput(clickedGenerator, clickedOutput, true);}, disabled:clickedOutput==null||clickedGenerator==null, priority:1),
				new PopupMenu.MenuItem("Clear", delegate() {PreviewOutput(null, null, false);}, priority:2 )//, disabled:MapMagic.instance.previewOutput==null)
			};

			PopupMenu.MenuItem[] popupItems = new PopupMenu.MenuItem[]
			{
				new PopupMenu.MenuItem("Create", createItems, priority:0),
				new PopupMenu.MenuItem("Export",	delegate () { ExportGenerator(clickedGenerator, mousePos); }, priority:10),
				new PopupMenu.MenuItem("Import",	delegate () { ImportGenerator(mousePos); }, priority:20),
				new PopupMenu.MenuItem("Duplicate",	delegate () { DuplicateGenerator(clickedGenerator); }, priority:30),
				new PopupMenu.MenuItem("Update",	delegate () { UpdateGenerator(clickedGenerator); }, disabled:clickedGenerator==null || !CouldBeUpdated(clickedGenerator), priority:40),
				new PopupMenu.MenuItem("Remove",	delegate () { if (clickedGenerator!=null) DeleteGenerator(clickedGenerator); },	disabled:clickedGenerator==null, priority:50),
				new PopupMenu.MenuItem("Reset",		delegate () { if (clickedGenerator!=null) ResetGenerator(clickedGenerator); },	disabled:clickedGenerator==null, priority:60), 
				new PopupMenu.MenuItem("Preview", previewSubs, priority:70)
			};

			if (onDrawPopup != null)
				popupItems = onDrawPopup(popupItems, mousePos, gens, clickedGenerator, clickedGroup, clickedOutput);

			PopupMenu.DrawPopup(popupItems, Event.current.mousePosition, closeAllOther:true);
		}
コード例 #4
0
		public void DrawPopup ()
		{
			Vector2 mousePos = layout.ToInternal(Event.current.mousePosition);
				
			//finding something that was clicked
			Generator clickedGenerator = null;
			for (int i=0; i<MapMagic.instance.gens.list.Length; i++) 
			{
				Generator gen = MapMagic.instance.gens.list[i];
				if (gen.guiRect.Contains(mousePos) && !(gen is Group)) clickedGenerator = MapMagic.instance.gens.list[i];
			}

			Group clickedGroup = null;
			for (int i=0; i<MapMagic.instance.gens.list.Length; i++) 
			{
				Generator gen = MapMagic.instance.gens.list[i];
				if (gen.guiRect.Contains(mousePos) && gen is Group) clickedGroup = MapMagic.instance.gens.list[i] as Group;
			}

			if (clickedGenerator == null) clickedGenerator = clickedGroup;
			
			Generator.Output clickedOutput = null;
			for (int i=0; i<MapMagic.instance.gens.list.Length; i++) 
				foreach (Generator.Output output in MapMagic.instance.gens.list[i].Outputs())
					if (output.guiRect.Contains(mousePos)) clickedOutput = output;

			//create
			Dictionary<string, PopupMenu.MenuItem> itemsDict = new Dictionary<string, PopupMenu.MenuItem>();
			
			List<System.Type> allGeneratorTypes = typeof(Generator).GetAllChildTypes();
			for (int i=0; i<allGeneratorTypes.Count; i++)
			{
				if (System.Attribute.IsDefined(allGeneratorTypes[i], typeof(GeneratorMenuAttribute)))
				{
					GeneratorMenuAttribute attribute = System.Attribute.GetCustomAttribute(allGeneratorTypes[i], typeof(GeneratorMenuAttribute)) as GeneratorMenuAttribute;
					System.Type genType = allGeneratorTypes[i];

					if (attribute.disabled) continue;

					PopupMenu.MenuItem item = new PopupMenu.MenuItem(attribute.name, delegate () { CreateGenerator(genType, mousePos); });
					item.priority = attribute.priority;

					if (attribute.menu.Length != 0)
					{
						if (!itemsDict.ContainsKey(attribute.menu)) itemsDict.Add(attribute.menu, new PopupMenu.MenuItem(attribute.menu, subs:new PopupMenu.MenuItem[0]));
						ArrayTools.Add(ref itemsDict[attribute.menu].subItems, item);
					}
					else itemsDict.Add(attribute.name, item);
				}
			} 
			PopupMenu.MenuItem[] createItems = new PopupMenu.MenuItem[itemsDict.Count];
			itemsDict.Values.CopyTo(createItems, 0);

			//create group
			//PopupMenu.MenuItem createGroupItem = new PopupMenu.MenuItem("Group",  delegate () { CreateGroup(mousePos); });
			//Extensions.ArrayAdd(ref createItems, createItems.Length-1, createGroupItem);

			//additional name
			string additionalName = "All";
			if (clickedGenerator != null) 
			{
				additionalName = "Generator";
				if (clickedGenerator is Group) additionalName = "Group";
			}

			//preview
			PopupMenu.MenuItem[] previewSubs = new PopupMenu.MenuItem[]
			{
				new PopupMenu.MenuItem("On Terrain", delegate() {PreviewOutput(clickedGenerator, clickedOutput, false);}, disabled:clickedOutput==null||clickedGenerator==null), 
				new PopupMenu.MenuItem("In Window", delegate() {PreviewOutput(clickedGenerator, clickedOutput, true);}, disabled:clickedOutput==null||clickedGenerator==null),
				new PopupMenu.MenuItem("Clear", delegate() {PreviewOutput(null, null, false);}, disabled:MapMagic.instance.gens.GetGenerator<PreviewOutput>()==null)
			};

			PopupMenu.MenuItem[] popupItems = new PopupMenu.MenuItem[]
			{
				new PopupMenu.MenuItem("Create", createItems),
				new PopupMenu.MenuItem("Save " + additionalName,	delegate () { SaveGenerator(clickedGenerator, mousePos); }),
				new PopupMenu.MenuItem("Load",						delegate () { LoadGenerator(mousePos); }),
				new PopupMenu.MenuItem("Duplicate",					delegate () { DuplicateGenerator(clickedGenerator); }),
				new PopupMenu.MenuItem("Remove",	delegate () { if (clickedGenerator!=null) DeleteGenerator(clickedGenerator); },	disabled:(clickedGenerator==null)),
				new PopupMenu.MenuItem("Reset",						delegate () { if (clickedGenerator!=null) ResetGenerator(clickedGenerator); },	disabled:clickedGenerator==null), 
				new PopupMenu.MenuItem("Preview", previewSubs)
			};

			PopupMenu.DrawPopup(popupItems, Event.current.mousePosition, closeAllOther:true);
		}