Skip to content

Commit

Permalink
Updated main menu to contain button to access global settings for the…
Browse files Browse the repository at this point in the history
… plugin in game
  • Loading branch information
8vogt committed Mar 21, 2021
1 parent 7654b49 commit c768472
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 24 deletions.
21 changes: 21 additions & 0 deletions SEWorldGenPlugin/GUI/MyPluginGuiHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,27 @@ public static MyGuiControlButton CreateDebugButton(float usableWidth, string tex
return myGuiControlButton;
}

/// <summary>
/// Creates a debug style button. It is smaller than a nornmal button.
/// </summary>
/// <param name="text">Text of the button</param>
/// <param name="onClick">On click event of the button</param>
/// <param name="enabled">If it is enabled</param>
/// <param name="tooltip">Tooltip for the button</param>
/// <returns>The created button</returns>
public static MyGuiControlButton CreateDebugButton(string text, Action<MyGuiControlButton> onClick, bool enabled = true, string tooltip = null)
{
MyGuiControlButton myGuiControlButton = new MyGuiControlButton(null, VRage.Game.MyGuiControlButtonStyleEnum.Debug, onButtonClick: onClick);
myGuiControlButton.VisualStyle = MyGuiControlButtonStyleEnum.Rectangular;
myGuiControlButton.Enabled = enabled;
myGuiControlButton.Text = text;
if (tooltip == null)
{
myGuiControlButton.SetToolTip(tooltip);
}
return myGuiControlButton;
}

/// <summary>
/// Displays an error message box to the user and calls the given callback, when it is closed.
/// </summary>
Expand Down
42 changes: 18 additions & 24 deletions SEWorldGenPlugin/GUI/MyPluginMainMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,20 @@ public override void RecreateControls(bool constructor)
OPENED_VERSION_NOTIFICATION = true;
MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(MyMessageBoxStyleEnum.Info, MyMessageBoxButtonsType.YES_NO, new StringBuilder(MyPluginTexts.MESSAGES.UPDATE_AVAILABLE_BOX), new StringBuilder(MyPluginTexts.MESSAGES.UPDATE_AVAILABLE_TITLE), null, null, null, null, OnUpdateNotifiactionMessageClose));
}

MyGuiControlLabel pluginVersionLabel = new MyGuiControlLabel();
pluginVersionLabel.Text = PLUGIN_LOADED + VersionCheck.Static.GetVersion();
pluginVersionLabel.Position = MyGuiManager.ComputeFullscreenGuiCoordinate(MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_BOTTOM, 8, 8);
pluginVersionLabel.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER;
pluginVersionLabel.PositionY -= pluginVersionLabel.Size.Y / 2;

MyGuiControlButton pluginSettingsBtn = MyPluginGuiHelper.CreateDebugButton("Settings", OnPluginSettingsClick);
pluginSettingsBtn.Position = pluginVersionLabel.Position;
pluginSettingsBtn.PositionX += pluginVersionLabel.Size.X + (8 / MyGuiConstants.GUI_OPTIMAL_SIZE.X);
pluginSettingsBtn.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER;

Controls.Add(pluginVersionLabel);
Controls.Add(pluginSettingsBtn);
}

/// <summary>
Expand Down Expand Up @@ -133,32 +147,12 @@ private void RunWithTutorialCheck(Action afterTutorial)
}

/// <summary>
/// OnDraw to draw on the screen
/// </summary>
/// <returns></returns>
public override bool Draw()
{
DrawPluginLoaded();
return base.Draw();
}

/// <summary>
/// Draws the plugins version and loaded message on the screen
/// Runs when the settings button for the plugin is clicked.
/// </summary>
private void DrawPluginLoaded()
/// <param name="btn">The button that called this event</param>
private void OnPluginSettingsClick(MyGuiControlButton btn)
{
Vector2 size;
Vector2 textLeftBottomPosition = MyGuiManager.ComputeFullscreenGuiCoordinate(MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_BOTTOM, 8, 8);
textLeftBottomPosition.Y -= 0 * TEXT_LINE_HEIGHT;

StringBuilder pluginWithVersion = new StringBuilder();
pluginWithVersion.AppendFormat(PLUGIN_LOADED.ToString(), VersionCheck.Static.GetVersion());

MyGuiManager.DrawString(MyFontEnum.BuildInfo, pluginWithVersion.ToString(), textLeftBottomPosition, 0.5f, new Color(MyGuiConstants.LABEL_TEXT_COLOR * m_transitionAlpha, 1), MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_BOTTOM);

size = MyGuiManager.MeasureString(MyFontEnum.BuildInfo, pluginWithVersion, 1);

textLeftBottomPosition.X += size.X;
MyGuiSandbox.AddScreen(new MyPluginGlobalSettings());
}
}
}
1 change: 1 addition & 0 deletions SEWorldGenPlugin/SEWorldGenPlugin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@
<Compile Include="GUI\Controls\MyGuiControlRangedSlider.cs" />
<Compile Include="GUI\AdminMenu\MyPluginAdminMenu.cs" />
<Compile Include="GUI\Controls\MyGuiScreenDialogCoordinate.cs" />
<Compile Include="GUI\MyPluginGlobalSettings.cs" />
<Compile Include="GUI\MyPluginGuiHelper.cs" />
<Compile Include="GUI\MyPluginSettingsMenu.cs" />
<Compile Include="GUI\PluginGuiScreenNewGame.cs" />
Expand Down

0 comments on commit c768472

Please sign in to comment.