public override void ContextMenuClicked(MyGuiScreenPluginConfig screen, MyGuiControlContextMenu.EventArgs args) { switch (args.ItemIndex) { case 0: Main.Instance.Config.PluginFolders.Remove(Id); screen.RemovePlugin(this); screen.RequireRestart(); break; case 1: LoaderTools.OpenFileDialog("Open an xml data file", Path.GetDirectoryName(FolderSettings.DataFile), XmlDataType, (file) => DeserializeFile(file, screen)); break; case 2: FolderSettings.DebugBuild = !FolderSettings.DebugBuild; screen.RequireRestart(); break; } }
// Deserializes a file and refreshes the plugin screen private void DeserializeFile(string file, MyGuiScreenPluginConfig screen = null) { if (!File.Exists(file)) { return; } try { XmlSerializer xml = new XmlSerializer(typeof(PluginData)); using (StreamReader reader = File.OpenText(file)) { object resultObj = xml.Deserialize(reader); if (resultObj.GetType() != typeof(GitHubPlugin)) { throw new Exception("Xml file is not of type GitHubPlugin!"); } GitHubPlugin github = (GitHubPlugin)resultObj; github.Init(LoaderTools.PluginsDir); FriendlyName = github.FriendlyName; Tooltip = github.Tooltip; Author = github.Author; Description = github.Description; sourceDirectories = github.SourceDirectories; FolderSettings.DataFile = file; if (screen != null && screen.Visible && screen.IsOpened) { screen.RefreshSidePanel(); } } } catch (Exception e) { LogFile.WriteLine("Error while reading the xml file: " + e); } }
public static void Postfix(MyGuiScreenMainMenu __instance, Vector2 leftButtonPositionOrigin, ref Vector2 lastButtonPosition) { MyGuiControlButton lastBtn = null; foreach (var control in __instance.Controls) { if (control is MyGuiControlButton btn && btn.Position == lastButtonPosition) { lastBtn = btn; break; } } Vector2 position; if (lastBtn == null) { position = lastButtonPosition + MyGuiConstants.MENU_BUTTONS_POSITION_DELTA; } else { position = lastBtn.Position; lastBtn.Position = lastButtonPosition + MyGuiConstants.MENU_BUTTONS_POSITION_DELTA; } MyGuiControlButton openBtn = new MyGuiControlButton(position, MyGuiControlButtonStyleEnum.StripeLeft, originAlign: MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_BOTTOM, text: new StringBuilder("Plugins"), onButtonClick: _ => MyGuiScreenPluginConfig.OpenMenu()) { BorderEnabled = false, BorderSize = 0, BorderHighlightEnabled = false, BorderColor = Vector4.Zero }; __instance.Controls.Add(openBtn); }
public virtual void ContextMenuClicked(MyGuiScreenPluginConfig screen, MyGuiControlContextMenu.EventArgs args) { }