private GameObject GetOrInitializeCanvas()
 {
     if (canvas == null)
     {
         logger.Log("Initializing Canvas.");
         canvas = new GameObject();
         canvas.AddComponent <Canvas>().renderMode = RenderMode.ScreenSpaceOverlay;
         CanvasScaler scaler = canvas.AddComponent <CanvasScaler>();
         scaler.uiScaleMode         = CanvasScaler.ScaleMode.ScaleWithScreenSize;
         scaler.referenceResolution = new Vector2(1920f, 1080f);
         UnityEngine.Object.DontDestroyOnLoad(canvas);
     }
     return(canvas);
 }
Exemple #2
0
        public override void Initialize()
        {
            if (Instance != null)
            {
                DebugLog.Warn("Initialized twice... Stop that.");
                return;
            }
            Instance = this;
            DebugLog.Log("RandoMapMod Initializing...");

            Resources.Initialize();

            On.GameMap.Start           += this.GameMap_Start;                           //Set up custom pins
            On.GameMap.WorldMap        += this.GameMap_WorldMap;                        //Set big map boundaries
            On.GameMap.SetupMapMarkers += this.GameMap_SetupMapMarkers;                 //Enable the custom pins
            On.GameMap.DisableMarkers  += this.GameMap_DisableMarkers;                  //Disable the custom pins

            ModHooks.Instance.SavegameLoadHook += this.SavegameLoadHook;                //Load object name changes
            ModHooks.Instance.SavegameSaveHook += this.SavegameSaveHook;                //Load object name changes

            //Giveaway time
            UnityEngine.SceneManagement.SceneManager.activeSceneChanged += HandleSceneChanges;
            ModHooks.Instance.LanguageGetHook += HandleLanguageGet;

            DebugLog.Log("RandoMapMod Initialize complete!");
        }
Exemple #3
0
        public static void GiveAllMaps(string from)
        {
            DebugLog.Log($"Maps granted from {from}");

            PlayerData pd         = PlayerData.instance;
            Type       playerData = typeof(PlayerData);

            // Give the maps to the player
            pd.SetBool(nameof(pd.hasMap), true);

            foreach (FieldInfo field in playerData.GetFields().Where(field => field.Name.StartsWith("map") && field.FieldType == typeof(bool)))
            {
                pd.SetBool(field.Name, true);
            }

            //Give them compass and Quill
            pd.SetBool(nameof(pd.gotCharm_2), true);
            pd.SetBool(nameof(pd.hasQuill), true);
            //GiveCollectorsMap();

            // Set cornifer as having left all the areas. This could be condensed into the previous foreach for one less GetFields(), but I value the clarity more.
            foreach (FieldInfo field in playerData.GetFields().Where(field => field.Name.StartsWith("corn") && field.Name.EndsWith("Left")))
            {
                pd.SetBool(field.Name, true);
            }

            // Set Cornifer as sleeping at home
            pd.SetBool(nameof(pd.corniferAtHome), true);

            //Make sure both groups are activated
            Instance._PinGroup.MainGroup.SetActive(true);
            Instance._PinGroup.HelperGroup.SetActive(true);

            AllMapsGiven = true;
        }
Exemple #4
0
 public static void SetPinStyleOrReturnToNormal(PinStyles style)
 {
     DebugLog.Log($"SetPins: {PinStyle} => {style}");
     if (PinStyle == style)
     {
         PinStyle = PinStyles.Normal;
         DebugLog.Log($"Back to Normal: {PinStyle}");
         return;
     }
     PinStyle = style;
     DebugLog.Log($"New Stuff: {PinStyle}");
 }
        public Resources()
        {
            Assembly theDLL = typeof(RandoMapMod).Assembly;

            pSprites = new Dictionary <SpriteId, Sprite>();
            foreach (string resource in theDLL.GetManifestResourceNames())
            {
                if (resource.EndsWith(".png"))
                {
                    //Load up all the one sprites!
                    Stream img  = theDLL.GetManifestResourceStream(resource);
                    byte[] buff = new byte[img.Length];
                    img.Read(buff, 0, buff.Length);
                    img.Dispose();

                    Texture2D texture = new Texture2D(1, 1);
                    texture.LoadImage(buff, true);
                    SpriteId?key = resource switch
                    {
                        "RandoMapMod.Resources.Map.prereqPin.png" => SpriteId.MissingPrereq,
                        "RandoMapMod.Resources.Map.randoPin.png" => SpriteId.Rando,
                        "RandoMapMod.Resources.Map.shopPin.png" => SpriteId.Shop,
                        _ => null
                    };
                    if (key == null)
                    {
                        logger.Warn($"Found unrecognized sprite {resource}. Ignoring.");
                    }
                    else
                    {
                        pSprites.Add(
                            (SpriteId)key,
                            UnityEngine.Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f)));
                    }
                }
                else if (resource.EndsWith("pindata.xml"))
                {
                    //Load the pin-specific data; we'll follow up with the direct rando info later, so we don't duplicate defs...
                    try
                    {
                        using (Stream stream = theDLL.GetManifestResourceStream(resource))
                        {
                            pPinData = loadPinData(stream);
                        }
                    }
                    catch (Exception e)
                    {
                        logger.Error("pindata.xml Load Failed!");
                        logger.Error(e.ToString());
                    }
                }
            }

            Assembly randoDLL = typeof(RandomizerMod.RandomizerMod).Assembly;
            Dictionary <String, Action <XmlDocument> > resourceProcessors = new Dictionary <String, Action <XmlDocument> >
            {
                {
                    "items.xml", (xml) => {
                        loadItemData(xml.SelectNodes("randomizer/item"));
                    }
                }
            };

            foreach (string resource in randoDLL.GetManifestResourceNames())
            {
                foreach (string resourceEnding in resourceProcessors.Keys)
                {
                    if (resource.EndsWith(resourceEnding))
                    {
                        logger.Log($"Loading data from {nameof(RandomizerMod)}'s {resource} file.");
                        try
                        {
                            using (Stream stream = randoDLL.GetManifestResourceStream(resource))
                            {
                                XmlDocument xml = new XmlDocument();
                                xml.Load(stream);
                                resourceProcessors[resourceEnding].Invoke(xml);
                            }
                        }
                        catch (Exception e)
                        {
                            logger.Error($"{resourceEnding} Load Failed!");
                            logger.Error(e.ToString());
                        }
                        break;
                    }
                }
            }
        }