public static bool MarkLocation(WorldMapLocation wml) { //Debug.Log ("Marking location " + wml.Reference.FullPath); if (!MarkedLocations.SafeAdd(wml.Reference)) { MarkedLocations.Remove(wml.Reference); wml.IsMarked = false; wml.IsNew = false; return(false); } wml.IsMarked = true; NGUIWorldMap.Get.RemoveMarkedLocationSprite(wml); NGUIWorldMap.Get.CreateMarkedLocationSprite(wml); return(true); }
//searches chunks and loads location data into the locationData list //only searches for locations added using the SetMapData function public IEnumerator LocationsForChunks(string chunkName, int chunkID, Queue <WorldMapLocation> locationData, List <MapMarker> activeMapMarkers) { //Debug.Log ("WorldMap: LocationsForChunks"); List <MobileReference> locationList = null; if (!mRevealableToShow.TryGetValue(chunkName, out locationList)) { //Debug.Log ("WorldMap: We have no locations for this chunk from SetMapData, returning immediately"); yield break; } Vector3 chunkPosition; //add markers for (int i = 0; i < activeMapMarkers.Count; i++) { if (activeMapMarkers [i].ChunkID == chunkID) { chunkPosition = activeMapMarkers [i].ChunkPosition; WorldMapLocation wml = new WorldMapLocation( null, 1, "Marker", string.Empty, string.Empty, true, false, "MapIconMapMarker", Color.white, MapIconStyle.Medium, MapLabelStyle.None, Vector3.zero, chunkPosition, false, false, LocationTypesToDisplay); locationData.Enqueue(wml); } } MobileReference currentLocation = null; for (int i = 0; i < locationList.Count; i++) { if (!LoadData) { //Debug.Log ("WorldMap: Load data is false, returning"); yield break; } currentLocation = locationList [i]; StackItem stackItem = null; if (WIGroups.LoadStackItem(currentLocation, out stackItem)) { chunkPosition = stackItem.ChunkPosition; //Debug.Log ("WorldMap: found stack item " + stackItem.DisplayName); //next we need to get the location state from the stack item LocationState ls = null; RevealableState rs = null; VisitableState vs = null; bool isNewLocation = false; bool isMarked = false; if (NewLocations.Count > 0) { for (int j = NewLocations.LastIndex(); j >= 0; j--) { if (NewLocations [j] == currentLocation) { NewLocations.RemoveAt(j); isNewLocation = true; break; } } } //Debug.Log ("current location " + currentLocation.FullPath + " is marked? " + isMarked.ToString ( )); isMarked = MarkedLocations.Contains(currentLocation); if (stackItem.GetStateData <RevealableState> (out rs)) { stackItem.GetStateData <LocationState> (out ls); stackItem.GetStateData <VisitableState> (out vs); //now convert it into a world map location WorldMapLocation wml = null; if (rs.CustomMapSettings || ls == null) { //non-custom settings come from the location //so we can only use custom settings if ls is not null //Debug.Log ("Custom settings for revealable with " + rs.IconName + " icon name"); wml = new WorldMapLocation( currentLocation, stackItem.Props.Local.ActiveRadius, ls != null ? ls.Name.CommonName : string.Empty, ls != null ? ls.Name.ProperName : string.Empty, ls != null ? ls.Name.NickName : string.Empty, vs != null ? vs.HasBeenVisited : true, rs.MarkedForTriangulation, rs.IconName, rs.IconColor, rs.IconStyle, rs.LabelStyle, rs.IconOffset, chunkPosition, isNewLocation, isMarked, LocationTypesToDisplay); locationData.Enqueue(wml); } else { string iconName = "Outpost"; MapIconStyle iconStyle = MapIconStyle.None; MapLabelStyle labelStyle = MapLabelStyle.None; Color32 iconColor = Color.gray; Vector3 iconOffset = Vector3.zero; GetIconProperties(stackItem, ls, rs, vs, ref iconName, ref iconStyle, ref labelStyle, ref iconColor, ref iconOffset); wml = new WorldMapLocation( currentLocation, stackItem.Props.Local.ActiveRadius, ls != null ? ls.Name.CommonName : string.Empty, ls != null ? ls.Name.ProperName : string.Empty, ls != null ? ls.Name.NickName : string.Empty, vs != null ? vs.HasBeenVisited : true, rs.MarkedForTriangulation, iconName, iconColor, iconStyle, labelStyle, iconOffset, chunkPosition, isNewLocation, isMarked, LocationTypesToDisplay); locationData.Enqueue(wml); } } else { //Debug.Log ("Didn't get revealable state data in " + currentLocation.FileName); } } else { //Debug.Log ("Didin't get stack item for location " + currentLocation.FullPath); } //clear the stack item, we don't need it any more if (stackItem != null) { stackItem.Clear(); } yield return(null); } locationList.Clear(); yield break; }
public static void CreateLocationLabel(GUI.GUIMapTile mapTile, WorldMapLocation wml) { //Debug.Log ("Creating location label for " + wml.Name); bool createIcon = true; bool createLabel = true; switch (wml.LabelStyle) { case MapLabelStyle.AlwaysVisible: default: createLabel = true; break; case MapLabelStyle.None: createLabel = false; break; case MapLabelStyle.Descriptive: createIcon = false; createLabel = true; break; } if (createIcon) { //sort it into the right list based on icon switch (wml.IconStyle) { case MapIconStyle.Small: mapTile.SmallLocations.Add(wml); break; case MapIconStyle.Medium: mapTile.MediumLocations.Add(wml); break; case MapIconStyle.Large: mapTile.LargeLocations.Add(wml); break; case MapIconStyle.AlwaysVisible: mapTile.ConstantLocations.Add(wml); break; case MapIconStyle.None: default: //Debug.Log("Icon style was none in " + wml.IconName); //NONE createIcon = false; //does it have a label? if (createLabel) { //if so, keep it in the constant list mapTile.ConstantLocations.Add(wml); } else { //otherwise, just ignore it //dont bother to create labels //return; } break; } } else { mapTile.ConstantLocations.Add(wml); } Vector3 mapTilePosition = new Vector3(wml.ChunkPosition.x, wml.ChunkPosition.z, 0f); //-(wml.ChunkPosition.y)); wml.LocationTransform = mapTile.TileBackground.gameObject.CreateChild(wml.Name).transform; mapTilePosition.z = NGUIWorldMap.GetWorldMapAtChunkPosition(mapTilePosition, mapTile.ChunkToDisplay.MiniHeightmap, 0f); wml.LocationTransform.localPosition = mapTilePosition; if (createLabel) { float mapTileScale = 1f; //Mathf.Clamp (location.Radius * gLocationRadiusMult, 1f, 5f); GameObject newWMLabelGo = NGUITools.AddChild(NGUIWorldMap.Get.LabelsPanel.gameObject, mapTile.WMLabelPrefab); UILabel label = newWMLabelGo.GetComponent <UILabel> (); label.name = wml.Name; label.text = wml.Name; if (wml.LabelStyle == MapLabelStyle.Descriptive) { label.font = Mats.Get.CleanHandwriting42Font; } else { label.font = Mats.Get.CleanHandwriting42Font; //PrintingPress40Font; } wml.Label = label; if (!createIcon) { wml.LabelPosition = Vector3.zero; } wml.LabelTransform = label.cachedTransform; wml.LabelTransform.localPosition = mapTilePosition + wml.LabelPosition + wml.IconOffset; wml.LabelTransform.localScale = Vector3.one; label.alpha = 0f; label.enabled = true; } if (createIcon) { GameObject newWMIconGo = NGUITools.AddChild(NGUIWorldMap.Get.IconsPanel.gameObject, mapTile.WMIconPrefab); UISprite icon = newWMIconGo.GetComponent <UISprite> (); WMIcon wmIcon = newWMIconGo.GetComponent <WMIcon> (); wmIcon.OnClick += wml.OnClick; wmIcon.Reference = wml.Reference; icon.name = wml.Name; icon.spriteName = wml.IconName; wml.Icon = icon; wml.IconTransform = wml.Icon.cachedTransform; wml.IconTransform.localPosition = mapTilePosition + wml.IconOffset; wml.IconTransform.localScale = Vector3.one * wml.IconScale; icon.alpha = 0f; icon.enabled = true; wml.Collider = newWMIconGo.AddComponent <SphereCollider> (); //for mouseovers if (wml.IsMarked || wml.IsNew) { NGUIWorldMap.Get.CreateMarkedLocationSprite(wml); } } else { //Debug.Log ("No create icon with icon name " + wml.IconName + " and icon style " + wml.IconStyle.ToString ()); } }