Exemplo n.º 1
0
 /// <summary>
 /// Returns an <see cref="IGadgetConfigMenu"/> for this Gadget. By default, returns a <see cref="INIGadgetConfigMenu"/> for this Gadget's UMF config file. May return null if the Gadget should not have a config menu.
 /// </summary>
 /// <returns></returns>
 public virtual IGadgetConfigMenu GetConfigMenu()
 {
     try
     {
         return(new INIGadgetConfigMenu(Regex.Replace(Gadgets.GetGadgetInfo(ModID).Attribute.Name, @"\s+", ""), false, Path.Combine(GadgetPaths.ConfigsPath, Assembly.GetAssembly(GetType()).GetName().Name) + ".ini", Info.Attribute.AllowConfigReloading ? ModMenuController.modEntries[ModID] : null));
     }
     catch (InvalidOperationException e)
     {
         if (e.Message == INIGadgetConfigMenu.NO_CONFIGURABLE_DATA)
         {
             return(null);
         }
         else
         {
             throw;
         }
     }
 }
Exemplo n.º 2
0
        internal static int RegisterStatic(E entry, string name, int preferredID = -1, bool overrideExisting = true)
        {
            if (!registeringVanilla && modRegistering < 0)
            {
                throw new InvalidOperationException("Data registration may only be performed by the Initialize method of a Gadget!");
            }
            if (!entry.ReadyToRegister())
            {
                throw new InvalidOperationException("This registry entry is not yet ready to be registered, or has already been registered!");
            }
            string modNamePrefix = Gadgets.GetGadgetInfo(modRegistering).Attribute.Name + ":";
            bool   hasPrefix     = false;

            if (name != null)
            {
                hasPrefix = name.StartsWith(modNamePrefix);
                if (!(hasPrefix ? name.Substring(modNamePrefix.Length) : name).All(x => char.IsLetterOrDigit(x) || x == ' '))
                {
                    throw new InvalidOperationException("Registry name must be alphanumeric!");
                }
            }
            if (name == null)
            {
                name = overrideExisting && Singleton.HasEntry(preferredID) ? Singleton[preferredID].RegistryName.Substring(Singleton[preferredID].RegistryName.IndexOf(':') + 1) : Singleton.GenerateDefaultRegistryName(preferredID);
            }
            if (name == null)
            {
                throw new InvalidOperationException("Must provide a registry name!");
            }
            string registryName = hasPrefix ? name : modNamePrefix + name;
            int    reservedID   = Singleton.GetReservedID(registryName);

            if (reservedID >= 0 && preferredID < 0)
            {
                preferredID = reservedID;
            }
            T   typeEnum = entry.GetEntryType();
            int id       = lastUsedIDs.ContainsKey(typeEnum) ? lastUsedIDs[typeEnum] : -1;

            if (preferredID < 0 || (!overrideExisting && Singleton.HasEntry(preferredID)) || !entry.IsValidIDForType(preferredID))
            {
                if (!overrideExisting && preferredID >= 0)
                {
                    return(-1);
                }
                do
                {
                    id = entry.GetNextIDForType(id);
                } while (id >= 0 && Singleton.HasEntry(id) || Singleton.IsIDReserved(id) != null);
                if (id < 0)
                {
                    return(id);
                }
            }
            else
            {
                id = preferredID;
            }
            entry.ModID = modRegistering;
            entry.ID    = id;
            if (name == preferredID.ToString())
            {
                name = id.ToString();
            }
            entry.RegistryName                         = (registeringVanilla ? "Roguelands" : Gadgets.GetGadgetInfo(modRegistering).Attribute.Name) + ":" + name;
            Singleton.IDRegistry[entry.ID]             = entry;
            Singleton.NameRegistry[entry.RegistryName] = entry;
            if (!registeringVanilla)
            {
                Singleton.reservedIDs[entry.RegistryName] = id;
            }
            lastUsedIDs[typeEnum] = id;
            Singleton.PostRegistration(entry);
            entry.PostRegister();
            return(id);
        }