Esempio n. 1
0
 /// <summary>
 /// Sets the Enabled status of the given gadget. Note that this can be queried using Gadget.Enabled.
 /// </summary>
 public static void SetEnabled(GadgetInfo gadget, bool enabled)
 {
     if (enabled && !gadget.Mod.Enabled)
     {
         GadgetMods.SetEnabled(gadget.Mod, true);
     }
     if (!SetEnabledInternal(gadget, enabled))
     {
         return;
     }
 }
Esempio n. 2
0
 /// <summary>
 /// Returns an <see cref="IGadgetConfigMenu"/> for this mod. By default, returns a <see cref="UMFGadgetConfigMenu"/> for this mod's UMF config file. May return null if the mod should not have a config menu.
 /// </summary>
 /// <returns></returns>
 public virtual IGadgetConfigMenu GetConfigMenu()
 {
     try
     {
         return(new UMFGadgetConfigMenu(Regex.Replace(GadgetMods.GetModInfo(ModID).Attribute.Name, @"\s+", ""), false, Path.Combine(UMFData.ConfigsPath, Assembly.GetAssembly(GetType()).GetName().Name) + ".ini"));
     }
     catch (InvalidOperationException e)
     {
         if (e.Message == UMFGadgetConfigMenu.NO_CONFIGURABLE_DATA)
         {
             return(null);
         }
         else
         {
             throw;
         }
     }
 }
Esempio n. 3
0
 /// <summary>
 /// Gets the mod that registered this Registry Entry. This will return null until the Registry Entry has been registered.
 /// </summary>
 public GadgetMod GetMod()
 {
     return(ModID >= 0 ? GadgetMods.GetMod(ModID) : null);
 }
Esempio n. 4
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>
 public virtual IGadgetConfigMenu GetConfigMenu()
 {
     try
     {
         return(new INIGadgetConfigMenu(Regex.Replace(Info.Attribute.Name, @"\s+", ""), false, Path.Combine(GadgetPaths.ConfigsPath, Assembly.GetAssembly(GetType()).GetName().Name) + ".ini", Info.Attribute.AllowConfigReloading ? ModMenuController.modEntries[GadgetMods.IndexOfMod(Info.Mod)] : null));
     }
     catch (InvalidOperationException e)
     {
         if (e.Message == INIGadgetConfigMenu.NO_CONFIGURABLE_DATA)
         {
             return(null);
         }
         else
         {
             throw;
         }
     }
 }
Esempio n. 5
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 GadgetMod!");
            }
            if (!entry.ReadyToRegister())
            {
                throw new InvalidOperationException("This registry entry is not yet ready to be registered, or has already been registered!");
            }
            if (name != null && !name.All(x => char.IsLetterOrDigit(x) || x == ' '))
            {
                throw new InvalidOperationException("Registry name must be alphanumeric!");
            }
            if (name == null && preferredID >= 0)
            {
                name = preferredID.ToString();
            }
            string registryName = GadgetMods.GetModInfo(modRegistering).Attribute.Name + ":" + 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 ? "Vanilla" : GadgetMods.GetModInfo(modRegistering).Attribute.Name) + ":" + name;
            Singleton.registry[id] = entry;
            if (!registeringVanilla)
            {
                Singleton.reservedIDs[entry.RegistryName] = id;
            }
            lastUsedIDs[typeEnum] = id;
            Singleton.PostRegistration(entry);
            entry.PostRegister();
            return(id);
        }