/// <summary> /// Returns a text menu entry. /// </summary> private TextMenuEntry BuildTextEntry(string text, EventHandler <EventArgs> e) { TextMenuEntry entry = new TextMenuEntry(new TextSprite(_menuFont, text)); entry.Selected += e; entry.Selected += (s, a) => _menuSound.Play(); return(entry); }
/// <summary> /// Returns a labelled text menu entry. /// </summary> private TextMenuEntry BuildOptionEntry(string label, string text, EventHandler <EventArgs> e) { TextMenuEntry entry = new TextMenuEntry( new TextSprite(_menuFont, label), new TextSprite(_menuFont, text)); entry.Selected += e; entry.Selected += (s, a) => _menuSound.Play(); entry.SelectText = Resources.MenuToggle; return(entry); }
internal void LoadMod(Mod mod, bool hotload) { CurrentlyLoading = mod; if (_Mods.Any(o => o.FullPath.Equals(mod.FullPath))) { MDebug.WriteLine($"Skipping already loaded mod {mod.Name}."); return; } if (!mod.Reloadable && hotload) { MDebug.WriteLine($"[WARNING] Skipping {mod.Name}: can't be hotloaded."); return; } if (mod.ModAssembly == null) { LoadError($"{mod.Name} failed to load: couldn't load assembly.", mod.Name); return; } if (!mod.MatchesVersion()) { LoadError($"{mod.Name} failed to load: wrong PiTUNG version. Required version: " + mod.GetRequiredVersion(), mod.Name); return; } try { mod.BeforePatch(); } catch (Exception ex) { LoadError($"{mod.Name} failed to load: error while executing before-patch method.", mod.Name); MDebug.WriteLine("More details: " + ex, 1); return; } try { _Harmony.PatchAll(mod.ModAssembly); foreach (Type cls in mod.ModAssembly.GetTypes()) { var attrs = (TargetAttribute[])cls.GetCustomAttributes(typeof(TargetAttribute), false); if (attrs.Length == 0) { continue; } foreach (var patch in PatchUtilities.GetMethodPatches(cls, attrs[0].ContainerType)) { var method = new HarmonyMethod(patch.PatchMethod); _Harmony.Patch( patch.BaseMethod, patch.Prefix ? method : null, patch.Postfix ? method : null); } } } catch (Exception ex) { LoadError($"{mod.Name} failed to load: error while patching methods.", mod.Name); MDebug.WriteLine("More details: " + ex, 1); return; } try { mod.AfterPatch(); } catch (Exception ex) { LoadError($"{mod.Name} failed to load: error while executing after-patch method.", mod.Name); MDebug.WriteLine("More details: " + ex, 1); return; } MenuEntry[] entries; try { entries = mod.GetMenuEntries().ToArray(); } catch (Exception) { LoadError($"{mod.Name} failed to load: error while creating menu entries.", mod.Name); return; } if (entries.Length > 0) { var entry = new TextMenuEntry { Text = mod.Name }; entry.AddChildren(entries); ConfigMenu.Instance.Entries.Add(entry); } _Mods.Add(mod); MDebug.WriteLine($"{mod.Name} loaded successfully."); }