Exemplo n.º 1
0
        public bool DrawMarker(Map.Marker marker, float angle = 0f, float scale = 1f)
        {
            Vector2 center    = new Vector2(Screen.width / 2f, Screen.height / 2f) + Position * Zoom;
            Vector2 wholeSize = new Vector2(Screen.width, Screen.height) * Zoom;
            Vector2 mapPos    = WorldToMap(marker.WorldPosition);

            mapPos.x *= wholeSize.x;
            mapPos.y *= wholeSize.y;
            float   markerSize = GetMarkerSize() * scale;
            Rect    texCoords  = GetTextureCoords(marker.Class.Texture);
            Vector2 mPos       = new Vector2(center.x + mapPos.x, center.y + mapPos.y);
            Rect    markerRect = new Rect(mPos.x - markerSize / 2f, mPos.y - markerSize / 2f, markerSize, markerSize);

            GUI.color = marker.Class.Color;
            if (angle != 0f)
            {
                Matrix4x4 bkpMatrix = GUI.matrix;
                GUIUtility.RotateAroundPivot(180f + TheForest.Utils.LocalPlayer.Transform.rotation.eulerAngles.y, mPos);
                GUI.DrawTextureWithTexCoords(markerRect, Markers, texCoords);
                GUI.matrix = bkpMatrix;
            }
            else
            {
                GUI.DrawTextureWithTexCoords(markerRect, Markers, texCoords);
            }
            GUI.color = Color.white;
            return(markerRect.Contains(Event.current.mousePosition));
        }
Exemplo n.º 2
0
        void Start()
        {
            try
            {
                Categories = new Dictionary <string, MarkerCategory>();
                foreach (MarkerSetting setting in markerSettings.Values)
                {
                    if (!Categories.ContainsKey(setting.Category))
                    {
                        Categories.Add(setting.Category, new MarkerCategory());
                        Categories[setting.Category].Color = setting.Color;
                    }
                    Categories[setting.Category].Markers.Add(setting);
                }

                playerMarker = new Map.Marker()
                {
                    Class = new MarkerSetting()
                    {
                        ID       = "Player",
                        Color    = Color.white,
                        Label    = "You",
                        Texture  = 31,
                        Category = "Player"
                    },
                    Description   = "You",
                    WorldPosition = Vector3.zero,
                };

                Markers    = ModAPI.Resources.GetTexture("Markers.png");
                background = new Texture2D(2, 2);
                background.SetPixel(0, 0, new Color(0f, 0f, 0f, 0.7f));
                background.SetPixel(1, 0, new Color(0f, 0f, 0f, 0.7f));
                background.SetPixel(0, 1, new Color(0f, 0f, 0f, 0.7f));
                background.SetPixel(1, 1, new Color(0f, 0f, 0f, 0.7f));
                background.filterMode = FilterMode.Point;
                background.Apply();

                foreground = new Texture2D(2, 2);
                foreground.SetPixel(0, 0, new Color(1f, 1f, 1f, 1f));
                foreground.SetPixel(1, 0, new Color(1f, 1f, 1f, 1f));
                foreground.SetPixel(0, 1, new Color(1f, 1f, 1f, 1f));
                foreground.SetPixel(1, 1, new Color(1f, 1f, 1f, 1f));
                foreground.filterMode = FilterMode.Point;
                foreground.Apply();

                WhiteLabel = new GUIStyle(ModAPI.GUI.Skin.label);
                WhiteLabel.normal.textColor = Color.white;

                Overworld  = new Map("http://theforestmap.com/map/map-4096.jpg", "http://theforestmap.com/map/md5.php?map=forest", "http://theforestmap.com/inc/api/?json&map=forest", "Mods/Map/Cache/Overworld/map.jpg");
                Underworld = new Map("http://theforestmap.com/map/cave-4096.jpg", "http://theforestmap.com/map/md5.php?map=cave", "http://theforestmap.com/inc/api/?json&map=cave", "Mods/Map/Cache/Underworld/map.jpg");
            }
            catch (Exception e)
            {
                ModAPI.Log.Write(e.ToString());
            }
        }
Exemplo n.º 3
0
        //public static List<GameObject> allMutants = new List<GameObject>();
        void OnGUI()
        {
            try
            {
                GUI.skin  = ModAPI.Interface.Skin;
                GUI.color = Color.white;
                if (Opened)
                {
                    GUI.DrawTexture(new Rect(0f, 0f, Camera.main.pixelWidth, Camera.main.pixelHeight), background);

                    if (currentMap.Textures != null && currentMap.Textures.Length > 0)
                    {
                        Vector2 wholeSize = new Vector2(Screen.height * 1.777778f, Screen.height) * Zoom;
                        if (wholeSize.x < wholeSize.y)
                        {
                            wholeSize.y = wholeSize.x;
                        }
                        else
                        {
                            wholeSize.x = wholeSize.y;
                        }
                        Vector2 size   = wholeSize / Map.SPLIT;
                        Vector2 center = new Vector2(Screen.width / 2f, Screen.height / 2f) + Position * Zoom;
                        Vector2 start  = center - wholeSize / 2f;
                        for (int x = 0; x < Map.SPLIT; x++)
                        {
                            for (int y = 0; y < Map.SPLIT; y++)
                            {
                                int index = x + (Map.SPLIT - y - 1) * Map.SPLIT;
                                GUI.DrawTexture(new Rect(start.x + size.x * x, start.y + size.y * y, size.x, size.y), currentMap.Textures[index]);
                            }
                        }
                        GUI.DrawTexture(new Rect(0, 0, 500, 500), currentMap.Texture);

                        List <Map.Marker> tooltip = new List <Map.Marker>();
                        for (int i = 0; i < currentMap.Markers.Count; i++)
                        {
                            if (currentMap.Markers[i].Class.Selected)
                            {
                                if (DrawMarker(currentMap.Markers[i]))
                                {
                                    tooltip.Add(currentMap.Markers[i]);
                                }
                            }
                        }


                        playerMarker = new Map.Marker()
                        {
                            Class = new MarkerSetting()
                            {
                                ID       = "Player",
                                Color    = Color.white,
                                Label    = "You",
                                Texture  = 31,
                                Category = "Player"
                            },
                            Description   = "You",
                            WorldPosition = Vector3.zero,
                        };

                        playerMarker.WorldPosition.x = -TheForest.Utils.LocalPlayer.Transform.position.z;
                        playerMarker.WorldPosition.y = TheForest.Utils.LocalPlayer.Transform.position.y;
                        playerMarker.WorldPosition.z = TheForest.Utils.LocalPlayer.Transform.position.x;
                        if (DrawMarker(playerMarker, 90f + TheForest.Utils.LocalPlayer.Transform.rotation.eulerAngles.y, 2f))
                        {
                            tooltip.Add(playerMarker);
                        }

                        // Only in Multiplayer
                        if (BoltNetwork.isRunning && Scene.SceneTracker != null && Scene.SceneTracker.allPlayerEntities != null)
                        {
                            // Refresh players
                            PlayerManager.Players.Clear();
                            PlayerManager.Players.AddRange(Scene.SceneTracker.allPlayerEntities
                                                           .Where(o => o.isAttached &&
                                                                  o.StateIs <IPlayerState>() &&
                                                                  LocalPlayer.Entity != o &&
                                                                  o.gameObject.activeSelf &&
                                                                  o.gameObject.activeInHierarchy &&
                                                                  o.GetComponent <BoltPlayerSetup>() != null)
                                                           .OrderBy(o => o.GetState <IPlayerState>().name)
                                                           .Select(o => new Player(o)));
                        }
                        if (BoltNetwork.isRunning)
                        {
                            foreach (var player in PlayerManager.Players)
                            {
                                playerMPMarker = new Map.Marker()
                                {
                                    Class = new MarkerSetting()
                                    {
                                        ID       = "Player",
                                        Color    = Color.red,
                                        Label    = player.Name,
                                        Texture  = 32,
                                        Category = "Player"
                                    },
                                    Description   = player.Name,
                                    WorldPosition = Vector3.zero,
                                };
                                playerMPMarker.WorldPosition.x = -player.Position.z;
                                playerMPMarker.WorldPosition.y = player.Position.y;
                                playerMPMarker.WorldPosition.z = player.Position.x;
                                if (DrawMarker(playerMPMarker, 0f, 2f))
                                {
                                    tooltip.Add(playerMPMarker);
                                }
                            }
                        }

                        if (livemarkers)
                        {
                            List <GameObject> allMutants;
                            if (GameSetup.IsMpClient)
                            {
                                allMutants = LiveEnemyForClients.liveEnemies;
                            }
                            else
                            {
                                if (TheForest.Utils.LocalPlayer.IsInCaves)
                                {
                                    allMutants = new List <GameObject>(Scene.MutantControler.activeCaveCannibals);
                                    foreach (GameObject current in Scene.MutantControler.activeInstantSpawnedCannibals)
                                    {
                                        if (!allMutants.Contains(current))
                                        {
                                            allMutants.Add(current);
                                        }
                                    }
                                    allMutants.RemoveAll((GameObject o) => o == null);
                                    allMutants.RemoveAll((GameObject o) => o != o.activeSelf);
                                }
                                else
                                {
                                    allMutants = new List <GameObject>(Scene.MutantControler.activeWorldCannibals);
                                    foreach (GameObject current in Scene.MutantControler.activeInstantSpawnedCannibals)
                                    {
                                        if (!allMutants.Contains(current))
                                        {
                                            allMutants.Add(current);
                                        }
                                    }
                                    allMutants.RemoveAll((GameObject o) => o == null);
                                    allMutants.RemoveAll((GameObject o) => o != o.activeSelf);
                                }
                            }

                            if (allMutants.Count > 0)
                            {
                                foreach (GameObject mutant in allMutants)
                                {
                                    if (mutant != null)
                                    {
                                        mutantMarker = new Map.Marker()
                                        {
                                            Class = new MarkerSetting()
                                            {
                                                ID       = "Live Cannibal",
                                                Color    = Color.red,
                                                Label    = "Cannibal",
                                                Texture  = 36,
                                                Category = "Natives"
                                            },
                                            Description   = "Cannibal",
                                            WorldPosition = Vector3.zero,
                                        };
                                        mutantMarker.WorldPosition.x = -mutant.transform.position.z;
                                        mutantMarker.WorldPosition.y = mutant.transform.position.y;
                                        mutantMarker.WorldPosition.z = mutant.transform.position.x;

                                        float rot = mutant.GetComponentInChildren <Animator>().rootRotation.eulerAngles
                                                    .y;

                                        if (DrawMarker(mutantMarker, 90f + rot, 2f))
                                        {
                                            tooltip.Add(mutantMarker);
                                        }
                                    }
                                }
                            }
                        }



                        if (tooltip.Count > 0)
                        {
                            Vector2 tooltipStart = new Vector2(Event.current.mousePosition.x - 125f, Event.current.mousePosition.y + 5f);
                            float   _height      = tooltip.Count * 30f + 5f;
                            GUI.Box(new Rect(tooltipStart.x, tooltipStart.y, 120f, _height), "");
                            float ty = 0f;
                            for (int j = 0; j < tooltip.Count; j++)
                            {
                                Rect tnr = new Rect(tooltipStart.x, tooltipStart.y + ty, 120f, 30f);
                                GUI.color = new Color(tooltip[j].Class.Color.r, tooltip[j].Class.Color.g, tooltip[j].Class.Color.b, 0.2f);
                                GUI.DrawTexture(tnr, foreground);
                                GUI.color = tooltip[j].Class.Color;
                                tnr       = new Rect(tooltipStart.x + 5f, tooltipStart.y + ty + 5f, 20f, 20f);
                                GUI.DrawTextureWithTexCoords(tnr, Markers, GetTextureCoords(tooltip[j].Class.Texture));
                                GUI.color = Color.white;
                                tnr       = new Rect(tooltipStart.x + 30f, tooltipStart.y + ty + 5f, 90f, 30f);
                                GUI.Label(tnr, tooltip[j].Class.Label);
                                ty += 30f;
                            }
                        }

                        /*WorldToMapFactor.x = float.Parse(GUI.TextField(new Rect(10, 10, 200, 20), WorldToMapFactor.x + ""));
                         * WorldToMapFactor.y = float.Parse(GUI.TextField(new Rect(10, 40, 200, 20), WorldToMapFactor.y + ""));
                         * WorldToMapOffset.x = float.Parse(GUI.TextField(new Rect(10, 70, 200, 20), WorldToMapOffset.x + ""));
                         * WorldToMapOffset.y = float.Parse(GUI.TextField(new Rect(10, 100, 200, 20), WorldToMapOffset.y + ""));
                         */

                        float height = 0f;
                        int   nn     = 0;
                        foreach (MarkerCategory category in Categories.Values)
                        {
                            height += 20f;
                            if (category.Selected)
                            {
                                nn = 0;
                                foreach (MarkerSetting setting in category.Markers)
                                {
                                    if (nn == 0)
                                    {
                                        height += 20f;
                                    }
                                    nn++;
                                    if (nn >= 2)
                                    {
                                        nn = 0;
                                    }
                                }
                            }
                        }
                        float offset = 70f;
                        GUI.Box(new Rect(10, Screen.height - (height + 30f) - offset, 200f, height + 35f), "Filter", GUI.skin.window);
                        int _y = 0;
                        int _x = 0;
                        foreach (MarkerCategory category in Categories.Values)
                        {
                            _x = 0;
                            string categoryName = category.Markers[0].Category;
                            category.Selected = GUI.Toggle(new Rect(10, Screen.height - (height) - offset + _y, 200f, 20f), category.Selected, categoryName, GUI.skin.button);
                            _y += 20;
                            if (category.Selected)
                            {
                                foreach (MarkerSetting setting in category.Markers)
                                {
                                    Rect nr = new Rect(10 + _x, Screen.height - (height) - offset + _y, 100f, 20f);
                                    GUI.color = new Color(category.Color.r, category.Color.g, category.Color.b, setting.Selected ? 0.2f : 0f);
                                    GUI.DrawTexture(nr, foreground);
                                    GUI.color = category.Color;
                                    nr        = new Rect(10 + _x, Screen.height - (height) - offset + _y, 20f, 20f);
                                    GUI.DrawTextureWithTexCoords(nr, Markers, GetTextureCoords(setting.Texture));
                                    GUI.color        = Color.white;
                                    nr               = new Rect(35 + _x, Screen.height - (height) - offset + _y, 65f, 20f);
                                    setting.Selected = GUI.Toggle(nr, setting.Selected, setting.Label, GUI.skin.label);
                                    _x              += 100;
                                    if (_x >= 200)
                                    {
                                        _x  = 0;
                                        _y += 20;
                                    }
                                }
                                if (_x == 100)
                                {
                                    _y += 20;
                                }
                            }
                        }

                        GUI.Label(new Rect(40f, Screen.height - 60f, 200f, 20f), "Live Cannibals", GUI.skin.label);
                        livemarkers = UnityEngine.GUI.Toggle(new Rect(10f, Screen.height - 60f, 20f, 30f), livemarkers, "");


                        if (GUI.Button(new Rect(10f, Screen.height - 30f, 200f, 20f), "Save"))
                        {
                            SaveMarkers(Categories, "Mods/Map.settings");
                        }

                        if (Event.current.type == EventType.MouseDown)
                        {
                            Drag         = true;
                            LastMousePos = Event.current.mousePosition;
                        }
                        else if (Event.current.type == EventType.MouseDrag)
                        {
                            Vector2 move = Event.current.mousePosition - LastMousePos;
                            float   w    = Mathf.Min(Screen.width, Screen.height);
                            Position    += move / Zoom;
                            Position.x   = Mathf.Clamp(Position.x, w / -2f, w / 2f);
                            Position.y   = Mathf.Clamp(Position.y, w / -2f, w / 2f);
                            LastMousePos = Event.current.mousePosition;
                        }
                        else if (Event.current.type == EventType.MouseUp)
                        {
                            Drag = false;
                        }

                        if (Event.current.type == EventType.ScrollWheel)
                        {
                            Zoom = Mathf.Clamp(Zoom + Event.current.delta.y / -20f, 1f, 3f);
                        }

                        GUIContent con  = new GUIContent("Thanks to https://theforestmap.com/ for providing the map data.");
                        Vector2    cons = GUI.skin.label.CalcSize(con);
                        GUI.color = Color.black;
                        GUI.Label(new Rect(Screen.width - 5f - cons.x, Screen.height - 25f, cons.x + 10f, cons.y + 10f), con);
                        GUI.color = Color.white;
                        GUI.Label(new Rect(Screen.width - 6f - cons.x, Screen.height - 26f, cons.x + 10f, cons.y + 10f), con);
                    }

                    if (currentMap.Loading)
                    {
                        if (currentMap.Textures == null || currentMap.Textures.Length == 0)
                        {
                            string loadingLabel = "Loading...";

                            // show big loader
                            Vector2 s = GUI.skin.label.CalcSize(new GUIContent(loadingLabel));
                            GUI.Label(new Rect(Screen.width / 2f - s.x / 2f, Screen.height / 2f - s.y - 5f, s.x + 10, s.y + 10), loadingLabel, WhiteLabel);

                            GUI.DrawTexture(new Rect(Screen.width / 4f, Screen.height / 2f + 1, (Screen.width / 2f) * currentMap.Progress, 2f), foreground);

                            string percentageLabel = currentMap.CurrentTask + ": " + Mathf.FloorToInt(currentMap.Progress * 100f) + "% (" + Mathf.FloorToInt(currentMap.BytesLoaded) + "kb / " + Mathf.FloorToInt(currentMap.BytesTotal / 1024f) + "kb)";
                            s = GUI.skin.label.CalcSize(new GUIContent(percentageLabel));
                            GUI.Label(new Rect(Screen.width / 2f - s.x / 2f, Screen.height / 2f + 2f, s.x + 10, s.y + 10), percentageLabel, WhiteLabel);
                            GUI.DrawTexture(new Rect(Screen.width / 4f, Screen.height / 2f, Screen.width / 2f, 1f), foreground);
                        }
                        else
                        {
                            string loadingLabel = "Loading...";

                            // show small loader
                            Vector2 s = GUI.skin.label.CalcSize(new GUIContent(loadingLabel));
                            GUI.Label(new Rect(Screen.width - 110f - s.x / 2f, Screen.height - 40f - s.y - 5f, s.x + 10, s.y + 10), loadingLabel, WhiteLabel);

                            GUI.DrawTexture(new Rect(Screen.width - 210f, Screen.height - 40f + 1, (200f) * currentMap.Progress, 2f), foreground);

                            string percentageLabel = currentMap.CurrentTask + ": " + Mathf.FloorToInt(currentMap.Progress * 100f) + " % (" + Mathf.FloorToInt(currentMap.BytesLoaded) + "kb / " + Mathf.FloorToInt(currentMap.BytesTotal / 1024f) + "kb)";
                            s = GUI.skin.label.CalcSize(new GUIContent(percentageLabel));
                            GUI.Label(new Rect(Screen.width - 110f - s.x / 2f, Screen.height - 40f + 2f, s.x + 10, s.y + 10), percentageLabel, WhiteLabel);
                            GUI.DrawTexture(new Rect(Screen.width - 210f, Screen.height - 40f, (200f), 1f), foreground);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                ModAPI.Log.Write(e.ToString());
            }
        }
Exemplo n.º 4
0
        void Start()
        {
            try
            {
                Categories = new Dictionary<string, MarkerCategory>();
                foreach (MarkerSetting setting in markerSettings.Values)
                {
                    if (!Categories.ContainsKey(setting.Category))
                    {
                        Categories.Add(setting.Category, new MarkerCategory());
                        Categories[setting.Category].Color = setting.Color;
                    }
                    Categories[setting.Category].Markers.Add(setting);
                }
                
                playerMarker = new Map.Marker()
                {
                    Class = new MarkerSetting()
                    {
                        ID = "Player",
                        Color = Color.white,
                        Label = "You",
                        Texture = 31,
                        Category = "Player"
                    },
                    Description = "You",
                    WorldPosition = Vector3.zero,
                };

                Markers = ModAPI.Resources.GetTexture("Markers.png");
                background = new Texture2D(2, 2);
                background.SetPixel(0, 0, new Color(0f, 0f, 0f, 0.7f));
                background.SetPixel(1, 0, new Color(0f, 0f, 0f, 0.7f));
                background.SetPixel(0, 1, new Color(0f, 0f, 0f, 0.7f));
                background.SetPixel(1, 1, new Color(0f, 0f, 0f, 0.7f));
                background.filterMode = FilterMode.Point;
                background.Apply();

                foreground = new Texture2D(2, 2);
                foreground.SetPixel(0, 0, new Color(1f, 1f, 1f, 1f));
                foreground.SetPixel(1, 0, new Color(1f, 1f, 1f, 1f));
                foreground.SetPixel(0, 1, new Color(1f, 1f, 1f, 1f));
                foreground.SetPixel(1, 1, new Color(1f, 1f, 1f, 1f));
                foreground.filterMode = FilterMode.Point;
                foreground.Apply();

                WhiteLabel = new GUIStyle(ModAPI.GUI.Skin.label);
                WhiteLabel.normal.textColor = Color.white;

                Overworld = new Map("http://theforestmap.com/map/map-4096.jpg", "http://theforestmap.com/map/md5.php?map=forest", "http://theforestmap.com/inc/api/?json&map=forest", "Mods/Map/Cache/Overworld/map.jpg");
                Underworld = new Map("http://theforestmap.com/map/cave-4096.jpg", "http://theforestmap.com/map/md5.php?map=cave", "http://theforestmap.com/inc/api/?json&map=cave", "Mods/Map/Cache/Underworld/map.jpg");
            }
            catch (Exception e)
            {
                ModAPI.Log.Write(e.ToString());
            }
        }